1
0

cart.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. var util = require('../../utils/util.js');
  2. var goodsUtil = require('../../utils/goods.js');
  3. var api = require('../../config/api.js');
  4. var app = getApp();
  5. Page({
  6. data: {
  7. cartGoods00: [], //保税仓数据
  8. cartGoods02: [], //保税展示数据
  9. cartGoods10: [], //现场速递数据
  10. cartGoods11: [], //普通商品
  11. cartGoods: [],
  12. validCartList: [],
  13. goodsBizTypeList: ['保税仓', '保税展示', '现场速递', '普通商品'],
  14. goodsBizType: '', //货品业务类型
  15. footprintList: [],
  16. cartTotal: {
  17. "goodsCount": 0,
  18. "goodsAmount": 0.00,
  19. "checkedGoodsCount": 0,
  20. "checkedGoodsAmount": 0.00
  21. },
  22. checkedAllStatus: true,
  23. checkedTypeStatus00: true,
  24. checkedTypeStatus02: true,
  25. checkedTypeStatus10: true,
  26. checkedTypeStatus11: true,
  27. couponInfoList: [],
  28. openAttr: false,
  29. specificationList: {},
  30. checkedSpecText: '请选择规格数量',
  31. number: 1,
  32. isAdd: true,
  33. mobile: '',
  34. retailPrice: '',
  35. stockNum: 0,
  36. cartNumber: 0,
  37. checkCart: app.globalData.appCheckCart,
  38. total00: 0,
  39. total11: 0,
  40. page: 1,
  41. size: 4,
  42. openTicketAttr: false,
  43. ticketDiscountList: [],
  44. ticketDiscountTotal: 0
  45. },
  46. onLoad: function(options) {
  47. // 页面初始化 options为页面跳转所带来的参数
  48. },
  49. onReady: function() {
  50. // 页面渲染完成
  51. },
  52. onShow: function () {
  53. let that = this;
  54. that.setData({
  55. checkCart: app.globalData.appCheckCart
  56. });
  57. // 页面显示
  58. if (wx.getStorageSync('userInfo') || wx.getStorageSync('token')) {
  59. if (wx.getStorageSync('storeId')) {
  60. util.request(api.ChooseStoreId, {
  61. storeId: wx.getStorageSync('storeId'),
  62. merchSn: wx.getStorageSync('merchSn')
  63. }, 'POST').then(function (res) {
  64. if (res.errno === 0) {
  65. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  66. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  67. that.reLoad();
  68. }
  69. });
  70. that.setData({
  71. footprintList: [],
  72. page: 1
  73. });
  74. that.getCartList();
  75. that.getTicketDiscountList();
  76. that.getFootprintList();
  77. }
  78. } else {
  79. wx.navigateTo({
  80. url: '/pages/auth/btnAuth/btnAuth',
  81. })
  82. }
  83. },
  84. openSortFilter: function(event) {
  85. let that = this;
  86. let currentId = event.currentTarget.id;
  87. switch (currentId) {
  88. case 'defaultActivity':
  89. that.setData({
  90. 'checkCart': '00',
  91. footprintList: [],
  92. page: 1
  93. });
  94. app.globalData.appCheckCart = '00';
  95. this.getCartList();
  96. this.getFootprintList();
  97. break;
  98. case 'ordActivity':
  99. that.setData({
  100. 'checkCart': '11',
  101. footprintList: [],
  102. page: 1
  103. });
  104. app.globalData.appCheckCart = '11';
  105. this.getCartList();
  106. this.getFootprintList();
  107. break;
  108. default:
  109. //综合排序
  110. that.setData({
  111. 'checkCart': '00',
  112. footprintList: [],
  113. page: 1
  114. });
  115. app.globalData.appCheckCart = '00';
  116. this.getCartList();
  117. this.getFootprintList();
  118. }
  119. },
  120. onHide: function() {
  121. // 页面隐藏
  122. },
  123. onUnload: function() {
  124. // 页面关闭
  125. },
  126. reLoad: function () {
  127. let that = this;
  128. if (wx.getStorageSync('storeId')) {
  129. if (wx.getStorageSync('userId')) {
  130. wx.request({
  131. url: api.updateLoginUser,
  132. data: {
  133. userId: wx.getStorageSync('userId'), storeId: wx.getStorageSync('storeId'), merchSn: wx.getStorageSync('merchSn')
  134. },
  135. method: 'POST',
  136. header: {
  137. 'Content-Type': 'application/json'
  138. },
  139. success: function (wxRes) {
  140. if (wxRes.data.errno === 0) {
  141. // console.log("用户信息更新成功");
  142. }
  143. },
  144. fail: function (err) {
  145. console.log("failed");
  146. }
  147. });
  148. }
  149. }
  150. },
  151. setCommonData(res) {
  152. let that = this;
  153. that.setData({
  154. cartGoods: res.data.cartList,
  155. cartGoods00: res.data.cart00List,
  156. cartGoods02: res.data.cart02List,
  157. cartGoods10: res.data.cart10List,
  158. cartGoods11: res.data.cart11List,
  159. validCartList: res.data.validCartList,
  160. cartTotal: res.data.cartTotal,
  161. couponInfoList: res.data.couponInfoList,
  162. total00: res.data.total00,
  163. total11: res.data.total11,
  164. ticketDiscountTotal: res.data.ticketDiscountTotal
  165. });
  166. },
  167. setCheckedData() {
  168. let that = this;
  169. that.setData({
  170. checkedAllStatus: that.isCheckedAll(),
  171. checkedTypeStatus00: that.isCheckedTypeStatus00(),
  172. checkedTypeStatus02: that.isCheckedTypeStatus02(),
  173. checkedTypeStatus10: that.isCheckedTypeStatus10(),
  174. checkedTypeStatus11: that.isCheckedTypeStatus11()
  175. });
  176. },
  177. setCheckedAllData() {
  178. let that = this;
  179. that.setData({
  180. checkedAllStatus: that.isCheckedAll(),
  181. checkedTypeStatus00: that.isCheckedAll(),
  182. checkedTypeStatus02: that.isCheckedAll(),
  183. checkedTypeStatus10: that.isCheckedAll(),
  184. checkedTypeStatus11: that.isCheckedAll()
  185. });
  186. },
  187. getCartList: function() { //获取购物车数据
  188. let that = this;
  189. wx.showLoading({
  190. title: '加载中...',
  191. });
  192. console.log('分享的storeId' + wx.getStorageSync('storeId'))
  193. util.request(api.CartList, {
  194. checkCart: that.data.checkCart,
  195. storeId: wx.getStorageSync('storeId')
  196. }).then(function(res) {
  197. if (res.errno === 0) {
  198. that.setCommonData(res);
  199. }
  200. wx.hideLoading();
  201. //数据渲染选中
  202. that.setCheckedData();
  203. });
  204. },
  205. isCheckedAll: function() {
  206. //判断购物车所有商品是否已全选
  207. return this.data.cartGoods.every(function(element, index, array) {
  208. if (element.checked == true) {
  209. return true;
  210. } else {
  211. return false;
  212. }
  213. });
  214. },
  215. isCheckedTypeStatus00: function() {
  216. //判断该业务类型的购物车商品是否已全选
  217. return this.data.cartGoods00.every(function(element, index, array) {
  218. if (element.checked == true) {
  219. return true;
  220. } else {
  221. return false;
  222. }
  223. });
  224. },
  225. isCheckedTypeStatus02: function() {
  226. //判断该业务类型的购物车商品是否已全选
  227. return this.data.cartGoods02.every(function(element, index, array) {
  228. if (element.checked == true) {
  229. return true;
  230. } else {
  231. return false;
  232. }
  233. });
  234. },
  235. isCheckedTypeStatus10: function() {
  236. //判断该业务类型的购物车商品是否已全选
  237. return this.data.cartGoods10.every(function(element, index, array) {
  238. if (element.checked == true) {
  239. return true;
  240. } else {
  241. return false;
  242. }
  243. });
  244. },
  245. isCheckedTypeStatus11: function() {
  246. //判断该业务类型的购物车商品是否已全选
  247. return this.data.cartGoods11.every(function(element, index, array) {
  248. if (element.checked == true) {
  249. return true;
  250. } else {
  251. return false;
  252. }
  253. });
  254. },
  255. toIndexPage: function() {
  256. wx.switchTab({
  257. url: "/pages/index/index"
  258. });
  259. },
  260. checkedItem: function(event) {
  261. let itemIndex = event.target.dataset.itemIndex;
  262. let goodsBizType = event.target.dataset.goodsBizType;
  263. let goodsId = event.target.dataset.goodsId;
  264. let checked = event.target.dataset.checked;
  265. let that = this;
  266. // console.log(goodsBizType);
  267. // console.log(goodsId);
  268. // console.log(that.data.cartGoods[itemIndex].checked);
  269. util.request(api.CartChecked, {
  270. goodsIds: goodsId,
  271. isChecked: checked ? 0 : 1,
  272. checkCart: that.data.checkCart
  273. }, 'POST').then(function(res) {
  274. if (res.errno === 0) {
  275. that.setCommonData(res);
  276. }
  277. that.setCheckedData();
  278. });
  279. },
  280. getCheckedGoodsCount: function() {
  281. let checkedGoodsCount = 0;
  282. this.data.cartGoods.forEach(function(v) {
  283. if (v.checked === true) {
  284. checkedGoodsCount += v.number;
  285. }
  286. });
  287. return checkedGoodsCount;
  288. },
  289. checkedAll: function() {
  290. let that = this;
  291. var goodsIds = this.data.cartGoods.map(function(v) {
  292. return v.goodsIds;
  293. });
  294. util.request(api.CartChecked, {
  295. goodsIds: goodsIds.join(','),
  296. isChecked: that.isCheckedAll() ? 0 : 1
  297. }, 'POST').then(function(res) {
  298. if (res.errno === 0) {
  299. that.setCommonData(res);
  300. }
  301. that.setCheckedAllData();
  302. });
  303. },
  304. checkedAllGoodType: function(e) {
  305. let that = this;
  306. let goodsBizType = e.target.dataset.goodsBizType;
  307. let isCheckedTypeStatu;
  308. let checkCart;
  309. if (goodsBizType == '00') {
  310. isCheckedTypeStatu = that.isCheckedTypeStatus00();
  311. checkCart = '00';
  312. }
  313. if (goodsBizType == '02') {
  314. isCheckedTypeStatu = that.isCheckedTypeStatus02();
  315. checkCart = '00';
  316. }
  317. if (goodsBizType == '10') {
  318. isCheckedTypeStatu = that.isCheckedTypeStatus10();
  319. checkCart = '00';
  320. }
  321. if (goodsBizType == '11') {
  322. isCheckedTypeStatu = that.isCheckedTypeStatus11();
  323. checkCart = '11';
  324. }
  325. util.request(api.CartChecked, {
  326. isChecked: isCheckedTypeStatu ? 0 : 1,
  327. goodsBizType: goodsBizType,
  328. checkCart: checkCart
  329. }, 'POST').then(function(res) {
  330. if (res.errno === 0) {
  331. // that.setCommonData(res);
  332. that.setData({
  333. validCartList: res.data.validCartList,
  334. couponInfoList: res.data.couponInfoList,
  335. ticketDiscountTotal: res.data.ticketDiscountTotal
  336. });
  337. if (goodsBizType == '11') {
  338. that.setData({
  339. cartGoods: res.data.cartList,
  340. cartTotal: res.data.cartTotal,
  341. cartGoods11: res.data.cart11List,
  342. total11: res.data.total11
  343. });
  344. } else {
  345. that.setData({
  346. cartGoods: res.data.cartList,
  347. cartTotal: res.data.cartTotal,
  348. cartGoods00: res.data.cart00List,
  349. cartGoods02: res.data.cart02List,
  350. cartGoods10: res.data.cart10List,
  351. total00: res.data.total00
  352. });
  353. }
  354. }
  355. if (goodsBizType == '00') {
  356. that.setData({
  357. checkedTypeStatus00: that.isCheckedTypeStatus00()
  358. });
  359. }
  360. if (goodsBizType == '02') {
  361. that.setData({
  362. checkedTypeStatus02: that.isCheckedTypeStatus02()
  363. });
  364. }
  365. if (goodsBizType == '10') {
  366. that.setData({
  367. checkedTypeStatus10: that.isCheckedTypeStatus10()
  368. });
  369. }
  370. if (goodsBizType == '11') {
  371. that.setData({
  372. checkedTypeStatus11: that.isCheckedTypeStatus11()
  373. });
  374. }
  375. that.setData({
  376. checkedAllStatus: that.isCheckedAll()
  377. });
  378. });
  379. },
  380. updateCart: function(productId, goodsId, number, beforeNumber, id, itemIndex) {
  381. let that = this;
  382. util.request(api.CartUpdate, {
  383. productId: productId,
  384. goodsId: goodsId,
  385. number: number,
  386. id: id,
  387. checkCart: that.data.checkCart
  388. }, 'POST').then(function(res) {
  389. if (res.errno === 0) {
  390. // console.log(res.data);
  391. that.setCommonData(res);
  392. } else {
  393. // util.showErrorToast(res.errmsg);
  394. wx.showModal({
  395. title: '提示信息',
  396. content: res.errmsg,
  397. showCancel: false
  398. });
  399. let cartItem = that.data.cartGoods[itemIndex];
  400. cartItem.number = beforeNumber;
  401. that.setData({
  402. cartGoods: that.data.cartGoods
  403. });
  404. that.setCommonData(res);
  405. }
  406. that.setCheckedData();
  407. });
  408. },
  409. cutNumber: function (event) {
  410. let goodsBizType = event.target.dataset.goodsBizType;
  411. let cartItem = {};
  412. let itemIndex = event.target.dataset.itemIndex;
  413. if (goodsBizType == '00') {
  414. cartItem = this.data.cartGoods00[itemIndex];
  415. }
  416. if (goodsBizType == '02') {
  417. cartItem = this.data.cartGoods02[itemIndex];
  418. }
  419. if (goodsBizType == '10') {
  420. cartItem = this.data.cartGoods10[itemIndex];
  421. }
  422. if (goodsBizType == '11') {
  423. cartItem = this.data.cartGoods11[itemIndex];
  424. }
  425. let beforeNumber = cartItem.number;
  426. let number = (cartItem.number - 1 > 1) ? cartItem.number - 1 : 1;
  427. cartItem.number = number;
  428. if (goodsBizType == '00') {
  429. this.setData({
  430. cartGoods00: this.data.cartGoods00
  431. });
  432. }
  433. if (goodsBizType == '02') {
  434. this.setData({
  435. cartGoods02: this.data.cartGoods02
  436. });
  437. }
  438. if (goodsBizType == '10') {
  439. this.setData({
  440. cartGoods10: this.data.cartGoods10
  441. });
  442. }
  443. if (goodsBizType == '11') {
  444. this.setData({
  445. cartGoods11: this.data.cartGoods11
  446. });
  447. }
  448. this.updateCart(cartItem.product_id, cartItem.goods_id, number, beforeNumber, cartItem.id, itemIndex);
  449. },
  450. addNumber: function (event) {
  451. let that = this;
  452. let goodsBizType = event.target.dataset.goodsBizType;
  453. let cartItem = {};
  454. let itemIndex = event.target.dataset.itemIndex;
  455. if (goodsBizType == '00') {
  456. cartItem = that.data.cartGoods00[itemIndex];
  457. }
  458. if (goodsBizType == '02') {
  459. cartItem = that.data.cartGoods02[itemIndex];
  460. }
  461. if (goodsBizType == '10') {
  462. cartItem = that.data.cartGoods10[itemIndex];
  463. }
  464. if (goodsBizType == '11') {
  465. cartItem = that.data.cartGoods11[itemIndex];
  466. }
  467. let beforeNumber = cartItem.number;
  468. let number = cartItem.number + 1;
  469. cartItem.number = number;
  470. if (goodsBizType == '00') {
  471. that.setData({
  472. cartGoods00: that.data.cartGoods00
  473. });
  474. }
  475. if (goodsBizType == '02') {
  476. that.setData({
  477. cartGoods02: that.data.cartGoods02
  478. });
  479. }
  480. if (goodsBizType == '10') {
  481. that.setData({
  482. cartGoods10: that.data.cartGoods10
  483. });
  484. }
  485. if (goodsBizType == '11') {
  486. that.setData({
  487. cartGoods11: that.data.cartGoods11
  488. });
  489. }
  490. that.updateCart(cartItem.product_id, cartItem.goods_id, number, beforeNumber, cartItem.id, itemIndex);
  491. },
  492. checkoutOrder: function() {
  493. //获取已选择的商品
  494. let that = this;
  495. util.request(api.getCurUser, {
  496. userInfo: app.globalData.userInfo
  497. }, 'POST').then(function(res) {
  498. if (res.errno === 0) {
  499. // console.log('that.data.mobile:' + res.data.mobile);
  500. if (res.data.mobile == '' || res.data.mobile == null) {
  501. wx.showModal({
  502. title: '',
  503. confirmColor: '#b4282d',
  504. showCancel: false,
  505. content: '您的手机号码未绑定,请先绑定手机号再进行购买',
  506. success: function(res) {
  507. if (res.confirm) {
  508. wx.navigateTo({
  509. url: '../../pages/auth/newuser/newuser'
  510. });
  511. }
  512. }
  513. });
  514. } else {
  515. var checkedGoods = that.data.cartGoods.filter(function(element, index, array) {
  516. if (element.checked == true) {
  517. return true;
  518. } else {
  519. return false;
  520. }
  521. });
  522. if (checkedGoods.length <= 0) {
  523. wx.showToast({
  524. title: '请选择要购买的商品',
  525. icon: 'none'
  526. })
  527. return false;
  528. }
  529. wx.navigateTo({
  530. url: '../shopping/checkout/checkout?checkCart=' + that.data.checkCart
  531. })
  532. }
  533. }
  534. });
  535. },
  536. deleteCart: function(event) {
  537. //获取已选择的商品
  538. let that = this;
  539. let cartId = event.target.dataset.cartId;
  540. let goodsName = event.target.dataset.goodsName;
  541. wx.showModal({
  542. title: '',
  543. content: '确定要删除' + goodsName + '?',
  544. success: function(res) {
  545. if (res.confirm) {
  546. util.request(api.CartDelete, {
  547. cartId: cartId,
  548. checkCart: that.data.checkCart
  549. }, 'POST').then(function(res) {
  550. if (res.errno === 0) {
  551. that.setCommonData(res);
  552. }
  553. that.setCheckedData();
  554. });
  555. console.log('用户点击确定')
  556. }
  557. }
  558. });
  559. },
  560. switchAttrPop: function() {
  561. this.setData({
  562. openAttr: !this.data.openAttr,
  563. openTicketAttr: false
  564. })
  565. console.log(this.data.openTicketAttr);
  566. },
  567. hideSwitchAttrPop: function () {
  568. this.setData({
  569. openAttr: false,
  570. openTicketAttr: false
  571. })
  572. },
  573. clickSkuValue: function(event) {
  574. let that = this;
  575. let specValueId = event.currentTarget.dataset.valueId;
  576. let index = event.currentTarget.dataset.index;
  577. let _specificationList = this.data.specificationList;
  578. for (let j = 0; j < _specificationList[index].valueList.length; j++) {
  579. if (_specificationList[index].valueList[j].id == specValueId) {
  580. //如果已经选中,则反选
  581. if (_specificationList[index].valueList[j].checked) {
  582. _specificationList[index].valueList[j].checked = false;
  583. } else {
  584. _specificationList[index].valueList[j].checked = true;
  585. }
  586. } else {
  587. _specificationList[index].valueList[j].checked = false;
  588. }
  589. }
  590. this.setData({
  591. 'specificationList': _specificationList
  592. });
  593. //重新计算spec改变后的信息
  594. goodsUtil.changeSpecInfo(that);
  595. },
  596. cutNumber2: function() {
  597. this.setData({
  598. number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
  599. });
  600. },
  601. addNumber2: function() {
  602. this.setData({
  603. number: this.data.number + 1
  604. });
  605. },
  606. //购物车增加
  607. addCart: function(e) {
  608. let that = this;
  609. that.setData({
  610. number: 1
  611. });
  612. var goodsId = e.currentTarget.dataset.goodsId;
  613. util.request(api.GoodsSku, {
  614. goodsId: goodsId
  615. }).then(function(res) {
  616. if (res.errno === 0 && null != res.data) {
  617. that.setData({
  618. goodsVo: res.data.goodsVo,
  619. specificationList: res.data.specificationList,
  620. productList: res.data.productList,
  621. openAttr: !that.data.openAttr,
  622. stockNum: res.data.stockNum,
  623. cartNumber: res.data.cartNumber,
  624. checkedSpecText: res.data.specificationList[0].valueList[0].value,
  625. openTicketAttr: false
  626. });
  627. //
  628. let _specificationList = res.data.specificationList;
  629. for (let i = 0; i < _specificationList.length; i++) {
  630. if (_specificationList[i].valueList.length == 1) {
  631. //如果已经选中,则反选
  632. _specificationList[i].valueList[0].checked = true;
  633. }
  634. }
  635. that.setData({
  636. 'specificationList': _specificationList
  637. });
  638. }
  639. });
  640. },
  641. //购物车增加
  642. addToCart: function() {
  643. let that = this;
  644. var goodsId = that.data.goodsVo.id;
  645. //提示选择完整规格
  646. if (!that.data.productList || !that.data.productList.length) {
  647. util.showErrorToast('当前门店没有库存');
  648. return false;
  649. }
  650. //提示选择完整规格
  651. if (!goodsUtil.isCheckedAllSpec(that)) {
  652. return false;
  653. }
  654. //根据选中的规格,判断是否有对应的sku信息
  655. let checkedProduct = goodsUtil.getCheckedProductItem(goodsUtil.getCheckedSpecKey(that), that);
  656. if (!checkedProduct || checkedProduct.length <= 0) {
  657. //找不到对应的product信息,提示没有库存
  658. return false;
  659. }
  660. //验证库存
  661. if (checkedProduct.stock_num < this.data.number) {
  662. //找不到对应的product信息,提示没有库存
  663. return false;
  664. }
  665. util.request(api.CartAdd, {
  666. goodsId: goodsId,
  667. productId: checkedProduct[0].id,
  668. number: this.data.number,
  669. checkCart: that.data.checkCart
  670. }, 'POST').then(function(res) {
  671. if (res.errno === 0 && null != res.data) {
  672. wx.showToast({
  673. title: '添加成功',
  674. icon: 'success',
  675. mask: true
  676. });
  677. that.setData({
  678. openAttr: !that.data.openAttr,
  679. footprintList:[],
  680. page:1
  681. })
  682. // 页面显示
  683. that.getCartList();
  684. that.getFootprintList();
  685. } else {
  686. wx.showToast({
  687. title: res.errmsg,
  688. icon: 'none'
  689. });
  690. that.hideSwitchAttrPop();
  691. }
  692. });
  693. },
  694. deleteValidCart: function() { //获取购物车数据
  695. let that = this;
  696. wx.showModal({
  697. title: '',
  698. content: '确定要清空所有失效商品?',
  699. success: function(res) {
  700. if (res.confirm) {
  701. util.request(api.deleteValidCart, {
  702. checkCart: that.data.checkCart
  703. }).then(function(res) {
  704. if (res.errno === 0) {
  705. that.setCommonData(res);
  706. } else {
  707. util.showErrorToast(res.errmsg);
  708. }
  709. });
  710. }
  711. }
  712. });
  713. },
  714. getFootprintList() {
  715. let that = this;
  716. util.request(api.GuessFootprintList, {
  717. storeId: wx.getStorageSync('storeId'),
  718. checkCart: that.data.checkCart, page: that.data.page, size: that.data.size
  719. }).then(function (res) {
  720. if (res.errno === 0) {
  721. let goodsList = that.data.footprintList.concat(res.data.list);
  722. that.setData({
  723. footprintList: goodsList
  724. });
  725. wx.hideLoading();
  726. }
  727. });
  728. },
  729. onReachBottom() {
  730. var that = this;
  731. if(!that.data.footprintList){
  732. // wx.showLoading({
  733. // title: '加载中...',
  734. // })
  735. }
  736. that.setData({
  737. page: that.data.page + 1
  738. });
  739. that.getFootprintList();
  740. },
  741. switchTicketPop: function () {
  742. this.setData({
  743. openTicketAttr: !this.data.openTicketAttr,
  744. openAttr: false
  745. })
  746. this.getTicketDiscountList();
  747. },
  748. hideSwitchTicketPop: function () {
  749. this.setData({
  750. openTicketAttr: false,
  751. openAttr: false
  752. })
  753. },
  754. hideTicketPop: function () {
  755. this.setData({
  756. openTicketAttr: false
  757. })
  758. },
  759. /**
  760. * 领取优惠券
  761. */
  762. getUserCoupon(event) {
  763. var that = this;
  764. let tickDiscId = event.currentTarget.dataset.couponId;
  765. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  766. let storeId = that.data.storeId;
  767. util.request(api.getUserCoupon, {
  768. tickDiscId: tickDiscId,
  769. storeTopicId: storeTopicId,
  770. storeId: storeId
  771. }, 'POST').then(function (res) {
  772. if (res.errno === 0) {
  773. wx.showToast({
  774. title: '领取成功'
  775. });
  776. that.setData({
  777. discStatus: 0
  778. });
  779. that.getTicketDiscountList();
  780. } else {
  781. wx.showToast({
  782. title: res.errmsg,
  783. icon: 'none'
  784. })
  785. }
  786. });
  787. },
  788. /**
  789. * 查看优惠券列表
  790. */
  791. getTicketDiscountList() {
  792. let that = this;
  793. util.request(api.TicketDiscountList, {
  794. storeId: wx.getStorageSync('storeId')
  795. }).then(function (res) {
  796. if (res.errno === 0) {
  797. that.setData({
  798. ticketDiscountList: res.data
  799. });
  800. }
  801. });
  802. },
  803. })