<#ibizinclude>
../../../@MACRO/LANG_FUN.ftl
</#ibizinclude>
    <#macro getres tempView>
    <#compress>
    <#if tempView.getPSAppDataEntity?? && tempView.getPSAppDataEntity()?? && tempView.getPSAppDataEntity().getMajorPSAppDERSs?? && tempView.getPSAppDataEntity().getMajorPSAppDERSs()??>
    <#assign appDataEneity = tempView.getPSAppDataEntity() />
    <#if appDataEneity.getMajorPSAppDERSs?? && appDataEneity.getMajorPSAppDERSs()??>
    [<#list appDataEneity.getMajorPSAppDERSs() as psDes><#if !P.exists("importService", psDes.getMajorPSAppDataEntity().getId(), "")>'${psDes.getMajorPSAppDataEntity().getCodeName()}'</#if></#list>]
    </#if>
    </#if>
    </#compress>
    </#macro>
    <#macro getreskey appEntity curEntity>
    <#compress>
    <#if appEntity.getMajorPSAppDERSs()??>
    <#list appEntity.getMajorPSAppDERSs() as appDeRs>
    <#if appDeRs.getMinorPSAppDataEntity().getCodeName() == curEntity.getCodeName()>
    ${appDeRs.getPSDER1N().getPSPickupDEField().getCodeName()?lower_case}
    </#if>
    </#list>
    </#if>
    </#compress>
    </#macro>
    <#if item.getPSViewLogic?? && item.getPSViewLogic()??>
    <#assign viewlogic = item.getPSViewLogic()/>
    /**
     * 打开新建数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof ${srfclassname('${view.name}')}
     */
    public newdata(args: any[],fullargs?:any[], params?: any, $event?: any, xData?: any) {
    <#if viewlogic.getPSAppUILogicRefViews?? && viewlogic.getPSAppUILogicRefViews()??>
    <#list viewlogic.getPSAppUILogicRefViews() as appUILogicRefView>
    <#if appUILogicRefView_index == 0><#assign curNewLogicRefView = appUILogicRefView /></#if>
    </#list>
    </#if>
        let localContext:any = <#if curNewLogicRefView?? && curNewLogicRefView.getPSNavigateContexts?? && curNewLogicRefView.getPSNavigateContexts()??><@getNavigateContext curNewLogicRefView /><#else>null</#if>;
        let localViewParam:any =<#if curNewLogicRefView?? && curNewLogicRefView.getPSNavigateParams?? && curNewLogicRefView.getPSNavigateParams()??><@getNavigateParams curNewLogicRefView /><#else>null</#if>;
    <#if viewlogic.isEnableWizardAdd()>
        <#if viewlogic.getWizardPSAppView?? && viewlogic.getWizardPSAppView()??>
        <#assign wizardAppView = viewlogic.getWizardPSAppView() />
        let wizardAppView:any = {viewname:'${srffilepath2(wizardAppView.getCodeName())}',height: ${wizardAppView.getHeight()?c},width: ${wizardAppView.getWidth()?c},title: '${wizardAppView.title}'};
        let container: Subject<any> = this.$appmodal.openModal(wizardAppView, JSON.parse(JSON.stringify(this.context)), args[0]);
        container.subscribe((result: any) => {
            if (!result || !Object.is(result.ret, 'OK')) {
                return;
            }
            if(result && result.datas && result.datas.length >0 ){
                let targetkey:string = result.datas[0].srfkey;
                <#if viewlogic.getNewDataPSAppViews?? && viewlogic.getNewDataPSAppViews()??>
                let newDataAppViews:any ={
                <#list viewlogic.getNewDataPSAppViews() as newDataAppView>
                <#compress>${newDataAppView.getRefMode()}:<#if newDataAppView.isPSDEView()><#assign appDataEntity = newDataAppView.getPSAppDataEntity() />[{ pathName: '${srfpluralize(appDataEntity.codeName)?lower_case}', parameterName: '${appDataEntity.getCodeName()?lower_case}' },{ pathName: '${newDataAppView.getPSDEViewCodeName()?lower_case}', parameterName: '${newDataAppView.getPSDEViewCodeName()?lower_case}' }]<#else>[]</#if><#if newDataAppView_has_next>,</#if></#compress>
                </#list>
                };
                </#if>
                const data: any = {};
                if(args[0].srfsourcekey) data.srfsourcekey = args[0].srfsourcekey;
                let tempContext = JSON.parse(JSON.stringify(this.context));
                const openIndexViewTab = (data: any) => {
                    const _data: any = { w: (new Date().getTime()) };
                    Object.assign(_data, data);
                    const routePath = this.$viewTool.buildUpRoutePath(this.$route, tempContext, [], newDataAppViews[targetkey], args, _data);
                    this.$router.push(routePath);
                }
                openIndexViewTab(data);
            }
        })
        <#else>
        this.$Notice.warning({ title: '错误', desc: '请添加新建数据向导视图' });
        </#if>
    <#elseif viewlogic.isEnableBatchAdd()>
        <#--  批量添加  -->
        let batchAddPSAppViews:Array<any>=[];
        <#if viewlogic.getBatchAddPSAppViews??  &&  viewlogic.getBatchAddPSAppViews()??>
        <#assign batchAddPSAppViews = viewlogic.getBatchAddPSAppViews()/>
        batchAddPSAppViews=[
        <#list batchAddPSAppViews as batchAddPSAppView>
            {view:{viewname:'${srffilepath2(batchAddPSAppView.getCodeName())}',height: ${batchAddPSAppView.getHeight()?c},width: ${batchAddPSAppView.getWidth()?c},title: '${batchAddPSAppView.title}'},
            res:<@getres tempView=batchAddPSAppView /><#if batchAddPSAppView.getPSAppDataEntity()??><#assign appDataEntity= batchAddPSAppView.getPSAppDataEntity()/>,
            'resAppKey':'<@getreskey appEntity=appDataEntity curEntity=view.getPSAppDataEntity() />'</#if>}<#if batchAddPSAppView_has_next>,</#if>
        </#list>
        ];
        </#if>
        if(batchAddPSAppViews.length == 0 || !this.context.srfparentdename){
            this.$Notice.warning({ title: '错误', desc: '批量添加需添加N:N关系' });
            return;
        }
        let openViewModel:any = batchAddPSAppViews.find((item:any) =>{
            return (item.res && (item.res[0] !== this.context.srfparentdename));
        })
        let otherViewModel:any = batchAddPSAppViews.find((item:any) =>{
            return (item.res && (item.res[0] == this.context.srfparentdename));
        })
        let container: Subject<any> = this.$appmodal.openModal(openViewModel.view, JSON.parse(JSON.stringify(this.context)), args[0]);
        container.subscribe((result: any) => {
            if (!result || !Object.is(result.ret, 'OK')) {
                return;
            }
            if(result.datas && result.datas.length == 0){
                return;
            }
            let requestParam:Array<any> = [];
            result.datas.forEach((record:any) => {
                let tempParam:any = {};
                tempParam[otherViewModel.resAppKey] = this.context['srfparentkey'];
                tempParam[openViewModel.resAppKey] = record.srfkey;
                requestParam.push(tempParam);
            });
            this.appEntityService.createBatch(JSON.parse(JSON.stringify(this.context)),requestParam,true).then((response:any) =>{
                if (!response || response.status !== 200) {
                    this.$Notice.error({ title: '错误', desc: '批处理操作失败' });
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        });
    <#elseif viewlogic.isBatchAddOnly()>
        this.$Notice.warning({ title: '错误', desc: '只支持批添加未实现' });
    <#elseif viewlogic.getNewDataPSAppView()??>
        <#assign dataview = viewlogic.getNewDataPSAppView()/>
        const data: any = {};
        if(args[0].srfsourcekey){
            data.srfsourcekey = args[0].srfsourcekey;
        }
        let tempContext = JSON.parse(JSON.stringify(this.context));
        <#if dataview.isPSDEView()>
        <#assign appDataEntity = dataview.getPSAppDataEntity()/>
        delete tempContext.${appDataEntity.getCodeName()?lower_case};
        </#if>
        if(args.length >0){
            Object.assign(tempContext,args[0]);
        }
        <#-- BEGIN:导航参数 -->
        <#if curNewLogicRefView?? && curNewLogicRefView.getPSNavigateContexts?? && curNewLogicRefView.getPSNavigateContexts()??>
        if(localContext && Object.keys(localContext).length >0){
            let _context:any = this.$util.computedNavData(args[0],this.context,this.viewparams,localContext);
            Object.assign(tempContext,_context);
        }
        </#if>
        <#if curNewLogicRefView?? && curNewLogicRefView.getPSNavigateParams?? && curNewLogicRefView.getPSNavigateParams()??>
        if(localViewParam && Object.keys(localViewParam).length >0){
            let _param:any = this.$util.computedNavData(args[0],this.context,this.viewparams,localViewParam);
            Object.assign(data,_param);
        }
        </#if>
        <#-- END:导航参数 -->
        <#--  BEGIN:准备参数  -->
        <#--  BEGIN:是否应用实体视图  -->
        <#if dataview.isPSDEView()>
        <#-- 存在关系start -->
        <#if dataview.getPSAppDERSPathCount() gt 0>
        <#list 1..dataview.getPSAppDERSPathCount() as count>
        <#assign condition = ''/>
        <#list dataview.getPSAppDERSPath(count_index)  as deRSPath>
            <#if deRSPath.getMajorPSAppDataEntity?? && deRSPath.getMajorPSAppDataEntity()??>
                <#assign _dataEntity = deRSPath.getMajorPSAppDataEntity()/>
                <#assign condition>${condition}tempContext.${_dataEntity.getCodeName()?lower_case} && </#assign>
            </#if>
        </#list>
        </#list>
        let deResParameters: any[] = [];
        <#-- 如果是主实体需对context判断start -->
        <#if dataview.getPSAppDataEntity().isMajor()>
        if(${condition}true){
            deResParameters = [
            <#list dataview.getPSAppDERSPath(dataview.getPSAppDERSPathCount() - 1) as deRSPath>
            <#assign majorPSAppDataEntity = deRSPath.getMajorPSAppDataEntity()/>
            { pathName: '${srfpluralize(majorPSAppDataEntity.codeName)?lower_case}', parameterName: '${majorPSAppDataEntity.getCodeName()?lower_case}' },
            </#list>
            ]
        }
        <#else>
        deResParameters = [
            <#list dataview.getPSAppDERSPath(dataview.getPSAppDERSPathCount() - 1) as deRSPath>
            <#assign majorPSAppDataEntity = deRSPath.getMajorPSAppDataEntity()/>
            { pathName: '${srfpluralize(majorPSAppDataEntity.codeName)?lower_case}', parameterName: '${majorPSAppDataEntity.getCodeName()?lower_case}' },
            </#list>
        ];
        </#if>
        <#-- 如果是主实体需对context判断end -->
        <#else>
        const deResParameters: any[] = [];
        </#if>
        <#-- 存在关系end -->
        <#else>
        const deResParameters: any[] = [];
        </#if>
        <#--  END:是否应用实体视图  -->       
        <#if dataview.getOpenMode() == 'INDEXVIEWTAB' || dataview.getOpenMode() == ''>
        <#--  BEGIN:是否应用实体视图  -->
        <#if dataview.isPSDEView()>
        <#assign appDataEntity = dataview.getPSAppDataEntity()/>
        const parameters: any[] = [
            { pathName: '${srfpluralize(appDataEntity.codeName)?lower_case}', parameterName: '${appDataEntity.getCodeName()?lower_case}' },
            { pathName: '${dataview.getPSDEViewCodeName()?lower_case}', parameterName: '${dataview.getPSDEViewCodeName()?lower_case}' },
        ];
        <#else>
        const parameters: any[] = [
            { pathName: '${dataview.getCodeName()?lower_case}', parameterName: '${dataview.getCodeName()?lower_case}' },
        ];
        </#if>
        <#--  END:是否应用实体视图  -->
        <#else>
        <#--  BEGIN:是否应用实体视图  -->
        <#if dataview.isPSDEView()>
        <#assign appDataEntity = dataview.getPSAppDataEntity()/>
        const parameters: any[] = [
            { pathName: '${srfpluralize(appDataEntity.codeName)?lower_case}', parameterName: '${appDataEntity.getCodeName()?lower_case}' },
        ];
        <#else>
        const parameters: any[] = [];
        </#if>
        <#--  END:是否应用实体视图  -->
        </#if>
        <#--  END:准备参数  -->
        <#if dataview.getOpenMode() == 'INDEXVIEWTAB' || dataview.getOpenMode() == ''>
        <#--  打开顶级分页视图  -->
        const _this: any = this;
        const openIndexViewTab = (data: any) => {
            const _data: any = { w: (new Date().getTime()) };
            Object.assign(_data, data);
            const routePath = this.$viewTool.buildUpRoutePath(this.$route, tempContext, deResParameters, parameters, args, _data);
            this.$router.push(routePath);
        }
        openIndexViewTab(data);
        <#elseif dataview.getOpenMode() == 'POPUPAPP'>
        <#--  打开独立程序弹出  -->
        const _this: any = this;
        const routePath = this.$viewTool.buildUpRoutePath(this.$route, tempContext, deResParameters, parameters, args, data);
        window.open('./#'+routePath, '_blank');
        <#elseif dataview.getOpenMode() = 'POPUPMODAL'>
        <#--  打开模态  -->
        const _this: any = this;
        const openPopupModal = (view: any, data: any) => {
            let container: Subject<any> = this.$appmodal.openModal(view, tempContext, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: '${srffilepath2(dataview.getCodeName())}', 
            height: ${dataview.getHeight()?c}, 
            width: ${dataview.getWidth()?c},  
            title: this.<@getViewLanguageTitle dataview />,
        };
        openPopupModal(view, data);
        <#elseif dataview.getOpenMode()?index_of('DRAWER') == 0>
        <#--  打开抽屉  -->
        const _this: any = this;
        const openDrawer = (view: any, data: any) => {
            let container: Subject<any> = this.$appdrawer.openDrawer(view, tempContext, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: '${srffilepath2(dataview.getCodeName())}', 
            height: ${dataview.getHeight()?c}, 
            width: ${dataview.getWidth()?c},  
            title: this.<@getViewLanguageTitle dataview />,
            placement: '${dataview.getOpenMode()}',
        };
        openDrawer(view, data);
        <#elseif dataview.getOpenMode() == 'POPOVER'>
        <#--  打开气泡卡片  -->
        const _this: any = this;
        const openPopOver = (view: any, data: any) => {
            let container: Subject<any> = this.$apppopover.openPop($event, view, tempContext,data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: '${srffilepath2(dataview.getCodeName())}', 
            height: ${dataview.getHeight()?c}, 
            width: ${dataview.getWidth()?c},  
            title: this.<@getViewLanguageTitle dataview />, 
            placement: '${dataview.getOpenMode()}',
        };
        openPopOver(view, data);
        <#else>
        this.$Notice.warning({ title: '错误', desc: this.<@getViewLanguageTitle dataview />+'不支持该模式打开' });
        </#if>
    <#else>
    this.$Notice.warning({ title: '错误', desc: '未指定关系视图' });
    </#if>
    }
    </#if>