Blame view

src/Form/Form.js 1.39 KB
3a3ecabe   Imshann   init
1
2
3
4
5
6
  import template from "./Form.html";
  import style from "antd/lib/form/style/index.css";
  
  class Form {
      useModules = ["esNgAntd"];
  
dd962f77   Imshann   优化
7
8
      template = template;
  
3a3ecabe   Imshann   init
9
10
11
12
13
      props = {
          name: String,
          labelCol: Object,
          wrapperCol: Object,
          onFinish: Function,
dd962f77   Imshann   优化
14
15
16
17
          form: Object,
      };
  
      state = {
a468667f   Imshann   优化
18
          formItems: [],
3a3ecabe   Imshann   init
19
      };
3a3ecabe   Imshann   init
20
21
22
23
  
      constructor() {
          esNgAntd.createStyle("ant-form", style);
  
dd962f77   Imshann   优化
24
25
          this.form = $scope;
  
3a3ecabe   Imshann   init
26
27
28
29
30
31
32
33
34
          if (this.props.name) {
              let inputs = $element[0].querySelectorAll("input");
              for (let i = 0; i < inputs.length; i++) {
                  const element = inputs[i];
                  element.id = this.props.name + "_" + element.id;
              }
          }
      }
  
dd962f77   Imshann   优化
35
36
      resetFields() {
          this.state.formItems.forEach(function (item) {
a468667f   Imshann   优化
37
38
39
40
41
42
              if (typeof item.setValue === "function") {
                  item.setValue(item.defaultValue || null);
              } else {
                  item.value = null;
              }
          });
dd962f77   Imshann   优化
43
44
      }
  
061629e7   Imshann   add
45
46
47
48
      submit() {
          this.handleSubmit();
      }
  
3a3ecabe   Imshann   init
49
50
      handleSubmit() {
          let values = {};
dd962f77   Imshann   优化
51
52
53
54
          this.state.formItems.forEach(function (item) {
              let name = item.esFormItem && item.esFormItem.name;
              let value = item.value || item.state.value || null;
              values[name] = value;
a468667f   Imshann   优化
55
          });
3a3ecabe   Imshann   init
56
57
58
59
60
          this.props.onFinish({
              values: values,
          });
      }
  }