category.js 8.2 KB

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