<template>
    ${P.getPartCode(item,'PANEL').code}
</template>
// 基于 @CONTROL/面板/CONTROL-BASE.vue.ftl 生成
<#assign import_block>
import { PanelDetailModel,PanelRawitemModel,PanelTabPanelModel,PanelTabPageModel,PanelFieldModel,PanelContainerModel,PanelControlModel,PanelUserControlModel,PanelButtonModel } from '@/model/panel-detail';
import ${srfclassname('${ctrl.codeName}')}Model from './${srffilepath2(ctrl.codeName)}-${ctrl.getControlType()?lower_case}-model';
import CodeListService from "@/codelist/codelist-service";
import UIService from '@/uiservice/ui-service';
</#assign>
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>
<#ibizinclude>
../../@MACRO/PANEL.ftl
</#ibizinclude>
<#ibizinclude>
../../@VIEW/@MACRO/VIEW_LAYOUTPANEL/VIEW_LAYOUTPANEL_UIACTION/VIEW_LAYOUTPANEL_UIACTION.ftl
</#ibizinclude>
    /**
     * 接口实现
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    getDatas(): any[] {
        if (!this.layoutData) {
            return [];
        }
        return [this.layoutData];
    }

    /**
     * 接口实现
     *
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    getData() {
        return this.layoutData;
    }

    /**
     * 父级部件引用
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Prop() public parentRef?: any;

    /**
     * 面板数据对象
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Prop() public inputData?: any;

    /**
     * 操作栏模型数据
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Prop() public actionModel?: any;

    /**
     * UI数据对象
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public data:any = {};

    /**
     * 数据模型对象
     *
     * @type {${srfclassname('${ctrl.codeName}')}Model}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public dataModel:${srfclassname('${ctrl.codeName}')}Model = new ${srfclassname('${ctrl.codeName}')}Model();

    /**
     * 代码表服务对象
     *
     * @type {CodeListService}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public codeListService:CodeListService = new CodeListService();

    <#if appde??>
    /**
     * 界面UI服务对象
     *
     * @type {${srfclassname('${appde.getCodeName()}')}UIService}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */  
    public appUIService:${srfclassname('${appde.getCodeName()}')}UIService = new ${srfclassname('${appde.getCodeName()}')}UIService();
    <#else>
    /**
     * 界面UI服务对象
     *
     * @type {UIService}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */  
    public appUIService:UIService = new UIService();
    </#if>

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

    <@initLayout item/>


    /**
     * 监听数据对象
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    @Watch('inputData', { deep: true, immediate: true } )
    public onInputDataChange(newVal: any, oldVal: any){
        if(newVal){
            this.computedUIData(newVal);
        }
    }

    /**
     * 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public mounted () {
        this.afterMounted();
    }

    /**
     * 执行mounted后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public afterMounted () {
        const _this: any = this;
        _this.initLayout().then((result: any) => {
            _this.isLayoutLoadding = false;
        });
    }

    /**
     * 计算UI展示数据
     * 
     * @param codelistArray 代码表模型数组
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public computedUIData(newVal:any){
        if((this.dataModel.getDataItems instanceof Function) && this.dataModel.getDataItems().length >0){
            this.dataModel.getDataItems().forEach((item:any) =>{
                this.data[item.prop] = newVal[item.prop];
            })
        }
    }

    /**
     * 打开编辑数据视图
     *
     * @type {any}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public opendata(args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any){
        if (this.parentRef.opendata && this.parentRef.opendata instanceof Function) {
            this.parentRef.opendata(args,fullargs,params, $event, xData);
        }
    }

    /**
     * 打开新建数据视图
     *
     * @type {any}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public newdata(args: any[],fullargs?:any[], params?: any, $event?: any, xData?: any) {
        if (this.parentRef.newdata && this.parentRef.newdata instanceof Function) {
            this.parentRef.newdata(args,fullargs,params, $event, xData);
        }
    }
    
    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public async remove(datas: any[]): Promise<any> {
        if (this.parentRef.remove && this.parentRef.remove instanceof Function) {
            return this.parentRef.remove(datas);
        }
    }

    /**
     * 刷新
     *
     * @param {*} [args={}]
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public refresh(args: any = {}) {
        if (this.parentRef.refresh && this.parentRef.refresh instanceof Function) {
            this.parentRef.refresh(args);
        }
    }

    /**
     * 处理值改变
     *
     * @public
     * @params args 改变数据
     * @params index 多数据容器下标
     * @memberof ${srfclassname('${ctrl.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.panelEditItemChange(name, value);
        this.computeButtonAuthState();
    }

    /**
     * 面板编辑项值变化后续操作
     *
     * @public
     * @param property 编辑项名
     * @param value 编辑项值
     * @returns {void}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public panelEditItemChange(property: string, value: any){
        // 面板数据变化事件
        if((this.dataModel.getDataItems instanceof Function) && this.dataModel.getDataItems().length >0){
            let modelitem =this.dataModel.getDataItems().find((item:any) =>{
                return item.name === property;
            }) 
            if(modelitem){
                this.$emit('panelDataChange',{[modelitem.prop]: value});
            }
        }
    }

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

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

    <#if ctrl.getPSUIActions?? && ctrl.getPSUIActions()??>
    <#list ctrl.getPSUIActions() as uiAction>
    <#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>
    </#list>
    </#if>

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

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