| | |
| | | <div class="app-container"> |
| | | |
| | | <el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules"> |
| | | <el-form-item label="排序:" prop="sequence"> |
| | | <el-input v-model="form.sequence"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="问题:" prop="question"> |
| | | <el-input v-model="form.question"></el-input> |
| | | <el-input v-model="form.question" maxlength="48"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="答案:" prop="answer"> |
| | | <el-input v-model="form.answer"></el-input> |
| | | <el-input v-model="form.answer" maxlength="1000"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="附件:" prop="attachment"> |
| | | <upload :fileUrl="form.contentUrl" :fileSizeLimitM="1024" :uploadNum="1" @getUploadUrl="getUploadAttachmentUrl" @removeFile="removeAttachmentFile"/> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" @click="submitForm">提交</el-button> |
| | |
| | | <script> |
| | | import { mapGetters, mapState, mapActions } from 'vuex' |
| | | import questionAnswerApi from '@/api/questionAnswer' |
| | | import Upload from '@/components/UploadC' |
| | | |
| | | export default { |
| | | components: { Upload }, |
| | | computed: { |
| | | fileContentUrl: () => { |
| | | return this.form ? this.form.contentUrl ? [this.form.contentUrl] : [] : []; |
| | | } |
| | | }, |
| | | data () { |
| | | return { |
| | | form: { |
| | | id: null, |
| | | question: '', |
| | | answer: '' |
| | | answer: '', |
| | | contentType: 'file', |
| | | subject: '', |
| | | belongType: 2, |
| | | contentUrl: [], |
| | | attachment: '', |
| | | temp: [], |
| | | sequence: '' |
| | | }, |
| | | formLoading: false, |
| | | rules: { |
| | |
| | | ], |
| | | answer: [ |
| | | { required: true, message: '请输入答案', trigger: 'blur' } |
| | | ], |
| | | sequence: [ |
| | | { required: true, message: '请输入排序', trigger: 'blur' } |
| | | ] |
| | | } |
| | | } |
| | |
| | | if (id && parseInt(id) !== 0) { |
| | | _this.formLoading = true |
| | | questionAnswerApi.query(id).then(re => { |
| | | _this.form = re.response |
| | | _this.form.id = re.response.id |
| | | _this.form.question = re.response.question |
| | | _this.form.answer = re.response.answer |
| | | _this.form.sequence = re.response.sequence |
| | | _this.form.attachment = re.response.attachment ? re.response.attachment : '' |
| | | _this.form.contentUrl = re.response.attachment ? JSON.parse(re.response.attachment) : [] |
| | | _this.formLoading = false |
| | | }) |
| | | } else { |
| | | questionAnswerApi.getLastSequence().then(re => { |
| | | _this.form.sequence = re.response |
| | | }) |
| | | } |
| | | }, |
| | | methods: { |
| | | removeAttachmentFile(fileList, fileName) { |
| | | this.form.attachment = JSON.stringify(fileList.filter(item => item.name !== fileName)); |
| | | this.form.contentUrl = fileList.filter(item => item.name !== fileName); |
| | | }, |
| | | getUploadAttachmentUrl(uploadData) { |
| | | this.form.attachment = JSON.stringify(uploadData); |
| | | this.form.contentUrl = uploadData; |
| | | }, |
| | | submitForm () { |
| | | let _this = this |
| | | this.$refs.form.validate((valid) => { |
| | | if (valid) { |
| | | this.formLoading = true |
| | | |
| | | questionAnswerApi.save(this.form).then(data => { |
| | | if (data.code === 1) { |
| | | _this.$message.success(data.message) |