index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  4. __name: "index",
  5. setup(__props) {
  6. var _a, _b, _c;
  7. const $api = (_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.appContext.config.globalProperties.$api;
  8. (_b = common_vendor.getCurrentInstance()) == null ? void 0 : _b.appContext.config.globalProperties.$config;
  9. const $apifile = (_c = common_vendor.getCurrentInstance()) == null ? void 0 : _c.appContext.config.globalProperties.$apifile;
  10. const openid = common_vendor.computed(() => {
  11. return common_vendor.index.getStorageSync("openid");
  12. });
  13. const config = common_vendor.ref({ logoUrl: "" });
  14. const form = common_vendor.ref({ icon: "" });
  15. const sexList = common_vendor.ref([]);
  16. const typeList = common_vendor.ref([]);
  17. const placeList = common_vendor.ref([]);
  18. const ballYearsList = common_vendor.ref([]);
  19. common_vendor.onLoad(async () => {
  20. await searchOther();
  21. await searchConfig();
  22. await search();
  23. common_vendor.index.$on("setCity", function(city) {
  24. form.value.city = city;
  25. });
  26. });
  27. const searchOther = async () => {
  28. let res;
  29. res = await $api(`dict/data/list`, "GET", { dictType: "sys_user_sex" });
  30. if (res.code === 200 && res.total > 0)
  31. sexList.value = res.rows;
  32. res = await $api(`dict/data/list`, "GET", { dictType: "sys_user_type" });
  33. if (res.code === 200 && res.total > 0)
  34. typeList.value = res.rows;
  35. res = await $api(`dict/data/list`, "GET", { dictType: "sys_user_place" });
  36. if (res.code === 200 && res.total > 0)
  37. placeList.value = res.rows;
  38. res = await $api(`dict/data/list`, "GET", { dictType: "sys_user_year" });
  39. if (res.code === 200 && res.total > 0)
  40. ballYearsList.value = res.rows;
  41. };
  42. const searchConfig = async () => {
  43. config.value = common_vendor.index.getStorageSync("config");
  44. };
  45. const search = async () => {
  46. const res = await $api(`matchUser/find`, "GET", {
  47. openid: openid.value
  48. });
  49. if (res.code === 200) {
  50. if (res.data) {
  51. form.value = res.data;
  52. form.value.sex = toData(form.value.sex, sexList.value);
  53. form.value.type = toData(form.value.type, typeList.value);
  54. form.value.place = toData(form.value.place, placeList.value);
  55. form.value.ballYears = toData(form.value.ballYears, ballYearsList.value);
  56. } else {
  57. common_vendor.index.navigateTo({
  58. url: `/pages/login/index`
  59. });
  60. }
  61. } else {
  62. common_vendor.index.showToast({
  63. title: res.msg || "",
  64. icon: "error"
  65. });
  66. }
  67. };
  68. const toData = (value, list) => {
  69. if (value)
  70. return value = list[value].dictLabel;
  71. };
  72. const toCity = () => {
  73. if (form.value.city) {
  74. common_vendor.index.navigateTo({
  75. url: `/pagesHome/city/index?city=${form.value.city}`
  76. });
  77. } else {
  78. common_vendor.index.navigateTo({
  79. url: `/pagesHome/city/index`
  80. });
  81. }
  82. };
  83. const sexChange = (e) => {
  84. const data = sexList.value[e.detail.value];
  85. if (data)
  86. form.value.sex = data.dictLabel;
  87. };
  88. const typeChange = (e) => {
  89. const data = typeList.value[e.detail.value];
  90. if (data)
  91. form.value.type = data.dictLabel;
  92. };
  93. const placeChange = (e) => {
  94. const data = placeList.value[e.detail.value];
  95. if (data)
  96. form.value.place = data.dictLabel;
  97. };
  98. const ballYearsChange = (e) => {
  99. const data = ballYearsList.value[e.detail.value];
  100. if (data)
  101. form.value.ballYears = data.dictLabel;
  102. };
  103. const Preview = () => {
  104. common_vendor.index.chooseImage({
  105. count: 1,
  106. sizeType: ["original", "compressed"],
  107. sourceType: ["album", "camera"],
  108. success: async function(res) {
  109. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  110. const arr = await $apifile(
  111. `/common/upload`,
  112. "file",
  113. tempFile[0],
  114. "file"
  115. );
  116. if (arr.code == 200) {
  117. form.value.icon = arr.url;
  118. } else {
  119. common_vendor.index.showToast({
  120. title: arr.msg,
  121. icon: "none"
  122. });
  123. }
  124. }
  125. });
  126. };
  127. const formSubmit = async (e) => {
  128. let data = e.detail.value;
  129. data.icon = form.value.icon;
  130. data = delEmptyQueryNodes(data);
  131. const arr = await $api(`matchUser`, "PUT", data);
  132. if (arr.code === 200) {
  133. search();
  134. } else {
  135. common_vendor.index.showToast({
  136. title: arr.msg,
  137. icon: "error"
  138. });
  139. }
  140. };
  141. const delEmptyQueryNodes = (obj = {}) => {
  142. Object.keys(obj).forEach((key) => {
  143. let value = obj[key];
  144. value && typeof value === "object" && delEmptyQueryNodes(value);
  145. (value === "" || value === null || value === void 0 || value.length === 0 || Object.keys(value).length === 0) && delete obj[key];
  146. });
  147. return obj;
  148. };
  149. return (_ctx, _cache) => {
  150. return common_vendor.e({
  151. a: form.value.id,
  152. b: form.value.icon || config.value.logoUrl,
  153. c: common_vendor.o(Preview),
  154. d: form.value.name,
  155. e: form.value.nickname,
  156. f: common_vendor.t(form.value.sex || "请选择性别"),
  157. g: common_vendor.o(sexChange),
  158. h: _ctx.index,
  159. i: sexList.value,
  160. j: form.value.phone,
  161. k: form.value.city
  162. }, form.value.city ? {
  163. l: common_vendor.t(form.value.city)
  164. } : {}, {
  165. m: common_vendor.o(toCity),
  166. n: form.value.city,
  167. o: form.value.height,
  168. p: form.value.weight,
  169. q: common_vendor.t(form.value.type || "请选择主要项目"),
  170. r: common_vendor.o(typeChange),
  171. s: _ctx.index,
  172. t: typeList.value,
  173. v: common_vendor.t(form.value.ballYears || "请选择球龄"),
  174. w: common_vendor.o(ballYearsChange),
  175. x: _ctx.index,
  176. y: ballYearsList.value,
  177. z: common_vendor.t(form.value.place || "请选择队内位置"),
  178. A: common_vendor.o(placeChange),
  179. B: _ctx.index,
  180. C: placeList.value,
  181. D: common_vendor.o(formSubmit)
  182. });
  183. };
  184. }
  185. });
  186. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-bf1a7b85"], ["__file", "D:/project/足球比赛/match_applet/pagesMy/basic/index.vue"]]);
  187. wx.createPage(MiniProgramPage);