import { IParam, UIServiceBase } from '@core';
import { AppFrontAction, AppBackendAction } from '@core';
/**
 * {{appEntity.logicName}}UI服务对象基类
 *
 * @export
 * @class {{pascalCase appEntity.codeName}}UIServiceBase
 * @extends {UIServiceBase}
 */
export class {{pascalCase appEntity.codeName}}UIServiceBase extends UIServiceBase {

    /**
      * Creates an instance of {{pascalCase appEntity.codeName}}UIServiceBase
      * 
      * @param {*} [opts={}]
      * @memberof {{pascalCase appEntity.codeName}}UIServiceBase
      */
    constructor(opts: IParam = {}) {
        super(opts);
        this.initBasicData();
    }

    /**
     * 初始化基础数据
     *
     * @memberof {{pascalCase appEntity.codeName}}UIServiceBase
     */
    public initBasicData() {
        // 应用实体主键属性
        this.appDeKeyFieldName = '{{lowerCase appEntity.pSDataEntity.keyPSDEField.codeName}}';
        // 是否启用主状态
        this.isEnableDEMainState = {{#if appEntity.allPSDEMainStates}}true{{else}}false{{/if}};
        {{#if appEntity.pSDataEntity.dEMainStateDEFields}}
        // 主状态属性集合
        this.mainStateFields = [
        {{~#each appEntity.pSDataEntity.dEMainStateDEFields as | mainStateDEField |~}}
        '{{lowerCase mainStateDEField.codeName}}'{{#unless @last}},{{/unless}}
        {{~/each~}}
        ];
        {{/if}}
        {{#if appEntity.allPSDEMainStates}}
        // 主状态集合Map
        {{#each appEntity.allPSDEMainStates as | mainState |}}
        this.allDeMainStateMap.set('{{mainState.mSTag}}', '{{mainState.mSTag}}');
        {{/each}}
         // 主状态操作标识Map
        {{#each appEntity.allPSDEMainStates as | mainState |}}
        this.allDeMainStateOPPrivsMap.set(
			'{{mainState.mSTag}}',
			Object.assign({ {{#each appEntity.allPSDEOPPrivs as | deOPPriv |}}'{{deOPPriv.name}}':{{#if deOPPriv.oPPrivAllowMode}}1{{else}}0{{/if}}{{#unless @last}},{{/unless}}{{/each}} }, { {{#each mainState.pSDEMainStateOPPrivs as | deMainStateOPPriv |}}'{{deMainStateOPPriv.name}}':{{#if deMainStateOPPriv.oPPrivAllowMode}}1{{else}}0{{/if}}{{#unless @last}},{{/unless}}{{/each}} })
		);
        {{/each}}
        {{/if}}
    }

  {{!--  遍历界面行为   --}}
  {{~#each appEntity.appDEUIActions as | appDEUIAction | }}
    /**
     * {{appDEUIAction.caption}}
     *
     * @param {*} params
     * @memberof {{pascalCase appEntity.codeName}}UIServiceBase
     */
    public async {{appDEUIAction.codeName}}(uiAction:any, params:any){
        const actionModel =  {
             codeName:'{{appDEUIAction.codeName}}',
             uIActionMode:'{{appDEUIAction.UIActionMode}}',
             actionTarget:'{{upperCase appDEUIAction.actionTarget}}',
             uIActionTag:'{{upperCase appDEUIAction.uIActionTag}}',
             frontPSAppView:'{{appDEUIAction.frontPSAppView}}',
             caption:'{{appDEUIAction.caption}}',
             entityCodeName:'{{appEntity.codeName}}',
             methodCodeName:'{{appDEUIAction.methodCodeName}}',
             frontProcessType:'{{appDEUIAction.frontProcessType}}',
             refreshMode:'{{appDEUIAction.refreshMode}}',
             htmlPageUrl:'{{appDEUIAction.htmlPageUrl}}',
             uILogicAttachMode:'{{appDEUIAction.uILogicAttachMode}}',
             nextActionCodeName:'{{appDEUIAction.nextActionCodeName}}',
             navContexts:{{appDEUIAction.navContexts}},
             navParams:{{appDEUIAction.navParams}}
         };
      {{#eq appDEUIAction.UIActionMode 'FRONT'}}
        AppFrontAction.doAction(actionModel, params);
      {{/eq}}
      {{#eq appDEUIAction.UIActionMode 'BACKEND'}}
        AppBackendAction.doAction(actionModel, params);
      {{/eq}}
    }

  {{/each}}


}