import { ControlVOBase, IParam, ListService, isEmpty, Verify } from '@core';
import { {{pascalCase ctrl.psAppDataEntity.codeName}}Service } from '@api/{{spinalCase ctrl.psAppDataEntity.codeName}}/{{spinalCase ctrl.psAppDataEntity.codeName}}-service';

export class ControlVO extends ControlVOBase {
	constructor(data: any){
    super(data);
    //  列表自持属性
    this.$ownKeys = 
  {{~#each ctrl.psDEListDataItems as | dataItem | ~}}
    {{#if @first}}[{{/if~}}
    '{{lowerCase dataItem.name}}'{{#unless @last}},{{/unless}}
    {{~#if @last}}];{{/if~}}
  {{/each}}
  
  }

	{{#each ctrl.psDEListDataItems as | dataItem |}}
		{{#if dataItem.psAppDEField}}
  get {{lowerCase dataItem.name}}() {
    return this.$DO.{{lowerCase dataItem.psAppDEField.codeName}};
  }
  set {{lowerCase dataItem.name}}(value: any) {
    this.$DO.{{lowerCase dataItem.psAppDEField.codeName}} = value;
  }
		{{/if}}
    {{#if dataItem.customCode}}
  get {{lowerCase dataItem.name}}() {
    let scriptCode: any = `{{dataItem.scriptCode}}`;
    if (scriptCode.indexOf('return') !== -1) {
      scriptCode = scriptCode.replace(new RegExp('return', "g"), '');
    }
    return scriptCode;
  }
    {{/if}}

	{{/each}}
}

export const ctrlState = {
	controlCodeName: '{{ctrl.codeName}}',
	controlName: '{{ctrl.name}}',
	appEntityCodeName: '{{ctrl.psAppDataEntity.codeName}}',
	appDeCodeName:'{{ctrl.psAppDataEntity.codeName}}',
	appDeLogicName: '{{ctrl.psAppDataEntity.logicName}}',
	appDeKeyFieldName: '{{#if ctrl.psAppDataEntity.keyPSAppDEField}}{{ctrl.psAppDataEntity.keyPSAppDEField.codeName}}{{/if}}',
	appDeMajorFieldName: '{{#if ctrl.psAppDataEntity.majorPSAppDEField}}{{ctrl.psAppDataEntity.majorPSAppDEField.codeName}}{{/if}}',
	controlService: new ListService<ControlVO>(ControlVO, new {{pascalCase ctrl.psAppDataEntity.codeName}}Service() ),
  selections: [],
  dataItems: [
    {{#if ctrl.psDEListDataItems}}
    {{#each ctrl.psDEListDataItems as | dataItem |}}
    {
      name: '{{dataItem.name}}',
      caption: '{{dataItem.caption}}',
      {{#if dataItem.customCode}}
      customCode: true,
      {{/if}}
      {{#if dataItem.psAppDEField}}
      property: '{{lowerCase dataItem.psAppDEField.codeName}}'
      {{/if}}
    }{{#unless @last}},{{/unless}}
    {{/each}}
    {{/if}}
  ],
	// 多数据部件分组
  mdCtrlGroup: {
    enableGroup: {{ctrl.enableGroup}},
    groupMode: "{{ctrl.groupMode}}",
    groupField: "{{lowerCase ctrl.groupPSAppDEField.codeName}}",
    {{#if ctrl.groupPSCodeList}}
    groupCodeList: {
      codeListTag: "{{ctrl.groupPSCodeList.codeListTag}}",
      codeListType: "{{ctrl.groupPSCodeList.codeListType}}",
    },
    {{/if}}
  },
  // 多数据部件排序
  mdCtrlSort: {
    noSort: {{ctrl.noSort}},
    minorSortDir: "{{#if ctrl.minorSortDir}}{{ctrl.minorSortDir}}{{/if}}",
    minorSortPSDEF: "{{ctrl.minorSortPSAppDEField.codeName}}",
  },
  // 多数据部件分页
  mdCtrlPaging: {
    enablePagingBar: true,
    current: 1,
    pageSize: {{#if ctrl.pagingSize}}{{ctrl.pagingSize}}{{else}}20{{/if}},
    pagination: {}
  },
	//	界面行为
	uIActions: {
	{{#each ctrl.psDEListItems as | listItem |}}
		{{#and listItem.psDEUIActionGroup listItem.psDEUIActionGroup.psUIActionGroupDetails}}
			{{#listItem}}
				{{#each psDEUIActionGroup.psUIActionGroupDetails as | uiActionDetail |}}
					{{#if uiActionDetail.getPSUIAction}}
						{{#uiActionDetail.getPSUIAction}}
		{{uIActionTag}}: { caption: '{{caption}}', tooltip: '{{tooltip}}', showCaption: {{../showCaption}}, showIcon: {{../showIcon}}, uIActionTag: '{{uIActionTag}}', uIActionType: '{{uIActionType}}', dataAccessAction: '{{dataAccessAction}}', noPrivDisplayMode: '{{noPrivDisplayMode}}', uIActionMode: '{{uIActionMode}}', disabled: false, visible: true, {{#if coutnerId}}counterId: '{{counterId}}', {{/if}}{{#if psSysImage}}cssClass: '{{psSysImage.cssClass}}', {{#if psSysImage.cssClass}}{{/if}}{{#if psSysImage.imagePath}}imagePath: '{{psSysImage.imagePath}}'{{/if}}{{/if}} },
						{{/uiActionDetail.getPSUIAction}}
					{{/if}}
				{{/each}}
			{{/listItem}}
		{{/and}}
	{{/each}}
	}
}