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
1804 lines
60 KiB
<template>
|
|
<view class="">
|
|
<view id="store-order">
|
|
<view class="border-box">
|
|
<view class="order-item no-mar" v-if="initInfo && initInfo.pick_self == 1">
|
|
<view class="title mx-1px-bottom">
|
|
配送方式
|
|
</view>
|
|
<view class="ways">
|
|
<view class="item">
|
|
<radio-group class="radio-group" @change="radioChange">
|
|
<label class="radio">
|
|
<radio value="0" color="#EA4448" checked="true" ></radio>快递到家
|
|
</label>
|
|
<label class="radio">
|
|
<radio value="1" color="#EA4448" ></radio>门店自提
|
|
</label>
|
|
</radio-group>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="order-item mx-1px-top" v-if="valueR == 0">
|
|
<view class="title mx-1px-bottom">
|
|
收货信息
|
|
</view>
|
|
<view class="address info" @tap="selectAddress">
|
|
|
|
|
|
|
|
<view v-if="form && form.address && form.address.mobile">
|
|
<view class="user">
|
|
<i class="iconfont icon-yonghu1"></i>
|
|
<view class="name-box">
|
|
<text class="name">{{form.address.accept_name}}</text>
|
|
<text class="telephone">{{form.address.mobile}}</text>
|
|
</view>
|
|
</view>
|
|
<view class="address">
|
|
<i class="iconfont icon-weizhi"></i>
|
|
<text>{{form.address.address_name}} {{form.address.address}}</text>
|
|
</view>
|
|
</view>
|
|
<view class="user" v-else>
|
|
<i class="iconfont icon-juxing"></i>
|
|
<view class="name-box">
|
|
<text class="add">添加收货地址</text>
|
|
</view>
|
|
</view>
|
|
|
|
|
|
<!--<view class="name" wx:if="{{form.address}}">-->
|
|
<!--<text>{{form.address.accept_name}}</text>-->
|
|
<!--<text>{{form.address.mobile}}</text>-->
|
|
<!--</view>-->
|
|
<!--<view wx:if="{{form.address}}">-->
|
|
<!--{{form.address.address}}-->
|
|
<!--</view>-->
|
|
</view>
|
|
</view>
|
|
<view class="order-item mx-1px-top" v-if="valueR == 1">
|
|
<!-- <view class="title mx-1px-bottom">
|
|
收货信息
|
|
</view>-->
|
|
<view class="address info" @tap="selectStore">
|
|
|
|
<view class="user" v-if="self_shop == ''">
|
|
<i class="iconfont icon-juxing"></i>
|
|
<view class="name-box">
|
|
<text class="add">请选择自提门店</text>
|
|
</view>
|
|
</view>
|
|
|
|
<view v-else>
|
|
<view class="address">
|
|
<i class="iconfont icon-weizhi"></i>
|
|
<text>{{self_shop.name}}</text>
|
|
</view>
|
|
</view>
|
|
|
|
|
|
<!--<view class="name" wx:if="{{form.address}}">-->
|
|
<!--<text>{{form.address.accept_name}}</text>-->
|
|
<!--<text>{{form.address.mobile}}</text>-->
|
|
<!--</view>-->
|
|
<!--<view wx:if="{{form.address}}">-->
|
|
<!--{{form.address.address}}-->
|
|
<!--</view>-->
|
|
</view>
|
|
</view>
|
|
<view class="order-item">
|
|
<view class="title mx-1px-bottom">
|
|
商品清单
|
|
</view>
|
|
<view class="goods info mx-1px-bottom" v-for="(item, index) in block.order.items" :key="index" v-if="block.order.items.length == 1">
|
|
<view class="goods-item">
|
|
<view class="item-left">
|
|
<image :src="item.item_meta.image"></image>
|
|
</view>
|
|
<view class="item-right">
|
|
<view class="goods-name item">
|
|
<view class="name">
|
|
{{item.item_name}}
|
|
</view>
|
|
<view>
|
|
{{item.quantity}}件
|
|
</view>
|
|
</view>
|
|
<view class="goods-money item">
|
|
<view>
|
|
{{item.item_meta.specs_text}}
|
|
</view>
|
|
<view>
|
|
¥{{(item.total / 100)}}
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="info mx-1px-bottom all-goods" v-if="block.order.items.length > 1" @tap="jumpGoods">
|
|
<view class="good-box">
|
|
<view class="good-img" v-for="(item, index) in block.order.items" :key="index" wx:for-index="index" v-if="index < 4">
|
|
<image :src="item.item_meta.image" alt></image>
|
|
</view>
|
|
</view>
|
|
<div class="num">
|
|
共{{block.order.count}}件
|
|
</div>
|
|
</view>
|
|
|
|
<view class="total">
|
|
{{block.order.count}}件商品,合计¥{{(block.order.total/100)}}
|
|
</view>
|
|
</view>
|
|
|
|
<view class="order-item">
|
|
<view class="title__point info" @tap="showDiscounts">
|
|
<text>促销活动</text>
|
|
<!--<view class="no-dis" wx:if="{{!block.discounts || block.discounts.length == 0}}">
|
|
您暂无可用优惠
|
|
</view>-->
|
|
<view v-if="available.currentDiscount.id" class="coupon-label">
|
|
{{available.currentDiscount.label}} ¥{{currentItem.discountAdjustment / 100}}
|
|
</view>
|
|
<view class="discounts-item" :style="'background: ' + config.mainColor" v-else>
|
|
<text v-if="available.discounts || available.discounts.length !== 0">{{available.discounts.length || 0}}个可用活动</text>
|
|
</view>
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<view class="order-item">
|
|
<view class="coupon info" @tap="select">
|
|
<view>优惠券</view>
|
|
<view class="coupon-item">
|
|
<view v-if="available.currentCoupon.id" class="coupon-label">
|
|
{{available.currentCoupon.discount.label}} ¥{{currentItem.couponAdjustment / 100}}
|
|
</view>
|
|
<view class="coupon-num" :style="'background: ' + config.mainColor" v-else>
|
|
{{available.coupons.length || 0}}个优惠可用
|
|
</view>
|
|
</view>
|
|
|
|
</view>
|
|
</view>
|
|
|
|
<view class="order-item" v-if="(available.coupons && available.coupons.length) || (available.discounts && available.discounts.length)">
|
|
<view class="info best">
|
|
<view>推荐组合</view>
|
|
<view class="text">
|
|
<block v-if="bestDiscount">
|
|
使用推荐组合省¥{{currentItem.adjustmentTotal_yuan}}
|
|
</block>
|
|
</view>
|
|
<switch :checked="bestDiscount" @change="bestSwitch" color="#FB5054"></switch>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="order-item">
|
|
<view class="mx-1px-bottom title__point" v-if="newBlock.orderPoint.pointCanUse && newBlock.orderPoint.pointCanUse > 0">
|
|
<view>积分抵扣</view>
|
|
<view>
|
|
<!--<switch checked />-->
|
|
<switch @change="usePoint"></switch>
|
|
</view>
|
|
</view>
|
|
<view class="info title__point" v-if="!newBlock.orderPoint.pointCanUse || newBlock.orderPoint.pointCanUse <= 0">
|
|
<text>积分抵扣</text>
|
|
|
|
<view class="no-dis" v-if="newBlock.orderPoint.length === 0">
|
|
此商品不支持积分
|
|
</view>
|
|
<view class="no-dis" v-else>
|
|
您暂无可用积分
|
|
</view>
|
|
</view>
|
|
<view class="point info" v-else>
|
|
<view class="input-box mx-1px-bottom">
|
|
<view style="overflow: hidden">
|
|
<view class="input__text">共有{{newBlock.orderPoint.userPoint}}积分, 可使用积分{{newBlock.orderPoint.pointCanUse || 0}} 抵扣¥{{-pointAmount || 0}}</view>
|
|
<!--<input placeholder="可使用积分{{block.orderPoint.pointCanUse || 0}}" type="number" bindinput="modifyPoint" @change="saveForm" value="{{form.point !== 0 ? form.point : ''}}"/>-->
|
|
</view>
|
|
<!--<view class="use-all" bindtap="usePoint">
|
|
全部使用
|
|
</view>-->
|
|
<!--<view class="offset">
|
|
|
|
</view>-->
|
|
</view>
|
|
|
|
</view>
|
|
</view>
|
|
|
|
<view class="order-item" v-if="block.invoice_status == 1">
|
|
|
|
<view class="invoice info" @tap="addInvoice">
|
|
<view>
|
|
发票信息
|
|
</view>
|
|
<view class="invoice__item">
|
|
<view v-if="form.invoice.name">
|
|
{{form.invoice.name}}
|
|
</view>
|
|
<view v-else>
|
|
不开发票
|
|
</view>
|
|
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="order-item">
|
|
<view class="title mx-1px-bottom">
|
|
备注
|
|
</view>
|
|
<view class="remarks info">
|
|
<view>
|
|
<input @input="inputNote" type="text" placeholder="选填:填写您的附加信息"></input>
|
|
</view>
|
|
|
|
</view>
|
|
</view>
|
|
|
|
<view class="order-info">
|
|
<view class="info-item">
|
|
<view class="item-left">
|
|
商品件数
|
|
</view>
|
|
<view class="item-right">
|
|
{{block.order.count}}件
|
|
</view>
|
|
</view>
|
|
<view class="info-item">
|
|
<view class="item-left">
|
|
金额合计
|
|
</view>
|
|
<view class="item-right">
|
|
¥ {{block.order.total / 100}}
|
|
</view>
|
|
</view>
|
|
<view class="info-item">
|
|
<view class="item-left">
|
|
积分抵扣
|
|
</view>
|
|
<view class="item-right">
|
|
<!-- ¥{{discounts!=undefined?discounts.point_yuan:0}} -->
|
|
¥{{discounts ? discounts.point_yuan:0}}
|
|
</view>
|
|
</view>
|
|
<view class="info-item">
|
|
<view class="item-left">
|
|
优惠抵扣 :
|
|
</view>
|
|
<view class="item-right">
|
|
¥{{discounts ? discounts.total_yuan:0}}
|
|
</view>
|
|
</view>
|
|
<view class="info-item">
|
|
<view class="item-left">
|
|
运费
|
|
</view>
|
|
<view class="item-right">
|
|
-¥{{newBlock.order.payable_freight}}
|
|
</view>
|
|
</view>
|
|
|
|
<!--<view class="info-item">-->
|
|
<!--<view class="item-left money-title">-->
|
|
<!--实际支付金额-->
|
|
<!--</view>-->
|
|
<!--<view class="item-right money">-->
|
|
<!--¥{{(paymentMoneys.total + block.order.payable_freight) / 100}}-->
|
|
<!--</view>-->
|
|
<!--</view>-->
|
|
</view>
|
|
</view>
|
|
<view class="sbumit-order mx-1px-top">
|
|
<view class="back" :style="'color: ' + config.mainColor">
|
|
{{newBlock.order.count}}件商品, 合计 ¥{{pay_amount_yuan}}
|
|
</view>
|
|
<button class="sbumit" :style="'background: ' + config.mainColor" @tap="submitOrder" :loading="loading">
|
|
提交订单
|
|
</button>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="coupon-maks" :class="show ? 'cur' : ''">
|
|
<view class="coupon-box">
|
|
<radio-group @change="change">
|
|
<view class="coupon-item" v-for="(item, index) in available.coupons" :key="index">
|
|
<radio :id="'index-' + index" :value="String(index)" :checked="item.checked"></radio>
|
|
<label :for="'index-' + index">
|
|
<view class="coupon">
|
|
<view class="coupon-left" :style="'background: ' + config.mainColor">
|
|
<view class="text-wrap">
|
|
<view class="text-box">
|
|
<view class="text">
|
|
<text class="money" v-if="item.discount.action_type.type == 'cash'">¥</text>
|
|
<span>{{ item.discount.action_type.value }}</span>
|
|
|
|
<text class="money" v-if="item.discount.action_type.type == 'discount'">折</text>
|
|
</view>
|
|
<text class="label text">{{ item.discount.label }}</text>
|
|
</view>
|
|
|
|
</view>
|
|
<view class="dot-wrap">
|
|
<view class="dot-item">
|
|
|
|
</view>
|
|
<view class="dot-item">
|
|
|
|
</view>
|
|
<view class="dot-item">
|
|
|
|
</view>
|
|
<view class="dot-item">
|
|
|
|
</view>
|
|
<view class="dot-item">
|
|
|
|
</view>
|
|
<view class="dot-item">
|
|
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="coupon-right">
|
|
<view class="top">
|
|
<span class="type">
|
|
<span v-if="item.discount.channel == 'ec'">商城</span>
|
|
<span v-else>门店</span>
|
|
</span>
|
|
<text class="info">{{item.discount.title}}</text>
|
|
</view>
|
|
<view class="bottom">
|
|
<view class="bottom-use">
|
|
<view class="tiem-box">
|
|
<text>{{item.discount.use_start_time}}至{{item.discount.use_end_time}}</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="select" :class=" index == couponCheckIndex ? 'activity' : ''">
|
|
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
</label>
|
|
</view>
|
|
|
|
</radio-group>
|
|
</view>
|
|
<view class="button-box">
|
|
<button class="sure" type="primary" :style="'background: ' + config.mainColor" @tap="sure">确定</button>
|
|
<button type="default" @tap="cancel">取消</button>
|
|
</view>
|
|
</view>
|
|
|
|
<!--选择促销部分-->
|
|
<view class="maks" :class="show_discounts ? 'cur' : ''" @tap="showDiscounts">
|
|
|
|
</view>
|
|
|
|
<view class="select-coupon-discounts" :class="show_discounts ? 'cur' : ''">
|
|
<view class="select-discounts">
|
|
<view class="select-discounts-top">
|
|
<view class="title">
|
|
促销活动
|
|
<view class="close" @tap="showDiscounts">
|
|
X
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="select-discounts-bottom">
|
|
<view class="activity info">
|
|
<view v-if="!block.discounts || block.discounts.length == 0">
|
|
您暂无可用优惠
|
|
</view>
|
|
<block v-else>
|
|
<radio-group @change="changeDiscounts">
|
|
<view class="input-box mx-1px-bottom" v-for="(item, index) in available.discounts" :key="index" >
|
|
<view>
|
|
<label class="radio">
|
|
<text>{{item.label}}</text>
|
|
<radio color="red" :value="String(index)" :checked="discountsCheckIndex == index"></radio>
|
|
</label>
|
|
</view>
|
|
</view>
|
|
<view class="input-box mx-1px-bottom">
|
|
<view>
|
|
<label class="radio">
|
|
<text>不使用优惠</text>
|
|
<radio value="-1" :checked="discountsCheckIndex == -1"></radio>
|
|
</label>
|
|
</view>
|
|
</view>
|
|
</radio-group>
|
|
</block>
|
|
|
|
</view>
|
|
</view>
|
|
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<!--
|
|
<view class="select-coupon-box {{show_discounts ? 'cur' : ''}}">
|
|
|
|
</view>-->
|
|
|
|
</template>
|
|
<script>
|
|
import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
currentItem:{},
|
|
loading: false,
|
|
show: false,
|
|
block: {
|
|
order: {
|
|
items: []
|
|
},
|
|
orderPoint: {
|
|
pointAmount: 0,
|
|
pointCanUse: 0
|
|
},
|
|
otherCoupon: {}
|
|
},
|
|
pointAmount: 0,
|
|
newBlock: {},
|
|
newForm: {},
|
|
discountStatus: {},
|
|
bestDiscount: false,
|
|
// 是否为最优折扣
|
|
discountsCheckIndex: -1,
|
|
// 选择的id
|
|
couponCheckIndex: -1,
|
|
available: {
|
|
coupons: [],
|
|
//可选择的优惠券
|
|
currentCoupon: '',
|
|
//当前选择的优惠券
|
|
discounts: [],
|
|
// 可使用的促销折扣
|
|
currentDiscount: '',
|
|
// 当前选择促销折扣
|
|
currentPoint: '',
|
|
pointStatus: false
|
|
},
|
|
pay_amount: '',
|
|
extra: {
|
|
point: {}
|
|
},
|
|
form: {
|
|
order_no: '',
|
|
address: {},
|
|
coupon: {},
|
|
invoice: {},
|
|
discount: {},
|
|
point: 0,
|
|
note: '',
|
|
formStates: {},
|
|
isDisabled: false //是否禁用优惠折扣按钮
|
|
|
|
},
|
|
useList: [[{
|
|
name: '不使用',
|
|
value: 0
|
|
}, {
|
|
name: '使用',
|
|
value: 1
|
|
}]],
|
|
formStates: {
|
|
discountsCheckIndex: -1,
|
|
noDiscountsCheckList: -1,
|
|
pointStatus: false
|
|
},
|
|
temporary: {
|
|
coupons: [],
|
|
//可选择的优惠券
|
|
coupon: {},
|
|
//当前选择的优惠券
|
|
discounts: [],
|
|
// 可使用的促销折扣
|
|
discount: {} // 当前选择促销折扣
|
|
|
|
},
|
|
paymentMoneys: {
|
|
discounts: {},
|
|
total: 0
|
|
},
|
|
reduce_items_id:'',
|
|
check: null,
|
|
is_login: '',
|
|
type: '',
|
|
show_discounts: false,
|
|
task_id: '',
|
|
valueR: 0,
|
|
initInfo: '',
|
|
config: '',
|
|
accountInfo: '',
|
|
self_shop: '',
|
|
coupon: {},
|
|
pay_amount_yuan:'',
|
|
discounts: ''
|
|
};
|
|
},
|
|
|
|
onShow() {
|
|
var block = this.$cookieStorage.get('local_order');
|
|
var form = this.$cookieStorage.get('order_form');
|
|
let self_shop = this.$cookieStorage.get('selfShop');
|
|
|
|
if (block) {
|
|
if (!form || form.order_no !== block.order.order_no) {
|
|
form = Object.assign({}, this.form);
|
|
form.order_no = block.order.order_no;
|
|
|
|
if (block.address) {
|
|
form.address = block.address;
|
|
} // Cache.set(cache_keys.order_form, form);
|
|
|
|
|
|
this.$cookieStorage.set('order_form', form);
|
|
}
|
|
}
|
|
|
|
if (self_shop) {
|
|
this.setData({
|
|
self_shop: self_shop
|
|
});
|
|
}
|
|
|
|
this.setData({
|
|
block: Object.assign({}, this.block, block),
|
|
form: Object.assign({}, this.form, form)
|
|
}); // let app =getApp();
|
|
// app.isBirthday().then(()=>{
|
|
// if(this.$cookieStorage.get("birthday_gift")){
|
|
// var giftData=this.$cookieStorage.get("birthday_gift").data;
|
|
// new app.ToastPannel().__page.showText(giftData);
|
|
// }
|
|
// });
|
|
},
|
|
|
|
onLoad(e) {
|
|
|
|
var accountInfo='';
|
|
// #ifdef MP-WEIXIN
|
|
var accountInfo = wx.getAccountInfoSync(); // 第三方平台配置颜色
|
|
// #endif
|
|
|
|
|
|
var gbConfig = this.$cookieStorage.get('globalConfig') || '';
|
|
this.setData({
|
|
config: gbConfig,
|
|
accountInfo: accountInfo
|
|
});
|
|
|
|
if (e.type) {
|
|
this.setData({
|
|
type: e.type
|
|
});
|
|
}
|
|
|
|
if (e.task_id) {
|
|
this.setData({
|
|
task_id: e.task_id
|
|
});
|
|
}
|
|
if(e.reduce_items_id){
|
|
this.reduce_items_id = e.reduce_items_id
|
|
}
|
|
|
|
var info = this.$cookieStorage.get('init');
|
|
|
|
/* if (info && info.pick_self == 1) {
|
|
this.setData({
|
|
valueR: 1
|
|
});
|
|
} */
|
|
|
|
this.setData({
|
|
initInfo: info
|
|
});
|
|
this.initData();
|
|
},
|
|
methods: {
|
|
|
|
|
|
//配送方式选择
|
|
radioChange(e) {
|
|
this.setData({
|
|
valueR: e.detail.value
|
|
});
|
|
},
|
|
|
|
selectStore() {
|
|
wx.navigateTo({
|
|
url: '/pages/store/selfShop/selfShop'
|
|
});
|
|
},
|
|
|
|
showDiscounts() {
|
|
if (!this.available.discounts || this.available.discounts.length == 0) {
|
|
wx.showModal({
|
|
content: '您暂无可用优惠',
|
|
showCancel: false
|
|
});
|
|
} else {
|
|
this.setData({
|
|
show_discounts: !this.show_discounts
|
|
});
|
|
}
|
|
},
|
|
|
|
addInvoice() {
|
|
wx.navigateTo({
|
|
url: `/pages/store/invoice/invoice?order_no=${this.block.order.order_no}&url=${getCurrentPages()[getCurrentPages().length - 1].route}`
|
|
});
|
|
},
|
|
|
|
selectAddress() {
|
|
wx.navigateTo({
|
|
url: `/pages/address/list/list?order_no=${this.block.order.order_no}&url=${getCurrentPages()[getCurrentPages().length - 1].route}`
|
|
});
|
|
},
|
|
|
|
jumpGoods() {
|
|
wx.navigateTo({
|
|
url: '/pages/store/orderGoods/orderGoods?no=' + this.block.order.order_no
|
|
});
|
|
},
|
|
|
|
change(e) {
|
|
let value = e.detail.value;
|
|
let couponList = this.available.coupons;
|
|
let item = '';
|
|
couponList.forEach((items, index) => {
|
|
if (index == value) {
|
|
item = items;
|
|
}
|
|
});
|
|
let exclusive = item.discount.exclusive;
|
|
|
|
if (exclusive) {
|
|
this.available.discounts = [];
|
|
this.available.currentDiscount = '';
|
|
this.discountsCheckIndex = -1;
|
|
/*this.setData({
|
|
'available.discounts': [],
|
|
'available.currentDiscount': '',
|
|
discountsCheckIndex: -1
|
|
});*/
|
|
}
|
|
|
|
this.available.currentCoupon = item;
|
|
this.show = false;
|
|
setTimeout(() => {
|
|
this.calculateOrder();
|
|
}, 100)
|
|
/*this.setData({
|
|
[`available.currentCoupon`]: item,
|
|
show: false
|
|
}, () => {
|
|
this.calculateOrder();
|
|
});*/
|
|
/*this.setData({
|
|
check: e.detail.value
|
|
})
|
|
var coupons = this.block.coupons
|
|
var item = coupons[e.detail.value]
|
|
var data = this.$cookieStorage.get('order_form')
|
|
let exclusive = item.discount.exclusive
|
|
if (!data) return;
|
|
coupons.forEach((v, key) => v.checked = key == e.detail.value)
|
|
if (Array.isArray(item.adjustments)) {
|
|
item.adjustments.sort((a, b) => {
|
|
return Math.abs(a.amount) < Math.abs(b.amount);
|
|
});
|
|
}
|
|
// 排他
|
|
if (exclusive) {
|
|
data.formStates.discountsCheckIndex = -1;
|
|
data.isDisabled = true;
|
|
} else {
|
|
data.isDisabled = false;
|
|
}
|
|
data.otherCoupon = item;
|
|
data.coupons = coupons;
|
|
// Cache.set(cache_keys.order_form, data);
|
|
this.setData({
|
|
block: Object.assign({}, this.block, data)
|
|
})
|
|
this.$cookieStorage.set('order_form', data)
|
|
this.paymentMoney()*/
|
|
},
|
|
|
|
sure() {
|
|
var block = this.block.otherCoupon;
|
|
this.setData({
|
|
/* [`block.coupon`]: block,
|
|
[`form.coupon`]:block,
|
|
[`temporary.coupon`]: block,*/
|
|
show: false
|
|
});
|
|
|
|
},
|
|
|
|
select() {
|
|
if (this.available.coupons.length) {
|
|
this.setData({
|
|
show: true
|
|
});
|
|
} else {
|
|
wx.showModal({
|
|
content: '暂无可使用的优惠券',
|
|
showCancel: false
|
|
});
|
|
}
|
|
},
|
|
|
|
cancel() {
|
|
var coupons = this.available.coupons;
|
|
coupons.forEach(v => v.checked = false);
|
|
this.couponCheckIndex = -1;
|
|
this.available.coupons = coupons;
|
|
this.available.currentCoupon = '';
|
|
this.show = false;
|
|
|
|
setTimeout(() => {
|
|
this.calculateOrder();
|
|
}, 100)
|
|
/* this.setData({
|
|
couponCheckIndex: -1,
|
|
'available.coupons': coupons,
|
|
'available.currentCoupon': '',
|
|
show: false
|
|
}, () => {
|
|
this.calculateOrder();
|
|
});*/
|
|
},
|
|
|
|
inputNote(e) {
|
|
this.form.note = e.detail.value
|
|
/* this.setData({
|
|
'form.note': e.detail.value
|
|
});*/
|
|
},
|
|
|
|
initData() {
|
|
var block = this.$cookieStorage.get('local_order');
|
|
var form = this.$cookieStorage.get('order_form');
|
|
var is_login = this.$cookieStorage.get('user_token');
|
|
this.setData({
|
|
is_login: is_login,
|
|
loading: false
|
|
});
|
|
|
|
if (block) {
|
|
if (!form || form.order_no !== block.order.order_no) {
|
|
form = Object.assign({}, this.form);
|
|
|
|
form.order_no = block.order.order_no;
|
|
|
|
if (block.address) {
|
|
form.address = block.address;
|
|
} // Cache.set(cache_keys.order_form, form);
|
|
|
|
this.$cookieStorage.set('order_form', form);
|
|
|
|
} else {}
|
|
|
|
/*if (form.formStates) {
|
|
this.setData({
|
|
[`formStates.discountsCheckIndex`]: form.formStates.discountsCheckIndex,
|
|
[`formStates.pointStatus`]: form.formStates.pointStatus
|
|
})
|
|
}
|
|
this.setData({
|
|
[`form.isDisabled`]: form.isDisabled,
|
|
[`temporary.coupon`]: form.coupon
|
|
})*/
|
|
// 自动选择最优优惠活动
|
|
|
|
/*if (JSON.stringify(form.discount) == '{}' && block.best_discount_id) {
|
|
if (Array.isArray(block.discounts)) {
|
|
block.discounts.forEach((item, index) => {
|
|
if (item.id == block.best_discount_id) {
|
|
var data = {
|
|
detail: {
|
|
value: index
|
|
}
|
|
}
|
|
this.changeDiscounts(data);
|
|
}
|
|
})
|
|
}
|
|
}*/
|
|
// 自动选择最优的优惠券
|
|
|
|
/*if (JSON.stringify(form.coupon) == '{}' && block.best_coupon_id) {
|
|
if (Array.isArray(block.coupons)) {
|
|
block.coupons.forEach((item, index) => {
|
|
if (item.id == block.best_coupon_id) {
|
|
this.setData({
|
|
'block.otherCoupon': item
|
|
}, () => {
|
|
this.sure();
|
|
});
|
|
this.setData({
|
|
check: index
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}*/
|
|
|
|
/*this.setData({
|
|
[`temporary.coupons`]: block.coupons,
|
|
[`temporary.discounts`]: block.discounts
|
|
})*/
|
|
|
|
|
|
this.queryOrderExtra();
|
|
|
|
this.setData({
|
|
block: Object.assign({}, this.block, block),
|
|
form: Object.assign({}, this.form, form),
|
|
newBlock: Object.assign({}, this.block, block),
|
|
newForm: Object.assign({}, this.form, form)
|
|
});
|
|
|
|
if (block.discountGroup && block.discountGroup.length) {
|
|
let currentItem = block.discountGroup[0]; // 第一个为最优促销
|
|
|
|
if (JSON.stringify(form.discount) == '{}' && currentItem.discount) {
|
|
if (Array.isArray(block.discounts)) {
|
|
block.discounts.forEach((item, index) => {
|
|
if (item.id == currentItem.discount) {
|
|
this.available.currentDiscount = item;
|
|
/* this.setData({
|
|
'available.currentDiscount': item
|
|
});*/
|
|
}
|
|
});
|
|
this.available.discounts = block.discounts
|
|
/*this.setData({
|
|
'available.discounts': block.discounts
|
|
});*/
|
|
}
|
|
}
|
|
|
|
if (JSON.stringify(form.coupon) == '{}' && currentItem.coupon) {
|
|
if (Array.isArray(block.coupons)) {
|
|
block.coupons.forEach((item, index) => {
|
|
if (item.id == currentItem.coupon) {
|
|
this.available.currentCoupon = item
|
|
/* this.setData({
|
|
'available.currentCoupon': item
|
|
});*/
|
|
}
|
|
});
|
|
this.available.coupons = block.coupons
|
|
/*this.setData({
|
|
'available.coupons': block.coupons
|
|
});*/
|
|
}
|
|
}
|
|
} // this.paymentMoney();
|
|
|
|
|
|
setTimeout(() => {
|
|
this.calculateOrder();
|
|
}, 300); // t.next({block, form});
|
|
} else {// this.addHistory();
|
|
// t.to.router.forward({name: 'user-order-online', params: {status: 1}});
|
|
}
|
|
},
|
|
|
|
queryOrderExtra() {
|
|
var oauth = this.is_login;
|
|
this.$http.get({
|
|
api: `api/shopping/order/extraInfo`,
|
|
header: {
|
|
Authorization: oauth
|
|
}
|
|
}).then(res => {
|
|
res = res.data;
|
|
var data = res.data;
|
|
|
|
if (res.status) {
|
|
var extra = {
|
|
point: data.userPoint,
|
|
limit: data.pointLimit,
|
|
factor: data.pointToMoney
|
|
};
|
|
this.setData({
|
|
extra: extra
|
|
}); // dispatch(UserOrderExtra, extra);
|
|
}
|
|
});
|
|
},
|
|
|
|
changeDiscounts(e) {
|
|
let value = e.detail.value;
|
|
let discountsList = this.available.discounts;
|
|
let item = '';
|
|
|
|
if (value == -1) {
|
|
item == '';
|
|
} else {
|
|
discountsList.forEach((items, index) => {
|
|
if (index == value) {
|
|
item = items;
|
|
}
|
|
});
|
|
}
|
|
|
|
let exclusive = item.exclusive;
|
|
|
|
if (exclusive) {
|
|
this.available.coupons = [];
|
|
this.available.currentCoupon = '';
|
|
this.couponCheckIndex = -1;
|
|
/* this.setData({
|
|
'available.coupons': [],
|
|
'available.currentCoupon': '',
|
|
couponCheckIndex: -1
|
|
});*/
|
|
}
|
|
|
|
this.available.currentDiscount = item;
|
|
setTimeout(() => {
|
|
this.calculateOrder();
|
|
}, 100)
|
|
/* this.setData({
|
|
[`available.currentDiscount`]: item
|
|
}, () => {
|
|
this.calculateOrder();
|
|
});*/
|
|
},
|
|
|
|
submitOrder() {
|
|
if (this.loading) return;
|
|
var info = this.initInfo;
|
|
this.setData({
|
|
loading: true
|
|
});
|
|
var data = {
|
|
order_no: this.form.order_no,
|
|
// 订单编号
|
|
note: this.form.note // 用户留言
|
|
|
|
};
|
|
var itemId = this.block.order.items[0].item_meta.detail_id;
|
|
|
|
if (info && info.pick_self == 1 && this.valueR != "shop" || info && info.pick_self == 0) {
|
|
if (this.form.address && this.form.address.id) {
|
|
data.address_id = this.form.address.id;
|
|
} else {
|
|
this.setData({
|
|
loading: false
|
|
});
|
|
wx.showModal({
|
|
content: '请填写收货地址',
|
|
success: function (res) {
|
|
if (res.confirm) {}
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
|
|
data.pick_self = this.valueR;
|
|
|
|
if (this.available.currentCoupon && this.available.currentCoupon.id) {
|
|
data.coupon_id = this.available.currentCoupon.id;
|
|
}
|
|
|
|
if (this.form.invoice && this.form.invoice.name) {
|
|
data.invoice = this.form.invoice;
|
|
}
|
|
|
|
if (this.available.currentDiscount && this.available.currentDiscount.id) {
|
|
data.discount_id = this.available.currentDiscount.id;
|
|
}
|
|
|
|
if (this.available.pointStatus) {
|
|
data.point = this.available.currentPoint;
|
|
}
|
|
|
|
if (this.task_id) {
|
|
data.task_id = this.task_id;
|
|
}
|
|
|
|
var agent_code = this.$cookieStorage.get('agent_code');
|
|
|
|
if (agent_code) {
|
|
data.agent_code = agent_code;
|
|
data.agent_goods_id = this.$cookieStorage.get('agent_goods_id');
|
|
|
|
if (this.$cookieStorage.get('agent_suit_id')) {
|
|
data.agent_suit_id = this.$cookieStorage.get('agent_suit_id');
|
|
}
|
|
}
|
|
|
|
if (this.$cookieStorage.get('shop_id')) {
|
|
data.shop_id = this.$cookieStorage.get('shop_id');
|
|
}
|
|
|
|
if (this.$cookieStorage.get('agent_code_time')) {
|
|
data.agent_code_time = this.$cookieStorage.get('agent_code_time');
|
|
}
|
|
|
|
if (this.$cookieStorage.get('clerk_id')) {
|
|
data.clerk_id = this.$cookieStorage.get('clerk_id');
|
|
}
|
|
|
|
if (this.$cookieStorage.get('shop_id_time')) {
|
|
data.shop_id_time = this.$cookieStorage.get('shop_id_time');
|
|
}
|
|
|
|
if (this.$cookieStorage.get('selfShop')) {
|
|
let storelocator_id = this.$cookieStorage.get('selfShop').id;
|
|
data.storelocator_id = storelocator_id;
|
|
}
|
|
|
|
var group_info = this.$cookieStorage.get('group_info');
|
|
|
|
if (this.type == 'groupon' && group_info) {
|
|
data.multi_groupon_id = group_info.multi_groupon_id;
|
|
data.multi_groupon_item_id = group_info.multi_groupon_item_id;
|
|
}
|
|
|
|
if (this.$cookieStorage.get('openGId')) {
|
|
data.wechat_group_id = this.$cookieStorage.get('openGId');
|
|
}
|
|
|
|
this.confirmOrder(data);
|
|
},
|
|
|
|
confirmOrder(data) {
|
|
|
|
var that = this;
|
|
var oauth = this.is_login;
|
|
this.$http.post({
|
|
api: 'api/shopping/order/confirm?reduce_items_id='+this.reduce_items_id,
|
|
data: data,
|
|
header: {
|
|
Authorization: oauth
|
|
}
|
|
}).then(res => {
|
|
res = res.data;
|
|
if (res.status) {
|
|
this.$cookieStorage.clear('local_order');
|
|
this.$cookieStorage.clear('selfShop'); // this.$emit('confirm', true, res.data);
|
|
|
|
that.confirm(true, res.data);
|
|
} else {
|
|
that.confirm(false, res.message);
|
|
}
|
|
}).catch(rej => {
|
|
wx.showToast({
|
|
title: '提交订单失败,请重试!'
|
|
});
|
|
});
|
|
},
|
|
|
|
confirm(success, data) {
|
|
if (success) {
|
|
this.setData({
|
|
loading: false
|
|
}); // this.$refs.button.finish();
|
|
|
|
var registration = this.block.registration_id;
|
|
var pay_status = data.order.pay_status;
|
|
|
|
if (registration || pay_status == 1) {
|
|
// this.addHistory();
|
|
// this.$router.forward({name: 'user-order-online', params: {status: 0}});
|
|
// this.$router.forward({name: 'user-order-online', params: {status: 0}, query: {registration}});
|
|
wx.redirectTo({
|
|
url: `/pages/order/index/index?status=0`,
|
|
success: function () {}
|
|
});
|
|
} else {
|
|
wx.redirectTo({
|
|
url: `/pages/store/payment/payment?order_no=${data.order.order_no}`,
|
|
success: function () {} // this.$router.forward({name: 'store-payment', params: {order_no: data.order.order_no}});
|
|
|
|
});
|
|
}
|
|
} else {
|
|
this.setData({
|
|
loading: false
|
|
});
|
|
wx.showModal({
|
|
content: data || '提交订单失败',
|
|
showCancel: false
|
|
});
|
|
}
|
|
},
|
|
|
|
// 计算订单优惠以及积分等信息
|
|
calculateOrder() {
|
|
let dis = {
|
|
order: 0,
|
|
discounts: 0,
|
|
// 促销抵扣的钱
|
|
coupon: 0,
|
|
// 优惠券抵扣的钱
|
|
point: 0,
|
|
// 积分抵扣的钱
|
|
pointCanUse: 0 // 可用多少积分
|
|
|
|
};
|
|
let amount = this.newBlock.order.total; // 订单应付金额
|
|
|
|
var fixedTotal = this.newBlock.order.total;
|
|
let pay_amount = amount;
|
|
let block = this.newBlock;
|
|
let pointCanotUseAmount =block.orderPoint ? block.orderPoint.pointCanotUseAmount : 0;
|
|
let currentDiscount = this.available.currentDiscount;
|
|
let currentDiscountID = currentDiscount ? currentDiscount.id : 0;
|
|
let currentCoupon = this.available.currentCoupon;
|
|
let currentCouponId = currentCoupon ? currentCoupon.id : 0;
|
|
let couponList = this.available.coupons;
|
|
let discountsList = this.available.discounts;
|
|
let currentItem = this.currentItemF(currentDiscountID, currentCouponId); // 拿到当前的组合方式
|
|
|
|
let pointStatus = this.available.pointStatus; // 如果有选择促销
|
|
|
|
if (currentDiscount) {
|
|
// 促销能减掉的钱
|
|
let discount = -currentDiscount.adjustmentTotal; // 是否排优惠券
|
|
|
|
let exclusive = currentDiscount.exclusive;
|
|
/* console.log(pay_amount); */
|
|
|
|
if (discount <= pay_amount) {
|
|
/* console.log(1); */
|
|
dis.discounts = -currentItem.discountAdjustment;
|
|
pay_amount = pay_amount + currentItem.discountAdjustment; // 值为负数,所以得加
|
|
|
|
discountsList.forEach((item, index) => {
|
|
if (item.id == currentDiscountID) {
|
|
this.setData({
|
|
discountsCheckIndex: index
|
|
});
|
|
}
|
|
}); // 如果排他,将选择的优惠券取消
|
|
|
|
if (exclusive) {
|
|
this.available.coupons = [];
|
|
this.available.currentCoupon = '';
|
|
this.couponCheckIndex = -1;
|
|
/* this.setData({
|
|
'available.coupons': [],
|
|
'available.currentCoupon': '',
|
|
couponCheckIndex: -1
|
|
});*/
|
|
currentCoupon = '';
|
|
currentCouponId = 0;
|
|
couponList = [];
|
|
currentItem = this.currentItemF(currentDiscountID, 0); // 拿到当前的组合方式
|
|
|
|
pay_amount = amount;
|
|
dis.discounts = -currentItem.discountAdjustment;
|
|
pay_amount = pay_amount + currentItem.discountAdjustment; // 值为负数,所以得加
|
|
} else {
|
|
// 开始筛选优惠券
|
|
|
|
let couponArr = [];
|
|
|
|
if (block.coupons && block.coupons.length) {
|
|
block.coupons.forEach(item => {
|
|
if (item.orderAmountLimit == 0 || item.orderAmountLimit <= pay_amount) {
|
|
item.checked = false;
|
|
couponArr.push(item);
|
|
}
|
|
});
|
|
this.available.coupons = couponArr;
|
|
/*this.setData({
|
|
'available.coupons': couponArr
|
|
});*/
|
|
couponList = couponArr;
|
|
}
|
|
}
|
|
} else {
|
|
wx.showModal({
|
|
content: '超过最大折扣',
|
|
showCancel: false
|
|
});
|
|
this.available.currentDiscount = '';
|
|
/* this.setData({
|
|
'available.currentDiscount': ''
|
|
});*/
|
|
}
|
|
|
|
|
|
} else {
|
|
// 不用促销将数据还原
|
|
dis.discounts = 0;
|
|
this.available.coupons = block.coupons;
|
|
this.discountsCheckIndex = -1;
|
|
/* this.setData({
|
|
'available.coupons': block.coupons,
|
|
discountsCheckIndex: -1
|
|
});*/
|
|
} // 如果有选择优惠券
|
|
|
|
|
|
if (currentCoupon) {
|
|
// 优惠券能减掉的钱
|
|
let discount = -currentCoupon.adjustmentTotal; // 是否排促销
|
|
|
|
let exclusive = currentCoupon.discount.exclusive;
|
|
|
|
if (discount <= pay_amount) {
|
|
|
|
dis.coupon = -currentItem.couponAdjustment;
|
|
pay_amount = pay_amount + currentItem.couponAdjustment; // 值为负数,所以得加
|
|
|
|
couponList.forEach((item, index) => {
|
|
if (item.id == currentCouponId) {
|
|
item.checked = true;
|
|
this.setData({
|
|
couponCheckIndex: index
|
|
});
|
|
} else {
|
|
item.checked = false;
|
|
}
|
|
});
|
|
|
|
this.available.coupons = couponList
|
|
/*this.setData({
|
|
'available.coupons': couponList
|
|
});*/
|
|
|
|
if (exclusive) {
|
|
this.available.discounts = [];
|
|
this.available.currentDiscount = '';
|
|
this.discountsCheckIndex = -1;
|
|
/* this.setData({
|
|
'available.discounts': [],
|
|
'available.currentDiscount': '',
|
|
discountsCheckIndex: -1
|
|
});*/
|
|
currentDiscount = '';
|
|
discountsList = [];
|
|
currentDiscountID = 0;
|
|
currentItem = this.currentItemF(0, currentCouponId); // 拿到当前的组合方式
|
|
|
|
pay_amount = amount;
|
|
dis.coupon = -currentItem.couponAdjustment;
|
|
pay_amount = pay_amount + currentItem.couponAdjustment; // 值为负数,所以得加
|
|
} else {
|
|
// 筛选促销
|
|
if (!currentDiscount) {
|
|
let discountArr = [];
|
|
|
|
if (block.discounts && block.discounts.length) {
|
|
block.discounts.forEach(item => {
|
|
if (item.orderAmountLimit == 0 || item.orderAmountLimit <= pay_amount) {
|
|
discountArr.push(item);
|
|
}
|
|
});
|
|
this.available.discounts = discountArr
|
|
/* this.setData({
|
|
'available.discounts': discountArr
|
|
});*/
|
|
discountsList = discountArr;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
|
|
wx.showModal({
|
|
content: '超过最大折扣',
|
|
showCancel: false
|
|
});
|
|
this.available.currentCoupon = '';
|
|
|
|
/* this.setData({
|
|
'available.currentCoupon': ''
|
|
});*/
|
|
}
|
|
|
|
|
|
} else {
|
|
dis.coupon = 0;
|
|
this.available.discounts = block.discounts
|
|
/* this.setData({
|
|
'available.discounts': block.discounts
|
|
});*/
|
|
}
|
|
|
|
this.newBlock.orderPoint.pointCanUse = Number(Math.min((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2));
|
|
this.newBlock.orderPoint.pointAmount = Number(Math.max(-((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2));
|
|
|
|
setTimeout(() => {
|
|
this.available.currentPoint = this.newBlock.orderPoint.pointCanUse;
|
|
this.pointAmount = (this.newBlock.orderPoint.pointAmount / 100).toFixed(2)
|
|
}, 100)
|
|
/* this.setData({
|
|
[`newBlock.orderPoint.pointCanUse`]: Number(Math.min((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
|
|
[`newBlock.orderPoint.pointAmount`]: Number(Math.max(-((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2))
|
|
}, () => {
|
|
this.setData({
|
|
[`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse,
|
|
pointAmount: (this.newBlock.orderPoint.pointAmount / 100).toFixed(2)
|
|
});
|
|
});*/
|
|
/*dis.pointCanUse = Number(Math.min((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney,this.block.orderPoint.userPoint).toFixed(2));
|
|
dis.point = Number(Math.min((pay_amount - pointCanotUseAmount) * this.block.orderPoint.pointLimit, this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney).toFixed(2))*/
|
|
// 如果使用了积分
|
|
|
|
if (pointStatus) {
|
|
|
|
let factor = this.extra.factor;
|
|
let discount = this.available.currentPoint * factor;
|
|
|
|
if (discount <= pay_amount) {
|
|
dis.point = -discount;
|
|
pay_amount -= discount;
|
|
|
|
if (pay_amount < 0) {
|
|
pay_amount = 0;
|
|
|
|
if (dis.point != 0) {
|
|
pay_amount = -(fixedTotal + dis.point);
|
|
}
|
|
}
|
|
} else {
|
|
this.available.currentPoint = 0;
|
|
|
|
/* this.setData({
|
|
[`available.currentPoint`]: 0
|
|
});*/
|
|
}
|
|
} else {
|
|
this.available.currentPoint = 0;
|
|
/* this.setData({
|
|
[`available.currentPoint`]: 0
|
|
});*/
|
|
}
|
|
|
|
let bestDiscount = false;
|
|
let bestDiscountItem = block.discountGroup[0];
|
|
|
|
if (bestDiscountItem && currentDiscountID == bestDiscountItem.discount && currentCouponId == bestDiscountItem.coupon) {
|
|
bestDiscount = true;
|
|
}
|
|
|
|
dis.coupon_yuan = -(dis.coupon / 100).toFixed(2);
|
|
dis.discounts_yuan = -(dis.discounts / 100).toFixed(2);
|
|
dis.total_yuan = -((dis.coupon + dis.discounts) / 100).toFixed(2);
|
|
dis.point_yuan = (dis.point / 100).toFixed(2);
|
|
currentItem.adjustmentTotal_yuan = (currentItem.adjustmentTotal / 100).toFixed(2);
|
|
|
|
|
|
// this.setData({
|
|
// discounts: dis,
|
|
// pay_amount: pay_amount,
|
|
// pay_amount_yuan: ((pay_amount + block.order.payable_freight) / 100).toFixed(2),
|
|
// currentItem: currentItem,
|
|
// bestDiscount: bestDiscount
|
|
// });
|
|
//
|
|
|
|
this.discounts=dis;
|
|
this.pay_amount=pay_amount;
|
|
this.pay_amount_yuan=((pay_amount + block.order.payable_freight) / 100).toFixed(2);
|
|
this.currentItem=currentItem;
|
|
this.bestDiscount=bestDiscount;
|
|
|
|
},
|
|
|
|
// 当前选择的组合方式
|
|
currentItemF(currentDiscountID, currentCouponId) {
|
|
|
|
let block = this.newBlock;
|
|
let currentItem = {
|
|
adjustmentTotal: 0,
|
|
// 总共减掉多少钱
|
|
coupon: 0,
|
|
// 优惠券id
|
|
couponAdjustment: 0,
|
|
// 优惠券减掉多少钱
|
|
discount: 0,
|
|
// 促销id
|
|
discountAdjustment: 0 // 促销减掉多少钱
|
|
|
|
};
|
|
|
|
if (block.discountGroup && block.discountGroup.length) {
|
|
block.discountGroup.forEach(item => {
|
|
if (item.discount == currentDiscountID && item.coupon == currentCouponId) {
|
|
currentItem = item;
|
|
}
|
|
});
|
|
}
|
|
|
|
return currentItem;
|
|
},
|
|
|
|
// 使用了最优组合
|
|
bestSwitch(e) {
|
|
var block = this.$cookieStorage.get('local_order');
|
|
var form = this.$cookieStorage.get('order_form');
|
|
|
|
if (e.detail.value) {
|
|
if (block.discountGroup && block.discountGroup.length) {
|
|
let currentItem = block.discountGroup[0]; // 第一个为最优促销
|
|
|
|
if (JSON.stringify(form.discount) == '{}' && currentItem.discount) {
|
|
if (Array.isArray(block.discounts)) {
|
|
block.discounts.forEach((item, index) => {
|
|
if (item.id == currentItem.discount) {
|
|
this.setData({
|
|
'available.currentDiscount': item
|
|
});
|
|
}
|
|
});
|
|
this.setData({
|
|
'available.discounts': block.discounts
|
|
});
|
|
}
|
|
}
|
|
|
|
if (JSON.stringify(form.coupon) == '{}' && currentItem.coupon) {
|
|
if (Array.isArray(block.coupons)) {
|
|
block.coupons.forEach((item, index) => {
|
|
if (item.id == currentItem.coupon) {
|
|
this.setData({
|
|
'available.currentCoupon': item
|
|
});
|
|
}
|
|
});
|
|
this.setData({
|
|
'available.coupons': block.coupons
|
|
});
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
this.setData({
|
|
'available.currentCoupon': '',
|
|
'available.currentDiscount': '',
|
|
discountsCheckIndex: -1,
|
|
couponCheckIndex: -1
|
|
});
|
|
}
|
|
|
|
setTimeout(() => {
|
|
this.calculateOrder();
|
|
}, 300);
|
|
},
|
|
|
|
paymentMoney() {
|
|
return;
|
|
var dis = {
|
|
order: 0,
|
|
point: 0,
|
|
coupon: 0
|
|
};
|
|
var total = this.block.order.total;
|
|
var fixedTotal = this.block.order.total;
|
|
var block = this.$cookieStorage.get('local_order');
|
|
var pointCanotUseAmount = block.orderPoint.pointCanotUseAmount || 0; // var pointToMoney = block.orderPoint.pointToMoney;
|
|
// 订单折扣
|
|
|
|
if (this.block.discounts && Array.isArray(this.block.discounts)) {
|
|
let discounts = this.block.discounts;
|
|
let check = this.formStates.discountsCheckIndex;
|
|
|
|
|
|
if (check == -1) {
|
|
// 当选择不使用优惠的情况
|
|
dis.order = 0;
|
|
this.setData({
|
|
[`form.discount`]: {},
|
|
[`form.formStates.discountsCheckIndex`]: check
|
|
});
|
|
|
|
if (this.temporary.coupons.length) {
|
|
this.setData({
|
|
[`block.coupons`]: this.temporary.coupons
|
|
});
|
|
} // 操作积分
|
|
// this.block.orderPoint.pointCanUse = Math.min(total * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint);
|
|
// this.block.orderPoint.pointAmount = Math.max(-(total * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney));
|
|
//
|
|
// this.form.coupon = this.temporary.coupon; // 将选择的优惠券还原
|
|
|
|
this.block.orderPoint.pointCanUse = Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2));
|
|
this.block.orderPoint.pointAmount = Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2));
|
|
this.form.coupon = this.temporary.coupon;
|
|
|
|
setTimeout(() => {
|
|
this.available.currentPoint = this.newBlock.orderPoint.pointCanUse
|
|
}, 100)
|
|
/*this.setData({
|
|
[`block.orderPoint.pointCanUse`]: Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
|
|
[`block.orderPoint.pointAmount`]: Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2)),
|
|
[`form.coupon`]: this.temporary.coupon
|
|
}, () => {
|
|
this.setData({
|
|
[`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse
|
|
});
|
|
});*/
|
|
this.$cookieStorage.set('order_form', this.form);
|
|
} else {
|
|
// 当使用了优惠的情况
|
|
let discount = -discounts[check].adjustmentTotal;
|
|
|
|
let exclusive = discounts[check].exclusive; //是否排他(优惠券);
|
|
|
|
if (discount <= total) {
|
|
if (exclusive) {
|
|
this.setData({
|
|
[`block.coupon`]: {},
|
|
[`block.coupons`]: [],
|
|
[`form.coupon`]: {}
|
|
});
|
|
} else {
|
|
this.setData({
|
|
[`block.coupons`]: this.temporary.coupons,
|
|
[`form.coupon`]: this.temporary.coupon
|
|
});
|
|
}
|
|
|
|
dis.order = discounts[check].adjustmentTotal;
|
|
this.setData({
|
|
[`form.discount`]: discounts[check]
|
|
});
|
|
total -= discount; // 操作积分
|
|
|
|
this.block.orderPoint.pointCanUse = Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
|
|
this.block.orderPoint.pointAmount = Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2)),
|
|
this.form.formStates.discountsCheckIndex = check;
|
|
|
|
this.setTimeout(() => {
|
|
this.available.currentPoint = this.newBlock.orderPoint.pointCanUse
|
|
}, 100)
|
|
/*this.setData({
|
|
[`block.orderPoint.pointCanUse`]: Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
|
|
[`block.orderPoint.pointAmount`]: Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2)),
|
|
[`form.formStates.discountsCheckIndex`]: check
|
|
}, () => {
|
|
this.setData({
|
|
[`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse
|
|
});
|
|
});*/ // Cache.set(cache_keys.order_form, this.form);
|
|
|
|
this.$cookieStorage.set('order_form', this.form);
|
|
} else {
|
|
// this.$Alert('超过最大优惠折扣', () => {
|
|
// check = -1;
|
|
// });
|
|
wx.showModal({
|
|
content: '超过最大折扣',
|
|
showCancel: false,
|
|
success: function (res) {
|
|
if (res.confirm) check = -1;
|
|
}
|
|
});
|
|
this.setData({
|
|
[`form.discount`]: {}
|
|
});
|
|
this.$cookieStorage.set('order_form', this.form);
|
|
}
|
|
}
|
|
} // 优惠券折扣
|
|
|
|
|
|
if (this.block.coupon && this.block.coupon.adjustments && Array.isArray(this.block.coupon.adjustments)) {
|
|
let adjustments = this.block.coupon.adjustments;
|
|
let exclusive = this.form.coupon.discount.exclusive;
|
|
let discount = -adjustments[0].amount;
|
|
|
|
if (discount <= total) {
|
|
if (exclusive) {
|
|
// 是否排他
|
|
|
|
|
|
if (dis.order != 0) {
|
|
// debugger
|
|
total -= dis.order;
|
|
|
|
}
|
|
|
|
dis.order = 0;
|
|
this.setData({
|
|
'form.isDisabled': true,
|
|
'form.discount': {},
|
|
'block.discounts': [],
|
|
'formStates.discountsCheckIndex': -1,
|
|
'form.formStates.discountsCheckIndex': -1
|
|
});
|
|
} else {
|
|
this.setData({
|
|
[`block.discounts`]: this.temporary.discounts,
|
|
[`form.isDisabled`]: false
|
|
}); // console.log(32424242);
|
|
}
|
|
|
|
dis.coupon = adjustments[0].amount;
|
|
total -= discount; // 操作积分
|
|
|
|
|
|
this.block.orderPoint.pointCanUse = Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
|
|
this.block.orderPoint.pointAmount = Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2))
|
|
setTimeout(() => {
|
|
this.available.currentPoint = this.newBlock.orderPoint.pointCanUse
|
|
}, 100)
|
|
/*this.setData({
|
|
[`block.orderPoint.pointCanUse`]: Number(Math.min((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit / this.block.orderPoint.pointToMoney, this.block.orderPoint.userPoint).toFixed(2)),
|
|
[`block.orderPoint.pointAmount`]: Number(Math.max(-((total - pointCanotUseAmount) * this.block.orderPoint.pointLimit), -(this.block.orderPoint.userPoint * this.block.orderPoint.pointToMoney)).toFixed(2))
|
|
}, () => {
|
|
this.setData({
|
|
[`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse
|
|
});
|
|
});*/
|
|
} else {
|
|
wx.showModal({
|
|
content: '超过最大折扣',
|
|
showCancel: false
|
|
});
|
|
this.setData({
|
|
[`form.coupon`]: {},
|
|
[`temporary.coupon`]: {},
|
|
[`form.isDisabled`]: false
|
|
});
|
|
this.$cookieStorage.set('order_form', this.form);
|
|
}
|
|
} // 积分折扣
|
|
|
|
|
|
if (this.form.point) {
|
|
let factor = this.extra.factor;
|
|
let discount = this.form.point * factor;
|
|
|
|
if (discount <= total) {
|
|
dis.point = -discount;
|
|
total -= discount;
|
|
|
|
if (total < 0) {
|
|
total = 0;
|
|
|
|
if (dis.point != 0) {
|
|
dis.total = -(fixedTotal + dis.point);
|
|
}
|
|
} else {
|
|
// 除积分外的优惠
|
|
dis.total = dis.order + dis.coupon;
|
|
}
|
|
|
|
this.$cookieStorage.set('order_form', this.form);
|
|
} else {
|
|
this.setData({
|
|
[`form.point`]: 0
|
|
});
|
|
this.$cookieStorage.set('order_form', this.form);
|
|
}
|
|
} // 除积分外的优惠
|
|
|
|
|
|
dis.total = dis.order + dis.coupon;
|
|
|
|
if (this.form.point > this.block.orderPoint.pointCanUse && this.block.orderPoint.pointCanUse > 0) {
|
|
this.setData({
|
|
[`form.point`]: this.block.orderPoint.pointCanUse
|
|
});
|
|
dis.point = Number((this.block.orderPoint.pointCanUse * 10).toFixed(2));
|
|
}
|
|
|
|
this.setData({
|
|
[`paymentMoneys.discounts`]: dis,
|
|
[`paymentMoneys.total`]: total
|
|
});
|
|
},
|
|
|
|
usePoint(e) {
|
|
/*if (e.detail.value) {
|
|
this.setData({
|
|
[`formStates.pointStatus`]: true,
|
|
[`form.point`]: this.block.orderPoint.pointCanUse
|
|
})
|
|
this.paymentMoney()
|
|
} else {
|
|
this.setData({
|
|
[`formStates.pointStatus`]: false,
|
|
[`form.point`]: 0
|
|
})
|
|
this.paymentMoney()
|
|
}*/
|
|
if (e.detail.value) {
|
|
this.setData({
|
|
[`available.pointStatus`]: true,
|
|
[`available.currentPoint`]: this.newBlock.orderPoint.pointCanUse
|
|
});
|
|
} else {
|
|
this.setData({
|
|
[`available.pointStatus`]: false,
|
|
[`available.currentPoint`]: 0
|
|
});
|
|
}
|
|
|
|
setTimeout(() => {
|
|
this.calculateOrder();
|
|
}, 300);
|
|
},
|
|
|
|
modifyPoint(e) {
|
|
var min = 0;
|
|
var max = this.extra.point;
|
|
var val = e.detail.value;
|
|
var use = Math.floor(this.block.order.total * this.extra.limit / this.extra.factor);
|
|
var sun = Math.floor((this.block.order.total + this.paymentMoneys.discounts.total) / this.extra.factor);
|
|
if (!isFinite(use)) use = max;
|
|
if (!isFinite(sun)) sun = max;
|
|
max = Math.min(max, use, sun);
|
|
val = parseInt(val);
|
|
|
|
if (isNaN(val)) {
|
|
val = '';
|
|
} else if (val < min) {
|
|
val = min;
|
|
} else if (val > max) {
|
|
val = max;
|
|
}
|
|
|
|
e.detail.value = val;
|
|
this.form.point = val
|
|
/* this.setData({
|
|
[`form.point`]: val
|
|
});*/
|
|
this.paymentMoney();
|
|
},
|
|
|
|
saveForm(e) {
|
|
this.$cookieStorage.set('order_form', this.form);
|
|
},
|
|
|
|
back() {
|
|
wx.navigateBack();
|
|
},
|
|
|
|
setData: function (obj) {
|
|
let that = this;
|
|
let keys = [];
|
|
let val, data;
|
|
Object.keys(obj).forEach(function (key) {
|
|
keys = key.split('.');
|
|
val = obj[key];
|
|
data = that.$data;
|
|
keys.forEach(function (key2, index) {
|
|
if (index + 1 == keys.length) {
|
|
that.$set(data, key2, val);
|
|
} else {
|
|
if (!data[key2]) {
|
|
that.$set(data, key2, {});
|
|
}
|
|
}
|
|
|
|
data = data[key2];
|
|
});
|
|
});
|
|
}
|
|
},
|
|
computed: {},
|
|
watch: {}
|
|
};
|
|
</script>
|
|
<style rel="stylesheet/less" lang="less">
|
|
@import "order";
|
|
</style>
|