<template>
        <div :style="'padding:10px;background:#f7f7f7;min-height:'+tableHeight+'px;'">
        <div style="margin: 0 auto;width:1120px;">
            <!-- <label>项目统计</label> -->
            <el-row :gutter="10">
            <!-- 任务数量总计 -->
            <el-col :span="12">    
            <div class="box">
                <div >
                    <div class="lableTxt">项目概览表</div>
                    <el-divider></el-divider>
                    <el-row :gutter="10">
                    <el-col :span="6" style="text-align:center;">
                        <p style="color:#666;font-size:12px;">全部</p>
                        <p style="font-size:28px;font-weight:bold;color:black;">{{taskSum.total}}</p>
                    </el-col>    
                    <el-col :span="6" style="text-align:center;">
                        <p style="color:#666;font-size:12px;">已完成</p>
                        <p style="font-size:28px;font-weight:bold;color:green;">{{taskSum.finishCount}}</p>
                    </el-col>
                    <el-col :span="6" style="text-align:center;">
                        <p style="color:#666;font-size:12px;">未完成</p>
                        <p style="font-size:28px;color:blue;font-weight:bold;">{{taskSum.unfinishCount}}</p>
                    </el-col>
                    <el-col :span="6" style="text-align:center;">
                        <p style="color:#666;font-size:12px;">已逾期</p>
                        <p style="font-size:28px;color:red;font-weight:bold;">{{taskSum.timeupCount}}</p>
                    </el-col>
                    </el-row>
                    <el-row :gutter="10">
                    <el-col :span="6" style="text-align:center;">
                        <p style="color:#666;font-size:12px;">待认领</p>
                        <p style="font-size:28px;color:#orange;font-weight:bold;">{{taskSum.unassignCount}}</p>
                    </el-col>
                    <el-col :span="6" style="text-align:center;">
                        <p style="color:#666;font-size:12px;">今日到期</p>
                        <p style="font-size:28px;font-weight:bold;color:pink;">{{taskSum.todayTimeupCount}}</p>
                    </el-col>
                    <el-col :span="6" style="text-align:center;">
                        <p style="color:#666;font-size:12px;">逾期完成</p>
                        <p style="font-size:28px;font-weight:bold;color:gray;">{{taskSum.timeupFinishCount}}</p>
                    </el-col>
                    <el-col :span="6" style="text-align:center;">
                        <p style="color:#666;font-size:12px;">时间待定</p>
                        <p style="font-size:28px;font-weight:bold;color:black;">{{taskSum.timeunsetCount}}</p>
                    </el-col>
                    </el-row>
                </div>
            </div>
            </el-col>
            <el-col :span="12">    
                <div class="box">   
                    <div class="lableTxt">执行人分配</div>
                    <el-divider></el-divider>
                    <div id="executorPanel" style="height:300px;width:500px;"></div>
                </div>
            </el-col>
            </el-row>
            <el-row :gutter="10">
                <el-col :span="12">    
                    <div class="box">   
                        <div class="lableTxt">耗时最多任务</div>
                        <el-divider></el-divider>
                        <div id="costPanel" style="height:300px;width:500px;"></div>
                    </div>
                </el-col>
                <el-col :span="12">    
                    <div class="box">   
                        <div class="lableTxt">按任务列表统计</div>
                        <el-divider></el-divider>
                        <div id="stagesPanel" style="height:300px;width:500px;"></div>
                    </div>
                </el-col>
            </el-row>

            <el-row :gutter="10">
                <el-col :span="24">    
                    <div class="box" style="height:550px;">   
                        <div class="lableTxt">任务 计划工时 VS 实际工时 <el-link @click="exportTaskCompare" style="float:right;"><i class="iconfont firerock-iconexport"></i>导出</el-link></div>
                        <el-divider></el-divider>
                        <div id="taskTimeComparePanel" style="height:500px;width:1100px;"></div>
                    </div>
                </el-col>
            </el-row>
        </div>
        
    </div>
</template>
<style scoped>
#executorPanel {
        display: inline-block;
        width: 100%; 
    }  
.el-divider--horizontal {
    margin: 10px 0;
    height: 0.5px;
}
.box {
    background:#fff;border: 1px solid #eeeeee;border-radius:5px;padding:10px;
    height:303.7px;margin-top:10px;
}
.info span {
    color:#303133;
}
.gray_label {
    color:#999 !important;
}

.el-row {
    margin-top:10px;
}
.lableTxt {
    color:#666;
}

