修改所有判断权重之和的逻辑

This commit is contained in:
wulin 2021-03-03 10:41:17 +08:00
parent da7050e297
commit bbb713c3c2
2 changed files with 66 additions and 6 deletions

View File

@ -411,7 +411,27 @@ export default {
async handleGetNext () { async handleGetNext () {
// //
const arr = this.handleFilter(this.obj.recortModelDtos) const arr = this.handleFilter(this.obj.recortModelDtos)
if (arr.some(i => i.weight === null)) { let weight = 0
for (let i in arr) {
let num = 0
this.handleFilter(arr[i].detailDtos).map(l => {
num += l.checkWeight
})
if (arr[i].weight !== null) {
//
if (num.toFixed(2) !== arr[i].weight.toFixed(2)) {
return this.$message.error(arr[i].name + '维度内的权重和必须为' + Math.round((arr[i].weight * 100) * 1000) / 1000)
}
}
weight += num
}
if (Math.round((weight * 100) * 1000) / 1000 !== 100) {
let str = arr.map(i => i.name).join(',')
this.$message.error(str + '维度内的权重和必须为100%')
return
}
/* if (arr.some(i => i.weight === null)) {
//
let weight = 0 let weight = 0
let maxWeight = 0 let maxWeight = 0
const nullArray = arr.map(i => { const nullArray = arr.map(i => {
@ -436,7 +456,7 @@ export default {
return this.$message.error(arr[i].name + '维度内的权重和必须为' + Math.round((arr[i].weight * 100) * 1000) / 1000) return this.$message.error(arr[i].name + '维度内的权重和必须为' + Math.round((arr[i].weight * 100) * 1000) / 1000)
} }
} }
} } */
this.obj.recortModelDtos.map(i => { this.obj.recortModelDtos.map(i => {
i.detailDtos.map(j => { i.detailDtos.map(j => {
@ -489,7 +509,27 @@ export default {
if (type === 1) { if (type === 1) {
// //
const arr = this.handleFilter(this.obj.recortModelDtos) const arr = this.handleFilter(this.obj.recortModelDtos)
if (arr.some(i => i.weight === null)) { let weight = 0
for (let i in arr) {
let num = 0
this.handleFilter(arr[i].detailDtos).map(l => {
num += l.checkWeight
})
if (arr[i].weight !== null) {
//
if (num.toFixed(2) !== arr[i].weight.toFixed(2)) {
return this.$message.error(arr[i].name + '维度内的权重和必须为' + Math.round((arr[i].weight * 100) * 1000) / 1000)
}
}
weight += num
}
if (Math.round((weight * 100) * 1000) / 1000 !== 100) {
let str = arr.map(i => i.name).join(',')
this.$message.error(str + '维度内的权重和必须为100%')
return
}
/* if (arr.some(i => i.weight === null)) {
//
let weight = 0 let weight = 0
let maxWeight = 0 let maxWeight = 0
const nullArray = arr.map(i => { const nullArray = arr.map(i => {
@ -515,7 +555,7 @@ export default {
return this.$message.error(arr[i].name + '维度内的权重和必须为' + Math.round((arr[i].weight * 100) * 1000) / 1000) return this.$message.error(arr[i].name + '维度内的权重和必须为' + Math.round((arr[i].weight * 100) * 1000) / 1000)
} }
} }
} } */
} }
// //
params.recortModelDtos.map(i => { params.recortModelDtos.map(i => {

View File

@ -386,7 +386,27 @@ export default {
async handleGetNext () { async handleGetNext () {
const arr = this.handleFilter(this.obj.recortModelDtos) const arr = this.handleFilter(this.obj.recortModelDtos)
arr.pop() arr.pop()
if (arr.some(i => i.weight === null)) { let weight = 0
for (let i in arr) {
let num = 0
this.handleFilter(arr[i].detailDtos).map(l => {
num += l.checkWeight
})
if (arr[i].weight !== null) {
//
if (num.toFixed(2) !== arr[i].weight.toFixed(2)) {
return this.$message.error(arr[i].name + '维度内的权重和必须为' + Math.round((arr[i].weight * 100) * 1000) / 1000)
}
}
weight += num
}
if (Math.round((weight * 100) * 1000) / 1000 !== 100) {
let str = arr.map(i => i.name).join(',')
this.$message.error(str + '维度内的权重和必须为100%')
return
}
/* if (arr.some(i => i.weight === null)) {
let weight = 0 let weight = 0
let maxWeight = 0 let maxWeight = 0
const nullArray = arr.map(i => { const nullArray = arr.map(i => {
@ -416,7 +436,7 @@ export default {
if (!_boolean) { if (!_boolean) {
return return
} }
} } */
let res1 = await apiSaveDetail(this.obj) let res1 = await apiSaveDetail(this.obj)
if (res1.code !== 200) { if (res1.code !== 200) {