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

1804 lines
60 KiB

  1. <template>
  2. <view class="">
  3. <view id="store-order">
  4. <view class="border-box">
  5. <view class="order-item no-mar" v-if="initInfo && initInfo.pick_self == 1">
  6. <view class="title mx-1px-bottom">
  7. 配送方式
  8. </view>
  9. <view class="ways">
  10. <view class="item">
  11. <radio-group class="radio-group" @change="radioChange">
  12. <label class="radio">
  13. <radio value="0" color="#EA4448" checked="true" ></radio>快递到家
  14. </label>
  15. <label class="radio">
  16. <radio value="1" color="#EA4448" ></radio>门店自提
  17. </label>
  18. </radio-group>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="order-item mx-1px-top" v-if="valueR == 0">
  23. <view class="title mx-1px-bottom">
  24. 收货信息
  25. </view>
  26. <view class="address info" @tap="selectAddress">
  27. <view v-if="form && form.address && form.address.mobile">
  28. <view class="user">
  29. <i class="iconfont icon-yonghu1"></i>
  30. <view class="name-box">
  31. <text class="name">{{form.address.accept_name}}</text>
  32. <text class="telephone">{{form.address.mobile}}</text>
  33. </view>
  34. </view>
  35. <view class="address">
  36. <i class="iconfont icon-weizhi"></i>
  37. <text>{{form.address.address_name}} {{form.address.address}}</text>
  38. </view>
  39. </view>
  40. <view class="user" v-else>
  41. <i class="iconfont icon-juxing"></i>
  42. <view class="name-box">
  43. <text class="add">添加收货地址</text>
  44. </view>
  45. </view>
  46. <!--<view class="name" wx:if="{{form.address}}">-->
  47. <!--<text>{{form.address.accept_name}}</text>-->
  48. <!--<text>{{form.address.mobile}}</text>-->
  49. <!--</view>-->
  50. <!--<view wx:if="{{form.address}}">-->
  51. <!--{{form.address.address}}-->
  52. <!--</view>-->
  53. </view>
  54. </view>
  55. <view class="order-item mx-1px-top" v-if="valueR == 1">
  56. <!-- <view class="title mx-1px-bottom">
  57. 收货信息
  58. </view>-->
  59. <view class="address info" @tap="selectStore">
  60. <view class="user" v-if="self_shop == ''">
  61. <i class="iconfont icon-juxing"></i>
  62. <view class="name-box">
  63. <text class="add">请选择自提门店</text>
  64. </view>
  65. </view>
  66. <view v-else>
  67. <view class="address">
  68. <i class="iconfont icon-weizhi"></i>
  69. <text>{{self_shop.name}}</text>
  70. </view>
  71. </view>
  72. <!--<view class="name" wx:if="{{form.address}}">-->
  73. <!--<text>{{form.address.accept_name}}</text>-->
  74. <!--<text>{{form.address.mobile}}</text>-->
  75. <!--</view>-->
  76. <!--<view wx:if="{{form.address}}">-->
  77. <!--{{form.address.address}}-->
  78. <!--</view>-->
  79. </view>
  80. </view>
  81. <view class="order-item">
  82. <view class="title mx-1px-bottom">
  83. 商品清单
  84. </view>
  85. <view class="goods info mx-1px-bottom" v-for="(item, index) in block.order.items" :key="index" v-if="block.order.items.length == 1">
  86. <view class="goods-item">
  87. <view class="item-left">
  88. <image :src="item.item_meta.image"></image>
  89. </view>
  90. <view class="item-right">
  91. <view class="goods-name item">
  92. <view class="name">
  93. {{item.item_name}}
  94. </view>
  95. <view>
  96. {{item.quantity}}
  97. </view>
  98. </view>
  99. <view class="goods-money item">
  100. <view>
  101. {{item.item_meta.specs_text}}
  102. </view>
  103. <view>
  104. {{(item.total / 100)}}
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. <view class="info mx-1px-bottom all-goods" v-if="block.order.items.length > 1" @tap="jumpGoods">
  111. <view class="good-box">
  112. <view class="good-img" v-for="(item, index) in block.order.items" :key="index" wx:for-index="index" v-if="index < 4">
  113. <image :src="item.item_meta.image" alt></image>
  114. </view>
  115. </view>
  116. <div class="num">
  117. {{block.order.count}}
  118. </div>
  119. </view>
  120. <view class="total">
  121. {{block.order.count}}件商品合计{{(block.order.total/100)}}
  122. </view>
  123. </view>
  124. <view class="order-item">
  125. <view class="title__point info" @tap="showDiscounts">
  126. <text>促销活动</text>
  127. <!--<view class="no-dis" wx:if="{{!block.discounts || block.discounts.length == 0}}">
  128. 您暂无可用优惠
  129. </view>-->
  130. <view v-if="available.currentDiscount.id" class="coupon-label">
  131. {{available.currentDiscount.label}} {{currentItem.discountAdjustment / 100}}
  132. </view>
  133. <view class="discounts-item" :style="'background: ' + config.mainColor" v-else>
  134. <text v-if="available.discounts || available.discounts.length !== 0">{{available.discounts.length || 0}}个可用活动</text>
  135. </view>
  136. </view>
  137. </view>
  138. <view class="order-item">
  139. <view class="coupon info" @tap="select">
  140. <view>优惠券</view>
  141. <view class="coupon-item">
  142. <view v-if="available.currentCoupon.id" class="coupon-label">
  143. {{available.currentCoupon.discount.label}} {{currentItem.couponAdjustment / 100}}
  144. </view>
  145. <view class="coupon-num" :style="'background: ' + config.mainColor" v-else>
  146. {{available.coupons.length || 0}}个优惠可用
  147. </view>
  148. </view>
  149. </view>
  150. </view>
  151. <view class="order-item" v-if="(available.coupons && available.coupons.length) || (available.discounts && available.discounts.length)">
  152. <view class="info best">
  153. <view>推荐组合</view>
  154. <view class="text">
  155. <block v-if="bestDiscount">
  156. 使用推荐组合省{{currentItem.adjustmentTotal_yuan}}
  157. </block>
  158. </view>
  159. <switch :checked="bestDiscount" @change="bestSwitch" color="#FB5054"></switch>
  160. </view>
  161. </view>
  162. <view class="order-item">
  163. <view class="mx-1px-bottom title__point" v-if="newBlock.orderPoint.pointCanUse && newBlock.orderPoint.pointCanUse > 0">
  164. <view>积分抵扣</view>
  165. <view>
  166. <!--<switch checked />-->
  167. <switch @change="usePoint"></switch>
  168. </view>
  169. </view>
  170. <view class="info title__point" v-if="!newBlock.orderPoint.pointCanUse || newBlock.orderPoint.pointCanUse <= 0">
  171. <text>积分抵扣</text>
  172. <view class="no-dis" v-if="newBlock.orderPoint.length === 0">
  173. 此商品不支持积分
  174. </view>
  175. <view class="no-dis" v-else>
  176. 您暂无可用积分
  177. </view>
  178. </view>
  179. <view class="point info" v-else>
  180. <view class="input-box mx-1px-bottom">
  181. <view style="overflow: hidden">
  182. <view class="input__text">共有{{newBlock.orderPoint.userPoint}}积分 可使用积分{{newBlock.orderPoint.pointCanUse || 0}} 抵扣{{-pointAmount || 0}}</view>
  183. <!--<input placeholder="可使用积分{{block.orderPoint.pointCanUse || 0}}" type="number" bindinput="modifyPoint" @change="saveForm" value="{{form.point !== 0 ? form.point : ''}}"/>-->
  184. </view>
  185. <!--<view class="use-all" bindtap="usePoint">
  186. 全部使用
  187. </view>-->
  188. <!--<view class="offset">
  189. </view>-->
  190. </view>
  191. </view>
  192. </view>
  193. <view class="order-item" v-if="block.invoice_status == 1">
  194. <view class="invoice info" @tap="addInvoice">
  195. <view>
  196. 发票信息
  197. </view>
  198. <view class="invoice__item">
  199. <view v-if="form.invoice.name">
  200. {{form.invoice.name}}
  201. </view>
  202. <view v-else>
  203. 不开发票
  204. </view>
  205. </view>
  206. </view>
  207. </view>
  208. <view class="order-item">
  209. <view class="title mx-1px-bottom">
  210. 备注
  211. </view>
  212. <view class="remarks info">
  213. <view>
  214. <input @input="inputNote" type="text" placeholder="选填:填写您的附加信息"></input>
  215. </view>
  216. </view>
  217. </view>
  218. <view class="order-info">
  219. <view class="info-item">
  220. <view class="item-left">
  221. 商品件数
  222. </view>
  223. <view class="item-right">
  224. {{block.order.count}}
  225. </view>
  226. </view>
  227. <view class="info-item">
  228. <view class="item-left">
  229. 金额合计
  230. </view>
  231. <view class="item-right">
  232. {{block.order.total / 100}}
  233. </view>
  234. </view>
  235. <view class="info-item">
  236. <view class="item-left">
  237. 积分抵扣
  238. </view>
  239. <view class="item-right">
  240. <!-- {{discounts!=undefined?discounts.point_yuan:0}} -->
  241. {{discounts ? discounts.point_yuan:0}}
  242. </view>
  243. </view>
  244. <view class="info-item">
  245. <view class="item-left">
  246. 优惠抵扣
  247. </view>
  248. <view class="item-right">
  249. {{discounts ? discounts.total_yuan:0}}
  250. </view>
  251. </view>
  252. <view class="info-item">
  253. <view class="item-left">
  254. 运费
  255. </view>
  256. <view class="item-right">
  257. -{{newBlock.order.payable_freight}}
  258. </view>
  259. </view>
  260. <!--<view class="info-item">-->
  261. <!--<view class="item-left money-title">-->
  262. <!--实际支付金额-->
  263. <!--</view>-->
  264. <!--<view class="item-right money">-->
  265. <!--{{(paymentMoneys.total + block.order.payable_freight) / 100}}-->
  266. <!--</view>-->
  267. <!--</view>-->
  268. </view>
  269. </view>
  270. <view class="sbumit-order mx-1px-top">
  271. <view class="back" :style="'color: ' + config.mainColor">
  272. {{newBlock.order.count}}件商品, 合计 {{pay_amount_yuan}}
  273. </view>
  274. <button class="sbumit" :style="'background: ' + config.mainColor" @tap="submitOrder" :loading="loading">
  275. 提交订单
  276. </button>
  277. </view>
  278. </view>
  279. <view class="coupon-maks" :class="show ? 'cur' : ''">
  280. <view class="coupon-box">
  281. <radio-group @change="change">
  282. <view class="coupon-item" v-for="(item, index) in available.coupons" :key="index">
  283. <radio :id="'index-' + index" :value="String(index)" :checked="item.checked"></radio>
  284. <label :for="'index-' + index">
  285. <view class="coupon">
  286. <view class="coupon-left" :style="'background: ' + config.mainColor">
  287. <view class="text-wrap">
  288. <view class="text-box">
  289. <view class="text">
  290. <text class="money" v-if="item.discount.action_type.type == 'cash'"></text>
  291. <span>{{ item.discount.action_type.value }}</span>
  292. <text class="money" v-if="item.discount.action_type.type == 'discount'"></text>
  293. </view>
  294. <text class="label text">{{ item.discount.label }}</text>
  295. </view>
  296. </view>
  297. <view class="dot-wrap">
  298. <view class="dot-item">
  299. </view>
  300. <view class="dot-item">
  301. </view>
  302. <view class="dot-item">
  303. </view>
  304. <view class="dot-item">
  305. </view>
  306. <view class="dot-item">
  307. </view>
  308. <view class="dot-item">
  309. </view>
  310. </view>
  311. </view>
  312. <view class="coupon-right">
  313. <view class="top">
  314. <span class="type">
  315. <span v-if="item.discount.channel == 'ec'">商城</span>
  316. <span v-else>门店</span>
  317. </span>
  318. <text class="info">{{item.discount.title}}</text>
  319. </view>
  320. <view class="bottom">
  321. <view class="bottom-use">
  322. <view class="tiem-box">
  323. <text>{{item.discount.use_start_time}}{{item.discount.use_end_time}}</text>
  324. </view>
  325. </view>
  326. </view>
  327. <view class="select" :class=" index == couponCheckIndex ? 'activity' : ''">
  328. </view>
  329. </view>
  330. </view>
  331. </label>
  332. </view>
  333. </radio-group>
  334. </view>
  335. <view class="button-box">
  336. <button class="sure" type="primary" :style="'background: ' + config.mainColor" @tap="sure">确定</button>
  337. <button type="default" @tap="cancel">取消</button>
  338. </view>
  339. </view>
  340. <!--选择促销部分-->
  341. <view class="maks" :class="show_discounts ? 'cur' : ''" @tap="showDiscounts">
  342. </view>
  343. <view class="select-coupon-discounts" :class="show_discounts ? 'cur' : ''">
  344. <view class="select-discounts">
  345. <view class="select-discounts-top">
  346. <view class="title">
  347. 促销活动
  348. <view class="close" @tap="showDiscounts">
  349. X
  350. </view>
  351. </view>
  352. </view>
  353. <view class="select-discounts-bottom">
  354. <view class="activity info">
  355. <view v-if="!block.discounts || block.discounts.length == 0">
  356. 您暂无可用优惠
  357. </view>
  358. <block v-else>
  359. <radio-group @change="changeDiscounts">
  360. <view class="input-box mx-1px-bottom" v-for="(item, index) in available.discounts" :key="index" >
  361. <view>
  362. <label class="radio">
  363. <text>{{item.label}}</text>
  364. <radio color="red" :value="String(index)" :checked="discountsCheckIndex == index"></radio>
  365. </label>
  366. </view>
  367. </view>
  368. <view class="input-box mx-1px-bottom">
  369. <view>
  370. <label class="radio">
  371. <text>不使用优惠</text>
  372. <radio value="-1" :checked="discountsCheckIndex == -1"></radio>
  373. </label>
  374. </view>
  375. </view>
  376. </radio-group>
  377. </block>
  378. </view>
  379. </view>
  380. </view>
  381. </view>
  382. </view>
  383. <!--
  384. <view class="select-coupon-box {{show_discounts ? 'cur' : ''}}">
  385. </view>-->
  386. </template>
  387. <script>
  388. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  389. export default {
  390. data() {
  391. return {
  392. currentItem:{},
  393. loading: false,
  394. show: false,
  395. block: {
  396. order: {
  397. items: []
  398. },
  399. orderPoint: {
  400. pointAmount: 0,
  401. pointCanUse: 0
  402. },
  403. otherCoupon: {}
  404. },
  405. pointAmount: 0,
  406. newBlock: {},
  407. newForm: {},
  408. discountStatus: {},
  409. bestDiscount: false,
  410. // 是否为最优折扣
  411. discountsCheckIndex: -1,
  412. // 选择的id
  413. couponCheckIndex: -1,
  414. available: {
  415. coupons: [],
  416. //可选择的优惠券
  417. currentCoupon: '',
  418. //当前选择的优惠券
  419. discounts: [],
  420. // 可使用的促销折扣
  421. currentDiscount: '',
  422. // 当前选择促销折扣
  423. currentPoint: '',
  424. pointStatus: false
  425. },
  426. pay_amount: '',
  427. extra: {
  428. point: {}
  429. },
  430. form: {
  431. order_no: '',
  432. address: {},
  433. coupon: {},
  434. invoice: {},
  435. discount: {},
  436. point: 0,
  437. note: '',
  438. formStates: {},
  439. isDisabled: false //是否禁用优惠折扣按钮
  440. },
  441. useList: [[{
  442. name: '不使用',
  443. value: 0
  444. }, {
  445. name: '使用',
  446. value: 1
  447. }]],
  448. formStates: {
  449. discountsCheckIndex: -1,
  450. noDiscountsCheckList: -1,
  451. pointStatus: false
  452. },
  453. temporary: {
  454. coupons: [],
  455. //可选择的优惠券
  456. coupon: {},
  457. //当前选择的优惠券
  458. discounts: [],
  459. // 可使用的促销折扣
  460. discount: {} // 当前选择促销折扣
  461. },
  462. paymentMoneys: {
  463. discounts: {},
  464. total: 0
  465. },
  466. reduce_items_id:'',
  467. check: null,
  468. is_login: '',
  469. type: '',
  470. show_discounts: false,
  471. task_id: '',
  472. valueR: 0,
  473. initInfo: '',
  474. config: '',
  475. accountInfo: '',
  476. self_shop: '',
  477. coupon: {},
  478. pay_amount_yuan:'',
  479. discounts: ''
  480. };
  481. },
  482. onShow() {
  483. var block = this.$cookieStorage.get('local_order');
  484. var form = this.$cookieStorage.get('order_form');
  485. let self_shop = this.$cookieStorage.get('selfShop');
  486. if (block) {
  487. if (!form || form.order_no !== block.order.order_no) {
  488. form = Object.assign({}, this.form);
  489. form.order_no = block.order.order_no;
  490. if (block.address) {
  491. form.address = block.address;
  492. } // Cache.set(cache_keys.order_form, form);
  493. this.$cookieStorage.set('order_form', form);
  494. }
  495. }
  496. if (self_shop) {
  497. this.setData({
  498. self_shop: self_shop
  499. });
  500. }
  501. this.setData({
  502. block: Object.assign({}, this.block, block),
  503. form: Object.assign({}, this.form, form)
  504. }); // let app =getApp();
  505. // app.isBirthday().then(()=>{
  506. // if(this.$cookieStorage.get("birthday_gift")){
  507. // var giftData=this.$cookieStorage.get("birthday_gift").data;
  508. // new app.ToastPannel().__page.showText(giftData);
  509. // }
  510. // });
  511. },
  512. onLoad(e) {
  513. var accountInfo='';
  514. // #ifdef MP-WEIXIN
  515. var accountInfo = wx.getAccountInfoSync(); // 第三方平台配置颜色
  516. // #endif
  517. var gbConfig = this.$cookieStorage.get('globalConfig') || '';
  518. this.setData({
  519. config: gbConfig,
  520. accountInfo: accountInfo
  521. });
  522. if (e.type) {
  523. this.setData({
  524. type: e.type
  525. });
  526. }
  527. if (e.task_id) {
  528. this.setData({
  529. task_id: e.task_id
  530. });
  531. }
  532. if(e.reduce_items_id){
  533. this.reduce_items_id = e.reduce_items_id
  534. }
  535. var info = this.$cookieStorage.get('init');
  536. /* if (info && info.pick_self == 1) {
  537. this.setData({
  538. valueR: 1
  539. });
  540. } */
  541. this.setData({
  542. initInfo: info
  543. });
  544. this.initData();
  545. },
  546. methods: {
  547. //配送方式选择
  548. radioChange(e) {
  549. this.setData({
  550. valueR: e.detail.value
  551. });
  552. },
  553. selectStore() {
  554. wx.navigateTo({
  555. url: '/pages/store/selfShop/selfShop'
  556. });
  557. },
  558. showDiscounts() {
  559. if (!this.available.discounts || this.available.discounts.length == 0) {
  560. wx.showModal({
  561. content: '您暂无可用优惠',
  562. showCancel: false
  563. });
  564. } else {
  565. this.setData({
  566. show_discounts: !this.show_discounts
  567. });
  568. }
  569. },
  570. addInvoice() {
  571. wx.navigateTo({
  572. url: `/pages/store/invoice/invoice?order_no=${this.block.order.order_no}&url=${getCurrentPages()[getCurrentPages().length - 1].route}`
  573. });
  574. },
  575. selectAddress() {
  576. wx.navigateTo({
  577. url: `/pages/address/list/list?order_no=${this.block.order.order_no}&url=${getCurrentPages()[getCurrentPages().length - 1].route}`
  578. });
  579. },
  580. jumpGoods() {
  581. wx.navigateTo({
  582. url: '/pages/store/orderGoods/orderGoods?no=' + this.block.order.order_no
  583. });
  584. },
  585. change(e) {
  586. let value = e.detail.value;
  587. let couponList = this.available.coupons;
  588. let item = '';
  589. couponList.forEach((items, index) => {
  590. if (index == value) {
  591. item = items;
  592. }
  593. });
  594. let exclusive = item.discount.exclusive;
  595. if (exclusive) {
  596. this.available.discounts = [];
  597. this.available.currentDiscount = '';
  598. this.discountsCheckIndex = -1;
  599. /*this.setData({
  600. 'available.discounts': [],
  601. 'available.currentDiscount': '',
  602. discountsCheckIndex: -1
  603. });*/
  604. }
  605. this.available.currentCoupon = item;
  606. this.show = false;
  607. setTimeout(() => {
  608. this.calculateOrder();
  609. }, 100)
  610. /*this.setData({
  611. [`available.currentCoupon`]: item,
  612. show: false
  613. }, () => {
  614. this.calculateOrder();
  615. });*/
  616. /*this.setData({
  617. check: e.detail.value
  618. })
  619. var coupons = this.block.coupons
  620. var item = coupons[e.detail.value]
  621. var data = this.$cookieStorage.get('order_form')
  622. let exclusive = item.discount.exclusive
  623. if (!data) return;
  624. coupons.forEach((v, key) => v.checked = key == e.detail.value)
  625. if (Array.isArray(item.adjustments)) {
  626. item.adjustments.sort((a, b) => {
  627. return Math.abs(a.amount) < Math.abs(b.amount);
  628. });
  629. }
  630. // 排他
  631. if (exclusive) {
  632. data.formStates.discountsCheckIndex = -1;
  633. data.isDisabled = true;
  634. } else {
  635. data.isDisabled = false;
  636. }
  637. data.otherCoupon = item;
  638. data.coupons = coupons;
  639. // Cache.set(cache_keys.order_form, data);
  640. this.setData({
  641. block: Object.assign({}, this.block, data)
  642. })
  643. this.$cookieStorage.set('order_form', data)
  644. this.paymentMoney()*/
  645. },
  646. sure() {
  647. var block = this.block.otherCoupon;
  648. this.setData({
  649. /* [`block.coupon`]: block,
  650. [`form.coupon`]:block,
  651. [`temporary.coupon`]: block,*/
  652. show: false
  653. });
  654. },
  655. select() {
  656. if (this.available.coupons.length) {
  657. this.setData({
  658. show: true
  659. });
  660. } else {
  661. wx.showModal({
  662. content: '暂无可使用的优惠券',
  663. showCancel: false
  664. });
  665. }
  666. },
  667. cancel() {
  668. var coupons = this.available.coupons;
  669. coupons.forEach(v => v.checked = false);
  670. this.couponCheckIndex = -1;
  671. this.available.coupons = coupons;
  672. this.available.currentCoupon = '';
  673. this.show = false;
  674. setTimeout(() => {
  675. this.calculateOrder();
  676. }, 100)
  677. /* this.setData({
  678. couponCheckIndex: -1,
  679. 'available.coupons': coupons,
  680. 'available.currentCoupon': '',
  681. show: false
  682. }, () => {
  683. this.calculateOrder();
  684. });*/
  685. },
  686. inputNote(e) {
  687. this.form.note = e.detail.value
  688. /* this.setData({
  689. 'form.note': e.detail.value
  690. });*/
  691. },
  692. initData() {
  693. var block = this.$cookieStorage.get('local_order');
  694. var form = this.$cookieStorage.get('order_form');
  695. var is_login = this.$cookieStorage.get('user_token');
  696. this.setData({
  697. is_login: is_login,
  698. loading: false
  699. });
  700. if (block) {
  701. if (!form || form.order_no !== block.order.order_no) {
  702. form = Object.assign({}, this.form);
  703. form.order_no = block.order.order_no;
  704. if (block.address) {
  705. form.address = block.address;
  706. } // Cache.set(cache_keys.order_form, form);
  707. this.$cookieStorage.set('order_form', form);
  708. } else {}
  709. /*if (form.formStates) {
  710. this.setData({
  711. [`formStates.discountsCheckIndex`]: form.formStates.discountsCheckIndex,
  712. [`formStates.pointStatus`]: form.formStates.pointStatus
  713. })
  714. }
  715. this.setData({
  716. [`form.isDisabled`]: form.isDisabled,
  717. [`temporary.coupon`]: form.coupon
  718. })*/
  719. // 自动选择最优优惠活动
  720. /*if (JSON.stringify(form.discount) == '{}' && block.best_discount_id) {
  721. if (Array.isArray(block.discounts)) {
  722. block.discounts.forEach((item, index) => {
  723. if (item.id == block.best_discount_id) {
  724. var data = {
  725. detail: {
  726. value: index
  727. }
  728. }
  729. this.changeDiscounts(data);
  730. }
  731. })
  732. }
  733. }*/
  734. // 自动选择最优的优惠券
  735. /*if (JSON.stringify(form.coupon) == '{}' && block.best_coupon_id) {
  736. if (Array.isArray(block.coupons)) {
  737. block.coupons.forEach((item, index) => {
  738. if (item.id == block.best_coupon_id) {
  739. this.setData({
  740. 'block.otherCoupon': item
  741. }, () => {
  742. this.sure();
  743. });
  744. this.setData({
  745. check: index
  746. })
  747. }
  748. })
  749. }
  750. }*/
  751. /*this.setData({
  752. [`temporary.coupons`]: block.coupons,
  753. [`temporary.discounts`]: block.discounts
  754. })*/
  755. this.queryOrderExtra();
  756. this.setData({
  757. block: Object.assign({}, this.block, block),
  758. form: Object.assign({}, this.form, form),
  759. newBlock: Object.assign({}, this.block, block),
  760. newForm: Object.assign({}, this.form, form)
  761. });
  762. if (block.discountGroup && block.discountGroup.length) {
  763. let currentItem = block.discountGroup[0]; // 第一个为最优促销
  764. if (JSON.stringify(form.discount) == '{}' && currentItem.discount) {
  765. if (Array.isArray(block.discounts)) {
  766. block.discounts.forEach((item, index) => {
  767. if (item.id == currentItem.discount) {
  768. this.available.currentDiscount = item;
  769. /* this.setData({
  770. 'available.currentDiscount': item
  771. });*/
  772. }
  773. });
  774. this.available.discounts = block.discounts
  775. /*this.setData({
  776. 'available.discounts': block.discounts
  777. });*/
  778. }
  779. }
  780. if (JSON.stringify(form.coupon) == '{}' && currentItem.coupon) {
  781. if (Array.isArray(block.coupons)) {
  782. block.coupons.forEach((item, index) => {
  783. if (item.id == currentItem.coupon) {
  784. this.available.currentCoupon = item
  785. /* this.setData({
  786. 'available.currentCoupon': item
  787. });*/
  788. }
  789. });
  790. this.available.coupons = block.coupons
  791. /*this.setData({
  792. 'available.coupons': block.coupons
  793. });*/
  794. }
  795. }
  796. } // this.paymentMoney();
  797. setTimeout(() => {
  798. this.calculateOrder();
  799. }, 300); // t.next({block, form});
  800. } else {// this.addHistory();
  801. // t.to.router.forward({name: 'user-order-online', params: {status: 1}});
  802. }
  803. },
  804. queryOrderExtra() {
  805. var oauth = this.is_login;
  806. this.$http.get({
  807. api: `api/shopping/order/extraInfo`,
  808. header: {
  809. Authorization: oauth
  810. }
  811. }).then(res => {
  812. res = res.data;
  813. var data = res.data;
  814. if (res.status) {
  815. var extra = {
  816. point: data.userPoint,
  817. limit: data.pointLimit,
  818. factor: data.pointToMoney
  819. };
  820. this.setData({
  821. extra: extra
  822. }); // dispatch(UserOrderExtra, extra);
  823. }
  824. });
  825. },
  826. changeDiscounts(e) {
  827. let value = e.detail.value;
  828. let discountsList = this.available.discounts;
  829. let item = '';
  830. if (value == -1) {
  831. item == '';
  832. } else {
  833. discountsList.forEach((items, index) => {
  834. if (index == value) {
  835. item = items;
  836. }
  837. });
  838. }
  839. let exclusive = item.exclusive;
  840. if (exclusive) {
  841. this.available.coupons = [];
  842. this.available.currentCoupon = '';
  843. this.couponCheckIndex = -1;
  844. /* this.setData({
  845. 'available.coupons': [],
  846. 'available.currentCoupon': '',
  847. couponCheckIndex: -1
  848. });*/
  849. }
  850. this.available.currentDiscount = item;
  851. setTimeout(() => {
  852. this.calculateOrder();
  853. }, 100)
  854. /* this.setData({
  855. [`available.currentDiscount`]: item
  856. }, () => {
  857. this.calculateOrder();
  858. });*/
  859. },
  860. submitOrder() {
  861. if (this.loading) return;
  862. var info = this.initInfo;
  863. this.setData({
  864. loading: true
  865. });
  866. var data = {
  867. order_no: this.form.order_no,
  868. // 订单编号
  869. note: this.form.note // 用户留言
  870. };
  871. var itemId = this.block.order.items[0].item_meta.detail_id;
  872. if (info && info.pick_self == 1 && this.valueR != "shop" || info && info.pick_self == 0) {
  873. if (this.form.address && this.form.address.id) {
  874. data.address_id = this.form.address.id;
  875. } else {
  876. this.setData({
  877. loading: false
  878. });
  879. wx.showModal({
  880. content: '请填写收货地址',
  881. success: function (res) {
  882. if (res.confirm) {}
  883. }
  884. });
  885. return;
  886. }
  887. }
  888. data.pick_self = this.valueR;
  889. if (this.available.currentCoupon && this.available.currentCoupon.id) {
  890. data.coupon_id = this.available.currentCoupon.id;
  891. }
  892. if (this.form.invoice && this.form.invoice.name) {
  893. data.invoice = this.form.invoice;
  894. }
  895. if (this.available.currentDiscount && this.available.currentDiscount.id) {
  896. data.discount_id = this.available.currentDiscount.id;
  897. }
  898. if (this.available.pointStatus) {
  899. data.point = this.available.currentPoint;
  900. }
  901. if (this.task_id) {
  902. data.task_id = this.task_id;
  903. }
  904. var agent_code = this.$cookieStorage.get('agent_code');
  905. if (agent_code) {
  906. data.agent_code = agent_code;
  907. data.agent_goods_id = this.$cookieStorage.get('agent_goods_id');
  908. if (this.$cookieStorage.get('agent_suit_id')) {
  909. data.agent_suit_id = this.$cookieStorage.get('agent_suit_id');
  910. }
  911. }
  912. if (this.$cookieStorage.get('shop_id')) {
  913. data.shop_id = this.$cookieStorage.get('shop_id');
  914. }
  915. if (this.$cookieStorage.get('agent_code_time')) {
  916. data.agent_code_time = this.$cookieStorage.get('agent_code_time');
  917. }
  918. if (this.$cookieStorage.get('clerk_id')) {
  919. data.clerk_id = this.$cookieStorage.get('clerk_id');
  920. }
  921. if (this.$cookieStorage.get('shop_id_time')) {
  922. data.shop_id_time = this.$cookieStorage.get('shop_id_time');
  923. }
  924. if (this.$cookieStorage.get('selfShop')) {
  925. let storelocator_id = this.$cookieStorage.get('selfShop').id;
  926. data.storelocator_id = storelocator_id;
  927. }
  928. var group_info = this.$cookieStorage.get('group_info');
  929. if (this.type == 'groupon' && group_info) {
  930. data.multi_groupon_id = group_info.multi_groupon_id;
  931. data.multi_groupon_item_id = group_info.multi_groupon_item_id;
  932. }
  933. if (this.$cookieStorage.get('openGId')) {
  934. data.wechat_group_id = this.$cookieStorage.get('openGId');
  935. }
  936. this.confirmOrder(data);
  937. },
  938. confirmOrder(data) {
  939. var that = this;
  940. var oauth = this.is_login;
  941. this.$http.post({
  942. api: 'api/shopping/order/confirm?reduce_items_id='+this.reduce_items_id,
  943. data: data,
  944. header: {
  945. Authorization: oauth
  946. }
  947. }).then(res => {
  948. res = res.data;
  949. if (res.status) {
  950. this.$cookieStorage.clear('local_order');
  951. this.$cookieStorage.clear('selfShop'); // this.$emit('confirm', true, res.data);
  952. that.confirm(true, res.data);
  953. } else {
  954. that.confirm(false, res.message);
  955. }
  956. }).catch(rej => {
  957. wx.showToast({
  958. title: '提交订单失败,请重试!'
  959. });
  960. });
  961. },
  962. confirm(success, data) {
  963. if (success) {
  964. this.setData({
  965. loading: false
  966. }); // this.$refs.button.finish();
  967. var registration = this.block.registration_id;
  968. var pay_status = data.order.pay_status;
  969. if (registration || pay_status == 1) {
  970. // this.addHistory();
  971. // this.$router.forward({name: 'user-order-online', params: {status: 0}});
  972. // this.$router.forward({name: 'user-order-online', params: {status: 0}, query: {registration}});
  973. wx.redirectTo({
  974. url: `/pages/order/index/index?status=0`,
  975. success: function () {}
  976. });
  977. } else {
  978. wx.redirectTo({
  979. url: `/pages/store/payment/payment?order_no=${data.order.order_no}`,
  980. success: function () {} // this.$router.forward({name: 'store-payment', params: {order_no: data.order.order_no}});
  981. });
  982. }
  983. } else {
  984. this.setData({
  985. loading: false
  986. });
  987. wx.showModal({
  988. content: data || '提交订单失败',
  989. showCancel: false
  990. });
  991. }
  992. },
  993. // 计算订单优惠以及积分等信息
  994. calculateOrder() {
  995. let dis = {
  996. order: 0,
  997. discounts: 0,
  998. // 促销抵扣的钱
  999. coupon: 0,
  1000. // 优惠券抵扣的钱
  1001. point: 0,
  1002. // 积分抵扣的钱
  1003. pointCanUse: 0 // 可用多少积分
  1004. };
  1005. let amount = this.newBlock.order.total; // 订单应付金额
  1006. var fixedTotal = this.newBlock.order.total;
  1007. let pay_amount = amount;
  1008. let block = this.newBlock;
  1009. let pointCanotUseAmount =block.orderPoint ? block.orderPoint.pointCanotUseAmount : 0;
  1010. let currentDiscount = this.available.currentDiscount;
  1011. let currentDiscountID = currentDiscount ? currentDiscount.id : 0;
  1012. let currentCoupon = this.available.currentCoupon;
  1013. let currentCouponId = currentCoupon ? currentCoupon.id : 0;
  1014. let couponList = this.available.coupons;
  1015. let discountsList = this.available.discounts;
  1016. let currentItem = this.currentItemF(currentDiscountID, currentCouponId); // 拿到当前的组合方式
  1017. let pointStatus = this.available.pointStatus; // 如果有选择促销
  1018. if (currentDiscount) {
  1019. // 促销能减掉的钱
  1020. let discount = -currentDiscount.adjustmentTotal; // 是否排优惠券
  1021. let exclusive = currentDiscount.exclusive;
  1022. /* console.log(pay_amount); */
  1023. if (discount <= pay_amount) {
  1024. /* console.log(1); */
  1025. dis.discounts = -currentItem.discountAdjustment;
  1026. pay_amount = pay_amount + currentItem.discountAdjustment; // 值为负数,所以得加
  1027. discountsList.forEach((item, index) => {
  1028. if (item.id == currentDiscountID) {
  1029. this.setData({
  1030. discountsCheckIndex: index
  1031. });
  1032. }
  1033. }); // 如果排他,将选择的优惠券取消
  1034. if (exclusive) {
  1035. this.available.coupons = [];
  1036. this.available.currentCoupon = '';
  1037. this.couponCheckIndex = -1;
  1038. /* this.setData({
  1039. 'available.coupons': [],
  1040. 'available.currentCoupon': '',
  1041. couponCheckIndex: -1
  1042. });*/
  1043. currentCoupon = '';
  1044. currentCouponId = 0;
  1045. couponList = [];
  1046. currentItem = this.currentItemF(currentDiscountID, 0); // 拿到当前的组合方式
  1047. pay_amount = amount;
  1048. dis.discounts = -currentItem.discountAdjustment;
  1049. pay_amount = pay_amount + currentItem.discountAdjustment; // 值为负数,所以得加
  1050. } else {
  1051. // 开始筛选优惠券
  1052. let couponArr = [];
  1053. if (block.coupons && block.coupons.length) {
  1054. block.coupons.forEach(item => {
  1055. if (item.orderAmountLimit == 0 || item.orderAmountLimit <= pay_amount) {
  1056. item.checked = false;
  1057. couponArr.push(item);
  1058. }
  1059. });
  1060. this.available.coupons = couponArr;
  1061. /*this.setData({
  1062. 'available.coupons': couponArr
  1063. });*/
  1064. couponList = couponArr;
  1065. }
  1066. }
  1067. } else {
  1068. wx.showModal({
  1069. content: '超过最大折扣',
  1070. showCancel: false
  1071. });
  1072. this.available.currentDiscount = '';
  1073. /* this.setData({
  1074. 'available.currentDiscount': ''
  1075. });*/
  1076. }
  1077. } else {
  1078. // 不用促销将数据还原
  1079. dis.discounts = 0;
  1080. this.available.coupons = block.coupons;
  1081. this.discountsCheckIndex = -1;
  1082. /* this.setData({
  1083. 'available.coupons': block.coupons,
  1084. discountsCheckIndex: -1
  1085. });*/
  1086. } // 如果有选择优惠券
  1087. if (currentCoupon) {
  1088. // 优惠券能减掉的钱
  1089. let discount = -currentCoupon.adjustmentTotal; // 是否排促销
  1090. let exclusive = currentCoupon.discount.exclusive;
  1091. if (discount <= pay_amount) {
  1092. dis.coupon = -currentItem.couponAdjustment;
  1093. pay_amount = pay_amount + currentItem.couponAdjustment; // 值为负数,所以得加
  1094. couponList.forEach((item, index) => {
  1095. if (item.id == currentCouponId) {
  1096. item.checked = true;
  1097. this.setData({
  1098. couponCheckIndex: index
  1099. });
  1100. } else {
  1101. item.checked = false;
  1102. }
  1103. });
  1104. this.available.coupons = couponList
  1105. /*this.setData({
  1106. 'available.coupons': couponList
  1107. });*/
  1108. if (exclusive) {
  1109. this.available.discounts = [];
  1110. this.available.currentDiscount = '';
  1111. this.discountsCheckIndex = -1;
  1112. /* this.setData({
  1113. 'available.discounts': [],
  1114. 'available.currentDiscount': '',
  1115. discountsCheckIndex: -1
  1116. });*/
  1117. currentDiscount = '';
  1118. discountsList = [];
  1119. currentDiscountID = 0;
  1120. currentItem = this.currentItemF(0, currentCouponId); // 拿到当前的组合方式
  1121. pay_amount = amount;
  1122. dis.coupon = -currentItem.couponAdjustment;
  1123. pay_amount = pay_amount + currentItem.couponAdjustment; // 值为负数,所以得加
  1124. } else {
  1125. // 筛选促销
  1126. if (!currentDiscount) {
  1127. let discountArr = [];
  1128. if (block.discounts && block.discounts.length) {
  1129. block.discounts.forEach(item => {
  1130. if (item.orderAmountLimit == 0 || item.orderAmountLimit <= pay_amount) {
  1131. discountArr.push(item);
  1132. }
  1133. });
  1134. this.available.discounts = discountArr
  1135. /* this.setData({
  1136. 'available.discounts': discountArr
  1137. });*/
  1138. discountsList = discountArr;
  1139. }
  1140. }
  1141. }
  1142. } else {
  1143. wx.showModal({
  1144. content: '超过最大折扣',
  1145. showCancel: false
  1146. });
  1147. this.available.currentCoupon = '';
  1148. /* this.setData({
  1149. 'available.currentCoupon': ''
  1150. });*/
  1151. }
  1152. } else {
  1153. dis.coupon = 0;
  1154. this.available.discounts = block.discounts
  1155. /* this.setData({
  1156. 'available.discounts': block.discounts
  1157. });*/
  1158. }
  1159. this.newBlock.orderPoint.pointCanUse = Number(Math.min((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2));
  1160. this.newBlock.orderPoint.pointAmount = Number(Math.max(-((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2));
  1161. setTimeout(() => {
  1162. this.available.currentPoint = this.newBlock.orderPoint.pointCanUse;
  1163. this.pointAmount = (this.newBlock.orderPoint.pointAmount / 100).toFixed(2)
  1164. }, 100)
  1165. /* this.setData({
  1166. [`newBlock.orderPoint.pointCanUse`]: Number(Math.min((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
  1167. [`newBlock.orderPoint.pointAmount`]: Number(Math.max(-((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2))
  1168. }, () => {
  1169. this.setData({
  1170. [`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse,
  1171. pointAmount: (this.newBlock.orderPoint.pointAmount / 100).toFixed(2)
  1172. });
  1173. });*/
  1174. /*dis.pointCanUse = Number(Math.min((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney,this.block.orderPoint.userPoint).toFixed(2));
  1175. dis.point = Number(Math.min((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit, this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney).toFixed(2))*/
  1176. // 如果使用了积分
  1177. if (pointStatus) {
  1178. let factor = this.extra.factor;
  1179. let discount = this.available.currentPoint * factor;
  1180. if (discount <= pay_amount) {
  1181. dis.point = -discount;
  1182. pay_amount -= discount;
  1183. if (pay_amount < 0) {
  1184. pay_amount = 0;
  1185. if (dis.point != 0) {
  1186. pay_amount = -(fixedTotal + dis.point);
  1187. }
  1188. }
  1189. } else {
  1190. this.available.currentPoint = 0;
  1191. /* this.setData({
  1192. [`available.currentPoint`]: 0
  1193. });*/
  1194. }
  1195. } else {
  1196. this.available.currentPoint = 0;
  1197. /* this.setData({
  1198. [`available.currentPoint`]: 0
  1199. });*/
  1200. }
  1201. let bestDiscount = false;
  1202. let bestDiscountItem = block.discountGroup[0];
  1203. if (bestDiscountItem && currentDiscountID == bestDiscountItem.discount && currentCouponId == bestDiscountItem.coupon) {
  1204. bestDiscount = true;
  1205. }
  1206. dis.coupon_yuan = -(dis.coupon / 100).toFixed(2);
  1207. dis.discounts_yuan = -(dis.discounts / 100).toFixed(2);
  1208. dis.total_yuan = -((dis.coupon + dis.discounts) / 100).toFixed(2);
  1209. dis.point_yuan = (dis.point / 100).toFixed(2);
  1210. currentItem.adjustmentTotal_yuan = (currentItem.adjustmentTotal / 100).toFixed(2);
  1211. // this.setData({
  1212. // discounts: dis,
  1213. // pay_amount: pay_amount,
  1214. // pay_amount_yuan: ((pay_amount + block.order.payable_freight) / 100).toFixed(2),
  1215. // currentItem: currentItem,
  1216. // bestDiscount: bestDiscount
  1217. // });
  1218. //
  1219. this.discounts=dis;
  1220. this.pay_amount=pay_amount;
  1221. this.pay_amount_yuan=((pay_amount + block.order.payable_freight) / 100).toFixed(2);
  1222. this.currentItem=currentItem;
  1223. this.bestDiscount=bestDiscount;
  1224. },
  1225. // 当前选择的组合方式
  1226. currentItemF(currentDiscountID, currentCouponId) {
  1227. let block = this.newBlock;
  1228. let currentItem = {
  1229. adjustmentTotal: 0,
  1230. // 总共减掉多少钱
  1231. coupon: 0,
  1232. // 优惠券id
  1233. couponAdjustment: 0,
  1234. // 优惠券减掉多少钱
  1235. discount: 0,
  1236. // 促销id
  1237. discountAdjustment: 0 // 促销减掉多少钱
  1238. };
  1239. if (block.discountGroup && block.discountGroup.length) {
  1240. block.discountGroup.forEach(item => {
  1241. if (item.discount == currentDiscountID && item.coupon == currentCouponId) {
  1242. currentItem = item;
  1243. }
  1244. });
  1245. }
  1246. return currentItem;
  1247. },
  1248. // 使用了最优组合
  1249. bestSwitch(e) {
  1250. var block = this.$cookieStorage.get('local_order');
  1251. var form = this.$cookieStorage.get('order_form');
  1252. if (e.detail.value) {
  1253. if (block.discountGroup && block.discountGroup.length) {
  1254. let currentItem = block.discountGroup[0]; // 第一个为最优促销
  1255. if (JSON.stringify(form.discount) == '{}' && currentItem.discount) {
  1256. if (Array.isArray(block.discounts)) {
  1257. block.discounts.forEach((item, index) => {
  1258. if (item.id == currentItem.discount) {
  1259. this.setData({
  1260. 'available.currentDiscount': item
  1261. });
  1262. }
  1263. });
  1264. this.setData({
  1265. 'available.discounts': block.discounts
  1266. });
  1267. }
  1268. }
  1269. if (JSON.stringify(form.coupon) == '{}' && currentItem.coupon) {
  1270. if (Array.isArray(block.coupons)) {
  1271. block.coupons.forEach((item, index) => {
  1272. if (item.id == currentItem.coupon) {
  1273. this.setData({
  1274. 'available.currentCoupon': item
  1275. });
  1276. }
  1277. });
  1278. this.setData({
  1279. 'available.coupons': block.coupons
  1280. });
  1281. }
  1282. }
  1283. }
  1284. } else {
  1285. this.setData({
  1286. 'available.currentCoupon': '',
  1287. 'available.currentDiscount': '',
  1288. discountsCheckIndex: -1,
  1289. couponCheckIndex: -1
  1290. });
  1291. }
  1292. setTimeout(() => {
  1293. this.calculateOrder();
  1294. }, 300);
  1295. },
  1296. paymentMoney() {
  1297. return;
  1298. var dis = {
  1299. order: 0,
  1300. point: 0,
  1301. coupon: 0
  1302. };
  1303. var total = this.block.order.total;
  1304. var fixedTotal = this.block.order.total;
  1305. var block = this.$cookieStorage.get('local_order');
  1306. var pointCanotUseAmount = block.orderPoint.pointCanotUseAmount || 0; // var pointToMoney = block.orderPoint.pointToMoney;
  1307. // 订单折扣
  1308. if (this.block.discounts && Array.isArray(this.block.discounts)) {
  1309. let discounts = this.block.discounts;
  1310. let check = this.formStates.discountsCheckIndex;
  1311. if (check == -1) {
  1312. // 当选择不使用优惠的情况
  1313. dis.order = 0;
  1314. this.setData({
  1315. [`form.discount`]: {},
  1316. [`form.formStates.discountsCheckIndex`]: check
  1317. });
  1318. if (this.temporary.coupons.length) {
  1319. this.setData({
  1320. [`block.coupons`]: this.temporary.coupons
  1321. });
  1322. } // 操作积分
  1323. // this.block.orderPoint.pointCanUse = Math.min(total * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint);
  1324. // this.block.orderPoint.pointAmount = Math.max(-(total * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney));
  1325. //
  1326. // this.form.coupon = this.temporary.coupon; // 将选择的优惠券还原
  1327. this.block.orderPoint.pointCanUse = Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2));
  1328. this.block.orderPoint.pointAmount = Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2));
  1329. this.form.coupon = this.temporary.coupon;
  1330. setTimeout(() => {
  1331. this.available.currentPoint = this.newBlock.orderPoint.pointCanUse
  1332. }, 100)
  1333. /*this.setData({
  1334. [`block.orderPoint.pointCanUse`]: Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
  1335. [`block.orderPoint.pointAmount`]: Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2)),
  1336. [`form.coupon`]: this.temporary.coupon
  1337. }, () => {
  1338. this.setData({
  1339. [`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse
  1340. });
  1341. });*/
  1342. this.$cookieStorage.set('order_form', this.form);
  1343. } else {
  1344. // 当使用了优惠的情况
  1345. let discount = -discounts[check].adjustmentTotal;
  1346. let exclusive = discounts[check].exclusive; //是否排他(优惠券);
  1347. if (discount <= total) {
  1348. if (exclusive) {
  1349. this.setData({
  1350. [`block.coupon`]: {},
  1351. [`block.coupons`]: [],
  1352. [`form.coupon`]: {}
  1353. });
  1354. } else {
  1355. this.setData({
  1356. [`block.coupons`]: this.temporary.coupons,
  1357. [`form.coupon`]: this.temporary.coupon
  1358. });
  1359. }
  1360. dis.order = discounts[check].adjustmentTotal;
  1361. this.setData({
  1362. [`form.discount`]: discounts[check]
  1363. });
  1364. total -= discount; // 操作积分
  1365. this.block.orderPoint.pointCanUse = Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
  1366. this.block.orderPoint.pointAmount = Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2)),
  1367. this.form.formStates.discountsCheckIndex = check;
  1368. this.setTimeout(() => {
  1369. this.available.currentPoint = this.newBlock.orderPoint.pointCanUse
  1370. }, 100)
  1371. /*this.setData({
  1372. [`block.orderPoint.pointCanUse`]: Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
  1373. [`block.orderPoint.pointAmount`]: Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2)),
  1374. [`form.formStates.discountsCheckIndex`]: check
  1375. }, () => {
  1376. this.setData({
  1377. [`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse
  1378. });
  1379. });*/ // Cache.set(cache_keys.order_form, this.form);
  1380. this.$cookieStorage.set('order_form', this.form);
  1381. } else {
  1382. // this.$Alert('超过最大优惠折扣', () => {
  1383. // check = -1;
  1384. // });
  1385. wx.showModal({
  1386. content: '超过最大折扣',
  1387. showCancel: false,
  1388. success: function (res) {
  1389. if (res.confirm) check = -1;
  1390. }
  1391. });
  1392. this.setData({
  1393. [`form.discount`]: {}
  1394. });
  1395. this.$cookieStorage.set('order_form', this.form);
  1396. }
  1397. }
  1398. } // 优惠券折扣
  1399. if (this.block.coupon && this.block.coupon.adjustments && Array.isArray(this.block.coupon.adjustments)) {
  1400. let adjustments = this.block.coupon.adjustments;
  1401. let exclusive = this.form.coupon.discount.exclusive;
  1402. let discount = -adjustments[0].amount;
  1403. if (discount <= total) {
  1404. if (exclusive) {
  1405. // 是否排他
  1406. if (dis.order != 0) {
  1407. // debugger
  1408. total -= dis.order;
  1409. }
  1410. dis.order = 0;
  1411. this.setData({
  1412. 'form.isDisabled': true,
  1413. 'form.discount': {},
  1414. 'block.discounts': [],
  1415. 'formStates.discountsCheckIndex': -1,
  1416. 'form.formStates.discountsCheckIndex': -1
  1417. });
  1418. } else {
  1419. this.setData({
  1420. [`block.discounts`]: this.temporary.discounts,
  1421. [`form.isDisabled`]: false
  1422. }); // console.log(32424242);
  1423. }
  1424. dis.coupon = adjustments[0].amount;
  1425. total -= discount; // 操作积分
  1426. this.block.orderPoint.pointCanUse = Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
  1427. this.block.orderPoint.pointAmount = Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2))
  1428. setTimeout(() => {
  1429. this.available.currentPoint = this.newBlock.orderPoint.pointCanUse
  1430. }, 100)
  1431. /*this.setData({
  1432. [`block.orderPoint.pointCanUse`]: Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
  1433. [`block.orderPoint.pointAmount`]: Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2))
  1434. }, () => {
  1435. this.setData({
  1436. [`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse
  1437. });
  1438. });*/
  1439. } else {
  1440. wx.showModal({
  1441. content: '超过最大折扣',
  1442. showCancel: false
  1443. });
  1444. this.setData({
  1445. [`form.coupon`]: {},
  1446. [`temporary.coupon`]: {},
  1447. [`form.isDisabled`]: false
  1448. });
  1449. this.$cookieStorage.set('order_form', this.form);
  1450. }
  1451. } // 积分折扣
  1452. if (this.form.point) {
  1453. let factor = this.extra.factor;
  1454. let discount = this.form.point * factor;
  1455. if (discount <= total) {
  1456. dis.point = -discount;
  1457. total -= discount;
  1458. if (total < 0) {
  1459. total = 0;
  1460. if (dis.point != 0) {
  1461. dis.total = -(fixedTotal + dis.point);
  1462. }
  1463. } else {
  1464. // 除积分外的优惠
  1465. dis.total = dis.order + dis.coupon;
  1466. }
  1467. this.$cookieStorage.set('order_form', this.form);
  1468. } else {
  1469. this.setData({
  1470. [`form.point`]: 0
  1471. });
  1472. this.$cookieStorage.set('order_form', this.form);
  1473. }
  1474. } // 除积分外的优惠
  1475. dis.total = dis.order + dis.coupon;
  1476. if (this.form.point > this.block.orderPoint.pointCanUse && this.block.orderPoint.pointCanUse > 0) {
  1477. this.setData({
  1478. [`form.point`]: this.block.orderPoint.pointCanUse
  1479. });
  1480. dis.point = Number((this.block.orderPoint.pointCanUse * 10).toFixed(2));
  1481. }
  1482. this.setData({
  1483. [`paymentMoneys.discounts`]: dis,
  1484. [`paymentMoneys.total`]: total
  1485. });
  1486. },
  1487. usePoint(e) {
  1488. /*if (e.detail.value) {
  1489. this.setData({
  1490. [`formStates.pointStatus`]: true,
  1491. [`form.point`]: this.block.orderPoint.pointCanUse
  1492. })
  1493. this.paymentMoney()
  1494. } else {
  1495. this.setData({
  1496. [`formStates.pointStatus`]: false,
  1497. [`form.point`]: 0
  1498. })
  1499. this.paymentMoney()
  1500. }*/
  1501. if (e.detail.value) {
  1502. this.setData({
  1503. [`available.pointStatus`]: true,
  1504. [`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse
  1505. });
  1506. } else {
  1507. this.setData({
  1508. [`available.pointStatus`]: false,
  1509. [`available.currentPoint`]: 0
  1510. });
  1511. }
  1512. setTimeout(() => {
  1513. this.calculateOrder();
  1514. }, 300);
  1515. },
  1516. modifyPoint(e) {
  1517. var min = 0;
  1518. var max = this.extra.point;
  1519. var val = e.detail.value;
  1520. var use = Math.floor(this.block.order.total * this.extra.limit / this.extra.factor);
  1521. var sun = Math.floor((this.block.order.total + this.paymentMoneys.discounts.total) / this.extra.factor);
  1522. if (!isFinite(use)) use = max;
  1523. if (!isFinite(sun)) sun = max;
  1524. max = Math.min(max, use, sun);
  1525. val = parseInt(val);
  1526. if (isNaN(val)) {
  1527. val = '';
  1528. } else if (val < min) {
  1529. val = min;
  1530. } else if (val > max) {
  1531. val = max;
  1532. }
  1533. e.detail.value = val;
  1534. this.form.point = val
  1535. /* this.setData({
  1536. [`form.point`]: val
  1537. });*/
  1538. this.paymentMoney();
  1539. },
  1540. saveForm(e) {
  1541. this.$cookieStorage.set('order_form', this.form);
  1542. },
  1543. back() {
  1544. wx.navigateBack();
  1545. },
  1546. setData: function (obj) {
  1547. let that = this;
  1548. let keys = [];
  1549. let val, data;
  1550. Object.keys(obj).forEach(function (key) {
  1551. keys = key.split('.');
  1552. val = obj[key];
  1553. data = that.$data;
  1554. keys.forEach(function (key2, index) {
  1555. if (index + 1 == keys.length) {
  1556. that.$set(data, key2, val);
  1557. } else {
  1558. if (!data[key2]) {
  1559. that.$set(data, key2, {});
  1560. }
  1561. }
  1562. data = data[key2];
  1563. });
  1564. });
  1565. }
  1566. },
  1567. computed: {},
  1568. watch: {}
  1569. };
  1570. </script>
  1571. <style rel="stylesheet/less" lang="less">
  1572. @import "order";
  1573. </style>