list.js 11 KB

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