<template>
  <el-dialog width="400px" :visible="visible" @close="handleClose" title="批量审批发票" center>
    <el-form ref="form" :model="formData" size="mini" :rules="rules" label-width="80px">
      <el-form-item prop="status" label="审批状态">
        <el-select v-model="formData.status" style="width: 100%" placeholder="审批状态">
          <el-option label="通过" value="2" />
          <el-option label="驳回" value="0" />
        </el-select>
      </el-form-item>

      <el-form-item label="备注" prop="remark">
        <el-input v-model="formData.remark" type="textarea" placeholder="备注" />
      </el-form-item>

      <ElFormItem class="flex-end">
        <ElButton type="primary" @click="onSubmit" :loading="loading">保存</ElButton>
      </ElFormItem>
    </el-form>
  </el-dialog>
</template>

<script>

const defaultData = {
  status:'',
  remark:''
}
export default {
  name: "approvalModal",
  props:['visible'],
  data(){
    return {
      formData:{...defaultData}
    }
  },
  computed:{
    rules(){
      return ({
        status:[
          {
            required:true,
            trigger:'change',
            message:'请选择审核状态'
          }
        ],
        remark:[
          {
            required: this.formData.status === "0",
            trigger:'change',
            message:'请输入备注'
          }
        ]
      })
    },
    _visible:{
      get(){
        return this.visible
      },
      set(newVal){
        this.$emit('update:visible',newVal)
      }
    }
  },
  methods:{
    handleClose(){
      this._visible = false
      this.formData = {...defaultData}
      this.loading = false
    },
    async onSubmit(){
      try{
        await this.$refs.form.validate()
        this.loading = true
        this.$emit("confirm",{
          ...this.formData,
          inv_type: '1',
        })
      }catch (e) {
        console.log(e)
      }
    }
  }
}
</script>

<style scoped>

</style>
