js部分
Change(n) {
// 查看是否是多选
if (n instanceof Array) {
// 每次修改置空
this.checkScore = 0
this.checkWeight = 0
// 总分数
let points = 0
// 那多选的总分数
n.forEach((item) => {
points = Number(item.split(‘-’)[2]) + points
})
// 计算多总分数 选项分加权重
this.checkScore = points * n[0].split(‘-’)[3] + this.checkScore
// 获取多选权重
this.checkWeight = Number(n[0].split(‘-’)[3])
} else {
// 单选初始值
this.radioScore = 0
this.radioWeight = 0
// 第一次添加选项
if (this.radioArr.length < 1) {
this.radioArr.push(n)
this.topicArr.push(n.split(‘-’)[0])
} else {
// 添加父级Id 去重
this.radioArr.forEach((item, index) => {
if (item.split(‘-’)[0] !== n.split(‘-’)[0]) {
this.topicArr.push(n.split(‘-’)[0])
}
})
// 根据父级id跟新数组
if (this.topicArr.indexOf(n.split(‘-’)[0]) + 1) {
let index = this.topicArr.indexOf(n.split(‘-’)[0])
this.radioArr[index] = n
}
}
// 单选初始分数
let points = 0
// 计算单选总分 总权重
this.radioArr.forEach((item) => {
this.radioScore = Number(item.split(‘-’)[2]) * Number(item.split(‘-’)[3]) + this.radioScore
this.radioWeight = Number(item.split(‘-’)[3]) + this.radioWeight
})
}
let visitScore = 0
// 根据 单选多选总分 除去总权重 计算问卷分数
visitScore = ((this.radioScore + this.checkScore) / (this.checkWeight + this.radioWeight)).toFixed()
// 根据不同分数扎实评分
if (visitScore > 90) {
this.value = 5
} else if (visitScore > 70) {
this.value = 4
} else if (visitScore > 50) {
this.value = 3
} else if (visitScore > 30) {
this.value = 2
} else {
this.value = 1
}
}
页面部分
<u-checkbox-group v-model=“ruleform[item.option]” placement=“column” @change=‘Change’
:disabled=‘item.isDisabled’>
<u-radio-group v-model=“ruleform[item.option]” placement=“column” @change=‘Change’
:disabled=‘item.isDisabled’>
分数回显
console.log(res)
if (res.status == 200) {
this.value = res.data.evaluationLevel ? res.data.evaluationLevel : 0
res.data.topicList.forEach((item, index) => {
item[‘option’] = ‘option’ + index
item[‘disabled’] = true
this.allWeight = this.allWeight + item.weight
})
let answerList = []
res.data.topicList.forEach((item, index) => {
item[‘isDisabled’] = true
if (item.topicType == ‘1’) {
item.answer.split(‘,’).forEach((every) => {
answerList.push(item.id + ‘-’ + every + ‘-’ + item.score +
‘-’ +
item.weight)
})
this.ruleform[‘option’ + index] = answerList
} else if (item.topicType == ‘2’) {
this.ruleform[‘option’ + index] = item.answer
} else {
this.ruleform[‘option’ + index] = item.id + ‘-’ + item.answer + ‘-’ + item
.score + ‘-’ +
item.weight
}
})
this.data = res.data
}