index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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", status: "0" });
  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.create_time = common_vendor.hooks().format("YYYY-MM-DD HH:mm:ss");
  81. data = delEmptyQueryNodes(data);
  82. data.userId = user.value.id;
  83. const arr = await $api(`team`, "POST", data);
  84. if (arr.code === 200) {
  85. common_vendor.index.navigateBack({
  86. delta: 1
  87. });
  88. } else {
  89. common_vendor.index.showToast({
  90. title: arr.msg,
  91. icon: "error"
  92. });
  93. }
  94. } else {
  95. common_vendor.index.showToast({
  96. title: `无用户信息 无法创建球队`,
  97. icon: "none"
  98. });
  99. }
  100. };
  101. const delEmptyQueryNodes = (obj = {}) => {
  102. Object.keys(obj).forEach((key) => {
  103. let value = obj[key];
  104. value && typeof value === "object" && delEmptyQueryNodes(value);
  105. (value === "" || value === null || value === void 0 || value.length === 0 || Object.keys(value).length === 0) && delete obj[key];
  106. });
  107. return obj;
  108. };
  109. return (_ctx, _cache) => {
  110. return common_vendor.e({
  111. a: form.value.logo || "/static/qiudui.png",
  112. b: common_vendor.o(Preview),
  113. c: form.value.name,
  114. d: common_vendor.t(form.value.type || "请选择类型"),
  115. e: common_vendor.o(typeChange),
  116. f: _ctx.index,
  117. g: typeList.value,
  118. h: form.value.city
  119. }, form.value.city ? {
  120. i: common_vendor.t(form.value.city)
  121. } : {}, {
  122. j: common_vendor.o(toCity),
  123. k: common_vendor.t(form.value.date || "请选择成立时间"),
  124. l: common_vendor.o(dateChange),
  125. m: _ctx.index,
  126. n: form.value.color,
  127. o: form.value.brief,
  128. p: common_vendor.o(formSubmit)
  129. });
  130. };
  131. }
  132. });
  133. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-01c8185c"], ["__file", "D:/project/足球比赛/match_applet/pagesHome/team/index.vue"]]);
  134. wx.createPage(MiniProgramPage);