goods.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. module.exports = Behavior({
  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. observer: function (t) {
  32. let url = `/lionfish_comshop/pages/goods/goodsDetail?id=${t.actId}`;
  33. // if (t && t.is_video) url = `/lionfish_comshop/moduleA/video/detail?&id=${t.actId}`;
  34. this.setData({ url });
  35. }
  36. },
  37. isPast: {
  38. type: Boolean,
  39. value: false
  40. },
  41. actEnd: {
  42. type: Boolean,
  43. value: false
  44. },
  45. reduction: {
  46. type: Object,
  47. value: {
  48. full_money: '',
  49. full_reducemoney: '',
  50. is_open_fullreduction: 0
  51. }
  52. },
  53. isShowListCount: {
  54. type: Number,
  55. value: 0
  56. },
  57. changeCarCount: {
  58. type: Boolean,
  59. value: false,
  60. observer: function (t) {
  61. if (t) this.setData({ number: this.data.spuItem.car_count || 0 });
  62. }
  63. },
  64. needAuth: {
  65. type: Boolean,
  66. value: false
  67. },
  68. is_open_vipcard_buy: {
  69. type: Number,
  70. value: 0
  71. },
  72. canLevelBuy: {
  73. type: Boolean,
  74. value: false
  75. },
  76. isShowListTimer: {
  77. type: Boolean,
  78. value: true
  79. },
  80. showPickTime: {
  81. type: Boolean,
  82. value: false
  83. },
  84. skin: {
  85. type: Object
  86. },
  87. saleUnit: {
  88. type: String
  89. },
  90. width250: {
  91. type: Boolean,
  92. value: false
  93. },
  94. diyInfo: {
  95. type: Object,
  96. value: {
  97. goodsTag: 'default'
  98. }
  99. }
  100. },
  101. attached() {
  102. this.setData({ placeholdeImg: app.globalData.placeholdeImg})
  103. },
  104. data: {
  105. disabled: false,
  106. placeholdeImg: '',
  107. number: 0,
  108. url: '',
  109. canClick: true
  110. },
  111. ready: function () {
  112. this.setData({
  113. number: this.data.spuItem.car_count || 0
  114. });
  115. },
  116. methods: {
  117. openSku: function() {
  118. if (this.data.needAuth) {
  119. this.triggerEvent("authModal", true);
  120. return;
  121. }
  122. console.log( 'step1');
  123. this.setData({
  124. stopClick:true,
  125. disabled:false
  126. })
  127. let spuItem = this.data.spuItem;
  128. if (this.data.spuItem.skuList.length === void 0) {
  129. this.triggerEvent("openSku", {
  130. actId:spuItem.actId,
  131. skuList: spuItem.skuList,
  132. promotionDTO: spuItem.promotionDTO,
  133. is_take_vipcard: spuItem.is_take_vipcard,
  134. is_mb_level_buy: spuItem.is_mb_level_buy,
  135. allData: {
  136. spuName: spuItem.spuName,
  137. skuImage: spuItem.skuImage,
  138. actPrice: spuItem.actPrice,
  139. canBuyNum: spuItem.spuCanBuyNum,
  140. stock: spuItem.spuCanBuyNum,
  141. marketPrice: spuItem.marketPrice,
  142. oneday_limit_count: spuItem.oneday_limit_count,
  143. total_limit_count: spuItem.total_limit_count,
  144. one_limit_count: spuItem.one_limit_count,
  145. goods_start_count: spuItem.goods_start_count
  146. }
  147. });
  148. } else {
  149. this.addCart({ value: 1, type: "plus" });
  150. }
  151. },
  152. countDownEnd: function() {
  153. this.setData({
  154. actEnd: true
  155. });
  156. },
  157. submit2: function(e) {
  158. (0, t.collectFormIds)(e.detail.formId);
  159. },
  160. changeNumber: function (t) {
  161. var e = t.detail;
  162. e && this.addCart(e);
  163. },
  164. outOfMax: function (t) {
  165. var e = t.detail;
  166. let { spuCanBuyNum, one_limit_count } = this.data.spuItem;
  167. let canBuyNum = spuCanBuyNum<one_limit_count ? spuCanBuyNum: one_limit_count;
  168. if(this.data.number >= canBuyNum) {
  169. wx.showToast({
  170. title: "不能购买更多啦",
  171. icon: "none"
  172. })
  173. }
  174. },
  175. addCart: function (t) {
  176. // {value: 2, type: "plus/minus"}
  177. var token = wx.getStorageSync('token');
  178. var community = wx.getStorageSync('community');
  179. let spuItem = this.data.spuItem;
  180. var goods_id = spuItem.actId;
  181. var community_id = community.communityId;
  182. let { car_count, goods_start_count } = spuItem;
  183. let quantity = 1;
  184. let number = this.data.number || 0;
  185. let that = this;
  186. if (t.type =='plus'){
  187. if(number<goods_start_count) {
  188. quantity = goods_start_count-number;
  189. }
  190. let data = {
  191. goods_id,
  192. community_id,
  193. quantity,
  194. sku_str: '',
  195. buy_type: 'dan',
  196. pin_id: 0,
  197. is_just_addcar: 1
  198. }
  199. util.addCart(data).then(res=>{
  200. if(res.showVipModal==1) {
  201. let { pop_vipmember_buyimage } = res.data;
  202. that.triggerEvent("vipModal", { pop_vipmember_buyimage, showVipModal: true, visible: false });
  203. } else {
  204. if (res.data.code == 3) {
  205. let max_quantity = res.data.max_quantity || '';
  206. (max_quantity > 0) && that.setData({ number: that.data.number })
  207. wx.showToast({
  208. title: res.data.msg,
  209. icon: 'none',
  210. duration: 2000
  211. })
  212. } else if (res.data.code == 4) {
  213. that.setData({ needAuth: true })
  214. that.triggerEvent("authModal", true);
  215. } else if (res.data.code == 6 || res.data.code == 7) {
  216. let max_quantity = res.data.max_quantity || '';
  217. (max_quantity > 0) && that.setData({ number: that.data.number })
  218. var msg = res.data.msg;
  219. wx.showToast({
  220. title: msg,
  221. icon: 'none',
  222. duration: 2000
  223. })
  224. } else {
  225. that.triggerEvent("changeCartNum", res.data.total);
  226. that.setData({ number: res.data.cur_count })
  227. wx.showToast({
  228. title: "已加入购物车",
  229. image: "../../images/addShopCart.png"
  230. })
  231. status.indexListCarCount(goods_id, res.data.cur_count);
  232. }
  233. }
  234. })
  235. } else {
  236. console.log('goods_start_count',goods_start_count)
  237. console.log('number',number)
  238. if(number<=goods_start_count) {
  239. quantity = number;
  240. }
  241. app.util.request({
  242. url: 'entry/wxapp/user',
  243. data: {
  244. controller: 'car.reduce_car_goods',
  245. token: token,
  246. goods_id: goods_id,
  247. community_id: community_id,
  248. quantity,
  249. sku_str: '',
  250. buy_type: 'dan',
  251. pin_id: 0,
  252. is_just_addcar: 1
  253. },
  254. dataType: 'json',
  255. method: 'POST',
  256. success: function (res) {
  257. if (res.data.code == 3) {
  258. wx.showToast({
  259. title: res.data.msg,
  260. icon: 'none',
  261. duration: 2000
  262. })
  263. } else if (res.data.code == 4) {
  264. if (that.data.needAuth) {
  265. that.setData({ needAuth: true })
  266. that.triggerEvent("authModal", true);
  267. return;
  268. }
  269. } else {
  270. that.triggerEvent("changeCartNum", res.data.total);
  271. that.setData({ number: res.data.cur_count })
  272. status.indexListCarCount(goods_id, res.data.cur_count);
  273. }
  274. }
  275. })
  276. }
  277. },
  278. goDetails: function(t){
  279. if(!this.data.canClick) {
  280. return;
  281. }
  282. let that = this;
  283. this.setData({
  284. canClick: false
  285. });
  286. let goodsid = t.currentTarget.dataset.id || '';
  287. let img = t.currentTarget.dataset.img || '';
  288. let url = '/lionfish_comshop/pages/goods/goodsDetail?id='+goodsid;
  289. util.getStorageImage(img).then(res=>{
  290. wx.navigateTo({
  291. url,
  292. complete: function () {
  293. setTimeout(function () {
  294. that.setData({
  295. canClick: true
  296. });
  297. }, 400);
  298. }
  299. })
  300. }).catch(err=>{
  301. wx.navigateTo({
  302. url,
  303. complete: function () {
  304. setTimeout(function () {
  305. that.setData({
  306. canClick: true
  307. });
  308. }, 400);
  309. }
  310. })
  311. });
  312. }
  313. }
  314. });