沈丘营商办后台前端项目
wjt
2024-06-19 21245bd2f9775bc0149174256f58001a67fddba6
src/views/infomanger/banner/index.vue
@@ -17,7 +17,12 @@
          </div>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="`评价项${index + 1}`" style="width: 100%" :prop="item.questionName">
              <el-form-item :label="`评价项${index + 1}`" :prop="`${index}`" style="width: 100%"  :rules="[
                {
                  validator: validateSubField,
                  trigger: 'blur'
                }
              ]">
                <el-input
                  placeholder="请输入"
                  v-model="item.questionName"
@@ -54,7 +59,11 @@
          </el-row>
          <el-row v-if="item.questionType === 1">
            <el-col :span="24">
              <el-form-item label="选项" style="width: 100%;"  :prop="item.answerList">
              <el-form-item label="选项" style="width: 100%;"  :prop="`${index}`" :rules="[
                {
                  validator: answerListField,
                }
              ]">
                  <div
                    v-for="(ele, childIndex) in item.answerList"
                    :key="index"
@@ -107,6 +116,8 @@
    }
  ]
})
const instance = getCurrentInstance()
function getListEvaluate() {
  listEvaluate().then((val) => {
    form.value.questionList = val.data.questionList
@@ -117,6 +128,7 @@
    questionStatus: 0,
    questionType: 2,
    questionScore: 5,
    questionName: '',
    answerList: []
  })
}
@@ -132,13 +144,29 @@
  formRef.value.validate((valid) => {
    console.log(valid)
    if(valid) {
      // saveEvaluate({questionList: form.value.questionList}).then(val => {
      //   ElMessage.success(item||'保存成功')
      // })
      saveEvaluate({questionList: form.value.questionList}).then(val => {
        ElMessage.success(item||'保存成功')
      })
    }
  })
}
function validateSubField(rule: any, value: any, callback: any) {
  // console.log(rule, value)
//   console.log(proxy['form'])
  if(!form.value.questionList[rule.field].questionName) {
    callback(new Error('请入评价项'))
  } else {
    callback()
  }
}
function answerListField(rule: { field: string | number }, value: any, callback: any) {
  if(form.value.questionList[rule.field].answerList.length < 2) {
    callback(new Error('请至少添加两项'))
  } else {
    callback()
  }
}
function changeValue(event, index, childIndex) {
  // form.value.questionList[index].isScore = event.target.
  form.value.questionList[index].answerList.forEach((item: { isScore: number }) => {