<template>
    <div>
        <div class="progress-top">
            <div class="progress-top-inner">
                <el-image class="progress-top-image" alt="" :src="baseUrl + '/activiti/process/read-resource/' + instanceId">
                    <div slot="placeholder" style="text-align: center;">
                        <i class="el-icon-loading" style="font-size: 20px"></i>
                        <div style="padding: 5px">加载中...</div>
                    </div>
                    <div slot="error">
                        <img :src="require('@/assets/images/empty.png')" width="256" alt="未找到数据">
                    </div>
                </el-image>
            </div>
        </div>
        <div class="progress-bottom">
            <h4 class="h4">审批流程历史</h4>
            <el-table v-loading="loading" stripe width="100%" :data="historyList">
                <el-table-column label="任务名称" prop="activityName" align="center"></el-table-column>
                <el-table-column label="流程实例ID" prop="processInstanceId" align="center"></el-table-column>
                <el-table-column label="开始时间" prop="startTime" align="center">
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="结束时间" prop="endTime" align="center">
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="耗时" prop="durationInMillis" align="center"></el-table-column>
                <el-table-column label="处理人" prop="assigneeName" align="center"></el-table-column>
                <el-table-column label="处理意见" prop="comment" align="center"></el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
import { listHistory } from "@/api/progress";
export default {
    name: "Progress",
    props: {
        instanceId: {
            type: [String, Number],
            default: ''
        }
    },
    data() {
        return {
            baseUrl: [process.env.VUE_APP_BASE_API],
            progressUrl: '',
            historyList: [],
            loading: false
        }
    },
    created() {
        this.setProgressUrl();
        this.getHistoryList();
    },
    methods: {
        /** 设置流程图src */
        setProgressUrl() {
            this.progressUrl = this.baseUrl + '/activiti/process/read-resource?pProcessInstanceId=' + this.instanceId;
        },

        /** 获取审批历史 */
        getHistoryList() {
            this.loading = true;
            listHistory({ instanceId: this.instanceId }).then(response => {

                let arr = response.data;
                this.historyList = arr.filter((item) => {
                    if (item.activityName != null) {
                        return true
                    }
                })
                this.loading = false;
            }).catch(error => {
                this.loading = false;
            })
        }
    }

}
</script>

<style lang="scss" scoped>
.progress-top {
    min-height: 256px;
    overflow-y: hidden;
    border-bottom: 1px solid #ccc;

    .progress-top-inner {
        display: flex;
        justify-content: center;
    }
}

.progress-bottom {

    .h4 {
        font-size: 18px;
        color: #6379bb;
        border-bottom: none;
    }
}
</style>
