list.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const sheep_util_index = require("../../sheep/util/index.js");
  5. const sheep_api_product_spu = require("../../sheep/api/product/spu.js");
  6. require("../../sheep/api/index.js");
  7. require("../../sheep/api/distri/score.js");
  8. require("../../sheep/request/index.js");
  9. require("../../sheep/config/index.js");
  10. require("../../sheep/store/index.js");
  11. require("../../sheep/store/app.js");
  12. require("../../sheep/api/promotion/diy.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/url/index.js");
  29. require("../../sheep/platform/pay.js");
  30. require("../../sheep/api/pay/order.js");
  31. require("../../sheep/store/user.js");
  32. require("../../sheep/store/cart.js");
  33. require("../../sheep/api/trade/cart.js");
  34. require("../../sheep/api/pay/wallet.js");
  35. require("../../sheep/api/trade/order.js");
  36. require("../../sheep/api/promotion/coupon.js");
  37. require("../../sheep/store/sys.js");
  38. require("../../sheep/store/modal.js");
  39. require("../../sheep/api/distri/share.js");
  40. require("../../sheep/api/distri/team.js");
  41. require("../../sheep/api/infra/file.js");
  42. require("../../sheep/api/member/address.js");
  43. require("../../sheep/api/member/point.js");
  44. require("../../sheep/api/migration/app.js");
  45. require("../../sheep/api/migration/chat.js");
  46. require("../../sheep/api/migration/index.js");
  47. require("../../sheep/api/migration/third.js");
  48. require("../../sheep/api/pay/channel.js");
  49. require("../../sheep/api/product/category.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_su_tabs2 = common_vendor.resolveComponent("su-tabs");
  68. const _easycom_su_sticky2 = common_vendor.resolveComponent("su-sticky");
  69. const _easycom_su_popup2 = common_vendor.resolveComponent("su-popup");
  70. const _easycom_s_goods_column2 = common_vendor.resolveComponent("s-goods-column");
  71. const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  72. const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  73. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  74. (_easycom_su_tabs2 + _easycom_su_sticky2 + _easycom_su_popup2 + _easycom_s_goods_column2 + _easycom_uni_load_more2 + _easycom_s_empty2 + _easycom_s_layout2)();
  75. }
  76. const _easycom_su_tabs = () => "../../sheep/ui/su-tabs/su-tabs.js";
  77. const _easycom_su_sticky = () => "../../sheep/ui/su-sticky/su-sticky.js";
  78. const _easycom_su_popup = () => "../../sheep/ui/su-popup/su-popup.js";
  79. const _easycom_s_goods_column = () => "../../sheep/components/s-goods-column/s-goods-column.js";
  80. const _easycom_uni_load_more = () => "../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
  81. const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
  82. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  83. if (!Math) {
  84. (_easycom_su_tabs + _easycom_su_sticky + _easycom_su_popup + _easycom_s_goods_column + _easycom_uni_load_more + _easycom_s_empty + _easycom_s_layout)();
  85. }
  86. const _sfc_main = {
  87. __name: "list",
  88. emits: ["close", "change"],
  89. setup(__props, { emit: __emit }) {
  90. const sys_navBar = sheep_index.sheep.$platform.navbar;
  91. const state = common_vendor.reactive({
  92. pagination: {
  93. list: [],
  94. total: 0,
  95. pageNo: 1,
  96. pageSize: 6
  97. },
  98. currentSort: void 0,
  99. currentOrder: void 0,
  100. currentTab: 0,
  101. // 当前选中的 tab
  102. curFilter: 0,
  103. // 当前选中的 list 筛选项
  104. showFilter: false,
  105. iconStatus: false,
  106. // true - 单列布局;false - 双列布局
  107. keyword: "",
  108. categoryId: 0,
  109. tabList: [
  110. {
  111. name: "综合推荐",
  112. list: [
  113. {
  114. label: "综合推荐"
  115. },
  116. {
  117. label: "价格升序",
  118. sort: "price",
  119. order: true
  120. },
  121. {
  122. label: "价格降序",
  123. sort: "price",
  124. order: false
  125. }
  126. ]
  127. },
  128. {
  129. name: "销量",
  130. sort: "salesCount",
  131. order: false
  132. },
  133. {
  134. name: "新品优先",
  135. value: "createTime",
  136. order: false
  137. }
  138. ],
  139. loadStatus: "",
  140. leftGoodsList: [],
  141. // 双列布局 - 左侧商品
  142. rightGoodsList: []
  143. // 双列布局 - 右侧商品
  144. });
  145. let count = 0;
  146. let leftHeight = 0;
  147. let rightHeight = 0;
  148. function mountMasonry(height = 0, where = "left") {
  149. if (!state.pagination.list[count]) {
  150. return;
  151. }
  152. if (where === "left") {
  153. leftHeight += height;
  154. } else {
  155. rightHeight += height;
  156. }
  157. if (leftHeight <= rightHeight) {
  158. state.leftGoodsList.push(state.pagination.list[count]);
  159. } else {
  160. state.rightGoodsList.push(state.pagination.list[count]);
  161. }
  162. count++;
  163. }
  164. function emptyList() {
  165. sheep_util_index.resetPagination(state.pagination);
  166. state.leftGoodsList = [];
  167. state.rightGoodsList = [];
  168. count = 0;
  169. leftHeight = 0;
  170. rightHeight = 0;
  171. }
  172. function onSearch(e) {
  173. state.keyword = e;
  174. emptyList();
  175. getList(state.currentSort, state.currentOrder);
  176. }
  177. function onTabsChange(e) {
  178. if (state.tabList[e.index].list) {
  179. state.currentTab = e.index;
  180. state.showFilter = !state.showFilter;
  181. return;
  182. }
  183. state.showFilter = false;
  184. if (e.index === state.currentTab) {
  185. return;
  186. }
  187. state.currentTab = e.index;
  188. state.currentSort = e.sort;
  189. state.currentOrder = e.order;
  190. emptyList();
  191. getList(e.sort, e.order);
  192. }
  193. const onFilterItem = (val) => {
  194. if (state.currentSort === state.tabList[0].list[val].sort && state.currentOrder === state.tabList[0].list[val].order) {
  195. state.showFilter = false;
  196. return;
  197. }
  198. state.showFilter = false;
  199. state.curFilter = val;
  200. state.tabList[0].name = state.tabList[0].list[val].label;
  201. state.currentSort = state.tabList[0].list[val].sort;
  202. state.currentOrder = state.tabList[0].list[val].order;
  203. emptyList();
  204. getList();
  205. };
  206. async function getList() {
  207. state.loadStatus = "loading";
  208. const { code, data } = await sheep_api_product_spu.SpuApi.getSpuPage({
  209. pageNo: state.pagination.pageNo,
  210. pageSize: state.pagination.pageSize,
  211. sortField: state.currentSort,
  212. sortAsc: state.currentOrder,
  213. categoryId: state.categoryId,
  214. keyword: state.keyword
  215. });
  216. if (code !== 0) {
  217. return;
  218. }
  219. state.pagination.list = common_vendor._.concat(state.pagination.list, data.list);
  220. state.pagination.total = data.total;
  221. state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
  222. mountMasonry();
  223. }
  224. function loadMore() {
  225. if (state.loadStatus === "noMore") {
  226. return;
  227. }
  228. state.pagination.pageNo++;
  229. getList(state.currentSort, state.currentOrder);
  230. }
  231. common_vendor.onLoad((options) => {
  232. state.categoryId = options.categoryId;
  233. state.keyword = options.keyword;
  234. getList(state.currentSort, state.currentOrder);
  235. });
  236. common_vendor.onReachBottom(() => {
  237. loadMore();
  238. });
  239. return (_ctx, _cache) => {
  240. return common_vendor.e({
  241. a: common_vendor.o(onTabsChange),
  242. b: common_vendor.p({
  243. list: state.tabList,
  244. scrollable: false,
  245. current: state.currentTab
  246. }),
  247. c: state.iconStatus
  248. }, state.iconStatus ? {} : {}, {
  249. d: common_vendor.o(($event) => state.iconStatus = !state.iconStatus),
  250. e: common_vendor.p({
  251. bgColor: "#fff"
  252. }),
  253. f: common_vendor.f(state.tabList[state.currentTab].list, (item, index, i0) => {
  254. return {
  255. a: common_vendor.t(item.label),
  256. b: item.value,
  257. c: common_vendor.n({
  258. "filter-item-active": index === state.curFilter
  259. }),
  260. d: common_vendor.o(($event) => onFilterItem(index), item.value)
  261. };
  262. }),
  263. g: common_vendor.o(($event) => state.showFilter = false),
  264. h: common_vendor.p({
  265. show: state.showFilter,
  266. type: "top",
  267. round: "10",
  268. space: common_vendor.unref(sys_navBar) + 38,
  269. backgroundColor: "#F6F6F6",
  270. zIndex: 10
  271. }),
  272. i: state.iconStatus && state.pagination.total > 0
  273. }, state.iconStatus && state.pagination.total > 0 ? {
  274. j: common_vendor.f(state.pagination.list, (item, k0, i0) => {
  275. return {
  276. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  277. id: item.id
  278. }), item.id),
  279. b: "7f2f18c6-4-" + i0 + ",7f2f18c6-0",
  280. c: common_vendor.p({
  281. size: "lg",
  282. data: item,
  283. topRadius: 10,
  284. bottomRadius: 10
  285. }),
  286. d: item.id
  287. };
  288. })
  289. } : {}, {
  290. k: !state.iconStatus && state.pagination.total > 0
  291. }, !state.iconStatus && state.pagination.total > 0 ? {
  292. l: common_vendor.f(state.leftGoodsList, (item, k0, i0) => {
  293. return {
  294. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  295. id: item.id
  296. }), item.id),
  297. b: common_vendor.o(($event) => mountMasonry($event, "left"), item.id),
  298. c: "7f2f18c6-5-" + i0 + ",7f2f18c6-0",
  299. d: common_vendor.p({
  300. size: "md",
  301. data: item,
  302. topRadius: 10,
  303. bottomRadius: 10
  304. }),
  305. e: item.id
  306. };
  307. }),
  308. m: common_vendor.f(state.rightGoodsList, (item, k0, i0) => {
  309. return {
  310. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  311. id: item.id
  312. }), item.id),
  313. b: common_vendor.o(($event) => mountMasonry($event, "right"), item.id),
  314. c: "7f2f18c6-6-" + i0 + ",7f2f18c6-0",
  315. d: common_vendor.p({
  316. size: "md",
  317. topRadius: 10,
  318. bottomRadius: 10,
  319. data: item
  320. }),
  321. e: item.id
  322. };
  323. })
  324. } : {}, {
  325. n: state.pagination.total > 0
  326. }, state.pagination.total > 0 ? {
  327. o: common_vendor.o(loadMore),
  328. p: common_vendor.p({
  329. status: state.loadStatus,
  330. ["content-text"]: {
  331. contentdown: "上拉加载更多"
  332. }
  333. })
  334. } : {}, {
  335. q: state.pagination.total === 0
  336. }, state.pagination.total === 0 ? {
  337. r: common_vendor.p({
  338. icon: "/static/soldout-empty.png",
  339. text: "暂无商品"
  340. })
  341. } : {}, {
  342. s: common_vendor.o(onSearch),
  343. t: common_vendor.p({
  344. navbar: "normal",
  345. leftWidth: 0,
  346. rightWidth: 0,
  347. tools: "search",
  348. defaultSearch: state.keyword
  349. })
  350. });
  351. };
  352. }
  353. };
  354. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-7f2f18c6"], ["__file", "D:/zx/mall-front-app/pages/goods/list.vue"]]);
  355. wx.createPage(MiniProgramPage);