WIDGET-CSH-COUNT-LINE.lview 17.5 KB
Newer Older
niminmin's avatar
niminmin committed
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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
<?xml version="1.0" encoding="UTF-8"?>

<!--
    $Author:
    $Date: 2018/8/2
    $Revision: 1.0
    CSH 年度回款/放款金额 按统计
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view template="default" package="leaf.ui.std">
        <!--单独微件测试用-->
        <!--<meta name="_csrf" content="${/session/@_csrf.token}"/>
        <meta name="_csrf_header" content="X-CSRF-TOKEN" />
        <script src="${/request/@context_path}/leafresource/js/attach/g2.min.js"></script>-->
        <style>
            html,body{
            width:840px;
            height:456px;
            margin: 0;
            padding: 0;
            }
            .widget_csh_count_line{
            box-sizing:border-box;
            width:840px;
            height:456px;
            background-color:#fff;
            position:relative;
            border:1px solid #F0F0F3;
            padding:0 88px 0 16px;
            user-select:none;
            cursor:default;
            }
            .widget_csh_count_line .widget_label{
            position:absolute;
            width:40px;
            height:4px;
            top:0;
            left:16px;
            background-color:#5A7FFF;
            }
            .widget_csh_count_line .row1{
            position:relative;
            height:20px;
            margin:16px 0 0 0;
            font-family: PingFangSC-Medium;
            font-size: 14px;
            color: rgba(75,80,90,0.85);
            letter-spacing: 0;
            line-height: 20px;
            }
            .widget_csh_count_line .row2{
            display:inline-block;
            position:relative;
            height:24px;
            margin:8px 0 0 0;
            font-family: PingFangSC-Regular;
            font-size: 12px;
            color: #5A7FFF;
            letter-spacing: 0;
            }
            .widget_csh_count_line .row2 span{
            display:inline-block;
            width:64px;
            height:24px;
            line-height:24px;
            font-family: PingFangSC-Regular;
            font-size: 12px;
            letter-spacing: 0;
            text-align: center;
            cursor:pointer;
            }
            .widget_csh_count_line .row2 input{
            display:none;
            }
            .widget_csh_count_line .row2 #widget_csh_count_line_payment{
            border-radius: 4px 0 0 4px;
            border: 1px solid #5A7FFF;
            color: #5A7FFF;
            }
            .widget_csh_count_line .row2 #widget_csh_count_line_receipt{
            border-radius:0 4px 4px 0;
            position:relative;
            left:-1px;
            border: 1px solid rgba(75,80,90,0.15);
            color: rgba(75,80,90,0.75);
            }
            .widget_csh_count_line .row2 input:checked~#widget_csh_count_line_payment {
            border-color:rgba(75,80,90,0.15);
            color:rgba(75,80,90,0.75);
            }
            .widget_csh_count_line .row2 input:checked~#widget_csh_count_line_receipt{
            border: 1px solid #5A7FFF;
            color: #5A7FFF;
            }
            .widget_csh_count_line .row3{
            position:relative;
            box-sizing:border-box;
            margin:16px 0 55px 0;
            width:100%;
            height:314px;
            border-top:1px solid #F0F0F3;
            padding-top:28px;
            }
            .widget_csh_count_line .row3 .tooltip{
            height:34px;
            }
            .widget_csh_count_line .row3 .tooltip div{
            height:17px;
            line-height:17px;
            font-family: PingFangSC-Regular;
            font-size: 12px;
            color: rgba(75,80,90,0.85);
            letter-spacing: 0;
            }
        </style>
        <script><![CDATA[
        function cshCountLoader(ds){
            var records=ds.data,
                recArr=[],
                payArr=[],
                recData=[],
                payData=[],
                curDate=new Date(),
                curYear=curDate.getFullYear(),
                curMonth=curDate.getMonth()+1;

            if(records!==null && records.length>0){
                records.forEach(function(r){
                    if(r.data["transaction_type"].toLowerCase()=='receipt'){
                        recArr[r.data["month"]]=new Array();
                        if(r.data["currency_code"]=='cny'){
                            recArr[r.data["month"]][0]=r.data["amount"];
                        }else if(r.data["currency_code"]=='usd'){
                            recArr[r.data["month"]][1]=r.data["amount"];
                        }
                    }else{
                        payArr[r.data["month"]]=new Array();
                        if(r.data["currency_code"]=='cny'){
                            payArr[r.data["month"]][0]=r.data["amount"];
                        }else if(r.data["currency_code"]=='usd'){
                            payArr[r.data["month"]][1]=r.data["amount"];
                        }
                    }
                });
            }

            //去年月份
            for(var i=curMonth+1;i<=12;i++){
                if(recArr[i]){
                    if(recArr[i][0]){
                        recData.push({
                            year:curYear-1,
                            month:i,
                            amount:recArr[i][0],
                            currency:'人民币',
                            time:curYear-1+'年'+i+'月'
                        });
                    }else{
                        recData.push({
                            year:curYear-1,
                            month:i,
                            amount:0,
                            currency:'人民币',
                            time:curYear-1+'年'+i+'月'
                        });
                    }
                    if(recArr[i][1]){
                        recData.push({
                            year:curYear-1,
                            month:i,
                            amount:recArr[i][1],
                            currency:'美元',
                            time:curYear-1+'年'+i+'月'
                        });
                    }else{
                        recData.push({
                            year:curYear-1,
                            month:i,
                            amount:0,
                            currency:'美元',
                            time:curYear-1+'年'+i+'月'
                        });
                    }
                }else{
                    recData.push({
                        year:curYear-1,
                        month:i,
                        amount:0,
                        currency:'美元',
                            time:curYear-1+'年'+i+'月'
                    });
                    recData.push({
                        year:curYear-1,
                        month:i,
                        amount:0,
                        currency:'人民币',
                            time:curYear-1+'年'+i+'月'
                    });
                };
                if(payArr[i]){
                    if(payArr[i][0]){
                        payData.push({
                            year:curYear-1,
                            month:i,
                            amount:payArr[i][0],
                            currency:'人民币',
                            time:curYear-1+'年'+i+'月'
                        });
                    }else{
                        payData.push({
                            year:curYear-1,
                            month:i,
                            amount:0,
                            currency:'人民币',
                            time:curYear-1+'年'+i+'月'
                        });
                    }
                    if(payArr[i][1]){
                        payData.push({
                            year:curYear-1,
                            month:i,
                            amount:payArr[i][1],
                            currency:'美元',
                            time:curYear-1+'年'+i+'月'
                        });
                    }else{
                        payData.push({
                            year:curYear-1,
                            month:i,
                            amount:0,
                            currency:'美元',
                            time:curYear-1+'年'+i+'月'
                        });
                    }
                }else{
                    payData.push({
                        year:curYear-1,
                        month:i,
                        amount:0,
                        currency:'美元',
                            time:curYear-1+'年'+i+'月'
                    });
                    payData.push({
                        year:curYear-1,
                        month:i,
                        amount:0,
                        currency:'人民币',
                            time:curYear-1+'年'+i+'月'
                    });
                };
            }

            //今年月份
            for(var i=1;i<=curMonth;i++){
                if(recArr[i]){
                    if(recArr[i][0]){
                        recData.push({
                            year:curYear,
                            month:i,
                            amount:recArr[i][0],
                            currency:'人民币',
                            time:curYear+'年'+i+'月'
                        });
                    }else{
                        recData.push({
                            year:curYear,
                            month:i,
                            amount:0,
                            currency:'人民币',
                            time:curYear+'年'+i+'月'
                        });
                    }
                    if(recArr[i][1]){
                        recData.push({
                            year:curYear,
                            month:i,
                            amount:recArr[i][1],
                            currency:'美元',
                            time:curYear+'年'+i+'月'
                        });
                    }else{
                        recData.push({
                            year:curYear,
                            month:i,
                            amount:0,
                            currency:'美元',
                            time:curYear+'年'+i+'月'
                        });
                    }
                }else{
                    recData.push({
                        year:curYear,
                        month:i,
                        amount:0,
                        currency:'美元',
                        time:curYear+'年'+i+'月'
                    });
                    recData.push({
                        year:curYear,
                        month:i,
                        amount:0,
                        currency:'人民币',
                        time:curYear+'年'+i+'月'
                    });
                };
                if(payArr[i]){
                    if(payArr[i][0]){
                        payData.push({
                            year:curYear,
                            month:i,
                            amount:payArr[i][0],
                            currency:'人民币',
                            time:curYear+'年'+i+'月'
                        });
                    }else{
                        payData.push({
                            year:curYear,
                            month:i,
                            amount:0,
                            currency:'人民币',
                            time:curYear+'年'+i+'月'
                        });
                    }
                    if(payArr[i][1]){
                        payData.push({
                            year:curYear,
                            month:i,
                            amount:payArr[i][1],
                            currency:'美元',
                            time:curYear+'年'+i+'月'
                        });
                    }else{
                        payData.push({
                            year:curYear,
                            month:i,
                            amount:0,
                            currency:'美元',
                            time:curYear+'年'+i+'月'
                        });
                    }
                }else{
                    payData.push({
                        year:curYear,
                        month:i,
                        amount:0,
                        currency:'美元',
                        time:curYear+'年'+i+'月'
                    });
                    payData.push({
                        year:curYear,
                        month:i,
                        amount:0,
                        currency:'人民币',
                        time:curYear+'年'+i+'月'
                    });
                };
            }

            jQuery(".widget_csh_count_line #widget_csh_count_line_transaction_type").on('change',function(e){
                //checked==true 对应 transaction_type=receipt
                //checked==false 对应 transaction_type=payment
                if(e.target.checked==true){
                    jQuery(".widget_csh_count_line .row1").text("本年回笼金额");
                    //切换数据源
                    widget_csh_count_line_chart.changeData(payData);
                }else{
                    jQuery(".widget_csh_count_line .row1").text("本年投放金额");
                    //切换数据源
                    widget_csh_count_line_chart.changeData(recData);
                }
            });

            // 关闭 G2 的体验改进计划打点请求
            G2.track(false);
            var widget_csh_count_line_chart = new G2.Chart({
              container: 'cshLineChart',
              forceFit: false,
              width:718,
              height: 300,
              padding:'auto'
            });
            widget_csh_count_line_chart.tooltip({
                showTitle: true,
                crosshairs: {
                    type: 'line'
                }
                <!--,-->
                <!--containerTpl: '<div class="g2-tooltip">'-->
                    <!--+ '<div class="g2-tooltip-title" style="margin:10px 0;">{title}</div>'-->
                    <!--+ '<ul class="g2-tooltip-list"></ul></div>',-->
                <!--itemTpl: function(name,value){-->
                    <!--console.log(name);-->
                    <!--return '<li>{name}kkk{value}</li>'-->
                <!--}()-->
            });
            widget_csh_count_line_chart.axis('amount', {
                label: {
                    formatter: function formatter(val) {
                        return $L.formatMoney(val,2);
                    }
                }
            });
            widget_csh_count_line_chart.axis('time',{
                label:{
                    formatter:function(text,item,index){
                        return text.substring(text.indexOf("年")+1);
                    }
                }
            });
            widget_csh_count_line_chart.source(recData);
            widget_csh_count_line_chart.line()
                .position(['time','amount'])
                .color('currency',['#5A7FFF','#FFD95B'])
                .size(2)
                .tooltip('month*amount*year*currency',function(month,amount,year,currency){
                    amount=$L.formatMoney(amount,2);
                    return {
                        title:year+'年'+month+'月',
                        name:currency,
                        value:amount
                    }
                });
            widget_csh_count_line_chart.point()
                .position(['time','amount'])
                .color('currency',['#5A7FFF','#FFD95B'])
                .shape('circle')
                .style({
                    stroke: '#fff',
                    lineWidth: 1
                })
                .tooltip('month*amount*year*currency',function(month,amount,year,currency){
                    amount=$L.formatMoney(amount,2);
                    return {
                        title:year+'年'+month+'月',
                        name:currency,
                        value:amount
                    }
                });
            widget_csh_count_line_chart.render();
        }
            ]]></script>
        <a:dataSets>
            <a:dataSet id="csh_count_line_ds" autoQuery="true" model="csh.CSH911.csh_count">
                <a:fields>
                    <a:field name="year"/>
                    <a:field name="month"/>
                    <a:field name="transaction_type"/>
                    <a:field name="currency_code"/>
                    <a:field name="amount"/>
                </a:fields>
                <a:events>
                    <a:event name="load" handler="cshCountLoader"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <div class="widget_csh_count_line">
            <span class="widget_label"> </span>
            <div class="row1">本年投放金额</div>
            <label class="row2" for="widget_csh_count_line_transaction_type">
                <!--用:check伪类做toggle tab的状态类转换,checked表示transaction_type=payment-->
                <input type="checkbox" id="widget_csh_count_line_transaction_type"/>
                <span id="widget_csh_count_line_payment">投放金额</span>
                <span id="widget_csh_count_line_receipt">回笼金额</span>
            </label>
            <div class="row3" id="cshLineChart"> </div>
        </div>
        <a:screenBody style="display:none"> </a:screenBody>
    </a:view>
</a:screen>