<template>
  <!-- 成交登记对话框 -->
  <el-dialog title="审核" :visible.sync="visible" width="800px" append-to-body :close-on-click-modal="false">
    <el-tabs v-model="checkTab">
      <el-tab-pane label="登记信息" name="one">
        <SignForm v-if="visible" :modalForm="modalForm" />
      </el-tab-pane>
      <el-tab-pane label="审核" name="two">
        <CheckForm v-if="visible" :checkForm="checkForm" />
      </el-tab-pane>
    </el-tabs>
    <span slot="footer">
      <el-button type="primary" v-if="modalForm.checkState == 1 && checkTab == 'two'" :disabled="!canSubmit" :loading="loading" @click="handleCheck(2)">通过</el-button>
      <el-button type="primary" v-if="modalForm.checkState == 1 && checkTab == 'two'" :disabled="!canSubmit" :loading="loading" @click="handleCheck(3)">驳回</el-button>
      <el-button @click="visible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>
    <script>
import { checkSign } from '@/api/zs/sign'
import CheckForm from './components/CheckForm.vue'
import SignForm from './components/SignForm.vue'
import CheckRecord from '../CheckRecord.vue'

export default {
  name: 'CheckDialog',
  components: {
    CheckForm, SignForm, CheckRecord
  },
  data() {
    return {
      admin: localStorage.getItem('admin'),
      preUrl: process.env.VUE_APP_BASE_API,
      userId: localStorage.getItem('userId'),
      visible: false,
      signLoading: false,
      modalForm: {},
      loading: false,
      checkTab: undefined,
      checkForm: {},
      canSubmit: true
    }
  },

  methods: {
    init(data) {
      console.log('打开弹框')
      this.resetForm('modalForm')
      this.modalForm = data
      if (this.modalForm.signSchool) {
        this.modalForm.signSchool = Number(this.modalForm.signSchool)
      }
      if (this.modalForm.signClass) {
        this.modalForm.signClass = Number(this.modalForm.signClass)
      }
      if (this.modalForm.signPlace) {
        this.modalForm.signPlace = Number(this.modalForm.signPlace)
      }
      this.visible = true
      this.checkTab = 'one'
      this.resetForm('modalForm2')
      this.checkForm = {
        signId: this.modalForm.signId,
        checkState: undefined,
        rejectReason: data.rejectReason,
        moneyState: data.moneyState,
      }
    },
    handleCheck(state) {
      console.log(this.checkForm)
      this.checkForm.checkState = state
      this.checkForm.signId = this.modalForm.signId
      this.canSubmit = false
      checkSign(this.checkForm).then((resp) => {
        if (resp && resp.code == 200) {
          if (state == 2) {
            this.$message.success('通过成功！')
          } else {
            this.$message.success('驳回成功！')
          }
          this.canSubmit = true
          this.visible = false
          this.$emit('refreshDataList')
        } else {
          this.canSubmit = true
        }
      })
    },
  },
}
    </script>