Browse Source

加上非空判断

master
xiejiahao 4 years ago
parent
commit
a46346ed0e
  1. 10
      src/utils/decimalUtil.js
  2. 43
      src/views/order/enterprise.vue

10
src/utils/decimalUtil.js

@ -0,0 +1,10 @@
import Decimal from "decimal.js"
export default function getDecimal(val, defaultVal) {
if(val == null || val == "" || val == undefined) {
return new Decimal(defaultVal);
}
return new Decimal(val);
}

43
src/views/order/enterprise.vue

@ -94,7 +94,8 @@ import {getAllMenuModule, getBuyMenuModule} from '@/api/mdp/sys/modules'
import aliPay from '@/assets/image/module/alipay.png'; import aliPay from '@/assets/image/module/alipay.png';
import weixinPay from '@/assets/image/module/weixin.png' import weixinPay from '@/assets/image/module/weixin.png'
import Decimal from "decimal.js" // import Decimal from "decimal.js" //
import { months } from 'moment';
import getDecimal from '@/utils/decimalUtil.js'
export default { export default {
props: ['menus'], props: ['menus'],
@ -150,6 +151,11 @@ export default {
}, },
computed: { computed: {
...mapGetters([
'userInfo'
]),
totalList() { totalList() {
if(this.menus == null) return; if(this.menus == null) return;
let obj = [{key: 'xmgl',name: '项目管理', val : 0},{key: 'oa',name: '智慧协同办公系统',val : 0},{key: 'mall',name: '商城',val : 0}] let obj = [{key: 'xmgl',name: '项目管理', val : 0},{key: 'oa',name: '智慧协同办公系统',val : 0},{key: 'mall',name: '商城',val : 0}]
@ -186,21 +192,17 @@ export default {
let oa = this.menus.oa.filter(res => {return res.isChecked == true;}) let oa = this.menus.oa.filter(res => {return res.isChecked == true;})
let mall = this.menus.mall.filter(res => {return res.isChecked == true;}) let mall = this.menus.mall.filter(res => {return res.isChecked == true;})
tempData = Array.concat(xm).concat(oa).concat(mall); tempData = Array.concat(xm).concat(oa).concat(mall);
if(tempData.length == 0) return 0;
// //
let amount = new Decimal(0); let amount = new Decimal(0);
let allNum = 0;
// * * * // * * *
tempData.forEach(t => { tempData.forEach(t => {
let numDiscount = 1; let numDiscount = 1;
let monthDiscount = 1; let monthDiscount = 1;
allNum += t.num;
// //
if(t.billMode == 0) { if(t.billMode == 0) {
amount = amount.add(0); amount = amount.add(0);
} }
if(t.billMode == 1) { if(t.billMode == 1) {
if(t.discount != null && t.discount != "" && t.discount != undefined) { if(t.discount != null && t.discount != "" && t.discount != undefined) {
let discount = JSON.parse(t.discount); let discount = JSON.parse(t.discount);
@ -209,22 +211,22 @@ export default {
// //
monthDiscount = this.getMonthDiscount(discount.months, this.form.usetime); monthDiscount = this.getMonthDiscount(discount.months, this.form.usetime);
} }
amount = amount.add(new Decimal(t.uniFee).mul(new Decimal(t.num)).mul(numDiscount).mul(monthDiscount));
amount = amount.add(getDecimal(t.uniFee, 0).mul(new Decimal(t.num)).mul(numDiscount).mul(monthDiscount));
} }
// //
if(t.billMode == 2) { if(t.billMode == 2) {
amount = amount.add(new Decimal(t.fee));
amount = amount.add(getDecimal(t.fee, 0));
} }
}) })
this.form.amount = amount; this.form.amount = amount;
return amount; return amount;
} }
}, },
watch: { watch: {
allAmount: { allAmount: {
handler(val, oval) { handler(val, oval) {
if(this.menus == null) return; if(this.menus == null) return;
@ -233,11 +235,11 @@ export default {
let oa = this.menus.oa.filter(res => {return res.isChecked == true;}) let oa = this.menus.oa.filter(res => {return res.isChecked == true;})
let mall = this.menus.mall.filter(res => {return res.isChecked == true;}) let mall = this.menus.mall.filter(res => {return res.isChecked == true;})
tempData = Array.concat(xm).concat(oa).concat(mall); tempData = Array.concat(xm).concat(oa).concat(mall);
if(tempData.length == 0) return 0;
let yearAmount = new Decimal(0); let yearAmount = new Decimal(0);
let halfYearAmount = new Decimal(0); let halfYearAmount = new Decimal(0);
let quarter = new Decimal(0); let quarter = new Decimal(0);
let allNum = 0; let allNum = 0;
tempData.forEach(t => { tempData.forEach(t => {
let numDiscount = 1; let numDiscount = 1;
let monthDiscount = 1; let monthDiscount = 1;
@ -249,22 +251,23 @@ export default {
this.useTimeOptions.forEach(element => { this.useTimeOptions.forEach(element => {
// //
monthDiscount = this.getMonthDiscount(discount.months, element.val); monthDiscount = this.getMonthDiscount(discount.months, element.val);
if(element.val == "12") { if(element.val == "12") {
yearAmount = yearAmount.add(new Decimal(t.uniFee).mul(new Decimal(t.num)).mul(numDiscount).mul(monthDiscount));
yearAmount = yearAmount.add(getDecimal(t.uniFee, 0).mul(new Decimal(t.num)).mul(numDiscount).mul(monthDiscount));
} }
if(element.val == "6") { if(element.val == "6") {
halfYearAmount = halfYearAmount.add(new Decimal(t.uniFee).mul(new Decimal(t.num)).mul(numDiscount).mul(monthDiscount));
halfYearAmount = halfYearAmount.add(getDecimal(t.uniFee, 0).mul(new Decimal(t.num)).mul(numDiscount).mul(monthDiscount));
} }
if(element.val == "3") { if(element.val == "3") {
quarter = quarter.add(new Decimal(t.uniFee).mul(new Decimal(t.num)).mul(numDiscount).mul(monthDiscount));
quarter = quarter.add(getDecimal(t.uniFee, 0).mul(new Decimal(t.num)).mul(numDiscount).mul(monthDiscount));
} }
}); });
}else { }else {
yearAmount = yearAmount.add(new Decimal(t.uniFee).mul(new Decimal(t.num)));
halfYearAmount = halfYearAmount.add(new Decimal(t.uniFee).mul(new Decimal(t.num)));
quarter = quarter.add(new Decimal(t.uniFee).mul(new Decimal(t.num)));
yearAmount = yearAmount.add(getDecimal(t.uniFee, 0).mul(new Decimal(t.num)));
halfYearAmount = halfYearAmount.add(getDecimal(t.uniFee, 0).mul(new Decimal(t.num)));
quarter = quarter.add(getDecimal(t.uniFee, 0).mul(new Decimal(t.num)));
} }
}) })
@ -279,13 +282,13 @@ export default {
element.price = quarter.div(allNum).toFixed(2, Decimal.ROUND_HALF_UP); element.price = quarter.div(allNum).toFixed(2, Decimal.ROUND_HALF_UP);
} }
}) })
}, },
// immediate: true; // immediate: true;
} }
}, },
methods: { methods: {
getNumDiscount(discount, num) { getNumDiscount(discount, num) {
let sale = new Decimal(1); let sale = new Decimal(1);
let nums = discount.split("\n"); let nums = discount.split("\n");
@ -383,10 +386,10 @@ export default {
} }
return obj; return obj;
}, },
}, },
created() { created() {
this.form.phone = this.userInfo.phoneno;
} }
} }

Loading…
Cancel
Save