Blame view

ant-design-vue-jeecg/src/views/system/config/modules/AddressForm.vue 3.61 KB
肖超群 authored
1
2
3
4
5
6
<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
7
8
9
10
11
            <a-form-model-item label="接口名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入接口名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
肖超群 authored
12
            <a-form-model-item label="编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
13
              <a-input v-model="model.param" placeholder="请输入编码"></a-input>
肖超群 authored
14
15
16
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
17
18
            <a-form-item label="库区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zoneCode">
              <a-select show-search placeholder="请选择库区" option-filter-prop="children" v-model="model.zoneCode">
19
20
21
22
                <a-select-option v-for="item in zoneList" :key="item.name" :value="item.code">
                  {{ item.name }}
                </a-select-option>
              </a-select>
23
            </a-form-item>
肖超群 authored
24
25
26
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="接口地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="url">
肖超群 authored
27
              <a-input v-model="model.url" placeholder="请输入接口地址"></a-input>
肖超群 authored
28
29
30
31
32
33
34
35
36
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
37
38
39
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { getZoneList } from '@/api/api'
肖超群 authored
40
肖超群 authored
41
42
43
44
45
46
47
48
49
50
51
52
53
54
export default {
  name: 'AddressForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
55
      zoneList: [],
肖超群 authored
56
      labelCol: {
57
58
        xs: { span: 24 },
        sm: { span: 5 }
肖超群 authored
59
60
      },
      wrapperCol: {
61
62
        xs: { span: 24 },
        sm: { span: 16 }
肖超群 authored
63
64
65
66
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
67
68
69
        add: '/config/address/add',
        edit: '/config/address/edit',
        queryById: '/config/address/queryById'
肖超群 authored
70
      }
肖超群 authored
71
72
73
74
75
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
76
    }
肖超群 authored
77
78
79
  },
  created() {
    //备份model原始值
80
81
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
    this.loadFrom()
肖超群 authored
82
83
  },
  methods: {
84
    loadFrom() {
85
      getZoneList().then(res => {
86
87
88
        if (res.success) {
          this.zoneList = res.result
        }
89
90
91
92
93
94
95
96
      })
    },
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
97
    },
肖超群 authored
98
    submitForm() {
99
      const that = this
肖超群 authored
100
101
102
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
103
104
105
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
肖超群 authored
106
          if (!this.model.id) {
107
108
            httpurl += this.url.add
            method = 'post'
肖超群 authored
109
          } else {
110
111
            httpurl += this.url.edit
            method = 'put'
肖超群 authored
112
          }
113
          httpAction(httpurl, this.model, method).then(res => {
肖超群 authored
114
            if (res.success) {
115
116
              that.$message.success(res.message)
              that.$emit('ok')
肖超群 authored
117
            } else {
118
              that.$message.warning(res.message)
肖超群 authored
119
            }
120
121
122
          })
          .finally(() => {
            that.confirmLoading = false
肖超群 authored
123
124
125
          })
        }
      })
126
    }
肖超群 authored
127
  }
肖超群 authored
128
}
肖超群 authored
129
</script>