vproto.js 34.5 KB
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 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
import Vue from 'vue'
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
import i18n from '../assets/i18n/i18n'
import cookie from 'js-cookie'
// import echarts from 'echarts'
import echarts from '@/third-party/echart_lib'
import Heatmapjs from 'heatmap.js'
import http from '../api/base'
import { Message } from 'element-ui'

/**
 * 获取本周时间[开始日期, 结束日期]
 * @param {*} date
 * @param {Boolean} isEnd
 * @return {String}
 */
Vue.prototype.getWeekTime = (date, isEnd) => {
    // if (!date instanceof Object) return;
    // debugger
    if (typeof date === 'string') {
        date = new Date(Date.parse(date.replace(/\-/g, '/')));
    }
    let time = '';
    let eqNowY = date.getFullYear() === new Date().getFullYear();
    let eqNowM = date.getMonth() === new Date().getMonth();
    let eqNowD = date.getDate() === new Date().getDate();
    // elemefe 官方并未解决 firstDayOfWeek 配置有效
    const { firstDayOfWeek } = window._vionConfig
    let weekStartDay = firstDayOfWeek ? 7 - Number(firstDayOfWeek) + 1 : 0;
    if (eqNowY && eqNowM && eqNowD) {
        let weekDay = date.getDay();
        weekDay = weekDay ? weekDay : (firstDayOfWeek ? weekDay : 6);
        let transDay = weekDay ? 7 : weekDay
        transDay = (firstDayOfWeek && transDay <= firstDayOfWeek) ? 0 : weekStartDay;
        time = isEnd ?
            new Date(date.getFullYear(), date.getMonth(), date.getDate() - Number(transDay)) :
            new Date(date.getFullYear(), date.getMonth(), date.getDate() - weekDay + 1 - Number(weekStartDay));
    } else {
        time = isEnd ?
            new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 7 - Number(weekStartDay)) :
            new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1 - Number(weekStartDay));
        // time = isEnd ?
        //     new Date(date.getFullYear(), date.getMonth(), date.getDate() + 5) :
        //     new Date(date.getFullYear(), date.getMonth(), date.getDate() - 1);
    }
    return dateUnit.dateFormat(time, 'yyyy-MM-dd');
}

/**
 * 获取一年的天数
 * @param {Object|String} yearDate
 * @return {Number}
 */
Vue.prototype.getNowYearDay = (yearDate) => {
    let time = '',
        returnNum = '';
    // 判断类型
    if (typeof yearDate === 'string') {
        time = new Date(Date.parse(yearDate.replace(/\-/g, '/')));
    } else {
        time = new Date(Date.parse(yearDate));
    }
    let _year = Date.parse(time.getFullYear() + '/01/01');
    returnNum = Math.ceil((Date.parse(time) - _year) / (24 * 60 * 60 * 1000));
    // console.log(returnNum);
    return returnNum;
}

/**
 * 获取月年的开始结束日期
 * @param {Object|String} startDate
 * @param {Object|String} endDate
 * @param {String} type
 * @return {Object}
 */
Vue.prototype.unitTime = (startDate, endDate, type) => {
    if (!startDate instanceof Object && !endDate instanceof Object) {
        startDate = new Date(Date.parse(startDate.replace(/\-/g, '/')));
        endDate = new Date(Date.parse(endDate.replace(/\-/g, '/')));
    }
    let _st = '',
        _et = '';
    if (type === 'month') {
        let s_month_time = '',
            e_month_time = '';
        s_month_time = startDate.getMonth() + 1;
        e_month_time = endDate.getMonth() + 1;
        if (e_month_time != s_month_time) {
            let endDay = new Date(startDate.getFullYear(), (startDate.getMonth() + 1), 0).getDate();
            _st = new Date(startDate.setDate('01'));
            _et = new Date(startDate.setDate(endDay));
        } else {
            _st = startDate;
            _et = endDate;
        }
    } else {
        let s_year_time = '',
            e_year_time = '';
        s_year_time = startDate.getFullYear();
        e_year_time = endDate.getFullYear();
        if (e_year_time != s_year_time) {
            _st = startDate.setMonth('0');
            _st = new Date(startDate.setDate('01'));
            // 设置最后一个月;
            let lastMonth = startDate.setMonth('11');
            let lastMonthDay = new Date(startDate.getFullYear(), (startDate.getMonth() + 1), 0).getDate();
            _et = new Date(startDate.setDate(lastMonthDay));
        } else {
            _st = startDate;
            _et = endDate;
        }
    }
    return {
        'startTime': dateUnit.dateFormat(_st, 'yyyy-MM-dd'),
        'endTime': dateUnit.dateFormat(_et, 'yyyy-MM-dd')
    }
}

