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({ fOrderId: "" });
  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. }
  74. },
  75. goToLogin() {
  76. common_vendor.index.reLaunch({ url: "/pages/login/index" });
  77. },
  78. contactAdmin() {
  79. common_vendor.index.showModal({ title: "联系管理员", content: "管理员电话:138-0000-0000", showCancel: false, confirmColor: "#C1001C" });
  80. },
  81. goToAddModel() {
  82. common_vendor.index.navigateTo({
  83. url: "/pages/order/add-model/index"
  84. });
  85. },
  86. editItem(index, item) {
  87. common_vendor.index.navigateTo({
  88. url: `/pages/order/edit-model/index?index=${index}&data=${encodeURIComponent(JSON.stringify(item))}`
  89. });
  90. },
  91. removeItem(index) {
  92. const self = this;
  93. common_vendor.index.showModal({
  94. title: "提示",
  95. content: "确定移除该型号吗?",
  96. success: (res) => {
  97. if (res.confirm) {
  98. self.selectedModels.splice(index, 1);
  99. }
  100. }
  101. });
  102. },
  103. async submitFinalOrder() {
  104. if (this.selectedModels.length === 0)
  105. return;
  106. common_vendor.index.showLoading({ title: "正在提交订单", mask: true });
  107. try {
  108. const detailIds = this.selectedModels.map((item) => item.frowId);
  109. await api_erp_order.addOrder({ detailIds });
  110. common_vendor.index.hideLoading();
  111. common_vendor.index.showToast({ title: "下单成功", icon: "success" });
  112. setTimeout(() => {
  113. common_vendor.index.navigateTo({
  114. url: "/pages/order/success/index"
  115. });
  116. }, 1500);
  117. } catch (e) {
  118. common_vendor.index.hideLoading();
  119. }
  120. }
  121. }
  122. };
  123. if (!Array) {
  124. const _component_erp_nav_bar = common_vendor.resolveComponent("erp-nav-bar");
  125. const _component_erp_tab_bar = common_vendor.resolveComponent("erp-tab-bar");
  126. (_component_erp_nav_bar + _component_erp_tab_bar)();
  127. }
  128. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  129. return common_vendor.e({
  130. a: common_vendor.p({
  131. title: "ERP 下单",
  132. ["show-back"]: false
  133. }),
  134. b: !$data.isLoggedIn
  135. }, !$data.isLoggedIn ? {
  136. c: common_vendor.o((...args) => $options.goToLogin && $options.goToLogin(...args), "93")
  137. } : !$data.myInfo.authClientFRowID ? {
  138. e: common_vendor.o((...args) => $options.contactAdmin && $options.contactAdmin(...args), "85")
  139. } : common_vendor.e({
  140. f: $data.isLoading
  141. }, $data.isLoading ? {} : common_vendor.e({
  142. g: $data.selectedModels.length > 0
  143. }, $data.selectedModels.length > 0 ? {} : {}, {
  144. h: $data.selectedModels.length > 0
  145. }, $data.selectedModels.length > 0 ? {
  146. i: common_vendor.f($data.selectedModels, (item, index, i0) => {
  147. return {
  148. a: common_vendor.o(($event) => $options.removeItem(index), index),
  149. b: common_vendor.t(item.modelNum),
  150. c: common_vendor.t(item.count),
  151. d: common_vendor.t(item.surfaceName),
  152. e: index,
  153. f: common_vendor.o(($event) => $options.editItem(index, item), index)
  154. };
  155. })
  156. } : {
  157. j: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "17")
  158. }), {
  159. k: $data.selectedModels.length > 0
  160. }, $data.selectedModels.length > 0 ? {
  161. l: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "4c")
  162. } : {}, {
  163. m: $data.selectedModels.length > 0
  164. }, $data.selectedModels.length > 0 ? {
  165. n: common_vendor.t($data.selectedModels.length),
  166. o: common_vendor.t($options.totalCount),
  167. p: $data.selectedModels.length === 0,
  168. q: common_vendor.o((...args) => $options.submitFinalOrder && $options.submitFinalOrder(...args), "63")
  169. } : {}), {
  170. d: !$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