<#ibizinclude>
./VIEW_LAYOUTPANEL/VIEW_LAYOUTPANEL_UIACTION/VIEW_LAYOUTPANEL_UIACTION.ftl
</#ibizinclude>
<#ibizinclude>
../../@MACRO/PANEL.ftl
</#ibizinclude>
<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch,Inject } from 'vue-property-decorator';
import { UIActionTool, Util } from '@/utils';
import { AppMessageBox } from '@/utils/app-message-box/app-message-box';
import NavDataService from '@/service/app/navdata-service';
<#if view.getPSAppCounterRefs()??>
<#list view.getPSAppCounterRefs() as singleCounterRef>
<#if singleCounterRef.getPSAppCounter()??>
<#assign appCounter = singleCounterRef.getPSAppCounter()/>
import  ${srfclassname('${appCounter.getCodeName()}')}CounterService  from '@/counter/${srffilepath2(appCounter.getCodeName())}/${srffilepath2(appCounter.getCodeName())}-counter';
</#if>
</#list>
</#if>
import { Subject,Subscription } from 'rxjs';
<#if view.getPSAppDataEntity?? && view.getPSAppDataEntity()??>
<#assign appde = view.getPSAppDataEntity()/>
import ${srfclassname('${appde.getCodeName()}')}Service from '@/service/${srffilepath2(appde.getCodeName())}/${srffilepath2(appde.getCodeName())}-service';
import ${srfclassname('${appde.getCodeName()}')}AuthService from '@/authservice/${srffilepath2(appde.getCodeName())}/${srffilepath2(appde.getCodeName())}-auth-service';
</#if>

<#if view.getPSAppViewEngines()??>
<#list view.getPSAppViewEngines() as engine>
import ${engine.getEngineType()}Engine from '@engine/${engine.getEngineCat()?lower_case}/${srffilepath2(engine.getEngineType())}-engine';
</#list>
</#if>

<#if view.getPSUIActions()??>
<#list view.getPSUIActions() as uiAction>
<#if uiAction.getPSAppDataEntity?? && uiAction.getPSAppDataEntity()??>
<#if uiAction.getPFLogicCodeType() == "WFBACKEND">
<#if uiAction.getPSAppWFVer?? && uiAction.getPSAppWFVer()??>
<#if !P.exists("importService", uiAction.getPSAppWFVer().getCodeName(), "")>
import ${srfclassname('${uiAction.getPSAppWFVer().getCodeName()}')}WFUIService from '@/wfuiservice/${uiAction.getPSAppWF().getCodeName()?lower_case}/${uiAction.getPSAppWFVer().getCodeName()?lower_case}-ui-service';
</#if>
</#if>
</#if>
</#if>
</#list>
</#if>
<#if appde??>
import ${srfclassname('${appde.getCodeName()}')}UIService from '@/uiservice/${srffilepath2(appde.getCodeName())}/${srffilepath2(appde.getCodeName())}-ui-service';
</#if>
<#if view.getPSViewLayoutPanel()?? && !view.getPSViewLayoutPanel().isUseDefaultLayout()>
import { PanelContainerModel, PanelRawitemModel, PanelFieldModel, PanelControlModel, PanelButtonModel, PanelUserControlModel, PanelTabPanelModel, PanelTabPageModel, PanelCtrlPosModel} from '@/model/panel-detail';
</#if>

<#if import_block??>
${import_block}
</#if>

@Component({
    components: {
    },
})
export default class ${srfclassname('${view.name}')}Base extends Vue {
<#if view.getPSAppDataEntity?? && view.getPSAppDataEntity()??>
<#assign appde = view.getPSAppDataEntity()/>

    /**
     * 实体服务对象
     *
     * @type {${srfclassname('${appde.getCodeName()}')}Service}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public appEntityService: ${srfclassname('${appde.getCodeName()}')}Service = new ${srfclassname('${appde.getCodeName()}')}Service();

    /**
     * 实体UI服务对象
     *
     * @type ${srfclassname('${appde.getCodeName()}')}UIService
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public appUIService: ${srfclassname('${appde.getCodeName()}')}UIService = new ${srfclassname('${appde.getCodeName()}')}UIService();
</#if>
    
    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

    /**
     * 传入视图上下文
     *
     * @type {string}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    @Prop() public viewdata!: string;

    /**
     * 传入视图参数
     *
     * @type {string}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    @Prop() public viewparam!: string;

    /**
     * 视图默认使用
     *
     * @type {boolean}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    @Prop({ default: true }) public viewDefaultUsage!: boolean;

    <#if view.getViewType() != "APPINDEXVIEW">
    /**
     * 视图默认使用
     *
     * @type {string}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    @Inject({from:'navModel',default: 'tab'})
    public navModel!:string;
    </#if>

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof ${srfclassname('${view.name}')}Base
	 */
	public viewtag: string = '${view.getId()}';

