Blame view

ant-design-vue-jeecg/src/views/jeecg/modules/JeecgOrderModalForJVexTable.vue 9.15 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
10
11
12
<template>
  <a-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :destroyOnClose="true"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel">

    <a-spin :spinning="confirmLoading">
肖超群 authored
13
      <a-form-model ref="form" :label-col="labelCol" :wrapper-col="wrapperCol" :model="model">
肖超群 authored
14
15
16
        <!-- 主表单区域 -->
        <a-row class="form-row" :gutter="0">
          <a-col :lg="8">
肖超群 authored
17
            <a-form-model-item label="订单号" prop="orderCode" :rules="[{ required: true, message: '请输入订单号!' }]">
肖超群 authored
18
19
20
21
              <a-input placeholder="请输入订单号" v-model="model.orderCode"/>
            </a-form-model-item>
          </a-col>
          <a-col :lg="8">
肖超群 authored
22
            <a-form-model-item label="订单类型">
肖超群 authored
23
24
25
26
27
28
29
              <a-select placeholder="请选择订单类型" v-model="model.ctype">
                <a-select-option value="1">国内订单</a-select-option>
                <a-select-option value="2">国际订单</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :lg="8">
肖超群 authored
30
            <a-form-model-item label="订单日期">
肖超群 authored
31
32
33
34
35
36
              <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" style="width: 100%" v-model="model.orderDate"/>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="0">
          <a-col :lg="8">
肖超群 authored
37
            <a-form-model-item label="订单金额">
肖超群 authored
38
39
40
41
              <a-input-number placeholder="请输入订单金额" style="width: 100%" v-model="model.orderMoney"/>
            </a-form-model-item>
          </a-col>
          <a-col :lg="8">
肖超群 authored
42
            <a-form-model-item label="订单备注">
肖超群 authored
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
              <a-input placeholder="请输入订单备注" v-model="model.content"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>

      <!-- 子表单区域 -->
      <a-tabs v-model="activeKey" @change="handleChangeTabs">
        <a-tab-pane tab="客户信息" key="1" :forceRender="true">
          <j-vxe-table
            ref="editableTable1"
            toolbar
            row-number
            row-selection
            keep-source
            :height="300"
            :loading="table1.loading"
            :dataSource="table1.dataSource"
            :columns="table1.columns"
            style="margin-top: 8px;"/>

        </a-tab-pane>

        <a-tab-pane tab="机票信息" key="2" :forceRender="true">
          <j-vxe-table
            ref="editableTable2"
            toolbar
            row-number
            row-selection
            keep-source
            :height="300"
            :loading="table2.loading"
            :dataSource="table2.dataSource"
            :columns="table2.columns"
            style="margin-top: 8px;"/>
        </a-tab-pane>
      </a-tabs>

    </a-spin>
  </a-modal>
</template>

<script>
肖超群 authored
87
88
89
90
91
import JEditableTable from '@/components/jeecg/JEditableTable'
import {VALIDATE_FAILED, getRefPromise, validateFormModelAndTables} from '@/components/jeecg/JVxeTable/utils/vxeUtils'
import {httpAction, getAction} from '@/api/manage'
import {JVXETypes} from '@/components/jeecg/JVxeTable'
import JDate from '@/components/jeecg/JDate'
肖超群 authored
92
肖超群 authored
93
94
95
96
97
98
99
100
101
102
103
104
105
106
export default {
  name: 'JeecgOrderModalForJvexTable',
  components: {
    JDate, JEditableTable
  },
  data() {
    return {
      title: '操作',
      visible: false,
      confirmLoading: false,
      model: {},
      labelCol: {
        xs: {span: 24},
        sm: {span: 6}
肖超群 authored
107
      },
肖超群 authored
108
109
110
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 24 - 6}
肖超群 authored
111
      },
肖超群 authored
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
      activeKey: '1',
      // 客户信息
      table1: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '客户名',
            key: 'name',
            width: '24%',
            type: JVXETypes.input,
            defaultValue: '',
            placeholder: '请输入${title}',
            validateRules: [{required: true, message: '${title}不能为空'}]
          },
          {
            title: '性别',
            key: 'sex',
            width: '18%',
            type: JVXETypes.select,
            options: [ // 下拉选项
              {title: '男', value: '1'},
              {title: '女', value: '2'}
            ],
            defaultValue: '',
            placeholder: '请选择${title}'
          },
          {
            title: '身份证号',
            key: 'idcard',
            width: '24%',
            type: JVXETypes.input,
            defaultValue: '',
            placeholder: '请输入${title}',
            validateRules: [{
              pattern: '^\\d{6}(18|19|20)?\\d{2}(0[1-9]|1[012])(0[1-9]|[12]\\d|3[01])\\d{3}(\\d|[xX])$',
              message: '${title}格式不正确'
            }]
          },
          {
            title: '手机号',
            key: 'telphone',
            width: '24%',
            type: JVXETypes.input,
            defaultValue: '',
            placeholder: '请输入${title}',
            validateRules: [{
              pattern: '^1(3|4|5|7|8)\\d{9}$',
              message: '${title}格式不正确'
            }]
肖超群 authored
162
          }
