<template>
  <bns-person-approval-tabs
    :items="formData"
    v-on:pass="approval"
    v-on:turnDown="turnDown"
    v-on:finalInstance="finalInstance"
  />
</template>
<script>
import { getMyToDoNum, getParams, hideSensitiveInfo } from '@/utils/bonus'
import BnsPersonApprovalTabs from '@/components/pro-tabs/bns-person-approval-tabs.vue'
import { getSubPersonnelDetails } from '@/api/pro/outsourcingPro'
import { submitPersonApproval } from '@/api/pro/subManagement/subList'
import BnsTimelineTabs from '@/components/pro-tabs/bns-timeline-tabs.vue'

import { approvalHistory } from '@/api/terminalEquipment/deviceInformation'
import { decryptCBC } from '@/utils/aescbc'
export default {
  components: {
    BnsTimelineTabs,
    BnsPersonApprovalTabs,
  },
  data() {
    return {
      paramsData: undefined,
      formData: {
        data: {},
        auditType: '入场',
        approvalInfo: [],
        finalCheck: '0',
        showType: 2,
        isExamine: true,
        btnShow: true, //需要根据按钮判断true   false   查看false 审核true
      },
    }
  },
  created() {
    const params = this.$route.params && this.$route.params.data
    this.paramsData = JSON.parse(decryptCBC(params))
    console.log('paramsData==' + JSON.stringify(this.paramsData))
    this.getDetails()
    this.approvalHistory()
  },
  methods: {
    getParams,
    approvalHistory() {
      console.log('this.paramsData.taskId:' + this.paramsData.taskId)
      approvalHistory({ taskId: this.paramsData.taskId }).then(res => {
        this.formData.approvalInfo = res.data
        console.log(JSON.stringify(res))
      })
    },
    getMyToDoNum,
    approval(e) {
      console.log('tongg')
      console.log(JSON.stringify(e))
      const param = {
        reason: e,
        ...this.paramsData,
        agree: '1',
      }
      submitPersonApproval(param).then(response => {
        this.getMyToDoNum()
        console.log('responseresponseresponse', JSON.stringify(response))
        if (response.code === 200) {
          this.$message({
            message: '审核成功',
            type: 'success',
          })
          this.$tab.closePage()
        } else {
          this.$message({
            message: response.msg,
            type: 'error',
          })
        }
      })
    },

    getDetails() {
      const params = {
        ...this.getParams(),
        uuid: this.paramsData.uuid,
      }
      getSubPersonnelDetails(params).then(response => {
        this.formData.data = response.data

        console.log('response.data详情数据', response.data)
        this.formData.data.phone = hideSensitiveInfo(response.data.phone)
        this.formData.data.idCard = hideSensitiveInfo(response.data.idCard)
        this.formData.finalCheck = this.paramsData.finalCheck
        this.formData.showType = this.paramsData.showType
        this.formData.isExamine = this.paramsData.isExamine
        this.formData.btnShow = this.paramsData.btnShow
        this.formData.auditType = this.paramsData.auditType
        console.log('this.formData.data==' + JSON.stringify(this.formData))
        this.loading = false
      })
    },
    finalInstance(e) {
      console.log('终审按钮点击')
      console.log(JSON.stringify(e))

      console.log('回退按钮点击')
      console.log('butongtongg')
      const param = {
        reason: e,
        ...this.paramsData,
        agree: '3',
      }
      console.log('param', JSON.stringify(param))
      submitPersonApproval(param).then(response => {
        this.getMyToDoNum()
        console.log('responseresponseresponse', JSON.stringify(response))
        if (response.code === 200) {
          this.$message({
            message: '终审成功',
            type: 'success',
          })
          this.$tab.closePage()
        } else {
          this.$message({
            message: response.msg,
            type: 'error',
          })
        }
      })
    },
    turnDown(e) {
      console.log('回退按钮点击')
      console.log('butongtongg')
      const param = {
        ...e,
        ...this.paramsData,
        agree: '2',
      }
      console.log('param', JSON.stringify(param))
      submitPersonApproval(param).then(response => {
        this.getMyToDoNum()
        console.log('responseresponseresponse', JSON.stringify(response))
        if (response.code === 200) {
          this.$message({
            message: '退回通过成功',
            type: 'success',
          })
          this.$tab.closePage()
        } else {
          this.$message({
            message: response.msg,
            type: 'error',
          })
        }
      })
    },
  },
}
</script>

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