<template>
|
<view class="pays">
|
<view class="addr" @tap="chooseAddr">
|
<image class="addrImg" src="/static/imgs/my-s-4.png" mode=""></image>
|
<view class="addrView">
|
<template v-if="addrData">
|
<view class="">
|
<text>{{addrData.realname}}</text>
|
<text>{{addrData.phone}}</text>
|
</view>
|
<view class="">{{addrData.area}}{{addrData.addr}}</view>
|
</template>
|
<template v-else>
|
<view class="" style="margin-top: 20upx;">请选择收货地址</view>
|
</template>
|
</view>
|
<image class="rgt" src="/static/imgs/right.png" mode=""></image>
|
</view>
|
<view class="goods">
|
<view class="goodsMain" v-for="(item, index) in cartsData">
|
<image class="goods-icon" :src="item.icon" mode=""></image>
|
<view class="goods-info">
|
<view class="goods-title">{{item.title}}</view>
|
<view class=""></view>
|
<view class="goods-price">
|
<view>价格:¥</view>
|
<view class="red">{{item.price}}</view>
|
</view>
|
<view class="goods-price">
|
<view>运费:¥</view>
|
<view class="red">{{item.freight}}</view>
|
</view>
|
<view class="carts-nums">
|
<view class="" @tap="setCartsNums(item, 1)">
|
<image src="/static/imgs/minus.png" mode=""></image>
|
</view>
|
<view class="">
|
<text>{{item.nums}}</text>
|
</view>
|
<view class="" @tap="setCartsNums(item, 2)">
|
<image src="/static/imgs/add.png" mode=""></image>
|
</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
<view class="total">
|
<!-- <view class="">
|
<text>加工费:</text>
|
<text class="red total-price">{{rateTotal}}</text>
|
<text class="cny">元</text>
|
</view> -->
|
<view class="">
|
<text>合计:</text>
|
<text class="red total-price">{{payTotal}}</text>
|
<text class="cny">元</text>
|
</view>
|
|
</view>
|
<view class="payment">
|
<view class="p-title">
|
<text>付款方式</text>
|
<!-- <view class="" v-if="payment == 1 && userInfo.edu_auth == 1" @tap="getPayTask">查看还款计划</view> -->
|
</view>
|
<view class="pay-li">
|
<!-- <view class="pay-item" @tap="choosePayment(1)" v-if="Config && Config.edu_open == 1 && isFenqi == 1">
|
<image class="pay-icon" src="/static/imgs/edupay.png" mode=""></image>
|
<text v-if="userInfo">余额支付(可用余额:{{userInfo.const}})</text>
|
<image class="rgt" :src="payment == 1 ? '/static/imgs/checked.png' : '/static/imgs/check.png'" mode=""></image>
|
</view> -->
|
<view class="pay-item" @tap="choosePayment(2)">
|
<image class="pay-icon" src="/static/imgs/wxpay.png" mode=""></image>
|
<text>微信支付</text>
|
<image class="rgt" :src="payment == 2 ? '/static/imgs/checked.png' : '/static/imgs/check.png'" mode=""></image>
|
</view>
|
<!-- <view class="pay-item">
|
<image class="pay-icon" src="/static/imgs/bankpay.png" mode=""></image>
|
<view @tap="chooseBank">
|
<text>银行卡支付</text>
|
<text v-if="bankData">({{bankData.bankno}}切换)</text>
|
<text v-else>(请选择银行卡 》》)</text>
|
</view>
|
<image class="rgt" :src="payment == 3 ? '/static/imgs/checked.png' : '/static/imgs/check.png'" mode="" @tap="choosePayment(3)"></image>
|
</view> -->
|
</view>
|
</view>
|
<view class="authBtn-desc" v-if="userInfo && payment == 1 && userInfo.edu_auth == 1">
|
<image @tap="agreeFlag = !agreeFlag" class="authBtn-icon" :src="!agreeFlag ? '/static/imgs/check.png' : '/static/imgs/checked.png'" mode=""></image>
|
<text>我已阅读并同意</text>
|
<text class="blue" @tap="eSignAgree">《赊销购货协议》(点击签署)</text>
|
</view>
|
<view class="paysBtn" @tap="payOrder">提交订单</view>
|
|
|
<uni-popup ref="popup" type="bottom">
|
<view class="popup-content">
|
<view class="pop-title">查看还款计划</view>
|
<view class="pop-main">
|
<view class="pop-main-view" v-for="(item, index) in paysData">
|
<view class="pop-nums">
|
第{{index + 1}}期
|
</view>
|
<view class="pop-pay">
|
<view class="">还款日期: {{item.days}}</view>
|
<view class="">还款金额: {{item.pays}}</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
</uni-popup>
|
|
</view>
|
</template>
|
<script>
|
export default {
|
components: {
|
},
|
data() {
|
return {
|
Config: null,
|
payment: 0,
|
cartsIds: '',
|
cartsData: [],
|
addrData: null,
|
payTotal: 0,
|
rateTotal: 0,
|
userInfo: this.$util.getUserInfo(),
|
bankData: null,
|
bankId: 0,
|
paysData: [],
|
agreeFlag: true,
|
esignFlag: 0,
|
isFenqi: 0,
|
}
|
},
|
onLoad (op) {
|
this.getConfig()
|
setTimeout(() => {
|
this.getUserInfo()
|
}, 300)
|
this.cartsIds = op.cartsIds ? op.cartsIds : ''
|
if(this.cartsIds != '') {
|
this.getCartsInfo(this.cartsIds)
|
}
|
//判断是否有地址
|
let addr = uni.getStorageSync('choose-address') ? uni.getStorageSync('choose-address') : null
|
if(addr) {
|
this.addrData = JSON.parse(uni.getStorageSync('choose-address'))
|
} else {
|
this.getAddr()
|
}
|
|
//判断是否有银行
|
let bank = uni.getStorageSync('choose-bank') ? uni.getStorageSync('choose-bank') : null
|
if(bank) {
|
this.bankData = JSON.parse(uni.getStorageSync('choose-bank'))
|
} else {
|
this.getBank()
|
}
|
},
|
onShow () {
|
//获取签署协议状态
|
this.getEsignStatus()
|
},
|
methods: {
|
getEsignStatus () {
|
let t = this
|
this.$util.post('Sign/getEsign', {cartsIds: this.cartsIds}).then(res => {
|
console.log('res', res)
|
if(res.code == 1){
|
t.esignFlag = 1
|
t.payment = 1
|
}
|
})
|
},
|
eSignAgree () {
|
let t = this
|
if(!this.addrData){
|
return uni.showToast({
|
title: '请选择收货地址',
|
icon: 'error'
|
})
|
}
|
console.log('eee', 1111)
|
this.$util.post('Sign/eSign', {addrId: this.addrData.id, cartsIds: this.cartsIds}).then(res => {
|
console.log('res111', res)
|
if(res.code == 1){
|
t.$goWebUrl(res.data)
|
} else {
|
uni.showToast({
|
title: res.msg || '操作失败',
|
icon: 'error'
|
})
|
}
|
})
|
},
|
|
getConfig () {
|
this.$util.post('Index/getConfig').then(res => {
|
if(res.code == 1){
|
this.Config = res.data
|
}
|
})
|
},
|
popOpen () {
|
this.$refs.popup.open()
|
},
|
//选择支付方式
|
choosePayment (n) {
|
this.payment = n
|
if(this.payment == 3){
|
if(!this.bankData){
|
this.getBank()
|
}
|
}
|
if(n == 1) {
|
let burl = '/pages/pays/pays?cartsIds=' + this.cartsIds
|
if(!this.$util.checkGoPages('/pages/login/login', burl, 0)) {
|
return
|
}
|
}
|
},
|
getUserInfo () {
|
let t = this
|
t.$util.post('User/getUser').then(res => {
|
t.userInfo = res.data
|
})
|
},
|
//获取默认银行
|
getBank () {
|
this.$util.post('Bank/getDefBank').then(res => {
|
if(res.code == 1) {
|
this.bankData = res.data
|
}
|
})
|
},
|
//跳转到选择银行
|
chooseBank (e) {
|
let url = '/pages/bank/bank?backUrl=/pages/pays/pays?cartsIds=' + this.cartsIds
|
this.$util.goPages(url)
|
},
|
//跳转到选择地址
|
chooseAddr () {
|
let url = '/pages/address/address?backUrl=/pages/pays/pays?cartsIds=' + this.cartsIds
|
this.$util.goPages(url)
|
},
|
//获取默认地址和银行
|
getAddr() {
|
this.$util.post('Address/getDefAddr').then(res => {
|
if(res.code == 1) {
|
this.addrData = res.data
|
}
|
})
|
},
|
getCartsInfo (cartsIds) {
|
this.$util.post('Carts/getCartsInfo', {cartsIds: cartsIds}).then(res => {
|
if(res.code == 1) {
|
this.cartsData = res.data.cartsList
|
this.payTotal = res.data.total
|
this.rateTotal = res.data.rate
|
this.isFenqi = res.data.isFenqi
|
}
|
})
|
},
|
//设置购物车数量
|
setCartsNums (e, y){
|
let n = e.nums
|
let t = this
|
if(y == 1){
|
if(n == 1) {
|
return
|
} else {
|
n = n > 1 ? n - 1 : 1
|
}
|
} else {
|
n = n + 1
|
}
|
t.$util.post('Carts/setCartsNums', {id: e.id, nums: n}).then(res => {
|
if(res.code == 1) {
|
e.nums = n
|
t.payTotal = res.data.total
|
t.rateTotal = res.data.rate
|
} else {
|
uni.showToast({
|
title: res.msg || '操作失败',
|
icon: 'error'
|
})
|
}
|
})
|
},
|
payOrder () {
|
if(this.payment == 1 || this.payment == 3) {
|
let burl = '/pages/pays/pays?cartsIds=' + this.cartsIds
|
if(!this.$util.checkGoPages('/pages/login/login', burl, 0)) {
|
return
|
}
|
}
|
|
let t = this
|
if(!this.addrData){
|
return uni.showToast({
|
title: '请选择收货地址',
|
icon: 'error'
|
})
|
}
|
if(this.payment == 0){
|
return uni.showToast({
|
title: '请选择支付方式',
|
icon: 'error'
|
})
|
}
|
|
if(this.payment == 1){
|
if(this.userInfo.const < this.payTotal) {
|
return uni.showToast({
|
title: '您的额度不足',
|
icon: 'error'
|
})
|
}
|
this.getEsignStatus()
|
if(this.esignFlag == 0 && this.Config.esign_open == 1) {
|
return uni.showToast({
|
title: '请签署购货协议',
|
icon: 'error'
|
})
|
}
|
}
|
|
let param = {}
|
param = {
|
cartsIds: t.cartsIds,
|
bankId: t.bankData ? t.bankData.id : 0,
|
addrId: t.addrData.id,
|
payment: t.payment
|
}
|
t.$util.post('Order/createOrder', param).then(res => {
|
console.log(res)
|
if(res.code == 1) {
|
if(t.payment == 1) {
|
uni.showToast({
|
title: res.msg || '操作成功',
|
icon: 'success'
|
})
|
//更新用户缓存
|
uni.setStorageSync('user-info', JSON.stringify(res.data))
|
setTimeout(() => {
|
t.$util.goPages('/pages/order/order')
|
}, 1500)
|
} else if(t.payment == 2) {
|
uni.requestPayment({
|
"provider": "wxpay",
|
"orderInfo": res.data,
|
success(rs) {
|
uni.showToast({
|
title: '支付成功',
|
icon: 'success',
|
})
|
setTimeout(() => {
|
t.$util.goPages('/pages/order/order')
|
}, 1000)
|
},
|
fail(e) {
|
uni.showToast({
|
title: '支付失败',
|
icon: 'success',
|
})
|
setTimeout(() => {
|
t.$util.goPages('/pages/order/order')
|
}, 1000)
|
}
|
})
|
} else if(t.payment == 3) {
|
uni.showToast({
|
title: res.msg || '操作成功',
|
icon: 'success'
|
})
|
setTimeout(() => {
|
t.$util.goPages('/pages/order/order')
|
}, 1500)
|
}
|
} else {
|
uni.showToast({
|
title: res.msg || '操作失败',
|
icon: 'error'
|
})
|
}
|
})
|
},
|
//获取还款计划
|
getPayTask () {
|
let t = this
|
t.$util.post('Goods/getPlan', {cartsIds: t.cartsIds}).then(res => {
|
if(res.code == 1) {
|
t.paysData = res.data
|
t.popOpen()
|
} else {
|
uni.showToast({
|
title: res.msg || '操作失败',
|
icon: 'error'
|
})
|
}
|
})
|
}
|
}
|
}
|
</script>
|
|
<style>
|
@import url(/static/css/pays.css);
|
</style>
|