goods.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. var app = getApp();
  2. var WxParse = require('../../lib/wxParse/wxParse.js');
  3. var util = require('../../utils/util.js');
  4. var api = require('../../config/api.js');
  5. var goodsUtil = require('../../utils/goods.js');
  6. Page({
  7. data: {
  8. winHeight: "",
  9. id: 0,
  10. referrer: 0,
  11. goods: {},
  12. gallery: [],
  13. attribute: [],
  14. issueList: [],
  15. comment: [],
  16. brand: {},
  17. specificationList: [],
  18. productList: [],
  19. relatedGoods: [],
  20. cartGoodsCount: 0,
  21. userHasCollect: 0,
  22. crashList: {},
  23. number: 1,
  24. checkedSpecText: '请选择规格数量',
  25. openAttr: false,
  26. noCollectImage: "/static/images/icon_collect.png",
  27. hasCollectImage: "/static/images/icon_collect_checked.png",
  28. collectBackImage: "/static/images/icon_collect.png",
  29. showNavList: false,
  30. stockNum: '',
  31. cartNumber: 0,
  32. autoplay: false,
  33. defaultFreight: 0,
  34. current: 0,//banner当前的index
  35. isPlay: true,
  36. indexNum: 0,
  37. windowWidth: 0,
  38. leftWidth: 0,
  39. startX:0,
  40. curr_id: '',
  41. videoHiddenName: true,
  42. imgHiddenName: false,
  43. page: 1,
  44. size: 3,
  45. detailContent: '',
  46. storeId: '',
  47. detailStoreId: '',
  48. promId:'',
  49. merchSn: '',
  50. openTicketAttr: false,
  51. ticketDiscountList:[],
  52. discountSize: 9999,//查看全部
  53. discountDetailSize: 3,//详情查看部分
  54. },
  55. toggleNav() {
  56. this.setData({
  57. showNavList: !this.data.showNavList
  58. })
  59. },
  60. switchNav(event) {
  61. let name = event.currentTarget.dataset.name;
  62. wx.switchTab({
  63. url: `/pages/${name}/${name}`,
  64. });
  65. },
  66. //小程序里的转义方法
  67. escape2Html: function (str) {
  68. var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
  69. return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) { return arrEntities[t]; });
  70. },
  71. //调用在需要的地方直接调用即可。如:this.escape2Html(contents)
  72. getGoodsInfo: function () {
  73. wx.showLoading({
  74. title: '加载中...',
  75. });
  76. setTimeout(function () {
  77. }, 350)
  78. let that = this;
  79. const regex = new RegExp('<img', 'gi');
  80. console.log('分享的storeId' + wx.getStorageSync('storeId'))
  81. // console.log('promId' + that.data.promId)
  82. util.request(api.GoodsDetail, { id: that.data.id, referrer: that.data.referrer,
  83. merchSn: wx.getStorageSync('merchSn'), storeId: wx.getStorageSync('storeId'), promId: that.data.promId }).then(function (res) {
  84. if (res.errno === 0) {
  85. that.setData({
  86. goods: res.data.info,
  87. gallery: res.data.gallery,
  88. attribute: res.data.attribute,
  89. issueList: res.data.issue,
  90. comment: res.data.comment,
  91. brand: res.data.brand,
  92. specificationList: res.data.specificationList,
  93. productList: res.data.productList,
  94. userHasCollect: res.data.userHasCollect,
  95. stockNum: res.data.stockNum,
  96. cartNumber: res.data.cartNumber,
  97. defaultFreight: res.data.defaultFreight,
  98. checkedSpecText: res.data.specificationList[0].valueList[0].value,
  99. detailContent: that.escape2Html(res.data.info.goods_desc).replace(regex, `<img style="width: 100%;"`),
  100. detailStoreId:res.data.info.storeId,
  101. merchSn: res.data.info.merchSn
  102. });
  103. that.getDetailTicketDiscountList();
  104. if (res.data.userHasCollect == 1) {
  105. that.setData({
  106. 'collectBackImage': that.data.hasCollectImage
  107. });
  108. } else {
  109. that.setData({
  110. 'collectBackImage': that.data.noCollectImage
  111. });
  112. }
  113. // WxParse.wxParse('goodsDetail', 'html', res.data.info.goods_desc, that);
  114. that.getGoodsRelated();
  115. // that.getGoodsCrashList();
  116. //
  117. let _specificationList = that.data.specificationList;
  118. for (let i = 0; i < _specificationList.length; i++) {
  119. if (_specificationList[i].valueList.length == 1) {
  120. //如果已经选中,则反选,前端默认选中
  121. _specificationList[i].valueList[0].checked = true;
  122. }
  123. }
  124. that.setData({
  125. 'specificationList': _specificationList
  126. });
  127. }
  128. wx.hideLoading();
  129. });
  130. if (null != that.data.referrer && that.data.referrer > 0) {
  131. //转发获取优惠券
  132. util.request(api.GoodsTransferCoupon, {
  133. goods_id: that.data.id,
  134. referrer: that.data.referrer,
  135. send_type: 2
  136. }).then(function (res) {
  137. });
  138. }
  139. //商品列表图
  140. util.request(api.GoodsGallery, {
  141. goods_id: that.data.id
  142. }).then(function (res) {
  143. if (res.errno === 0) {
  144. that.setData({
  145. gallery: res.data
  146. })
  147. }
  148. });
  149. },
  150. // getGoodsCrashList: function () {
  151. // let that = this;
  152. // util.request(api.GoodsCrashList, { goodsId: that.data.id }).then(function (res) {
  153. // if (res.errno === 0) {
  154. // that.setData({
  155. // crashList: res.data,
  156. // });
  157. // that.data.crashList.length;
  158. // }
  159. // });
  160. // },
  161. clickSkuValue: function (event) {
  162. let that = this;
  163. let specNameId = event.currentTarget.dataset.nameId;
  164. let specValueId = event.currentTarget.dataset.valueId;
  165. //
  166. let _specificationList = this.data.specificationList;
  167. for (let i = 0; i < _specificationList.length; i++) {
  168. if (_specificationList[i].specification_id == specNameId) {
  169. for (let j = 0; j < _specificationList[i].valueList.length; j++) {
  170. if (_specificationList[i].valueList[j].id == specValueId) {
  171. //如果已经选中,则反选
  172. if (_specificationList[i].valueList[j].checked) {
  173. _specificationList[i].valueList[j].checked = false;
  174. } else {
  175. _specificationList[i].valueList[j].checked = true;
  176. }
  177. } else {
  178. _specificationList[i].valueList[j].checked = false;
  179. }
  180. }
  181. }
  182. }
  183. this.setData({
  184. 'specificationList': _specificationList
  185. });
  186. //重新计算spec改变后的信息
  187. goodsUtil.changeSpecInfo(that);
  188. },
  189. onLoad: function (options) {
  190. // 页面初始化 options为页面跳转所带来的参数
  191. //由渠道推广生成的小程序码带来的参数,格式:商品id&门店id&推广id&用户id
  192. // options.scene = "1181115&20&1&26";
  193. // options.scene = "1181167&12&5&26";
  194. // options.scene = "1181133&12&6&26";
  195. if (options.scene) {
  196. var scene = decodeURIComponent(options.scene);
  197. console.log("scene is ", scene);
  198. var scanArray = scene.split('&');
  199. var id = scanArray[0];
  200. var storeId = scanArray[1];
  201. var promId = scanArray[2];
  202. var referrer = scanArray[3];
  203. console.log("id is ", id);
  204. console.log("storeId is ", storeId);
  205. console.log("promId is ", promId);
  206. console.log("referrer is ", referrer);
  207. this.setData({
  208. id: id,
  209. storeId: storeId,
  210. promId: promId,
  211. referrer: referrer
  212. });
  213. if (storeId) {
  214. wx.setStorageSync('storeId', storeId);
  215. wx.setStorageSync('isShare', 'true');
  216. }
  217. } else {
  218. //由列表页、与普通用户分享点进来带来的参数,商品id,门店id;商品id,门店id,分享用户
  219. this.setData({
  220. id: parseInt(options.id)
  221. });
  222. if (options.storeId) {
  223. this.setData({
  224. storeId: options.storeId
  225. });
  226. wx.setStorageSync('storeId', options.storeId);
  227. }
  228. if (options.referrer) {
  229. this.setData({
  230. referrer: options.referrer
  231. });
  232. wx.setStorageSync('isShare', 'true');
  233. } else {
  234. wx.removeStorageSync('isShare');//由列表页、与普通用户分享点进来则清除是否分享缓存
  235. }
  236. }
  237. var that = this;
  238. // 高度自适应
  239. wx.getSystemInfo({
  240. success: function (res) {
  241. var clientHeight = res.windowHeight,
  242. clientWidth = res.windowWidth,
  243. rpxR = 750 / clientWidth;
  244. var calc = clientHeight * rpxR - 100;
  245. // console.log(calc);
  246. that.setData({
  247. winHeight: calc,
  248. windowWidth: res.windowWidth
  249. });
  250. }
  251. });
  252. },
  253. onReady: function () {
  254. let that = this;
  255. this.videoContext = wx.createVideoContext('myVideo');
  256. // 页面渲染完成
  257. // wx.setClipboardData({
  258. // data: '/pages/goods/goods?id=' + that.data.id,
  259. // success: function (res) {
  260. // wx.getClipboardData({
  261. // success: function (res) {
  262. // // console.log(res.data) // data
  263. // }
  264. // })
  265. // }
  266. // })
  267. },
  268. //购物车增加
  269. addNumber2: function (e) {
  270. let that = this;
  271. var goodsId = e.currentTarget.dataset.goodsId;
  272. var productId = e.currentTarget.dataset.productId;
  273. var hotGoods = that.data.hotGoods;
  274. util.request(api.CartAdd, { goodsId: goodsId, productId: productId, number: 1 }, 'POST').then(function (res) {
  275. if (res.errno === 0 && null != res.data) {
  276. util.request(api.CartGoodsCount).then(function (res) {
  277. if (res.errno === 0) {
  278. that.setData({
  279. cartGoodsCount: res.data.cartTotal.goodsCount
  280. });
  281. }
  282. });
  283. wx.showToast({
  284. title: '添加成功',
  285. icon: 'success',
  286. mask: true
  287. });
  288. } else {
  289. wx.showToast({
  290. title: res.errmsg,
  291. icon: 'none'
  292. })
  293. }
  294. });
  295. },
  296. onShow: function () {
  297. let that = this;
  298. // 页面显示
  299. if (wx.getStorageSync('userInfo') || wx.getStorageSync('token')) {
  300. if (wx.getStorageSync('storeId')) {
  301. util.request(api.ChooseStoreId, {
  302. storeId: wx.getStorageSync('storeId'),
  303. merchSn: wx.getStorageSync('merchSn')
  304. }, 'POST').then(function (res) {
  305. if (res.errno === 0) {
  306. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  307. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  308. that.reLoad();
  309. that.getGoodsInfo();
  310. util.request(api.CartGoodsCount, { storeId: wx.getStorageSync('storeId') }).then(function (res) {
  311. if (res.errno === 0) {
  312. that.setData({
  313. cartGoodsCount: res.data.cartTotal.goodsCount
  314. });
  315. }
  316. });
  317. }
  318. });
  319. }
  320. } else {
  321. wx.navigateTo({
  322. url: '/pages/auth/btnAuth/btnAuth',
  323. })
  324. }
  325. },
  326. onHide: function () {
  327. // 页面隐藏
  328. },
  329. onUnload: function () {
  330. // 页面关闭
  331. },
  332. switchAttrPop: function () {
  333. this.setData({
  334. openAttr: !this.data.openAttr,
  335. openTicketAttr: false
  336. })
  337. },
  338. hideSwitchAttrPop: function() {
  339. this.setData({
  340. openAttr: false,
  341. openTicketAttr: false
  342. })
  343. },
  344. reLoad: function () {
  345. let that = this;
  346. if (wx.getStorageSync('storeId')) {
  347. if (wx.getStorageSync('userId')) {
  348. wx.request({
  349. url: api.updateLoginUser,
  350. data: {
  351. userId: wx.getStorageSync('userId'), storeId: wx.getStorageSync('storeId'), merchSn: wx.getStorageSync('merchSn')
  352. },
  353. method: 'POST',
  354. header: {
  355. 'Content-Type': 'application/json'
  356. },
  357. success: function (wxRes) {
  358. if (wxRes.data.errno === 0) {
  359. // console.log("用户信息更新成功");
  360. }
  361. },
  362. fail: function (err) {
  363. console.log("failed");
  364. }
  365. });
  366. }
  367. }
  368. },
  369. changeProperty: function (e) {
  370. var propertyName = e.currentTarget.dataset.propertyName;
  371. console.log(propertyName);
  372. },
  373. closeAttrOrCollect: function () {
  374. let that = this;
  375. //添加或是取消收藏
  376. util.request(api.CollectAddOrDelete, { typeId: 0, valueId: this.data.id }, "POST")
  377. .then(function (res) {
  378. let _res = res;
  379. if (_res.errno == 0) {
  380. if (_res.data.type == 'add') {
  381. that.setData({
  382. 'collectBackImage': that.data.hasCollectImage
  383. });
  384. wx.showToast({
  385. title: "收藏成功",
  386. mask: true
  387. });
  388. } else {
  389. that.setData({
  390. 'collectBackImage': that.data.noCollectImage
  391. });
  392. wx.showToast({
  393. title: "收藏取消",
  394. mask: true
  395. });
  396. }
  397. } else {
  398. wx.showToast({
  399. image: '/static/images/icon_error.png',
  400. title: _res.errmsg,
  401. mask: true
  402. });
  403. }
  404. });
  405. },
  406. openCartPage: function () {
  407. wx.switchTab({
  408. url: '/pages/cart/cart',
  409. });
  410. },
  411. addToCart: function () {
  412. var that = this;
  413. if (this.data.openAttr == false) {
  414. //打开规格选择窗口
  415. this.setData({
  416. openAttr: !this.data.openAttr
  417. });
  418. } else {
  419. //提示选择完整规格
  420. if (!goodsUtil.isCheckedAllSpec(that)) {
  421. return false;
  422. }
  423. if (that.data.number + that.data.cartNumber > that.data.stockNum){
  424. // wx.showToast({
  425. // title: '库存不足',
  426. // mask: true
  427. // });
  428. util.showErrorToast('库存不足');
  429. //找不到对应的product信息,提示没有库存
  430. return false;
  431. }
  432. // console.log(that.data.productList)
  433. // //根据选中的规格,判断是否有对应的sku信息
  434. let checkedProduct = goodsUtil.getCheckedProductItem(goodsUtil.getCheckedSpecKey(that), that);
  435. // console.log(goodsUtil.getCheckedSpecKey(that))
  436. if (!checkedProduct || checkedProduct.length <= 0) {
  437. wx.showToast({
  438. title: '库存不足',
  439. icon: 'none'
  440. });
  441. //找不到对应的product信息,提示没有库存
  442. return false;
  443. }
  444. //验证库存
  445. // if (checkedProduct.goods_number < this.data.number) {
  446. // //找不到对应的product信息,提示没有库存
  447. // return false;
  448. // }
  449. //添加到购物车
  450. util.request(api.CartAdd, {
  451. goodsId: this.data.goods.id,
  452. number: this.data.number,
  453. productId: checkedProduct[0].id,
  454. promId: that.data.promId
  455. }, "POST")
  456. .then(function (res) {
  457. let _res = res;
  458. if (_res.errno == 0) {
  459. wx.showToast({
  460. title: '添加成功'
  461. });
  462. that.setData({
  463. openAttr: !that.data.openAttr,
  464. cartGoodsCount: _res.data.cartTotal.goodsCount
  465. });
  466. if (that.data.userHasCollect == 1) {
  467. that.setData({
  468. 'collectBackImage': that.data.hasCollectImage
  469. });
  470. } else {
  471. that.setData({
  472. 'collectBackImage': that.data.noCollectImage
  473. });
  474. }
  475. } else {
  476. wx.showToast({
  477. title: _res.errmsg,
  478. icon: 'none'
  479. })
  480. that.hideSwitchAttrPop();
  481. // that.setData({
  482. // stockNum: 0
  483. // });
  484. }
  485. });
  486. }
  487. },
  488. cutNumber: function () {
  489. this.setData({
  490. number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
  491. });
  492. },
  493. addNumber: function () {
  494. this.setData({
  495. number: this.data.number + 1
  496. });
  497. },
  498. onShareAppMessage: function () {
  499. var that = this;
  500. // console.log("url:" + that.data.goods.list_pic_url);
  501. var userId = wx.getStorageSync('userId');
  502. console.log("userId:" + userId);
  503. console.log("detailStoreId:" + that.data.detailStoreId);
  504. console.log("merchSn:" + that.data.merchSn);
  505. console.log("promId:" + that.data.promId);
  506. var requestUrl = "";
  507. if (that.data.promId) {
  508. requestUrl = '/pages/goods/goods?scene='+that.data.id+'&'+that.data.detailStoreId+'&'+ that.data.promId
  509. + '&' + wx.getStorageSync('userId');
  510. } else {
  511. requestUrl = '/pages/goods/goods?id=' + that.data.id + '&&referrer=' + wx.getStorageSync('userId')
  512. + '&&storeId=' + that.data.detailStoreId
  513. + '&&merchSn=' + that.data.merchSn;
  514. }
  515. // console.log("requestUrl:" + requestUrl);
  516. return {
  517. title: '商品详情',
  518. desc: null != that.data.goods.name ? that.data.goods.name : "商品详情",
  519. imageUrl: that.data.goods.list_pic_url,
  520. path: requestUrl,
  521. success: function (res) {
  522. // console.log("转发成功");
  523. console.log("转发成功12:"+that.data.promId);
  524. if (that.data.promId){
  525. //转发成功记录推广信息转发次数
  526. wx.request({
  527. url: api.GoodsSaveTransNum,
  528. data: {
  529. referrer: wx.getStorageSync('userId'),
  530. storeId: that.data.detailStoreId,
  531. promId: that.data.promId
  532. },
  533. method: 'POST',
  534. header: { 'Content-Type': 'application/json' },
  535. success: function (wxRes) {
  536. console.log("转发成功");
  537. }
  538. });
  539. }
  540. },
  541. fail: function (res) {
  542. console.log("转发失败");
  543. }
  544. }
  545. },
  546. //购物车增加
  547. addCrashNumber: function (e) {
  548. let that = this;
  549. var goodsId = e.currentTarget.dataset.goodsId;
  550. var productId = e.currentTarget.dataset.productId;
  551. util.request(api.CartAdd, { goodsId: goodsId, productId: productId, number: 1 }, 'POST').then(function (res) {
  552. if (res.errno === 0 && null != res.data) {
  553. var hotGoods = that.data.hotGoods;
  554. hotGoods.forEach(function (val, index, arr) {
  555. if (val.id == goodsId) {
  556. val.cart_num = res.data;
  557. hotGoods[index] = val;
  558. that.setData({ hotGoods: hotGoods });
  559. }
  560. }, that);
  561. }
  562. });
  563. },
  564. previewPic(e) {
  565. let url = e.currentTarget.dataset.url;
  566. let urls = [];
  567. urls[0] = url;
  568. wx.previewImage({
  569. urls
  570. })
  571. },
  572. switchNav(event) {
  573. wx.switchTab({
  574. url: '/pages/index/index'
  575. });
  576. },
  577. //触摸事件start
  578. touchStart(e) {
  579. let startX = e.changedTouches[0].pageX
  580. this.setData({
  581. startX: startX
  582. })
  583. console.log("startX:" + startX);
  584. },
  585. //触摸事件end
  586. touchEnd(e) {
  587. let _self = this;
  588. let windowWidth = this.data.windowWidth;
  589. let moveWidth = e.changedTouches[0].pageX - this.data.startX;
  590. let defineWidth = windowWidth / 20;
  591. let rankList = this.data.gallery;
  592. let index_now = e.currentTarget.dataset.index;
  593. if (moveWidth >= defineWidth) {
  594. //上一张
  595. let transWidth = (index_now - 1) * (-this.data.windowWidth);
  596. if (index_now >= 1) {
  597. this.setData({
  598. indexNum: index_now - 1,
  599. rankList: rankList,
  600. leftWidth: transWidth
  601. })
  602. }
  603. } else if (moveWidth <= (0 - defineWidth)) {
  604. //下一张
  605. this.videoContext.pause();
  606. let transWidth = (index_now + 1) * (-this.data.windowWidth);
  607. if (index_now < rankList.length - 1) {
  608. this.setData({
  609. indexNum: index_now + 1,
  610. rankList: rankList,
  611. leftWidth: transWidth
  612. })
  613. }
  614. } else {
  615. //console.log('不能修改样式')
  616. }
  617. },
  618. videoPlay(e) {
  619. // if (this.data.curr_id == e.currentTarget.dataset.id) {
  620. // this.setData({
  621. // curr_id: 0,
  622. // })
  623. // } else {
  624. // this.setData({
  625. // curr_id: e.currentTarget.dataset.id,
  626. // })
  627. // }
  628. this.setData({
  629. imgHiddenName: true,
  630. videoHiddenName: false
  631. })
  632. this.videoContext.play();
  633. },
  634. //触摸事件start
  635. touchStart2(e) {
  636. },
  637. touchEnd2(e) {
  638. this.setData({
  639. curr_id: 0,
  640. imgHiddenName: false,
  641. videoHiddenName: true
  642. })
  643. this.videoContext.pause();
  644. },
  645. getGoodsRelated: function () {
  646. let that = this;
  647. util.request(api.GoodsRelated, { id: that.data.id, page: that.data.page, size: that.data.size }).then(function (res) {
  648. if (res.errno === 0) {
  649. let goodsList = that.data.relatedGoods.concat(res.data.goodsList);
  650. that.setData({
  651. relatedGoods: goodsList,
  652. });
  653. }
  654. });
  655. },
  656. onReachBottom() {
  657. var that = this;
  658. wx.showLoading({
  659. title: '加载中...',
  660. })
  661. that.setData({
  662. page: that.data.page + 1
  663. });
  664. that.getGoodsRelated();
  665. },
  666. switchTicketPop: function () {
  667. this.setData({
  668. openTicketAttr: !this.data.openTicketAttr,
  669. openAttr: false
  670. })
  671. this.getTicketDiscountList();
  672. },
  673. hideSwitchTicketPop: function () {
  674. this.setData({
  675. openTicketAttr: false,
  676. openAttr: false
  677. })
  678. },
  679. /**
  680. * 领取优惠券
  681. */
  682. getUserCoupon(event) {
  683. var that = this;
  684. let tickDiscId = event.currentTarget.dataset.couponId;
  685. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  686. let storeId = that.data.storeId;
  687. util.request(api.getUserCoupon, {
  688. tickDiscId: tickDiscId,
  689. storeTopicId: storeTopicId,
  690. storeId: storeId
  691. }, 'POST').then(function (res) {
  692. if (res.errno === 0) {
  693. wx.showToast({
  694. title: '领取成功'
  695. });
  696. that.setData({
  697. discStatus: 0
  698. });
  699. that.getTicketDiscountList();
  700. } else {
  701. wx.showToast({
  702. title: res.errmsg,
  703. icon: 'none'
  704. })
  705. }
  706. });
  707. },
  708. /**
  709. * 查看优惠券列表
  710. */
  711. getTicketDiscountList() {
  712. let that = this;
  713. util.request(api.DiscountByGoodsIdList, {
  714. storeId: that.data.storeId,
  715. goodsId: that.data.id,
  716. size: that.data.discountSize
  717. }).then(function (res) {
  718. if (res.errno === 0) {
  719. that.setData({
  720. ticketDiscountList: res.data
  721. });
  722. }
  723. });
  724. },
  725. /**
  726. * 查看优惠券列表,详情页展示
  727. */
  728. getDetailTicketDiscountList() {
  729. let that = this;
  730. util.request(api.DiscountByGoodsIdList, {
  731. storeId: that.data.storeId,
  732. goodsId: that.data.id,
  733. size: that.data.discountDetailSize
  734. }).then(function (res) {
  735. if (res.errno === 0) {
  736. that.setData({
  737. detailTicketDiscountList: res.data
  738. });
  739. }
  740. });
  741. },
  742. })