<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 || selectRow.title }}</li>
        <li v-if="!isCenterProcess"><span>流程结果：</span><p :class="['row-state', !isHistroy?'ing-state':(selectRow.endTime?'end-state':'cancel-state')]">{{ !isHistroy ? '进行中' : ( selectRow.endTime ? '已完成' : '已取消') }}</p></li>
        <li v-if="isCenterProcess">
          <span>流程结果：</span>
          <p v-if="selectRow.status === 1" class="row-state ing-state">运行中</p>
          <p v-if="selectRow.status === 2" class="row-state case-cancel">已取消</p>
          <p v-if="selectRow.status === 3" class="row-state end-state">已完成</p>
          <p v-if="selectRow.status === 4" class="row-state cancel-state">不通过</p>
        </li>
        <!-- 等门类树更改之后再显示 -->
        <!-- <li><span>所属全宗：</span>全宗A</li> -->
        <li v-if="selectRow.endTime || selectRow.complete_time"><span>结束时间：</span>{{ (selectRow.endTime || selectRow.complete_time) | parseTime }}</li>
        <li v-else><span>结束时间：</span>-</li>
      </ul>
      <!-- 1.归档 index=1  2.退回 index=2  3.开放 index=6  4.销毁index=7   5.利用index=3   6.内部移交index=4  7.外部移交index=5 -->
      <!-- 归档 / 退档 -->
      <!-- <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" :table-data="tableData" :src-img="srcImg" :task-table-list="taskTableList" :is-utilize="isUtilize" :set-page="setPage" @page-change="pageChangeHandler" @size-change="sizeChangeHandler" />
      </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 { FetchBusinessFlowDetails } from '@/api/archivesManage/library'
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
    },
    isCenterProcess: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      detailVisible: false,
      isExpend: false,
      activeIndex: 0,
      selectRow: {},
      srcImg: '',
      taskTableList: [],
      tableData: [],
      isUtilize: false,
      setPage: {
        total: 0,
        size: 10,
        page: 0
      }
    }
  },
  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'
    }
  },
  mounted() {

  },
  methods: {
    changeActiveTab(data) {
      this.activeIndex = data
      if (this.activeIndex === 0) {
        this.setPage.page = 0
        this.getBusinessFlowDetails()
      } else if (this.activeIndex === 1) {
        this.getTaskByProcinstId()
      } else if (this.activeIndex === 2) {
        this.getProcessImg()
      }
    },
    getBusinessFlowDetails() {
      const params = {
        'businessId': (this.selectRow && this.selectRow.businessId) ? this.selectRow.businessId : this.selectRow.id,
        'page': this.setPage.page,
        'size': this.setPage.size
      }
      FetchBusinessFlowDetails(params).then((res) => {
        if (res.code !== 500) {
          console.log(res)
          this.baseInfo = res.businessFlow
          if (res.businessFlow.businessType === 5) {
            this.isUtilize = true
            res.details.content.forEach(item => {
              item.utilizeType = item.utilizeType.split(',').map(Number)
            })
          } else {
            this.isUtilize = false
            res.details.content.forEach(item => {
              item.utilizeType = []
            })
          }
          this.tableData = res.details.content
          this.setPage.total = res.details.totalElements
        } else {
          this.$message({ message: '获取数据失败', type: 'error', offset: 8 })
        }
      }).catch(err => {
        console.log(err)
      })
    },
    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)
      })
    },
    // 当前页改变
    pageChangeHandler(e) {
      this.setPage.page = e
      this.getBusinessFlowDetails()
    },
    // 每页条数改变
    sizeChangeHandler(e) {
      this.setPage.size = e
      this.setPage.page = 0
      this.getBusinessFlowDetails()
    }
  }
}
</script>

<style lang='scss' scoped>

.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%;
      }
    }
  }
}
</style>
