<template>
<#if ctrl.render??>
    ${ctrl.render.code}
<#else>
    <div id="${ctrl.getCodeName()?lower_case}" class="app-calendar-exp-bar<#if ctrl.getPSSysCss?? && ctrl.getPSSysCss()??><#assign singleCss = ctrl.getPSSysCss()> ${singleCss.getCssName()}</#if>">
        <#if ctrl.isShowTitleBar()>
            <div class='calendar-exp-bar-header'>
                <div class="calendar-exp-bar-title">
                    <icon type='ios-home-outline'/><#if ctrl.getTitle() == ''>{{ $t('app.calendarExpBar.title') }}<#else>${ctrl.getTitle()}</#if>
                </div>
            </div>
        </#if>
        <div class="exp-bar-action-container">
            <#if ctrl.isEnableSearch()>
            <div class='search-container'>
                <i-input
                    v-model="searchText"
                    :search="true"
                    :placeholder="placeholder"
                    @on-search="onSearch">
                </i-input>
            </div>
            </#if>
            <#if ctrl.getPSControls()??>
            <#assign controls = ctrl.getPSControls()/>
            <#list controls as singleControl>
            <#if singleControl.getControlType() == "TOOLBAR">
            ${P.getCtrlCode(singleControl, 'CONTROL.html').code}
            </#if>
            </#list>
            </#if>
        </div>
        <div class='calendar-exp-bar-content'>
            <#if ctrl.getPSControls()??>
            <#assign controls = ctrl.getPSControls()/>
            <#list controls as singleControl>
            <#if singleControl.getControlType() == "CALENDAR">
            ${P.getCtrlCode(singleControl, 'CONTROL.html').code}
            </#if>
            </#list>
            </#if>
        </div>
    </div>
</#if>
</template>


<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>

