luban-mall/pagesA/cart/settlement.vue

169 lines
4.8 KiB
Vue
Raw Normal View History

2022-07-08 08:15:29 +00:00
<template>
<view class="pad-b150">
<status-nav :ifReturn="true" navBarTitle="订单提交" :marginBottom="0"></status-nav>
<view class="settlement-content">
<view class="settlement-title">联系方式</view>
<view class="settlement-tips">请输入您的联系方式我们将尽快与您联系并确认订单信息</view>
<view class="settlement-list">
<view class="settlement-item">
<view class="name">联系人</view>
<view class="txt flex">
<text>称呼</text>
<input type="text" v-model="name" @tap="chooseEv(0)" :class="current==0 ? 'focusc' : ''" placeholder="请输入您的称呼" placeholder-style="color:#999999">
</view>
</view>
<view class="settlement-item">
<view class="name">联系方式</view>
<view class="txt flex">
<text>电话</text>
<input type="text" v-model="phone" @tap="chooseEv(1)" :class="current==1 ? 'focusc' : ''" placeholder="请输入手机号码" placeholder-style="color:#999999">
</view>
</view>
<view class="settlement-item">
<view class="name">联系地址</view>
<view class="txt flex">
<text>地址</text>
<input type="text" v-model="address" @tap="chooseEv(2)" :class="current==2 ? 'focusc' : ''" placeholder="请输入地址" placeholder-style="color:#999999">
</view>
</view>
<view class="settlement-item">
<view class="name">送货时间</view>
<view class="txt flex">
<text>日期</text>
2022-07-13 08:04:38 +00:00
<picker mode="date" :start="startDate" :end="endDate" @change="chooseTime(3,$event)">
2022-07-08 08:15:29 +00:00
<input type="text" v-model="toTime" disabled @tap="chooseEv(0)" :class="current==0 ? 'focusc' : ''" placeholder="请选择送货日期" placeholder-style="color:#999999">
</picker>
</view>
</view>
</view>
</view>
<view class="settlement-btn flex">
<view class="btn" @tap="submit"></view>
</view>
</view>
</template>
<script>
import statusNav from '@/components/status-navs/status-nav';
2022-07-13 08:04:38 +00:00
import {getCartNum,userInfoEv} from '@/jsFile/public-api.js';
import {mapState} from 'vuex'//引入mapState
function getDate(type) {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
if (type === 'start') {
year = year;
} else if (type === 'end') {
year = year + 10;
}
month = month > 9 ? month : '0' + month;
day = day > 9 ? day : '0' + day;
return `${year}-${month}-${day}`;
}
2022-07-08 08:15:29 +00:00
export default {
components:{
statusNav
},
data() {
return {
current:6,
address:'',// 地址
name:'',// 称呼
phone:'',// 电话
2022-07-13 08:04:38 +00:00
flag:true,
// 日期
toTime: getDate({
format: true
}),
startDate: getDate('start'),
endDate: getDate('end'),
2022-07-15 03:05:54 +00:00
cacheBusinessId:-1, //商户id
2022-07-08 08:15:29 +00:00
}
},
2022-07-12 10:07:08 +00:00
onLoad(op) {
if(op.business_id){
2022-07-15 03:05:54 +00:00
this.cacheBusinessId = op.business_id;
}
},
onShow() {
if(this.cacheBusinessId !== -1){
this.$requst.post('/api/index/change-business',{business_id:this.cacheBusinessId}).then(res=>{
2022-07-12 10:07:08 +00:00
if(res.code == 0){
this.getUserInfo()
}
})
}else{
this.getUserInfo()
}
2022-07-08 08:15:29 +00:00
},
methods: {
// 获取默认信息
getUserInfo(){
this.$requst.get('/api/user/info').then(res=>{
if(res.code==0) {
2022-07-13 08:04:38 +00:00
uni.setStorageSync('business_id',res.data.business_id);
2022-07-08 08:15:29 +00:00
this.address = res.data.order_address; //地址
this.name = res.data.order_contact; //联系人
this.phone = res.data.order_phone; //电话
}
})
},
// 提交
submit(){
if(this.checkEmpty() && this.flag){
this.flag = false;
let params = {
sku_list: uni.getStorageSync('buyList'),
order_phone: this.phone,
order_contact: this.name,
order_address: this.address,
order_date: this.toTime,
}
this.$requst.post('/api/order/create',params).then(res=>{
if(res.code==0) {
uni.navigateTo({
url:`/pagesA/cart/finish?id=${res.data.id}&coding=${res.data.coding}`
})
2022-07-15 10:29:01 +00:00
setTimeout(()=>{
this.flag = true;
},1200)
2022-07-08 08:15:29 +00:00
}else{
console.log(res.msg,'提示信息')
this.$toolAll.tools.showToast(res.msg);
2022-07-15 10:29:01 +00:00
setTimeout(()=>{
this.flag = true;
},1200)
2022-07-08 08:15:29 +00:00
}
})
}
},
checkEmpty(){
let result = false;
if(!this.name) {
this.$toolAll.tools.showToast('请填写联系人');
} else if(this.$toolAll.tools.isPhone(this.phone)) {
this.$toolAll.tools.showToast('请正确填写联系电话');
} else if(!this.address) {
this.$toolAll.tools.showToast('请填写收货地址');
2022-07-12 10:07:08 +00:00
} else if(!this.toTime) {
this.$toolAll.tools.showToast('请选择送货时间');
2022-07-08 08:15:29 +00:00
} else {
result = true;
}
return result;
},
chooseEv(index) {
this.current = index;
},
chooseTime(index,e) {
this.toTime = e.detail.value;
}
}
}
</script>
<style>
</style>