goods-collect.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const sheep_api_product_favorite = require("../../sheep/api/product/favorite.js");
  5. const sheep_util_index = require("../../sheep/util/index.js");
  6. require("../../sheep/url/index.js");
  7. require("../../sheep/store/index.js");
  8. require("../../sheep/store/app.js");
  9. require("../../sheep/api/promotion/diy.js");
  10. require("../../sheep/request/index.js");
  11. require("../../sheep/config/index.js");
  12. require("../../sheep/platform/index.js");
  13. require("../../sheep/platform/provider/wechat/index.js");
  14. require("../../sheep/platform/provider/wechat/miniProgram.js");
  15. require("../../sheep/api/member/auth.js");
  16. require("../../sheep/api/member/social.js");
  17. require("../../sheep/api/member/user.js");
  18. require("../../sheep/platform/provider/apple/index.js");
  19. require("../../sheep/platform/share.js");
  20. require("../../sheep/router/index.js");
  21. require("../../sheep/hooks/useModal.js");
  22. require("../../sheep/helper/index.js");
  23. require("../../sheep/helper/test.js");
  24. require("../../sheep/helper/digit.js");
  25. require("../../sheep/helper/throttle.js");
  26. require("../../sheep/platform/pay.js");
  27. require("../../sheep/api/pay/order.js");
  28. require("../../sheep/store/user.js");
  29. require("../../sheep/store/cart.js");
  30. require("../../sheep/api/trade/cart.js");
  31. require("../../sheep/api/pay/wallet.js");
  32. require("../../sheep/api/trade/order.js");
  33. require("../../sheep/api/promotion/coupon.js");
  34. require("../../sheep/store/sys.js");
  35. require("../../sheep/store/modal.js");
  36. require("../../sheep/config/zIndex.js");
  37. if (!Array) {
  38. const _easycom_s_goods_item2 = common_vendor.resolveComponent("s-goods-item");
  39. const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
  40. const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  41. const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  42. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  43. (_easycom_s_goods_item2 + _easycom_su_fixed2 + _easycom_uni_load_more2 + _easycom_s_empty2 + _easycom_s_layout2)();
  44. }
  45. const _easycom_s_goods_item = () => "../../sheep/components/s-goods-item/s-goods-item.js";
  46. const _easycom_su_fixed = () => "../../sheep/ui/su-fixed/su-fixed.js";
  47. const _easycom_uni_load_more = () => "../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
  48. const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
  49. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  50. if (!Math) {
  51. (_easycom_s_goods_item + _easycom_su_fixed + _easycom_uni_load_more + _easycom_s_empty + _easycom_s_layout)();
  52. }
  53. const _sfc_main = {
  54. __name: "goods-collect",
  55. setup(__props) {
  56. common_vendor.useCssVars((_ctx) => ({
  57. "a2866b58": common_vendor.unref(sys_navBar)
  58. }));
  59. const sys_navBar = sheep_index.sheep.$platform.navbar;
  60. const state = common_vendor.reactive({
  61. pagination: {
  62. list: [],
  63. total: 0,
  64. pageNo: 1,
  65. pageSize: 6
  66. },
  67. loadStatus: "",
  68. editMode: false,
  69. selectedCollectList: [],
  70. // 选中的 SPU 数组
  71. selectAll: false
  72. });
  73. async function getData() {
  74. state.loadStatus = "loading";
  75. const { code, data } = await sheep_api_product_favorite.FavoriteApi.getFavoritePage({
  76. pageNo: state.pagination.pageNo,
  77. pageSize: state.pagination.pageSize
  78. });
  79. if (code !== 0) {
  80. return;
  81. }
  82. state.pagination.list = common_vendor._.concat(state.pagination.list, data.list);
  83. state.pagination.total = data.total;
  84. state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
  85. }
  86. const onSelect = (spuId) => {
  87. if (!state.selectedCollectList.includes(spuId)) {
  88. state.selectedCollectList.push(spuId);
  89. } else {
  90. state.selectedCollectList.splice(state.selectedCollectList.indexOf(spuId), 1);
  91. }
  92. state.selectAll = state.selectedCollectList.length === state.pagination.list.length;
  93. };
  94. const onSelectAll = () => {
  95. state.selectAll = !state.selectAll;
  96. if (!state.selectAll) {
  97. state.selectedCollectList = [];
  98. } else {
  99. state.selectedCollectList = state.pagination.list.map((item) => item.spuId);
  100. }
  101. };
  102. async function onCancel() {
  103. if (!state.selectedCollectList) {
  104. return;
  105. }
  106. for (const spuId of state.selectedCollectList) {
  107. await sheep_api_product_favorite.FavoriteApi.deleteFavorite(spuId);
  108. }
  109. state.editMode = false;
  110. state.selectedCollectList = [];
  111. state.selectAll = false;
  112. sheep_util_index.resetPagination(state.pagination);
  113. await getData();
  114. }
  115. function loadMore() {
  116. if (state.loadStatus === "noMore") {
  117. return;
  118. }
  119. state.pagination.pageNo++;
  120. getData();
  121. }
  122. common_vendor.onReachBottom(() => {
  123. loadMore();
  124. });
  125. common_vendor.onLoad(() => {
  126. getData();
  127. });
  128. return (_ctx, _cache) => {
  129. return common_vendor.e({
  130. a: common_vendor.t(state.pagination.total),
  131. b: state.editMode && state.pagination.total
  132. }, state.editMode && state.pagination.total ? {
  133. c: common_vendor.o(($event) => state.editMode = false)
  134. } : {}, {
  135. d: !state.editMode && state.pagination.total
  136. }, !state.editMode && state.pagination.total ? {
  137. e: common_vendor.o(($event) => state.editMode = true)
  138. } : {}, {
  139. f: common_vendor.f(state.pagination.list, (item, k0, i0) => {
  140. return common_vendor.e(state.editMode ? {
  141. a: state.selectedCollectList.includes(item.spuId),
  142. b: common_vendor.o(($event) => onSelect(item.spuId), item.id),
  143. c: common_vendor.o(($event) => onSelect(item.spuId), item.id)
  144. } : {}, {
  145. d: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  146. id: item.spuId
  147. }), item.id),
  148. e: "28ee79e9-1-" + i0 + ",28ee79e9-0",
  149. f: common_vendor.p({
  150. title: item.spuName,
  151. img: item.picUrl,
  152. price: item.price,
  153. priceColor: "#FF3000",
  154. titleWidth: 400
  155. }),
  156. g: item.id
  157. });
  158. }),
  159. g: state.editMode,
  160. h: state.selectAll,
  161. i: common_vendor.o(onSelectAll),
  162. j: common_vendor.o(onSelectAll),
  163. k: common_vendor.o(onCancel),
  164. l: state.editMode,
  165. m: common_vendor.p({
  166. bottom: true,
  167. val: 0,
  168. placeholder: true
  169. }),
  170. n: state.pagination.total > 0
  171. }, state.pagination.total > 0 ? {
  172. o: common_vendor.o(loadMore),
  173. p: common_vendor.p({
  174. status: state.loadStatus,
  175. ["content-text"]: {
  176. contentdown: "上拉加载更多"
  177. }
  178. })
  179. } : {}, {
  180. q: state.pagination.total === 0
  181. }, state.pagination.total === 0 ? {
  182. r: common_vendor.p({
  183. text: "暂无收藏",
  184. icon: "/static/collect-empty.png"
  185. })
  186. } : {}, {
  187. s: common_vendor.s(_ctx.__cssVars()),
  188. t: common_vendor.p({
  189. title: "商品收藏"
  190. })
  191. });
  192. };
  193. }
  194. };
  195. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-28ee79e9"], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/pages/user/goods-collect.vue"]]);
  196. wx.createPage(MiniProgramPage);