auto bind prop value to formGroup value

export class DeviceBatchControlComponent extends ComponentBase implements OnChanges {

  @Input() batchControlType: DeviceBatchControlType;

  @Input() deviceId: string;

  @Input() deviceIds: string[];

  @Input() groupId: string;

  @Input() sceneId: string;

  @Input() projectId: string;

  @Input() comPortName: string;

  @Input() batchControlCommonAjaxOption: AjaxOption<BatchControlDeviceEvent, any>;

  constructor(ioc: IocInject, protected afb: AjaxFormBuilder, protected dss: DeviceRefStorage, protected ses: SceneService, public projectProvider: DeviceProjectContextProvider, protected sceneStorage: SceneStorage, protected devSvc: DeviceService, protected detypes: DeviceTypeStorage) {

    super(ioc);

  }

  ngOnChanges(changes: SimpleChanges): void {

    // debugger    let cs = {};

    for (let key in changes) {

      if (key == ‘batchControlCommonAjaxOption’)continue;

      let c = changes[key];

      cs[key] = c.currentValue;

    }

    var ajax = this.batchControlCommonAjaxOption;

    if (ajax) ajax.formGroup.patchValue(cs);

    console.log(‘device-batch-control changed to’, cs);

  }

  onInit() {

    super.onInit();

    let deviceId = this.deviceId || this.navParams.get(‘deviceId’);

    let sceneId = this.sceneId || this.navParams.get(‘sceneId’);

    let groupId = this.groupId || this.navParams.get(‘groupId’);

    let projectId = this.projectId || this.navParams.get(‘projectId’);

    let comPortName = this.comPortName || this.navParams.get(‘comPortName’);

    {

      // 批量控制表单      //’ch_nums_for_crt’,’ch_color_for_crt’,      let ajax = this.batchControlCommonAjaxOption = this.afb

        .create<BatchControlDeviceEvent, any>(model => {

          //debugger          return this.devSvc.batchControl(model, [‘ch_nums_for_crt’, ‘ch_color_for_crt’, ‘blink_freq_for_crt’, ‘strength_for_crt’]);

        })

        .formGroup(form => {

          return form.group({

            propertyValues: form.group({

              blink_freq_for_crt: [],

              strength_for_crt: [],

              ch_nums_for_crt: [],

              ch_color_for_crt: [],

              onoff: [],

            }),

            batchControlType: [],

            groupId: [],

            sceneId: [],

            deviceIds: [],

          });

        }).defaultValue({

          sceneId: sceneId,

          groupId: groupId,

          deviceIds: deviceId ? [deviceId] : this.deviceIds,

          batchControlType: this.batchControlType,

          propertyValues: {

            ch_nums_for_crt: 1,

            ch_color_for_crt: 1,

          }

        })

        .doneAfterShow((result) => {

          console.log(‘done – >’, result);

        })

        .build();

      // ajax.formGroup.patchValue({sceneId: sceneId, groupId: groupId});    }

  }

  deviceSwitch(event) {

    // debugger;    this.batchControlCommonAjaxOption.submit((model) => {

      // debugger;      //currentTarget      let isOpen = event.checked;

      var v = isOpen ? 1 : 0;

      model.propertyValues[‘ch_nums_for_crt’] = v + ;

      model.propertyValues[‘ch_color_for_crt’] = v + ;

      return this.devSvc.batchControl(model, null);

    });

  }

}

发表评论

您的电子邮箱地址不会被公开。