menuGoodsItem.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. needAuth: {
  60. type: Boolean,
  61. value: false
  62. },
  63. is_open_vipcard_buy: {
  64. type: Number,
  65. value: 0
  66. }
  67. },
  68. attached() {
  69. this.setData({ placeholdeImg: app.globalData.placeholdeImg })
  70. },
  71. data: {
  72. disabled: false,
  73. placeholdeImg: '',
  74. number: 0
  75. },
  76. ready: function () {
  77. this.setData({
  78. number: this.data.spuItem.car_count || 0
  79. });
  80. },
  81. methods: {
  82. openSku: function () {
  83. if (this.data.needAuth) {
  84. this.triggerEvent("authModal", true);
  85. return;
  86. }
  87. this.setData({
  88. stopClick: true,
  89. disabled: false
  90. })
  91. if (this.data.spuItem.skuList.length === void 0) {
  92. this.triggerEvent("openSku", {
  93. actId: this.data.spuItem.actId,
  94. skuList: this.data.spuItem.skuList,
  95. promotionDTO: this.data.spuItem.promotionDTO,
  96. allData: {
  97. spuName: this.data.spuItem.spuName,
  98. skuImage: this.data.spuItem.skuImage,
  99. actPrice: this.data.spuItem.actPrice,
  100. canBuyNum: this.data.spuItem.spuCanBuyNum,
  101. stock: this.data.spuItem.spuCanBuyNum,
  102. marketPrice: this.data.spuItem.marketPrice
  103. }
  104. });
  105. } else {
  106. this.addCart({ value: 1, type: "plus" });
  107. }
  108. },
  109. countDownEnd: function () {
  110. this.setData({
  111. actEnd: true
  112. });
  113. },
  114. submit2: function (e) {
  115. (0, t.collectFormIds)(e.detail.formId);
  116. },
  117. changeNumber: function (t) {
  118. var e = t.detail;
  119. e && this.addCart(e);
  120. },
  121. outOfMax: function (t) {
  122. var e = t.detail, canBuyNum = this.data.spuItem.spuCanBuyNum;
  123. if (this.data.number >= canBuyNum) {
  124. wx.showToast({
  125. title: "不能购买更多啦",
  126. icon: "none"
  127. })
  128. }
  129. },
  130. addCart: function (t) {
  131. // {value: 2, type: "plus/minus"}
  132. var token = wx.getStorageSync('token');
  133. var community = wx.getStorageSync('community');
  134. var goods_id = this.data.spuItem.actId;
  135. var community_id = community.communityId;
  136. let that = this;
  137. if (t.type == 'plus') {
  138. let data = {
  139. goods_id,
  140. community_id,
  141. quantity: 1,
  142. sku_str: '',
  143. buy_type: 'dan',
  144. pin_id: 0,
  145. is_just_addcar: 1
  146. }
  147. util.addCart(data).then(res=>{
  148. if(res.showVipModal==1) {
  149. let { pop_vipmember_buyimage } = res.data;
  150. that.triggerEvent("vipModal", { pop_vipmember_buyimage, showVipModal: true, visible: false });
  151. } else {
  152. if (res.data.code == 3) {
  153. let max_quantity = res.data.max_quantity || '';
  154. (max_quantity > 0) && that.setData({ number: max_quantity })
  155. wx.showToast({
  156. title: res.data.msg,
  157. icon: 'none',
  158. duration: 2000
  159. })
  160. } else if (res.data.code == 4) {
  161. that.setData({ needAuth: true })
  162. that.triggerEvent("authModal", true);
  163. } else if (res.data.code == 6 || res.data.code == 7) {
  164. let max_quantity = res.data.max_quantity || '';
  165. (max_quantity > 0) && that.setData({ number: max_quantity })
  166. var msg = res.data.msg;
  167. wx.showToast({
  168. title: msg,
  169. icon: 'none',
  170. duration: 2000
  171. })
  172. } else {
  173. that.triggerEvent("changeCartNum", res.data.total);
  174. that.setData({ number: res.data.cur_count })
  175. wx.showToast({
  176. title: "已加入购物车",
  177. image: "../../images/addShopCart.png"
  178. })
  179. status.indexListCarCount(goods_id, res.data.cur_count);
  180. }
  181. }
  182. })
  183. } else {
  184. app.util.request({
  185. url: 'entry/wxapp/user',
  186. data: {
  187. controller: 'car.reduce_car_goods',
  188. token: token,
  189. goods_id: goods_id,
  190. community_id: community_id,
  191. quantity: 1,
  192. sku_str: '',
  193. buy_type: 'dan',
  194. pin_id: 0,
  195. is_just_addcar: 1
  196. },
  197. dataType: 'json',
  198. method: 'POST',
  199. success: function (res) {
  200. if (res.data.code == 3) {
  201. wx.showToast({
  202. title: res.data.msg,
  203. icon: 'none',
  204. duration: 2000
  205. })
  206. } else if (res.data.code == 4) {
  207. that.setData({ needAuth: true })
  208. that.triggerEvent("authModal", true);
  209. } else {
  210. that.triggerEvent("changeCartNum", res.data.total);
  211. that.setData({ number: res.data.cur_count })
  212. status.indexListCarCount(goods_id, res.data.cur_count);
  213. }
  214. }
  215. })
  216. }
  217. }
  218. }
  219. });