| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <div class="form-content"> |
| | | <el-form inline :model="form.questionList" label-width="75px" :rules="rules"> |
| | | <el-form inline :model="form.questionList" ref="formRef" label-width="75px" :rules="rules"> |
| | | <div |
| | | class="border" |
| | | v-for="(item, index) in form.questionList" |
| | |
| | | </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" |
| | |
| | | </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" |
| | |
| | | </el-form> |
| | | <div class="center mt20 fixed"> |
| | | <el-button type="primary" @click="addContent">添加评价项</el-button> |
| | | <el-button @click="save" type="primary" >保存内容</el-button> |
| | | <el-button @click="save()" type="primary" >保存内容</el-button> |
| | | </div> |
| | | </div> |
| | | </div> |
| | |
| | | import { ElMessage, ElMessageBox} from 'element-plus' |
| | | const tableData = ref([]) |
| | | const addNewRef = ref() |
| | | const formRef = ref() |
| | | const form: any = ref({ |
| | | questionList: [] |
| | | }) |
| | | const rules = ref({ |
| | | questionName: [ |
| | | { |
| | | required: true, |
| | | message: '请输入问题', |
| | | trigger: 'blur' |
| | | required: true, |
| | | message: '请输入问题', |
| | | trigger: 'blur' |
| | | } |
| | | ] |
| | | }) |
| | | const instance = getCurrentInstance() |
| | | |
| | | function getListEvaluate() { |
| | | listEvaluate().then((val) => { |
| | | form.value.questionList = val.data.questionList |
| | |
| | | questionStatus: 0, |
| | | questionType: 2, |
| | | questionScore: 5, |
| | | questionName: '', |
| | | answerList: [] |
| | | }) |
| | | } |
| | | function addOptions(index: number, name){ |
| | | function addOptions(index: number, name: any){ |
| | | if(!form.value.questionList[index].answerList) { |
| | | form.value.questionList[index].answerList = [] |
| | | } |
| | |
| | | }) |
| | | } |
| | | function save(item?: string) { |
| | | saveEvaluate({questionList: form.value.questionList}).then(val => { |
| | | ElMessage.success(item||'保存成功') |
| | | formRef.value.validate((valid) => { |
| | | console.log(valid) |
| | | if(valid) { |
| | | 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 if(form.value.questionList[rule.field].answerList) { |
| | | const value = form.value.questionList[rule.field].answerList.every(item => item.answerName) |
| | | if(!value) { |
| | | callback(new Error('请完善选项内容')) |
| | | } else { |
| | | callback() |
| | | } |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | function changeValue(event, index, childIndex) { |
| | | // form.value.questionList[index].isScore = event.target. |