/**
 * 标段相关js
 *
 * @author CaiAoLin
 * @date 2018/2/5
 * @version
 */

// 整理数据
let tenderData = [];
try {
    if (tenderList.length <= 0) {
        throw '数据为空';
    }
    for(const tmp of tenderList) {
        const tmpData = {
            value: 7814964.00,
            name: tmp.name,
        };
        tenderData.push(tmpData);
    }
} catch (error) {

}
//1 标段完成占比/
let myChart = echarts.init(document.getElementById('chartContainer1'));
let option = {
    color: ['#e9af68','#57b7b6','#e4575a','#959eac','#6699FF',
        '#d38b70','#8fb7cf','#cd5c5c','#ffa500','#40e0d0',
        '#1e90ff','#ff6347','#7b68ee','#00fa9a','#ffd700',
        '#5c616b','#ff6666','#3cb371','#b8860b','#30e0e0'],
    title : {
        text: '标段完成占比',
        x:'left'
    },

    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b}：{c} 元<br>占：{d} %"
    },
    calculable : true,
    series : [
        {
            name:'标段计量分布',
            type:'pie',
            radius : '60%',
            center: ['50%','50%'],
            data: tenderData
        }
    ]
};
// 为echarts对象加载数据
myChart.setOption(option);
//1 //
//2 土建标月进度//
myChart = echarts.init(document.getElementById('chartContainer2'));
option = {
    color:['#6699FF','#3cb371'],
    title : {
        text: '土建标月进度'
    },
    tooltip : {
        trigger: 'axis',
        formatter: "{b} <br/>{a}：{c} %<br/>{a1}：{c1} %"
    },
    legend: {
        data:['累计完成','本月完成']
    },
    dataZoom : {
        show : true,
        start :50,
        end : 100
    },
    xAxis : [
        {
            type : 'category',
            boundaryGap : true,
            data : [
                '2017-01','2017-02','2017-03','2017-04','2017-05','2017-06','2017-07','2017-08','2017-09'
            ]
        }
    ],
    yAxis : [
        {
            type : 'value',
            axisLabel : {
                formatter: '{value} %'
            },
            splitArea : {show : true}
        }
    ],
    series : [
        {
            name:'累计完成',
            type:'line',
            itemStyle: {
                normal: {
                    lineStyle: {
                        shadowColor : 'rgba(0,0,0,0.4)',
                        shadowBlur: 5,
                        shadowOffsetX: 3,
                        shadowOffsetY: 3
                    }
                }
            },
            data:[10, 10, 30, 40, 50, 60, 80, 85, 100]
        },
        {
            name:'本月完成',
            type:'line',
            itemStyle: {
                normal: {
                    lineStyle: {
                        shadowColor : 'rgba(0,0,0,0.4)',
                        shadowBlur: 5,
                        shadowOffsetX: 3,
                        shadowOffsetY: 3
                    }
                }
            },
            data:[10, 0, 20, 10, 10, 10, 10, 5, 15]
        }
    ]
};


// 为echarts对象加载数据
myChart.setOption(option);
//3 标段计量分布//

$(document).ready(function() {
    //标段类型选择
    $('#tender_type_select').change(function () {
        const type = $(this).val() != 0 ? '/?type='+$(this).val() : '';
        window.location.href = '/tender' + type;
    });
    //编辑标段 选择
    $('.save-btn').on('click',function () {
        $('#saveid').val($(this).attr('tender-id'));
        $('#savename').val($(this).attr('tender-name'));
        $('#savetype').val($(this).attr('tender-type'));
    });
    //删除标段 选择
    $('.del-btn').on('click',function () {
        $('#delid').val($(this).attr('tender-id'));
    });
});