/**
 * 截止日期
 * @param {Object|String} endDate
 * @return {String}
 */
Vue.prototype.notOverNow = (endDate) => {
    let time = '',
        returnTime = '';
    // 判断类型
    if (typeof endDate === 'string') {
        time = Date.parse(endDate.replace(/\-/g, '/'));
    } else {
        time = Date.parse(endDate);
    }
    // 比较大小
    if (time > Date.parse(new Date())) {
        returnTime = new Date();
    } else {
        returnTime = new Date(time);
    }
    return dateUnit.dateFormat(returnTime, 'yyyy-MM-dd');
}

/**
 * 增加日期
 * @param {Object} date
 * @param {Number} addNum
 * @return {String}
 */
Vue.prototype.dayAdd = (date, addNum) => {
    if (!date instanceof Object) return;
    let computeTime = new Date(Date.parse(date) + ((addNum - 1) * 24 * 60 * 60 * 1000));
    return dateUnit.dateFormat(computeTime, "yyyy-MM-dd");
}

/**
 * 减少日期
 * @param {Object} date
 * @param {Number} reduceNum
 * @return {String}
 */
Vue.prototype.dayReduce = (date, reduceNum) => {
    if (!date instanceof Object) return;
    let computeTime = new Date(Date.parse(date) - ((reduceNum - 1) * 24 * 60 * 60 * 1000));
    return dateUnit.dateFormat(computeTime, "yyyy-MM-dd");
}

/**
 * 开始结束时间处理
 * @param {Object|String} date 
 * @param {String} timeType
 * @return {Object} 
 */
function dealTime(timeType, date) {
    if (timeType === 'week') {
        if (!date instanceof Object) {
            date = new Date(Date.parse(date.replace(/\-/g, '/')));
        }
        let eqNowY = date.getFullYear() === new Date().getFullYear();
        let eqNowM = date.getMonth() === new Date().getMonth();
        let eqNowD = date.getDate() === new Date().getDate();
        if (eqNowY && eqNowM && eqNowD) {
            // time = isEnd ?
            return {
                'startTime': dateUnit.dateFormat(date, 'yyyy-MM-dd'),
                'endTime': dateUnit.dateFormat(new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1), 'yyyy-MM-dd')
            }
        } else {
            return {
                'startTime': new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 7),
                'endTime': new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1)
            }
        }
    }
}

/**
 * 获取本地缓存
 * @param {String} type
 * @param {String|Number} key
 * @return {String}
 */
Vue.prototype.getSessionLocal = (type, key) => {
    let sessionstorage = window.sessionStorage;
    let result = '',
        localResult = '';
    result = (key || key == 0) ? sessionstorage.getItem(type + '-' + key) : sessionstorage.getItem(type);
    localResult = result ? result : '';
    return localResult;
}

/**
 * 本地缓存
 * @param {String} key
 * @param {*} value
 */
Vue.prototype.setSessionLocal = (key, value) => {
    let sessionstorage = window.sessionStorage;
    sessionstorage.setItem(key, value);
}

/**
 * 表格导出
 * @param {*} domId 
 * @param {*} fileName 
 */
Vue.prototype.dealExport = (domId, fileName) => {
    let fix = document.querySelector('.el-table__fixed'),wb;
    if(fix){
       wb = XLSX.utils.table_to_book(document.querySelector('#' + domId).removeChild(fix), { raw: true });
       document.querySelector('#' + domId).appendChild(fix);
    }else{
        wb = XLSX.utils.table_to_book(document.getElementById(domId), { raw: true });   // dateNF: 'General'
    }

    let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
    let _fileName = fileName + '.xlsx';
    try {
        FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), _fileName)
    } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
    return wbout;
},
/**
 * 获取dom样式
 * @param {String} element
 * @param {String} styleAttr
 * @return {Number}
 */
