<template>
  <div>
    <el-dialog
      v-loading="loading"
      :visible.sync="visible"
      :append-to-body="appendToBody"
      :before-close="beforeClose"
      title="审批"
      width="1200px"
      destroy-on-close>
      <el-form ref="form" :model="form" :rules="rules" label-width="200px" label-position="right" type="flex">
        <el-row :gutter="12">
          <el-col :span="12">
            <el-form-item prop="STATUS" label="是否通过: ">
              <el-select v-model="form.STATUS" filterable style="width: 300px" placeholder="请选择">
                <el-option label="是" value="2"/>
                <el-option label="否" value="3"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col v-if="form.STATUS === '3'" :span="24">
            <el-form-item v-if="form.STATUS === '3'" prop="OPINION" label="打回原因:">
              <el-input v-model="form.OPINION" :rows="2" type="textarea" placeholder="填写审批意见"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">关 闭</el-button>
        <el-button type="primary" @click="sendMessage">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import vueQr from 'vue-qr'
import Treeselect from '@riophae/vue-treeselect'
import uploadFile from '../../../util/uploadFile/index.vue'
import { requestFN } from '@/utils/request'
export default {
  components: { uploadFile, Treeselect, vueQr },
  props: {
    appendToBody: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      VEHICLE_ID: '',
      visible: false,
      loading: false,
      form: {
        STATUS: null,
        APPOINT_CORP_ID: '',
        APPOINT_CORP_NAME: '',
        APPOINT_DEPARTMENT_ID: null,
        APPOINT_DEPARTMENT_NAME: '',
        APPOINT_USER_ID: null,
        APPOINT_USER_NAME: '',
        OPINION: '',
        APPOINT_ANNEX: [],
        user: '',
        tm: new Date().getTime(),
        list: [],
        isShow: true,
        info: {},
        BACK_NAME: '',
        BACK_STEP: ''
      },
      rules: {
        STATUS: [
          { required: true, message: '请选择是否通过', trigger: 'change' }
        ],
        OPINION: [
          { required: true, message: '请填写打回原因', trigger: 'change' }
        ]
      },
      heirloom: {},

      normalizer(node) {
        return {
          id: node.id,
          label: node.name,
          children: node.nodes
        }
      },

      departmentTree: [],
      peopleList: [],
      corpFlag: false,
      menu: {
        department: '',
        user: '',
        uploadFile: '',
        limitFlag: ''
      },
      step: 0,
      list: [],
      ACCESS_AUDIT_ID: ''
    }
  },
  methods: {
    async init(e) {
      console.log(e)
      this.loading = true
      this.visible = true
      this.VEHICLE_ID = e.VEHICLE_ID
      this.loading = false
    },
    beforeClose() {
      this.handleClose()
    },
    handleClose() {
      this.form = {
        STATUS: '',
        APPOINT_DEPARTMENT_ID: null,
        APPOINT_DEPARTMENT_NAME: '',
        APPOINT_USER_ID: '',
        APPOINT_USER_NAME: '',
        OPINION: '',
        user: '',
        list: [],
        tm: new Date().getTime()
      }
      this.visible = false
    },
    goDetail() {
      this.$parent.activeName = 'List'
    },
    sendMessage() {
      requestFN(
        '/vehiclemessage/qyAudit',
        {
          AUDITOR: JSON.parse(sessionStorage.getItem('user')).USER_ID,
          VEHICLE_ID: this.VEHICLE_ID,
          IS_AUDIT: this.form.STATUS,
          REMARK: this.form.OPINION
        }
      ).then((data) => {
        this.visible = false
        this.$emit('refresh', '')
      }).catch((e) => {
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>