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