cart.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
  5. require("../../sheep/api/index.js");
  6. require("../../sheep/api/distri/score.js");
  7. require("../../sheep/request/index.js");
  8. require("../../sheep/config/index.js");
  9. require("../../sheep/store/index.js");
  10. require("../../sheep/store/app.js");
  11. require("../../sheep/api/promotion/diy.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/url/index.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/api/distri/share.js");
  39. require("../../sheep/api/distri/team.js");
  40. require("../../sheep/api/infra/file.js");
  41. require("../../sheep/api/member/address.js");
  42. require("../../sheep/api/member/point.js");
  43. require("../../sheep/api/migration/app.js");
  44. require("../../sheep/api/migration/chat.js");
  45. require("../../sheep/api/migration/index.js");
  46. require("../../sheep/api/migration/third.js");
  47. require("../../sheep/api/pay/channel.js");
  48. require("../../sheep/api/product/category.js");
  49. require("../../sheep/api/product/comment.js");
  50. require("../../sheep/api/product/favorite.js");
  51. require("../../sheep/api/product/history.js");
  52. require("../../sheep/api/product/spu.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. require("../../sheep/util/index.js");
  67. if (!Array) {
  68. const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  69. const _easycom_su_number_box2 = common_vendor.resolveComponent("su-number-box");
  70. const _easycom_s_goods_item2 = common_vendor.resolveComponent("s-goods-item");
  71. const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
  72. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  73. (_easycom_s_empty2 + _easycom_su_number_box2 + _easycom_s_goods_item2 + _easycom_su_fixed2 + _easycom_s_layout2)();
  74. }
  75. const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
  76. const _easycom_su_number_box = () => "../../sheep/ui/su-number-box/su-number-box.js";
  77. const _easycom_s_goods_item = () => "../../sheep/components/s-goods-item/s-goods-item.js";
  78. const _easycom_su_fixed = () => "../../sheep/ui/su-fixed/su-fixed.js";
  79. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  80. if (!Math) {
  81. (_easycom_s_empty + _easycom_su_number_box + _easycom_s_goods_item + _easycom_su_fixed + _easycom_s_layout)();
  82. }
  83. const _sfc_main = {
  84. __name: "cart",
  85. setup(__props) {
  86. common_vendor.useCssVars((_ctx) => ({
  87. "6cd98758": common_vendor.unref(sys_navBar)
  88. }));
  89. const sys_navBar = sheep_index.sheep.$platform.navbar;
  90. const cart = sheep_index.sheep.$store("cart");
  91. const state = common_vendor.reactive({
  92. editMode: false,
  93. list: common_vendor.computed(() => cart.list),
  94. shopList: common_vendor.computed(() => cart.shopNameMap),
  95. skuList: common_vendor.computed(() => cart.shopSkuMap),
  96. selectedList: [],
  97. selectedIds: common_vendor.computed(() => cart.selectedIds),
  98. isAllSelected: common_vendor.computed(() => cart.isAllSelected),
  99. totalPriceSelected: common_vendor.computed(() => cart.totalPriceSelected)
  100. });
  101. const processedValidList = common_vendor.computed(() => {
  102. const groups = {};
  103. state.list.forEach((item) => {
  104. const shopId = Object.keys(state.skuList).find((key) => state.skuList[key].includes(item.sku.id));
  105. const shopName = state.shopList[shopId] || "未知店铺";
  106. if (!groups[shopName]) {
  107. groups[shopName] = [];
  108. }
  109. groups[shopName].push(item);
  110. });
  111. return groups;
  112. });
  113. function onSelectSingle(id) {
  114. console.log("单选");
  115. cart.selectSingle(id);
  116. }
  117. function onSelectAll() {
  118. cart.selectAll(!state.isAllSelected);
  119. }
  120. function onConfirm() {
  121. let items = [];
  122. let goods_list = [];
  123. state.selectedList = state.list.filter((item) => state.selectedIds.includes(item.id));
  124. state.selectedList.map((item) => {
  125. items.push({
  126. skuId: item.sku.id,
  127. count: item.count,
  128. cartId: item.id
  129. });
  130. goods_list.push({
  131. // goods_id: item.goods_id,
  132. goods_id: item.spu.id,
  133. // goods_num: item.goods_num,
  134. goods_num: item.count
  135. // 商品价格id真没有
  136. // goods_sku_price_id: item.goods_sku_price_id,
  137. });
  138. });
  139. if (goods_list.length === 0) {
  140. sheep_index.sheep.$helper.toast("请选择商品");
  141. return;
  142. }
  143. sheep_index.sheep.$router.go("/pages/order/confirm", {
  144. data: JSON.stringify({
  145. // order_type: 'goods',
  146. // goods_list,
  147. items,
  148. // from: 'cart',
  149. pointStatus: false,
  150. // 从购物车这里提交订单的 一定是实体商品和用人民币买的 所以可以直接写死
  151. deliveryType: 1,
  152. spuPayType: 1,
  153. spuType: 1
  154. })
  155. });
  156. }
  157. function onNumberChange(e, cartItem) {
  158. if (e === 0) {
  159. cart.delete(cartItem.id);
  160. return;
  161. }
  162. if (cartItem.goods_num === e)
  163. return;
  164. cartItem.goods_num = e;
  165. cart.update({
  166. goods_id: cartItem.id,
  167. goods_num: e,
  168. goods_sku_price_id: cartItem.goods_sku_price_id
  169. });
  170. }
  171. async function onDelete() {
  172. cart.delete(state.selectedIds);
  173. }
  174. return (_ctx, _cache) => {
  175. var _a;
  176. return common_vendor.e({
  177. a: state.list.length === 0
  178. }, state.list.length === 0 ? {
  179. b: common_vendor.p({
  180. text: "购物车空空如也,快去逛逛吧~",
  181. icon: "/static/cart-empty.png"
  182. })
  183. } : {}, {
  184. c: state.list.length
  185. }, state.list.length ? common_vendor.e({
  186. d: common_vendor.t(state.list.length),
  187. e: state.editMode
  188. }, state.editMode ? {
  189. f: common_vendor.o(($event) => state.editMode = false)
  190. } : {
  191. g: common_vendor.o(($event) => state.editMode = true)
  192. }, {
  193. h: common_vendor.f(processedValidList.value, (shopItems, shopName, index) => {
  194. return {
  195. a: common_vendor.t(shopName),
  196. b: common_vendor.f(shopItems, (product, productIndex, i1) => {
  197. return common_vendor.e({
  198. a: state.selectedIds.includes(product.id),
  199. b: common_vendor.o(($event) => onSelectSingle(product.id), product.id),
  200. c: common_vendor.o(($event) => onSelectSingle(product.id), product.id)
  201. }, !state.editMode ? {
  202. d: common_vendor.o(($event) => onNumberChange($event, product), product.id),
  203. e: "c30a4c2b-3-" + index + "-" + i1 + "," + ("c30a4c2b-2-" + index + "-" + i1),
  204. f: common_vendor.o(($event) => product.count = $event, product.id),
  205. g: common_vendor.p({
  206. min: 0,
  207. max: product.sku.stock,
  208. step: 1,
  209. modelValue: product.count
  210. })
  211. } : {}, {
  212. h: "c30a4c2b-2-" + index + "-" + i1 + ",c30a4c2b-0",
  213. i: common_vendor.p({
  214. title: product.spu.name,
  215. img: product.spu.picUrl || product.goods.image,
  216. price: product.sku.price,
  217. skuText: product.sku.properties.length > 1 ? product.sku.properties.reduce((items2, items) => items2.valueName + " " + items.valueName) : product.sku.properties[0].valueName,
  218. priceColor: "#FF3000",
  219. titleWidth: 400
  220. }),
  221. j: product.id
  222. });
  223. }),
  224. c: shopName
  225. };
  226. }),
  227. i: !state.editMode,
  228. j: state.list.length > 0
  229. }, state.list.length > 0 ? common_vendor.e({
  230. k: state.isAllSelected,
  231. l: common_vendor.o(onSelectAll),
  232. m: common_vendor.o(onSelectAll),
  233. n: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.totalPriceSelected)),
  234. o: state.editMode
  235. }, state.editMode ? {
  236. p: common_vendor.o(onDelete)
  237. } : {
  238. q: common_vendor.t(((_a = state.selectedIds) == null ? void 0 : _a.length) ? `(${state.selectedIds.length})` : ""),
  239. r: common_vendor.o(onConfirm)
  240. }, {
  241. s: common_vendor.p({
  242. bottom: true,
  243. val: 48,
  244. placeholder: true,
  245. isInset: false
  246. })
  247. }) : {}) : {}, {
  248. t: common_vendor.s(_ctx.__cssVars()),
  249. v: common_vendor.p({
  250. title: "购物车",
  251. tabbar: "/pages/index/cart",
  252. bgStyle: {
  253. color: "#fff"
  254. }
  255. })
  256. });
  257. };
  258. }
  259. };
  260. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c30a4c2b"], ["__file", "D:/zx/mall-front-app/pages/index/cart.vue"]]);
  261. wx.createPage(MiniProgramPage);