index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_system_customer = require("../../api/system/customer.js");
  4. const ErpTabBar = () => "../../components/erp-tab-bar.js";
  5. const ErpNavBar = () => "../../components/erp-nav-bar.js";
  6. const _sfc_main = {
  7. components: { ErpNavBar, ErpTabBar },
  8. data() {
  9. return {
  10. isLoggedIn: false,
  11. authorizedClients: [],
  12. selectedModels: []
  13. };
  14. },
  15. computed: {
  16. totalCount() {
  17. return this.selectedModels.reduce((sum, item) => sum + parseInt(item.count || 0), 0);
  18. }
  19. },
  20. onLoad() {
  21. common_vendor.index.$on("add_order_item", (data) => {
  22. this.selectedModels.push(data);
  23. common_vendor.index.showToast({ title: "添加成功", icon: "success" });
  24. });
  25. common_vendor.index.$on("update_order_item", (res) => {
  26. if (res.index > -1) {
  27. this.$set(this.selectedModels, res.index, res.data);
  28. common_vendor.index.showToast({ title: "修改成功", icon: "success" });
  29. }
  30. });
  31. },
  32. onShow() {
  33. this.checkLoginStatus();
  34. },
  35. onUnload() {
  36. common_vendor.index.$off("add_order_item");
  37. common_vendor.index.$off("update_order_item");
  38. },
  39. methods: {
  40. async checkLoginStatus() {
  41. const token = common_vendor.index.getStorageSync("token");
  42. if (!token) {
  43. this.isLoggedIn = false;
  44. this.authorizedClients = [];
  45. return;
  46. }
  47. try {
  48. await api_system_customer.getMyInfo();
  49. this.isLoggedIn = true;
  50. this.loadAuthorizedClients();
  51. } catch (e) {
  52. common_vendor.index.removeStorageSync("token");
  53. common_vendor.index.removeStorageSync("isLogin");
  54. this.isLoggedIn = false;
  55. this.authorizedClients = [];
  56. }
  57. },
  58. loadAuthorizedClients() {
  59. const clients = common_vendor.index.getStorageSync("authorizedClients");
  60. this.authorizedClients = clients || [];
  61. },
  62. goToLogin() {
  63. common_vendor.index.reLaunch({ url: "/pages/login/index" });
  64. },
  65. contactAdmin() {
  66. common_vendor.index.showModal({ title: "联系管理员", content: "管理员电话:138-0000-0000", showCancel: false, confirmColor: "#C1001C" });
  67. },
  68. goToAddModel() {
  69. common_vendor.index.navigateTo({
  70. url: "/pages/order/add-model/index"
  71. });
  72. },
  73. editItem(index, item) {
  74. common_vendor.index.navigateTo({
  75. url: `/pages/order/edit-model/index?index=${index}&data=${encodeURIComponent(JSON.stringify(item))}`
  76. });
  77. },
  78. removeItem(index) {
  79. const self = this;
  80. common_vendor.index.showModal({
  81. title: "提示",
  82. content: "确定移除该型号吗?",
  83. success: (res) => {
  84. if (res.confirm) {
  85. self.selectedModels.splice(index, 1);
  86. }
  87. }
  88. });
  89. },
  90. submitFinalOrder() {
  91. if (this.selectedModels.length === 0)
  92. return;
  93. common_vendor.index.showLoading({ title: "正在提交结果", mask: true });
  94. setTimeout(() => {
  95. common_vendor.index.hideLoading();
  96. common_vendor.index.navigateTo({
  97. url: "/pages/order/success/index"
  98. });
  99. }, 1500);
  100. }
  101. }
  102. };
  103. if (!Array) {
  104. const _component_erp_nav_bar = common_vendor.resolveComponent("erp-nav-bar");
  105. const _component_erp_tab_bar = common_vendor.resolveComponent("erp-tab-bar");
  106. (_component_erp_nav_bar + _component_erp_tab_bar)();
  107. }
  108. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  109. return common_vendor.e({
  110. a: common_vendor.p({
  111. title: "ERP 下单",
  112. ["show-back"]: false
  113. }),
  114. b: !$data.isLoggedIn
  115. }, !$data.isLoggedIn ? {
  116. c: common_vendor.o((...args) => $options.goToLogin && $options.goToLogin(...args), "93")
  117. } : $data.authorizedClients.length === 0 ? {
  118. e: common_vendor.o((...args) => $options.contactAdmin && $options.contactAdmin(...args), "e2")
  119. } : common_vendor.e({
  120. f: $data.selectedModels.length > 0
  121. }, $data.selectedModels.length > 0 ? {} : {}, {
  122. g: $data.selectedModels.length > 0
  123. }, $data.selectedModels.length > 0 ? {
  124. h: common_vendor.f($data.selectedModels, (item, index, i0) => {
  125. return {
  126. a: common_vendor.o(($event) => $options.removeItem(index), index),
  127. b: common_vendor.t(item.type),
  128. c: common_vendor.t(item.count),
  129. d: common_vendor.t(item.surfaceName),
  130. e: index,
  131. f: common_vendor.o(($event) => $options.editItem(index, item), index)
  132. };
  133. })
  134. } : {
  135. i: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "7a")
  136. }, {
  137. j: $data.selectedModels.length > 0
  138. }, $data.selectedModels.length > 0 ? {
  139. k: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "6d")
  140. } : {}, {
  141. l: $data.selectedModels.length > 0
  142. }, $data.selectedModels.length > 0 ? {
  143. m: common_vendor.t($data.selectedModels.length),
  144. n: common_vendor.t($options.totalCount),
  145. o: $data.selectedModels.length === 0,
  146. p: common_vendor.o((...args) => $options.submitFinalOrder && $options.submitFinalOrder(...args), "7e")
  147. } : {}), {
  148. d: $data.authorizedClients.length === 0,
  149. q: common_vendor.p({
  150. active: "order"
  151. })
  152. });
  153. }
  154. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-17a44f9d"]]);
  155. wx.createPage(MiniProgramPage);
  156. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/index.js.map