cart.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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/url/index.js");
  6. require("../../sheep/store/index.js");
  7. require("../../sheep/store/app.js");
  8. require("../../sheep/api/promotion/diy.js");
  9. require("../../sheep/request/index.js");
  10. require("../../sheep/config/index.js");
  11. require("../../sheep/platform/index.js");
  12. require("../../sheep/platform/provider/wechat/index.js");
  13. require("../../sheep/platform/provider/wechat/miniProgram.js");
  14. require("../../sheep/api/member/auth.js");
  15. require("../../sheep/api/member/social.js");
  16. require("../../sheep/api/member/user.js");
  17. require("../../sheep/platform/provider/apple/index.js");
  18. require("../../sheep/platform/share.js");
  19. require("../../sheep/router/index.js");
  20. require("../../sheep/hooks/useModal.js");
  21. require("../../sheep/helper/index.js");
  22. require("../../sheep/helper/test.js");
  23. require("../../sheep/helper/digit.js");
  24. require("../../sheep/api/member/signin.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. require("../../sheep/util/index.js");
  38. if (!Array) {
  39. const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  40. const _easycom_su_number_box2 = common_vendor.resolveComponent("su-number-box");
  41. const _easycom_s_goods_item2 = common_vendor.resolveComponent("s-goods-item");
  42. const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
  43. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  44. (_easycom_s_empty2 + _easycom_su_number_box2 + _easycom_s_goods_item2 + _easycom_su_fixed2 + _easycom_s_layout2)();
  45. }
  46. const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
  47. const _easycom_su_number_box = () => "../../sheep/ui/su-number-box/su-number-box.js";
  48. const _easycom_s_goods_item = () => "../../sheep/components/s-goods-item/s-goods-item.js";
  49. const _easycom_su_fixed = () => "../../sheep/ui/su-fixed/su-fixed.js";
  50. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  51. if (!Math) {
  52. (_easycom_s_empty + _easycom_su_number_box + _easycom_s_goods_item + _easycom_su_fixed + _easycom_s_layout)();
  53. }
  54. const _sfc_main = {
  55. __name: "cart",
  56. setup(__props) {
  57. common_vendor.useCssVars((_ctx) => ({
  58. "6cd98758": common_vendor.unref(sys_navBar)
  59. }));
  60. const sys_navBar = sheep_index.sheep.$platform.navbar;
  61. const cart = sheep_index.sheep.$store("cart");
  62. const state = common_vendor.reactive({
  63. editMode: false,
  64. list: common_vendor.computed(() => cart.list),
  65. shopList: common_vendor.computed(() => cart.shopNameMap),
  66. skuList: common_vendor.computed(() => cart.shopSkuMap),
  67. selectedList: [],
  68. selectedIds: common_vendor.computed(() => cart.selectedIds),
  69. isAllSelected: common_vendor.computed(() => cart.isAllSelected),
  70. totalPriceSelected: common_vendor.computed(() => cart.totalPriceSelected)
  71. });
  72. const processedValidList = common_vendor.computed(() => {
  73. const groups = {};
  74. state.list.forEach((item) => {
  75. const shopId = Object.keys(state.skuList).find((key) => state.skuList[key].includes(item.sku.id));
  76. const shopName = state.shopList[shopId] || "未知店铺";
  77. if (!groups[shopName]) {
  78. groups[shopName] = [];
  79. }
  80. groups[shopName].push(item);
  81. });
  82. return groups;
  83. });
  84. function onSelectSingle(id) {
  85. console.log("单选");
  86. cart.selectSingle(id);
  87. }
  88. function onSelectAll() {
  89. cart.selectAll(!state.isAllSelected);
  90. }
  91. function onConfirm() {
  92. let items = [];
  93. let goods_list = [];
  94. state.selectedList = state.list.filter((item) => state.selectedIds.includes(item.id));
  95. state.selectedList.map((item) => {
  96. console.log(item, "便利");
  97. items.push({
  98. skuId: item.sku.id,
  99. count: item.count,
  100. cartId: item.id
  101. });
  102. goods_list.push({
  103. // goods_id: item.goods_id,
  104. goods_id: item.spu.id,
  105. // goods_num: item.goods_num,
  106. goods_num: item.count
  107. // 商品价格id真没有
  108. // goods_sku_price_id: item.goods_sku_price_id,
  109. });
  110. });
  111. if (goods_list.length === 0) {
  112. sheep_index.sheep.$helper.toast("请选择商品");
  113. return;
  114. }
  115. sheep_index.sheep.$router.go("/pages/order/confirm", {
  116. data: JSON.stringify({
  117. // order_type: 'goods',
  118. // goods_list,
  119. items,
  120. // from: 'cart',
  121. deliveryType: 1,
  122. pointStatus: false
  123. })
  124. });
  125. }
  126. function onNumberChange(e, cartItem) {
  127. if (e === 0) {
  128. cart.delete(cartItem.id);
  129. return;
  130. }
  131. if (cartItem.goods_num === e)
  132. return;
  133. cartItem.goods_num = e;
  134. cart.update({
  135. goods_id: cartItem.id,
  136. goods_num: e,
  137. goods_sku_price_id: cartItem.goods_sku_price_id
  138. });
  139. }
  140. async function onDelete() {
  141. cart.delete(state.selectedIds);
  142. }
  143. return (_ctx, _cache) => {
  144. var _a;
  145. return common_vendor.e({
  146. a: state.list.length === 0
  147. }, state.list.length === 0 ? {
  148. b: common_vendor.p({
  149. text: "购物车空空如也,快去逛逛吧~",
  150. icon: "/static/cart-empty.png"
  151. })
  152. } : {}, {
  153. c: state.list.length
  154. }, state.list.length ? common_vendor.e({
  155. d: common_vendor.t(state.list.length),
  156. e: state.editMode
  157. }, state.editMode ? {
  158. f: common_vendor.o(($event) => state.editMode = false)
  159. } : {
  160. g: common_vendor.o(($event) => state.editMode = true)
  161. }, {
  162. h: common_vendor.f(processedValidList.value, (shopItems, shopName, index) => {
  163. return {
  164. a: common_vendor.t(shopName),
  165. b: common_vendor.f(shopItems, (product, productIndex, i1) => {
  166. return common_vendor.e({
  167. a: state.selectedIds.includes(product.id),
  168. b: common_vendor.o(($event) => onSelectSingle(product.id), product.id),
  169. c: common_vendor.o(($event) => onSelectSingle(product.id), product.id)
  170. }, !state.editMode ? {
  171. d: common_vendor.o(($event) => onNumberChange($event, product), product.id),
  172. e: "c30a4c2b-3-" + index + "-" + i1 + "," + ("c30a4c2b-2-" + index + "-" + i1),
  173. f: common_vendor.o(($event) => product.count = $event, product.id),
  174. g: common_vendor.p({
  175. min: 0,
  176. max: product.sku.stock,
  177. step: 1,
  178. modelValue: product.count
  179. })
  180. } : {}, {
  181. h: "c30a4c2b-2-" + index + "-" + i1 + ",c30a4c2b-0",
  182. i: common_vendor.p({
  183. title: product.spu.name,
  184. img: product.spu.picUrl || product.goods.image,
  185. price: product.sku.price,
  186. skuText: product.sku.properties.length > 1 ? product.sku.properties.reduce((items2, items) => items2.valueName + " " + items.valueName) : product.sku.properties[0].valueName,
  187. priceColor: "#FF3000",
  188. titleWidth: 400
  189. }),
  190. j: product.id
  191. });
  192. }),
  193. c: shopName
  194. };
  195. }),
  196. i: !state.editMode,
  197. j: state.list.length > 0
  198. }, state.list.length > 0 ? common_vendor.e({
  199. k: state.isAllSelected,
  200. l: common_vendor.o(onSelectAll),
  201. m: common_vendor.o(onSelectAll),
  202. n: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.totalPriceSelected)),
  203. o: state.editMode
  204. }, state.editMode ? {
  205. p: common_vendor.o(onDelete)
  206. } : {
  207. q: common_vendor.t(((_a = state.selectedIds) == null ? void 0 : _a.length) ? `(${state.selectedIds.length})` : ""),
  208. r: common_vendor.o(onConfirm)
  209. }, {
  210. s: common_vendor.p({
  211. bottom: true,
  212. val: 48,
  213. placeholder: true,
  214. isInset: false
  215. })
  216. }) : {}) : {}, {
  217. t: common_vendor.s(_ctx.__cssVars()),
  218. v: common_vendor.p({
  219. title: "购物车",
  220. tabbar: "/pages/index/cart",
  221. bgStyle: {
  222. color: "#fff"
  223. }
  224. })
  225. });
  226. };
  227. }
  228. };
  229. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c30a4c2b"], ["__file", "D:/zx/mall-front-app/pages/index/cart.vue"]]);
  230. wx.createPage(MiniProgramPage);