<!-- 新增反馈意见弹窗 李昱佳 -->
<template>
  <div>
    <DialogEdit @onSaved="created"
                :autoSave="false"
                :top="dialogTop"
                title="反馈意见"
                :visible.sync="dialogFormVisible"
                width="600px"
                center
                :labelPosition="labelPosition"
                :form="form"
                :editModel="DialogEdit"
                :formRules="formRules"
                :appendToBody= "appendToBody">
          <el-form-item :label="$t('knowledgeBaseIndex.feedback')" :label-width="formLabelWidth" prop="opinion">
              <el-input type="textarea"
                        :maxlength=125
                        :autosize="{ minRows: 5}"
                        :placeholder="$t('common.pleaseInput')"
                        v-model.trim="form.opinion"
                        style="vertical-align: middle">
              </el-input>
          </el-form-item>
    </DialogEdit>
  </div>
</template>

<script>
import { DialogEdit } from 'newepoch-components'
import AssetauditApi from '@/api/assetaudit/assetauditApi'
export default {
  name: 'createFeedback',
  components: {
    DialogEdit
  },
  props: {
    visible: { // 开启弹窗
      type: [Boolean],
      required: true,
      default: function () {
        return false
      }
    },
    feedbackKeyId: { // 主画面传入的keyId
      type: String,
      required: true,
      default: function () {
        return ''
      }
    }
  },
  data () {
    return {
      dialogTop: '30vh',
      appendToBody: true,
      DialogEdit: '',
      labelPosition: 'left',
      form: {
        keyId: '',
        opinion: ''
      },
      formRules: {
        opinion: [
          { required: true, message: this.$t('common.promptFeedback'), trigger: 'blur' }
        ]
      },
      formLabelWidth: '80px'
    }
  },
  methods: {
    created (form) { // 保存函数
      this.form.keyId = this.feedbackKeyId
      this.$LoadingShow()
      AssetauditApi.createFeedback.feedback(form).then(res => {
        this.$LoadingClose()
        if (res.data === true) {
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          this.dialogFormVisible = false
          this.$emit('dialogClose')
        } else {
          this.$message({
            message: '保存失败',
            type: 'error'
          })
          this.dialogFormVisible = false
        }
      })
    }
  },
  computed: {
    // api接口
    api () {
      return AssetauditApi.createFeedback
    },
    dialogFormVisible: {
      get: function () {
        return this.visible
      },
      set: function (value) {
        this.$emit('update:visible', value)
      }
    }
  }
}
</script>

<style>

</style>
