goods.js 25 KB

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