s-select-seckill-sku.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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-seckill-sku",
  79. props: {
  80. modelValue: {
  81. type: Object,
  82. default() {
  83. }
  84. },
  85. show: {
  86. type: Boolean,
  87. default: false
  88. },
  89. // 单次限购数量
  90. singleLimitCount: {
  91. type: Number,
  92. default: 1
  93. }
  94. },
  95. emits: ["change", "addCart", "buy", "close"],
  96. setup(__props, { emit: __emit }) {
  97. const emits = __emit;
  98. const props = __props;
  99. const state = common_vendor.reactive({
  100. goodsInfo: common_vendor.computed(() => props.modelValue),
  101. selectedSku: {},
  102. currentPropertyArray: []
  103. });
  104. const propertyList = sheep_hooks_useGoods.convertProductPropertyList(state.goodsInfo.skus);
  105. const skuList = common_vendor.computed(() => {
  106. let skuPrices = state.goodsInfo.skus;
  107. for (let price of skuPrices) {
  108. price.value_id_array = price.properties.map((item) => item.valueId);
  109. }
  110. return skuPrices;
  111. });
  112. if (!state.goodsInfo.is_sku) {
  113. state.selectedSku = state.goodsInfo.skus[0];
  114. }
  115. common_vendor.watch(
  116. () => state.selectedSku,
  117. (newVal) => {
  118. emits("change", newVal);
  119. },
  120. {
  121. immediate: true,
  122. // 立即执行
  123. deep: true
  124. // 深度监听
  125. }
  126. );
  127. const onBuy = () => {
  128. if (state.selectedSku.id) {
  129. if (state.selectedSku.stock <= 0) {
  130. sheep_index.sheep.$helper.toast("库存不足");
  131. } else {
  132. emits("buy", state.selectedSku);
  133. }
  134. } else {
  135. sheep_index.sheep.$helper.toast("请选择规格");
  136. }
  137. };
  138. function onBuyCountChange(buyCount) {
  139. if (buyCount > 0 && state.selectedSku.count !== buyCount) {
  140. state.selectedSku.count = buyCount;
  141. }
  142. }
  143. const changeDisabled = (isChecked = false, propertyId = 0, valueId = 0) => {
  144. let newSkus = [];
  145. if (isChecked) {
  146. for (let price of skuList.value) {
  147. if (price.stock <= 0) {
  148. continue;
  149. }
  150. if (price.value_id_array.indexOf(valueId) >= 0) {
  151. newSkus.push(price);
  152. }
  153. }
  154. } else {
  155. newSkus = getCanUseSkuList();
  156. }
  157. let noChooseValueIds = [];
  158. for (let price of newSkus) {
  159. noChooseValueIds = noChooseValueIds.concat(price.value_id_array);
  160. }
  161. noChooseValueIds = Array.from(new Set(noChooseValueIds));
  162. if (isChecked) {
  163. let index = noChooseValueIds.indexOf(valueId);
  164. noChooseValueIds.splice(index, 1);
  165. } else {
  166. state.currentPropertyArray.forEach((currentPropertyId) => {
  167. if (currentPropertyId.toString() !== "") {
  168. return;
  169. }
  170. let index = noChooseValueIds.indexOf(currentPropertyId);
  171. if (index >= 0) {
  172. noChooseValueIds.splice(index, 1);
  173. }
  174. });
  175. }
  176. let choosePropertyIds = [];
  177. if (!isChecked) {
  178. state.currentPropertyArray.forEach((currentPropertyId, currentValueId) => {
  179. if (currentPropertyId !== "") {
  180. choosePropertyIds.push(currentValueId);
  181. }
  182. });
  183. } else {
  184. choosePropertyIds = [propertyId];
  185. }
  186. for (let propertyIndex in propertyList) {
  187. if (choosePropertyIds.indexOf(propertyList[propertyIndex]["id"]) >= 0) {
  188. continue;
  189. }
  190. for (let valueIndex in propertyList[propertyIndex]["values"]) {
  191. propertyList[propertyIndex]["values"][valueIndex]["disabled"] = noChooseValueIds.indexOf(propertyList[propertyIndex]["values"][valueIndex]["id"]) < 0;
  192. }
  193. }
  194. };
  195. const getCanUseSkuList = () => {
  196. let newSkus = [];
  197. for (let sku of skuList.value) {
  198. if (sku.stock <= 0) {
  199. continue;
  200. }
  201. let isOk = true;
  202. state.currentPropertyArray.forEach((propertyId) => {
  203. if (propertyId.toString() !== "" && sku.value_id_array.indexOf(propertyId) < 0) {
  204. isOk = false;
  205. }
  206. });
  207. if (isOk) {
  208. newSkus.push(sku);
  209. }
  210. }
  211. return newSkus;
  212. };
  213. const onSelectSku = (propertyId, valueId) => {
  214. let isChecked = true;
  215. if (state.currentPropertyArray[propertyId] !== void 0 && state.currentPropertyArray[propertyId] === valueId) {
  216. isChecked = false;
  217. state.currentPropertyArray.splice(propertyId, 1, "");
  218. } else {
  219. state.currentPropertyArray[propertyId] = valueId;
  220. }
  221. let choosePropertyId = [];
  222. state.currentPropertyArray.forEach((currentPropertyId) => {
  223. if (currentPropertyId !== "") {
  224. choosePropertyId.push(currentPropertyId);
  225. }
  226. });
  227. let newSkuList = getCanUseSkuList();
  228. if (choosePropertyId.length === propertyList.length && newSkuList.length) {
  229. newSkuList[0].count = state.selectedSku.count || 1;
  230. state.selectedSku = newSkuList[0];
  231. } else {
  232. state.selectedSku = {};
  233. }
  234. changeDisabled(isChecked, propertyId, valueId);
  235. };
  236. changeDisabled(false);
  237. return (_ctx, _cache) => {
  238. return {
  239. a: common_vendor.unref(sheep_index.sheep).$url.cdn(state.selectedSku.picUrl || state.goodsInfo.picUrl),
  240. b: common_vendor.t(state.goodsInfo.name),
  241. c: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.selectedSku.price || state.goodsInfo.price)),
  242. d: common_vendor.t(state.selectedSku.stock || state.goodsInfo.stock),
  243. e: common_vendor.f(common_vendor.unref(propertyList), (property, k0, i0) => {
  244. return {
  245. a: common_vendor.t(property.name),
  246. b: common_vendor.f(property.values, (value, k1, i1) => {
  247. return {
  248. a: common_vendor.t(value.name),
  249. b: common_vendor.n({
  250. "checked-btn": state.currentPropertyArray[property.id] === value.id
  251. }),
  252. c: common_vendor.n({
  253. "disabled-btn": value.disabled === true
  254. }),
  255. d: value.id,
  256. e: value.disabled === true,
  257. f: common_vendor.o(($event) => onSelectSku(property.id, value.id), value.id)
  258. };
  259. }),
  260. c: property.id
  261. };
  262. }),
  263. f: common_vendor.o(($event) => onBuyCountChange($event)),
  264. g: common_vendor.o(($event) => state.selectedSku.count = $event),
  265. h: common_vendor.p({
  266. min: 1,
  267. max: common_vendor.unref(common_vendor.lodashExports.min)([__props.singleLimitCount, state.selectedSku.stock]),
  268. step: 1,
  269. activity: "seckill",
  270. modelValue: state.selectedSku.count
  271. }),
  272. i: common_vendor.o(onBuy),
  273. j: common_vendor.o(($event) => emits("close")),
  274. k: common_vendor.p({
  275. show: __props.show,
  276. round: "10"
  277. })
  278. };
  279. };
  280. }
  281. };
  282. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-e3bc621c"], ["__file", "D:/zx/mall-front-app/sheep/components/s-select-seckill-sku/s-select-seckill-sku.vue"]]);
  283. wx.createComponent(Component);