表格问题自动计算更改
continuous-integration/drone/push Build is passing Details

uat_us
caiyiling 2024-10-30 13:31:54 +08:00
parent a19d756879
commit bb4193730e
2 changed files with 63 additions and 29 deletions

View File

@ -763,35 +763,84 @@ export default {
} }
// this.$emit('formItemNumberChange') // this.$emit('formItemNumberChange')
}, },
// formItemTableNumberChange() {
// this.question.TableQuestions.Questions.forEach(v => {
// if (v.Type === 'number' && v.DataSource === 1) {
// var CalculateQuestions = JSON.parse(v.CalculateQuestions)
// var num
// CalculateQuestions.forEach((o, i) => {
// if (i === 0) {
// num = this.QuestionsForm[o.TableQuestionId]
// } else {
// switch (v.CustomCalculateMark) {
// case 1:
// num += this.QuestionsForm[o.TableQuestionId]
// break;
// case 2:
// num -= this.QuestionsForm[o.TableQuestionId]
// break;
// case 3:
// num *= this.QuestionsForm[o.TableQuestionId]
// break;
// case 4:
// num /= this.QuestionsForm[o.TableQuestionId]
// break;
// }
// }
// })
// this.$set(this.QuestionsForm, v.Id, num.toString())
// }
// })
// },
formItemTableNumberChange() { formItemTableNumberChange() {
this.question.TableQuestions.Questions.forEach(v => { this.question.TableQuestions.Questions.forEach((v) => {
if (v.Type === 'number' && v.DataSource === 1) { if (v.Type === "number" && v.DataSource === 1) {
var CalculateQuestions = JSON.parse(v.CalculateQuestions) var CalculateQuestions = JSON.parse(v.CalculateQuestions);
var num var num,
arr = [];
CalculateQuestions.forEach((o, i) => { CalculateQuestions.forEach((o, i) => {
if (i === 0) { if (i === 0) {
num = this.QuestionsForm[o.TableQuestionId] num = parseFloat(this.QuestionsForm[o.TableQuestionId]);
arr = [num];
} else { } else {
switch (v.CustomCalculateMark) { switch (v.CustomCalculateMark) {
case 1: case 1:
num += this.QuestionsForm[o.TableQuestionId] num += parseFloat(this.QuestionsForm[o.TableQuestionId]);
break; break;
case 2: case 2:
num -= this.QuestionsForm[o.TableQuestionId] num -= parseFloat(this.QuestionsForm[o.TableQuestionId]);
break; break;
case 3: case 3:
num *= this.QuestionsForm[o.TableQuestionId] num *= parseFloat(this.QuestionsForm[o.TableQuestionId]);
break; break;
case 4: case 4:
num /= this.QuestionsForm[o.TableQuestionId] num /= parseFloat(this.QuestionsForm[o.TableQuestionId]);
break;
case 7:
arr.push(parseFloat(this.QuestionsForm[o.TableQuestionId]));
num =
arr.length === 0
? 0
: arr.reduce((acc, curr) => {
return acc + (typeof curr === "number" ? curr : 0);
}, 0) / arr.length;
break;
case 8:
arr.push(parseFloat(this.QuestionsForm[o.TableQuestionId]));
num = arr.length === 0 ? 0 : Math.max(...arr);
break;
case 9:
arr.push(parseFloat(this.QuestionsForm[o.TableQuestionId]));
num = arr.length === 0 ? 0 : Math.min(...arr);
// console.log('min', this.questionForm[o.QuestionId], arr, num)
break; break;
} }
} }
}) });
this.$set(this.QuestionsForm, v.Id, num.toString()) this.$set(this.QuestionsForm, v.Id, num.toString());
} }
}) });
}, },
openAddTableCol(row, index) { openAddTableCol(row, index) {
this.addOrEdit.visible = true this.addOrEdit.visible = true

View File

@ -482,22 +482,7 @@ export default {
return num.toFixed(digitPlaces) return num.toFixed(digitPlaces)
}, },
formItemNumberChange(v, question) { formItemNumberChange(v, question) {
this.CalculationList.forEach((v, i) => { this.$emit('formItemTableNumberChange', v, question)
console.log('v', v)
var find = v.CalculateQuestionList.filter(o => {
return o.QuestionId === question.Id
})
console.log('find', find)
// findnumber
if (find) {
var num = this.logic(v)
console.log(num)
if (num !== false) {
this.$set(this.questionForm, v.QuestionId, num)
// this.$emit('setFormItemData', { key: v.QuestionId, val: num })
}
}
})
// this.$emit('formItemTableNumberChange', v, question) // this.$emit('formItemTableNumberChange', v, question)
}, },
resetChild(obj) { resetChild(obj) {