ZhangXianQiang
2024-05-24 2bddfa78e65f351d6cb81f670775e79620f684a6
src/views/questionAnswer/edit.vue
@@ -3,10 +3,13 @@
    <el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules">
      <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>
@@ -19,14 +22,27 @@
<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: []
      },
      formLoading: false,
      rules: {
@@ -45,17 +61,30 @@
    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.attachment = re.response.attachment ? re.response.attachment : ''
        _this.form.contentUrl = re.response.attachment ? JSON.parse(re.response.attachment) : []
        _this.formLoading = false
      })
    }
  },
  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)