import { Subject } from 'rxjs';
import { TabExpViewBase } from '@/studio-core';
import IBizListService from '@/service/ibiz-list/ibiz-list-service';
import TabExpViewEngine from '@engine/view/tab-exp-view-engine';

/**
 * 市场营销列表视图基类
 *
 * @export
 * @class IBizListInfoBase
 * @extends {TabExpViewBase}
 */
export class IBizListInfoBase extends TabExpViewBase {

    /**
     * 实体服务对象
     *
     * @type {IBizListService}
     * @memberof IBizListInfoBase
     */
    protected appEntityService: IBizListService = new IBizListService;


    /**
     * 计数器服务对象集合
     *
     * @protected
     * @type {Array<*>}
     * @memberof IBizListInfoBase
     */    
    protected counterServiceArray: Array<any> = [];

    /**
     * 视图模型数据
     *
     * @protected
     * @type {*}
     * @memberof IBizListInfoBase
     */
    protected model: any = {
        srfCaption: 'entities.ibizlist.views.info.caption',
        srfTitle: 'entities.ibizlist.views.info.title',
        srfSubTitle: 'entities.ibizlist.views.info.subtitle',
        dataInfo: ''
    }

    /**
     * 容器模型
     *
     * @protected
     * @type {*}
     * @memberof IBizListInfoBase
     */
    protected containerModel: any = {
        view_tabexppanel: { name: 'tabexppanel', type: 'TABEXPPANEL' },
    };


	/**
     * 视图唯一标识
     *
     * @protected
     * @type {string}
     * @memberof ViewBase
     */
	protected viewtag: string = 'b10964e86f6d70d588618c69fb4d6297';


    /**
     * 视图引擎
     *
     * @public
     * @type {Engine}
     * @memberof IBizListInfoBase
     */
    public engine: TabExpViewEngine = new TabExpViewEngine();

    /**
     * 引擎初始化
     *
     * @public
     * @memberof IBizListInfoBase
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            keyPSDEField: 'ibizlist',
            majorPSDEField: 'listname',
            isLoadDefault: true,
        });
    }



    /**
     * 加载模型
     *
     * @protected
     * @memberof IBizListInfoBase
     */
    protected async loadModel(): Promise<any> {
        if(this.context.ibizlist){
            this.appEntityService.getDataInfo(JSON.parse(JSON.stringify(this.context)),{},false).then((response:any) =>{
                if (!response || response.status !== 200) {
                    return;
                }
                const { data: _data } = response;
                if (_data.listname) {
                    Object.assign(this.model, { dataInfo: _data.listname });
                    if (this.$tabPageExp) {
                        this.$tabPageExp.setCurPageCaption(this.model.srfTitle, this.model.srfTitle, this.model.dataInfo);
                    }
                    if(this.$route){
                        this.$route.meta.info = this.model.dataInfo;
                    }
                    Object.assign(this.model, { srfTitle: `${this.$t(this.model.srfTitle)} - ${this.model.dataInfo}` });
                }
            })
        }
    }


}