<template>
<view class="money">
<view class="countdown">
<text>支付剩余时间:</text><text>{{countdown}}</text>
</view>
<view class="money-item">
<view class="detailitem" v-if="shopinfo.title">
<view class="left">
<text>项目</text>
</view>
<view class="right">
<text>{{shopinfo.title}}</text>
</view>
</view>
<view class="detailitem" v-if="shopinfo.hour_price">
<view class="left">
<text>时价</text>
</view>
<view class="right">
<text>{{shopinfo.hour_price}}元</text>
</view>
</view>
<view class="detailitem" v-if="shopinfo.hours">
<view class="left">
<text>时长</text>
</view>
<view class="right">
<text>{{shopinfo.hours}}</text>
</view>
</view>
<view class="detailitem" v-if="shopinfo.content">
<view class="left">
<text>配件</text>
</view>
<view class="right">
<text>{{shopinfo.content}}</text>
</view>
</view>
<view class="detailitem" v-if="shopinfo.price">
<view class="left">
<text>价格</text>
</view>
<view class="right">
<text>{{shopinfo.price}}元</text>
</view>
</view>
</view>
<view class="content">
<personallist wrapheight="100" leftTitle="优惠券" :rightTitle='couponstitle' @tap="tocoupons(shopinfo.class_id)">
<uni-icons type="arrowright" size="27" color="#D6D3D6" />
</personallist>
<personallist wrapheight="100" leftTitle="推荐师傅服务" :rightTitle='shopinfo.order.advance+"元"'>
<!-- <uni-icons type="info" size="27" color="#D6D3D6" /> -->
</personallist>
<personallist wrapheight="100" leftTitle="支付金额" :rightTitle='sum+"元"'>
<!-- <uni-icons type="arrowright" size="27" color="#D6D3D6" /> -->
</personallist>
</view>
<view class="paytype">
<view class="radioitem">
<view class="contentleft">
<uni-icons type="weixin" size="60" color="#81DB37" />
<text>微信</text>
</view>
<radio color='#2F2F2F' style="transform: scale(0.7)" value="微信" :checked="true" />
</view>
</view>
<view class="goodnav">
<view class="combined">
合计:{{sum}}元
</view>
<view class="buybtn" @tap='paymoney'>
立即支付
</view>
</view>
</view>
</template>
<script>
import uniIcons from '@/components/uni-icons/uni-icons.vue'
import personallist from '@/components/personallist/personallist.vue'
import http from '@/common/http.js'
export default {
data() {
return {
countdown: '还剩 30 分 00 秒',
userinfo: null,
id: null,
shopinfo: null,
coupons: null,
couponsid:0,
couponstitle: "不使用",
sum:0
}
},
components: {
uniIcons,
personallist
},
onLoad(options) {
this.timing();
this.userinfo = getApp().globalData.userinfo;
this.id = options.id;
},
onShow() {
this.getpaydetail();
},
onHide() {
},
onUnload(){
},
methods: {
// 付款
paymoney() {
http.httpTokenRequest({
url: "Order/wxPay",
method: 'POST'
}, {
user_id: this.userinfo.id,
order_id: this.id,
type: 3,
user_coupon_id:this.couponsid
}).then((res) => {
if(res.data.code==0){
uni.showModal({
content:res.data.msg,
showCancel:false
});
return false
}
let data = res.data.data;
// 付钱行为
uni.requestPayment({
timeStamp: data['timeStamp'] + '',
nonceStr: data['nonceStr'],
package: data['package'],
signType: data['signType'],
paySign: data['paySign'],
success: (res)=> {
// getApp().globalData.refreshorder=false;
http.httpTokenRequest({
url: "Order/alipaySuccess",
method: 'POST'
}, {
user_id: this.userinfo.id,
order_id: this.id,
pay_way: 2,
wx_type:3
}).then((res)=>{
if(res.data.code==1){
uni.$emit('update')
getApp().globalData.refreshorder=true;
uni.showToast({
title: '支付成功'
})
uni.redirectTo({
url: '../../pages/comment/index?id='+this.id
});
}
})
},
fail:(res)=>{
uni.showToast({
title: '支付失败',
icon:'none'
})
}
})
})
},
// 去往优惠券页面
tocoupons(class_id) {
let allsum;
if(this.shopinfo.order.advance==null){
allsum=Number(this.shopinfo.price)
}else{
allsum=Number(this.shopinfo.price)+Number( this.shopinfo.order.advance)
}
uni.navigateTo({
url: '../selectcoupons/index?class_id=' + class_id+'&price='+allsum
});
},
// 倒计时
timing() {
var time = 1800; //30分钟换算成1800秒
setInterval(() => {
time = time - 1;
var minute = parseInt(time / 60);
var second = parseInt(time % 60);
this.countdown = minute + '分' + second + '秒';
}, 1000);
},
// 用户查询报价
getpaydetail() {
http.httpTokenRequest({
url: "Listing/getInfo",
method: 'POST'
}, {
user_id: this.userinfo.id,
order_id: this.id
}).then((res) => {
this.shopinfo = res.data.data;
let allmoney;
if (this.coupons) {
this.couponstitle = this.coupons.amount
allmoney = (Number(this.shopinfo.price)+Number( this.shopinfo.order.advance)) - Number(this.couponstitle )>= 0.01 ?(Number(this.shopinfo.price)+Number( this.shopinfo.order.advance)) - Number(this.couponstitle ):
0.01;
this.sum=allmoney.toFixed(2);
}else{
allmoney=Number(this.shopinfo.price)+Number( this.shopinfo.order.advance);
this.sum=allmoney.toFixed(2);
}
})
}
}
}
</script>