index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. var t = require("../../utils/public");
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. var app = getApp();
  5. Component({
  6. properties: {
  7. spuItem: {
  8. type: Object,
  9. value: {
  10. spuId: "",
  11. skuId: "",
  12. spuImage: "",
  13. spuName: "",
  14. endTime: 0,
  15. beginTime: "",
  16. actPrice: ["", ""],
  17. marketPrice: ["", ""],
  18. spuCanBuyNum: "",
  19. soldNum: "",
  20. actId: "",
  21. limitMemberNum: "",
  22. limitOrderNum: "",
  23. serverTime: "",
  24. isLimit: false,
  25. skuList: [],
  26. spuDescribe: "",
  27. is_take_fullreduction: 0,
  28. label_info: "",
  29. car_count: 0
  30. }
  31. },
  32. isPast: {
  33. type: Boolean,
  34. value: false
  35. },
  36. actEnd: {
  37. type: Boolean,
  38. value: false
  39. },
  40. reduction: {
  41. type: Object,
  42. value: {
  43. full_money: '',
  44. full_reducemoney: '',
  45. is_open_fullreduction: 0
  46. }
  47. },
  48. isShowListCount: {
  49. type: Number,
  50. value: 0
  51. },
  52. changeCarCount: {
  53. type: Boolean,
  54. value: false,
  55. observer: function (t) {
  56. if (t) this.setData({ number: this.data.spuItem.car_count || 0 });
  57. }
  58. }
  59. },
  60. attached() {
  61. this.setData({ placeholdeImg: app.globalData.placeholdeImg})
  62. },
  63. data: {
  64. disabled: false,
  65. placeholdeImg: '',
  66. number: 0
  67. },
  68. ready: function () {
  69. this.setData({
  70. number: this.data.spuItem.car_count || 0
  71. });
  72. },
  73. methods: {
  74. openSku: function() {
  75. console.log( 'step1');
  76. this.setData({
  77. stopClick:true,
  78. disabled:false
  79. })
  80. if (this.data.spuItem.skuList.length === void 0) {
  81. this.triggerEvent("openSku", {
  82. actId:this.data.spuItem.actId,
  83. skuList: this.data.spuItem.skuList,
  84. promotionDTO: this.data.spuItem.promotionDTO,
  85. allData: {
  86. spuName: this.data.spuItem.spuName,
  87. skuImage: this.data.spuItem.skuImage,
  88. actPrice: this.data.spuItem.actPrice,
  89. canBuyNum: this.data.spuItem.spuCanBuyNum,
  90. stock: this.data.spuItem.spuCanBuyNum,
  91. marketPrice: this.data.spuItem.marketPrice
  92. }
  93. });
  94. } else {
  95. this.addCart({ value: 1, type: "plus" });
  96. }
  97. },
  98. countDownEnd: function() {
  99. this.setData({
  100. actEnd: true
  101. });
  102. },
  103. submit2: function(e) {
  104. (0, t.collectFormIds)(e.detail.formId);
  105. },
  106. changeNumber: function (t) {
  107. var e = t.detail;
  108. e && this.addCart(e);
  109. },
  110. outOfMax: function (t) {
  111. var e = t.detail, canBuyNum = this.data.spuItem.spuCanBuyNum;
  112. if(this.data.number >= canBuyNum) {
  113. wx.showToast({
  114. title: "不能购买更多啦",
  115. icon: "none"
  116. })
  117. }
  118. },
  119. addCart: function (t) {
  120. console.log(t)
  121. // {value: 2, type: "plus/minus"}
  122. var token = wx.getStorageSync('token');
  123. var community = wx.getStorageSync('community');
  124. var goods_id = this.data.spuItem.actId;
  125. var community_id = community.communityId;
  126. // var quantity = t.value || 1;
  127. let that = this;
  128. if (t.type =='plus'){
  129. // let spuCanBuyNum = this.data.spuItem.spuCanBuyNum;
  130. // if (quantity > spuCanBuyNum) quantity = spuCanBuyNum;
  131. app.util.request({
  132. url: 'entry/wxapp/user',
  133. data: {
  134. controller: 'car.add',
  135. token: token,
  136. goods_id: goods_id,
  137. community_id: community_id,
  138. quantity: 1,
  139. sku_str: '',
  140. buy_type: 'dan',
  141. pin_id: 0,
  142. is_just_addcar: 1
  143. },
  144. dataType: 'json',
  145. method: 'POST',
  146. success: function (res) {
  147. if (res.data.code == 3) {
  148. let max_quantity = res.data.max_quantity || '';
  149. (max_quantity > 0) && that.setData({ number: that.data.number })
  150. wx.showToast({
  151. title: res.data.msg,
  152. icon: 'none',
  153. duration: 2000
  154. })
  155. } else if (res.data.code == 6) {
  156. let max_quantity = res.data.max_quantity || '';
  157. (max_quantity > 0) && that.setData({ number: that.data.number })
  158. var msg = res.data.msg;
  159. wx.showToast({
  160. title: msg,
  161. icon: 'none',
  162. duration: 2000
  163. })
  164. } else {
  165. that.triggerEvent("changeCartNum", res.data.total);
  166. that.setData({ number: res.data.cur_count })
  167. wx.showToast({
  168. title: "已加入购物车",
  169. image: "../../images/addShopCart.png"
  170. })
  171. status.indexListCarCount(goods_id, res.data.cur_count);
  172. }
  173. }
  174. })
  175. } else {
  176. app.util.request({
  177. url: 'entry/wxapp/user',
  178. data: {
  179. controller: 'car.reduce_car_goods',
  180. token: token,
  181. goods_id: goods_id,
  182. community_id: community_id,
  183. quantity: 1,
  184. sku_str: '',
  185. buy_type: 'dan',
  186. pin_id: 0,
  187. is_just_addcar: 1
  188. },
  189. dataType: 'json',
  190. method: 'POST',
  191. success: function (res) {
  192. if (res.data.code == 3) {
  193. wx.showToast({
  194. title: res.data.msg,
  195. icon: 'none',
  196. duration: 2000
  197. })
  198. } else {
  199. that.triggerEvent("changeCartNum", res.data.total);
  200. that.setData({ number: res.data.cur_count })
  201. status.indexListCarCount(goods_id, res.data.cur_count);
  202. }
  203. }
  204. })
  205. }
  206. }
  207. }
  208. });