<template>
  <div class="resource">
    <el-dialog @close="cancelData"
               :visible.sync="dialogTableVisible"
               width='70%'>
      <div slot="title">
        <i class="el-icon-document" style="font-size: 20px"></i>
        <span style="margin-left:10px;font-size:18px">审核</span>
      </div>
      <el-form :model="formData" label-width="90px" :rules="monitorRules"  ref="monitorForm" >
        <el-row>
          <el-col :span='8'>
            <el-form-item prop="auditNum" label="审核数量">
              <el-input v-model="formData.auditNum" type="number" size="small" style="width: 100%;"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span='8'>
            <el-form-item prop="auditDesc" label="审核描述">
              <el-input v-model="formData.auditDesc" type="text" size="small" style="width: 100%;"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" icon="el-icon-check" @click="audit">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancelData">取消</el-button>
      </div>

    </el-dialog>
  </div>
</template>
<script>
import {getCookie ,formatDate, isStartEndDate,} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  props: ['showFlag', 'Params'],
  data() {
    return {
      dialogTableVisible: false,
      monitorRules: {
        auditNum: [{ required: true, message: '该项不能为空', trigger: 'blur'}]
      },
      formData: {
        auditNum: '',
        auditDesc: '',
        ppId: ''
      }
    }
  },
  methods: {
    audit() {
      this.$refs['monitorForm'].validate(valid => {
        if (valid) {
          let model = JSON.parse(JSON.stringify(this.formData))
          this.axios.put(`pass/testManagement/v1/limslrcstuffpps/arrList/${model.ppId}`, model, {individualType: 'json'}).then(res => {
            if (res.code == 0 || res.code == 200) {
              this.cancelData()
              this.$emit('refresh')
              return this.$message.success('审核成功!')
            } else {
              return this.$message.warning(res.message)
            }
          }).catch(e => {
            return this.$message.error(e.message)
          })
        }
      })
    },
    cancelData() {
      this.Params = null
      this.formData.auditNum = ''
      this.formData.ppId = ''
      this.resetForm('monitorForm')
      this.dialogTableVisible = false;
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  watch: {
    showFlag (arg) {
      if (this.Params !== null) {
        this.formData.auditNum = this.Params.planNum
        this.formData.auditDesc = this.Params.auditDesc
        this.formData.ppId = this.Params.ppId
      }
      this.dialogTableVisible = true;
    }
  }
}
</script>
