data() {
return{
// 支付数值统计
statistic:[],
coupon_money:0,//可抵扣优惠价
real_total:0,//商品实付金额
}
//计算变量,避免在html写入冗长计算式
computed: {
total() {
return Number(this.statistic.all_price) + Number(this.statistic.all_deposit_price) + Number(this.statistic.delivery_price) - Number(this.coupon_money)
}
//实时监听计算变量的变化
watch: {
total(val) {
this.real_total=val
console.log("total:",val,this.statistic.all_price,this.statistic.all_deposit_price,this.statistic.delivery_price,this.coupon_money )
}
const tools = {
data() {
return {
buttons: {
0: { cancel: true, pay: true, flag: "UNPAID", desc: "未支付" },
1: { cancel: true, flag: "UNCONFIRMED", desc: "待确认" },
2: { viewOrders: true, flag: "UNSHIPPED", desc: "待发货" },
3: { viewOrders: true, flag: "SHIPPED", desc: "已发货" },
4: { delete: true, viewOrders: true, flag: "COMPLETED", desc: "已收货" },
5: { viewOrders: true, flag: "SERVICING", desc: "售后中" },
9: { delete: true, viewOrders: true, flag: "BANKING", desc: "已存酒库" },
10: { delete: true, viewOrders: true, flag: "CANCELED", desc: "已取消" },
11: { delete: true, viewOrders: true, flag: "AUTOCANCELED", desc: "系统自动取消" },
}
}
},
methods: {
getInteger(val) {
val = val ? Number(val) : 0;
return val.toFixed(2).split(".")[0]
},
getDecimal(val) {
val = val ? Number(val) : 0;
return val.toFixed(2).split(".")[1]
},
}
}
export default tools
import tools from "@/mixins/mixin.js";
components: {
uniIcon,uniPopup,uniDrawer
},
mixins: [tools],
data() {
return{}
},
}
//然后直接在html里调用mixin.js里的方法即可:
合计:¥{{getInteger(real_total)}}.{{getDecimal(real_total)}}