Vue.prototype.getStyleFn = (ele, styleAttr) => {
    let styleNum = null;
    // try {
    styleNum = Number(window.getComputedStyle(document.querySelector(ele))[styleAttr].replace(/[a-z]/g, ''));
    // } catch (error) {}
    return styleNum;
}

/**
 * 限定区间值
 * @param {String | Number} val 当前值
 * @param {String | Number} min 所有值中最小
 * @param {String | Number} max 所有值中最大
 * @param {String | Number} limitMin    限制最小值
 * @param {String | Number} limitMax    限制最大值
 * @return {String | Number}
 */
Vue.prototype.calcSymbol = (val, min, max, limitMin, limitMax) => {
    let nomalVal = (val - min) / (max - min) * (limitMax - limitMin) + limitMin;
    return nomalVal;
}

/**
 * 禁用滚动条
 * @param {Boolean} isShow
 */
Vue.prototype.overflowBar = (isShow) => {
    if (isShow) {
        document.body.style.overflow = 'auto';
    } else {
        document.body.style.overflow = 'hidden';
    }
}

Vue.prototype.i18nFormatter = (title) => {
    if (title) {
        let languageTitle = 'echartsTitle.' + title;
        return i18n.t(languageTitle);
    }
}

/**
 * 检测类型
 * @param {*} value 
 */
Vue.prototype.toRawType = (value) => {
    let _toString = Object.prototype.toString;
    return _toString.call(value).slice(8, -1);
}

/**
 * 获取Windows高度
 * @param {String} unit 
 */
Vue.prototype.computedWinH = (unit) => {
    let contentMaxHeight = '';
    let winH = $(window).height()
        ,scale = 0.28;
    if(winH <= 720) {
        scale = 0.35
    }else if (winH <= 768) {
        scale = 0.33
    } else if (winH <= 900) {
        scale = 0.28
    } else if (winH <= 1080) {
        scale = 0.31
    }
    contentMaxHeight = winH - winH * scale;
    return unit ? contentMaxHeight + unit : contentMaxHeight;
}

/**
 * 深度拷贝对象
 */
Vue.prototype.deepCopyObject = () => {
    let args = Array.prototype.slice.call(arguments);
    if (args.length === 0) {
        console.error('extends params is undefined')
        return {};
    }
    if (args.length === 1) {
        return args[0]
    }
    //要合并的目标对象
    let target = args[0];
    //要合并的内容 
    let sources = args.slice(1, args.length)

    if (!isObject(target) && !isArray(target)) {
        target = {};
    }
    sources.map(function (item) {
        //防止死循环
        if (target === item) {
            return false;
        }
        //如果内容是对象 
        if (isObject(item)) {
            //开始遍历
            for (let key in item) {
                //如果内容是对象
                if (isObject(item[key])) {
                    //修正数据
                    target[key] = (target[key] && isObject(target[key])) ? target[key] : {};
                    target[key] = extend(target[key], item[key])
                } else if (isArray(item[key])) {
                    //修正数据
                    target[key] = (target[key] && isArray(target[key])) ? target[key] : [];
                    target[key] = extend(target[key], item[key])
                } else {
                    //基本类型直接赋值
                    target[key] = item[key]
                }
            }
        } else if (isArray(item)) {
            for (let i = 0; i < item.length; i++) {
                //如果内容是对象
                if (isObject(item[i])) {
                    //修正数据
                    target[i] = (target[i] && isObject(target[i])) ? target[i] : {}
                    target[i] = extend(target[i], item[i])
                } else if (isArray(item[i])) {
                    //修正数据
                    target[i] = (target[i] && isArray(target[i])) ? target[i] : [];
                    target[i] = extend(target[i], item[i])
                } else {
                    //基本类型直接赋值
                    target[i] = item[i]
                }
            }
        }
        //其他类型直接忽略  
    })
    return target
}

Vue.prototype.removeCookies = function(){
    let cookieInfo = cookie.get();
    for(let k in cookieInfo) {
        cookie.remove(k);
	}
}

