s-select-groupon-sku.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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-groupon-sku",
  50. props: {
  51. show: {
  52. type: Boolean,
  53. default: false
  54. },
  55. goodsInfo: {
  56. type: Object,
  57. default() {
  58. }
  59. },
  60. grouponAction: {
  61. type: String,
  62. default: "create"
  63. },
  64. grouponNum: {
  65. type: [Number, String],
  66. default: 0
  67. }
  68. },
  69. emits: ["change", "addCart", "buy", "close", "ladder"],
  70. setup(__props, { emit: __emit }) {
  71. common_vendor.useCssVars((_ctx) => ({
  72. "478364b0": common_vendor.unref(headerBg)
  73. }));
  74. const headerBg = sheep_index.sheep.$url.css("/static/images/groupon-btn-long.png");
  75. const emits = __emit;
  76. const props = __props;
  77. const state = common_vendor.reactive({
  78. selectedSku: {},
  79. // 选中的 SKU
  80. currentPropertyArray: [],
  81. // 当前选中的属性,实际是个 Map。key 是 property 编号,value 是 value 编号
  82. grouponNum: props.grouponNum
  83. });
  84. const propertyList = sheep_hooks_useGoods.convertProductPropertyList(props.goodsInfo.skus);
  85. const skuList = common_vendor.computed(() => {
  86. let skuPrices = props.goodsInfo.skus;
  87. for (let price of skuPrices) {
  88. price.value_id_array = price.properties.map((item) => item.valueId);
  89. }
  90. return skuPrices;
  91. });
  92. common_vendor.watch(
  93. () => state.selectedSku,
  94. (newVal) => {
  95. emits("change", newVal);
  96. },
  97. {
  98. immediate: true,
  99. // 立即执行
  100. deep: true
  101. // 深度监听
  102. }
  103. );
  104. function onNumberChange(e) {
  105. if (e === 0)
  106. return;
  107. if (state.selectedSku.count === e)
  108. return;
  109. state.selectedSku.count = e;
  110. }
  111. function onBuy() {
  112. if (!state.selectedSku.id || state.selectedSku.id <= 0) {
  113. sheep_index.sheep.$helper.toast("请选择规格");
  114. return;
  115. }
  116. if (state.selectedSku.stock <= 0) {
  117. sheep_index.sheep.$helper.toast("库存不足");
  118. return;
  119. }
  120. emits("buy", state.selectedSku);
  121. }
  122. function changeDisabled(isChecked = false, propertyId = 0, valueId = 0) {
  123. let newSkus = [];
  124. if (isChecked) {
  125. for (let price of skuList.value) {
  126. if (price.stock <= 0) {
  127. continue;
  128. }
  129. if (price.value_id_array.indexOf(valueId) >= 0) {
  130. newSkus.push(price);
  131. }
  132. }
  133. } else {
  134. newSkus = getCanUseSkuList();
  135. }
  136. let noChooseValueIds = [];
  137. for (let price of newSkus) {
  138. noChooseValueIds = noChooseValueIds.concat(price.value_id_array);
  139. }
  140. noChooseValueIds = Array.from(new Set(noChooseValueIds));
  141. if (isChecked) {
  142. let index = noChooseValueIds.indexOf(valueId);
  143. noChooseValueIds.splice(index, 1);
  144. } else {
  145. state.currentPropertyArray.forEach((currentPropertyId) => {
  146. if (currentPropertyId.toString() !== "") {
  147. return;
  148. }
  149. let index = noChooseValueIds.indexOf(currentPropertyId);
  150. if (index >= 0) {
  151. noChooseValueIds.splice(index, 1);
  152. }
  153. });
  154. }
  155. let choosePropertyIds = [];
  156. if (!isChecked) {
  157. state.currentPropertyArray.forEach((currentPropertyId, currentValueId) => {
  158. if (currentPropertyId !== "") {
  159. choosePropertyIds.push(currentValueId);
  160. }
  161. });
  162. } else {
  163. choosePropertyIds = [propertyId];
  164. }
  165. for (let propertyIndex in propertyList) {
  166. if (choosePropertyIds.indexOf(propertyList[propertyIndex]["id"]) >= 0) {
  167. continue;
  168. }
  169. for (let valueIndex in propertyList[propertyIndex]["values"]) {
  170. propertyList[propertyIndex]["values"][valueIndex]["disabled"] = noChooseValueIds.indexOf(propertyList[propertyIndex]["values"][valueIndex]["id"]) < 0;
  171. }
  172. }
  173. }
  174. function getCanUseSkuList() {
  175. let newSkus = [];
  176. for (let sku of skuList.value) {
  177. if (sku.stock <= 0) {
  178. continue;
  179. }
  180. let isOk = true;
  181. state.currentPropertyArray.forEach((propertyId) => {
  182. if (propertyId.toString() !== "" && sku.value_id_array.indexOf(propertyId) < 0) {
  183. isOk = false;
  184. }
  185. });
  186. if (isOk) {
  187. newSkus.push(sku);
  188. }
  189. }
  190. return newSkus;
  191. }
  192. function onSelectSku(propertyId, valueId) {
  193. let isChecked = true;
  194. if (state.currentPropertyArray[propertyId] !== void 0 && state.currentPropertyArray[propertyId] === valueId) {
  195. isChecked = false;
  196. state.currentPropertyArray.splice(propertyId, 1, "");
  197. } else {
  198. state.currentPropertyArray[propertyId] = valueId;
  199. }
  200. let choosePropertyId = [];
  201. state.currentPropertyArray.forEach((currentPropertyId) => {
  202. if (currentPropertyId !== "") {
  203. choosePropertyId.push(currentPropertyId);
  204. }
  205. });
  206. let newSkuList = getCanUseSkuList();
  207. if (choosePropertyId.length === propertyList.length && newSkuList.length) {
  208. newSkuList[0].count = state.selectedSku.count || 1;
  209. state.selectedSku = newSkuList[0];
  210. } else {
  211. state.selectedSku = {};
  212. }
  213. changeDisabled(isChecked, propertyId, valueId);
  214. }
  215. changeDisabled(false);
  216. return (_ctx, _cache) => {
  217. return common_vendor.e({
  218. a: common_vendor.unref(sheep_index.sheep).$url.cdn(state.selectedSku.picUrl || __props.goodsInfo.picUrl),
  219. b: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/groupon-tag-white.png"),
  220. c: common_vendor.t(__props.goodsInfo.name),
  221. d: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(__props.goodsInfo.price)),
  222. e: common_vendor.t(state.selectedSku.stock || __props.goodsInfo.stock),
  223. f: common_vendor.f(common_vendor.unref(propertyList), (property, k0, i0) => {
  224. return {
  225. a: common_vendor.t(property.name),
  226. b: common_vendor.f(property.values, (value, k1, i1) => {
  227. return {
  228. a: common_vendor.t(value.name),
  229. b: common_vendor.n({
  230. "checked-btn": state.currentPropertyArray[property.id] === value.id
  231. }),
  232. c: common_vendor.n({
  233. "disabled-btn": value.disabled === true
  234. }),
  235. d: value.id,
  236. e: value.disabled === true,
  237. f: common_vendor.o(($event) => onSelectSku(property.id, value.id), value.id)
  238. };
  239. }),
  240. c: property.id
  241. };
  242. }),
  243. g: common_vendor.o(($event) => onNumberChange($event)),
  244. h: common_vendor.o(($event) => state.selectedSku.count = $event),
  245. i: common_vendor.p({
  246. min: 1,
  247. max: state.selectedSku.stock,
  248. step: 1,
  249. activity: "groupon",
  250. modelValue: state.selectedSku.count
  251. }),
  252. j: common_vendor.t(__props.grouponNum + "人团"),
  253. k: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(__props.goodsInfo.price)),
  254. l: __props.grouponAction === "create"
  255. }, __props.grouponAction === "create" ? {} : __props.grouponAction === "join" ? {} : {}, {
  256. m: __props.grouponAction === "join",
  257. n: common_vendor.o(onBuy),
  258. o: common_vendor.o(($event) => emits("close")),
  259. p: common_vendor.s(_ctx.__cssVars()),
  260. q: common_vendor.p({
  261. show: __props.show,
  262. round: "10"
  263. })
  264. });
  265. };
  266. }
  267. };
  268. 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"]]);
  269. wx.createComponent(Component);