s-select-seckill-sku.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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("../../url/index.js");
  6. require("../../store/index.js");
  7. require("../../store/app.js");
  8. require("../../api/promotion/diy.js");
  9. require("../../request/index.js");
  10. require("../../config/index.js");
  11. require("../../platform/index.js");
  12. require("../../platform/provider/wechat/index.js");
  13. require("../../platform/provider/wechat/miniProgram.js");
  14. require("../../api/member/auth.js");
  15. require("../../api/member/social.js");
  16. require("../../api/member/user.js");
  17. require("../../platform/provider/apple/index.js");
  18. require("../../platform/share.js");
  19. require("../../router/index.js");
  20. require("../../hooks/useModal.js");
  21. require("../../helper/index.js");
  22. require("../../helper/test.js");
  23. require("../../helper/digit.js");
  24. require("../../api/member/signin.js");
  25. require("../../helper/throttle.js");
  26. require("../../platform/pay.js");
  27. require("../../api/pay/order.js");
  28. require("../../store/user.js");
  29. require("../../store/cart.js");
  30. require("../../api/trade/cart.js");
  31. require("../../api/pay/wallet.js");
  32. require("../../api/trade/order.js");
  33. require("../../api/promotion/coupon.js");
  34. require("../../store/sys.js");
  35. require("../../store/modal.js");
  36. require("../../config/zIndex.js");
  37. require("../../util/index.js");
  38. if (!Array) {
  39. const _easycom_su_number_box2 = common_vendor.resolveComponent("su-number-box");
  40. const _easycom_su_popup2 = common_vendor.resolveComponent("su-popup");
  41. (_easycom_su_number_box2 + _easycom_su_popup2)();
  42. }
  43. const _easycom_su_number_box = () => "../../ui/su-number-box/su-number-box.js";
  44. const _easycom_su_popup = () => "../../ui/su-popup/su-popup.js";
  45. if (!Math) {
  46. (_easycom_su_number_box + _easycom_su_popup)();
  47. }
  48. const _sfc_main = {
  49. __name: "s-select-seckill-sku",
  50. props: {
  51. modelValue: {
  52. type: Object,
  53. default() {
  54. }
  55. },
  56. show: {
  57. type: Boolean,
  58. default: false
  59. },
  60. // 单次限购数量
  61. singleLimitCount: {
  62. type: Number,
  63. default: 1
  64. }
  65. },
  66. emits: ["change", "addCart", "buy", "close"],
  67. setup(__props, { emit: __emit }) {
  68. const emits = __emit;
  69. const props = __props;
  70. const state = common_vendor.reactive({
  71. goodsInfo: common_vendor.computed(() => props.modelValue),
  72. selectedSku: {},
  73. currentPropertyArray: []
  74. });
  75. const propertyList = sheep_hooks_useGoods.convertProductPropertyList(state.goodsInfo.skus);
  76. const skuList = common_vendor.computed(() => {
  77. let skuPrices = state.goodsInfo.skus;
  78. for (let price of skuPrices) {
  79. price.value_id_array = price.properties.map((item) => item.valueId);
  80. }
  81. return skuPrices;
  82. });
  83. if (!state.goodsInfo.is_sku) {
  84. state.selectedSku = state.goodsInfo.skus[0];
  85. }
  86. common_vendor.watch(
  87. () => state.selectedSku,
  88. (newVal) => {
  89. emits("change", newVal);
  90. },
  91. {
  92. immediate: true,
  93. // 立即执行
  94. deep: true
  95. // 深度监听
  96. }
  97. );
  98. const onBuy = () => {
  99. if (state.selectedSku.id) {
  100. if (state.selectedSku.stock <= 0) {
  101. sheep_index.sheep.$helper.toast("库存不足");
  102. } else {
  103. emits("buy", state.selectedSku);
  104. }
  105. } else {
  106. sheep_index.sheep.$helper.toast("请选择规格");
  107. }
  108. };
  109. function onBuyCountChange(buyCount) {
  110. if (buyCount > 0 && state.selectedSku.count !== buyCount) {
  111. state.selectedSku.count = buyCount;
  112. }
  113. }
  114. const changeDisabled = (isChecked = false, propertyId = 0, valueId = 0) => {
  115. let newSkus = [];
  116. if (isChecked) {
  117. for (let price of skuList.value) {
  118. if (price.stock <= 0) {
  119. continue;
  120. }
  121. if (price.value_id_array.indexOf(valueId) >= 0) {
  122. newSkus.push(price);
  123. }
  124. }
  125. } else {
  126. newSkus = getCanUseSkuList();
  127. }
  128. let noChooseValueIds = [];
  129. for (let price of newSkus) {
  130. noChooseValueIds = noChooseValueIds.concat(price.value_id_array);
  131. }
  132. noChooseValueIds = Array.from(new Set(noChooseValueIds));
  133. if (isChecked) {
  134. let index = noChooseValueIds.indexOf(valueId);
  135. noChooseValueIds.splice(index, 1);
  136. } else {
  137. state.currentPropertyArray.forEach((currentPropertyId) => {
  138. if (currentPropertyId.toString() !== "") {
  139. return;
  140. }
  141. let index = noChooseValueIds.indexOf(currentPropertyId);
  142. if (index >= 0) {
  143. noChooseValueIds.splice(index, 1);
  144. }
  145. });
  146. }
  147. let choosePropertyIds = [];
  148. if (!isChecked) {
  149. state.currentPropertyArray.forEach((currentPropertyId, currentValueId) => {
  150. if (currentPropertyId !== "") {
  151. choosePropertyIds.push(currentValueId);
  152. }
  153. });
  154. } else {
  155. choosePropertyIds = [propertyId];
  156. }
  157. for (let propertyIndex in propertyList) {
  158. if (choosePropertyIds.indexOf(propertyList[propertyIndex]["id"]) >= 0) {
  159. continue;
  160. }
  161. for (let valueIndex in propertyList[propertyIndex]["values"]) {
  162. propertyList[propertyIndex]["values"][valueIndex]["disabled"] = noChooseValueIds.indexOf(propertyList[propertyIndex]["values"][valueIndex]["id"]) < 0;
  163. }
  164. }
  165. };
  166. const getCanUseSkuList = () => {
  167. let newSkus = [];
  168. for (let sku of skuList.value) {
  169. if (sku.stock <= 0) {
  170. continue;
  171. }
  172. let isOk = true;
  173. state.currentPropertyArray.forEach((propertyId) => {
  174. if (propertyId.toString() !== "" && sku.value_id_array.indexOf(propertyId) < 0) {
  175. isOk = false;
  176. }
  177. });
  178. if (isOk) {
  179. newSkus.push(sku);
  180. }
  181. }
  182. return newSkus;
  183. };
  184. const onSelectSku = (propertyId, valueId) => {
  185. let isChecked = true;
  186. if (state.currentPropertyArray[propertyId] !== void 0 && state.currentPropertyArray[propertyId] === valueId) {
  187. isChecked = false;
  188. state.currentPropertyArray.splice(propertyId, 1, "");
  189. } else {
  190. state.currentPropertyArray[propertyId] = valueId;
  191. }
  192. let choosePropertyId = [];
  193. state.currentPropertyArray.forEach((currentPropertyId) => {
  194. if (currentPropertyId !== "") {
  195. choosePropertyId.push(currentPropertyId);
  196. }
  197. });
  198. let newSkuList = getCanUseSkuList();
  199. if (choosePropertyId.length === propertyList.length && newSkuList.length) {
  200. newSkuList[0].count = state.selectedSku.count || 1;
  201. state.selectedSku = newSkuList[0];
  202. } else {
  203. state.selectedSku = {};
  204. }
  205. changeDisabled(isChecked, propertyId, valueId);
  206. };
  207. changeDisabled(false);
  208. return (_ctx, _cache) => {
  209. return {
  210. a: common_vendor.unref(sheep_index.sheep).$url.cdn(state.selectedSku.picUrl || state.goodsInfo.picUrl),
  211. b: common_vendor.t(state.goodsInfo.name),
  212. c: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.selectedSku.price || state.goodsInfo.price)),
  213. d: common_vendor.t(state.selectedSku.stock || state.goodsInfo.stock),
  214. e: common_vendor.f(common_vendor.unref(propertyList), (property, k0, i0) => {
  215. return {
  216. a: common_vendor.t(property.name),
  217. b: common_vendor.f(property.values, (value, k1, i1) => {
  218. return {
  219. a: common_vendor.t(value.name),
  220. b: common_vendor.n({
  221. "checked-btn": state.currentPropertyArray[property.id] === value.id
  222. }),
  223. c: common_vendor.n({
  224. "disabled-btn": value.disabled === true
  225. }),
  226. d: value.id,
  227. e: value.disabled === true,
  228. f: common_vendor.o(($event) => onSelectSku(property.id, value.id), value.id)
  229. };
  230. }),
  231. c: property.id
  232. };
  233. }),
  234. f: common_vendor.o(($event) => onBuyCountChange($event)),
  235. g: common_vendor.o(($event) => state.selectedSku.count = $event),
  236. h: common_vendor.p({
  237. min: 1,
  238. max: common_vendor.unref(common_vendor.lodashExports.min)([__props.singleLimitCount, state.selectedSku.stock]),
  239. step: 1,
  240. activity: "seckill",
  241. modelValue: state.selectedSku.count
  242. }),
  243. i: common_vendor.o(onBuy),
  244. j: common_vendor.o(($event) => emits("close")),
  245. k: common_vendor.p({
  246. show: __props.show,
  247. round: "10"
  248. })
  249. };
  250. };
  251. }
  252. };
  253. 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"]]);
  254. wx.createComponent(Component);