category.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const sheep_api_product_category = require("../../sheep/api/product/category.js");
  5. const sheep_api_product_spu = require("../../sheep/api/product/spu.js");
  6. const sheep_util_index = require("../../sheep/util/index.js");
  7. require("../../sheep/url/index.js");
  8. require("../../sheep/store/index.js");
  9. require("../../sheep/store/app.js");
  10. require("../../sheep/api/promotion/diy.js");
  11. require("../../sheep/request/index.js");
  12. require("../../sheep/config/index.js");
  13. require("../../sheep/platform/index.js");
  14. require("../../sheep/platform/provider/wechat/index.js");
  15. require("../../sheep/platform/provider/wechat/miniProgram.js");
  16. require("../../sheep/api/member/auth.js");
  17. require("../../sheep/api/member/social.js");
  18. require("../../sheep/api/member/user.js");
  19. require("../../sheep/platform/provider/apple/index.js");
  20. require("../../sheep/platform/share.js");
  21. require("../../sheep/router/index.js");
  22. require("../../sheep/hooks/useModal.js");
  23. require("../../sheep/helper/index.js");
  24. require("../../sheep/helper/test.js");
  25. require("../../sheep/helper/digit.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_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  40. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  41. (_easycom_uni_load_more2 + _easycom_s_layout2)();
  42. }
  43. const _easycom_uni_load_more = () => "../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
  44. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  45. if (!Math) {
  46. (firstOne + firstTwo + secondOne + _easycom_uni_load_more + _easycom_s_layout)();
  47. }
  48. const secondOne = () => "./components/second-one.js";
  49. const firstOne = () => "./components/first-one.js";
  50. const firstTwo = () => "./components/first-two.js";
  51. const _sfc_main = {
  52. __name: "category",
  53. setup(__props) {
  54. const state = common_vendor.reactive({
  55. style: "second_one",
  56. // first_one(一级 - 样式一), first_two(二级 - 样式二), second_one(二级)
  57. categoryList: [],
  58. // 商品分类树
  59. activeMenu: 0,
  60. // 选中的一级菜单,在 categoryList 的下标
  61. pagination: {
  62. // 商品分页
  63. list: [],
  64. // 商品列表
  65. total: [],
  66. // 商品总数
  67. pageNo: 1,
  68. pageSize: 6
  69. },
  70. loadStatus: ""
  71. });
  72. const {
  73. safeArea
  74. } = sheep_index.sheep.$platform.device;
  75. const pageHeight = common_vendor.computed(() => safeArea.height - 44 - 50);
  76. async function getList() {
  77. const {
  78. code,
  79. data
  80. } = await sheep_api_product_category.CategoryApi.getCategoryList();
  81. if (code !== 0) {
  82. return;
  83. }
  84. state.categoryList = sheep_util_index.handleTree(data);
  85. }
  86. const onMenu = (val) => {
  87. state.activeMenu = val;
  88. if (state.style === "first_one" || state.style === "first_two") {
  89. state.pagination.pageNo = 1;
  90. state.pagination.list = [];
  91. state.pagination.total = 0;
  92. getGoodsList();
  93. }
  94. };
  95. async function getGoodsList() {
  96. state.loadStatus = "loading";
  97. const res = await sheep_api_product_spu.SpuApi.getSpuPage({
  98. categoryId: state.categoryList[state.activeMenu].id,
  99. pageNo: state.pagination.pageNo,
  100. pageSize: state.pagination.pageSize
  101. });
  102. if (res.code !== 0) {
  103. return;
  104. }
  105. state.pagination.list = common_vendor._.concat(state.pagination.list, res.data.list);
  106. state.pagination.total = res.data.total;
  107. state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
  108. }
  109. function loadMore() {
  110. if (state.loadStatus === "noMore") {
  111. return;
  112. }
  113. state.pagination.pageNo++;
  114. getGoodsList();
  115. }
  116. common_vendor.onLoad(async () => {
  117. await getList();
  118. if (state.style === "first_one" || state.style === "first_two") {
  119. onMenu(0);
  120. }
  121. });
  122. common_vendor.onReachBottom(() => {
  123. loadMore();
  124. });
  125. return (_ctx, _cache) => {
  126. var _a, _b;
  127. return common_vendor.e({
  128. a: common_vendor.f(state.categoryList, (item, index, i0) => {
  129. return {
  130. a: common_vendor.t(item.name),
  131. b: item.id,
  132. c: common_vendor.n({
  133. "menu-item-active": index === state.activeMenu
  134. }),
  135. d: common_vendor.o(($event) => onMenu(index), item.id)
  136. };
  137. }),
  138. b: common_vendor.s({
  139. height: common_vendor.unref(pageHeight) + "px"
  140. }),
  141. c: (_a = state.categoryList) == null ? void 0 : _a.length
  142. }, ((_b = state.categoryList) == null ? void 0 : _b.length) ? common_vendor.e({
  143. d: state.categoryList[state.activeMenu].picUrl
  144. }, state.categoryList[state.activeMenu].picUrl ? {
  145. e: common_vendor.unref(sheep_index.sheep).$url.cdn(state.categoryList[state.activeMenu].picUrl)
  146. } : {}, {
  147. f: state.style === "first_one"
  148. }, state.style === "first_one" ? {
  149. g: common_vendor.p({
  150. pagination: state.pagination
  151. })
  152. } : {}, {
  153. h: state.style === "first_two"
  154. }, state.style === "first_two" ? {
  155. i: common_vendor.p({
  156. pagination: state.pagination
  157. })
  158. } : {}, {
  159. j: state.style === "second_one"
  160. }, state.style === "second_one" ? {
  161. k: common_vendor.p({
  162. data: state.categoryList,
  163. activeMenu: state.activeMenu
  164. })
  165. } : {}, {
  166. l: (state.style === "first_one" || state.style === "first_two") && state.pagination.total > 0
  167. }, (state.style === "first_one" || state.style === "first_two") && state.pagination.total > 0 ? {
  168. m: common_vendor.o(loadMore),
  169. n: common_vendor.p({
  170. status: state.loadStatus,
  171. ["content-text"]: {
  172. contentdown: "点击查看更多"
  173. }
  174. })
  175. } : {}, {
  176. o: common_vendor.s({
  177. height: common_vendor.unref(pageHeight) + "px"
  178. })
  179. }) : {}, {
  180. p: common_vendor.s({
  181. height: common_vendor.unref(pageHeight) + "px"
  182. }),
  183. q: common_vendor.p({
  184. title: "分类",
  185. tabbar: "/pages/index/category",
  186. bgStyle: {
  187. color: "#fff"
  188. }
  189. })
  190. });
  191. };
  192. }
  193. };
  194. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1031f1cf"], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/pages/index/category.vue"]]);
  195. wx.createPage(MiniProgramPage);