    /**
	 * 视图类型
	 *
	 * @type {string}
	 * @memberof ${srfclassname('${view.name}')}Base
	 */
	public viewType: string = '${view.getViewType()}';

	/**
	 * 自定义视图导航上下文集合
	 *
	 * @type {*}
	 * @memberof ${srfclassname('${view.name}')}Base
	 */
    public customViewNavContexts:any ={
    <#if view.getPSAppViewNavContexts()??>
    <#list view.getPSAppViewNavContexts() as viewNavContext>
    "${viewNavContext.getKey()}":{"isRawValue":${viewNavContext.isRawValue()?c},"value":"${viewNavContext.getValue()}"}<#if viewNavContext_has_next>,</#if>
    </#list>
    </#if>
    };

	/**
	 * 自定义视图导航参数集合
	 *
	 * @type {*}
	 * @memberof ${srfclassname('${view.name}')}Base
	 */
    public customViewParams:any ={
    <#if view.getPSAppViewNavParams()??>
    <#list view.getPSAppViewNavParams() as viewNavParam>
    "${viewNavParam.getKey()}":{"isRawValue":${viewNavParam.isRawValue()?c},"value":"${viewNavParam.getValue()}"}<#if viewNavParam_has_next>,</#if>
    </#list>
    </#if>
    };

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public model: any = {
        srfCaption: '<#if view.getPSAppDataEntity()??>entities.${view.getPSAppDataEntity().getCodeName()?lower_case}.views.${view.getPSDEViewCodeName()?lower_case}.caption<#else>app.views.${view.getCodeName()?lower_case}.caption</#if>',
        srfTitle: '<#if view.getPSAppDataEntity()??>entities.${view.getPSAppDataEntity().getCodeName()?lower_case}.views.${view.getPSDEViewCodeName()?lower_case}.title<#else>app.views.${view.getCodeName()?lower_case}.title</#if>',
        srfSubTitle: '<#if view.getPSAppDataEntity()??>entities.${view.getPSAppDataEntity().getCodeName()?lower_case}.views.${view.getPSDEViewCodeName()?lower_case}.subtitle<#else>app.views.${view.getCodeName()?lower_case}.subtitle</#if>',
        dataInfo: ''
    }

    /**
     * 视图参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof ${srfclassname('${view.name}')}Base
     */
    @Watch('viewparam',{immediate: true, deep: true})
    onParamData(newVal: any, oldVal: any) {
        if(newVal){
            this.viewparams = {};
            if(typeof newVal == 'string') {
                Object.assign(this.viewparams, JSON.parse(this.viewparam));
            }else{
                this.viewparams = Util.deepCopy(this.viewparam);
            }
            <#if watch_viewparam_block??>${watch_viewparam_block}</#if>
        } 
    }

