爱简收旧衣按件回收前端代码仓库
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.

184 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. statusBarHeight: 0,
  9. currentCategory: 0,
  10. allProducts: {},
  11. // { [categoryId]: [商品数组] }
  12. allProductsPage: {},
  13. // { [categoryId]: 当前已加载页码 }
  14. allProductsTotal: {},
  15. // { [categoryId]: 总数 }
  16. pageSize: 10,
  17. loadingMore: false,
  18. finished: false
  19. };
  20. },
  21. computed: {
  22. categories() {
  23. const list = getApp().globalData.pricePreviewList || [];
  24. const extra = [{ id: "unrecyclable", title: "不可回收" }];
  25. return [...list.filter((item) => item.pid === "0").sort((a, b) => a.sort - b.sort), ...extra];
  26. },
  27. currentGoods() {
  28. var _a;
  29. const currentCategoryId = (_a = this.categories[this.currentCategory]) == null ? void 0 : _a.id;
  30. if (currentCategoryId === "unrecyclable") {
  31. return [{
  32. id: "unrecyclable-1",
  33. image: "/static/回收/衣物.png",
  34. name: "不可回收品类",
  35. price: "—",
  36. desc: "允许脏破烂,160码以上",
  37. quantity: 2,
  38. amount: ""
  39. }];
  40. }
  41. return this.allProducts[currentCategoryId] || [];
  42. }
  43. },
  44. methods: {
  45. fetchGoodsList(categoryId, page = 1, callback) {
  46. this.$api("getClassGoodsList", {
  47. classId: categoryId,
  48. pageNo: page,
  49. pageSize: this.pageSize
  50. }, (res) => {
  51. if (res.code === 200 && res.result && Array.isArray(res.result.records)) {
  52. const oldList = this.allProducts[categoryId] || [];
  53. const newList = page === 1 ? res.result.records : oldList.concat(res.result.records);
  54. this.$set(this.allProducts, categoryId, newList);
  55. this.$set(this.allProductsPage, categoryId, page);
  56. this.$set(this.allProductsTotal, categoryId, res.result.total);
  57. }
  58. if (callback)
  59. callback();
  60. });
  61. },
  62. goBack() {
  63. common_vendor.index.navigateBack();
  64. },
  65. goNext() {
  66. common_vendor.index.navigateTo({
  67. url: "/pages/manager/inspect-result"
  68. });
  69. },
  70. switchCategory(idx) {
  71. var _a;
  72. this.currentCategory = idx;
  73. this.loadingMore = false;
  74. this.finished = false;
  75. const categoryId = (_a = this.categories[idx]) == null ? void 0 : _a.id;
  76. if (categoryId === "unrecyclable") {
  77. this.$set(this.allProducts, "unrecyclable", [{
  78. id: "unrecyclable-1",
  79. image: "/static/回收/衣物.png",
  80. name: "不可回收品类",
  81. price: "—",
  82. desc: "允许脏破烂,160码以上",
  83. quantity: 2,
  84. amount: ""
  85. }]);
  86. this.$forceUpdate && this.$forceUpdate();
  87. return;
  88. }
  89. if (!this.allProducts[categoryId]) {
  90. this.fetchGoodsList(categoryId, 1);
  91. }
  92. },
  93. changeNum(item, key, delta) {
  94. if (key === "qualified") {
  95. item.qualified = Math.max(0, (item.qualified || 0) + delta);
  96. } else {
  97. item.unqualified = Math.max(0, (item.unqualified || 0) + delta);
  98. }
  99. },
  100. refreshData() {
  101. },
  102. async onRefresh() {
  103. await this.refreshData && this.refreshData();
  104. }
  105. },
  106. created() {
  107. this.currentCategory = 0;
  108. this.$nextTick(() => {
  109. var _a;
  110. if (this.categories.length > 0) {
  111. const firstCategoryId = (_a = this.categories[0]) == null ? void 0 : _a.id;
  112. if (firstCategoryId) {
  113. this.fetchGoodsList(firstCategoryId, 1);
  114. }
  115. }
  116. });
  117. },
  118. onLoad() {
  119. this.statusBarHeight = common_vendor.index.getSystemInfoSync().statusBarHeight;
  120. },
  121. onPullDownRefresh() {
  122. this.refreshData && this.refreshData();
  123. common_vendor.index.stopPullDownRefresh();
  124. }
  125. };
  126. if (!Array) {
  127. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  128. _easycom_uni_icons2();
  129. }
  130. const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  131. if (!Math) {
  132. _easycom_uni_icons();
  133. }
  134. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  135. return {
  136. a: common_vendor.p({
  137. type: "left",
  138. size: "20",
  139. color: "#222"
  140. }),
  141. b: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  142. c: common_vendor.p({
  143. type: "scan",
  144. size: "24",
  145. color: "#222"
  146. }),
  147. d: common_vendor.f($options.categories, (cat, idx, i0) => {
  148. return common_vendor.e({
  149. a: common_vendor.t(cat.title),
  150. b: cat.badge
  151. }, cat.badge ? {
  152. c: common_vendor.t(cat.badge)
  153. } : {}, {
  154. d: cat.title,
  155. e: common_vendor.n({
  156. active: idx === $data.currentCategory
  157. }),
  158. f: common_vendor.o(($event) => $options.switchCategory(idx), cat.title)
  159. });
  160. }),
  161. e: common_vendor.f($options.currentGoods, (item, idx, i0) => {
  162. return {
  163. a: item.image,
  164. b: common_vendor.t(item.name),
  165. c: common_vendor.t(item.price),
  166. d: common_vendor.t(item.desc),
  167. e: common_vendor.o(($event) => $options.changeNum(item, "qualified", -1), item.id),
  168. f: common_vendor.t(item.qualified),
  169. g: common_vendor.o(($event) => $options.changeNum(item, "qualified", 1), item.id),
  170. h: common_vendor.o(($event) => $options.changeNum(item, "unqualified", -1), item.id),
  171. i: common_vendor.t(item.unqualified),
  172. j: common_vendor.o(($event) => $options.changeNum(item, "unqualified", 1), item.id),
  173. k: item.amount,
  174. l: common_vendor.o(($event) => item.amount = $event.detail.value, item.id),
  175. m: item.id
  176. };
  177. }),
  178. f: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  179. g: common_vendor.o((...args) => $options.goNext && $options.goNext(...args))
  180. };
  181. }
  182. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-e802c881"]]);
  183. wx.createPage(MiniProgramPage);
  184. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/manager/inspect.js.map