肖超群 authored
163
        ]
肖超群 authored
164
      },
肖超群 authored
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
      // 机票信息
      table2: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '航班号',
            key: 'ticketCode',
            width: '40%',
            type: JVXETypes.input,
            defaultValue: '',
            placeholder: '请输入${title}',
            validateRules: [{required: true, message: '${title}不能为空'}]
          },
          {
            title: '航班时间',
            key: 'tickectDate',
            width: '30%',
            type: JVXETypes.date,
            placeholder: '请选择${title}',
            defaultValue: ''
肖超群 authored
186
          }
肖超群 authored
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
        ]
      },
      url: {
        add: '/test/jeecgOrderMain/add',
        edit: '/test/jeecgOrderMain/edit',
        orderCustomerList: '/test/jeecgOrderMain/queryOrderCustomerListByMainId',
        orderTicketList: '/test/jeecgOrderMain/queryOrderTicketListByMainId'
      }
    }
  },
  created() {
  },
  methods: {

    // 获取所有的editableTable实例
    getAllTable() {
      return Promise.all([
        getRefPromise(this, 'editableTable1'),
        getRefPromise(this, 'editableTable2')
      ])
    },

    add() {
      // 默认新增一条数据
      this.getAllTable().then(editableTables => {
        //editableTables[0].add()
        //editableTables[1].add()
      })
      this.edit({})
    },
    edit(record) {
      this.visible = true
      this.activeKey = '1'
      this.model = Object.assign({}, record)
      // 加载子表数据
      if (this.model.id) {
        let params = {id: this.model.id}
        this.requestTableData(this.url.orderCustomerList, params, this.table1)
        this.requestTableData(this.url.orderTicketList, params, this.table2)
肖超群 authored
226
227
      }
肖超群 authored
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
    },
    close() {
      this.visible = false
      this.getAllTable().then(editableTables => {
        this.table1.dataSource = [];
        this.table2.dataSource = [];
      })
      this.$emit('close')
    },
    /** 查询某个tab的数据 */
    requestTableData(url, params, tab) {
      tab.loading = true
      getAction(url, params).then(res => {
        tab.dataSource = res.result || []
      }).finally(() => {
        tab.loading = false
      })
    },
    handleOk() {
      this.validateFields()
    },
    handleCancel() {
      this.close()
    },
    /** ATab 选项卡切换事件 */
    handleChangeTabs(key) {
      getRefPromise(this, `editableTable${key}`).then(editableTable => {
        editableTable.resetScrollTop()
      })
    },

    /** 触发表单验证 */
    validateFields() {
      this.getAllTable().then(tables => {
        /** 一次性验证主表和所有的次表 */
        return validateFormModelAndTables(this.$refs.form, this.model, tables)
      }).then(allValues => {
        let formData = this.classifyIntoFormData(allValues)
        // 发起请求
        return this.requestAddOrEdit(formData)
      }).catch(e => {
        if (e.error === VALIDATE_FAILED) {
          // 如果有未通过表单验证的子表,就自动跳转到它所在的tab
          this.activeKey = e.index == null ? this.activeKey : (e.index + 1).toString()
        } else {
          console.error(e)
        }
      })
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      let orderMain = Object.assign(this.model, allValues.formValue)
      return {
        ...orderMain, // 展开
        jeecgOrderCustomerList: allValues.tablesValue[0].tableData,
        jeecgOrderTicketList: allValues.tablesValue[1].tableData
      }
    },
    /** 发起新增或修改的请求 */
    requestAddOrEdit(formData) {
      let url = this.url.add, method = 'post'
      if (this.model.id) {
        url = this.url.edit
        method = 'put'
      }
      this.confirmLoading = true
      httpAction(url, formData, method).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.$emit('ok')
          this.close()
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.confirmLoading = false
      })
肖超群 authored
305
    }
肖超群 authored
306
肖超群 authored
307
  }
肖超群 authored
308
}
肖超群 authored
309
310
311
312
</script>

<style scoped>
</style>