solitaireGood.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. var app = getApp();
  2. var status = require('../../utils/index.js');
  3. var util = require('../../utils/util.js');
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. spuItem: {
  10. type: Object,
  11. value: {
  12. skuList: []
  13. },
  14. observer: function (t) {
  15. let skuList = t.skuList || [];
  16. let specs = 0;
  17. if (Object.prototype.toString.call(skuList) === '[object Array]') {
  18. if (skuList.length) specs = 1;
  19. } else {
  20. if (Object.keys(skuList).length) specs = 1;
  21. }
  22. this.setData({ specs, number: t.goods_total_count || 0 })
  23. }
  24. },
  25. idx: {
  26. type: Number,
  27. value: -1
  28. },
  29. type: {
  30. type: Number,
  31. value: 0
  32. },
  33. hasIpt: {
  34. type: Boolean,
  35. value: true
  36. },
  37. state: {
  38. type: Boolean,
  39. value: false
  40. },
  41. needAuth: {
  42. type: Boolean,
  43. value: false
  44. },
  45. soliId: {
  46. type: Number,
  47. value: 0
  48. }
  49. },
  50. /**
  51. * 组件的初始数据
  52. */
  53. data: {
  54. number: 0,
  55. placeholdeImg: app.globalData.placeholdeImg,
  56. specs: 0 // 0单规格 1多规格
  57. },
  58. /**
  59. * 组件的方法列表
  60. */
  61. methods: {
  62. handleSelect: function(){
  63. this.triggerEvent("onSelect", this.data.spuItem);
  64. },
  65. handleDelete: function(){
  66. this.triggerEvent("onSelect", this.data.idx);
  67. },
  68. showTip: function(){
  69. let that = this;
  70. wx.showToast({
  71. title: '多规格商品只能去购物车删除',
  72. icon: 'none',
  73. complete: () => {
  74. that.triggerEvent("showCart");
  75. }
  76. })
  77. },
  78. openSku: function () {
  79. if (this.data.needAuth) {
  80. this.triggerEvent("authModal", true);
  81. return;
  82. }
  83. this.setData({
  84. stopClick: true,
  85. disabled: false
  86. })
  87. if (this.data.spuItem.skuList.length === void 0) {
  88. console.log('多规格')
  89. this.triggerEvent("openSku", {
  90. actId: this.data.spuItem.actId,
  91. skuList: this.data.spuItem.skuList,
  92. promotionDTO: this.data.spuItem.promotionDTO,
  93. is_take_vipcard: this.data.spuItem.is_take_vipcard,
  94. is_mb_level_buy: this.data.spuItem.is_mb_level_buy,
  95. allData: {
  96. spuName: this.data.spuItem.spuName,
  97. skuImage: this.data.spuItem.skuImage,
  98. actPrice: this.data.spuItem.actPrice,
  99. canBuyNum: this.data.spuItem.spuCanBuyNum,
  100. stock: this.data.spuItem.spuCanBuyNum,
  101. marketPrice: this.data.spuItem.marketPrice
  102. }
  103. });
  104. } else {
  105. this.addCart({ value: 1, type: "plus" });
  106. }
  107. },
  108. changeNumber: function (t) {
  109. var e = t.detail;
  110. e && this.addCart(e);
  111. },
  112. outOfMax: function (t) {
  113. var e = t.detail, canBuyNum = this.data.spuItem.spuCanBuyNum;
  114. if (this.data.number >= canBuyNum) {
  115. wx.showToast({
  116. title: "不能购买更多啦",
  117. icon: "none"
  118. })
  119. }
  120. },
  121. addCart: function (t) {
  122. // {value: 2, type: "plus/minus"}
  123. let token = wx.getStorageSync('token');
  124. let community = wx.getStorageSync('community');
  125. let goods_id = this.data.spuItem.actId;
  126. let soli_id = this.data.soliId;
  127. let community_id = community.communityId;
  128. let that = this;
  129. if (t.type == 'plus') {
  130. let quantity = 1
  131. if(t.value==1&&this.data.spuItem.goods_start_count>1) {
  132. quantity = this.data.spuItem.goods_start_count;
  133. }
  134. let data = {
  135. goods_id: goods_id,
  136. community_id: community_id,
  137. quantity,
  138. sku_str: '',
  139. buy_type: 'soitaire',
  140. pin_id: 0,
  141. is_just_addcar: 1,
  142. soli_id
  143. }
  144. util.addCart(data).then(res=>{
  145. if(res.showVipModal==1) {
  146. let { pop_vipmember_buyimage } = res.data;
  147. that.triggerEvent("vipModal", { pop_vipmember_buyimage, showVipModal: true, visible: false });
  148. } else {
  149. if (res.data.code == 3) {
  150. let max_quantity = res.data.max_quantity || '';
  151. (max_quantity > 0) && that.setData({ number: that.data.number })
  152. wx.showToast({
  153. title: res.data.msg,
  154. icon: 'none',
  155. duration: 2000
  156. })
  157. } else if (res.data.code == 4) {
  158. that.setData({ needAuth: true })
  159. that.triggerEvent("authModal", true);
  160. } else if (res.data.code == 6 || res.data.code == 7) {
  161. let max_quantity = res.data.max_quantity || '';
  162. (max_quantity > 0) && that.setData({ number: that.data.number })
  163. var msg = res.data.msg;
  164. wx.showToast({
  165. title: msg,
  166. icon: 'none',
  167. duration: 2000
  168. })
  169. } else {
  170. let { goods_total_count, total, cur_count } = res.data;
  171. that.setData({ number: cur_count })
  172. wx.showToast({
  173. title: "已加入购物车",
  174. image: "../../images/addShopCart.png"
  175. })
  176. that.triggerEvent("changeCartNum", { goods_total_count, total, goods_id });
  177. }
  178. }
  179. })
  180. } else {
  181. console.log(t)
  182. let quantity = 1
  183. if(t.value>=1&&this.data.spuItem.goods_start_count==(t.value+1)) {
  184. quantity = this.data.spuItem.goods_start_count;
  185. }
  186. app.util.request({
  187. url: 'entry/wxapp/user',
  188. data: {
  189. controller: 'car.reduce_car_goods',
  190. token: token,
  191. goods_id: goods_id,
  192. community_id: community_id,
  193. quantity,
  194. sku_str: '',
  195. buy_type: 'soitaire',
  196. pin_id: 0,
  197. is_just_addcar: 1,
  198. soli_id
  199. },
  200. dataType: 'json',
  201. method: 'POST',
  202. success: function (res) {
  203. if (res.data.code == 3) {
  204. wx.showToast({
  205. title: res.data.msg,
  206. icon: 'none',
  207. duration: 2000
  208. })
  209. } else if (res.data.code == 4) {
  210. if (that.data.needAuth) {
  211. that.setData({ needAuth: true })
  212. that.triggerEvent("authModal", true);
  213. return;
  214. }
  215. } else {
  216. let { goods_total_count, total, cur_count } = res.data;
  217. that.setData({ number: cur_count })
  218. that.triggerEvent("changeCartNum", { goods_total_count, total, goods_id });
  219. }
  220. }
  221. })
  222. }
  223. }
  224. }
  225. })