import Vue from 'vue'; //改变数量 export function changeCount(row, countObj, noDiscountSingle, weightType) { // console.log('changeCount~~', row, countObj, noDiscountSingle); let data = JSON.parse(JSON.stringify(row)); let total = data[countObj.countKey] || 0; let _endIndex = 0; //计算单重需要 if (data.packageDispositionList) { let endIndex = data.packageDispositionList.findIndex( (ite) => data[countObj.unitIdKey] == ite.id ); _endIndex = endIndex; let packageData = data.packageDispositionList.find( (ite) => data[countObj.unitIdKey] == ite.id ); data[countObj.unitKey] = packageData.conversionUnit; if (data.weightUnit == data.measuringUnit && data.singleWeight) { data.packageDispositionList[1].packageCell = data.singleWeight; } for (; 0 < endIndex; endIndex--) { total = Vue.prototype.$math.format( data.packageDispositionList[endIndex].packageCell * total, 14 ); } } data['totalCount'] = total; data['discountSinglePrice'] = !noDiscountSingle ? data.singlePrice : data.discountSinglePrice; if (weightType == 'totalWeight') { console.log('weightType~~', 1); setSingleWeight(data, countObj, _endIndex); } else { console.log('weightType~~', 2); setWeight(data, countObj); } data['totalPrice'] = 0; data['discountTotalPrice'] = 0; if (data.pricingWay == 2 || data.pricingWay == 3) { if (data.totalWeight && data.singlePrice) { data['totalPrice'] = (data.totalWeight * data.singlePrice).toFixed(2); } } else { if (data[countObj.countKey] && data.singlePrice) { data['totalPrice'] = (data[countObj.countKey] * data.singlePrice).toFixed( 2 ); } } data['discountTotalPrice'] = !noDiscountSingle ? data.totalPrice : data.discountTotalPrice; return data; } // 计算总重 function setWeight(row, countObj) { // return if (row.weightUnit == row.measuringUnit) { row['totalWeight'] = row.totalCount; } else if (row.totalCount && row.singleWeight) { row['totalWeight'] = Number((row.totalCount * row.singleWeight).toFixed(2)); } else { row['totalWeight'] = 0; } // if (row.weightUnit == row[countObj.unitKey]) { // row['totalWeight'] = row.totalCount; // } else if (row[countObj.countKey] && row.singleWeight) { // row['totalWeight'] = (row[countObj.countKey] * row.singleWeight).toFixed(2); // } else { // row['totalWeight'] = 0; // } // if (row.weightUnit == row.measuringUnit) { // row['totalCount'] = row.totalWeight; // } console.log(row['totalCount'], 'dsds'); } // 计算单重 function setSingleWeight(row, countObj, endIndex) { console.log('setSingleWeight~~', row); // if (row.totalWeight && row[countObj.countKey]) { // row['singleWeight'] = (row.totalWeight / row[countObj.countKey]).toFixed(2); // console.log('singleWeight~~', row['singleWeight']); // } else { // row['singleWeight'] = 0; // } // console.log(endIndex, 'endIndex'); if (row.weightUnit == row.measuringUnit) { let totalWeight = row['totalWeight']; for (; 1 < endIndex; endIndex--) { totalWeight = Vue.prototype.$math.format( totalWeight / row.packageDispositionList[endIndex].packageCell, 14 ); } // console.log(totalWeight, 'totalWeight'); row['singleWeight'] = Number(totalWeight / row[countObj.countKey]).toFixed( 2 ); } else if (row.totalWeight && row.totalCount) { row['singleWeight'] = Number((row.totalWeight / row.totalCount).toFixed(2)); } else { row['singleWeight'] = 0; } if (row.weightUnit == row.measuringUnit) { row['totalCount'] = row.totalWeight; } if (row.weightUnit == row[countObj.unitKey]) { row[countObj.countKey] = row.totalWeight; } } export function getAllPrice(arr) { let sum = 0; arr.forEach((item) => { if (item.totalPrice) { sum += Number(item.totalPrice); } }); return isNaN(sum) ? 0 : sum.toFixed(2); } // //计算不含税单价 // function getNotaxSinglePrice(row) { // if (row.singlePrice && row.taxRate) { // row['notaxSinglePrice'] = parseFloat( // (row.singlePrice / (1 + row.taxRate / 100)).toFixed(2) // ); // } else { // row['notaxSinglePrice'] = ''; // } // } // //计算总金额 // function getNumTotalPrice(arr, noDiscountSingle) { // let sum = 0; // arr.forEach((r, index) => { // // if (r.singlePrice) { // // r.notaxSinglePrice=r.taxRate?r.singlePrice/(1-(r.taxRate/100)):r.singlePrice // // } // if (r.singlePrice && r.totalCount) { // Vue.set( // arr[index], // 'discountSinglePrice', // !noDiscountSingle ? r.singlePrice : r.discountSinglePrice // ); // Vue.set(arr[index], 'totalPrice', getAllPrice(r)); // Vue.set( // arr[index], // 'discountTotalPrice', // !noDiscountSingle ? r.totalPrice : r.discountTotalPrice // ); // sum += Number(r.totalPrice); // } else { // Vue.set(arr[index], 'totalPrice', 0); // Vue.set(arr[index], 'discountTotalPrice',0); // } // }); // return { allPrice: isNaN(sum) ? 0 : sum.toFixed(2), arr }; // } // //获取合计 // function getAllPrice(row) { // let num = 0; // if (row.pricingWay == 1) { // //按数量计价计算总金额 // num = Number(row.singlePrice) * Number(row.totalCount); // } // if (row.pricingWay == 2) { // //按重量计价计算总金额 // num = // Number(row.singlePrice) * // Number(row.totalCount) * // Number(row.singleWeight); // } // return isNaN(num) ? '' : num.toFixed(2); // } // function singleWeightChange(row) { // console.log(row, 'row'); // if (row && row.singleWeight && row.totalCount) { // row.totalWeight = (row.singleWeight * row.totalCount).toFixed(2) || 0; // } else { // row.totalWeight = ''; // } // }