goods.js 25 KB

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