<template>
    <div class="app-container">
      <van-nav-bar
        left-arrow
        fixed
        placeholder
        @click-left="$router.back(-1)"
      >
        <template #title>
          <p style="font-weight: bold;">审批历史</p>
        </template>
      </van-nav-bar>
      <div class="main_box">
        <van-row v-if="approvalTemplateDetailList.length>0" v-for="(item1,index,i) in approvalTemplateDetailList" :key="i">
          <van-col span="4" align="right">
            <p class="icon_jian blue" ><van-icon name="minus" size="14" /></p>
          </van-col>
          <van-col span="20">
            <van-row>
              <van-col span="9" style="padding: 0;">
                <p>{{item1.activityName}}</p>
              </van-col>
              <van-col span="15" style="padding: 0;">
                <p style="text-align: right;">{{item1.startTime}}</p>
              </van-col>
            </van-row>
            <van-row>
              <van-col span="9" style="padding: 0;">
                <p>{{item1.assigneeName}}</p>
              </van-col>
              <van-col span="15" style="padding: 0;">
                <p style="text-align: right;">{{item1.comment}}</p>
              </van-col>
            </van-row>
          </van-col>
        </van-row>
      </div>
    </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "approvalProcess",
  data() {
    return {
      processList:{},
      form:{},
      approvalTemplateDeptList:[],
      approvalTemplateDetailList:[]
    };
  },
  created() {
    this.getHistoryList(this.$route.query.id);
  },
  methods: {
    getHistoryList(instanceId) {
      this.loading = true;
      return request({
        url: "/activiti/process/listHistory",
        method: "post",
        data: { processInstanceId: instanceId },
      })
        .then((response) => {
          this.approvalTemplateDetailList = response.rows;
          this.approvalTemplateDetailList.forEach((row) => {
            row.startTime = this.format(row.startTime, "yyyy-MM-dd HH:mm:ss");
            row.endTime = this.format(row.endTime, "yyyy-MM-dd HH:mm:ss");
            row.durationInMillis = this.formatTotalDateSub(
              row.durationInMillis / 1000
            );
          });
          this.total = response.total;
          this.loading = false;
        })
        .then(() => {});
    },
    formatTotalDateSub (secondSub) {
      var days = Math.floor(secondSub / (24 * 3600));     // 计算出小时数
      var leave1 = secondSub % (24*3600) ;                // 计算天数后剩余的毫秒数
      var hours = Math.floor(leave1 / 3600);              // 计算相差分钟数
      var leave2 = leave1 % (3600);                       // 计算小时数后剩余的毫秒数
      var minutes = Math.floor(leave2 / 60);              // 计算相差秒数
      var leave3 = leave2 % 60;                           // 计算分钟数后剩余的毫秒数
      var seconds = Math.round(leave3);
      return days + "天" + hours + "时" + minutes + "分" + seconds + '秒';
    },
    format(time, format) {
      var t = new Date(time);
      var tf = function (i) { return (i < 10 ? '0' : '') + i };
      return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
        switch (a) {
          case 'yyyy':
            return tf(t.getFullYear());
            break;
          case 'MM':
            return tf(t.getMonth() + 1);
            break;
          case 'mm':
            return tf(t.getMinutes());
            break;
          case 'dd':
            return tf(t.getDate());
            break;
          case 'HH':
            return tf(t.getHours());
            break;
          case 'ss':
            return tf(t.getSeconds());
            break;
        }
      })
    }
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    padding: 0.2rem 0;
  }
  .main_box{
    width: 96%;
    margin: 0 auto;
    border-radius: 6px;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    background-color: #FFF;
    padding: 20Px 0;
  }
  .icon_jian{
    background-color: #C9C9C9;
    display: inline-block;
    width: 20Px;
    height: 20Px;
    line-height: 24Px;
    text-align: center;
    border-radius: 50%;
    color: #FFF;
  }
  .blue{
    background-color: #1D6FE9;
  }
  .red{
    background-color: rgb(245, 108, 108);
  }
  .textBlue{
    color: #1D6FE9!important;
  }
  .textRed{
    color: rgb(245, 108, 108)!important;
  }
  .van-col{
    padding: 10Px 10Px;
  }
  .van-col:nth-child(2){
    font-size: 16Px;
    color: #878787;
    line-height: 22Px;
  }
  .van-row{
    .van-row{
      .van-col{
        padding: 0 0 5Px 0!important;
        color: #878787;
      }
    }
  }
</style>
