<template lang="pug">
  el-dialog( :close-on-click-modal="false",  :close-on-press-escape="false"  :visible.sync="visible", :append-to-body="true", :before-close="handleClose" )
    .title-bold(slot="title") {{'审批接管站点申请' }}
    el-form( :model="dataForm" ref="dataForm" label-width="140px" )
      el-row(:span="24")
        el-col(:span='24')
          el-form-item(label="申请接管站点单位:" )
            font {{dataForm.takeoverOrgName}}
        el-col(:span='24')
          el-form-item(label="申请人:")
            font {{dataForm.applyUserName}}
        el-col(:span='24')
          el-form-item(label="申请时间:")
            font {{dataForm.applyTime}}
        el-col(:span='24')
          el-form-item(label="接管类型:" )
            font(v-if='dataForm.takeoverType===1') 主动接管
            font(v-if='dataForm.takeoverType===2') 被动接管
        el-col(:span='24')
          el-form-item(label="申请理由:")
            font {{dataForm.reason}}
    div(slot="footer" align="center")
      el-button( size="medium" @click="cancel") 取消
      el-button( type="primary" size="medium" @click="dataFormSubmit(3)" v-prevent-re-click) 审批不通过
      el-button( type="primary" size="medium" @click="dataFormSubmit(2)" v-prevent-re-click) 审批通过
</template>

<script>
  // import { isEmail, isMobile } from '@/util/validate'
  export default {
    data() {
      return {
        id: '',
        clickFlag: false,
        visible: false,
        dataForm: {}
      }
    },
    mounted() {},
    methods: {
      init(id) {
        this.clickFlag = false
        this.visible = true
        this.id = id || ''
        if (id) {
          this.$http({
            url: this.$http.adornUrl('/sysStationTakeover/getId/' + id),
            method: 'get',
            params: this.$http.adornParams()
          }).then((data) => {
            // console.log(data)
            this.dataForm = data.bean || {}
          })
        } else {
          this.dataForm = {}
        }
      },
      //关闭前
      handleClose() {
        this.visible = false
        this.$refs.dataForm.resetFields()
      },

      // 表单提交
      dataFormSubmit(status) {
        this.dataForm.status = status
        //站点系统
        this.dataForm.type = JSON.parse(localStorage.getItem('sysSystem')).type || 1
        this.clickFlag = true
        this.$http({
            url: this.$http.adornUrl(`/sysStationTakeover/agree`),
            method: 'post',
            data: this.dataForm
          }).then((data) => {
            if (data && data.code === 0) {
              this.$message.success('操作成功')
              if (status === 2) sessionStorage.setItem('takeover', true)
              if (status === 3) sessionStorage.removeItem('takeover')
              this.handleClose()
              location.reload(true)
              // this.$emit('refreshdatalist')
            }
            this.clickFlag = false
          })
          .catch((data) => {
            this.$message.error(data.msg)
            this.clickFlag = false
          })
      },
      //取消
      cancel() {
        this.$confirm('确认取消?', '审批接管站点申请', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          .then(() => {
            this.handleClose()
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消退出'
            })
          })
      }
    }
  }
</script>
<style lang='scss' scoped>
  .el-table__header {
    width: 100% !important;
  }

  .el-table__body {
    width: 100% !important;
  }

  .el-form-item {
    margin-bottom: 0px !important;
  }
</style>
