index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. common_vendor.index.showToast({ title: e || "加载型号列表失败", icon: "none" });
  53. } finally {
  54. this.isLoading = false;
  55. }
  56. },
  57. async checkLoginStatus() {
  58. const token = common_vendor.index.getStorageSync("token");
  59. if (!token) {
  60. this.isLoggedIn = false;
  61. this.myInfo = {};
  62. return;
  63. }
  64. try {
  65. const res = await api_system_customer.getMyInfo();
  66. this.isLoggedIn = true;
  67. this.myInfo = res.data || {};
  68. this.loadOrderItems();
  69. } catch (e) {
  70. common_vendor.index.showToast({ title: e || "登录状态校验失败", icon: "none" });
  71. common_vendor.index.removeStorageSync("token");
  72. common_vendor.index.removeStorageSync("isLogin");
  73. this.isLoggedIn = false;
  74. this.myInfo = {};
  75. this.isLoading = false;
  76. }
  77. },
  78. goToLogin() {
  79. common_vendor.index.reLaunch({ url: "/pages/login/index" });
  80. },
  81. contactAdmin() {
  82. common_vendor.index.showModal({ title: "联系管理员", content: "管理员电话:138-0000-0000", showCancel: false, confirmColor: "#C1001C" });
  83. },
  84. goToAddModel() {
  85. common_vendor.index.navigateTo({
  86. url: "/pages/order/add-model/index"
  87. });
  88. },
  89. editItem(index, item) {
  90. common_vendor.index.navigateTo({
  91. url: `/pages/order/edit-model/index?index=${index}&data=${encodeURIComponent(JSON.stringify(item))}`
  92. });
  93. },
  94. removeItem(index) {
  95. const self = this;
  96. common_vendor.index.showModal({
  97. title: "提示",
  98. content: "确定移除该型号吗?",
  99. success: (res) => {
  100. if (res.confirm) {
  101. self.selectedModels.splice(index, 1);
  102. }
  103. }
  104. });
  105. },
  106. async submitFinalOrder() {
  107. if (this.selectedModels.length === 0)
  108. return;
  109. common_vendor.index.showLoading({ title: "正在提交订单", mask: true });
  110. try {
  111. const detailIds = this.selectedModels.map((item) => item.rowId);
  112. const res = await api_erp_order.addOrder({ detailIds });
  113. common_vendor.index.hideLoading();
  114. const orderId = res.data;
  115. common_vendor.index.showToast({ title: "下单成功", icon: "success" });
  116. setTimeout(() => {
  117. common_vendor.index.navigateTo({
  118. url: "/pages/order/success/index?orderId=" + orderId
  119. });
  120. }, 1500);
  121. } catch (e) {
  122. common_vendor.index.hideLoading();
  123. common_vendor.index.showToast({ title: e || "下单失败", icon: "none" });
  124. }
  125. }
  126. }
  127. };
  128. if (!Array) {
  129. const _component_erp_nav_bar = common_vendor.resolveComponent("erp-nav-bar");
  130. const _component_erp_tab_bar = common_vendor.resolveComponent("erp-tab-bar");
  131. (_component_erp_nav_bar + _component_erp_tab_bar)();
  132. }
  133. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  134. return common_vendor.e({
  135. a: common_vendor.p({
  136. title: "ERP 下单",
  137. ["show-back"]: false
  138. }),
  139. b: $data.isLoading
  140. }, $data.isLoading ? {} : !$data.isLoggedIn ? {
  141. d: common_vendor.o((...args) => $options.goToLogin && $options.goToLogin(...args), "65")
  142. } : !$data.myInfo.authClientFRowID ? {
  143. f: common_vendor.o((...args) => $options.contactAdmin && $options.contactAdmin(...args), "b0")
  144. } : common_vendor.e({
  145. g: $data.selectedModels.length > 0
  146. }, $data.selectedModels.length > 0 ? {} : {}, {
  147. h: $data.selectedModels.length > 0
  148. }, $data.selectedModels.length > 0 ? {
  149. i: common_vendor.f($data.selectedModels, (item, index, i0) => {
  150. return {
  151. a: common_vendor.o(($event) => $options.removeItem(index), index),
  152. b: common_vendor.t(item.modelNum),
  153. c: common_vendor.t(item.count),
  154. d: common_vendor.t(item.surfaceName),
  155. e: index,
  156. f: common_vendor.o(($event) => $options.editItem(index, item), index)
  157. };
  158. })
  159. } : {
  160. j: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "1f")
  161. }, {
  162. k: $data.selectedModels.length > 0
  163. }, $data.selectedModels.length > 0 ? {
  164. l: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "6e")
  165. } : {}, {
  166. m: $data.selectedModels.length > 0
  167. }, $data.selectedModels.length > 0 ? {
  168. n: common_vendor.t($data.selectedModels.length),
  169. o: common_vendor.t($options.totalCount),
  170. p: $data.selectedModels.length === 0,
  171. q: common_vendor.o((...args) => $options.submitFinalOrder && $options.submitFinalOrder(...args), "cb")
  172. } : {}), {
  173. c: !$data.isLoggedIn,
  174. e: !$data.myInfo.authClientFRowID,
  175. r: common_vendor.p({
  176. active: "order"
  177. })
  178. });
  179. }
  180. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-17a44f9d"]]);
  181. wx.createPage(MiniProgramPage);
  182. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/index.js.map