import previewRealDate from '../../utils/dateUtils'
import _ from 'lodash'
import biUtils from '../../utils/biUtils'
const previewMixins = {
    data() {
        return {
            screenItem: '', //过滤器数据
            formId: '',
            paramData: {},
            menuRes: [],
            tabMergeArr: [],
            dateRangeVal: this.$utils.getCurrentRangDate(30) +
                ' ~ ' +
                this.$utils.getTodayDate('time'),
            dataSourceUrls: [], // 整体提交的路径
            filterNatus: {}, // 处理URL在组件内部的控件 {筛选ID:[]}
            lazyPostData: {}, //处理树形懒加载参数
            tabActiveIndexObj: {}, //保存tab首次渲染的激活数：{Pid:activeIndex}
            eventSources: [], // 实时数据的路径
        }
    },
    // watch: {},
    methods: {
        refreshAllData() {
            this.screenData = []
            this.dataSourceUrls = []
            this.getScreenDataByNatureArr(this.natureArr, null)
            this.getControlData(this.natureArr, null, this.dateRangeVal)
            this.finalNatureArr = [...this.natureArr] //赋最终值
            this.$store.commit('setBiDSUrls', this.dataSourceUrls) // 保存最终预览的URL数据，以便下拉用
                // 外部请求
            this.$nextTick(() => {
                if (this.filterNatus && this.screenData) {
                    for (let screenItem of this.screenData) {
                        this.setFilterNatusParam(screenItem)
                    }
                }
            })
            this.formId = this.isFromPreview && this.oldData && this.oldData.length > 0 ? this.oldData[0].id : ''
            this.getAllPromise(this.dataSourceUrls, 'all')
            this.getAncher()
        },
        // 刷新全部页面，整体刷新
        refreshData({ dateRangeVal, isRefreshScreen, item }) {
            this.natureArr = this.$refs.gridMainLayout.layout //重新赋值
            if (item && item.type == 'tab') { // tab切换
                this.refreshDataByTab(item)
                return
            }
            if (isRefreshScreen) {
                this.refreshDataByScreen(item) // 局部刷新
                return
            }
            if (item.clickEvent == '查询' || item.clickEvent == '刷新') {
                this.refreshAllData()
                return
            }
            this.getAllPromise(this.dataSourceUrls, 'part')
            this.getAncher()
        },
        // 按需刷新tab页内的控件
        refreshDataByTab(tab) {

            this.tabActiveIndexObj[tab.id] = tab.activeIndex // 保存当前tab的激活页
            let tabDataSourceUrls = []
            for (let url of this.dataSourceUrls) {
                const item = url.item
                if (item.pType == 'tab' && item.pIndex == tab.activeIndex) {
                    tabDataSourceUrls.push(url)
                }
            }
            let tabItem = tab.tabs.find(res => res.index == tab.activeIndex) // 找到激活页
            tabItem.type = 'tab'
            this.$nextTick(() => {
                    this.setFilterNatusParam(tabItem)
                })
                // this.refreshDataByScreen(this.screenItem)
            this.getAllPromise(tabDataSourceUrls, 'part')
        },
        //通过筛选刷新数据，局部刷新
        refreshDataByScreen(screenItem) {
            this.screenItem = screenItem
            let temporyparams = screenItem.noDate ? { orgIds: screenItem.area } : (screenItem.noArea ? { endDate: screenItem.end, beginDate: screenItem.start } : { orgIds: screenItem.area, endDate: screenItem.end, beginDate: screenItem.start })
            this.$store.commit("setparams", temporyparams)
            let dataSourceUrlsByScreen = []
            if (screenItem) {
                for (let dsUrs of this.dataSourceUrls) {
                    let isFitParam = false // 是否匹配上参数
                    if (screenItem.type == 'screen' && dsUrs.relateScreen[screenItem.type + screenItem.id]) { // 筛选器
                        for (let ds of screenItem.dataSourceData) {
                            if (ds.dataSourceId == dsUrs.item.dataSourceId || (ds.reqUrl && dsUrs.item.reqUrl && ds.reqUrl.split('?')[0] == dsUrs.item.reqUrl.split('?')[0])) {
                                dsUrs = this.getSeqParamByScreen(dsUrs, screenItem, ds)
                            }
                        }
                        isFitParam = true
                    }

                    if (dsUrs.item.filterData && dsUrs.item.filterData.length > 0) { // 存在关联筛选
                        for (let fd of dsUrs.item.filterData) {
                            if (fd.filterId && fd.filterId == (screenItem.type + '_' + (screenItem.state || '0') + '_' + screenItem.id)) { // 关联上了
                                dsUrs = this.getSeqParamByScreen(dsUrs, screenItem, fd)
                                isFitParam = true
                                break
                            }
                        }
                    }
                    if (isFitParam) { // 匹配上
                        dataSourceUrlsByScreen.push(dsUrs)
                    }
                }
                if (dataSourceUrlsByScreen && dataSourceUrlsByScreen.length > 0) {
                    // 请求服务
                    this.getAllPromise(dataSourceUrlsByScreen, 'part')
                }
                // 非dataSourceUrls外的筛选联动
                this.setFilterNatusParam(screenItem)
            }
        },
        // 设置外部参数
        setFilterNatusParam(screenItem) {
            let key = screenItem.type != 'tab' ? (screenItem.type + '_' + (screenItem.state || '0') + '_' + screenItem.id) : (screenItem.type + '_' + (screenItem.id.replace(screenItem.index, '')) + '_' + screenItem.index)
            if (this.filterNatus && this.filterNatus[key]) {
                for (let natu of this.filterNatus[key]) { // 被关联的控件
                    let params = {}
                    if (screenItem.type == 'filter') { // 筛选器
                        params = screenItem.noDate ? { orgIds: screenItem.area } : (screenItem.noArea ? { endDate: screenItem.end, beginDate: screenItem.start } : { orgIds: screenItem.area, endDate: screenItem.end, beginDate: screenItem.start })
                    } else if (screenItem.type == 'tab') { //假如是局部tabs
                        if (screenItem.natureArr && screenItem.natureArr.length > 0) {
                            params = this.screenItem.noDate ? { orgIds: this.screenItem.area } : (this.screenItem.noArea ? { endDate: this.screenItem.end, beginDate: this.screenItem.start } : { orgIds: this.screenItem.area, endDate: this.screenItem.end, beginDate: this.screenItem.start })
                        }
                    } else if (natu.fd) {
                        if (screenItem.state == '1') { //日期组件
                            params[natu.fd.reqParam] = screenItem.value ? screenItem.value.split(' ~ ')[natu.fd.dataSourceDateType] : ''
                        } else {
                            params[natu.fd.reqParam] = screenItem.value
                        }
                    }
                    if (!natu.tabId || this.tabActiveIndexObj[natu.tabId] == natu.pIndex) {
                        if (natu.type == 'table' && natu.treeNode) { // 属性表格
                            if (natu.pivotType) { //假如是科室
                                params = { orgIds: screenItem.area, endDate: screenItem.end, beginDate: screenItem.start, pivotType: 'doctor', busiCode: natu.targetCode }
                                if (screenItem.noArea) {
                                    delete params.orgIds
                                }
                            }
                            setTimeout(() => {
                                this.$eventBus.$emit('refreshTreeData' + natu.id + false, screenItem.noDate ? { orgIds: screenItem.area } : params)
                            }, 1000)
                        } else if (natu.type == 'biElement' && (natu.state == '1' || natu.state == '5' || natu.state == '6' || natu.state == '7')) { // 指标项
                            this.$eventBus.$emit('refreshBiTarget' + natu.id + this.paramId_ + false, params)
                        } else if (natu.type == 'screen' && natu.state == '5') {
                            this.$eventBus.$emit('refreshBiText' + natu.id + false, params)
                        } else if (natu.type == 'chart' && natu.cate == 'custom') {
                            this.$eventBus.$emit('refreshDashBoard' + natu.id + false, params)
                        }
                    }
                }
            }
        },
        // 局部设置响应参数
        getSeqParamByScreen(dsUrs, screenItem, fd) {

            if ((!dsUrs.item.dsType || dsUrs.item.dsType == '0') && dsUrs.item.dataSourceId) { // 自定义URL
                let parameters = dsUrs.data.parameters ? JSON.parse(dsUrs.data.parameters) : []
                if (screenItem.type == 'filter') { // 筛选器
                    if (!screenItem.noDate) {
                        if (!screenItem.noArea) {
                            parameters.unshift({ name: 'orgIds', value: screenItem.area })
                        }
                        parameters.unshift({ name: 'endDate', value: screenItem.end })
                        parameters.unshift({ name: 'beginDate', value: screenItem.start })
                    } else { //假如只有院区的时候
                        if (!screenItem.noArea) {
                            parameters.unshift({ name: 'orgIds', value: screenItem.area })
                        }
                    }
                } else {
                    let param = { name: (fd.dataSourceCol || fd.reqParam) }
                    if (screenItem.state == '1') { //日期组件
                        param.value = screenItem.value ? screenItem.value.split(' ~ ')[fd.dataSourceDateType] : ''
                    } else {
                        param.value = screenItem.value
                    }
                    parameters.unshift(param)
                }
                // 数组去重
                let obj = {};
                parameters = parameters.reduce((cur, next) => {
                    obj[next.name] ? "" : obj[next.name] = true && cur.push(next);
                    return cur;
                }, [])
                dsUrs.data.parameters = JSON.stringify(parameters)
            } else { // 自定义服务
                if (screenItem.type == 'filter') { // 筛选器
                    if (screenItem.noDate) {
                        Object.assign(dsUrs.data, { orgIds: screenItem.area })
                    } else {
                        Object.assign(dsUrs.data, screenItem.noArea ? { endDate: screenItem.end, beginDate: screenItem.start } : { orgIds: screenItem.area, endDate: screenItem.end, beginDate: screenItem.start })
                    }
                } else {
                    if (screenItem.state == '1') { //日期组件
                        dsUrs.data[fd.reqParam] = screenItem.value ? screenItem.value.split(' ~ ')[fd.dataSourceDateType] : ''
                    } else {
                        dsUrs.data[fd.reqParam] = screenItem.value
                    }
                }
            }
            return dsUrs
        },
        getAncher() {
            if (this.natureArr && this.natureArr.length > 0) {
                this.ancherList = []
                this.natureArr.forEach(res => {
                    if (res.type == "biElement" && res.state == 3) {
                        this.ancherList.push({
                            name: res.ancherName,
                            id: 'biancher_' + res.id
                        })
                    }
                })
            }
        },
        // 交互数据
        interData(param) {
            let interDataUrls = []
            let thisItem = param.thisItem // 源控件
            let thisParam = null // 源参数
            for (let inter of thisItem.clickEvent) {
                if (inter.action == '001') { // 隐藏
                    let nature = this.getNatureArrByid(this.natureArr, inter.targetControl)
                    nature.isHide = true
                } else if (this.dataSourceUrls.length > 0) { // 渲染
                    for (let ds of this.dataSourceUrls) {
                        if (ds.item && ds.item.id == thisItem.id) { // 获取源控件的数据源内容
                            thisParam = JSON.parse(JSON.stringify(ds.data))
                        }
                        if (ds.item && ds.item.id == inter.targetControl) {
                            let newDs = ds //JSON.parse(JSON.stringify(ds)) // item为被联动的控件
                                // newDs.item = this.getNatureArrByid(this.natureArr, inter.targetControl)
                            let value = param.row[inter.sourceParam]
                            if (newDs.item.dsType == 0) { //自定义服务
                                //???自定义服务的参数跟随暂未完成
                                let parameters = JSON.parse(newDs.data.parameters)
                                let isSet = false // 判断是否已经设置
                                if (parameters && parameters.length > 0) {
                                    for (let param of parameters) {
                                        if (param.name == inter.targetParam) {
                                            param.value = value
                                            isSet = true
                                            break
                                        }
                                    }
                                }
                                if (!isSet) { //未设置，手动加入
                                    parameters.push({ name: inter.targetParam, value: value })
                                }
                                newDs.data.parameters = JSON.stringify(parameters)
                            } else { // 自定义URL
                                newDs.data[inter.targetParam] = value
                                if (thisParam) { // 防止被覆盖
                                    delete thisParam[inter.targetParam] // 被传的参数，不能被覆盖
                                    delete thisParam.pivotType // 【维度】个性化独有字段，不能被覆盖
                                    delete thisParam.sortOrder // 【排序】个性化独有字段，不能被覆盖
                                    delete thisParam.sortName // 【排序】个性化独有字段，不能被覆盖
                                    delete thisParam.generalType // 占比
                                    delete thisParam.enableBusiCodeAlias // 别名
                                    newDs.data = Object.assign(newDs.data, thisParam) // 将源控件的参数带上
                                }
                            }
                            interDataUrls.push(newDs) // 加入被联动控件URL，使其刷新
                            break
                        }
                    }
                }
            }
            this.getAllPromise(interDataUrls, 'part') // 去服务器上下载数据
        },
        // 发出所有的promise请求
        getAllPromise(dataSourceUrls, type) {
            let _this = this
            if (dataSourceUrls.length > 0) {
                let newDataSourceUrls = {}
                for (let item of dataSourceUrls) {
                    // 局部刷新或者未添加关联过滤或者在设计区预览（非真实菜单预览）
                    if (type == 'part' || !item.hasFilter) { // change关联跳过过滤,只针对过滤，若过滤器改变，则变
                        if (item.item && (item.item.pType != 'tab' || (item.item.pIndex && this.tabActiveIndexObj[item.item.tabId] == item.item.pIndex))) { // tab除开首次进来的，其他只在切换时才响应请求
                            const key = item.url + JSON.stringify(item.data) + item.item.isRealTime // 将url和参数data匹配的请求合并在一起
                            if (newDataSourceUrls.hasOwnProperty(key)) {
                                newDataSourceUrls[key].push(item)
                            } else {
                                newDataSourceUrls[key] = []
                                newDataSourceUrls[key].push(item)
                            }
                        }
                    }
                }
                // 清空sse：后续虚考虑未绑定过滤组件的实时数据，目前只考虑全部组件都绑定筛选器的情况
                this.clearEventSource()
                for (let newData of Object.keys(newDataSourceUrls)) {
                    const newItems = newDataSourceUrls[newData]
                    if (newItems[0].item.isRealTime) {
                        this.openRealTimeUrl(newItems)
                    } else {
                        this.setLoading(true, newItems)
                        this.$api({
                                url: newItems[0].url,
                                method: newItems[0].method,
                                data: newItems[0].data,
                                headers: newItems[0].headers
                            })
                            .then(res => {
                                _this.initServeResult(newItems, res)
                            }).catch(err => {
                                _this.$utils.msg(_this, err.message || '请求失败，请检查数据源配置是否正确', 'error')
                                _this.setLoading(false, newItems)
                            })
                    }

                }
            }
        },
        // 初始化服务器结果
        initServeResult(newItems, res) {
            const _this = this
            for (let ni of newItems) {
                // ni.item.parameters = JSON.parse(ni.data.parameters)  
                sessionStorage.setItem("parameters", ni.data.parameters)
                    // 对接口返回的数据进行处理
                _this.initServeData(ni.item, res, true)
                let biMap = { loading: false, data: ni.item.data }
                if (ni.item.type == 'element' && (ni.item.state == '1' || ni.item.state == '2')) {
                    //快捷连和方块签
                    biMap.data = ni.item.dataSourceData
                }
                _this.$store.commit('setBiPreviewMap', { id: 'bi' + (ni.item.pId ? (ni.item.id + ni.item.pId) : ni.item.id), pMap: biMap, formId: this.formId })
            }
        },
        // 打开实时功能
        openRealTimeUrl(newItems) {
            const _this = this
            if (typeof(EventSource) !== "undefined") {
                let param = newItems[0].data
                let contentType = newItems[0].headers['Content-Type']
                var source = new EventSource(biUtils.objArgs(param, newItems[0].url, contentType));
                source.onmessage = function(event) {
                    if (event.data) {
                        try {
                            _this.initServeResult(newItems, JSON.parse(event.data))
                        } catch (error) {
                            console.warn(error)
                                // _this.$utils.msg(_this, '返回格式存在问题，请联系管理员', 'error')
                        }
                    }
                };
                // source.onerror = function(e) {
                //     _this.$utils.msg(_this, '请求参数过长，请检查参数', 'warning')
                //     source.close();
                //     source = null
                // };
                if (source) {
                    this.eventSources.push(source)
                }
            } else {
                _this.$utils.msg(_this, '该浏览器不支持SSE,请升级浏览器版本', 'warning')
            }
        },

        // 设置加载状态
        setLoading(status, list) {
            for (let ni of list) {
                this.$store.commit('setBiPreviewMap', { id: 'bi' + (ni.item.pId ? (ni.item.id + ni.item.pId) : ni.item.id), pMap: { loading: status }, formId: this.formId })
            }
        },
        // 初始化筛选框服务器数据
        initServeRaidoData(item, response) {
            let value = ''
            let text = ''
            let resObj = response.object || response.rows
            if (item.dataType == 1) { // 数据源
                value = item.selectDataSourceCode
                text = item.selectDataSourceName
            } else {
                value = 'LEVEL_NAME'
                text = 'DESCRIPTION'
            }
            for (let obj of resObj) {
                item.data.push({ value: obj[value], text: obj[text] })
                    // width = width + (obj[text].length + 1) * 18
            }
            // item.w = this.getControlWidth(width) //需自动填充
        },
        // 初始化除筛选框以外的服务器数据
        initServeData(item, response, isClear) {
            const _this = this
            if (item.dataSourceId === '000' && item.dataSourceName === '维度指标') { // 维度指标
                switch (item.type) {
                    case 'table': //表格
                        item.data = response.rows || response.object.rows
                        break;
                    case 'chart': //图表
                        item.data = [];
                        if (response.rows && response.rows.length > 0) {
                            let resData = _this.initDataByNum(item, response.rows)
                            for (let r of resData) {
                                for (let x of item.fieldsXIdList) {
                                    let c = x.fieldsXId ? x.fieldsXId.split(',')[0] : ''
                                    let v = (item.targetIds) ? item.targetIds.split(',')[0] : ''
                                    item.data.push({ column: item.columnLabel ? r[item.columnLabel] : x.fieldsXName, category: r[v], value: r[x.measureName] })
                                        // item.data.push({ column: item.columnLabel ? r[item.columnLabel] : x.fieldsXName, category: r[v], value: r[itemParam.chart.measureName[0]] })
                                }
                                // item.data.push({ column: r[itemParam.chart.fieldsX[0]], category: itemParam.chart.targetName[0], value: r[itemParam.chart.measureName[0]] })
                            }
                        }
                        break;
                }
            } else {
                if (isClear) {
                    item.data = []
                }
                let respData = null
                if (item.dsType == '1') { // 手输url
                    if (item.resNode) { // 取节点
                        respData = response
                        for (let node of item.resNode.split('.')) {
                            respData = respData[node]
                        }
                    } else {
                        respData = response.rows || response.object || []
                    }
                } else if (!response.success) {
                    console.warn(response.errMsg || '预览请求失败，请检查参数值是否完整')
                        // _this.$utils.msg(
                        //     _this,
                        //     response.errMsg || '预览请求失败，请检查参数值是否完整', 'error'
                        // )
                } else {
                    respData = response.rows || response.object || []
                }
                if (item.dsType == '1' || response.success) {
                    const isResult = item.dsType == '1' ? false : (item.dataSource && item.dataSource.serviceType == 2) || (item.dataSourceDataResult && item.dataSourceDataResult.length) || (item.selectDataSourceResultData && item.selectDataSourceResultData.length)
                    switch (item.type) {
                        case 'table': //表格
                            // 存储过程
                            if (isResult) {
                                for (let obj of response.object) {
                                    if (item.dataSource.resultName == obj.name) {
                                        item.data = obj.result
                                        break
                                    }
                                }
                            } else {
                                if (item.treeNode) { //目前支持url 树表格懒加载 
                                    let tableData = respData || response.rows || (Array.isArray(response.object) ? response.object : response.object ? response.object.rows : [])
                                    if (tableData.length > 0) {
                                        tableData.forEach(res => { res.hasChild = true })
                                    }
                                    item.data = tableData
                                } else {
                                    item.data = respData || response.rows || (Array.isArray(response.object) ? response.object : response.object ? response.object.rows : [])
                                }
                            }
                            break;
                        case 'chart': //图表
                            item.data = [];
                            if (isResult) {
                                if (respData && respDatas.length > 0) {
                                    for (let obj of response.object) {
                                        if (item.resultName == obj.name) {
                                            let resData = _this.initDataByNum(item, obj.result)
                                            for (let r of resData) {
                                                for (let x of item.fieldsXIdList) {
                                                    let c = x.fieldsXId ? x.fieldsXId.split(',')[0] : ''
                                                    if (item.targetIds && item.targetIds.split(',').length > 0) {
                                                        for (let target of item.targetIds.split(',')) {
                                                            item.data.push({ column: item.columnLabel ? r[item.columnLabel] : x.fieldsXName, category: r[target], value: r[c].replace(/,/gi, '') })
                                                        }
                                                    }
                                                }
                                            }
                                            break
                                        }
                                    }
                                }
                            } else {
                                if (respData && respData.length > 0) {
                                    if (respData[0].targetUnit) {
                                        item.targetUnit = respData[0].targetUnit || ''
                                    }
                                    let resData = _this.initDataByNum(item, respData)
                                    for (let r of resData) {
                                        // item.data.push({ column: r.cname, category: r[item.targetIds], value: r.success })
                                        for (let x of item.fieldsXIdList) {
                                            let c = x.fieldsXId ? x.fieldsXId.split(',')[0] : ''
                                            if (item.targetIds && item.targetIds.split(',').length > 0) {
                                                for (let target of item.targetIds.split(',')) {
                                                    let value = 0
                                                    try {
                                                        //保留精度 可能存在小于1的数值展示
                                                        value = parseFloat(r[c].replace(/,/gi, ''))
                                                    } catch (err) {}
                                                    if (r[target] != '合计') { //合计特殊处理 不展示
                                                        item.data.push({ column: item.columnLabel ? r[item.columnLabel] : x.fieldsXName, category: r[target], value: value })
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        case 'element': //元素
                            //日程 - 组件内部处理
                            if (item.state == '5') {
                                return
                            }
                            let datas = []
                                // 存储过程
                            if (isResult) {
                                for (let obj of response.object) {
                                    if (item.dataSource.resultName == obj.name) {
                                        datas = obj.result
                                        break
                                    }
                                }
                            } else {
                                datas = respData || response.rows || response.object.rows
                            }
                            if (item.state == '6') { // 人物块状
                                let data = this.initDataByNum(item, [...datas]) // 数据量
                                if (isClear) {
                                    item.data = data
                                } else {
                                    item.data = item.data.concat(data)
                                }
                            } else {
                                _this.initElementData(item, datas, isClear)
                            }
                            break;
                        case 'screen':
                            if (item.state == 4) { // 单选
                                item.data = []
                                _this.initServeRaidoData(item, response)
                            } else if (item.state == 5) { //标签
                                if (isResult) {
                                    for (let obj of response.object) {
                                        if (item.dataSource.resultName == obj.name) {
                                            item.controlName = obj.result[0][item.selectDataSourceCode]
                                            break
                                        }
                                    }
                                } else {
                                    item.controlName = respData[0][item.selectDataSourceCode]
                                }
                            }
                            break;
                        case 'biElement':
                            if (item.state == 2) { // 轮播图
                                item.data = []
                                if (isResult) {
                                    for (let obj of response.object) {
                                        if (item.dataSource.resultName == obj.name) {
                                            datas = obj.result
                                            break
                                        }
                                    }
                                } else {
                                    datas = respData || response.rows || response.object.rows
                                }
                                for (let d of datas) {
                                    item.data.push({ name: d[item.namePara], value: d[item.valPara] })
                                }
                            }
                            break
                    }
                }
            }
        },
        //处理type为element的数据项
        initElementData(item, dataList, isClear) {
            if (dataList.length == 0 && isClear) {
                // 没有数据时 给他附加初值 如果清除则页面会出现空白
                item.dataSourceData.forEach(e => {
                        e.showValue = '-'
                    })
                    // item.dataSourceData = []
                return
            }
            let data = _.cloneDeep(item.dataSourceData[0])
                // item.dataSourceData = []
            if (item.dataType == '1') { // 列表
                isClear ? item.dataSourceData = [] : ''
                dataList = this.initDataByNum(item, dataList) // 数据量
                for (let row of dataList) {
                    let data_ = _.cloneDeep(data)
                    data_.data = row
                    if (item.state == 1) { // 快捷链接
                        data_.showIcon = row[data_.selectDSIconCode] // 图片
                    }
                    data_.showValue = row[data_.selectDataSourceCode]
                    item.dataSourceData.push(data_)
                }
            } else { // 对象
                for (let ds of item.dataSourceData) {
                    ds.data = item.dsType == 1 ? dataList : dataList[0]
                    ds.showValue = ds.data[ds.selectDataSourceCode]
                }
            }
        },
        // 处理list的数据量
        initDataByNum(item, dataList) {
            if (dataList && dataList.length > 0) {
                let start = item.dataNumStart ? parseInt(item.dataNumStart) - 1 : 0
                let end = item.dataNumEnd ? parseInt(item.dataNumEnd) : dataList.length
                return dataList.slice(start == -1 ? 0 : start, end)
            }
        },
        //---------------------------------------------真实菜单--------------------------------
        //初始化菜单服务器信息
        initMenuServeData(id) {
            const _this = this
            let url = '/ts-bi/api/BiReportDesign/' + id
            if (this.isFromList && this.versionCode == '草稿') {
                url =
                    '/ts-version/api/version/data?type=3&systemName=平台应用&moduleName=自定义报表&name=' +
                    id +
                    '&copyFlag=1'
            }
            this.$api({
                    url: url,
                    method: 'get',
                    headers: {
                        'Content-Type': 'application/json; charset=utf-8'
                    }
                })
                .then(function(response) {
                    // 请求成功
                    if (response.success) {
                        let other = {}
                        if (_this.isFromList && _this.versionCode == '草稿') {
                            other = JSON.parse(response.object)
                            _this.oldData = [{ other: response.object, id: id, displayMode: _this.displayMode }]
                        } else {
                            other = response.object && response.object.length > 0 ? JSON.parse(response.object[0].other) : null
                            _this.oldData = response.object
                        }
                        if (!other) {
                            return
                        }
                        if (Array.isArray(_this.oldData) && _this.oldData[0].displayMode == 1) { // 大屏模式
                            _this.type = 'bigScreen'
                            _this.bigScreenNature = _.cloneDeep(other.natureArr)
                            _this.createTimer()
                            _this.refreshBigData()
                        }
                        if (Array.isArray(_this.oldData) && _this.oldData[0].displayMode == 2) {
                            _this.type = 'pivot'

                        } else {
                            _this.natureArr = _.cloneDeep(other.natureArr)
                            _this.newBiCustom = _.cloneDeep(other.biCustom)
                            _this.refreshAllData()
                        }
                    } else {
                        _this.$utils.msg(_this, response.message || '操作失败', 'error')
                    }
                })
                .catch(function(error) {
                    // 请求失败
                    _this.$utils.msg(_this, error.message || '系统异常', 'error')
                })
        },
        //---------------------------------------------预览--------------------------------
        // // 初始化筛选数据
        // getScreenData(screenData, dateRangeVal) {
        //     let paramData = {}
        //         // paramData.selectDimensions = [];
        //         // for (let item of this.newBiCustom.weidu) {
        //         //     paramData.selectDimensions.push({ dimension: item.dimensionName, dimensionName: item._name });
        //         // }
        //     if (screenData && screenData.length > 0) {
        //         paramData.conditions = [];
        //         for (let item of screenData) {
        //             // var screen = { controlId: item.id, size: { width: item.controlWidth || 100, height: item.controlHeight || 100 }, type: item.state };
        //             // if (item.clickEvent) {
        //             //     screen.clickEvent = item.clickEvent;
        //             // }
        //             // if (item.isAutoNewLine) {
        //             //     screen.isAutoNewLine = item.isAutoNewLine;
        //             // }
        //             // if (item.controlName) {
        //             //     screen.controlName = item.controlName;
        //             // }
        //             // if (item.dimensionLevel) {
        //             //     screen.dimensionLevel = item.dimensionLevelId;
        //             // }
        //             // 日期控件
        //             // if (item.state == 1) {
        //             //     if (item.isSelect) { // 为默认筛选框
        //             //         // item.value = dateRangeVal
        //             //         screen.fieldValues = dateRangeVal
        //             //     } else {
        //             //         // 属性值不为空
        //             //         if (item.value) {
        //             //             // screen.fieldValues = ['2018-01-01', '2020-09-09']
        //             //             screen.fieldValues = [item.value.split(' ~ ')[0].split(' ')[0], item.value.split(' ~ ')[1].split(' ')[0]]
        //             //         } else {
        //             //             if (item.endDateId || item.startDateId) {
        //             //                 screen.fieldValues = [previewRealDate.getRealDate(item.startDateType).startDate, previewRealDate.getRealDate(item.endDateType).endDate];
        //             //                 // screen.fieldValues = ['2018-01-01', '2020-09-09']
        //             //                 // item.value = screen.fieldValues[0] + ' 00:00:00' + ' ~ ' + screen.fieldValues[1] + ' 23:59:59'
        //             //                 // previewRealDate.setDateTime(item, screen.fieldValues[0], screen.fieldValues[1]);
        //             //             }
        //             //         }
        //             //     }
        //             // }
        //             // if (item.state == 5) {
        //             //     item.controlName = item.dataType == 0 ? item.controlName : ''
        //             // } else
        //             // if (item.state != 7) { //非按钮/非标签
        //             //     screen.andOr = item.andOrId || 'and';
        //             //     screen.isDimension = item.isDimension || '1';
        //             //     if (item.state == 6 && item.isDimension == '0') {
        //             //         screen.operate = item.operate;
        //             //     }
        //             //     screen.fieldNames = item.fieldNamesId ? item.fieldNamesId.split(',') : ['DIM_DATE_DAY'];
        //             // }
        //             // paramData.conditions.push(screen)
        //         }
        //         return paramData
        //     }
        // },
        //初始化筛选数据源链接
        initScreenDataSourceUrls(item) {
            // if (item.dataType == 1) { // 数据源
            let isResult = (item.dataSource && item.dataSource.serviceType == 2) || (item.dataSourceDataResult && item.dataSourceDataResult.length) || (item.selectDataSourceResultData && item.selectDataSourceResultData.length)
                // SQL与存储过程分开处理
            let url = !isResult ? '/ts-query/api/user/query/table/query' : '/ts-query/api/user/query/procFun/query'
            let data = {
                id: item.selectDataSource || item.dataSourceId
            }
            data = biUtils.setToken(data, item, this, global)
            return {
                method: 'post',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
                },
                data: data,
                url: url,
                item: item
            }
        },
        //根据宽度算出比例
        getControlWidth(width) {
            let allWidth = document.body.offsetWidth
            return width / allWidth * 36
        },
        //获取筛选元素
        getScreenDataByNatureArr(natureArr, nature) {
            for (let item of natureArr) {
                if (item.type == 'screen') { // 整体筛选框
                    if (item.state == 4) { //radio
                        if (item.dataType == 2) {
                            item.data = [...item.dataTypeList]
                        } else if (item.dataType == 1) {
                            this.dataSourceUrls.push(this.initScreenDataSourceUrls(item))
                        }
                    } else if (item.state == 5) { //标签
                        if (item.dsType == 0 || item.dsType == 1) { // 自定义服务
                            item.controlName = ''
                            this.dataSourceUrls.push(item.dsType == 0 ? this.initScreenDataSourceUrls(item) : this.getDefinedURL(item, []))
                        }
                    } else if (item.state == 1) { // 日期
                        if (item.dimensionLevelId) {
                            if (item.dimensionLevel == '年') {
                                const fieldValues = [previewRealDate.getRealDate('y').startDate, previewRealDate.getRealDate('y').endDate];
                                if (item.dateType == 'range') {
                                    item.value = fieldValues[0] + ' ~ ' + fieldValues[1]
                                } else if (item.dateType == 'yyyy') {
                                    item.value = previewRealDate.getRealDate('y').startDate.substring(0, 10)
                                } else {
                                    item.value = fieldValues[0] + ' 00:00:00' + ' ~ ' + fieldValues[1] + ' 23:59:59'
                                }
                            } else if (item.dimensionLevel == '月') {
                                const fieldValues = [previewRealDate.getRealDate('now').startDate, previewRealDate.getRealDate('now').endDate];
                                if (item.dateType == 'range') {
                                    item.value = fieldValues[0] + ' ~ ' + fieldValues[1]
                                } else if (item.dateType == 'yyyy-MM') {
                                    item.value = fieldValues[0].substr(0, 7) + ' ~ ' + fieldValues[1].substr(0, 7)
                                } else if (item.dateType == 'yyyyMM') {
                                    item.value = fieldValues[0].substr(0, 7).replace("-", "") + ' ~ ' + fieldValues[1].substr(0, 7).replace("-", "")
                                } else {
                                    item.value = fieldValues[0] + ' 00:00:00' + ' ~ ' + fieldValues[1] + ' 23:59:59'
                                }
                            }
                        } else {
                            if (item.isSelect) { // 为默认筛选框
                                item.value = this.dateRangeVal
                            } else {
                                if (item.endDateId || item.startDateId) {
                                    const fieldValues = [previewRealDate.getRealDate(item.startDateType).startDate, previewRealDate.getRealDate(item.endDateType).endDate];
                                    if (item.dateType == 'rangetime') {
                                        item.value = fieldValues[0] + ' 00:00:00' + ' ~ ' + fieldValues[1] + ' 23:59:59'
                                    } else {
                                        item.value = fieldValues[0] + ' ~ ' + fieldValues[1]
                                    }
                                }
                            }
                        }
                    } else if (item.state == 6) {
                        if (!item.inputType || item.inputType == "text") { //当输入框为文字的时候
                            if (!item.value) {
                                if (item.value == undefined) {
                                    if (item.defaultCode) {
                                        item.value = item.defaultCode
                                    }
                                }

                            }
                        } else if (item.inputType == "date") { //当输入框选择日期的时候
                            if (item.isTime == 'YYYY-MM') {} else if (!item.value) {
                                if (item.endDateId || item.startDateId) {
                                    let startDate = previewRealDate.getRealDate(item.startDateType).startDate
                                    let endDate = item.endDateType ? previewRealDate.getRealDate(item.endDateType).endDate : ''
                                    if (item.isRange && item.isTime == 'YYYY-MM-DD') {
                                        item.value = startDate + ' ~ ' + endDate
                                    } else if (item.isRange && item.isTime == 'YYYY-MM-DD hh:mm:ss') {
                                        item.value = startDate + ' 00:00:00' + ' ~ ' + endDate + ' 23:59:59'
                                    } else if (!item.isRange && item.isTime == 'YYYY-MM-DD') {
                                        item.value = startDate
                                    } else if (!item.isRange && item.isTime == 'YYYY-MM-DD hh:mm:ss') {
                                        item.value = startDate + ' 00:00:00'
                                    }
                                }
                            }
                        }
                    }
                    if (nature) {
                        if (!nature.screenData) {
                            nature.screenData = []
                        }
                        nature.screenData.push(item)
                    } else {
                        this.screenData.push(item)
                    }
                } else if (item.type == 'tab') {
                    for (let tab of item.tabs) {
                        tab.screenData = []
                        tab.screenData.push({ dataSourceData: tab.dataSourceData })
                        this.getScreenDataByNatureArr(tab.natureArr, tab)
                    }
                } else if (item.type == 'panel' || item.type == 'business') {
                    this.getScreenDataByNatureArr(item.natureArr, null)
                }
            }
        },
        //渲染 table tab chart
        getControlData(natureArr, tab, dateRangeVal, pId, tabType) {
            for (let item of natureArr) {
                if (item.filterId && !item.filterData) { // 兼容旧关联筛选
                    item.filterData = [
                        { filterId: 'filter' + '_0_' + item.filterId }
                    ]
                }
                // 用于分布加载tab，懒加载
                if (tab && tabType) {
                    item.pType = tabType.split('_')[0]
                    item.pIndex = tabType.split('_')[2]
                    item.tabId = tabType.split('_')[1]
                }
                if (item.type == 'tab' && item.tabs) {
                    for (var i = 0; i < item.tabs.length; i++) {
                        let t = item.tabs[i]
                        let isExist = true
                        if (t.roleIds) { // 角色配置
                            let userRoles = global.userInfo && global.userInfo.sysRoleCode ? global.userInfo.sysRoleCode.split(',') : ''
                            isExist = t.roleIds.split(',').some(res => userRoles.indexOf(res) > -1)
                            if (!isExist) { // 不匹配，删除
                                item.tabs.splice(i, 1)
                                i--
                            }
                        }
                        if (isExist) { // 匹配
                            this.getControlData(t.natureArr, t, dateRangeVal, pId ? pId + item.id : item.id, 'tab' + '_' + item.id + '_' + t.index) // 加上PID防止与业务组件内部id向冲，唯一性判断为：pid+id
                        }
                    }
                    item.activeIndex = item.tabs && item.tabs.length > 0 ? item.tabs[0].index : '0'
                    this.tabActiveIndexObj[item.id] = item.activeIndex
                }
                if (item.type == 'panel' || item.type == 'business') {
                    this.getControlData(item.natureArr, item, dateRangeVal, pId ? pId + item.id : item.id, tabType)
                } else if (item.type == 'biElement' && (item.state == '1' || item.state == '5' || item.state == '6' || item.state == '7')) { // 指标项
                    this.setFilterNatusObj(item, tabType)
                } else if (item.type != 'screen' && item.type != 'filter') {
                    if (item.type == 'table') {
                        if (item.treeNode && item.filterData) { //假如是树形懒加载需要把外部条件传到table组件
                            this.setFilterNatusObj(item, tabType)
                        }
                        this.setTableCols(item)
                    }
                    if (item.type == 'chart' && item.cate == 'custom') {
                        this.setFilterNatusObj(item, tabType)
                    }
                    item.data = []
                    let screenData = [...this.screenData]
                    if (tab && tab.screenData && tab.screenData.length > 0) { // 全局筛选管全局和tab内，tab只管tab内
                        screenData = [...this.screenData.concat(tab.screenData)]
                    }
                    // // 用于分布加载tab，懒加载
                    // if (tab && tabType) {
                    //     item.pType = tabType.split('_')[0]
                    //     item.pIndex = tabType.split('_')[2]
                    //     item.tabId = tabType.split('_')[1]
                    // }
                    if ((!item.dsType || item.dsType == '0') && item.dataSourceId) {
                        item.pId = pId
                        this.dataSourceUrls.push(this.getDataSourceUrl(item, screenData))
                    } else if (item.dsType == '1' && item.reqUrl) {
                        item.pId = pId
                        this.dataSourceUrls.push(this.getDefinedURL(item, screenData))
                    }
                } else if (item.type == 'screen' && item.state == 5) { //文本标签联动
                    if (item.filterData) {
                        this.setFilterNatusObj(item, tabType)
                    }

                }
            }
        },
        // 设置外部请求过滤对象
        setFilterNatusObj(item, tabType) {
            if (item.filterData && item.filterData.length > 0) {
                for (let fd of item.filterData) {
                    if (fd.filterId) { // 关联筛选器
                        item.fd = fd
                        this.filterNatus[fd.filterId] ? this.filterNatus[fd.filterId].push(item) : this.filterNatus[fd.filterId] = [item]
                    }
                }
            }
            if (tabType) { // 父级为tab类型
                this.filterNatus[tabType] ? this.filterNatus[tabType].push(item) : this.filterNatus[tabType] = [item]
            }
        },
        getShowUpDown(array, item) {
            for (let i = 0; i < array.length; i++) {
                let ce = array[i]
                ce.formatter = function({ cellValue, row, column }) {
                    if (ce.filter) { // 格式化
                        cellValue = biUtils.formatFilterCol(ce.filter, cellValue)
                    }
                    // if (item.targetCode) { // 指标  假如是指标统一处理千分位
                    cellValue = biUtils.splitNum(cellValue, row.dataOf)
                        // }
                    if (ce.showUpDownIcon) { // 增减标识
                        cellValue = biUtils.formatUpDown(cellValue)
                    }
                    return `<span style="font-size:${ce.fontSize ||
                        '12px'}px;color:${ce.fontColor ||
                        'var(--base-black)'};background:${ce.backgroundColor ||
                        ''}">${cellValue}</span>`
                }
                ce.type = 'html'
                if (ce.children && ce.children.length > 0) {
                    this.getShowUpDown(ce.children)
                }
            }
        },
        // 处理表格单元格内容
        setTableCols(item) {
            // 表格整理数据列
            item.totalSet = [];
            // 整理表格控件
            if (item.cols) {
                this.getField(item.cols, item)
            }
        },
        // 获取数据源---筛选取值
        getDataSourceParamItem(item, screenData) {
            let result = { parameters: [], relateScreen: {}, parameterObj: {} }
            let hasFilter = false
            if (screenData && screenData.length > 0) {
                for (let screenItem of screenData) {
                    if (screenItem.dataSourceData) { // 数据源入参配置
                        for (let ds of screenItem.dataSourceData) {
                            if (ds.dataSourceId == item.dataSourceId || (ds.reqUrl && item.reqUrl && ds.reqUrl.split('?')[0] == item.reqUrl.split('?')[0])) { // 数据源相同
                                result.relateScreen[screenItem.type + screenItem.id] = screenItem
                                result = this.setInitScreenVal(ds, screenItem, item, result)
                            }
                        }
                    }
                    if (item.filterData && item.filterData.length > 0) { // 关联筛选器
                        for (let fd of item.filterData) {
                            if (fd.filterId && fd.filterId == (screenItem.type + '_' + (screenItem.state || '0') + '_' + screenItem.id)) { // 关联上了
                                result = this.setInitScreenVal(fd, screenItem, item, result)
                            }
                            if (!hasFilter && fd.filterId && (fd.filterId.indexOf('filter_') > -1 || fd.filterId.indexOf('screen_10') > -1)) {
                                hasFilter = true // 标示存在筛选器，将首次不渲染
                            }
                        }
                    }
                }
            } else if (item.filterData && item.filterData.length > 0) { // 只包含筛选器
                hasFilter = true
            }
            result.hasFilter = hasFilter
            return result
        },
        // 设置初始化筛选值
        setInitScreenVal(fd, screenItem, item, result) {
            if (fd.dataSourceDateType && screenItem.value && screenItem.state == 1) { // r日期
                fd.value = screenItem.value.split(' ~ ')[fd.dataSourceDateType]
            } else if (screenItem.value) {
                fd.value = screenItem.value
            } else if (screenItem.state == 2 || screenItem.state == 3 || screenItem.state == 4) { // 默认第一个
                fd.value = screenItem.data && screenItem.data.length > 0 ? screenItem.data[0].value : ''
            } else if (screenItem.state == 6) {
                if (screenItem.value == "") {
                    fd.value = screenItem.value
                }
            }
            // 控件和表单控件必须是同一个数据源才能做为筛选条件
            if ((!item.dsType || item.dsType == 0)) { //自定义服务
                result.parameters.unshift({ name: (fd.dataSourceCol || fd.reqParam), value: fd.value })
            } else {
                result.parameters.unshift({ name: fd.reqParam, value: fd.value })
                result.parameterObj[fd.reqParam] = fd.value
            }
            let obj = {};
            result.parameters = result.parameters.reduce((cur, next) => {
                obj[next.name] ? "" : obj[next.name] = true && cur.push(next);
                return cur;
            }, [])
            return result
        },
        //递归子类 geified赋值
        getField(children, item) {
            for (let i = 0; i < children.length; i++) {
                let ce = children[i]
                ce.formatter = function({ cellValue, row, column }) {

                    // if (item.targetCode) { // 指标  假如是指标统一处理千分位
                    cellValue = biUtils.splitNum(cellValue, row.dataOf)
                        // }
                    if (ce.showUpDownIcon) { // 增减标识
                        cellValue = biUtils.formatUpDown(cellValue)
                    }
                    if (ce.filter) { // 格式化
                        cellValue = biUtils.formatFilterCol(ce.filter, cellValue)
                    }
                    return `<span style="font-size:${ce.fontSize ||
                        '12px'}px;color:${ce.fontColor ||
                        'var(--base-black)'};background:${ce.backgroundColor ||
                        ''}">${cellValue}</span>`
                }
                ce.type = 'html'

                ce.resizable = item.baseTable ? false : (item.reszable != false)
                if (!ce.width) { // 为空则删除
                    delete ce.width
                }
                if (ce.targetId && ce.title) { //非无效单元格
                    if (ce.linkType) {
                        ce.className = 'link_cell'
                        ce.params = { link: { linkTypeId: ce.linkTypeId, openPatternId: ce.openPatternId, reportName: ce.reportName, reportNameId: ce.reportNameId } }
                    }
                    ce.field = ce.targetId
                    if (ce.isHasChild && ce.children && ce.children.length > 0) { // 含子类
                        ce.sortable = false
                            //递归子类 geified赋值
                        this.getField(ce.children, item)
                    } else {
                        // ce.sortable = ce.sortable !== false
                        ce.children = []
                    }
                    if ((item.isCount && typeof ce.isCount == 'undefined') || ce.isCount) { // 合计,item.isCount为兼容老数据，之后的取消
                        item.totalSet.push(ce.field)
                    }
                } else if (ce.pid) { //不为序列号列，且无有效列
                    item.cols.splice(i, 1)
                    i--
                } else {
                    ce.type = 'seq'
                }
            }
        },
        // 得到所有的数据源url-自定义服务
        getDataSourceUrl(item, screenData, dsId, isResult) {
            let screenParamObj = this.getDataSourceParamItem(item, screenData) || {}
            item.parameters = screenParamObj.parameters //给item 添加参数 为了导出方便获取参数值
            if (typeof isResult == 'undefined') {
                // SQL与存储过程分开处理
                isResult = (item.dataSource && item.dataSource.serviceType == 2) || (item.dataSourceDataResult && item.dataSourceDataResult.length) || (item.selectDataSourceResultData && item.selectDataSourceResultData.length)
            }
            let url = !isResult ? '/ts-query/api/user/query/table/query' : '/ts-query/api/user/query/procFun/query'
            let data = {
                    id: dsId || item.dataSourceId,
                    pageSize: item.isPage && item.pageSize ? Number(item.pageSize) : 3000,
                    pageNo: 1,
                    parameters: JSON.stringify(screenParamObj.parameters)
                }
                // 这个接口如何加token
            data = biUtils.setToken(data, item, this, global)
                // item.parameters = parameters
            return {
                method: 'post',
                url: url,
                data: data,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
                },
                item: item,
                relateScreen: screenParamObj.relateScreen,
                hasFilter: screenParamObj.hasFilter || false
            }
        },
        // 获取自定义URL
        getDefinedURL(item, screenData, reqType, reqUrl) {
            let screenParamObj = this.getDataSourceParamItem(item, screenData) || {}

            let data = screenParamObj.parameterObj || {}
                // parameters = this.getCanlendarParameter(item, parameters)
                // let data = {}
                // if (parameters && parameters.length > 0) {
                //     for (let param of parameters) {
                //         data[param.name] = param.value
                //     }
                // }
            data = biUtils.setToken(data, item, this, global)
            if (item.targetCode) { // 存在所属指标，入参加内容
                data.busiCode = item.targetCode // '80010' //
                    // 模拟日期
                data.beginDate = data.beginDate || previewRealDate.getRealDate('y').startDate
                data.sortOrder = item.sortOrder || '' // 排序方式
                data.sortName = item.sortName || '' // 排序方式
                if (item.pivotType) {
                    data.pivotType = item.pivotType
                }
                if (item.generalType) {
                    data.generalType = item.generalType
                }
                data.originalTargetUnit = item.originalTargetUnit
                    //只有originalTargetUnit为true时才会把万元还原

                data.enableBusiCodeAlias = item.enableBusiCodeAlias
            }
            return {
                method: reqType || item.reqType,
                url: reqUrl || item.reqUrl,
                data: data,
                headers: {
                    'Content-Type': (item.contentType || 'application/x-www-form-urlencoded') + '; charset=utf-8'
                },
                item: item,
                relateScreen: screenParamObj.relateScreen,
                hasFilter: screenParamObj.hasFilter || false
            }
        },
        // // 统一设置权限
        // setToken(item, data) {
        //     if (item.isToken) { //需要权限控制
        //         data.token = this.$cookies.get('token')
        //             // data.dep = this.$cookies.get('dep')
        //             // data.user = this.$cookies.get('user')
        //         data.deptcode = global.userInfo.deptcode
        //         data.deptid = global.userInfo.deptId
        //         data.userId = global.userInfo.id
        //         data.userCode = global.userInfo.usercode
        //         data.roleCode = global.userInfo.sysRoleCode
        //         data.hospCode = global.userInfo.hospCode
        //         data.corpCode = global.userInfo.corpcode
        //         if (!item.dsType || item.dsType == '0') { // 自定义服务
        //             data.orgRang = global.userInfo.orgRang
        //         }
        //     }
        //     return data
        // },
        //---------------------------------------------------纬度指标---------------------------------------
        // // 得到维度指标参数控件值
        // getControlParamItem(item, itemParam, isTab) {
        //     switch (item.type) {
        //         case 'chart':
        //             itemParam.type = '21';
        //             item.targetIds = []
        //             item.measureName = []
        //             item.targetName = []
        //             if (item.fieldsXIdList.length > 0) {
        //                 for (let it of item.fieldsXIdList) {
        //                     item.targetIds.push(it.targetIds)
        //                     item.measureName.push(it.measureName)
        //                     item.targetName.push(it.fieldsXName)
        //                 }
        //             }
        //             // item.targetIds = 
        //             itemParam.chart = { chartType: item.chartType, controlId: item.id, fieldsX: item.fieldsX ? item.fieldsX.split(',') : [], linkType: item.linkTypeId, openPattern: item.openPatternId, reportName: item.reportName, size: { width: item.controlWidth || 100, height: item.controlWidth || 100 }, targetIds: item.targetIds, measureName: item.measureName, state: item.state, targetName: item.targetName, title: item.controlTitle || '', type: '21' };
        //             // itemParam.chart = { chartType: item.chartType, controlId: item.id, fieldsX: item.fieldsX ? item.fieldsX.split(',') : [], linkType: item.linkTypeId, openPattern: item.openPatternId, reportName: item.reportName, size: { width: item.controlWidth || 100, height: item.controlWidth || 100 }, targetIds: item.targetIds ? item.targetIds.split(',') : [], measureName: item.measureName ? item.measureName.split(',') : [], state: item.state, targetName: item.targetName ? item.targetName.split(',') : [], title: item.controlTitle || '', type: '21' };
        //             break;
        //         case 'table':
        //             itemParam.type = '20';
        //             itemParam.table = { cells: [], controlId: item.id, isCount: item.isCount || '0', isPage: item.offPage || '0', size: { width: item.controlWidth || 100, height: item.controlHeight || 100 }, type: '20' };
        //             if (!item.offPage) {
        //                 itemParam.page = { _search: false, pageSize: 2000000, pageNo: 1, sord: 'desc' };
        //             }
        //             if (item.isCount) {
        //                 item.totalSet = [];
        //             }
        //             if (item.cols) {
        //                 for (let i = 0; i < item.cols.length; i++) {
        //                     let ce = item.cols[i]
        //                     ce.resizable = item.resizable != false
        //                     if (!ce.width) { // 为空则删除
        //                         delete ce.width
        //                     }
        //                     if (ce.targetId && ce.title) { //非无效单元格
        //                         var newCe = { align: ce.align || 'center', isFreeze: ce.frozen ? '1' : '0', isSort: ce.sortable ? '1' : '0', name: ce.cellId, relationTargetIds: [], showName: ce.title, targetId: ce.targetId, width: ce.width || 80 };
        //                         if (ce.linkType) {
        //                             ce.className = 'link_cell'
        //                             ce.params = { link: { linkTypeId: ce.linkTypeId, openPatternId: ce.openPatternId, reportName: ce.reportName, reportNameId: ce.reportNameId } }
        //                             newCe.linkType = ce.linkTypeId;
        //                         }
        //                         if (ce.openPattern) { // 超链接
        //                             newCe.openPattern = ce.openPatternId;
        //                         }
        //                         if (ce.reportName) {
        //                             newCe.reportName = ce.reportName;
        //                         }
        //                         if (ce.relationTarget) {
        //                             for (let rel of ce.relationTarget) {
        //                                 // ce.rowKey = ce.rowKey ? ce.rowKey + '|' + rel.measureName : rel.measureName;
        //                                 newCe.relationTargetIds.push(rel.id);
        //                             }
        //                         }
        //                         itemParam.table.cells.push(newCe)
        //                         ce.field = ce.measureName
        //                         if (item.isCount) { // 为合计
        //                             item.totalSet.push(ce.field)
        //                         }
        //                         if (ce.isCommon) { //通用指标(合并)
        //                             ce.children = []
        //                             for (let rel of ce.relationTarget) {
        //                                 ce.rowKey = ce.rowKey ? ce.rowKey + '|' + rel.measureName : rel.measureName;
        //                             }
        //                             let key = '';
        //                             if (ce.relationTarget && ce.relationTarget.length > 0) {
        //                                 key = ce.relationTarget[0].measureName + '_' + ce.targetId;
        //                             }
        //                             let childrenTitle = ''
        //                             for (let rel of ce.relationTarget) {
        //                                 childrenTitle = childrenTitle ? childrenTitle + ' | ' + rel.name : rel.name
        //                             }
        //                             let relChildren = {
        //                                 title: childrenTitle,
        //                                 field: key,
        //                                 width: 60,
        //                                 align: 'center'
        //                             }
        //                             if (ce.linkType) {
        //                                 relChildren.className = 'link_cell'
        //                                 relChildren.params = { link: { linkTypeId: ce.linkTypeId, openPatternId: ce.openPatternId, reportName: ce.reportName, reportNameId: ce.reportNameId } }
        //                             }
        //                             ce.children.push(relChildren)
        //                         }
        //                     } else if (ce.pid) { //不为序列号列，且无有效列
        //                         item.cols.splice(i, 1)
        //                         i--
        //                     } else {
        //                         ce.type = 'seq'
        //                     }
        //                 }
        //             }
        //             // this.getRealData(itemParam, item);
        //             break;
        //     }
        //     return this.getWeiduNormUrl(itemParam, item)
        // },
        // // 得到维度指标所有的url
        // getWeiduNormUrl(itemParam, item) {
        //     return {
        //         headers: {
        //             'Content-Type': 'application/json; charset=utf-8'
        //         },
        //         method: 'post',
        //         url: '/ts-bi/api/BiReportDesign/selectDataByConfig',
        //         data: JSON.stringify(itemParam),
        //         item: item
        //     }
        // },
    }
}
export default previewMixins