金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

955 lines
27 KiB

  1. <template>
  2. <view id="store-cart">
  3. <lf-nav title="购物车"></lf-nav>
  4. <view class="discount-box">
  5. <!--登录状态-->
  6. <view class="is-login" v-if="(is_login && discounts.length) || (is_login && coupons.length)">
  7. <view class="promotion-box">
  8. <view class="promotion" @tap="changeDiscounts" v-if="discounts.length">
  9. <view class="title" :style="'color: ' + config.mainColor + '; border-color: ' + config.mainColor">
  10. {{discounts[0].tags}}
  11. </view>
  12. <view>
  13. {{discounts[0].label}} >
  14. </view>
  15. </view>
  16. </view>
  17. <view class="coupon mx-1px-left" :style="'color: ' + config.mainColor + ';'" @tap="changeCoupons" v-if="coupons.length">
  18. 优惠券
  19. </view>
  20. </view>
  21. <!--未登录状态-->
  22. <div class="no-login" v-if="!is_login" @tap="goLogin">
  23. <div class="left">
  24. <i class="iconfont icon-warning"></i>
  25. <div>
  26. <span>登录</span>后查看是否享受优惠
  27. </div>
  28. </div>
  29. <div class="right">
  30. 登录 >
  31. </div>
  32. </div>
  33. </view>
  34. <view class="no-goods" v-if="list && list.length == 0">
  35. <image mode="widthFix" src="https://cdn.guojiang.club/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20200323164958.png"></image>
  36. </view>
  37. <view class="goods-box" v-if="list && list.length">
  38. <checkbox-group @change="changeCheck">
  39. <view class="goods-item mx-1px-bottom" v-for="(item, index) in list" :key="index">
  40. <view class="input">
  41. <label class="checkbox">
  42. <!-- #ifdef APP-PLUS -->
  43. <checkbox :value="String(index)" color="red" :checked="item.checked"></checkbox>
  44. <!-- #endif -->
  45. <!-- #ifdef MP-WEIXIN -->
  46. <checkbox :value="String(index)" color="#FFFFFF" :checked="item.checked"></checkbox>
  47. <!-- #endif -->
  48. <!-- #ifdef H5 -->
  49. <checkbox :value="String(index)" color="red" :checked="item.checked"></checkbox>
  50. <!-- #endif -->
  51. {{item.value!=undefined?item.value:''}}
  52. </label>
  53. </view>
  54. <view class="img-box" :data-id="item.com_id" @tap.stop="jump">
  55. <image :src="item.img"></image>
  56. </view>
  57. <view class="item-info">
  58. <view class="name" :data-id="item.com_id" @tap.stop="jump">
  59. {{item.name}}
  60. </view>
  61. <view class="money-box" :data-id="item.com_id" @tap.stop="jump">
  62. <view class="model">
  63. {{item.color}} <span v-if="item.color && item.size">,</span> {{item.size}}
  64. </view>
  65. <view class="money">
  66. {{item.total}}
  67. </view>
  68. </view>
  69. <view class="mun-box">
  70. <view class="change-num">
  71. <view class="ul-list-content">
  72. <view class="item" :data-index="index" data-change="0" @tap="changeCount">-</view>
  73. <view class="item"><input type="number" :value="item.qty" :data-index="index" @change="modifyCount" /></view>
  74. <view class="item" :data-index="index" data-change="1" @tap="changeCount">+</view>
  75. </view>
  76. </view>
  77. <view class="remove" @tap="removeFromCart" :data-index="index">
  78. 移除
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </checkbox-group>
  84. </view>
  85. <view class="buy-box">
  86. <label class="checkbox">
  87. <!-- #ifdef APP-PLUS -->
  88. <checkbox value="all" color="red" :checked="allCheck" @tap="selectAll"></checkbox>
  89. <!-- #endif -->
  90. <!-- #ifdef MP-WEIXIN -->
  91. <checkbox value="all" color="#FFFFFF" :checked="allCheck" @tap="selectAll"></checkbox>
  92. <!-- #endif -->
  93. <!-- #ifdef H5 -->
  94. <checkbox value="all" color="red" :checked="allCheck" @tap="selectAll"></checkbox>
  95. <!-- #endif -->
  96. <text>全选</text>
  97. </label>
  98. <view class="money-box">
  99. 商品总计<text>{{select_products.total!=undefined?select_products.total:''}}</text>
  100. </view>
  101. <button class="num-box" :style="'background: ' + config.mainColor" @tap="order" :loading="loading">
  102. 结算<text>{{'('+ select_products.count + ')' || 0}}</text>
  103. </button>
  104. </view>
  105. <!--选择优惠券部分-->
  106. <view class="maks" :class="show_coupons ? 'cur' : ''" @tap="showCoupons">
  107. </view>
  108. <view class="select-coupon-box" :class="show_coupons ? 'cur' : ''">
  109. <view class="select-coupon">
  110. <view class="select-coupon-top">
  111. <view class="title">
  112. 领取优惠券
  113. <view class="close" @tap="showCoupons">
  114. X
  115. </view>
  116. </view>
  117. </view>
  118. <view class="select-coupon-bottom">
  119. <view class="title">
  120. 可领优惠券
  121. </view>
  122. <view class="coupon-box">
  123. <view class="coupon-item" v-for="(item, index) in coupons" :key="index" v-if="item.is_open">
  124. <view class="coupon">
  125. <view class="coupon-left">
  126. <view class="text-wrap">
  127. <view class="text-box">
  128. <view class="text">
  129. <span class="money" v-if="item.action_type.type == 'cash'"></span>
  130. <span class="num">{{ item.action_type.value }}</span>
  131. <span class="money" v-if="item.action_type.type == 'discount'"></span>
  132. </view>
  133. <span class="label text">{{ item.label }}</span>
  134. </view>
  135. </view>
  136. <view class="dot-wrap">
  137. <view class="dot-item">
  138. </view>
  139. <view class="dot-item">
  140. </view>
  141. <view class="dot-item">
  142. </view>
  143. <view class="dot-item">
  144. </view>
  145. <view class="dot-item">
  146. </view>
  147. </view>
  148. </view>
  149. <view class="coupon-right">
  150. <view class="top">
  151. <span>
  152. <span class="type" v-if="item.channel == 'ec'">商店</span>
  153. <span class="type" v-if="item.channel == 'shop'">门店</span>
  154. </span>
  155. <span class="info">{{item.title}}</span>
  156. </view>
  157. <view class="bottom">
  158. <view class="bottom-use">
  159. <view class="tiem-box">
  160. <text>{{item.use_start_time}}{{item.use_end_time}}</text>
  161. </view>
  162. <view class="btn use" :style="'background: ' + config.mainColor + '; border-color: ' + config.mainColor" :data-code="item.code" :data-index="index" v-if="!coupons[index].receive" @tap="getCoupon">
  163. 点击领取
  164. </view>
  165. <view class="btn already" v-else>
  166. 已领取
  167. </view>
  168. </view>
  169. </view>
  170. </view>
  171. </view>
  172. </view>
  173. </view>
  174. </view>
  175. </view>
  176. </view>
  177. <!--查看促销部分-->
  178. <view class="maks" :class="show_discounts ? 'cur' : ''" @tap="showDiscounts">
  179. </view>
  180. <view class="see-discounts-box" :class="show_discounts ? 'cur' : ''">
  181. <view class="select-discounts">
  182. <view class="select-discounts-top">
  183. <view class="title">
  184. 促销
  185. <view class="close" @tap="showDiscounts">
  186. X
  187. </view>
  188. </view>
  189. </view>
  190. <view class="select-discounts-bottom">
  191. <view class="discounts-box">
  192. <view class="disconts-item mx-1px-bottom" v-for="(item, index) in discounts" :key="index">
  193. <view class="discounts-tags-title" :style="'color: ' + config.mainColor + '; border-color: ' + config.mainColor">
  194. {{item.tags}}
  195. </view>
  196. <view class="tags-item">
  197. {{item.label}}
  198. </view>
  199. </view>
  200. </view>
  201. </view>
  202. </view>
  203. </view>
  204. <lf-tabbar></lf-tabbar>
  205. </view>
  206. </template>
  207. <script>
  208. import {pageLogin, getUrl,config} from '@/common/js/utils.js';
  209. import lfNav from '@/components/lf-nav/lf-nav.vue';
  210. import lfTabbar from '@/components/lf-tabbar/lf-tabbar.vue';
  211. export default {
  212. data() {
  213. return {
  214. is_login: '',
  215. list: [],
  216. groupList: [],
  217. select_products: {},
  218. allCheck: true,
  219. channel: 'normal',
  220. loading: false,
  221. show_coupons: false,
  222. // 领取优惠券
  223. show_discounts: false,
  224. // 查看促销活动
  225. goodsList: [],
  226. // 购物车里存在的商品id
  227. config: '',
  228. author: config.PACKAGES.author,
  229. discounts:'',
  230. coupons:''
  231. };
  232. },
  233. onShow() {
  234. // var oauth = Cache.get(cache_keys.token);
  235. // var locals = Cache.get(cache_keys.cart);
  236. var is_login = this.$cookieStorage.get('user_token');
  237. this.setData({
  238. is_login: is_login,
  239. loading: false
  240. });
  241. var oauth = this.is_login;
  242. var locals = this.$cookieStorage.get('cart');
  243. if (oauth && locals && locals.length) {
  244. // 提交本地购物车
  245. this.appendToCart(locals);
  246. } else {
  247. this.queryCartList();
  248. } // let app =getApp();
  249. // app.isBirthday().then(()=>{
  250. // if(this.$cookieStorage.get("birthday_gift")){
  251. // var giftData=this.$cookieStorage.get("birthday_gift").data;
  252. // new app.ToastPannel().__page.showText(giftData);
  253. // }
  254. // });
  255. },
  256. onLoad() {
  257. // 第三方平台配置颜色
  258. var bgConfig = this.$cookieStorage.get('globalConfig') || '';
  259. this.setData({
  260. config: bgConfig
  261. });
  262. },
  263. components: {
  264. lfNav,
  265. lfTabbar
  266. },
  267. props: {},
  268. methods: {
  269. jump(e) {
  270. var id = e.currentTarget.dataset.id;
  271. wx.navigateTo({
  272. url: '/pages/store/detail/detail?id=' + id
  273. });
  274. },
  275. select_product() {
  276. var data = {
  277. count: 0,
  278. total: 0,
  279. __ids: []
  280. };
  281. this.list.forEach(v => {
  282. if (v.checked) {
  283. data.count += parseInt(v.qty);
  284. data.total += Number(v.total);
  285. data.__ids.push(v.__raw_id || v.index);
  286. } else {
  287. this.setData({
  288. allCheck: false
  289. });
  290. }
  291. });
  292. this.setData({
  293. select_products: data
  294. });
  295. },
  296. addCart(success, message) {
  297. // this.$refs.button.finish();
  298. // this.setData({
  299. // loading: false
  300. // });
  301. console.log(success);
  302. this.loading=false;
  303. if (success) {
  304. this.$cookieStorage.clear('cart'); // wx.removeStorageSync('cart')
  305. // TODO
  306. //this.$emit('readyCheckout');
  307. this.queryCartList();
  308. } else {
  309. this.$cookieStorage.clear('cart'); // wx.removeStorageSync('cart')
  310. wx.showModal({
  311. title: message || '保存本地购物车失败,请重试!'
  312. });
  313. }
  314. },
  315. order() {
  316. var data = this.select_products;
  317. if (!data.count) {
  318. // this.$refs.button.finish();
  319. return;
  320. }
  321. ;
  322. this.setData({
  323. loading: true
  324. });
  325. var oauth = this.is_login;
  326. if (!oauth) {
  327. // 滚去登录
  328. var url = getUrl(); // this.$router.go({ name: 'user-quick-login', query: { source: this.$route.path } });
  329. wx.navigateTo({
  330. url: '/pages/user/register/register?url=' + url
  331. });
  332. return;
  333. } // var locals = wx.getStorageSync('cart');
  334. var locals = this.$cookieStorage.get('cart');
  335. if (locals && locals.length) {
  336. // 提交本地购物车
  337. this.appendToCart(locals);
  338. return;
  339. }
  340. this.readyCheckout();
  341. },
  342. readyCheckout() {
  343. var ids = this.select_products.__ids;
  344. var type = this.channel;
  345. this.checkoutOrder(ids, type);
  346. },
  347. checkoutOrder(ids, type) {
  348. var oauth = this.is_login;
  349. var cart_ids = ids.filter(id => id);
  350. var wechat_group_id = this.$cookieStorage.get('openGId') || '';
  351. var that = this;
  352. this.$http.post({
  353. api: `api/shopping/order/checkout`,
  354. data: {
  355. cart_ids,
  356. type,
  357. wechat_group_id
  358. },
  359. header: {
  360. Authorization: oauth
  361. },
  362. method: 'POST'
  363. }).then(res => {
  364. res = res.data;
  365. if (res.status) {
  366. // Cache.set(cache_keys.order, res.data);
  367. // wx.setStorageSync('local_order',res.data)
  368. this.$cookieStorage.set('local_order', res.data);
  369. that.checkout(true);
  370. } else {
  371. that.checkout(false, res.message);
  372. }
  373. }).catch(() => {
  374. that.checkout(false);
  375. });
  376. },
  377. checkout(success, message) {
  378. // this.$refs.button.finish();
  379. this.setData({
  380. loading: false
  381. });
  382. if (success) {
  383. // this.$router.go({ name: 'store-order'});
  384. wx.navigateTo({
  385. url: '/pages/store/order/order'
  386. });
  387. } else {
  388. // this.$Alert(message || '结算失败,请重试!');
  389. if (message == 'User unbind mobile') {
  390. wx.showModal({
  391. content: '请先绑定手机号',
  392. showCancel: false,
  393. success: res => {
  394. if (res.confirm || !res.cancel && !res.confirm) {
  395. wx.navigateTo({
  396. url: '/pages/user/phone/phone?url=' + getUrl()
  397. });
  398. }
  399. }
  400. });
  401. } else {
  402. wx.showModal({
  403. content: message || '结算失败,请重试!',
  404. showCancel: false
  405. });
  406. }
  407. }
  408. },
  409. queryCartList() {
  410. // var data = wx.getStorageSync('cart') || [];
  411. var data = this.$cookieStorage.get('cart') || []; // var oauth = Cache.get(cache_keys.token);
  412. var oauth = this.is_login;
  413. if (!oauth) {
  414. this.setData({
  415. list: data
  416. });
  417. this.select_product();
  418. this.groupListF();
  419. return;
  420. }
  421. var that = this;
  422. this.$http.get({
  423. api: `api/shopping/cart`,
  424. header: {
  425. Authorization: oauth
  426. }
  427. }).then(res => {
  428. res = res.data;
  429. var data = [];
  430. if (res.status && res.data) {
  431. data = Object.keys(res.data).map(key => {
  432. res.data[key].checked = true;
  433. return res.data[key];
  434. }).concat(data); // 购物车领券
  435. if (data.length) {
  436. var list = [];
  437. data.forEach(v => {
  438. if (that.goodsList.indexOf(v.com_id) == -1) {
  439. list.push(v.com_id);
  440. }
  441. ;
  442. });
  443. this.setData({
  444. goodsList: list
  445. });
  446. this.cardDiscount(list);
  447. }
  448. }
  449. that.setData({
  450. list: data
  451. });
  452. that.select_product();
  453. that.groupListF();
  454. }).catch(rej=> {
  455. this.addCart(false);
  456. });
  457. },
  458. updated(success, data, item, index) {
  459. if (success) {
  460. item.qty = data.qty;
  461. item.total = data.total;
  462. } else {
  463. // TODO;
  464. item.qty = data.qty;
  465. item.total = item.qty * Number(item.price);
  466. wx.showToast({
  467. title: '超过最大库存',
  468. image: '../../../static/error.png'
  469. });
  470. }
  471. var list = this.list;
  472. list[index] = item;
  473. this.setData({
  474. list: list
  475. });
  476. this.select_product();
  477. this.groupListF();
  478. },
  479. change(item, data, index) {
  480. if (item.local) {
  481. var locals = uni.getStorageInfo('cart') || [];
  482. locals[item.index].qty = data.qty;
  483. locals[item.index].total = data.total; // Cache.set(cache_keys.cart, locals, 0, null);
  484. // wx.setStorageSync('cart',locals)
  485. this.$cookieStorage.set('cart', locals); // this.$emit('updated', true, data, item);
  486. this.updated(true, data, item, index);
  487. } else {
  488. // clearTimeout(this.countTimer);
  489. //
  490. // this.countTimer = setTimeout(() => {
  491. // this.updateToCart(data, item);
  492. // }, 200);
  493. this.updateToCart(data, item, index);
  494. }
  495. },
  496. modifyCount(e) {
  497. var index = e.currentTarget.dataset.index;
  498. var item = this.list[index];
  499. var val = e.detail.value;
  500. var store_count = item.store_count;
  501. if (!val) {
  502. val = 1;
  503. } else if (!/^[1-9]\d*$/.test(val)) {
  504. val = val.replace(/[^\d].*$/, '');
  505. val = parseInt(val) || 1;
  506. }
  507. if (store_count != undefined) {
  508. if (val > store_count) {
  509. val = store_count;
  510. wx.showToast({
  511. title: '超过最大库存'
  512. });
  513. }
  514. }
  515. var data = {
  516. qty: val,
  517. total: val * Number(item.price)
  518. };
  519. this.change(item, data);
  520. },
  521. updateToCart(attr, data, index) {
  522. var oauth = this.is_login;
  523. var that = this;
  524. this.$http.ajax({
  525. api: `api/shopping/cart/${data.__raw_id}`,
  526. data: {
  527. attributes: {
  528. qty: attr.qty
  529. }
  530. },
  531. method: 'PUT',
  532. header: {
  533. Authorization: oauth
  534. }
  535. }).then(res => {
  536. res = res.data;
  537. if (res.status !== false) {
  538. // this.$emit('updated', true, attr, data);
  539. that.updated(true, attr, data, index);
  540. } else {
  541. // this.$emit('updated', false, { qty: res.data.stock_qty }, data);
  542. that.updated(false, {
  543. qty: res.data.stock_qty
  544. }, data, index);
  545. }
  546. });
  547. },
  548. changeCount(e) {
  549. var index = e.currentTarget.dataset.index,
  550. change = e.currentTarget.dataset.change,
  551. list = this.list,
  552. val = (parseInt(list[index].qty) || 0) + (parseInt(change) ? 1 : -1),
  553. store_count = list[index].store_count;
  554. if (store_count == undefined) {
  555. if (val > 0 && val <= 99) {
  556. var data = {
  557. qty: val,
  558. total: val * Number(list[index].price)
  559. };
  560. this.change(list[index], data, index);
  561. }
  562. } else {
  563. if (val > 0 && val <= store_count) {
  564. var data = {
  565. qty: val,
  566. total: val * Number(list[index].price)
  567. };
  568. this.change(list[index], data, index);
  569. } else {
  570. wx.showToast({
  571. title: '超过最大库存',
  572. image: '../../../static/error.png'
  573. });
  574. }
  575. }
  576. },
  577. groupListF() {
  578. if (this.list) {
  579. var data = [];
  580. var groups = {};
  581. this.list.forEach((v, i) => {
  582. let channel = v.channel || 'normal';
  583. if (groups[channel] !== undefined) {
  584. data[groups[channel]].items.push(v);
  585. data[groups[channel]].index.push(i);
  586. } else {
  587. groups[channel] = data.length;
  588. data.push({
  589. channel,
  590. items: [v],
  591. checked: [],
  592. index: [i]
  593. });
  594. }
  595. });
  596. }
  597. this.setData({
  598. groupList: data
  599. });
  600. },
  601. appendToCart(data) {
  602. // var oauth = Cache.get(cache_keys.token);
  603. var oauth = this.is_login;
  604. if (!oauth) return;
  605. if (!Array.isArray(data)) {
  606. data = [data];
  607. }
  608. var json = {};
  609. data.forEach((v, i) => json[i] = v);
  610. data = json;
  611. var that = this;
  612. this.$http.post({
  613. api: `api/shopping/cart`,
  614. data: data,
  615. header: {
  616. Authorization: oauth
  617. }
  618. }).then(res => {
  619. res = res.data;
  620. if (res.status) {
  621. that.addCart(true);
  622. } else {
  623. that.addCart(false, res.message);
  624. }
  625. }).catch(rej => {
  626. that.addCart(false);
  627. });
  628. },
  629. removeFromCart(e) {
  630. var oauth = this.is_login;
  631. var index = e.currentTarget.dataset.index;
  632. var list = this.list;
  633. var data = list[index];
  634. if (list[index].local) {
  635. // var locals = wx.getStorageSync('cart') || [];
  636. var locals = this.$cookieStorage.get('cart') || [];
  637. for (let i = 0; i < locals.length; i++) {
  638. if (locals[i].index === list[index].index) {
  639. locals.splice(i, 1);
  640. break;
  641. }
  642. }
  643. if (locals.length) {
  644. this.$cookieStorage.set('cart', locals); // wx.setStorageSync('cart',locals)
  645. } else {
  646. this.$cookieStorage.clear('cart'); // wx.removeStorageSync('cart')
  647. }
  648. this.removed(true, index);
  649. } else {
  650. this.$http.ajax({
  651. api: `api/shopping/cart/${data.__raw_id}`,
  652. header: {
  653. Authorization: oauth
  654. },
  655. method: 'DELETE'
  656. }).then(res => {
  657. res = res.data;
  658. this.removed(true, index);
  659. }).catch(rej => {
  660. this.removed(false);
  661. });
  662. }
  663. },
  664. removed(success, index) {
  665. if (success) {
  666. var list = this.list;
  667. var product = list.splice(index, 1)[0];
  668. this.setData({
  669. list: list
  670. });
  671. this.select_product();
  672. this.groupListF();
  673. } else {
  674. wx.showToast({
  675. title: '删除购物车商品失败!',
  676. image: '../../../static/error.png'
  677. });
  678. }
  679. },
  680. changeCheck(e) {
  681. var ids = e.detail.value;
  682. var list = this.list;
  683. list.forEach(item => {
  684. item.checked = false;
  685. });
  686. ids.forEach(item => {
  687. list[item].checked = true;
  688. });
  689. this.setData({
  690. list: list
  691. });
  692. this.select_product();
  693. this.groupListF();
  694. },
  695. selectAll(e) {
  696. var allCheck = this.allCheck;
  697. var list = this.list;
  698. this.setData({
  699. allCheck: !allCheck
  700. });
  701. list.forEach(item => {
  702. item.checked = this.allCheck ? true : false;
  703. });
  704. this.setData({
  705. list: list
  706. });
  707. this.select_product();
  708. this.groupListF();
  709. },
  710. showCoupons() {
  711. this.setData({
  712. show_coupons: !this.show_coupons
  713. });
  714. },
  715. showDiscounts() {
  716. this.setData({
  717. show_discounts: !this.show_discounts
  718. });
  719. },
  720. getCoupon(e) {
  721. var is_login = this.$cookieStorage.get('user_token');
  722. var code = e.currentTarget.dataset.code;
  723. var index = e.currentTarget.dataset.index;
  724. if (is_login) {
  725. this.goodsConvertCoupon(code, index);
  726. } else {
  727. var url = getUrl();
  728. wx.showModal({
  729. tiele: '',
  730. content: '请先登录',
  731. success: res => {
  732. if (res.confirm) {
  733. wx.navigateTo({
  734. url: '/pages/user/register/register?url=' + url
  735. });
  736. }
  737. }
  738. });
  739. }
  740. },
  741. // 领取优惠券
  742. goodsConvertCoupon(code, index) {
  743. var token = this.$cookieStorage.get('user_token');
  744. this.$http.post({
  745. api: 'api/coupon/convert',
  746. header: {
  747. Authorization: token
  748. },
  749. data: {
  750. coupon_code: code
  751. }
  752. }).then(res => {
  753. if (res.statusCode == 200) {
  754. res = res.data;
  755. if (res.status) {
  756. this.coupons[index].receive = true;
  757. wx.showToast({
  758. title: '领取成功'
  759. });
  760. } else {
  761. wx.showToast({
  762. title: res.message,
  763. image: '../../../static/error.png'
  764. });
  765. }
  766. } else {
  767. wx.showToast({
  768. title: '领取失败',
  769. image: '../../../static/error.png'
  770. });
  771. }
  772. });
  773. },
  774. goLogin() {
  775. var url = getUrl();
  776. wx.navigateTo({
  777. url: '/pages/user/register/register?url=' + url
  778. });
  779. },
  780. changeCoupons() {
  781. this.setData({
  782. show_coupons: !this.show_coupons
  783. });
  784. },
  785. changeDiscounts() {
  786. this.setData({
  787. show_discounts: !this.show_discounts
  788. });
  789. },
  790. // 购物车领券
  791. cardDiscount(ids) {
  792. var wechat_group_id = this.$cookieStorage.get('openGId') || '';
  793. wx.request({
  794. url: config.GLOBAL.baseUrl + 'api/shoppingCart/discount',
  795. method: 'POST',
  796. data: {
  797. ids: ids,
  798. wechat_group_id: wechat_group_id
  799. },
  800. success: res => {
  801. if (res.statusCode == 200) {
  802. res = res.data;
  803. if (res.status && res.data) {
  804. res.data.coupons.forEach(v => v.receive = false);
  805. // this.setData({
  806. // coupons: res.data.coupons,
  807. // discounts: res.data.discounts
  808. // });
  809. this.coupons=res.data.coupons;
  810. this.discounts=res.data.discounts;
  811. }
  812. }
  813. }
  814. });
  815. },
  816. setData: function (obj) {
  817. let that = this;
  818. let keys = [];
  819. let val, data;
  820. Object.keys(obj).forEach(function (key) {
  821. keys = key.split('.');
  822. val = obj[key];
  823. data = that.$data;
  824. keys.forEach(function (key2, index) {
  825. if (index + 1 == keys.length) {
  826. that.$set(data, key2, val);
  827. } else {
  828. if (!data[key2]) {
  829. that.$set(data, key2, {});
  830. }
  831. }
  832. data = data[key2];
  833. });
  834. });
  835. }
  836. },
  837. computed: {},
  838. watch: {}
  839. };
  840. </script>
  841. <style rel="stylesheet/less" lang="less">
  842. @import "cart";
  843. </style>