/**
 * 传递公共处理
 */
const natureArrMixins = {
    methods: {
        //通过下标找
        getNatureArrByid(natureArr, id) {
            if (natureArr && natureArr.length > 0) {
                for (let i = 0; i < natureArr.length; i++) {
                    if (natureArr[i].id === id) {
                        return natureArr[i]
                    } else {
                        if (natureArr[i].type === 'tab') {
                            for (let tab of natureArr[i].tabs) {
                                if (tab.index == natureArr[i].activeIndex) {
                                    let tabNature = this.getNatureArrByid(tab.natureArr, id)
                                    if (Object.keys(tabNature).length > 0) {
                                        return tabNature
                                    }
                                }
                            }
                        } else if (natureArr[i].type === 'panel') {
                            // 删除面板里面的值
                            let nature = this.getNatureArrByid(natureArr[i].natureArr, id)
                            if (Object.keys(nature).length > 0) {
                                return nature
                            }
                        }
                    }
                }
            }
            return {}
        },
        // 获取所有的控件id集合
        getNatureArrIds(arrs, type) {
            if (arrs && arrs.length > 0) {
                for (let item of arrs) {
                    if (item.type == 'tab') {
                        for (let tab of item.tabs) {
                            this.getNatureArrIds(tab.natureArr, type)
                        }
                    } else if (item.type == 'panel' || item.type == 'business') {
                        this.getNatureArrIds(item.natureArr, type)
                    }
                    if (!type || type.split(',').indexOf(item.type) > -1) { // 根据type进行过滤
                        this.natureArrIds.push({
                            id: item.id,
                            typeId: item.type + '_' + item.id,
                            state: item.type + '_' + (item.state || '0') + '_' + item.id,
                            type: item.type
                        })
                    }
                }
            }
        },
        // 改变内存
        changeStoreArray() {
            this.$store.commit('setSelectData', {...this.selectData })
            this.$store.commit('saveArr', { data: {...this.selectData } })
            this.setStoreNatureArr()
        },
        setStoreNatureArr() {
            if (this.biModel == 'mobile') {
                this.$store.commit('setPhoneNature', [...this.$store.state.bi.phoneNature])
            } else {
                this.$store.commit('setNatureArr', {...this.$store.state.bi.natureArr })
            }
        },
        // 获取控件id保存的数据集合
        getParamList(id, type, nature) {
            let childDatasList = []
            if (nature) {
                return
            } else {
                nature = this.getNatureArrByid(this.$store.state.bi.natureArr['d' + (this.$store.state.bi.dialogEditors.length - 1)], id)
                if (nature && nature.dataSourceId) {
                    for (let ds of this.$store.state.bi.dataSource) {
                        if (nature.dataSourceId == ds.id) {
                            if (ds[type]) {
                                childDatasList = JSON.parse(ds[type])
                            }
                            break
                        }
                    }
                }
            }

            return childDatasList
        },
    }
}
export default natureArrMixins