金诚优选前端代码
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.

952 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. </view>
  205. </template>
  206. <script>
  207. import {pageLogin, getUrl,config} from '@/common/js/utils.js';
  208. import lfNav from '@/components/lf-nav/lf-nav.vue';
  209. export default {
  210. data() {
  211. return {
  212. is_login: '',
  213. list: [],
  214. groupList: [],
  215. select_products: {},
  216. allCheck: true,
  217. channel: 'normal',
  218. loading: false,
  219. show_coupons: false,
  220. // 领取优惠券
  221. show_discounts: false,
  222. // 查看促销活动
  223. goodsList: [],
  224. // 购物车里存在的商品id
  225. config: '',
  226. author: config.PACKAGES.author,
  227. discounts:'',
  228. coupons:''
  229. };
  230. },
  231. onShow() {
  232. // var oauth = Cache.get(cache_keys.token);
  233. // var locals = Cache.get(cache_keys.cart);
  234. var is_login = this.$cookieStorage.get('user_token');
  235. this.setData({
  236. is_login: is_login,
  237. loading: false
  238. });
  239. var oauth = this.is_login;
  240. var locals = this.$cookieStorage.get('cart');
  241. if (oauth && locals && locals.length) {
  242. // 提交本地购物车
  243. this.appendToCart(locals);
  244. } else {
  245. this.queryCartList();
  246. } // let app =getApp();
  247. // app.isBirthday().then(()=>{
  248. // if(this.$cookieStorage.get("birthday_gift")){
  249. // var giftData=this.$cookieStorage.get("birthday_gift").data;
  250. // new app.ToastPannel().__page.showText(giftData);
  251. // }
  252. // });
  253. },
  254. onLoad() {
  255. // 第三方平台配置颜色
  256. var bgConfig = this.$cookieStorage.get('globalConfig') || '';
  257. this.setData({
  258. config: bgConfig
  259. });
  260. },
  261. components: {
  262. lfNav
  263. },
  264. props: {},
  265. methods: {
  266. jump(e) {
  267. var id = e.currentTarget.dataset.id;
  268. wx.navigateTo({
  269. url: '/pages/store/detail/detail?id=' + id
  270. });
  271. },
  272. select_product() {
  273. var data = {
  274. count: 0,
  275. total: 0,
  276. __ids: []
  277. };
  278. this.list.forEach(v => {
  279. if (v.checked) {
  280. data.count += parseInt(v.qty);
  281. data.total += Number(v.total);
  282. data.__ids.push(v.__raw_id || v.index);
  283. } else {
  284. this.setData({
  285. allCheck: false
  286. });
  287. }
  288. });
  289. this.setData({
  290. select_products: data
  291. });
  292. },
  293. addCart(success, message) {
  294. // this.$refs.button.finish();
  295. // this.setData({
  296. // loading: false
  297. // });
  298. console.log(success);
  299. this.loading=false;
  300. if (success) {
  301. this.$cookieStorage.clear('cart'); // wx.removeStorageSync('cart')
  302. // TODO
  303. //this.$emit('readyCheckout');
  304. this.queryCartList();
  305. } else {
  306. this.$cookieStorage.clear('cart'); // wx.removeStorageSync('cart')
  307. wx.showModal({
  308. title: message || '保存本地购物车失败,请重试!'
  309. });
  310. }
  311. },
  312. order() {
  313. var data = this.select_products;
  314. if (!data.count) {
  315. // this.$refs.button.finish();
  316. return;
  317. }
  318. ;
  319. this.setData({
  320. loading: true
  321. });
  322. var oauth = this.is_login;
  323. if (!oauth) {
  324. // 滚去登录
  325. var url = getUrl(); // this.$router.go({ name: 'user-quick-login', query: { source: this.$route.path } });
  326. wx.navigateTo({
  327. url: '/pages/user/register/register?url=' + url
  328. });
  329. return;
  330. } // var locals = wx.getStorageSync('cart');
  331. var locals = this.$cookieStorage.get('cart');
  332. if (locals && locals.length) {
  333. // 提交本地购物车
  334. this.appendToCart(locals);
  335. return;
  336. }
  337. this.readyCheckout();
  338. },
  339. readyCheckout() {
  340. var ids = this.select_products.__ids;
  341. var type = this.channel;
  342. this.checkoutOrder(ids, type);
  343. },
  344. checkoutOrder(ids, type) {
  345. var oauth = this.is_login;
  346. var cart_ids = ids.filter(id => id);
  347. var wechat_group_id = this.$cookieStorage.get('openGId') || '';
  348. var that = this;
  349. this.$http.post({
  350. api: `api/shopping/order/checkout`,
  351. data: {
  352. cart_ids,
  353. type,
  354. wechat_group_id
  355. },
  356. header: {
  357. Authorization: oauth
  358. },
  359. method: 'POST'
  360. }).then(res => {
  361. res = res.data;
  362. if (res.status) {
  363. // Cache.set(cache_keys.order, res.data);
  364. // wx.setStorageSync('local_order',res.data)
  365. this.$cookieStorage.set('local_order', res.data);
  366. that.checkout(true);
  367. } else {
  368. that.checkout(false, res.message);
  369. }
  370. }).catch(() => {
  371. that.checkout(false);
  372. });
  373. },
  374. checkout(success, message) {
  375. // this.$refs.button.finish();
  376. this.setData({
  377. loading: false
  378. });
  379. if (success) {
  380. // this.$router.go({ name: 'store-order'});
  381. wx.navigateTo({
  382. url: '/pages/store/order/order'
  383. });
  384. } else {
  385. // this.$Alert(message || '结算失败,请重试!');
  386. if (message == 'User unbind mobile') {
  387. wx.showModal({
  388. content: '请先绑定手机号',
  389. showCancel: false,
  390. success: res => {
  391. if (res.confirm || !res.cancel && !res.confirm) {
  392. wx.navigateTo({
  393. url: '/pages/user/phone/phone?url=' + getUrl()
  394. });
  395. }
  396. }
  397. });
  398. } else {
  399. wx.showModal({
  400. content: message || '结算失败,请重试!',
  401. showCancel: false
  402. });
  403. }
  404. }
  405. },
  406. queryCartList() {
  407. // var data = wx.getStorageSync('cart') || [];
  408. var data = this.$cookieStorage.get('cart') || []; // var oauth = Cache.get(cache_keys.token);
  409. var oauth = this.is_login;
  410. if (!oauth) {
  411. this.setData({
  412. list: data
  413. });
  414. this.select_product();
  415. this.groupListF();
  416. return;
  417. }
  418. var that = this;
  419. this.$http.get({
  420. api: `api/shopping/cart`,
  421. header: {
  422. Authorization: oauth
  423. }
  424. }).then(res => {
  425. res = res.data;
  426. var data = [];
  427. if (res.status && res.data) {
  428. data = Object.keys(res.data).map(key => {
  429. res.data[key].checked = true;
  430. return res.data[key];
  431. }).concat(data); // 购物车领券
  432. if (data.length) {
  433. var list = [];
  434. data.forEach(v => {
  435. if (that.goodsList.indexOf(v.com_id) == -1) {
  436. list.push(v.com_id);
  437. }
  438. ;
  439. });
  440. this.setData({
  441. goodsList: list
  442. });
  443. this.cardDiscount(list);
  444. }
  445. }
  446. that.setData({
  447. list: data
  448. });
  449. that.select_product();
  450. that.groupListF();
  451. }).catch(rej=> {
  452. this.addCart(false);
  453. });
  454. },
  455. updated(success, data, item, index) {
  456. if (success) {
  457. item.qty = data.qty;
  458. item.total = data.total;
  459. } else {
  460. // TODO;
  461. item.qty = data.qty;
  462. item.total = item.qty * Number(item.price);
  463. wx.showToast({
  464. title: '超过最大库存',
  465. image: '../../../static/error.png'
  466. });
  467. }
  468. var list = this.list;
  469. list[index] = item;
  470. this.setData({
  471. list: list
  472. });
  473. this.select_product();
  474. this.groupListF();
  475. },
  476. change(item, data, index) {
  477. if (item.local) {
  478. var locals = uni.getStorageInfo('cart') || [];
  479. locals[item.index].qty = data.qty;
  480. locals[item.index].total = data.total; // Cache.set(cache_keys.cart, locals, 0, null);
  481. // wx.setStorageSync('cart',locals)
  482. this.$cookieStorage.set('cart', locals); // this.$emit('updated', true, data, item);
  483. this.updated(true, data, item, index);
  484. } else {
  485. // clearTimeout(this.countTimer);
  486. //
  487. // this.countTimer = setTimeout(() => {
  488. // this.updateToCart(data, item);
  489. // }, 200);
  490. this.updateToCart(data, item, index);
  491. }
  492. },
  493. modifyCount(e) {
  494. var index = e.currentTarget.dataset.index;
  495. var item = this.list[index];
  496. var val = e.detail.value;
  497. var store_count = item.store_count;
  498. if (!val) {
  499. val = 1;
  500. } else if (!/^[1-9]\d*$/.test(val)) {
  501. val = val.replace(/[^\d].*$/, '');
  502. val = parseInt(val) || 1;
  503. }
  504. if (store_count != undefined) {
  505. if (val > store_count) {
  506. val = store_count;
  507. wx.showToast({
  508. title: '超过最大库存'
  509. });
  510. }
  511. }
  512. var data = {
  513. qty: val,
  514. total: val * Number(item.price)
  515. };
  516. this.change(item, data);
  517. },
  518. updateToCart(attr, data, index) {
  519. var oauth = this.is_login;
  520. var that = this;
  521. this.$http.ajax({
  522. api: `api/shopping/cart/${data.__raw_id}`,
  523. data: {
  524. attributes: {
  525. qty: attr.qty
  526. }
  527. },
  528. method: 'PUT',
  529. header: {
  530. Authorization: oauth
  531. }
  532. }).then(res => {
  533. res = res.data;
  534. if (res.status !== false) {
  535. // this.$emit('updated', true, attr, data);
  536. that.updated(true, attr, data, index);
  537. } else {
  538. // this.$emit('updated', false, { qty: res.data.stock_qty }, data);
  539. that.updated(false, {
  540. qty: res.data.stock_qty
  541. }, data, index);
  542. }
  543. });
  544. },
  545. changeCount(e) {
  546. var index = e.currentTarget.dataset.index,
  547. change = e.currentTarget.dataset.change,
  548. list = this.list,
  549. val = (parseInt(list[index].qty) || 0) + (parseInt(change) ? 1 : -1),
  550. store_count = list[index].store_count;
  551. if (store_count == undefined) {
  552. if (val > 0 && val <= 99) {
  553. var data = {
  554. qty: val,
  555. total: val * Number(list[index].price)
  556. };
  557. this.change(list[index], data, index);
  558. }
  559. } else {
  560. if (val > 0 && val <= store_count) {
  561. var data = {
  562. qty: val,
  563. total: val * Number(list[index].price)
  564. };
  565. this.change(list[index], data, index);
  566. } else {
  567. wx.showToast({
  568. title: '超过最大库存',
  569. image: '../../../static/error.png'
  570. });
  571. }
  572. }
  573. },
  574. groupListF() {
  575. if (this.list) {
  576. var data = [];
  577. var groups = {};
  578. this.list.forEach((v, i) => {
  579. let channel = v.channel || 'normal';
  580. if (groups[channel] !== undefined) {
  581. data[groups[channel]].items.push(v);
  582. data[groups[channel]].index.push(i);
  583. } else {
  584. groups[channel] = data.length;
  585. data.push({
  586. channel,
  587. items: [v],
  588. checked: [],
  589. index: [i]
  590. });
  591. }
  592. });
  593. }
  594. this.setData({
  595. groupList: data
  596. });
  597. },
  598. appendToCart(data) {
  599. // var oauth = Cache.get(cache_keys.token);
  600. var oauth = this.is_login;
  601. if (!oauth) return;
  602. if (!Array.isArray(data)) {
  603. data = [data];
  604. }
  605. var json = {};
  606. data.forEach((v, i) => json[i] = v);
  607. data = json;
  608. var that = this;
  609. this.$http.post({
  610. api: `api/shopping/cart`,
  611. data: data,
  612. header: {
  613. Authorization: oauth
  614. }
  615. }).then(res => {
  616. res = res.data;
  617. if (res.status) {
  618. that.addCart(true);
  619. } else {
  620. that.addCart(false, res.message);
  621. }
  622. }).catch(rej => {
  623. that.addCart(false);
  624. });
  625. },
  626. removeFromCart(e) {
  627. var oauth = this.is_login;
  628. var index = e.currentTarget.dataset.index;
  629. var list = this.list;
  630. var data = list[index];
  631. if (list[index].local) {
  632. // var locals = wx.getStorageSync('cart') || [];
  633. var locals = this.$cookieStorage.get('cart') || [];
  634. for (let i = 0; i < locals.length; i++) {
  635. if (locals[i].index === list[index].index) {
  636. locals.splice(i, 1);
  637. break;
  638. }
  639. }
  640. if (locals.length) {
  641. this.$cookieStorage.set('cart', locals); // wx.setStorageSync('cart',locals)
  642. } else {
  643. this.$cookieStorage.clear('cart'); // wx.removeStorageSync('cart')
  644. }
  645. this.removed(true, index);
  646. } else {
  647. this.$http.ajax({
  648. api: `api/shopping/cart/${data.__raw_id}`,
  649. header: {
  650. Authorization: oauth
  651. },
  652. method: 'DELETE'
  653. }).then(res => {
  654. res = res.data;
  655. this.removed(true, index);
  656. }).catch(rej => {
  657. this.removed(false);
  658. });
  659. }
  660. },
  661. removed(success, index) {
  662. if (success) {
  663. var list = this.list;
  664. var product = list.splice(index, 1)[0];
  665. this.setData({
  666. list: list
  667. });
  668. this.select_product();
  669. this.groupListF();
  670. } else {
  671. wx.showToast({
  672. title: '删除购物车商品失败!',
  673. image: '../../../static/error.png'
  674. });
  675. }
  676. },
  677. changeCheck(e) {
  678. var ids = e.detail.value;
  679. var list = this.list;
  680. list.forEach(item => {
  681. item.checked = false;
  682. });
  683. ids.forEach(item => {
  684. list[item].checked = true;
  685. });
  686. this.setData({
  687. list: list
  688. });
  689. this.select_product();
  690. this.groupListF();
  691. },
  692. selectAll(e) {
  693. var allCheck = this.allCheck;
  694. var list = this.list;
  695. this.setData({
  696. allCheck: !allCheck
  697. });
  698. list.forEach(item => {
  699. item.checked = this.allCheck ? true : false;
  700. });
  701. this.setData({
  702. list: list
  703. });
  704. this.select_product();
  705. this.groupListF();
  706. },
  707. showCoupons() {
  708. this.setData({
  709. show_coupons: !this.show_coupons
  710. });
  711. },
  712. showDiscounts() {
  713. this.setData({
  714. show_discounts: !this.show_discounts
  715. });
  716. },
  717. getCoupon(e) {
  718. var is_login = this.$cookieStorage.get('user_token');
  719. var code = e.currentTarget.dataset.code;
  720. var index = e.currentTarget.dataset.index;
  721. if (is_login) {
  722. this.goodsConvertCoupon(code, index);
  723. } else {
  724. var url = getUrl();
  725. wx.showModal({
  726. tiele: '',
  727. content: '请先登录',
  728. success: res => {
  729. if (res.confirm) {
  730. wx.navigateTo({
  731. url: '/pages/user/register/register?url=' + url
  732. });
  733. }
  734. }
  735. });
  736. }
  737. },
  738. // 领取优惠券
  739. goodsConvertCoupon(code, index) {
  740. var token = this.$cookieStorage.get('user_token');
  741. this.$http.post({
  742. api: 'api/coupon/convert',
  743. header: {
  744. Authorization: token
  745. },
  746. data: {
  747. coupon_code: code
  748. }
  749. }).then(res => {
  750. if (res.statusCode == 200) {
  751. res = res.data;
  752. if (res.status) {
  753. this.coupons[index].receive = true;
  754. wx.showToast({
  755. title: '领取成功'
  756. });
  757. } else {
  758. wx.showToast({
  759. title: res.message,
  760. image: '../../../static/error.png'
  761. });
  762. }
  763. } else {
  764. wx.showToast({
  765. title: '领取失败',
  766. image: '../../../static/error.png'
  767. });
  768. }
  769. });
  770. },
  771. goLogin() {
  772. var url = getUrl();
  773. wx.navigateTo({
  774. url: '/pages/user/register/register?url=' + url
  775. });
  776. },
  777. changeCoupons() {
  778. this.setData({
  779. show_coupons: !this.show_coupons
  780. });
  781. },
  782. changeDiscounts() {
  783. this.setData({
  784. show_discounts: !this.show_discounts
  785. });
  786. },
  787. // 购物车领券
  788. cardDiscount(ids) {
  789. var wechat_group_id = this.$cookieStorage.get('openGId') || '';
  790. wx.request({
  791. url: config.GLOBAL.baseUrl + 'api/shoppingCart/discount',
  792. method: 'POST',
  793. data: {
  794. ids: ids,
  795. wechat_group_id: wechat_group_id
  796. },
  797. success: res => {
  798. if (res.statusCode == 200) {
  799. res = res.data;
  800. if (res.status && res.data) {
  801. res.data.coupons.forEach(v => v.receive = false);
  802. // this.setData({
  803. // coupons: res.data.coupons,
  804. // discounts: res.data.discounts
  805. // });
  806. this.coupons=res.data.coupons;
  807. this.discounts=res.data.discounts;
  808. }
  809. }
  810. }
  811. });
  812. },
  813. setData: function (obj) {
  814. let that = this;
  815. let keys = [];
  816. let val, data;
  817. Object.keys(obj).forEach(function (key) {
  818. keys = key.split('.');
  819. val = obj[key];
  820. data = that.$data;
  821. keys.forEach(function (key2, index) {
  822. if (index + 1 == keys.length) {
  823. that.$set(data, key2, val);
  824. } else {
  825. if (!data[key2]) {
  826. that.$set(data, key2, {});
  827. }
  828. }
  829. data = data[key2];
  830. });
  831. });
  832. }
  833. },
  834. computed: {},
  835. watch: {}
  836. };
  837. </script>
  838. <style rel="stylesheet/less" lang="less">
  839. @import "cart";
  840. </style>