/**
 * Created by sff on 2018/4/2.
 */
$(function() {
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/zjsMkz',
        success: function (res) {
            if (res) {
                $('#all .zjs_mh_mkz_today').html(res.zjs_mh_mkz_today);
                $('#all .zjs_ja_mkz_today').html(res.zjs_ja_mkz_today);
                $('#all .zjs_xh_mkz_today').html(res.zjs_xh_mkz_today);
                $('#all .zjs_fz_mkz_today').html(res.zjs_fz_mkz_today);
                $('#all .zjs_jiana_mkz_today').html(res.zjs_jiana_mkz_today);
                $('#all .zjs_mh_mkz_month').html(res.zjs_mh_mkz_month);
                $('#all .zjs_qita_mkz_today').html(res.zjs_qita_mkz_today);
                $('#all .zjs_qita_mkz_month').html(res.zjs_qita_mkz_month);
                $('#all .zjs_total_mkz_today').html(res.zjs_total_mkz_today);
                $('#all .zjs_total_mkz_month').html(res.zjs_total_mkz_month);
                $('#all .zjs_ja_mkz_month').html(res.zjs_ja_mkz_month);
                $('#all .zjs_xh_mkz_month').html(res.zjs_xh_mkz_month);
                $('#all .zjs_fz_mkz_month').html(res.zjs_fz_mkz_month);
                $('#all .zjs_jiana_mkz_month').html(res.zjs_jiana_mkz_month);
                var jkChart = echarts.init(document.getElementById('jkChart'));
                // 指定图表的配置项和数据
                var option = {
                    color: ['#ffe168', '#ff9558', '#d1f342', '#f95c50', '#6dffe8', '#56d1ff'],
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b}: {c}<br/> ({d}%)"
                    },
                    legend: {
                        orient: 'horizontal',
                        data: ['静安店', '闵行店', '徐汇店', '蜂巢基地', '嘉娜基地', '其他'],
                        textStyle: {
                            fontSize: 12,
                            color: '#fff'
                        },
                        itemWidth: 20,
                        itemHeight: 12,
                        padding: [0, 10]
                    },
                    series: [{
                        name: '本日累计',
                        type: 'pie',
                        selectedMode: 'single',
                        radius: [0, '37%'],
                        label: {
                            normal: {
                                position: 'inner',
                                formatter: '{c}',
                                color: '#104078',
                                fontSize: '13'
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data: [
                            { value: res.zjs_ja_mkz_today, name: '静安店' },
                            { value: res.zjs_ja_mkz_today, name: '闵行店' },
                            { value: res.zjs_xh_mkz_today, name: '徐汇店' },
                            { value: res.zjs_fz_mkz_today, name: '蜂巢基地' },
                            { value: res.zjs_jiana_mkz_today, name: '嘉娜基地' },
                            { value: res.zjs_qita_mkz_today, name: '其他' }
                        ]
                    },
                        {
                            name: '本月累计',
                            type: 'pie',
                            radius: ['43%', '52%'],
                            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: res.zjs_ja_mkz_month, name: '静安店' },
                                { value: res.zjs_ja_mkz_month, name: '闵行店' },
                                { value: res.zjs_xh_mkz_month, name: '徐汇店' },
                                { value: res.zjs_fz_mkz_month, name: '蜂巢基地' },
                                { value: res.zjs_jiana_mkz_month, name: '嘉娜基地' },
                                { value: res.zjs_qita_mkz_month, name: '其他' }
                            ]
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                jkChart.setOption(option);
            }
        }
    })
    //日转介绍情况
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/mdZjsToday',
        success: function (res) {
            if (res) {
                $('#md_today .mh_order_today').html(res.mh_order_today);
                $('#md_today .ja_order_today').html(res.ja_order_today);
                $('#md_today .xh_order_today').html(res.xh_order_today);
                $('#md_today .zjs_mh_order_today').html(res.zjs_mh_order_today);
                $('#md_today .zjs_ja_order_today').html(res.zjs_ja_order_today);
                $('#md_today .zjs_xh_order_today').html(res.zjs_xh_order_today);
                $('#md_today .zjs_mh_mkz_today').html(res.zjs_mh_mkz_today);
                $('#md_today .zjs_ja_mkz_today').html(res.zjs_ja_mkz_today);
                $('#md_today .zjs_xh_mkz_today').html(res.zjs_xh_mkz_today);
                $('#md_today .mh_mkz_order_today').html(res.mh_mkz_order_today);
                $('#md_today .ja_mkz_order_today').html(res.ja_mkz_order_today);
                $('#md_today .xh_mkz_order_today').html(res.xh_mkz_order_today);
                $('#md_today .zjs_mh_mkz_order_today').html(res.zjs_mh_mkz_order_today);
                $('#md_today .zjs_ja_mkz_order_today').html(res.zjs_ja_mkz_order_today);
                $('#md_today .zjs_xh_mkz_order_today').html(res.zjs_xh_mkz_order_today);
            }
        }
    })
    //月转介绍情况
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/mdZjsMonth',
        success: function (res) {
            if (res) {
                $('#md_month .mh_order_month').html(res.mh_order_month);
                $('#md_month .ja_order_month').html(res.ja_order_month);
                $('#md_month .xh_order_month').html(res.xh_order_month);
                $('#md_month .zjs_mh_order_month').html(res.zjs_mh_order_month);
                $('#md_month .zjs_ja_order_month').html(res.zjs_ja_order_month);
                $('#md_month .zjs_xh_order_month').html(res.zjs_xh_order_month);
                $('#md_month .zjs_mh_mkz_month').html(res.zjs_mh_mkz_month);
                $('#md_month .zjs_ja_mkz_month').html(res.zjs_ja_mkz_month);
                $('#md_month .zjs_xh_mkz_month').html(res.zjs_xh_mkz_month);
                $('#md_month .mh_mkz_order_month').html(res.mh_mkz_order_month);
                $('#md_month .ja_mkz_order_month').html(res.ja_mkz_order_month);
                $('#md_month .xh_mkz_order_month').html(res.xh_mkz_order_month);
                $('#md_month .zjs_mh_mkz_order_month').html(res.zjs_mh_mkz_order_month);
                $('#md_month .zjs_ja_mkz_order_month').html(res.zjs_ja_mkz_order_month);
                $('#md_month .zjs_xh_mkz_order_month').html(res.zjs_xh_mkz_order_month);
                var mdZjsChart1 = echarts.init(document.getElementById('mdZjsChart1'));
                // 指定图表的配置项和数据
                var mdZjsOption1 = {
                    color: ['#57e9ff'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    grid: {
                        top: '3%',
                        left: '8%',
                        right: '8%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        data: ['静安店', '闵行店', '徐汇店'],
                        axisTick: {
                            alignWithLabel: true
                        },
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        }
                    }],
                    yAxis: [{
                        type: 'value',
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        }
                    }],
                    series: [{
                        name: '本日数据',
                        type: 'bar',
                        barWidth: '30%',
                        data: [replace_all(res.ja_order_month.toString(),',',''),replace_all(res.mh_order_month.toString(),',',''),replace_all(res.xh_order_month.toString(),',','')]
                    }]
                };

                // 使用刚指定的配置项和数据显示图表。
                mdZjsChart1.setOption(mdZjsOption1);
            }
        }
    })

    //基地日转介绍情况
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/zjsJdToday',
        success: function (res) {
            if (res) {
                $('#jd_today .ps_fz_order_today').html(res.ps_fz_order_today);
                $('#jd_today .ps_jiana_order_today').html(res.ps_jiana_order_today);
                $('#jd_today .zjs_fz_order_today').html(res.zjs_fz_order_today);
                $('#jd_today .zjs_jiana_order_today').html(res.zjs_jiana_order_today);
                $('#jd_today .zjs_fz_mkz_today').html(res.zjs_fz_mkz_today);
                $('#jd_today .zjs_jiana_mkz_today').html(res.zjs_jiana_mkz_today);
                $('#jd_today .fz_mkz_order_today').html(res.fz_mkz_order_today);
                $('#jd_today .jiana_mkz_order_today').html(res.jiana_mkz_order_today);
                $('#jd_month .zjs_fz_order_day').html(res.zjs_fz_order_today);
                $('#jd_month .zjs_jiana_order_day').html(res.zjs_jiana_order_today);
                $('#jd_today .zjs_fz_mkz_order_today').html(res.zjs_fz_mkz_order_today);
                $('#jd_today .zjs_jiana_mkz_order_today').html(res.zjs_jiana_mkz_order_today);
            }
        }
    })
    //基地月转介绍情况
    $.ajax({
        type: 'POST',
        // data: {brandclass_id:brandclass_id},
        url: '/crm/juzi/zjsJdMonth',
        success: function (res) {
            if (res) {
                $('#jd_month .ps_fz_order_month').html(res.ps_fz_order_month);
                $('#jd_month .ps_jiana_order_month').html(res.ps_jiana_order_month);
                $('#jd_month .zjs_fz_mkz_month').html(res.zjs_fz_mkz_month);
                $('#jd_month .zjs_jiana_mkz_month').html(res.zjs_jiana_mkz_month);
                $('#jd_month .fz_mkz_order_month').html(res.fz_mkz_order_month);
                $('#jd_month .jiana_mkz_order_month').html(res.jiana_mkz_order_month);
                $('#jd_month .zjs_fz_order_month').html(res.zjs_fz_order_month);
                $('#jd_month .zjs_jiana_order_month').html(res.zjs_jiana_order_month);
                $('#jd_month .zjs_fz_mkz_order_month').html(res.zjs_fz_mkz_order_month);
                $('#jd_month .zjs_jiana_mkz_order_month').html(res.zjs_jiana_mkz_order_month);
                // 【 基地 — 月转介绍情况 】
                var jdZjsChart1 = echarts.init(document.getElementById('jdZjsChart1'));
                // 指定图表的配置项和数据
                var jdZjsOption1 = {
                    color: ['#57e9ff'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    grid: {
                        top: '3%',
                        left: '8%',
                        right: '8%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        data: ['蜂巢基地', '嘉娜基地'],
                        axisTick: {
                            alignWithLabel: true
                        },
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        }
                    }],
                    yAxis: [{
                        type: 'value',
                        axisLine: {
                            lineStyle: {
                                color: '#fff',
                                width: 1
                            }
                        }
                    }],
                    series: [{
                        name: '本月数据',
                        type: 'bar',
                        barWidth: '20%',
                        data: [replace_all(res.zjs_fz_order_month.toString(),',',''),replace_all(res.zjs_jiana_order_month.toString(),',','')]
                    }]
                };

                // 使用刚指定的配置项和数据显示图表。
                jdZjsChart1.setOption(jdZjsOption1);
            }
        }
    })




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