3b98e59bfd144fba77b886249b5667a5b6b28701.svn-base 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <a-modal
  3. :title="title"
  4. :width="1200"
  5. :visible="visible"
  6. :maskClosable="false"
  7. :confirmLoading="confirmLoading"
  8. @ok="handleOk"
  9. @cancel="handleCancel">
  10. <a-spin :spinning="confirmLoading">
  11. <a-form-model ref="form" :label-col="labelCol" :wrapper-col="wrapperCol" :model="model" >
  12. <!-- 主表单区域 -->
  13. <a-row class="form-row" :gutter="0">
  14. <a-col :lg="8">
  15. <a-form-model-item label="订单号" prop="orderCode" :rules="[{ required: true, message: '请输入订单号!' }]">
  16. <a-input placeholder="请输入订单号" v-model="model.orderCode"/>
  17. </a-form-model-item>
  18. </a-col>
  19. <a-col :lg="8">
  20. <a-form-model-item label="订单类型">
  21. <a-select placeholder="请选择订单类型" v-model="model.ctype">
  22. <a-select-option value="1">国内订单</a-select-option>
  23. <a-select-option value="2">国际订单</a-select-option>
  24. </a-select>
  25. </a-form-model-item>
  26. </a-col>
  27. <a-col :lg="8">
  28. <a-form-model-item label="订单日期">
  29. <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" style="width: 100%" v-model="model.orderDate"/>
  30. </a-form-model-item>
  31. </a-col>
  32. </a-row>
  33. <a-row class="form-row" :gutter="0">
  34. <a-col :lg="8">
  35. <a-form-model-item label="订单金额">
  36. <a-input-number placeholder="请输入订单金额" style="width: 100%" v-model="model.orderMoney"/>
  37. </a-form-model-item>
  38. </a-col>
  39. <a-col :lg="8">
  40. <a-form-model-item label="订单备注">
  41. <a-input placeholder="请输入订单备注" v-model="model.content"/>
  42. </a-form-model-item>
  43. </a-col>
  44. </a-row>
  45. </a-form-model>
  46. <!-- 子表单区域 -->
  47. <a-tabs v-model="activeKey" @change="handleChangeTabs">
  48. <a-tab-pane tab="客户信息" key="1" :forceRender="true">
  49. <j-editable-table
  50. ref="editableTable1"
  51. :loading="table1.loading"
  52. :columns="table1.columns"
  53. :dataSource="table1.dataSource"
  54. :maxHeight="300"
  55. :rowNumber="true"
  56. :rowSelection="true"
  57. :actionButton="true"/>
  58. </a-tab-pane>
  59. <a-tab-pane tab="机票信息" key="2" :forceRender="true">
  60. <j-editable-table
  61. ref="editableTable2"
  62. :loading="table2.loading"
  63. :columns="table2.columns"
  64. :dataSource="table2.dataSource"
  65. :maxHeight="300"
  66. :rowNumber="true"
  67. :rowSelection="true"
  68. :actionButton="true"/>
  69. </a-tab-pane>
  70. </a-tabs>
  71. </a-spin>
  72. </a-modal>
  73. </template>
  74. <script>
  75. import JEditableTable from '@/components/jeecg/JEditableTable'
  76. import { FormTypes, VALIDATE_NO_PASSED, getRefPromise, validateFormModelAndTables } from '@/utils/JEditableTableUtil'
  77. import { httpAction, getAction } from '@/api/manage'
  78. import JDate from '@/components/jeecg/JDate'
  79. export default {
  80. name: 'JeecgOrderModalForJEditableTable',
  81. components: {
  82. JDate, JEditableTable
  83. },
  84. data() {
  85. return {
  86. title: '操作',
  87. visible: false,
  88. confirmLoading: false,
  89. model: {},
  90. labelCol: {
  91. xs: { span: 24 },
  92. sm: { span: 6 }
  93. },
  94. wrapperCol: {
  95. xs: { span: 24 },
  96. sm: { span: 24 - 6 }
  97. },
  98. activeKey: '1',
  99. // 客户信息
  100. table1: {
  101. loading: false,
  102. dataSource: [],
  103. columns: [
  104. {
  105. title: '客户名',
  106. key: 'name',
  107. width: '24%',
  108. type: FormTypes.input,
  109. defaultValue: '',
  110. placeholder: '请输入${title}',
  111. validateRules: [{ required: true, message: '${title}不能为空' }]
  112. },
  113. {
  114. title: '性别',
  115. key: 'sex',
  116. width: '18%',
  117. type: FormTypes.select,
  118. options: [ // 下拉选项
  119. { title: '男', value: '1' },
  120. { title: '女', value: '2' }
  121. ],
  122. defaultValue: '',
  123. placeholder: '请选择${title}'
  124. },
  125. {
  126. title: '身份证号',
  127. key: 'idcard',
  128. width: '24%',
  129. type: FormTypes.input,
  130. defaultValue: '',
  131. placeholder: '请输入${title}',
  132. validateRules: [{
  133. pattern: '^\\d{6}(18|19|20)?\\d{2}(0[1-9]|1[012])(0[1-9]|[12]\\d|3[01])\\d{3}(\\d|[xX])$',
  134. message: '${title}格式不正确'
  135. }]
  136. },
  137. {
  138. title: '手机号',
  139. key: 'telphone',
  140. width: '24%',
  141. type: FormTypes.input,
  142. defaultValue: '',
  143. placeholder: '请输入${title}',
  144. validateRules: [{
  145. pattern: '^1(3|4|5|7|8)\\d{9}$',
  146. message: '${title}格式不正确'
  147. }]
  148. }
  149. ]
  150. },
  151. // 机票信息
  152. table2: {
  153. loading: false,
  154. dataSource: [],
  155. columns: [
  156. {
  157. title: '航班号',
  158. key: 'ticketCode',
  159. width: '40%',
  160. type: FormTypes.input,
  161. defaultValue: '',
  162. placeholder: '请输入${title}',
  163. validateRules: [{ required: true, message: '${title}不能为空' }]
  164. },
  165. {
  166. title: '航班时间',
  167. key: 'tickectDate',
  168. width: '30%',
  169. type: FormTypes.date,
  170. placeholder: '请选择${title}',
  171. defaultValue: ''
  172. }
  173. ]
  174. },
  175. url: {
  176. add: '/test/jeecgOrderMain/add',
  177. edit: '/test/jeecgOrderMain/edit',
  178. orderCustomerList: '/test/jeecgOrderMain/queryOrderCustomerListByMainId',
  179. orderTicketList: '/test/jeecgOrderMain/queryOrderTicketListByMainId'
  180. }
  181. }
  182. },
  183. created() {
  184. },
  185. methods: {
  186. // 获取所有的editableTable实例
  187. getAllTable() {
  188. return Promise.all([
  189. getRefPromise(this, 'editableTable1'),
  190. getRefPromise(this, 'editableTable2')
  191. ])
  192. },
  193. add() {
  194. // 默认新增一条数据
  195. this.getAllTable().then(editableTables => {
  196. editableTables[0].add()
  197. editableTables[1].add()
  198. })
  199. this.edit({})
  200. },
  201. edit(record) {
  202. this.visible = true
  203. this.activeKey = '1'
  204. this.model = Object.assign({}, record)
  205. // 加载子表数据
  206. if (this.model.id) {
  207. let params = { id: this.model.id }
  208. this.requestTableData(this.url.orderCustomerList, params, this.table1)
  209. this.requestTableData(this.url.orderTicketList, params, this.table2)
  210. }
  211. },
  212. close() {
  213. this.visible = false
  214. this.getAllTable().then(editableTables => {
  215. editableTables[0].initialize()
  216. editableTables[1].initialize()
  217. })
  218. this.$emit('close')
  219. this.$refs.form.resetFields();
  220. },
  221. /** 查询某个tab的数据 */
  222. requestTableData(url, params, tab) {
  223. tab.loading = true
  224. getAction(url, params).then(res => {
  225. tab.dataSource = res.result || []
  226. }).finally(() => {
  227. tab.loading = false
  228. })
  229. },
  230. handleOk() {
  231. this.validateFields()
  232. },
  233. handleCancel() {
  234. this.close()
  235. },
  236. /** ATab 选项卡切换事件 */
  237. handleChangeTabs(key) {
  238. getRefPromise(this, `editableTable${key}`).then(editableTable => {
  239. editableTable.resetScrollTop()
  240. })
  241. },
  242. /** 触发表单验证 */
  243. validateFields() {
  244. this.getAllTable().then(tables => {
  245. /** 一次性验证主表和所有的次表 */
  246. return validateFormModelAndTables(this.$refs.form,this.model, tables)
  247. }).then(allValues => {
  248. let formData = this.classifyIntoFormData(allValues)
  249. // 发起请求
  250. return this.requestAddOrEdit(formData)
  251. }).catch(e => {
  252. if (e.error === VALIDATE_NO_PASSED) {
  253. // 如果有未通过表单验证的子表,就自动跳转到它所在的tab
  254. this.activeKey = e.index == null ? this.activeKey : (e.index + 1).toString()
  255. } else {
  256. console.error(e)
  257. }
  258. })
  259. },
  260. /** 整理成formData */
  261. classifyIntoFormData(allValues) {
  262. let orderMain = Object.assign(this.model, allValues.formValue)
  263. return {
  264. ...orderMain, // 展开
  265. jeecgOrderCustomerList: allValues.tablesValue[0].values,
  266. jeecgOrderTicketList: allValues.tablesValue[1].values
  267. }
  268. },
  269. /** 发起新增或修改的请求 */
  270. requestAddOrEdit(formData) {
  271. let url = this.url.add, method = 'post'
  272. if (this.model.id) {
  273. url = this.url.edit
  274. //method = 'put'
  275. }
  276. this.confirmLoading = true
  277. httpAction(url, formData, method).then((res) => {
  278. if (res.success) {
  279. this.$message.success(res.message)
  280. this.$emit('ok')
  281. this.close()
  282. } else {
  283. this.$message.warning(res.message)
  284. }
  285. }).finally(() => {
  286. this.confirmLoading = false
  287. })
  288. }
  289. }
  290. }
  291. </script>
  292. <style scoped>
  293. </style>