s-select-groupon-sku.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const sheep_index = require("../../index.js");
  4. const sheep_hooks_useGoods = require("../../hooks/useGoods.js");
  5. require("../../api/index.js");
  6. require("../../api/distri/score.js");
  7. require("../../request/index.js");
  8. require("../../config/index.js");
  9. require("../../store/index.js");
  10. require("../../store/app.js");
  11. require("../../api/promotion/diy.js");
  12. require("../../platform/index.js");
  13. require("../../platform/provider/wechat/index.js");
  14. require("../../platform/provider/wechat/miniProgram.js");
  15. require("../../api/member/auth.js");
  16. require("../../api/member/social.js");
  17. require("../../api/member/user.js");
  18. require("../../platform/provider/apple/index.js");
  19. require("../../platform/share.js");
  20. require("../../router/index.js");
  21. require("../../hooks/useModal.js");
  22. require("../../helper/index.js");
  23. require("../../helper/test.js");
  24. require("../../helper/digit.js");
  25. require("../../api/member/signin.js");
  26. require("../../helper/throttle.js");
  27. require("../../url/index.js");
  28. require("../../platform/pay.js");
  29. require("../../api/pay/order.js");
  30. require("../../store/user.js");
  31. require("../../store/cart.js");
  32. require("../../api/trade/cart.js");
  33. require("../../api/pay/wallet.js");
  34. require("../../api/trade/order.js");
  35. require("../../api/promotion/coupon.js");
  36. require("../../store/sys.js");
  37. require("../../store/modal.js");
  38. require("../../api/distri/share.js");
  39. require("../../api/distri/team.js");
  40. require("../../api/infra/file.js");
  41. require("../../api/member/address.js");
  42. require("../../api/member/point.js");
  43. require("../../api/migration/app.js");
  44. require("../../api/migration/chat.js");
  45. require("../../api/migration/index.js");
  46. require("../../api/migration/third.js");
  47. require("../../api/pay/channel.js");
  48. require("../../api/product/category.js");
  49. require("../../api/product/comment.js");
  50. require("../../api/product/favorite.js");
  51. require("../../api/product/history.js");
  52. require("../../api/product/spu.js");
  53. require("../../api/promotion/activity.js");
  54. require("../../api/promotion/article.js");
  55. require("../../api/promotion/bargain.js");
  56. require("../../api/promotion/combination.js");
  57. require("../../api/promotion/rewardActivity.js");
  58. require("../../api/promotion/seckill.js");
  59. require("../../api/system/area.js");
  60. require("../../api/system/voice.js");
  61. require("../../api/trade/afterSale.js");
  62. require("../../api/trade/brokerage.js");
  63. require("../../api/trade/config.js");
  64. require("../../api/trade/delivery.js");
  65. require("../../config/zIndex.js");
  66. require("../../util/index.js");
  67. if (!Array) {
  68. const _easycom_su_number_box2 = common_vendor.resolveComponent("su-number-box");
  69. const _easycom_su_popup2 = common_vendor.resolveComponent("su-popup");
  70. (_easycom_su_number_box2 + _easycom_su_popup2)();
  71. }
  72. const _easycom_su_number_box = () => "../../ui/su-number-box/su-number-box.js";
  73. const _easycom_su_popup = () => "../../ui/su-popup/su-popup.js";
  74. if (!Math) {
  75. (_easycom_su_number_box + _easycom_su_popup)();
  76. }
  77. const _sfc_main = {
  78. __name: "s-select-groupon-sku",
  79. props: {
  80. show: {
  81. type: Boolean,
  82. default: false
  83. },
  84. goodsInfo: {
  85. type: Object,
  86. default() {
  87. }
  88. },
  89. grouponAction: {
  90. type: String,
  91. default: "create"
  92. },
  93. grouponNum: {
  94. type: [Number, String],
  95. default: 0
  96. }
  97. },
  98. emits: ["change", "addCart", "buy", "close", "ladder"],
  99. setup(__props, { emit: __emit }) {
  100. common_vendor.useCssVars((_ctx) => ({
  101. "478364b0": common_vendor.unref(headerBg)
  102. }));
  103. const headerBg = sheep_index.sheep.$url.css("/static/images/groupon-btn-long.png");
  104. const emits = __emit;
  105. const props = __props;
  106. const state = common_vendor.reactive({
  107. selectedSku: {},
  108. // 选中的 SKU
  109. currentPropertyArray: [],
  110. // 当前选中的属性,实际是个 Map。key 是 property 编号,value 是 value 编号
  111. grouponNum: props.grouponNum
  112. });
  113. const propertyList = sheep_hooks_useGoods.convertProductPropertyList(props.goodsInfo.skus);
  114. const skuList = common_vendor.computed(() => {
  115. let skuPrices = props.goodsInfo.skus;
  116. for (let price of skuPrices) {
  117. price.value_id_array = price.properties.map((item) => item.valueId);
  118. }
  119. return skuPrices;
  120. });
  121. common_vendor.watch(
  122. () => state.selectedSku,
  123. (newVal) => {
  124. emits("change", newVal);
  125. },
  126. {
  127. immediate: true,
  128. // 立即执行
  129. deep: true
  130. // 深度监听
  131. }
  132. );
  133. function onNumberChange(e) {
  134. if (e === 0)
  135. return;
  136. if (state.selectedSku.count === e)
  137. return;
  138. state.selectedSku.count = e;
  139. }
  140. function onBuy() {
  141. if (!state.selectedSku.id || state.selectedSku.id <= 0) {
  142. sheep_index.sheep.$helper.toast("请选择规格");
  143. return;
  144. }
  145. if (state.selectedSku.stock <= 0) {
  146. sheep_index.sheep.$helper.toast("库存不足");
  147. return;
  148. }
  149. emits("buy", state.selectedSku);
  150. }
  151. function changeDisabled(isChecked = false, propertyId = 0, valueId = 0) {
  152. let newSkus = [];
  153. if (isChecked) {
  154. for (let price of skuList.value) {
  155. if (price.stock <= 0) {
  156. continue;
  157. }
  158. if (price.value_id_array.indexOf(valueId) >= 0) {
  159. newSkus.push(price);
  160. }
  161. }
  162. } else {
  163. newSkus = getCanUseSkuList();
  164. }
  165. let noChooseValueIds = [];
  166. for (let price of newSkus) {
  167. noChooseValueIds = noChooseValueIds.concat(price.value_id_array);
  168. }
  169. noChooseValueIds = Array.from(new Set(noChooseValueIds));
  170. if (isChecked) {
  171. let index = noChooseValueIds.indexOf(valueId);
  172. noChooseValueIds.splice(index, 1);
  173. } else {
  174. state.currentPropertyArray.forEach((currentPropertyId) => {
  175. if (currentPropertyId.toString() !== "") {
  176. return;
  177. }
  178. let index = noChooseValueIds.indexOf(currentPropertyId);
  179. if (index >= 0) {
  180. noChooseValueIds.splice(index, 1);
  181. }
  182. });
  183. }
  184. let choosePropertyIds = [];
  185. if (!isChecked) {
  186. state.currentPropertyArray.forEach((currentPropertyId, currentValueId) => {
  187. if (currentPropertyId !== "") {
  188. choosePropertyIds.push(currentValueId);
  189. }
  190. });
  191. } else {
  192. choosePropertyIds = [propertyId];
  193. }
  194. for (let propertyIndex in propertyList) {
  195. if (choosePropertyIds.indexOf(propertyList[propertyIndex]["id"]) >= 0) {
  196. continue;
  197. }
  198. for (let valueIndex in propertyList[propertyIndex]["values"]) {
  199. propertyList[propertyIndex]["values"][valueIndex]["disabled"] = noChooseValueIds.indexOf(propertyList[propertyIndex]["values"][valueIndex]["id"]) < 0;
  200. }
  201. }
  202. }
  203. function getCanUseSkuList() {
  204. let newSkus = [];
  205. for (let sku of skuList.value) {
  206. if (sku.stock <= 0) {
  207. continue;
  208. }
  209. let isOk = true;
  210. state.currentPropertyArray.forEach((propertyId) => {
  211. if (propertyId.toString() !== "" && sku.value_id_array.indexOf(propertyId) < 0) {
  212. isOk = false;
  213. }
  214. });
  215. if (isOk) {
  216. newSkus.push(sku);
  217. }
  218. }
  219. return newSkus;
  220. }
  221. function onSelectSku(propertyId, valueId) {
  222. let isChecked = true;
  223. if (state.currentPropertyArray[propertyId] !== void 0 && state.currentPropertyArray[propertyId] === valueId) {
  224. isChecked = false;
  225. state.currentPropertyArray.splice(propertyId, 1, "");
  226. } else {
  227. state.currentPropertyArray[propertyId] = valueId;
  228. }
  229. let choosePropertyId = [];
  230. state.currentPropertyArray.forEach((currentPropertyId) => {
  231. if (currentPropertyId !== "") {
  232. choosePropertyId.push(currentPropertyId);
  233. }
  234. });
  235. let newSkuList = getCanUseSkuList();
  236. if (choosePropertyId.length === propertyList.length && newSkuList.length) {
  237. newSkuList[0].count = state.selectedSku.count || 1;
  238. state.selectedSku = newSkuList[0];
  239. } else {
  240. state.selectedSku = {};
  241. }
  242. changeDisabled(isChecked, propertyId, valueId);
  243. }
  244. changeDisabled(false);
  245. return (_ctx, _cache) => {
  246. return common_vendor.e({
  247. a: common_vendor.unref(sheep_index.sheep).$url.cdn(state.selectedSku.picUrl || __props.goodsInfo.picUrl),
  248. b: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/groupon-tag-white.png"),
  249. c: common_vendor.t(__props.goodsInfo.name),
  250. d: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(__props.goodsInfo.price)),
  251. e: common_vendor.t(state.selectedSku.stock || __props.goodsInfo.stock),
  252. f: common_vendor.f(common_vendor.unref(propertyList), (property, k0, i0) => {
  253. return {
  254. a: common_vendor.t(property.name),
  255. b: common_vendor.f(property.values, (value, k1, i1) => {
  256. return {
  257. a: common_vendor.t(value.name),
  258. b: common_vendor.n({
  259. "checked-btn": state.currentPropertyArray[property.id] === value.id
  260. }),
  261. c: common_vendor.n({
  262. "disabled-btn": value.disabled === true
  263. }),
  264. d: value.id,
  265. e: value.disabled === true,
  266. f: common_vendor.o(($event) => onSelectSku(property.id, value.id), value.id)
  267. };
  268. }),
  269. c: property.id
  270. };
  271. }),
  272. g: common_vendor.o(($event) => onNumberChange($event)),
  273. h: common_vendor.o(($event) => state.selectedSku.count = $event),
  274. i: common_vendor.p({
  275. min: 1,
  276. max: state.selectedSku.stock,
  277. step: 1,
  278. activity: "groupon",
  279. modelValue: state.selectedSku.count
  280. }),
  281. j: common_vendor.t(__props.grouponNum + "人团"),
  282. k: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(__props.goodsInfo.price)),
  283. l: __props.grouponAction === "create"
  284. }, __props.grouponAction === "create" ? {} : __props.grouponAction === "join" ? {} : {}, {
  285. m: __props.grouponAction === "join",
  286. n: common_vendor.o(onBuy),
  287. o: common_vendor.o(($event) => emits("close")),
  288. p: common_vendor.s(_ctx.__cssVars()),
  289. q: common_vendor.p({
  290. show: __props.show,
  291. round: "10"
  292. })
  293. });
  294. };
  295. }
  296. };
  297. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f77ace9d"], ["__file", "D:/zx/mall-front-app/sheep/components/s-select-groupon-sku/s-select-groupon-sku.vue"]]);
  298. wx.createComponent(Component);