Vue.prototype.newDateFormat = function(dateType,date) {
    let formatDate = {},startTime,endTime;
    if(date) {
        if(dateType == 'day'){
            let regex = /(\d)+\-(\d)+\-(\d)+/
            if(regex.test(date)){
                formatDate.startTime = date;
                formatDate.endTime = date;
            }else{
                let time = dateUnit.dateFormat(date, 'yyyy-MM-dd');
                formatDate.startTime = time;
                formatDate.endTime = time;
            }
        }else if(dateType == 'week'){
            formatDate.startTime = this.getWeekTime(date, false)
            formatDate.endTime = this.getWeekTime(date, true)
        }else if(dateType == 'month') {
            if (date.getMonth() === new Date().getMonth() && date.getFullYear() === new Date().getFullYear()) {
                endTime = dateUnit.dateFormat(date, 'yyyy-MM-dd');
                startTime = dateUnit.dateFormat(new Date(Date.parse(date.getFullYear() + '/' + (date.getMonth() + 1) + '/01')), 'yyyy-MM-dd');
                if(startTime == endTime) {
                    endTime = dateUnit.dateFormat(new Date(), 'yyyy-MM-dd');
                }
                formatDate.startTime = startTime;
                formatDate.endTime = endTime;
            } else {
                startTime = date;
                endTime = new Date(Date.parse(this.dayAdd(date, 31).replace(/\-/, '/')));
                formatDate = this.unitTime(startTime, endTime, 'month');
            }
        }else if(dateType == 'year') {
            if (date.getFullYear() === new Date().getFullYear()) {
                endTime = dateUnit.dateFormat(date, 'yyyy-MM-dd');
                startTime = dateUnit.dateFormat(new Date(Date.parse(date.getFullYear() + '/01/01')), 'yyyy-MM-dd');
                if(startTime == endTime) {
                    endTime = dateUnit.dateFormat(new Date(), 'yyyy-MM-dd');
                }
                formatDate.startTime = startTime;
                formatDate.endTime = endTime;
            } else {
                startTime = date;
                endTime = new Date(Date.parse(this.dayAdd(date, 365).replace(/\-/, '/')));
                formatDate = this.unitTime(startTime, endTime, 'year');
            }
        }else if(dateType == 'custom'){
            formatDate.startTime = date[0];
            formatDate.endTime = date[1];
        }else {
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            formatDate.startTime = `${year}-01-01`;
            let lastDay = new Date(year,month,0);
            formatDate.endTime = dateUnit.dateFormat(lastDay, 'yyyy-MM-dd')
        }
        return formatDate
    }else{
        date = new Date();
        return this.newDateFormat(dateType,date);
    }
}
Vue.prototype.getItemName = function(array, val, asisLevel) {
    if(typeof(val) == 'string') { 
        if(val.indexOf(',') != -1) {
            return this.$t('title.' + (asisLevel || this.asisLevel))
        }
    }
    let firstItem = typeof(val) == 'object' ? val.split(',')[0] : Number(val);
    let filterName = array.find(item => item.id == firstItem)
    return filterName && filterName.name || '';
}
// 路由跳转日周月年自定义
Vue.prototype.routerJump = function(oneRouter, twoRouter ,emitData) {
    let router = `/${oneRouter}/${twoRouter}/${(emitData.asis_date == 'day' ? 'daily' : emitData.asis_date + 'ly')}`;
    let propParams = {
        dateType: `/${twoRouter}/${(emitData.asis_date == 'day' ? 'daily' : emitData.asis_date + 'ly')}`,
        data: emitData
    };
    let result = {
        router: router,
        params: propParams,
    }
    return result;
}
// 获取语言
Vue.prototype.datePickerFormatter = function(dateType) {
    let lang = localStorage.getItem('lang') || 'zh_CN'
        , dateFormatterText = ''
    
    if (dateType === 'week') {
        dateFormatterText = (lang === 'zh_CN' || lang === 'mall_CN')
            ? 'yyyy 第 WW 周'
            : lang === 'zh_TW'
                ? 'yyyy 第 WW 週'
                : 'Week WW, yyyy'
    } else if (dateType === 'month') {
        dateFormatterText = (lang === 'zh_CN' || lang === 'mall_CN')
            ? 'yyyy 年 MM 月'
            : 'MM, yyyy'
    } else {
        dateFormatterText = (lang === 'zh_CN' || lang === 'mall_CN') ? 'yyyy 年' : 'In yyyy'
    }

    return dateFormatterText
}
//处理表格数据
var secondLabel = null
Vue.prototype.autoComplateHead = function(reportType,headData = []) {
    let asisOrgName = [], defaultHead = [];
    headData.forEach((k, index) => {
        defaultHead.push({
            prop: 'defaultOrg' + index,
            label: k
        })
    })
    return defaultHead;
}
Vue.prototype.dealData = function(data = [], headData = [], isAverandASum, rowLen) {
    let obj = {}, arr = [], _prop = '',sums = 0,status = 0;
    secondLabel = headData.length > 1 && headData[1].label;
    let dataKey = secondLabel == '星期' || secondLabel == 'Week' ?  'defaultOrg1' : ' '
    data.forEach(item => {
        sums = 0
        status = 0
        if (item.data.length < headData.length) {
            for (let i = 0, len = headData.length; i < len; i++) {
                _prop = headData[i].prop;
                obj[_prop] = (item.data[i] || item.data[i] == 0) ? item.data[i] : '--';
                if(isAverandASum) {
                    obj.sums = '--';
                    obj.averageVal = '--';
                    if(_prop!='defaultOrg0' && _prop != dataKey && obj[_prop].constructor == Number){
                        status = 1
                        sums += Number(obj[_prop])
                    }
                }
            }
        } else {
            for (let i = 0, len = item.data.length; i < len; i++) {
                _prop = headData[i].prop;
                obj[_prop] = (item.data[i] || item.data[i] == 0) ? item.data[i] : '--';
                if(isAverandASum) {
                    obj.sums = '--';
                    obj.averageVal = '--';
                    if(_prop!='defaultOrg0' && _prop != dataKey && obj[_prop].constructor == Number){
                        status = 1
                        sums += Number(obj[_prop])
                    }
                }
            }
        }
        if(isAverandASum) {
            if (sums != 0 || status != 0) {
                obj.sums = sums;
                let averageNums = sums/(dataKey == ' ' ? rowLen - 1 : rowLen - 2);
                obj.averageVal = averageNums == 0 ? averageNums : Math.round(averageNums * 100) / 100;
            }
        }
        arr.push(obj);
        obj = {};
    })
    return arr;
},
Vue.prototype.computeData = function(data) {
    let obj = {}, object = {},columnLen = 0;
    let dataKey = secondLabel == '星期' || secondLabel == 'Week' ?  'defaultOrg1' : ' '
        if(data.length) {
            for(var key in data[0]){
                if(key == 'defaultOrg0'){
                    obj[key]= this.$t('table.total')
                }else if(key === dataKey){
                    obj[key]='--'
                }else{
                    if(obj[key]){
                        obj[key]+=data[0][key]
                    }else{
                        obj[key]=0;
                    }
                }
            }
            data.map((v,i)=>{
                columnLen = columnLen+1;
                for(var j in v){
                    if(!isNaN(Number(obj[j])) && !isNaN(Number(v[j]))) {
                            obj[j] += Number(Math.round(v[j] * 100) / 100);      
                        }
                }
            });
            for(var j in obj){
                if(j == 'defaultOrg0') {
                    object[j] = this.$t('table.average')
                }else if(j == dataKey){
                    object[j] = '--'
                } else {
                    object[j] = Number(Math.round(obj[j]/columnLen*100) / 100);
                }
            }
            obj.averageVal = (obj.averageVal && typeof obj.averageVal === 'number') ? (obj.averageVal).toFixed(2) : obj.averageVal;
            data.push(object)
            data.push(obj)
        }
        return data
},
Vue.prototype.removeStorge = (key) => {
    for(let i in window.localStorage) {
        if(i == 'lang' || i == 'oldAlarm' || i == 'webVersion'){
            
        }else{
            window.localStorage.removeItem(i);
        }
    }
    // for(let i in window.sessionStorage) {
    //     window.sessionStorage.removeItem(i);
    // }
    window.sessionStorage.clear()
    let cookieInfo = cookie.get();
    for(let k in cookieInfo) {
        cookie.remove(k);
    }
},
Vue.prototype.getCommonMalls = () => {
    return new Promise((resolve,reject) =>{
        let mallData = [],titleName = '',localMallId,localMultiMallId,multiMallId = [];
        http.mall({
            accountId: cookie.get('accountId'),
            status: 1,
        })
        .then(res => {
            let result = res.data;
            localMallId = window.sessionStorage.getItem('mallId');
            localMultiMallId = window.sessionStorage.getItem('multiMallId') ? JSON.parse(window.sessionStorage.getItem('multiMallId')) : [];
            localMallId = localMallId ? Number(localMallId) : false;
            if(result.data.length >= 0) {
                result.data.forEach((item,index) => {
                    mallData.push(item)
                    if(localMallId) {
                        if(item.id == localMallId) {
                            titleName = item.name;
                        }
                    }
                    if(localMultiMallId.length === 0) {
                        if(index < 5) {
                            multiMallId.push(item.id);
                        }
                    }
                })
            }
            localMallId = titleName ? localMallId : mallData[0].id;
            titleName = titleName ? titleName : mallData[0].name;
            multiMallId = multiMallId.length === 0 ? localMultiMallId : multiMallId;
            if (localMallId && multiMallId.indexOf(localMallId) === - 1) {
                multiMallId.unshift(localMallId)
            }
            let thisData = {
                'mallData': mallData,
                'localMallId': localMallId,
                'titleName': titleName,
                'multiMallId': multiMallId,
            }
            resolve(thisData)
        })
        .catch(err => {})
    })
},
Vue.prototype.zoneFilterMall = (params,zoneType) => {
    return new Promise((resolve,reject) =>{
        let mallData = [],mallId = [],titleName = '', localMallId,localMultiMallId,multiMallId = [];
        http.zone(params)
        .then(res => {
            let result = res.data;
            localMallId = window.sessionStorage.getItem('mallId');
            localMallId = localMallId ? Number(localMallId) : false;
            localMultiMallId = window.sessionStorage.getItem('multiMallId') ? JSON.parse(window.sessionStorage.getItem('multiMallId')) : [];
            if(result.data.length >= 0) {
                result.data.forEach((item,index) => {
                    if(item.type === zoneType && (!mallId.includes(item.mallId))) {
                        let obj = {}
                        obj['name'] = item.mall.name;
                        obj['id'] = item.mallId
                        mallData.push(obj)
                        mallId.push(item.mallId)
                        if(localMallId) {
                            if(item.mallId == localMallId) {
                                titleName = item.mall.name;
                            }
                        }
                        if(localMultiMallId.length === 0) {
                            if(index < 5) {
                                multiMallId.push(item.mallId);
                            }
                        }
                    }
                })
            }
            if (mallData.length > 0) {
                localMallId = titleName ? localMallId : mallData[0].id
                titleName = titleName ? titleName : mallData[0].name
                let thisData = {
                    'mallData': mallData,
                    'localMallId': localMallId,
                    'titleName': titleName,
                    'multiMallId': multiMallId,
                }
                resolve(thisData)
            } else {
                resolve({
                    'mallData': mallData,
                    'localMallId': '',
                    'titleName': '',
                    'multiMallId': '',
                })
                Message({
                    type: 'warning', message: i18n.t('message.notSupportFunction')
                })
            }
        })
        .catch(err => {
            Message({
                type: 'error', message: err
            })
        })
    })
},
Vue.prototype.gateFilterMall = (mallStatus,params) => {
    return new Promise((resolve,reject) =>{
        let mallData = [],mallId = [],titleName = '', localMallId,localMultiMallId,multiMallId = [];
        http.gate(params)
        .then(res => {
            let result = res.data;
            localMallId = window.sessionStorage.getItem('mallId');
            localMallId = localMallId ? Number(localMallId) : false;
            localMultiMallId = window.sessionStorage.getItem('multiMallId') ? JSON.parse(window.sessionStorage.getItem('multiMallId')) : [];
            if(result.data.length >= 0) {
                result.data.forEach((item,index) => {
                    if((!mallId.includes(item.mallId)) && mallStatus.includes(item.mallId)) {
                        let obj = {}
                        obj['name'] = item.mall.name;
                        obj['id'] = item.mallId;
                        mallData.push(obj);
                        mallId.push(item.mallId);
                        if(localMallId) {
                            if(item.mallId == localMallId) {
                                titleName = item.mall.name;
                            }
                        }
                        if(localMultiMallId.length === 0) {
                            if(index < 5) {
                                multiMallId.push(item.mallId);
                            }
                        }
                    }
                })
            }
            if (mallData.length) {
                localMallId = titleName ? localMallId : mallData[0].id
                titleName = titleName ? titleName : mallData[0].name
            } else {
                localMallId = null
            }
            let thisData = {
                'mallData': mallData,
                'localMallId': localMallId,
                'titleName': titleName,
                'multiMallId': multiMallId,
            }
            resolve(thisData);
        })
        .catch(err => { console.log(err) })
    })
},
Vue.prototype.changeHandle = (val, data) => {
    let selectAll = val.length < data.length ? false : true;
    window.sessionStorage.setItem('multiMallId', JSON.stringify(val))
    return selectAll
},
Vue.prototype.behaviorMallChange = (val, data, space) => {
    if(val instanceof Array) {
        let selectAll = val.length < data.length ? false : true;
        if(val.length <= 1) {
            window.sessionStorage.setItem('mallId',val[0]);
            window.sessionStorage.removeItem('multiMallId');
        }else{
            window.sessionStorage.setItem('multiMallId',JSON.stringify(val));
        }
        return selectAll
    }else {
        let mallName = '';
        data.forEach(item => {
            if(item.id == val) {
                mallName = space ?  item.name : item.name + ' ';
            }
        })
        window.sessionStorage.setItem('mallId',val);
        return mallName
    }
},
Vue.prototype.createDate = (addNum = 15) => {
    let dateArr = ['dayDate', 'weekDate', 'monthDate' , 'yearDate', 'customDate'], dateObj = {};
    dateArr.forEach(item => {
        if(item == 'dayDate' || item == 'customDate') {
            dateObj[item] = JSON.parse(window.sessionStorage.getItem(item));
        }else{
            dateObj[item] = window.sessionStorage.getItem(item) ? new Date(JSON.parse(window.sessionStorage.getItem(item))) : null;
        }
    })
    for(let key in dateObj) {
        if(key == 'dayDate') {
            if(!dateObj[key]) {
                dateObj[key] =  dateUnit.dateFormat(new Date(), 'yyyy-MM-dd');
            }
        }else if(key == 'customDate') {
            if(!dateObj[key]) {
                dateObj[key] = [Vue.prototype.dayReduce(new Date(), addNum), dateUnit.dateFormat(new Date(), 'yyyy-MM-dd')];
            }
        }else {
            if(!dateObj[key]) {
                dateObj[key] = new Date();
            }
        }
    }
    return dateObj
},
Vue.prototype.sessionDate = (key,val) =>{
    let dateVal = window.sessionStorage.getItem(key);
    if(dateVal != JSON.stringify(val)) {
        window.sessionStorage.setItem(key,JSON.stringify(val));
    }
},
Vue.prototype.sessionCity = (callback) => {
    let sessionCity = JSON.parse(window.sessionStorage.getItem('cityMap'));
    if(sessionCity) {
        if(callback) {
            callback(sessionCity)
            return
        }
    };
    http.city()
    .then((data) => {
        let result = data.data;
        let cityMap = {};
        result.data.forEach((item, arr, index) => {
            if(!item.cityId) {
                cityMap[item.id] = item.areaName;
            }else if(item.countyId){
                // cityMap[item.countyId] = item.areaName;
            }else {
                cityMap[item.cityId] = item.areaName;
            }
        })
        let cityStr = JSON.stringify(cityMap);
        if(callback) {
            callback(cityStr)
        }
        window.sessionStorage.setItem('cityMap', cityStr);
    })
    .catch((err) => { })
},
Vue.prototype.sessionFormat = (key, isReset) => {
    let sessionOpts = isReset ? false : JSON.parse(window.sessionStorage.getItem(key)) 
    if(sessionOpts) {
        return new Promise((resolve,reject) =>{ 
            resolve(sessionOpts);
        })
    }else{
        return new Promise((resolve,reject) =>{
            let accountId = key === 'filterFormat' ? cookie.get('accountId') : '';
            http.format(accountId).then(data => {
                let result = data.data,formatOpts = [], subFormatsOpts = [];
                result.data.forEach((item,index) => {
                    let parent = {
                        id: item.id,
                        label: item.name,
                    }
                    formatOpts.push({
                        id: item.id,
                        label: item.name,
                    });
                    if(item.subFormats) {
                        parent = Vue.prototype.dealChild(item.subFormats,parent);
                    }
                    subFormatsOpts.push(parent);
                })
                let options = {
                    format: formatOpts,
                    subFormat: subFormatsOpts
                }
                window.sessionStorage.setItem(key, JSON.stringify(options));
                resolve(options);
            })
            .catch((err) => {
            })
        })
    }
},
Vue.prototype.dealChild = (child,parent) => {
    parent.children = []
    child.forEach(item => {
        let childOfChild = {
            id: item.id,
            label: item.name,
            formatId: item.formatId
        }
        parent.children.push(childOfChild)
    })
    return parent
},
Vue.prototype.dealFormat = (params,emitData) => {
    if(emitData.asis_level === 'format' || emitData.asis_level === 'subFormat') {
        emitData.asis_formats ? params['formats'] = emitData.asis_formats.toString() : params['subFormats'] = emitData.asis_subFormats.toString();
        emitData.asis_subFormats ?  emitData.asis_level = 'subFormat' : emitData.asis_level === 'format';
    }
    return {
        'params': params,
        'asisLevel': emitData.asis_level
    }
},
Vue.prototype.animate = (wrap) => {
    setTimeout(() => {
        let headerH = '', titleH = '', collapseH = '', mt = '';
        headerH = Vue.prototype.getStyleFn('.el-header', 'height');
        titleH = Vue.prototype.getStyleFn('.analysis-wrapper .el-header', 'height');
        collapseH = Vue.prototype.getStyleFn('.analysis-option-wrapper', 'height');
        mt = headerH + titleH + collapseH + 8 + 'px';
        $(wrap).animate({ marginTop: mt });
    },0);
},
Vue.prototype.dealDate = (counttime) => {
    let date=counttime.split(' ')[0];
    let year=date.split('-')[0];
    let month=date.split('-')[1];
    let day=date.split('-')[2];
    let dateStr=year+month+day;
    return dateStr
},
Vue.prototype.dealTypeImage = (item, type) => {
    let path = type + 'Path', pic = type + 'Pic',img = '';
    if(item[path] && item[pic]){
        img = item[path] + item[pic];
    } else if(item[pic]){
        let dateStr = Vue.prototype.dealDate(item.counttime);
        img = type + '/' + dateStr + '/' +item.channelSerialnum + '/' + item[pic];
    }
    return img;
},
Vue.prototype.dealImage = (item) => {
    let img = '';
    if(item.facePath && item.facePic){
        img = item.pic = item.facePath + item.facePic;
    } else if(item.facePic){
        let dateStr = Vue.prototype.dealDate(item.counttime);
        img = 'face/' + dateStr + '/' +item.channelSerialnum + '/' +item.facePic;
    } else if(item.bodyPath && item.bodyPic){
        img = item.bodyPath + item.bodyPic;
    }else if(item.bodyPic){
        let dateStr = Vue.prototype.dealDate(item.counttime);
        img = 'body/' + dateStr + '/' +item.channelSerialnum + '/' + item.bodyPic;
    }
    return img;
}

