index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 delEmptyQueryNodes = (obj = {}) => {
  128. Object.keys(obj).forEach((key) => {
  129. let value = obj[key];
  130. value && typeof value === "object" && delEmptyQueryNodes(value);
  131. (value === "" || value === null || value === void 0 || value.length === 0 || Object.keys(value).length === 0) && delete obj[key];
  132. });
  133. return obj;
  134. };
  135. const formSubmit = async (e) => {
  136. const data = delEmptyQueryNodes(e.detail.value);
  137. data.id = form.value.id;
  138. if (form.value.icon)
  139. data.icon = form.value.icon;
  140. if (form.value.city)
  141. data.city = form.value.city;
  142. const arr = await $api(`matchUser`, "put", data);
  143. if (arr.code === 200) {
  144. search();
  145. } else {
  146. common_vendor.index.showToast({
  147. title: arr.msg,
  148. icon: "error"
  149. });
  150. }
  151. };
  152. return (_ctx, _cache) => {
  153. return common_vendor.e({
  154. a: form.value.icon || config.value.logoUrl,
  155. b: common_vendor.o(Preview),
  156. c: form.value.name,
  157. d: form.value.nickname,
  158. e: common_vendor.t(form.value.sex || "请选择性别"),
  159. f: common_vendor.o(sexChange),
  160. g: _ctx.index,
  161. h: sexList.value,
  162. i: form.value.phone,
  163. j: form.value.city
  164. }, form.value.city ? {
  165. k: common_vendor.t(form.value.city)
  166. } : {}, {
  167. l: common_vendor.o(toCity),
  168. m: form.value.height,
  169. n: form.value.weight,
  170. o: common_vendor.t(form.value.type || "请选择主要项目"),
  171. p: common_vendor.o(typeChange),
  172. q: _ctx.index,
  173. r: typeList.value,
  174. s: common_vendor.t(form.value.ballYears || "请选择球龄"),
  175. t: common_vendor.o(ballYearsChange),
  176. v: _ctx.index,
  177. w: ballYearsList.value,
  178. x: common_vendor.t(form.value.place || "请选择队内位置"),
  179. y: common_vendor.o(placeChange),
  180. z: _ctx.index,
  181. A: placeList.value,
  182. B: common_vendor.o(formSubmit)
  183. });
  184. };
  185. }
  186. });
  187. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-bf1a7b85"], ["__file", "D:/project/足球比赛/match_applet/pagesMy/basic/index.vue"]]);
  188. wx.createPage(MiniProgramPage);