s-select-seckill-sku.js 8.7 KB

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