<template>
  <el-tabs v-model="activeName" :style="{padding:'20px',height:'90%'}">
    <el-tab-pane label="开工材料" name="first">
      <el-container>
          <el-form ref="elForm" :model="items" size="medium" label-width="100px">
            <el-form-item label="开工申请单" prop="applicationForCommencementFiles">
              <bns-file-list-tabs :items="items.applicationForCommencementFiles" />
            </el-form-item>
            <el-form-item label="其他附件" prop="otherFiles">
              <bns-file-list-tabs :items="items.otherFiles" />
            </el-form-item>
          </el-form>
      </el-container>
    </el-tab-pane>
    <el-tab-pane label="审批信息" name="second">
      <bns-timeline-tabs :is-examine="paramsData.isExamine" :btn-show="paramsData.btnShow" :show-type="paramsData.showType" :items="approvalItems" :final-check="paramsData.finalCheck"
                         v-on:pass="approvalPass"
                         v-on:turnDown="approvalTurnDown"
                         v-on:finalInstance="approvalFinalInstance"/>
    </el-tab-pane>
  </el-tabs>
</template>
<script>
import BnsEquipDetailsTabs from '@/components/pro-tabs/bns-equip-details-tabs.vue'
import uploadFile from '@/views/pro/admissionRequest/uploadFile.vue'
import BnsTimelineTabs from '@/components/pro-tabs/bns-timeline-tabs.vue'
import { addConsStartWorkApply } from '@/api/pro/cons/consList'
import { getFileData, getMyToDoNum, parseTime } from '@/utils/bonus'
import BnsFileListTabs from '@/components/pro-tabs/bns-file-list-tabs.vue'
import { selectFile } from '@/api/tool/select'
import { submitPersonApproval } from '@/api/pro/subManagement/subList'
import { approvalHistory } from '@/api/terminalEquipment/deviceInformation'
import { decryptCBC } from '@/utils/aescbc'

export default {
  components: { BnsFileListTabs, BnsTimelineTabs, BnsEquipDetailsTabs, uploadFile },
  data() {
    return {
      activeName: 'first',
      items: {
        proName: '',
        applicationForCommencementFiles: [],
        otherFiles: [],
      },
      approvalItems:[],
      paramsData: {},
    }
  },
  created() {
    const params = this.$route.params && this.$route.params.data
    this.paramsData = JSON.parse(decryptCBC(params))
    this.getStartWorkFile()
    this.getOtherFile()
    this.approvalHistory()

  },
  methods: {
    approvalHistory(){
      console.log("this.paramsData.taskId:"+this.paramsData.taskId)
      approvalHistory({taskId:this.paramsData.taskId}).then(res => {
        this.approvalItems = res.data;
      })
    },
    getStartWorkFile(){
      const params = {
        uuid: this.paramsData.uuid,
        classification: '1',
        fromType: '1',
        informationType: '6',
      }
      selectFile(params).then(response => {
        this.items.applicationForCommencementFiles = response.data;
      });
    },
    getOtherFile(){
      const params = {
        uuid: this.paramsData.uuid,
        classification: '1',
        fromType: '1',
        informationType: '7',
      }
      selectFile(params).then(response => {
        this.items.otherFiles = response.data;
      });
    },
    //上传组件-图片查看
    picturePreview(file) {
      console.log(file)
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    cancel() {
      this.$tab.closePage()
    },
    /** 审核通过*/
    approvalPass(e){
      const param = {
        reason:e,
        ...this.paramsData,
        agree:"1"
      }
      this.approval(param,"审批通过")
    },
    /**审核驳回*/
    approvalTurnDown(e){
      const param = {
        ...e,
        ...this.paramsData,
        agree:"2"
      }
      this.approval(param,"退回成功")
    },
    /**终审*/
    approvalFinalInstance(e){
      const param = {
        reason:e,
        ...this.paramsData,
        agree:"3"
      }
      this.approval(param,"终审成功")
    },
    /**
     * 审批方法+
     * @param param
     * @param text
     */
    getMyToDoNum,
    approval(param,text){
      submitPersonApproval(param).then(response => {
        this.getMyToDoNum()
        if (response.code === 200) {
          this.$message({
            message: text,
            type: 'success'
          })
          this.$tab.closePage();
        } else {
          this.$message({
            message: response.msg,
            type: 'error'
          })
        }
      })
    }
  }

}
</script>
<style scoped lang="scss">
.el-header, .el-footer {
  color: #333;
  line-height: 60px;
  text-align: right;
  position: absolute;
  top: 90%;
  left: 85%
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  line-height: 660px;
  height: 750px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
