/**
 * Created by sff on 2018/4/2.
 */
$(function() {
    var pieChar = echarts.init(document.getElementById('pieChar'));
    //基础数据
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/mobileBaseData',
        success: function (res) {
            if (res) {
                $('.order_today').html(res.order_today);
                $('.order_month').html(res.order_month);
                $('.ps_today').html(res.ps_today);
                $('.ps_month').html(res.ps_month);
                $('.xp_today').html(res.xp_today);
                $('.xp_month').html(res.xp_month);
                $('.cost_today').html(res.cost_today);
                $('.cost_month').html(res.cost_month);
                $('.yi_avg_today').html(res.yi_avg_today);
                $('.yi_avg_month').html(res.yi_avg_month);
                $('.er_avg_today').html(res.er_avg_today);
                $('.er_avg_month').html(res.er_avg_month);
            }
        }
    })
    //订单情况
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/orderInfo',
        success: function (res) {
            if (res) {
                //$('.order_today').html(res.order_today);
                //$('.order_month').html(res.order_month);
                $('.yeji_today').html(res.yeji_today);
                $('.yeji_month').html(res.yeji_month);
                $('.avg_today').html(res.avg_today);
                $('.avg_month').html(res.avg_month);
            }
        }
    })
    // 【 渠道单量比重 】
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/channelOrder',
        success: function (res) {
            if (res) {
                $('.channel_order_wx_today').html(res.channel_order_wx_today);
                $('.channel_order_wx_month').html(res.channel_order_wx_month);
                $('.channel_order_jd_today').html(res.channel_order_jd_today);
                $('.channel_order_jd_month').html(res.channel_order_jd_month);
                $('.channel_order_zjs_today').html(res.channel_order_zjs_today);
                $('.channel_order_zjs_month').html(res.channel_order_zjs_month);
                $('.channel_order_hbh_today').html(res.channel_order_hbh_today);
                $('.channel_order_hbh_month').html(res.channel_order_hbh_month);

                var option = {
                    color: ['#ffd85c', '#55d1ff', '#fd7b5f', '#00ffd5'],
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b}: {c}<br/> ({d}%)"
                    },
                    legend: {
                        orient: 'horizontal',
                        data: ['自然进店', '网销', '转介绍', '婚博会'],
                        textStyle: {
                            fontSize: 12,
                            color: '#fff'
                        },
                        itemWidth: 20,
                        itemHeight: 12,
                        bottom:20
                    },
                    series: [
                        // {
                        //     name: '本日累计',
                        //     type: 'pie',
                        //     selectedMode: 'single',
                        //     radius: [0, '40%'],
                        //     label: {
                        //         normal: {
                        //             position: 'inner',
                        //             formatter: '{b}\n{c}\n{d}% ',
                        //             color: '#104078',
                        //             fontSize: '13'
                        //         }
                        //     },
                        //     labelLine: {
                        //         normal: {
                        //             show: false
                        //         }
                        //     },
                        //     data: [
                        //         { value: replace_all(res.channel_order_jd_today.toString(),',',''), name: '' },
                        //         { value: replace_all(res.channel_order_wx_today.toString(),',',''), name: '' },
                        //         { value: replace_all(res.channel_order_zjs_today.toString(),',',''), name: '' },
                        //         { value: replace_all(res.channel_order_hbh_today.toString(),',',''), name: '' }
                        //     ]
                        // },
                        {
                            name: '本月累计',
                            type: 'pie',
                            radius: ['50%', '30%'],
                            label: {
                                normal: {
                                    formatter: '{b|{b}}\n{hr|}\n {b|{c}}\n {per|{d}%}  ',
                                    backgroundColor: 'rgba(255,255,255,.2)',
                                    borderColor: 'transparent',
                                    color: '#fff',
                                    borderRadius: 4,
                                    padding: [3, 0, 5],
                                    rich: {
                                        a: {
                                            color: '#999',
                                            align: 'center',
                                            lineHeight: 22
                                        },
                                        hr: {
                                            borderColor: '#aaa',
                                            width: '100%',
                                            borderWidth: 0.5,
                                            height: 0
                                        },
                                        b: {
                                            fontSize: 12,
                                            lineHeight: 22,
                                            align: 'center'
                                        },
                                        per: {
                                            color: '#eee',
                                            backgroundColor: '#334455',
                                            padding: [2, 4],
                                            borderRadius: 2,
                                            lineHeight: 20
                                        }
                                    }
                                }
                            },
                            data: [
                                { value:replace_all(res.channel_order_jd_month.toString(),',',''), name: '自然进店' },
                                { value:replace_all(res.channel_order_wx_month.toString(),',',''), name: '网销' },
                                { value:replace_all(res.channel_order_zjs_month.toString(),',',''), name: '转介绍' },
                                { value:replace_all(res.channel_order_hbh_month.toString(),',',''), name: '婚博会' }
                            ]
                        }
                    ]
                };

                // 使用刚指定的配置项和数据显示图表。
                pieChar.setOption(option);
            }
        }
    })
    //实收情况
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/factInfo',
        success: function (res) {
            if (res) {
                $('.fact_yi_today').html(res.fact_yi_today);
                $('.fact_yi_month').html(res.fact_yi_month);
                $('.fact_er_today').html(res.fact_er_today);
                $('.fact_er_month').html(res.fact_er_month);
                $('.fact_today').html(res.fact_today);
                $('.fact_month').html(res.fact_month);
            }
        }
    })
    // 拍摄情况
    var psChart1 = echarts.init(document.getElementById('psChart1'));
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/psInfo',
        success: function (res) {
            if (res) {
                $('.ps_order_today').html(res.ps_order_today);
                $('.ps_order_month').html(res.ps_order_month);
                $('.ps_fc_order_today').html(res.ps_fc_order_today);
                $('.ps_fc_order_month').html(res.ps_fc_order_month);
                $('.ps_jn_order_today').html(res.ps_jn_order_today);
                $('.ps_jn_order_month').html(res.ps_jn_order_month);
                $('.ps_fact_today').html(res.ps_fact_today);
                $('.ps_fact_month').html(res.ps_fact_month);
                $('.ps_fc_fact_today').html(res.ps_fc_fact_today);
                $('.ps_fc_fact_month').html(res.ps_fc_fact_month);
                $('.ps_jn_fact_today').html(res.ps_jn_fact_today);
                $('.ps_jn_fact_month').html(res.ps_jn_fact_month);
                // 指定图表的配置项和数据
                var option1 = {
                    color: ['#ffe168'],
                    legend: {
                        data: ['本月单量'],
                        textStyle: {
                            fontSize: 12,
                            color: '#fff'
                        },
                        right: '10',
                        itemWidth: 20,
                        itemHeight: 12,
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    grid: {
                        top: '50',
                        left: '10%',
                        right: 0,
                        bottom: 0,
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        data: ['蜂巢', '嘉娜'],
                        axisTick: {
                            alignWithLabel: true
                        },
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        },
                        axisLabel: {
                            interval: 0,
                            rotate: 45
                        }
                    }],
                    yAxis: [{
                        type: 'value',
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        }
                    }],
                    series: [{
                        name: ['本月单量'],
                        type: 'bar',
                        barWidth: '37%',
                        data: [replace_all(res.ps_fc_order_month.toString(),',',''),replace_all(res.ps_jn_order_month.toString(),',','')]

                    }]
                };
                /* var option1 = {
                    color: ['#ffc091', '#55d1ff'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    legend: {
                        padding: 0,
                        top: "10%",
                        data: ['蜂巢单量', '嘉娜单量'],
                        textStyle: {
                            fontSize: 12,
                            color: '#fff'
                        },
                        itemWidth: 20,
                        itemHeight: 12,
                    },
                    grid: {
                        top: '50',
                        left: 0,
                        right: 0,
                        bottom: 0,
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        data: ['日单量', '月单量'],
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        }
                    }],
                    yAxis: [{
                        type: 'value',
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        }
                    }],
                    series: [{
                        name: '蜂巢单量',
                        type: 'bar',
                        stack: '日单量',
                        barWidth: '30%',
                        data: [replace_all(res.ps_fc_order_today.toString(),',',''),replace_all(res.ps_fc_order_month.toString(),',','')]
                    },
                        {
                            name: '嘉娜单量',
                            type: 'bar',
                            stack: '日单量',
                            barWidth: '30%',
                            data: [replace_all(res.ps_jn_order_today.toString(),',',''),replace_all(res.ps_jn_order_month.toString(),',','')]
                        }

                    ]
                };*/
                // 使用刚指定的配置项和数据显示图表。
                psChart1.setOption(option1);
                // 拍摄情况
                var psChart2 = echarts.init(document.getElementById('psChart2'));
                // 指定图表的配置项和数据
                var option2 = {

                    color: ['#6dffe8'],
                    legend: {
                        data: ['本月均价'],
                        textStyle: {
                            fontSize: 12,
                            color: '#fff'
                        },
                        right: '10',
                        itemWidth: 20,
                        itemHeight: 12,
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    grid: {
                        top: '50',
                        left: '10%',
                        right: 0,
                        bottom: 0,
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        data: ['蜂巢', '嘉娜'],
                        axisTick: {
                            alignWithLabel: true
                        },
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        },
                        axisLabel: {
                            interval: 0,
                            rotate: 45
                        }
                    }],
                    yAxis: [{
                        type: 'value',
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        }
                    }],
                    series: [{
                        name: ['本月均价'],
                        type: 'bar',
                        barWidth: '37%',
                        data: [replace_all(res.ps_fc_fact_month.toString(),',',''),replace_all(res.ps_jn_fact_month.toString(),',','')]
                    }]
                };
                // 使用刚指定的配置项和数据显示图表。
                psChart2.setOption(option2);
            }
        }
    })
    //选片
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/xpInfo',
        success: function (res) {
            if (res) {
                $('.xp_fact_today').html(res.xp_fact_today);
                $('.xp_fact_month').html(res.xp_fact_month);
                $('.xp_avg_today').html(res.xp_avg_today);
                $('.xp_avg_month').html(res.xp_avg_month);
                $('.xp_fc_er_today').html(res.xp_fc_er_today);
                $('.xp_fc_er_month').html(res.xp_fc_er_month);
                $('.xp_jn_er_today').html(res.xp_jn_er_today);
                $('.xp_jn_er_month').html(res.xp_jn_er_month);
            }
        }
    })
    //门店情况
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/mdInfo',
        success: function (res) {
            if (res) {
                $('.md_order_today').html(res.md_order_today);
                $('.md_order_month').html(res.md_order_month);
                $('.md_fact_today').html(res.md_fact_today);
                $('.md_fact_month').html(res.md_fact_month);
                $('.md_avg_today').html(res.md_avg_today);
                $('.md_avg_month').html(res.md_avg_month);
                $('.md_zjs_order_today').html(res.md_zjs_order_today);
                $('.md_zjs_order_month').html(res.md_zjs_order_month);
                $('.md_jd_today').html(res.md_jd_today);
                $('.md_jd_month').html(res.md_jd_month);
                $('.md_order_rate_today').html(res.md_order_rate_today);
                $('.md_order_rate_month').html(res.md_order_rate_month);
            }
        }
    })
    //推广网销
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/tuiWang',
        success: function (res) {
            if (res) {
                $('.wx_order_today').html(res.wx_order_today);
                $('.wx_order_month').html(res.wx_order_month);
                $('.wx_fact_today').html(res.wx_fact_today);
                $('.wx_fact_month').html(res.wx_fact_month);
                $('.wx_avg_today').html(res.wx_avg_today);
                $('.wx_avg_month').html(res.wx_avg_month);
                $('.wx_mkz_today').html(res.wx_mkz_today);
                $('.wx_mkz_month').html(res.wx_mkz_month);
                $('.wx_jd_today').html(res.wx_jd_today);
                $('.wx_jd_month').html(res.wx_jd_month);
                //$('.wx_tel_today').html(res.wx_tel_today);
                //$('.wx_tel_month').html(res.wx_tel_month);
                $('.wx_wechat_today').html(res.wx_wechat_today);
                $('.wx_wechat_month').html(res.wx_wechat_month);
                $('.wx_zh_today').html(res.wx_zh_today);
                $('.wx_zh_month').html(res.wx_zh_month);
                $('.wx_order_rate_today').html(res.wx_order_rate_today);
                $('.wx_order_rate_month').html(res.wx_order_rate_month);
                $('.wx_order2_rate_today').html(res.wx_order2_rate_today);
                $('.wx_order2_rate_month').html(res.wx_order2_rate_month);
                $('.wx_order_cost_today').html(res.wx_order_cost_today);
                $('.wx_order_cost_month').html(res.wx_order_cost_month);
                $('.roi_today').html(res.roi_today);
                $('.roi_month').html(res.roi_month);
            }
        }
    })
    //转介绍情况
    $.ajax({
        type: 'POST',
        url: '/crm/juzi/zjsInfo',
        success: function (res) {
            if (res) {
                $('.zjs_order_today').html(res.zjs_order_today);
                $('.zjs_order_month').html(res.zjs_order_month);
                $('.zjs_fact_today').html(res.zjs_fact_today);
                $('.zjs_fact_month').html(res.zjs_fact_month);
                $('.zjs_avg_today').html(res.zjs_avg_today);
                $('.zjs_avg_month').html(res.zjs_avg_month);

                $('.zjs_mkz_today').html(res.zjs_mkz_today);
                $('.zjs_mkz_month').html(res.zjs_mkz_month);
                $('.zjs_jd_today').html(res.zjs_jd_today);
                $('.zjs_jd_month').html(res.zjs_jd_month);
                $('.zjs_mkz_order_rate_today').html(res.zjs_mkz_order_rate_today);
                $('.zjs_mkz_order_rate_month').html(res.zjs_mkz_order_rate_month);
                $('.zjs_order_rate_today').html(res.zjs_order_rate_today);
                $('.zjs_order_rate_month').html(res.zjs_order_rate_month);
            }
        }
    })
})
function replace_all(str,tag,rep){
    var re = new RegExp(tag,"g"); //定义正则表达式
//第一个参数是要替换掉的内容，第二个参数"g"表示替换全部（global）。
    var Newstr = str.replace(re,rep);
    return Newstr;
}