爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
6.1 KiB

  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const pages_mixins_pullRefreshMixin = require("../mixins/pullRefreshMixin.js");
  4. const _sfc_main = {
  5. mixins: [pages_mixins_pullRefreshMixin.pullRefreshMixin],
  6. data() {
  7. return {
  8. tabs: [
  9. { name: "全部", count: 0 },
  10. { name: "进行中", count: 0 },
  11. { name: "已完成", count: 0 }
  12. ],
  13. currentTab: 0,
  14. orderList: [],
  15. // 当前显示的订单列表
  16. loading: false,
  17. page: 1,
  18. pageSize: 10,
  19. hasMore: true
  20. };
  21. },
  22. created() {
  23. this.fetchOrderList();
  24. },
  25. methods: {
  26. async fetchOrderList(isLoadMore = false) {
  27. this.loading = true;
  28. let statusArr = [];
  29. if (this.currentTab === 1)
  30. statusArr = [0, 1, 2];
  31. else if (this.currentTab === 2)
  32. statusArr = [3];
  33. else
  34. statusArr = [];
  35. let allOrders = [];
  36. if (statusArr.length === 0) {
  37. await new Promise((resolve) => {
  38. this.$api("getOrderListPage", { pageSize: this.pageSize, current: this.page }, (res) => {
  39. if (res && res.code === 200 && res.result && Array.isArray(res.result.records)) {
  40. allOrders = res.result.records;
  41. if (isLoadMore) {
  42. this.orderList = this.orderList.concat(allOrders);
  43. } else {
  44. this.orderList = allOrders;
  45. }
  46. this.hasMore = allOrders.length === this.pageSize;
  47. }
  48. resolve();
  49. });
  50. });
  51. } else {
  52. for (let status of statusArr) {
  53. await new Promise((resolve) => {
  54. this.$api("getOrderListPage", { status, pageSize: this.pageSize, current: this.page }, (res) => {
  55. if (res && res.code === 200 && res.result && Array.isArray(res.result.records)) {
  56. allOrders = allOrders.concat(res.result.records);
  57. }
  58. resolve();
  59. });
  60. });
  61. }
  62. const map = {};
  63. allOrders = allOrders.filter((item) => {
  64. if (map[item.id])
  65. return false;
  66. map[item.id] = 1;
  67. return true;
  68. });
  69. if (isLoadMore) {
  70. this.orderList = this.orderList.concat(allOrders);
  71. } else {
  72. this.orderList = allOrders;
  73. }
  74. this.hasMore = allOrders.length === this.pageSize;
  75. }
  76. this.loading = false;
  77. },
  78. switchTab(index) {
  79. if (this.currentTab === index)
  80. return;
  81. this.currentTab = index;
  82. this.page = 1;
  83. this.hasMore = true;
  84. this.orderList = [];
  85. this.fetchOrderList();
  86. },
  87. getOrderStatusText(order) {
  88. const { status, state } = order;
  89. if (state == 3)
  90. return "已取消";
  91. if (status == 0)
  92. return "【在线预约】";
  93. if (status == 1 && state == 0)
  94. return "【待取件】快递员正在赶来";
  95. if (status == 1 && state == 1)
  96. return "【已取件】快递员正在送至质检";
  97. if (status == 2 && state == 1)
  98. return "【质检中】质检员正在质检";
  99. if (status == 3 && state == 1)
  100. return "【待结款】待平台确认结款项";
  101. if (status == 3 && state == 2)
  102. return "【已结款】平台已结款至账户";
  103. return "";
  104. },
  105. async onRefresh() {
  106. await new Promise((resolve) => setTimeout(resolve, 1e3));
  107. common_vendor.index.stopPullRefresh();
  108. },
  109. goBack() {
  110. common_vendor.index.navigateBack();
  111. },
  112. showMore() {
  113. },
  114. onShare() {
  115. },
  116. viewAll() {
  117. this.switchTab(0);
  118. },
  119. // 加载更多
  120. loadMore() {
  121. if (this.loading || !this.hasMore)
  122. return;
  123. this.page++;
  124. this.fetchOrderList(true);
  125. },
  126. goToDetail(order) {
  127. common_vendor.index.navigateTo({
  128. url: `/pages/subcomponent/detail?id=${order.id}`
  129. });
  130. }
  131. }
  132. };
  133. if (!Array) {
  134. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  135. const _component_uni_loading = common_vendor.resolveComponent("uni-loading");
  136. (_easycom_uni_icons2 + _component_uni_loading)();
  137. }
  138. const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  139. if (!Math) {
  140. _easycom_uni_icons();
  141. }
  142. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  143. return common_vendor.e({
  144. a: common_vendor.p({
  145. type: "left",
  146. size: "20"
  147. }),
  148. b: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  149. c: common_vendor.f($data.tabs, (tab, index, i0) => {
  150. return common_vendor.e({
  151. a: common_vendor.t(tab.name),
  152. b: tab.count > 0
  153. }, tab.count > 0 ? {
  154. c: common_vendor.t(tab.count)
  155. } : {}, {
  156. d: index,
  157. e: $data.currentTab === index ? 1 : "",
  158. f: common_vendor.o(($event) => $options.switchTab(index), index)
  159. });
  160. }),
  161. d: common_vendor.f($data.orderList, (order, k0, i0) => {
  162. return {
  163. a: common_vendor.t(order.ordeNo || order.id),
  164. b: order.image || "/static/回收/衣物.png",
  165. c: common_vendor.t(order.num || order.count || 1),
  166. d: common_vendor.t(order.onePrice || order.priceRange || 0),
  167. e: common_vendor.t(order.price || order.estimatePrice),
  168. f: order.statusIcon || "/static/my/【待取件】快递员正在赶来.png",
  169. g: common_vendor.t($options.getOrderStatusText(order)),
  170. h: common_vendor.t(order.goTime || order.statusTime),
  171. i: order.id,
  172. j: common_vendor.o(($event) => $options.goToDetail(order), order.id)
  173. };
  174. }),
  175. e: $data.loading
  176. }, $data.loading ? {
  177. f: common_vendor.p({
  178. color: "#ffac07",
  179. size: 40
  180. })
  181. } : !$data.hasMore && $data.orderList.length ? {} : {}, {
  182. g: !$data.hasMore && $data.orderList.length,
  183. h: common_vendor.o((...args) => $options.loadMore && $options.loadMore(...args))
  184. });
  185. }
  186. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-e4b66be1"]]);
  187. wx.createPage(MiniProgramPage);
  188. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/subcomponent/order.js.map