index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. var t = Object.assign || function (t) {
  2. for (var a = 1; a < arguments.length; a++) {
  3. var e = arguments[a];
  4. for (var u in e) Object.prototype.hasOwnProperty.call(e, u) && (t[u] = e[u]);
  5. }
  6. return t;
  7. }, a = require("../../utils/public"), e = getApp();
  8. Component({
  9. properties: {
  10. visible: {
  11. type: Boolean,
  12. value: false,
  13. observer: function (t) {
  14. t && this.setData({
  15. value: 1,
  16. loading: false
  17. });
  18. }
  19. },
  20. skuList: {
  21. type: Array,
  22. value: [{
  23. "list": [{
  24. "goods_option_id": "15",
  25. "option_id": "15",
  26. "name": "尺码",
  27. "option_value": [{
  28. "goods_option_value_id": "30",
  29. "option_value_id": "30",
  30. "name": "XL",
  31. "image": ""
  32. }, {
  33. "goods_option_value_id": "29",
  34. "option_value_id": "29",
  35. "name": "M",
  36. "image": ""
  37. }]
  38. }, {
  39. "goods_option_id": "16",
  40. "option_id": "16",
  41. "name": "尺码",
  42. "option_value": [{
  43. "goods_option_value_id": "32",
  44. "option_value_id": "32",
  45. "name": "XL",
  46. "image": "https:\/\/shiziyu.liofis.com\/attachment\/images\/3\/2018\/12\/sZjsKytoyYKTOOPzLkE56RK65csGrj.png"
  47. }, {
  48. "goods_option_value_id": "31",
  49. "option_value_id": "31",
  50. "name": "M",
  51. "image": "https:\/\/shiziyu.liofis.com\/attachment\/images\/3\/2018\/12\/KO66uCjozjrjf0cSu6RfrZrKU6K6Yr.jpeg"
  52. }]
  53. }],
  54. "name": ["尺码", "尺码"],
  55. "sku_mu_list": [{
  56. "spec": "M+M",
  57. "canBuyNum": "22",
  58. "spuName": "大毛领短款羊剪绒外套女显瘦2018冬季新款加厚仿水貂绒毛呢外套女",
  59. "actPrice": ["1", "50"],
  60. "marketPrice": ["2", "00"],
  61. "skuImage": "https:\/\/shiziyu.liofis.com\/attachment\/images\/3\/2018\/12\/KO66uCjozjrjf0cSu6RfrZrKU6K6Yr.jpeg"
  62. }, {
  63. "spec": "M+XL",
  64. "canBuyNum": "22",
  65. "spuName": "大毛领短款羊剪绒外套女显瘦2018冬季新款加厚仿水貂绒毛呢外套女",
  66. "actPrice": ["2", "00"],
  67. "marketPrice": ["2", "00"],
  68. "skuImage": "https:\/\/shiziyu.liofis.com\/attachment\/images\/3\/2018\/12\/sZjsKytoyYKTOOPzLkE56RK65csGrj.png"
  69. }, {
  70. "spec": "XL+M",
  71. "canBuyNum": "22",
  72. "spuName": "大毛领短款羊剪绒外套女显瘦2018冬季新款加厚仿水貂绒毛呢外套女",
  73. "actPrice": ["3", "00"],
  74. "marketPrice": ["2", "00"],
  75. "skuImage": "https:\/\/shiziyu.liofis.com\/attachment\/images\/3\/2018\/12\/KO66uCjozjrjf0cSu6RfrZrKU6K6Yr.jpeg"
  76. }, {
  77. "spec": "XL+XL",
  78. "canBuyNum": "22",
  79. "spuName": "大毛领短款羊剪绒外套女显瘦2018冬季新款加厚仿水貂绒毛呢外套女",
  80. "actPrice": ["4", "00"],
  81. "marketPrice": ["2", "00"],
  82. "skuImage": "https:\/\/shiziyu.liofis.com\/attachment\/images\/3\/2018\/12\/sZjsKytoyYKTOOPzLkE56RK65csGrj.png"
  83. }]
  84. }],
  85. observer: function (t) {
  86. if (t && t.length) {
  87. console.log('t.length');
  88. console.log(t.length);
  89. for (var a = t, e = "", u = 0; u < a.length; u++) if (a[u].canBuyNum - 1 >= 0) {
  90. e = u;
  91. break;
  92. }
  93. "number" == typeof e ? this.setData({
  94. current: e,
  95. canBuyFlag: true
  96. }) : this.setData({
  97. canBuyFlag: false,
  98. current: 0
  99. });
  100. }
  101. }
  102. },
  103. promotionDTO: Object,
  104. current: {
  105. type: Number,
  106. value: 0
  107. },
  108. type: {
  109. type: Number,
  110. value: 0
  111. }
  112. },
  113. data: {
  114. value: 1,
  115. cur_option_idx:"",
  116. canBuyMsg: "",
  117. loading: false,
  118. canBuyFlag: !0,
  119. focusFlag: false
  120. },
  121. methods: {
  122. close: function () {
  123. this.triggerEvent("cancel");
  124. },
  125. switchSpec: function (t) {
  126. this.data.focusFlag || t.target.dataset.disabled || this.data.current !== 1 * t.target.dataset.idx && this.canBuyFn(1, t.target.dataset.idx, {
  127. current: t.target.dataset.idx
  128. });
  129. },
  130. focus: function () {
  131. this.data.focusFlag = !0;
  132. },
  133. canBuyFn: function (a, e) {
  134. var u = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, i = this.data.skuList[e].canBuyNum - a, s = {
  135. value: a
  136. };
  137. i <= 10 && (s.canBuyMsg = "还可以购买 " + i + " 件"), this.data.canBuyMsg && i > 10 && (s.canBuyMsg = ""),
  138. this.setData(t({}, s, u));
  139. },
  140. changeNumber: function (t) {
  141. var a = t.detail;
  142. this.data.focusFlag = false, a && this.canBuyFn(a.value, this.data.current);
  143. },
  144. confirm: function () {
  145. var t = this;
  146. if (this.setData({
  147. loading: !0
  148. }), this.data.canBuyFlag) {
  149. var u = this.data.current, i = this.data.skuList, s = {
  150. actId: i[u].actId,
  151. skuId: i[u].skuId,
  152. goodsNum: this.data.value,
  153. spuId: i[u].spuId
  154. }, n = i[u].actId, r = i[u].skuId, c = this.data.value, o = i[u].spuId, d = e.globalData.community.communityId;
  155. 0 === this.data.type ? (0, a.addToCart)({
  156. actId: n,
  157. communityId: e.globalData.community.communityId,
  158. goodsNum: c,
  159. skuId: r
  160. }, function () {
  161. t.triggerEvent("confirm");
  162. }) : 1 === this.data.type ? (0, a.skuConfirm)({
  163. communityId: d,
  164. skuInfo: [{
  165. skuNum: c,
  166. skuId: r,
  167. actId: n,
  168. spuId: o
  169. }]
  170. }, function () {
  171. t.triggerEvent("confirm");
  172. }) : this.triggerEvent("confirm", s);
  173. } else wx.showToast({
  174. title: "该商品已失效",
  175. icon: "none"
  176. });
  177. }
  178. }
  179. });