</style>
<script>
    import util from "../../common/js/util";
    export default {
        data() {
            return {
                compareChart:null,
                costChart:null,
                stagesChart: null,
                executorChart: null,
                pVisible:false,
                taskSum:{},
                users:[],
                importanceList:[{id:1,label:'一般'},{id:2,label:'紧急'},{id:3,label:'重要'},{id:4,label:'重要且紧急'}],
                //1-一般,2-紧急,3-重要,4-重要且紧急
                levelTxt:["全部","一般","紧急","重要","重要且紧急"],
                //1-进行中,2-已完成,3-已撤销
                statusTxt: ["全部","进行中","已完成","已撤销"],
                addFolderDialog: false,
                upLoading:false,
                user: JSON.parse(sessionStorage.getItem("user")),
                addLoading: false,
                curProjectId:null,
                title: "",
                
            };
        },
        methods: {
            exportTaskCompare() {
                let _this = this;
                this.http.post('/task/exportTaskTimeCompare', {projectId: this.curProjectId},
                res => {
                    if (res.code == "ok") {
                        location.href = res.data;
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                }
                );
            },
            getTaskTimeCompare() {
                let _this = this;
                this.http.post('/task/getTaskTimeCompare', {projectId: this.curProjectId},
                res => {
                    if (res.code == "ok") {
                        var xList1 = [], xList2 = [], list = res.data.reverse();
                        var taskNames = [];
                        for(var i in list) {
                            xList1.push({
                                "value": list[i].workHours,
                                "id": list[i].id,
                                "fullName":list[i].name,
                            });
                            xList2.push({
                                "value": list[i].planHours,
                                "id": list[i].id,
                                "fullName":list[i].name,
                            });
                            taskNames.push(list[i].name.length>12?list[i].name.substring(0,12)+'..':list[i].name);
                        }
                        var myChart = echarts.init(document.getElementById("taskTimeComparePanel"));
                        _this.compareChart = myChart;
                        var option = {
                            // 全局调色盘。
                            color: ["#409EFF","#71C671"],
                            title: {
                                show:list.length == 0,
                                textStyle: {
                                    color: "#666666",
                                    fontSize: 18,
                                    fontWeight: 'normal',
                                 },
                              text: list.length == 0?"暂无数据":"工时对比",
                              left: "center",
                              top: "center"
                            },
                            toolbox: {
                                show: true,
                                feature:{
                                    saveAsImage:{
                                        show:true
                                    },
                                    restore:{
                                        show:true
                                    },
                                    magicType:{
                                        type:['line','bar']
                                    },
                                }
                            },
                            legend: {
                                data: ['实际工时', '计划工时']
                            },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    type: 'shadow'
                                },
                            },
                            xAxis: {
                                type: 'value',
                                boundaryGap: [0, 1],
                                axisLabel: {
                                    formatter:'{value} 小时'
                                }
                            },
                            yAxis: [{
                                type: 'category',
                                data: taskNames
                            }],
                            series: [{
                                    name: '实际工时',
                                    type: 'bar',
                                    data: xList1
                                },
                                {
                                    name: '计划工时',
                                    type: 'bar',
                                    data: xList2
                                }]
                        };
                        myChart.setOption(option,{notMerge: true});
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            getTopCostTask() {
                let _this = this;
                this.http.post('/task/getTopCostTask', {projectId: this.curProjectId},
                res => {
                    if (res.code == "ok") {
                        var xList = [], yList = [], list = res.data;
                        for(var i in list) {
                            xList.push(list[i].name.length>6?list[i].name.substring(0,6)+'..':list[i].name);
                            yList.push({
                                "value": list[i].value,
                                "id": list[i].id,
                                "fullName":list[i].name,
                            });
                        }
                        var myChart = echarts.init(document.getElementById("costPanel"));
                        _this.costChart = myChart;
                        var option = {
                            title: {
                                show:list.length == 0,
                                textStyle: {
                                    color: "#666666",
                                    fontSize: 18,
                                    fontWeight: 'normal',
                                 },
                              text: list.length == 0?"暂无数据":"耗时最多任务图",
                              left: "center",
                              top: "center"
                            },
                            toolbox: {
                                show: true,
                                feature:{
                                    saveAsImage:{
                                        show:true
                                    },
                                    restore:{
                                        show:true
                                    },
                                    magicType:{
                                        type:['line','bar']
                                    },
                                }
                            },
                            tooltip:{
                                trigger:'axis',
                                formatter: function (params,ticket,callback) {
                                    var res = params[0].data.fullName + ""+" : " + params[0].data.value 
                                    + "小时";
                                    _this.params = params;
                                    return res;
                                }
                            },
                            xAxis: {
                                data: xList,
                                axisLabel: {
                                    interval:0,rotate:20
                                }
                            },
                            yAxis: [{
                                type : 'value',
                                axisLabel: {
                                    formatter:'{value} 小时'
                                }
                            }],
                            series: [{
                                name: '耗时(小时)',
                                type: 'bar',
                                barMaxWidth: 30,
                                data: yList,
                            }]
                        };
                        myChart.setOption(option,{notMerge: true});
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            getStagesPanel(){
                let _this = this;
                this.http.post('/task/getStagesPanel', {projectId: this.curProjectId},
                res => {
                    if (res.code == "ok") {
                        var list = res.data;
                        var myChart = echarts.init(document.getElementById("stagesPanel"));
                        _this.stagesChart = myChart;
                        myChart.setOption({
                            title: {
                                show:list.length == 0,
                                textStyle: {
                                    color: "#666666",
                                    fontSize: 18,
                                    fontWeight: 'normal',
                                 },
                              text: list.length == 0?"暂无数据":"任务列表统计",
                              left: "center",
                              top: "center"
                            },
                            toolbox: {
                                show: true,
                                feature:{
                                    saveAsImage:{
                                        show:true
                                    },
                                }
                            },
                            tooltip:{
                                trigger:'item',
                                formatter: "{b}<br/>任务数:{c} ({d}%)",
                            },
                            series : [
                                {
                                    name: '任务列表',
                                    type: 'pie',
                                    radius: '55%',
                                    data:list
                                }
                            ]
                        },{notMerge: true})
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            getExecutorPanel(){
                let _this = this;
                this.http.post('/task/getExecutorPanel', {projectId: this.curProjectId},
                res => {
                    if (res.code == "ok") {
                        var xList = [], yList = [], list = res.data;
                        for(var i in list) {
                            xList.push(list[i].executorName);
                            yList.push({
                                "value": list[i].taskCount,
                                "id": list[i].executorId
                            });
                        }
                        var myChart = echarts.init(document.getElementById("executorPanel"));
                        _this.executorChart = myChart;
                        var option = {
                            color: ["#409EFF","#71C671"],
                            title: {
                                show:list.length == 0,
                                textStyle: {
                                    color: "#666666",
                                    fontSize: 18,
                                    fontWeight: 'normal',
                                 },
                              text: list.length == 0?"暂无数据":"执行人分配图",
                              left: "center",
                              top: "center"
                            },
                            toolbox: {
                                show: true,
                                feature:{
                                    saveAsImage:{
                                        show:true
                                    },
                                    restore:{
                                        show:true
                                    },
                                    magicType:{
                                        type:['line','bar']
                                    },
                                }
                            },
                            tooltip:{
                                trigger:'axis',
                                formatter: function (params,ticket,callback) {
                                    var res = params[0].name + ""+" : " + params[0].data.value 
                                    + "个";
                                    _this.params = params;
                                    return res;
                                }
                            },
                            xAxis: {
                                data: xList,
                                axisLabel: {
                                    interval:0,rotate:20
                                }
                            },
                            yAxis: [{
                                type : 'value',
                                axisLabel: {
                                    formatter:'{value} '
                                }
                            }],
                            series: [{
                                name: '任务数量（个）',
                                type: 'bar',
                                barMaxWidth: 30,
                                data: yList,
                            }]
                        };
                        myChart.setOption(option,{notMerge: true});
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            getProjectTaskSum() {
                this.http.post('/project/taskSum', {
                    id: this.curProjectId
                },
                res => {
                    if (res.code == "ok") {
                        this.taskSum = res.data;
                    } else {
                        this.$message({
                        message: res.msg,
                        type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            refreshPage() {
                this.curProjectId = parseInt(this.$route.params.id);
                this.getProjectTaskSum();
                this.getExecutorPanel();
                this.getTopCostTask();
                this.getStagesPanel();
                this.getTaskTimeCompare();
            }
        },
        created() {
            let height = window.innerHeight;
            this.tableHeight = height - 160;
            const that = this;
            window.onresize = function temp() {
                that.tableHeight = window.innerHeight - 160;
            };
        },
        mounted() {
            this.curProjectId = parseInt(this.$route.params.id);
            var _this = this;
            window.addEventListener("resize", function() {
                if (_this.executorChart != null) {
                    _this.executorChart.resize();
                }
                if (_this.stagesChart != null) {
                    _this.stagesChart.resize();
                }
                if (_this.costChart != null) {
                    _this.costChart.resize();
                }
                if (_this.compareChart != null) {
                    _this.compareChart.resize();
                }
            });
            this.getProjectTaskSum();
            this.getExecutorPanel();
            this.getStagesPanel();
            this.getTopCostTask();
            this.getTaskTimeCompare();
        }
    };
</script>