<#ibizinclude>
../@MACRO/FUNC/MACRO.ftl
</#ibizinclude>

    /**
     * 视图唯一标识
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Prop() public viewUID!:string;

<#if view.getPSAppViewLogics?? && view.getPSAppViewLogics()??>
  <#list view.getPSAppViewLogics() as logic>
    <#if logic.getPFLogicCodeType() == 'APP_NEWDATA'>
    /**
     * 打开新建数据视图
     *
     * @type {any}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Prop() public newdata: any;
    </#if>
    <#if logic.getPFLogicCodeType() == 'APP_OPENDATA'>
    /**
     * 打开编辑数据视图
     *
     * @type {any}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Prop() public opendata: any;
    </#if>
  </#list>
</#if>

    /**
     * 是否单选
     * 
     * @public
     * @type {(boolean)}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public isSingleSelect:boolean = true;

    /**
     * 可搜索字段名称
     * 
     * 
     * @type {(string)}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public placeholder = "<@getQuickSearchPlaceholder ctrl />";

    /**
     * 搜素值
     * 
     * @public
     * @type {(string)}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public searchText: string = "";

<#if ctrl.getXDataPSControl()??>
<#assign xDataControl = ctrl.getXDataPSControl() />

    /**
     * 导航视图名称
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public navViewName: any = {
<#if xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
        ${calendarItem.getItemType()}: "<#if calendarItem.getNavPSAppView?? && calendarItem.getNavPSAppView()??><#assign navPSAppView = calendarItem.getNavPSAppView() />${srffilepath2(navPSAppView.getCodeName())}</#if>"<#if calendarItem_has_next>,</#if>
  </#list>
</#if>
    };

    /**
     * 导航参数
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public navParam: any = {
<#if xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
        ${calendarItem.getItemType()}: {
            navigateContext:<#if calendarItem.getPSNavigateContexts?? && calendarItem.getPSNavigateContexts()??><@getNavigateContext calendarItem /><#else>null</#if>,
            navigateParams:<#if calendarItem.getPSNavigateParams?? && calendarItem.getPSNavigateParams()??><@getNavigateParams calendarItem /><#else>null</#if>
        }<#if calendarItem_has_next>,</#if>
  </#list>
</#if>
    };

    /**
     * 导航过滤项
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public navFilter: any = {
<#if xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
        ${calendarItem.getItemType()}: "<#if calendarItem.getNavFilter?? && calendarItem.getNavFilter()??>${calendarItem.getNavFilter()}</#if>"<#if calendarItem_has_next>,</#if>
  </#list>
</#if>
    };

    /**
     * 导航关系
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public navPSDer: any = {
<#if xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
        ${calendarItem.getItemType()}: "<#if calendarItem.getNavPSDER?? && calendarItem.getNavPSDER()??>n_${calendarItem.getNavPSDER().getPSPickupDEField().getCodeName()?lower_case}_eq</#if>"<#if calendarItem_has_next>,</#if>
  </#list>
</#if>
    };
</#if>

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Prop({ default: true }) public showBusyIndicator!: boolean;

    <#if ctrl.getPSControls()??>
    <#assign controls = ctrl.getPSControls()/>
    <#list controls as singleControl>
    <#if singleControl.getControlType() == "TOOLBAR">

    ${P.getCtrlCode(singleControl, 'CONTROL.vue').code}
    </#if>
    </#list>
    </#if>

    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public getDatas(): any[] {
        return [];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public getData(): any {
        return null;
    }

    /**
    * Vue声明周期(组件初始化完毕)
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
    */
    public created() {
        this.afterCreated();     
    }

    /**
    * 执行created后的逻辑
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
    */
    public afterCreated(){
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                <#if ctrl.getXDataPSControl?? && ctrl.getXDataPSControl()??>
                <#assign xDataControl = ctrl.getXDataPSControl() />
                this.viewState.next({ tag: '${xDataControl.getName()}', action: action, data: data });
                </#if>
            });
        }  
    }
    
    /**
    * Vue声明周期(组件渲染完毕)
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
    */
    public mounted() {
        this.afterMounted();     
    }

    /**
    * 执行mounted后的逻辑
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
    */
    public afterMounted() { }
 
    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public destroyed() {
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public afterDestroy() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

    /**
    * 刷新
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
    */
    public refresh(args?: any): void {
    <#if ctrl.getXDataPSControl?? && ctrl.getXDataPSControl()??>
    <#assign dataControl = ctrl.getXDataPSControl() />
        const refs: any = this.$refs;
        if (refs && refs.${dataControl.name}) {
            refs.${dataControl.name}.refresh();
        }
    </#if>
    }

    /**
     * ${ctrl.name}的选中数据事件
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public ${ctrl.name}_selectionchange(args: any [], tag?: string, $event2?: any): void {
        let tempContext:any = {};
        let tempViewParam:any = {};
        if (args.length === 0) {
            this.calcToolbarItemState(true);
            return ;
        }
        const arg:any = args[0];
        if(this.context){
            Object.assign(tempContext,JSON.parse(JSON.stringify(this.context)));
        }
        switch(arg.itemType) {
<#if xDataControl?? && xDataControl.getPSSysCalendarItems()??>
  <#list xDataControl.getPSSysCalendarItems() as calendarItem>
    <#if calendarItem.getPSAppDataEntity()??>
      <#assign _appde = calendarItem.getPSAppDataEntity() />
            case "${calendarItem.getItemType()}":
                Object.assign(tempContext,{ ${_appde.getCodeName()?lower_case} : arg.${_appde.getCodeName()?lower_case}});
                Object.assign(tempContext,{srfparentdename:'${_appde.getCodeName()}',srfparentkey:arg['${_appde.getCodeName()?lower_case}']});
                if(this.navFilter && this.navFilter['${calendarItem.getItemType()}'] && !Object.is(this.navFilter['${calendarItem.getItemType()}'],"")){
                    Object.assign(tempViewParam,{[this.navFilter['${calendarItem.getItemType()}']]:arg['${_appde.getCodeName()?lower_case}']});
                }
                if(this.navPSDer && this.navFilter['${calendarItem.getItemType()}'] && !Object.is(this.navPSDer['${calendarItem.getItemType()}'],"")){
                    Object.assign(tempViewParam,{[this.navPSDer['${calendarItem.getItemType()}']]:arg['${_appde.getCodeName()?lower_case}']});
                }
                if(this.navParam && this.navParam['${calendarItem.getItemType()}'] && this.navParam['${calendarItem.getItemType()}'].navigateContext && Object.keys(this.navParam['${calendarItem.getItemType()}'].navigateContext).length >0){
                    let _context:any = this.$util.computedNavData(arg,tempContext,tempViewParam,this.navParam['${calendarItem.getItemType()}'].navigateContext);
                    Object.assign(tempContext,_context);
                }
                if(this.navParam && this.navParam['${calendarItem.getItemType()}'] && this.navParam['${calendarItem.getItemType()}'].navigateParams && Object.keys(this.navParam['${calendarItem.getItemType()}'].navigateParams).length >0){
                    let _params:any = this.$util.computedNavData(arg,tempContext,tempViewParam,this.navParam['${calendarItem.getItemType()}'].navigateParams);
                    Object.assign(tempViewParam,_params);
                }
                break;
    </#if>
  </#list>
</#if>
        }
        const navItem: any = {
            navView: this.navViewName,
            data: args,
            srfnavdata: {
                context: tempContext,
                viewparams: tempViewParam
            }
        }
        this.calcToolbarItemState(false);
        this.$emit('selectionchange', navItem);
    }

    /**
     * ${ctrl.name}的load完成事件
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public ${ctrl.name}_load(args:any, tag?: string, $event2?: any){
        this.calcToolbarItemState(true);
        this.$emit('load',args);
    }

    /**
     * 设置导航区工具栏禁用状态
     *
     * @param {boolean} state
     * @return {*} 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public calcToolbarItemState(state: boolean) {
        let _this: any = this;
        const models:any = _this.${ctrl.getCodeName()?lower_case}_toolbarModels;
        if (models) {
            for (const key in models) {
                if (!models.hasOwnProperty(key)) {
                    return;
                }
                const _item = models[key];
                if (_item.uiaction && (Object.is(_item.uiaction.target, 'SINGLEKEY') || Object.is(_item.uiaction.target, 'MULTIKEY'))) {
                    _item.disabled = state;
                }
                _item.visabled = true;
                if (_item.noprivdisplaymode && _item.noprivdisplaymode === 6) {
                    _item.visabled = false;
                }
            }
            this.calcNavigationToolbarState();
        }
    }

    /**
     * 计算导航工具栏权限状态
     * 
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public calcNavigationToolbarState(){
        let _this: any = this;
        // 界面行为
        <#assign ModelsName>${ctrl.getCodeName()?lower_case}_toolbarModels</#assign>
        if(_this.${ModelsName}){
        <#if ctrl.getPSAppDataEntity?? && ctrl.getPSAppDataEntity()??>
        <#assign curAppEntity = ctrl.getPSAppDataEntity() />
            const curUIService:${srfclassname('${curAppEntity.getCodeName()}')}UIService  = new ${srfclassname('${curAppEntity.getCodeName()}')}UIService();
            ViewTool.calcActionItemAuthState({},_this.${ModelsName},curUIService);
        </#if>
        }
    }

    /**
    * 执行搜索
    *
    * @memberof ${srfclassname('${ctrl.codeName}')}Base
    */
    public onSearch($event:any) {
        <#if ctrl.getXDataPSControl()??>
        <#assign xDataControl = ctrl.getXDataPSControl()/>
        let calendar:any = this.$refs.${xDataControl.getName()};
        calendar.searchEvents({ query: this.searchText });
        </#if>
    }

<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

<#ibizinclude>
../@MACRO/CONTROL/CONTROL-BASE.style.ftl
</#ibizinclude>