/**
 * 捕获错误, 取消请求不提示
 * @param {object} err
 */
Vue.prototype.catchErrorHandle = (err) => {
    if (!err.__proto__.__CANCEL__) {
        Message({
            type: 'error',
            message: err.message
        })
    }
}

/**
 * 定义标注宽高
 */
Vue.prototype.normalWidth = 100;
Vue.prototype.normalHeight = 100;

// echarts
Vue.prototype.$echarts = echarts;

// cookie
Vue.prototype.$cookie = cookie;

// 文件导出
Vue.prototype.FileSaver = FileSaver;
Vue.prototype.XLSX = XLSX;

// 热力图
Vue.prototype.$heatmapjs = Heatmapjs;

//店铺层级
Vue.prototype.storeFloorVal = '';
Vue.prototype.storeLevel= 'floor';
Vue.prototype.storemutiFormatVal = [];
Vue.prototype.storemutiFormatTwoVal = [];
Vue.prototype.storeformatLevel = 1;

Vue.prototype.menuName = []

Vue.prototype.curryAvgAndSum = function curryAvgAndSum(columnCallback, rowCallback) {
    return function(...args) {
        console.log('vue prototype', this)
      const columnRes = columnCallback.apply(this, args)
      const newArgs = Object.assign({}, ...args, { data: columnRes })
      return rowCallback.call(this, newArgs)
    }
  }