<template>
  <el-dialog :title="title" :visible.sync="approvalOpen" width="800px" append-to-body destroy-on-close :close-on-click-modal="false">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="审核状态" prop="state">
            <el-radio-group v-model="form.state">
              <el-radio :label="0">通过</el-radio>
              <el-radio :label="1">不通过</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="审核意见" prop="suggestion">
            <el-input type="textarea" v-model="form.suggestion" placeholder="请输入审核意见"/>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { dangerApproval } from "@/api/checktask/danger";
    export default {
      name: "approval",
      data(){
          return{
            title: "审核",
            approvalOpen: false,
            ids: [],
            form: {},
            rules: {
              state: [
                { required: true, message: "请选择审核状态", trigger: "change" }
              ],
            }
          }
      },
      methods:{
        open(ids){
          this.reset();
          this.ids = ids;
          this.approvalOpen = true;
        },
        submitForm(){
          this.$refs["form"].validate(valid => {
            if (valid) {
              let data = [];
              this.ids.forEach(item =>{
                data.push({
                  id: item,
                  ...this.form
                })
              })
              dangerApproval(data).then(res =>{
                this.$message.success("审核成功");
                this.approvalOpen = false;
              })
            }
          })

        },
        cancel(){
          this.approvalOpen = false;
        },
        reset(){
          this.form = {
            state: null,
            suggestion: null
          }
          this.resetForm("form");
        }
      }
    }
</script>

<style scoped>

</style>
