goods-collect.js 7.4 KB

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