<template>
  <el-dialog class="detail-dialog" :visible.sync="detailVisible" :close-on-click-modal="false" :modal-append-to-body="false" append-to-body title="流程详情">
    <div class="setting-dialog">
      <ul class="detail-info">
        <li><span>流程名称：</span>{{ selectRow.flowableName }}</li>
        <li><span>流程结果：</span><p :class="['row-state', !isHistroy?'ing-state':(selectRow.endTime?'end-state':'cancel-state')]">{{ !isHistroy ? '进行中' : ( selectRow.endTime ? '已完成' : '已取消') }}</p></li>
        <li><span>所属全宗：</span>全宗A</li>
        <li v-if="selectRow.endTime"><span>结束时间：</span>{{ selectRow.endTime | parseTime }}</li>
        <li v-else><span>结束时间：</span>-</li>
      </ul>
      <!-- 归档 / 退档 -->
      <!-- <ul class="detail-type-info">
        <li><span>原始位置：</span>整编库</li>
        <li><span>目标位置：</span>管理库</li>
      </ul> -->
      <!-- 赋权审批 -->
      <!-- <ul class="detail-type-info">
        <li><span>利用目的：</span>资料查阅</li>
        <li><span>赋权开始：</span>2022-10-01 10:23:56</li>
        <li><span>赋权结束：</span>2022-10-07 10:23:56</li>
      </ul> -->
      <!-- 内部移交 -->
      <!-- <ul class="detail-type-info">
        <li><span>目标全宗：</span>全宗B</li>
      </ul> -->
      <!-- 开发鉴定 / 销毁鉴定 -->
      <!-- <ul class="detail-type-info">
        <li><span>申请缘由：</span>开放学习</li>
      </ul> -->
      <!-- <div class="detail-arrow" @click="isExpend = !isExpend"><i :class="[ isExpend ? 'arrow-up':'']" /></div>
      <el-collapse-transition>
        <div v-show="isExpend" class="service-detail">
          <h4>业务详情</h4>
          <ul class="detail-list">
            <li><span>业务类型：</span>归档审批</li>
            <li><span>原始位置：</span>全宗A-整理库-门类A</li>
            <li><span>目标位置：</span>全宗A-整理库-门类A</li>
            <li><span>赋权类型：</span>-</li>
            <li><span>起始时间：</span>-</li>
            <li><span>终止时间：</span>-</li>
            <li><span>利用目的：</span>-</li>
            <li><span>业务状态：</span>已完成</li>
            <li><span>审批状态：</span>通过</li>
          </ul>
        </div>
      </el-collapse-transition> -->
      <div class="detail-tab tab-content">
        <ul class="tab-nav">
          <li :class="{'active-tab-nav': activeIndex == 0 }" @click="changeActiveTab(0)">档案列表</li>
          <li :class="{'active-tab-nav': activeIndex == 1 }" @click="changeActiveTab(1)">任务列表</li>
          <li :class="{'active-tab-nav': activeIndex == 2 }" @click="changeActiveTab(2)">流程图</li>
        </ul>
        <div v-if="activeIndex == 0" class="double-click-btn"><i class="iconfont icon-zhuyi-lan" /><span>双击列表数据查看详情</span></div>
        <component :is="comName" class="component-cont" :src-img="srcImg" :task-table-list="taskTableList" />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="detailVisible=false">确定</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { FetchGenProcessDiagram, FetchTaskByProcinstId } from '@/api/system/flowable'
import processImg from './processImg/index'
import businessDetails from './businessDetails/index'
import taskList from './taskList/index'
// import approvalList from './approvalList/index'
export default {
  name: 'Detail',
  components: {
    processImg,
    businessDetails,
    taskList
    // approvalList
  },
  props: {
    isHistroy: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      detailVisible: false,
      isExpend: false,
      activeIndex: 0,
      selectRow: {},
      srcImg: '',
      taskTableList: []
    }
  },
  computed: {
    comName: function() {
      if (this.activeIndex === 0) {
        return 'businessDetails'
      } else if (this.activeIndex === 1) {
        return 'taskList'
      } else if (this.activeIndex === 2) {
        return 'processImg'
      }
      return 'businessDetails'
    }
  },
  methods: {
    changeActiveTab(data) {
      this.activeIndex = data
      if (this.activeIndex === 1) {
        this.getTaskByProcinstId()
      } else if (this.activeIndex === 2) {
        this.getProcessImg()
      }
    },
    getProcessImg() {
      this.srcImg = ''
      FetchGenProcessDiagram({ 'processId': this.selectRow.procinstId }).then((res) => {
        this.srcImg = res
      }).catch(err => {
        console.log(err)
      })
    },
    getTaskByProcinstId() {
      this.taskTableList = []
      FetchTaskByProcinstId({ 'procinstId': this.selectRow.procinstId }).then((res) => {
        this.taskTableList = res
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style lang='scss' scoped>
.detail-tab{
  position: relative;
}
.detail-dialog{
  .detail-info,
  .detail-list,
  .detail-type-info{
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    padding-top: 10px;
    font-size: 14px;
    line-height: 30px;
    color: #545B65;
    li{
      display: flex;
      justify-content: flex-start;
      width: 50%;
      span{
        display: inline-block;
        width: 75px;
        text-align: right;
        color: #0C0E1E;
      }
      p.row-state{
        display: block;
        font-size: 14px;
        height: 26px;
        line-height: 26px;
        margin-top: 2px;
      }
    }
  }
  .detail-type-info{
    padding-top: 0;
  }
  .detail-arrow{
    position: relative;
    width: 64px;
    height: 16px;
    margin: 10px auto;
    background-color:#E8F2FF;
    border-radius: 3px;
    cursor: pointer;
    i{
      position: absolute;
      left: 50%;
      top: 50%;
      display: block;
      width: 9px;
      height: 5px;
      margin-top: -2px;
      margin-left: -4px;
      background: url('~@/assets/images/icon/arrow.png') no-repeat center center;
      transition: all ease-in 0.5s;
      &.arrow-up {
        transform: rotate(180deg);
      }
    }

  }
  .service-detail{
    padding: 8px 12px;
    background-color: #F6F8FC;
    font-size: 14px;
    h4{
      position: relative;
      padding-left: 10px;
      color: #0C0E1E;
      &::before {
        content: "";
        position: absolute;
        left: 0;
        top: 50%;
        width: 3px;
        height: 14px;
        background-color: #0348F3;
        transform: translateY(-50%);
      }
    }
    .detail-list{
      p{
        width: 33%;
      }
    }
  }
  .double-click-btn{
    position: absolute;
    right: 0;
    top: 0;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    line-height: 26px;
    span{
      display: inline-block;
      font-size: 12px;
      color: #545B65;
    }
    i{
      display: inline-block;
      color: #0348F3;
    }
  }
}
</style>
