puzhibing
2023-10-08 22199bbdda579861736420fe26c2873ab0f5d21c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
 
var simple_ajax = function( url, params, callback, errorCallback) {
    (new $ax(Feng.ctxPath + url, function (data) {
        callback && callback( data);
    }, function (data) {
        errorCallback ? errorCallback( data) : (Feng.error("失败!" + data.responseJSON.message + "!"))
    })).setData( params).start();
}
var TBlackBoard = {
    /* 统计数据 */
    num_map_100: [
        { title: "注册人数", field: "userNum", unit: ""},
        { title: "认证用户数", field: "checkNum", unit: ""},
        { title: "商家申请数", field: "merchantNum", unit: ""}
    ],
    /* 商家数据 */
    num_map_101: [
        { title: "总数", field: "allBusinessNum", unit: ""},
        { title: "旗舰店商家", field: "superVipNum", unit: ""},
        { title: "会员商家", field: "vipNum", unit: ""},
        { title: "普通商家", field: "businessesNum", unit: ""}
    ],
    /* 商品数据 */
    num_map_102: [
        { title: "总数", field: "goodsTotalNum", unit: ""},
        { title: "商城商品", field: "goodsNum", unit: ""},
        { title: "米粒商城商品", field: "riceGoodsNum", unit: ""}
    ],
    /* 订单数据 */
    num_map_103: [
        { title: "总数", field: "orderTotalNum", unit: ""},
        { title: "商城订单", field: "orderNum", unit: ""},
        { title: "米粒商城订单", field: "riceOrderNum", unit: ""}
    ],
    /* 交易额 */
    num_map_104: [
        { title: "交易额", field: "mallMoney", unit: ""},
        { title: "米粒商城交易额", field: "riceMoney", unit: ""}
    ],
    /* 币值总值 */
    num_map_105: [
        { title: "米粒总量", field: "riceValueAll", unit: ""},
        { title: "贡献值总量", field: "contributionScoreAll", unit: ""},
        { title: "分红股总量", field: "bonusSharesAll", unit: ""},
        { title: "分红金额", field: "shareMoneyAll", unit: ""}
    ],
    /* 平台收入 */
    num_map_106: [
        { title: "手续费提现收入", field: "withdrawalMoney", unit: "元"},
        { title: "商家手续费收入", field: "merchantServiceMoney", unit: "元"},
        { title: "米粒收入", field: "riceFeeAll", unit: "米粒"}
    ],
    card_$el: function ( val) {
        return '' +
            '<div class="col-sm-4 col-md-3" style="padding: 20px;">' +
            '   <div class="ibox float-e-margins" style="border: 1px solid #ccc">' +
            '      <div class="ibox-content notice-1">' +
            '         <h3>' + (val.title) + '</h3>' +
            '         <h2 class=" text-navy" style="margin-top:30px; margin-left: 30px">' + (val.front||'') + (val.value||0) + '</h2>' +
            '         <h5 style="text-align: right;">' + (val.unit) + '</h5>' +
            '      </div>' +
            '   </div>' +
            '</div>';
    },
 
    init_card: function ( map, $id) {
        var opera = TBlackBoard;
        $("#" + $id).empty()
            .append(opera[ $id].map(function (item) {
                item.value = map[ item.field];
                return opera.card_$el( item);
            }));
    },
    loading: function ( params) {
        /* 今日数据 */
        simple_ajax( "/indexReport/getData", (params||{}), function (data) {
            TBlackBoard.init_card( data, "num_map_100");
            TBlackBoard.init_card( data, "num_map_101");
            TBlackBoard.init_card( data, "num_map_102");
            TBlackBoard.init_card( data, "num_map_103");
            TBlackBoard.init_card( data, "num_map_104");
            TBlackBoard.init_card( data, "num_map_105");
            TBlackBoard.init_card( data, "num_map_106");
        });
    },
 
    /* eCharts 部分 */
    def_chart_list: [
        { id:"char_uid_1", title: "注册人数", url: { 1: "/indexReport/getRegisterUserCount"}},
        { id:"char_uid_2", title: "认证用户数", url: {1: "/indexReport/getCheckUserCount"}},
        { id:"char_uid_3", title: "商家数", url: { 1: "/indexReport/getMerchantCount"}},
        { id:"char_uid_4", title: "贡献值奖励", url: { 1: "/indexReport/getContributionNum"}},
        { id:"char_uid_5", title: "米粒奖励", url: { 1: "/indexReport/getRiceNum"}},
        { id:"char_uid_6", title: "分红股", url: { 1: "/indexReport/getBonusSharesNum"}},
        { id:"char_uid_7", title: "分红金额", url: { 1: "/indexReport/getShareMoneyNum"}},
        { id:"char_uid_8", title: "手续费提现收入", url: { 1: "/indexReport/getWithodMoneyNum"}},
        { id:"char_uid_9", title: "商家手续费", url: { 1: "/indexReport/getMerchantServiceMoneyNum"}},
        { id:"char_uid_10", title: "米粒收入", url: { 1: "/indexReport/getRiceFeeAllNum"}}
    ],
    def_char_date_limit: [
        { name: "近7天", url_index: 1, params: { timeSpan: "DAY_7"}, field: { key: "day", value: "num"}},
        { name: "近30天", url_index: 1, params: { timeSpan: "DAY_30"}, field: { key: "day", value: "num"}},
        { name: "季度", url_index: 1, params:  { timeSpan: "QUARTERLY_1"}, field: { key: "month", value: "num"}},
        { name: "本年", url_index: 1, params:  { timeSpan: "THIS_YEAR"}, field: { key: "month", value: "num"}}
    ],
    refresh_chart: function ( item, data) {
        // 绘制图表。
        echarts.init(document.getElementById(item.id)).setOption({
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: Object.keys(data || {})
            },
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            yAxis: { type: 'value' },
            series: [{
                data: Object.keys( data||{}).map(function(k) { return data[k]}),
                type: 'line'
            }]
        });
    },
    loading_chart: function ( item) {
        var url = item.url + "?";
        for (var key in item.params) { url += "&" + key + "=" + item.params[ key]; }
        simple_ajax( url , {}, function (data) {
            TBlackBoard.refresh_chart( item, data);
        });
    },
    chart_nav_list: function () {
        var nav_list = [];
        TBlackBoard.def_chart_list.forEach(function (val, index) {
            var $el = $( '<li class="chart-nav-li"><a href="javascript:void(0);"></a></li>');
            $el.find( "a").text( val.title);
 
            $el.on( "click", function () {
                $( "li.chart-nav-li").removeClass( "active");
                $( this).addClass( "active");
                TBlackBoard.init_chart_content( val);
            });
            nav_list.push( $el);
        });
        nav_list[0].trigger( "click");
        return nav_list;
    },
    init_chart_content: function ( item) {
        var $el_group = $('<div class="btn-group" style="margin-top: 10px;margin-bottom: 10px;"></div>');
        $el_group.append( TBlackBoard.def_char_date_limit.map(function (val, index) {
            var $el = $('<button type="button" class="btn btn-white">' + (val.name) + '</button>');
            $el.addClass( index === 0 ? "active" : "");
            $el.on( "click", function () {
                $el_group.find( "div").remove();
                $el_group.find( "button").removeClass("active");
                $(this).addClass( "active");
                var query_item = {
                    url: item.url[ val.url_index],
                    params: val.params,
                    id: item.id,
                    field: val.field
                };
                if ( val.name === "季度") {
                    var $elem_selector = TBlackBoard.init_chart_quarter();
                    var default_val = "QUARTERLY_1";
                    $elem_selector.find( "select").val( default_val);
                    $el_group.append( $elem_selector);
                    query_item.params = $.extend( query_item.params, { timeSpan: default_val});
                    $elem_selector.find( "select").on( "change", function () {
                        query_item.params = $.extend( query_item.params, { timeSpan: $(this).val()});
                        TBlackBoard.loading_chart( query_item);
                    });
                }
                TBlackBoard.loading_chart( query_item);
            });
            return $el;
        }));
        $( "#chart_content").empty()
            .append( [ $el_group, $( "<div class='chart-content' id='"+ (item.id) +"'></div>")]);
        $el_group.find( "button:first").trigger( "click");
    },
    init_chart_quarter: function () {
        return $('' +
            '<div>' +
            '   <select class="form-control">' +
            '       <option value="QUARTERLY_1">第一季度</option>' +
            '       <option value="QUARTERLY_2">第二季度</option>' +
            '       <option value="QUARTERLY_3">第三季度</option>' +
            '       <option value="QUARTERLY_4">第四季度</option>' +
            '   </select>' +
            '</div>');
    },
    init_chart: function () {
        var navList = TBlackBoard.chart_nav_list();
        $("#chart_tabs").empty().append( navList);
    }
};