index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_system_customer = require("../../api/system/customer.js");
  4. const api_erp_orderDetail = require("../../api/erp/orderDetail.js");
  5. const api_erp_order = require("../../api/erp/order.js");
  6. const ErpTabBar = () => "../../components/erp-tab-bar.js";
  7. const ErpNavBar = () => "../../components/erp-nav-bar.js";
  8. const _sfc_main = {
  9. components: { ErpNavBar, ErpTabBar },
  10. data() {
  11. return {
  12. isLoggedIn: false,
  13. isLoading: true,
  14. // 初始为加载中
  15. myInfo: {},
  16. selectedModels: []
  17. };
  18. },
  19. computed: {
  20. totalCount() {
  21. return this.selectedModels.reduce((sum, item) => sum + parseInt(item.count || 0), 0);
  22. }
  23. },
  24. onLoad() {
  25. common_vendor.index.$on("add_order_item", (data) => {
  26. this.loadOrderItems(false);
  27. });
  28. common_vendor.index.$on("update_order_item", (res) => {
  29. this.loadOrderItems(false);
  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. /**
  41. * 加载已选型号列表(OrderID 为空的草稿)
  42. * @Author: Antigravity
  43. */
  44. async loadOrderItems(showFullLoading = true) {
  45. if (showFullLoading)
  46. this.isLoading = true;
  47. try {
  48. const res = await api_erp_orderDetail.listOrderDetail({ orderId: "" });
  49. this.selectedModels = res.data || [];
  50. } catch (e) {
  51. common_vendor.index.__f__("error", "at pages/order/index.vue:156", "加载型号列表失败", e);
  52. } finally {
  53. this.isLoading = false;
  54. }
  55. },
  56. async checkLoginStatus() {
  57. const token = common_vendor.index.getStorageSync("token");
  58. if (!token) {
  59. this.isLoggedIn = false;
  60. this.myInfo = {};
  61. return;
  62. }
  63. try {
  64. const res = await api_system_customer.getMyInfo();
  65. this.isLoggedIn = true;
  66. this.myInfo = res.data || {};
  67. this.loadOrderItems();
  68. } catch (e) {
  69. common_vendor.index.removeStorageSync("token");
  70. common_vendor.index.removeStorageSync("isLogin");
  71. this.isLoggedIn = false;
  72. this.myInfo = {};
  73. this.isLoading = false;
  74. }
  75. },
  76. goToLogin() {
  77. common_vendor.index.reLaunch({ url: "/pages/login/index" });
  78. },
  79. contactAdmin() {
  80. common_vendor.index.showModal({ title: "联系管理员", content: "管理员电话:138-0000-0000", showCancel: false, confirmColor: "#C1001C" });
  81. },
  82. goToAddModel() {
  83. common_vendor.index.navigateTo({
  84. url: "/pages/order/add-model/index"
  85. });
  86. },
  87. editItem(index, item) {
  88. common_vendor.index.navigateTo({
  89. url: `/pages/order/edit-model/index?index=${index}&data=${encodeURIComponent(JSON.stringify(item))}`
  90. });
  91. },
  92. removeItem(index) {
  93. const self = this;
  94. common_vendor.index.showModal({
  95. title: "提示",
  96. content: "确定移除该型号吗?",
  97. success: (res) => {
  98. if (res.confirm) {
  99. self.selectedModels.splice(index, 1);
  100. }
  101. }
  102. });
  103. },
  104. async submitFinalOrder() {
  105. if (this.selectedModels.length === 0)
  106. return;
  107. common_vendor.index.showLoading({ title: "正在提交订单", mask: true });
  108. try {
  109. const detailIds = this.selectedModels.map((item) => item.rowId);
  110. await api_erp_order.addOrder({ detailIds });
  111. common_vendor.index.hideLoading();
  112. common_vendor.index.showToast({ title: "下单成功", icon: "success" });
  113. setTimeout(() => {
  114. common_vendor.index.navigateTo({
  115. url: "/pages/order/success/index"
  116. });
  117. }, 1500);
  118. } catch (e) {
  119. common_vendor.index.hideLoading();
  120. }
  121. }
  122. }
  123. };
  124. if (!Array) {
  125. const _component_erp_nav_bar = common_vendor.resolveComponent("erp-nav-bar");
  126. const _component_erp_tab_bar = common_vendor.resolveComponent("erp-tab-bar");
  127. (_component_erp_nav_bar + _component_erp_tab_bar)();
  128. }
  129. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  130. return common_vendor.e({
  131. a: common_vendor.p({
  132. title: "ERP 下单",
  133. ["show-back"]: false
  134. }),
  135. b: $data.isLoading
  136. }, $data.isLoading ? {} : !$data.isLoggedIn ? {
  137. d: common_vendor.o((...args) => $options.goToLogin && $options.goToLogin(...args), "65")
  138. } : !$data.myInfo.authClientFRowID ? {
  139. f: common_vendor.o((...args) => $options.contactAdmin && $options.contactAdmin(...args), "b0")
  140. } : common_vendor.e({
  141. g: $data.selectedModels.length > 0
  142. }, $data.selectedModels.length > 0 ? {} : {}, {
  143. h: $data.selectedModels.length > 0
  144. }, $data.selectedModels.length > 0 ? {
  145. i: common_vendor.f($data.selectedModels, (item, index, i0) => {
  146. return {
  147. a: common_vendor.o(($event) => $options.removeItem(index), index),
  148. b: common_vendor.t(item.modelNum),
  149. c: common_vendor.t(item.count),
  150. d: common_vendor.t(item.surfaceName),
  151. e: index,
  152. f: common_vendor.o(($event) => $options.editItem(index, item), index)
  153. };
  154. })
  155. } : {
  156. j: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "1f")
  157. }, {
  158. k: $data.selectedModels.length > 0
  159. }, $data.selectedModels.length > 0 ? {
  160. l: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "6e")
  161. } : {}, {
  162. m: $data.selectedModels.length > 0
  163. }, $data.selectedModels.length > 0 ? {
  164. n: common_vendor.t($data.selectedModels.length),
  165. o: common_vendor.t($options.totalCount),
  166. p: $data.selectedModels.length === 0,
  167. q: common_vendor.o((...args) => $options.submitFinalOrder && $options.submitFinalOrder(...args), "cb")
  168. } : {}), {
  169. c: !$data.isLoggedIn,
  170. e: !$data.myInfo.authClientFRowID,
  171. r: common_vendor.p({
  172. active: "order"
  173. })
  174. });
  175. }
  176. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-17a44f9d"]]);
  177. wx.createPage(MiniProgramPage);
  178. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/index.js.map