index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. common_vendor.computed(() => {
  11. return common_vendor.index.getStorageSync("openid");
  12. });
  13. const user = common_vendor.ref({});
  14. const form = common_vendor.ref({});
  15. const typeList = common_vendor.ref([]);
  16. common_vendor.onShow(() => {
  17. searchUser();
  18. searchOther();
  19. common_vendor.index.$on("setCity", function(city) {
  20. form.value.city = city;
  21. });
  22. });
  23. const searchUser = async () => {
  24. user.value = common_vendor.index.getStorageSync("user");
  25. };
  26. const searchOther = async () => {
  27. let res;
  28. res = await $api(`dict/data/list`, "GET", { dictType: "sys_user_type" });
  29. if (res.code === 200 && res.total > 0)
  30. typeList.value = res.rows;
  31. };
  32. const typeChange = (e) => {
  33. const data = typeList.value[e.detail.value];
  34. if (data)
  35. form.value.type = data.dictLabel;
  36. };
  37. const dateChange = (e) => {
  38. form.value.date = e.detail.value;
  39. };
  40. const toCity = () => {
  41. if (form.value.city) {
  42. common_vendor.index.navigateTo({
  43. url: `/pagesHome/city/index?city=${form.value.city}`
  44. });
  45. } else {
  46. common_vendor.index.navigateTo({
  47. url: `/pagesHome/city/index`
  48. });
  49. }
  50. };
  51. const Preview = () => {
  52. common_vendor.index.chooseImage({
  53. count: 1,
  54. sizeType: ["original", "compressed"],
  55. sourceType: ["album", "camera"],
  56. success: async function(res) {
  57. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  58. const arr = await $apifile(
  59. `/common/upload`,
  60. "file",
  61. tempFile[0],
  62. "file"
  63. );
  64. if (arr.code == 200) {
  65. form.value.logo = arr.url;
  66. } else {
  67. common_vendor.index.showToast({
  68. title: arr.msg,
  69. icon: "none"
  70. });
  71. }
  72. }
  73. });
  74. };
  75. const formSubmit = async (e) => {
  76. if (user.value.id) {
  77. let data = e.detail.value;
  78. data.logo = form.value.logo;
  79. data.city = form.value.city;
  80. data = delEmptyQueryNodes(data);
  81. data.userId = user.value.id;
  82. const arr = await $api(`team`, "POST", data);
  83. if (arr.code === 200) {
  84. common_vendor.index.navigateBack({
  85. delta: 1
  86. });
  87. } else {
  88. common_vendor.index.showToast({
  89. title: arr.msg,
  90. icon: "error"
  91. });
  92. }
  93. } else {
  94. common_vendor.index.showToast({
  95. title: `无用户信息 无法创建球队`,
  96. icon: "none"
  97. });
  98. }
  99. };
  100. const delEmptyQueryNodes = (obj = {}) => {
  101. Object.keys(obj).forEach((key) => {
  102. let value = obj[key];
  103. value && typeof value === "object" && delEmptyQueryNodes(value);
  104. (value === "" || value === null || value === void 0 || value.length === 0 || Object.keys(value).length === 0) && delete obj[key];
  105. });
  106. return obj;
  107. };
  108. return (_ctx, _cache) => {
  109. return common_vendor.e({
  110. a: form.value.logo || "/static/qiudui.png",
  111. b: common_vendor.o(Preview),
  112. c: form.value.name,
  113. d: common_vendor.t(form.value.type || "请选择类型"),
  114. e: common_vendor.o(typeChange),
  115. f: _ctx.index,
  116. g: typeList.value,
  117. h: form.value.city
  118. }, form.value.city ? {
  119. i: common_vendor.t(form.value.city)
  120. } : {}, {
  121. j: common_vendor.o(toCity),
  122. k: common_vendor.t(form.value.date || "请选择成立时间"),
  123. l: common_vendor.o(dateChange),
  124. m: _ctx.index,
  125. n: form.value.color,
  126. o: form.value.brief,
  127. p: common_vendor.o(formSubmit)
  128. });
  129. };
  130. }
  131. });
  132. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-01c8185c"], ["__file", "D:/project/足球比赛/match_applet/pagesHome/team/index.vue"]]);
  133. wx.createPage(MiniProgramPage);