vue根据权重计算问卷分数

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
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值