<template>
  <dialog-edit
    :visible.sync="dialogVisible"
    :title="$t('chargeback.audit_opinion')"
    :editModel="editModel"
    :form="form"
    :api="api"
    :footerVisible="true"
    :footerBtnShow="false"
    width="600px"
    class="audit_opinion"
  >
    <el-form :model="formData" inline ref="auditForm" >
      <el-form-item :label="$t('chargeback.bulk_operation')" label-width="100px">
        <el-input v-model="formData.auditName" disabled></el-input>
      </el-form-item>
      <el-form-item :label="$t('chargeback.audit_opinion')" label-width="100px"
                    prop="auditReason"
                    :rules="[
                      { required: auditCode==='2', message: '请输入', trigger: 'blur' }
                    ]">
        <el-input type="textarea" v-model.trim="formData.auditReason" :rows="4" :maxlength="200" show-word-limit></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <auth-button size="medium" type="primary" :label="$t('common.submit')" @click="save"  ></auth-button>
      <auth-button size="medium" :label="$t('common.close')" @click="dialogVisible = false"  ></auth-button>
    </div>
  </dialog-edit>
</template>

<script>
import BaseEditPage from '@/pages/baseEditPage'
import chargebackApi from '@/api/chargeback'
import {
  DialogEdit,
  authButton
} from 'newepoch-components'
const auditItem = {
  1: '审核通过',
  2: '审核不通过'
}
export default {
  extends: new BaseEditPage(''),
  computed: {
    api () {
      return chargebackApi.auditApi
    }
  },
  data () {
    return {
      formData: {
        auditName: null,
        auditReason: ''
      }
    }
  },
  methods: {
    save () {
      let $this = this
      this.$refs.auditForm.validate((val) => {
        if (val) { //
          $this.dialogVisible = false
          $this.$emit('successAudit', this.formData.auditReason)
          this.formData.auditReason = ''
        }
      })
    }
  },
  props: {
    auditCode: {
      type: String,
      default: () => null
    }
  },
  components: {
    DialogEdit,
    authButton
  },
  watch: {
    visible (val) {
      if (val) {
        this.formData.auditName = auditItem[this.auditCode]
      } else {
        this.formData.auditReason = ''
        this.$refs.auditForm.clearValidate()
      }
    }
  }
}
</script>
