<template>
    <div class="hqSimulateWrap">
        <div class='divstockfull'>
            <StockFull ref='stockfull' DefaultPeriod='日线' :DefaultSymbol=this.Symbol :KLineOption=this.KLineOption
                :MinuteOption=this.MinuteOption>
            </StockFull>
        </div>
        <div class='simulateWrap' ref='simulateWrap'>
            <SimulateTrade ref='simulatetrade' DefaultUserID='lixq' @selectRow='OnChangeSymbol' @selectedsymbol='OnChangeSymbol' @collapsediv='CollapseOnSize'></SimulateTrade>
        </div>
    </div>

</template>

<script>
    import StockFull from '../../jscommon/umychart.vue.components/stockfull.vue'
    import SimulateTrade from '../../jscommon/umychart.vue.components/simulatetrade.vue'

    //定制K线设置
    const CUSTOM_KLINE_OPTION = {
        Windows: //窗口指标
            [{
                    Index: "MA"
                },
                {
                    Index: "MACD"
                },
            ],

        //TradeIndex: {Index:'交易系统-BIAS'},    //交易系统
        //ColorIndex:{ Index:'五彩K线-十字星'},     //五彩K线

        KLine: {
            //Info:["公告","互动易","调研"],              //信息地雷
            Right: 0, //复权 0 不复权 1 前复权 2 后复权
        }
    }

    const CUSTOM_MINUTE_OPTION = {
        Windows: //窗口指标
            [{
                Index: "RSI"
            }, ]
    }
    export default {
        data() {
            return {
                KLineOption: CUSTOM_KLINE_OPTION,
                MinuteOption: CUSTOM_MINUTE_OPTION,
                Symbol: '000001.sz'
            }
        },
        components: {
            StockFull,
            SimulateTrade
        },
        created() {
            var symbol = this.GetURLParams('symbol');
            if (symbol != null) this.Symbol = symbol;
        },
        mounted() {
            var simulatetrade = this.$refs.simulatetrade;
            var stockfull=this.$refs.stockfull;

            var self=this;
            self.OnSize();
            window.onresize = function () {
                self.OnSize();
            };

        },
        methods: {
            CollapseOnSize(simulateHeight){
                var simulateWrap= this.$refs.simulateWrap;
                simulateWrap.style.height = simulateHeight + 'px';
                this.OnSize();
            },
            OnChangeSymbol(symbol)
            {
                console.log(`[simulate demo::OnChangeSymbol] symbol=${symbol}`);
                var stockfull = this.$refs.stockfull;
                if(symbol != ''){
                    stockfull.OnChangeSymbol(symbol);
                }
                
            },
            GetURLParams(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return decodeURI(r[2]);
                return null;
            },
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            OnSize(){
                var height= $(window).height();
                var width = $(window).width();
                $('.hqSimulateWrap').width(width);
                $('.hqSimulateWrap').height(height);
                var simulateWrapHeight = $('.simulateWrap').height();

                $('.divstockfull').height(height-simulateWrapHeight);

                this.$refs.stockfull.OnSize();
                this.$refs.simulatetrade.OnSize();
            }
        }
    }
</script>