{{>@macro/front-end/widgets/form-detail/include-form.hbs}}
import { ControlVOBase, EditFormService } from '@core';
import { {{pascalCase ctrl.psAppDataEntity.codeName}}Service } from '@api/{{spinalCase ctrl.psAppDataEntity.codeName}}/{{spinalCase ctrl.psAppDataEntity.codeName}}-service';

/**
 * 部件展示数据对象
 * @export
 * @class ControlVO
 */
export class ControlVO extends ControlVOBase {
  /**
   * 用后台数据对象创建部件数据对象
   * @param data 后台数据
   */
  constructor(data: any){
    super(data);
    // 记录没有映射的属性
    this.$ownKeys = 
  {{~#each ctrl.psDEFormItems as | formItem | ~}}
    {{#if @first}}[{{/if~}}
    '{{lowerCase formItem.id}}'{{#unless @last}},{{/unless}}
    {{~#if @last}}];{{/if~}}
  {{/each}}
  
  }

  // 表单里映射了属性的字段
  {{#each ctrl.psDEFormItems as | formItem | }}
    {{!-- TODO: 表单formItem的name拿不到 --}}
    {{#neq formItem.psAppDEField null }}
  get {{lowerCase formItem.id}}() {
    return this.$DO.{{lowerCase formItem.psAppDEField.codeName}};
  }
  set {{lowerCase formItem.id}}(value: any) {
    this.$DO.{{lowerCase formItem.psAppDEField.codeName}} = value;
  }

    {{/neq}}
  {{/each}}

  // 表单里没有映射实体属性的字段(srfuf除外)
  {{#each ctrl.psDEFormItems as | formItem | }}
    {{#if (and (eq formItem.psAppDEField null) (neq formItem.id "srfuf" )) }}
  {{lowerCase formItem.id}}: any;
    {{/if}}
  {{/each}}
}

// 部件配置对象
export const ctrlState = {
  controlCodeName: '{{ctrl.codeName}}',
  controlName: '{{ctrl.name}}',
  controlService: new EditFormService<ControlVO>(ControlVO, new {{pascalCase ctrl.psAppDataEntity.codeName}}Service() ),
  data: new ControlVO({}),
  {{#each ctrl.psAppDataEntity.allPSAppDEFields as | appDEField | }}
  {{#if appDEField.keyField}}
  appDeKeyFieldName: '{{appDEField.codeName}}',
  {{/if}}
  {{#if appDEField.majorField}}
  appDeMajorFieldName: '{{appDEField.codeName}}',
  {{/if}}
  {{/each}}
  enableAutoSave: {{ctrl.enableAutoSave}},
  detailsModel: {
  {{#if ctrl.psDEFormPages}}
    {{#each ctrl.psDEFormPages as | FormPage | }}
      {{>(lookup 'FORMDETAILSMODEL') formDetail=FormPage}}
    {{/each}}
  {{/if}}
  },
  actionModel: {
    {{#each ctrl.psDEFormPages as | FormPage | }}
    {{>(lookup 'FORMACTIONMODEL') items=FormPage.psDEFormDetails}}
    {{/each}}
  },
  rules: {
        {{#each ctrl.psDEFormItemVRs as | ruleItem |}}
          {{#if ruleItem.valueRuleType 'SYSVALUERULE'}}
          {{ruleItem.psDEFormItemName}}: [
            {
                trigger: ['change', 'blur'],
               {{#eq ruleItem.psSysValueRule.ruleType 'REG'}}
                pattern: /{{ruleItem.psSysValueRule.regExCode}}/,
               {{/eq}}
               message:'{{ruleItem.psSysValueRule.ruleInfo}}'
          }],
          {{/if}}
        {{/each}}
  },
};