import Vue from 'vue'; //改变数量 export function changeCount(row, countObj, noDiscountSingle, weightType) { console.log('changeCount~~', row, countObj, noDiscountSingle) const type = countObj.type || 'sale'; let total = row[countObj.countKey] || 0; let data = row; if (row.packageDispositionList) { let endIndex = row.packageDispositionList.findIndex( (ite) => row[countObj.unitIdKey] == ite.id ); for (; 0 < endIndex; endIndex--) { total = Vue.prototype.$math.format( row.packageDispositionList[endIndex].packageCell * total, 14 ); } } data['totalCount'] = total; data['discountSinglePrice'] = !noDiscountSingle ? data.singlePrice : data.discountSinglePrice; if(weightType == 'totalWeight'){ console.log('weightType~~', 1) setSingleWeight(data); } else { console.log('weightType~~', 2) setWeight(data, type); } data['totalPrice'] = 0; data['discountTotalPrice'] = 0; if (row.pricingWay == 2||row.pricingWay == 3) { let weightKey=countObj.weightKey||'totalWeight' if (row[weightKey] && row.singlePrice) { data['totalPrice'] = (row[weightKey] * row.singlePrice).toFixed(2); } } else { if (row[countObj.countKey] && row.singlePrice) { data['totalPrice'] = (row[countObj.countKey] * row.singlePrice).toFixed(2); } } data['discountTotalPrice'] = !noDiscountSingle ? data.totalPrice : data.discountTotalPrice; return data; } // 计算总重 function setWeight(row, type) { if (row.weightUnit == row.measuringUnit && row.pricingWay == 1 && type != 'purchase') { row['totalWeight'] = row.totalCount; } else if (row.totalCount && row.singleWeight) { row['totalWeight'] = (row.totalCount * row.singleWeight).toFixed(2); } else { row['totalWeight'] = 0; } } // 计算单重 function setSingleWeight(row) { console.log('setSingleWeight~~', row) if (row.totalWeight && row.totalCount) { console.log('setSingleWeight~~', row.totalWeight, row.totalCount) row['singleWeight'] = (row.totalWeight/row.totalCount).toFixed(2); console.log('singleWeight~~', row['singleWeight']) } else { row['singleWeight'] = 0; } } 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 = ''; // } // }