<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :destroy-on-close="true"
      width="50%"
    >
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="160px" class="demo-ruleForm">
        <el-form-item label="申诉企业" prop="">
          <div v-for="(item, index) in entList" :key="index" style="margin-bottom: 8px">
            <span>{{ index + 1 }}、{{ item.entName }}（统一社会信用代码：{{ item.uscc }}）</span>
          </div>
        </el-form-item>
        <el-form-item label="异议意见" prop="objectionOpinion">
          <el-input v-model="ruleForm.objectionOpinion" type="textarea" placeholder="请输入异议意见" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { expelledObjectSave } from '@/api/除名公告.js'
export default {
  data() {
    return {
      noticeBizId: '',
      title: '',
      dialogVisible: false,
      ruleForm: {
        objectionOpinion: ''
      },
      entList: [],
      rules: {
        objectionOpinion: [
          { required: true, message: '请输入异议意见', trigger: 'blur' }
        ]
      }
    }
  },
  created() {

  },
  mounted() {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const submitForm = {
            ...this.ruleForm,
            entIds: this.entList.map((item) => {
              return item.entId
            }),
            noticeBizId: this.noticeBizId
          }
          expelledObjectSave(submitForm).then(res => {
            if (res.code === 0) {
              this.dialogVisible = false
              this.$message({
                message: this.title + '成功！',
                type: 'success'
              })
              this.$emit('refreshList')
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    openDialog(data) {
      this.dialogVisible = true
      this.title = '除名异议申请'
      this.entList = data.list
      this.noticeBizId = data.id
    }
  }
}
</script>

<style scoped lang="scss">

</style>