    /**
     * 处理应用上下文变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof ${srfclassname('${view.name}')}Base
     */
    @Watch('viewdata')
    onViewData(newVal: any, oldVal: any) {
        const _this: any = this;
        <#if viewdata_block??>${viewdata_block}</#if>
        if (!Object.is(newVal, oldVal) && _this.engine) {
            this.$nextTick(()=>{
              _this.parseViewParam();
              _this.engine.load();
            });
        } else if(!Object.is(newVal, oldVal) && _this.refresh && _this.refresh instanceof Function) {
            _this.refresh();
        }
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public containerModel: any = {
        <#if view.getPSControls()??>
        <#list view.getPSControls() as ctrl>
        view_${ctrl.name}: { name: '${ctrl.name}', type: '${ctrl.getControlType()}' },
        </#list>
        </#if>
        <#if view.isPickupView() || (view.getViewType?? && (view.getViewType() == 'DEOPTVIEW' || view.getViewType() == 'DEWFSTARTVIEW' || view.getViewType() == 'DEWFACTIONVIEW'))>
        view_okbtn: { name: 'okbtn', type: 'button', text: '确定', disabled: true },
        view_cancelbtn: { name: 'cancelbtn', type: 'button', text: '取消', disabled: false },
        view_leftbtn: { name: 'leftbtn', type: 'button', text: '左移', disabled: true },
        view_rightbtn: { name: 'rightbtn', type: 'button', text: '右移', disabled: true },
        view_allleftbtn: { name: 'allleftbtn', type: 'button', text: '全部左移', disabled: true },
        view_allrightbtn: { name: 'allrightbtn', type: 'button', text: '全部右移', disabled: true },
        </#if>
        <#if view.getPSWorkflow?? && view.getPSWorkflow()??>
        wflinks: [],
        </#if>
    };

    /**
     * 视图操作参数
     *
     * @type {*}
     * @readonly
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public viewCtx: any = {};

<#if view.getXDataPSControl?? && view.getXDataPSControl()??>
<#assign dataControl = view.getXDataPSControl()/>
    /**
     * 视图刷新
     *
     * @param {*} args
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public refresh(args?: any): void {
        const refs: any = this.$refs;
        if (refs && refs.${dataControl.name}) {
            refs.${dataControl.name}.refresh();
        }
    }
</#if>
    /**
     *  计数器刷新
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public counterRefresh(){
        const _this:any =this;
        if(_this.counterServiceArray && _this.counterServiceArray.length >0){
            _this.counterServiceArray.forEach((item:any) =>{
                if(item.refreshData && item.refreshData instanceof Function){
                    item.refreshData();
                }
            })
        }
    }

    /**
     * 视图状态订阅对象
     *
     * @public
     * @type {Subject<{action: string, data: any}>}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public viewState: Subject<ViewState> = new Subject();
<#if view.hasPSControl('toolbar')>
${P.getCtrlCode('toolbar', 'CONTROL.vue').code}
</#if>
<#if view.getPSViewLayoutPanel()?? && !view.getPSViewLayoutPanel().isUseDefaultLayout() && view.getPSViewLayoutPanel().getAllPSPanelItems()??>
<#assign searchform=false />
<#list view.getPSViewLayoutPanel().getAllPSPanelItems() as panelDetail>
<#if panelDetail.getItemType()?? && panelDetail.getItemType() == "CTRLPOS" && panelDetail.getName() == 'searchform'>
<#assign searchform=true />
</#if>
</#list>
<#if searchform>
    /**
     * 快速搜索栏数据对象
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public quickFormData:any;

    /**
     * 快速搜索栏值变化
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public quickFormValueChange($event:any){
        this.quickFormData = $event;
        this.onSearch($event);
    }
</#if>

    /**
     * 视图布局顶级成员名称
     *
     * @public
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public rootLayoutDetailNames: string[] = <@compress  single_line=true>[
        <#if view.getPSViewLayoutPanel().getRootPSPanelItems?? && view.getPSViewLayoutPanel().getRootPSPanelItems()??>
        <#list view.getPSViewLayoutPanel().getRootPSPanelItems() as panelItem>
        '${panelItem.name}'<#if panelItem_has_next>,</#if>
        </#list>
        </#if>
        ];</@compress>
    <#assign panelItems = view.getPSViewLayoutPanel().getAllPSPanelItems() />
    <#assign type='VIEWLAYOUT' />
    <#assign item=view />
    <@getLayoutItemModel panelItems type view item/>

    <@initLayout item/>

    /**
     * 处理值改变
     *
     * @public
     * @params args 改变数据
     * @params index 多数据容器下标
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public handleValueChange(args: { name: string, value: any }, index?: number) {
        const { name, value } = args;
        <#noparse>let fullName = (index || index === 0) ? `${name}_${index}` : name;</#noparse>
        if (!fullName || !this.layoutData.hasOwnProperty(fullName)) {
            return;
        }
        this.layoutData[fullName] = value;
        this.layoutModelDetails[fullName].setData(value);
        this.panelLogic(name, index);
        this.computeButtonAuthState();
    }

    <#assign panelItems = view.getPSViewLayoutPanel().getAllPSPanelItems() />
    <@panelDynamicLogic panelItems item />

    <#assign panelItems = view.getPSViewLayoutPanel().getAllPSPanelItems() />
    <@handleButtonClick panelItems item />

    <#if view.getPSViewLayoutPanel().getPSAppViewUIActions()??>
    <#list view.getPSViewLayoutPanel().getPSAppViewUIActions() as viewUIAction>
    <#if viewUIAction.getPSUIAction?? && viewUIAction.getPSUIAction()??>
    <#assign uiAction = viewUIAction.getPSUIAction()/>
    <#if !P.exists("importService", uiAction.getFullCodeName(), "")>
    <#if !(uiAction.getPSAppDataEntity?? && uiAction.getPSAppDataEntity()??) || (uiAction.getPSAppDataEntity?? && uiAction.getPSAppDataEntity()?? && uiAction.getUIActionMode?? && (uiAction.getUIActionMode() == 'SYS' || uiAction.getUIActionMode() == 'CUSTOM'))>
    <@viewLayoutPanelUIAction item=uiAction />
    </#if>
    </#if>
    </#if>
    </#list>
    </#if>
</#if>