index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. var t = require("../../utils/public");
  2. var app = getApp();
  3. var status = require('../../utils/index.js');
  4. var util = require('../../utils/util.js');
  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. bigImg: '',
  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. // {value: 2, type: "plus/minus"}
  121. var token = wx.getStorageSync('token');
  122. var community = wx.getStorageSync('community');
  123. var goods_id = this.data.spuItem.actId;
  124. var community_id = community.communityId;
  125. let that = this;
  126. if (t.type == 'plus') {
  127. app.util.request({
  128. url: 'entry/wxapp/user',
  129. data: {
  130. controller: 'car.add',
  131. token: token,
  132. goods_id: goods_id,
  133. community_id: community_id,
  134. quantity: 1,
  135. sku_str: '',
  136. buy_type: 'dan',
  137. pin_id: 0,
  138. is_just_addcar: 1
  139. },
  140. dataType: 'json',
  141. method: 'POST',
  142. success: function (res) {
  143. if (res.data.code == 3) {
  144. let max_quantity = res.data.max_quantity || '';
  145. (max_quantity > 0) && that.setData({ number: max_quantity })
  146. wx.showToast({
  147. title: res.data.msg,
  148. icon: 'none',
  149. duration: 2000
  150. })
  151. } else if (res.data.code == 6) {
  152. let max_quantity = res.data.max_quantity || '';
  153. (max_quantity > 0) && that.setData({ number: max_quantity })
  154. var msg = res.data.msg;
  155. wx.showToast({
  156. title: msg,
  157. icon: 'none',
  158. duration: 2000
  159. })
  160. } else {
  161. console.log(res)
  162. that.triggerEvent("changeCartNum", res.data.total);
  163. that.setData({ number: res.data.cur_count })
  164. wx.showToast({
  165. title: "已加入购物车",
  166. image: "../../images/addShopCart.png"
  167. })
  168. status.indexListCarCount(goods_id, res.data.cur_count);
  169. }
  170. }
  171. })
  172. } else {
  173. app.util.request({
  174. url: 'entry/wxapp/user',
  175. data: {
  176. controller: 'car.reduce_car_goods',
  177. token: token,
  178. goods_id: goods_id,
  179. community_id: community_id,
  180. quantity: 1,
  181. sku_str: '',
  182. buy_type: 'dan',
  183. pin_id: 0,
  184. is_just_addcar: 1
  185. },
  186. dataType: 'json',
  187. method: 'POST',
  188. success: function (res) {
  189. if (res.data.code == 3) {
  190. wx.showToast({
  191. title: res.data.msg,
  192. icon: 'none',
  193. duration: 2000
  194. })
  195. } else {
  196. that.triggerEvent("changeCartNum", res.data.total);
  197. that.setData({ number: res.data.cur_count })
  198. status.indexListCarCount(goods_id, res.data.cur_count);
  199. }
  200. }
  201. })
  202. }
  203. }
  204. }
  205. });