index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. if (!Array) {
  4. const _component_up_button = common_vendor.resolveComponent("up-button");
  5. const _component_up_popup = common_vendor.resolveComponent("up-popup");
  6. (_component_up_button + _component_up_popup)();
  7. }
  8. const _sfc_main = {
  9. __name: "index",
  10. props: {
  11. attr: {
  12. type: Object,
  13. default: () => ({})
  14. },
  15. showPopup: {
  16. type: Boolean,
  17. default: false
  18. },
  19. limitNum: {
  20. type: Number,
  21. default: 0
  22. },
  23. isShow: {
  24. type: Number,
  25. default: 0
  26. },
  27. iSbnt: {
  28. type: Number,
  29. default: 0
  30. },
  31. iSplus: {
  32. type: Number,
  33. default: 0
  34. },
  35. iScart: {
  36. type: Number,
  37. default: 0
  38. }
  39. },
  40. emits: [
  41. "goCat",
  42. "iptCartNum",
  43. "myevent",
  44. "ChangeCartNum",
  45. "attrVal",
  46. "ChangeAttr",
  47. "submit",
  48. "closePopup"
  49. ],
  50. setup(__props, { emit: __emit }) {
  51. const props = __props;
  52. const emit = __emit;
  53. const calcNumPrice = common_vendor.computed(() => {
  54. var _a;
  55. if (!((_a = props.attr) == null ? void 0 : _a.productSelect)) {
  56. return "0.00";
  57. }
  58. const { storePrice, cart_num } = props.attr.productSelect;
  59. if (!storePrice || !cart_num) {
  60. return "0.00";
  61. }
  62. const price = Number(storePrice);
  63. const quantity = Number(cart_num);
  64. if (isNaN(price) || isNaN(quantity)) {
  65. return "0.00";
  66. }
  67. if (price < 0 || quantity < 0) {
  68. return "0.00";
  69. }
  70. const total = price * quantity;
  71. return total.toFixed(2);
  72. });
  73. function bindCode() {
  74. emit("iptCartNum", props.attr.productSelect.cart_num);
  75. }
  76. function close() {
  77. emit("closePopup");
  78. }
  79. function submit() {
  80. emit("submit");
  81. }
  82. function CartNumDes() {
  83. emit("ChangeCartNum", false);
  84. }
  85. function CartNumAdd() {
  86. emit("ChangeCartNum", true);
  87. }
  88. function tapAttr(indexw, indexn) {
  89. emit("attrVal", { indexw, indexn });
  90. if (props.attr.productAttr && props.attr.productAttr[indexw]) {
  91. props.attr.productAttr[indexw].index = props.attr.productAttr[indexw].attrValues[indexn];
  92. }
  93. const value = getCheckedValue().join(",");
  94. emit("ChangeAttr", value);
  95. }
  96. function getCheckedValue() {
  97. const productAttr = props.attr.productAttr || [];
  98. const value = [];
  99. for (let i = 0; i < productAttr.length; i++) {
  100. for (let j = 0; j < productAttr[i].attrValues.length; j++) {
  101. if (productAttr[i].index === productAttr[i].attrValues[j]) {
  102. value.push(productAttr[i].attrValues[j]);
  103. }
  104. }
  105. }
  106. return value;
  107. }
  108. return (_ctx, _cache) => {
  109. return common_vendor.e({
  110. a: __props.attr.productSelect.image,
  111. b: common_vendor.t(__props.attr.productSelect.storeName),
  112. c: common_vendor.t(calcNumPrice.value),
  113. d: __props.isShow
  114. }, __props.isShow ? {
  115. e: common_vendor.t(__props.attr.productSelect.stock)
  116. } : {}, {
  117. f: __props.limitNum
  118. }, __props.limitNum ? {
  119. g: common_vendor.t(__props.attr.productSelect.quota)
  120. } : {}, {
  121. h: common_vendor.o(close),
  122. i: common_vendor.f(__props.attr.productAttr, (item, indexw, i0) => {
  123. return {
  124. a: common_vendor.t(item.attrName),
  125. b: common_vendor.f(item.attrValues, (itemn, indexn, i1) => {
  126. return {
  127. a: common_vendor.t(itemn),
  128. b: common_vendor.n(item.index === itemn ? "on" : ""),
  129. c: common_vendor.o(($event) => tapAttr(indexw, indexn), indexn),
  130. d: indexn
  131. };
  132. }),
  133. c: indexw
  134. };
  135. }),
  136. j: common_vendor.n(__props.attr.productSelect.cart_num <= 1 ? "on" : ""),
  137. k: common_vendor.o(CartNumDes),
  138. l: common_vendor.o([($event) => __props.attr.productSelect.cart_num = $event.detail.value, ($event) => bindCode(__props.attr.productSelect.cart_num)]),
  139. m: __props.attr.productSelect.cart_num,
  140. n: __props.iSplus
  141. }, __props.iSplus ? {
  142. o: common_vendor.n(__props.attr.productSelect.cart_num >= __props.attr.productSelect.stock ? "on" : ""),
  143. p: common_vendor.o(CartNumAdd)
  144. } : {
  145. q: common_vendor.n(__props.attr.productSelect.cart_num >= __props.attr.productSelect.quota || __props.attr.productSelect.cart_num >= __props.attr.productSelect.stock || __props.attr.productSelect.cart_num >= __props.attr.productSelect.num ? "on" : ""),
  146. r: common_vendor.o(CartNumAdd)
  147. }, {
  148. s: __props.attr.productSelect.stock > 0
  149. }, __props.attr.productSelect.stock > 0 ? {
  150. t: common_vendor.o(submit),
  151. v: common_vendor.p({
  152. type: "primary",
  153. text: "确定"
  154. })
  155. } : {
  156. w: common_vendor.o(submit),
  157. x: common_vendor.p({
  158. type: "primary",
  159. text: "已售罄"
  160. })
  161. }, {
  162. y: common_vendor.n((__props.iSbnt ? "join" : "") + " " + (__props.iScart ? "joinCart" : "")),
  163. z: common_vendor.o(close),
  164. A: common_vendor.p({
  165. show: __props.showPopup,
  166. closeOnClickOverlay: true
  167. })
  168. });
  169. };
  170. }
  171. };
  172. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2914200c"]]);
  173. wx.createComponent(Component);
  174. //# sourceMappingURL=../../../.sourcemap/mp-weixin/components/productWindow/index.js.map