{{>@macro/front-end/widgets/grid-detail/include-grid.hbs}}
import { ControlVOBase, IParam, GridService } 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);
  }
  {{#each ctrl.psDEGridDataItems as | dataItem |}}

  get {{lowerCase dataItem.name}}() {
    return this.$DO.{{lowerCase dataItem.psAppDEField.codeName}};
  }
  set {{lowerCase dataItem.name}}(value: any) {
    this.$DO.{{lowerCase dataItem.psAppDEField.codeName}} = value;
  }
  {{/each}}

}

export const ctrlState = {
  controlCodeName: '{{ctrl.codeName}}',
  controlName: '{{ctrl.name}}',
  appEntityCodeName:'{{ctrl.appEntity.codeName}}',
  controlService: new GridService<ControlVO>(ControlVO, new {{pascalCase ctrl.psAppDataEntity.codeName}}Service() ),
  items: [],
  selectedRowKeys: [],
  // 多数据部件分组
  mdCtrlGroup: {
    enableGroup: {{ctrl.enableGroup}},
    groupMode: "{{ctrl.groupMode}}",
    groupField: "{{lowerCase ctrl.groupPSAppDEField.codeName}}",
    {{#if ctrl.groupPSCodeList}}
    groupCodeList: {
      codeListTag: "{{ctrl.groupPSCodeList.codeName}}",
      codeListType: "{{ctrl.groupPSCodeList.codeListType}}",
    },
    {{/if}}
  },
  // 多数据部件排序
  mdCtrlSort: {
    noSort: {{ctrl.noSort}},
    minorSortDir: "{{#if ctrl.minorSortDir}}{{ctrl.minorSortDir}}{{/if}}",
    minorSortPSDEF: "{{ctrl.minorSortPSAppDEField.codeName}}",
  },
  // 多数据部件分页
  mdCtrlPaging: {
    enablePagingBar: {{ctrl.enablePagingBar}},
    current: 1,
    pageSize: {{#if ctrl.pagingSize}}{{ctrl.pagingSize}}{{else}}20{{/if}},
    pagination: {{#if ctrl.enablePagingBar}}{
      position: ['bottomRight'],
      defaultPageSize: {{#if ctrl.pagingSize}}{{ctrl.pagingSize}}{{else}}20{{/if}},
      showQuickJumper: true,
      showTotal: (total: number, range: IParam[]) => `显示 ${range[0]} - ${range[1]} 条数据，共 ${total} 条数据`,
      pageSizeOptions: ['10','20','50','100'],
    }{{else}}false{{/if}},
  },
  gridAgg: {
    aggMode: "{{ctrl.aggMode}}",
    aggData: [],
    {{#if ctrl.aggPSAppDataEntity}}
    aggEntity: "{{ctrl.aggPSAppDataEntity.codeName}}",
    aggDataSet: "{{ctrl.aggPSAppDEDataSet.codeName}}",
    {{/if}}
  },
  uAColumnModel:[
  {{#each ctrl.psDEGridColumns as | column |}}
    {{>(lookup 'UACOLUMNMODEL') item=column}}
  {{/each}}
  ],
  gridEditState:{
    {{#each ctrl.psDEGridEditItems as | column |}}
    {{#if column.codeName }}
    {{column.codeName}}:{},
    {{/if}}
    {{/each}}
  },
  columnsModel: [
    {{#if ctrl.enableGroup}}
    {{#if ctrl.groupPSAppDEField}}
    {
      title: "分组",
      align: "left",
      columnType: "GROUP",
      width: 100,
      resizable: true,
      ellipsis: true,
      dataIndex: "grid_group",
    },
    {{/if}}
    {{/if}}
    {{#each ctrl.psDEGridColumns as | column |}}
    {{>(lookup 'COLUMNMODEL') item=column}}
    {{/each}}
  ],
  // 是否单选
  isSingleSelect:{{#if ctrl.singleSelect}}{{ctrl.singleSelect}}{{else}}false{{/if}},
  rules:{
          {{#each ctrl.psDEGridEditItemVRs as | ruleItem |}}
            {{#if ruleItem.valueRuleType 'SYSVALUERULE'}}
            {{ruleItem.psDEGridEditItemName}}: [
              {
                  trigger: ['change', 'blur'],
                 {{#eq ruleItem.psSysValueRule.ruleType 'REG'}}
                  pattern: /{{ruleItem.psSysValueRule.regExCode}}/,
                 {{/eq}}
                 message:'{{ruleItem.psSysValueRule.ruleInfo}}'
            }],
            {{/if}}
          {{/each}}
  }
};