list.js 11 KB

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