import utils from '../../utils/utils'
const dragOperate = {
    data() {
        return {}
    },
    created() {},
    methods: {
        //触发改变控件大小 改变bireportLayout
        resizedEvent(args, item) {
            this.$nextTick(() => {
                if (this.$refs[item.i][0]) {
                    switch (item.type) {
                        case 'chart':
                            if (!item.cate) {
                                let chart = this.$refs[item.i][0].$refs.tsChart
                                if (chart.id === item.id) {
                                    chart.chartWidth = args[4] - 10
                                    chart.chartHeight = (item.controlTitle || item.subTitle) ? (item.controlTitle && item.subTitle ? args[3] - 64 : (item.controlTitle ? args[3] - 34 : args[3] - 30)) : args[3]
                                    chart.initChart()
                                }
                            }
                            break
                        case 'table':
                            let table = this.$refs[item.i][0].$refs.tsTable.$refs.tstable
                            table.refreshColumn() //触发更新渲染表格
                            break
                        case 'biElement':
                            if (item.state == 1) { // BI指标组件
                                this.$nextTick(() => {
                                    let chart = this.$refs[item.i][0].$refs.biTarget.$refs.tsChart
                                    if (chart) {
                                        chart.chartWidth = args[4] - 10
                                        chart.chartHeight = args[3] - 34 - 64
                                        chart.initChart()
                                    }
                                })
                            }
                            break
                    }
                }
                if (item.borderType || item.childBorderType) { //重载大屏
                    item.dataVKey = this.$utils.uuid(6)
                }
                this.$store.commit('setSelectData', {...item })
                this.$store.commit('saveArr', { data: {...item }, biModel: this.biModel })
                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 })
            }
        },
        //移动后触发
        movedEvent(args, item) {
            this.$store.commit('saveArr', { data: {...item }, biModel: this.biModel })
            this.setStoreNatureArr()
        },
        // 父宽度变化
        containerWidthUpdated(args, item) {
            this.$nextTick(() => {
                if ((item.borderType || item.childBorderType) && !this.dataVKey) { // 首次渲染，重载大屏组件
                    this.dataVKey = this.$utils.uuid(6)
                }
            })
        },
        moveEvent: function(args, item) {
            // const msg = 'MOVE i=' + i + ', X=' + newX + ', Y=' + newY;
            // console.log(args)
            // console.log(item)
        }
    }

}
export default dragOperate