cart.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. items.push({
  97. skuId: item.sku.id,
  98. count: item.count,
  99. cartId: item.id
  100. });
  101. goods_list.push({
  102. // goods_id: item.goods_id,
  103. goods_id: item.spu.id,
  104. // goods_num: item.goods_num,
  105. goods_num: item.count
  106. // 商品价格id真没有
  107. // goods_sku_price_id: item.goods_sku_price_id,
  108. });
  109. });
  110. if (goods_list.length === 0) {
  111. sheep_index.sheep.$helper.toast("请选择商品");
  112. return;
  113. }
  114. sheep_index.sheep.$router.go("/pages/order/confirm", {
  115. data: JSON.stringify({
  116. // order_type: 'goods',
  117. // goods_list,
  118. items,
  119. // from: 'cart',
  120. pointStatus: false,
  121. // 从购物车这里提交订单的 一定是实体商品和用人民币买的 所以可以直接写死
  122. deliveryType: 1,
  123. spuPayType: 1,
  124. spuType: 1
  125. })
  126. });
  127. }
  128. function onNumberChange(e, cartItem) {
  129. if (e === 0) {
  130. cart.delete(cartItem.id);
  131. return;
  132. }
  133. if (cartItem.goods_num === e)
  134. return;
  135. cartItem.goods_num = e;
  136. cart.update({
  137. goods_id: cartItem.id,
  138. goods_num: e,
  139. goods_sku_price_id: cartItem.goods_sku_price_id
  140. });
  141. }
  142. async function onDelete() {
  143. cart.delete(state.selectedIds);
  144. }
  145. return (_ctx, _cache) => {
  146. var _a;
  147. return common_vendor.e({
  148. a: state.list.length === 0
  149. }, state.list.length === 0 ? {
  150. b: common_vendor.p({
  151. text: "购物车空空如也,快去逛逛吧~",
  152. icon: "/static/cart-empty.png"
  153. })
  154. } : {}, {
  155. c: state.list.length
  156. }, state.list.length ? common_vendor.e({
  157. d: common_vendor.t(state.list.length),
  158. e: state.editMode
  159. }, state.editMode ? {
  160. f: common_vendor.o(($event) => state.editMode = false)
  161. } : {
  162. g: common_vendor.o(($event) => state.editMode = true)
  163. }, {
  164. h: common_vendor.f(processedValidList.value, (shopItems, shopName, index) => {
  165. return {
  166. a: common_vendor.t(shopName),
  167. b: common_vendor.f(shopItems, (product, productIndex, i1) => {
  168. return common_vendor.e({
  169. a: state.selectedIds.includes(product.id),
  170. b: common_vendor.o(($event) => onSelectSingle(product.id), product.id),
  171. c: common_vendor.o(($event) => onSelectSingle(product.id), product.id)
  172. }, !state.editMode ? {
  173. d: common_vendor.o(($event) => onNumberChange($event, product), product.id),
  174. e: "c30a4c2b-3-" + index + "-" + i1 + "," + ("c30a4c2b-2-" + index + "-" + i1),
  175. f: common_vendor.o(($event) => product.count = $event, product.id),
  176. g: common_vendor.p({
  177. min: 0,
  178. max: product.sku.stock,
  179. step: 1,
  180. modelValue: product.count
  181. })
  182. } : {}, {
  183. h: "c30a4c2b-2-" + index + "-" + i1 + ",c30a4c2b-0",
  184. i: common_vendor.p({
  185. title: product.spu.name,
  186. img: product.spu.picUrl || product.goods.image,
  187. price: product.sku.price,
  188. skuText: product.sku.properties.length > 1 ? product.sku.properties.reduce((items2, items) => items2.valueName + " " + items.valueName) : product.sku.properties[0].valueName,
  189. priceColor: "#FF3000",
  190. titleWidth: 400
  191. }),
  192. j: product.id
  193. });
  194. }),
  195. c: shopName
  196. };
  197. }),
  198. i: !state.editMode,
  199. j: state.list.length > 0
  200. }, state.list.length > 0 ? common_vendor.e({
  201. k: state.isAllSelected,
  202. l: common_vendor.o(onSelectAll),
  203. m: common_vendor.o(onSelectAll),
  204. n: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.totalPriceSelected)),
  205. o: state.editMode
  206. }, state.editMode ? {
  207. p: common_vendor.o(onDelete)
  208. } : {
  209. q: common_vendor.t(((_a = state.selectedIds) == null ? void 0 : _a.length) ? `(${state.selectedIds.length})` : ""),
  210. r: common_vendor.o(onConfirm)
  211. }, {
  212. s: common_vendor.p({
  213. bottom: true,
  214. val: 48,
  215. placeholder: true,
  216. isInset: false
  217. })
  218. }) : {}) : {}, {
  219. t: common_vendor.s(_ctx.__cssVars()),
  220. v: common_vendor.p({
  221. title: "购物车",
  222. tabbar: "/pages/index/cart",
  223. bgStyle: {
  224. color: "#fff"
  225. }
  226. })
  227. });
  228. };
  229. }
  230. };
  231. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c30a4c2b"], ["__file", "D:/zx/mall-front-app/pages/index/cart.vue"]]);
  232. wx.createPage(MiniProgramPage);