2b8adbb7439b8b25288094a19281020e0279946d.svn-base 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <a-card :bordered="false">
  3. <a-row :gutter="8">
  4. <a-col :span="12">
  5. <!-- 左上父 -->
  6. <j-vxe-table
  7. toolbar
  8. row-number
  9. row-selection
  10. click-select-row
  11. highlight-current-row
  12. :radio-config="{highlight: false}"
  13. :checkbox-config="{highlight: false}"
  14. :height="357"
  15. :loading="table1.loading"
  16. :columns="table1.columns"
  17. :dataSource="table1.dataSource"
  18. :pagination="table1.pagination"
  19. style="margin-bottom: 8px;"
  20. @pageChange="handleTable1PageChange"
  21. @selectRowChange="handleTable1SelectRowChange"
  22. />
  23. <!-- 左下子 -->
  24. <j-vxe-table
  25. toolbar
  26. row-number
  27. row-selection
  28. click-select-row
  29. :height="356"
  30. :loading="table2.loading"
  31. :columns="table2.columns"
  32. :dataSource="table2.dataSource"
  33. :pagination="table2.pagination"
  34. @pageChange="handleTable2PageChange"
  35. />
  36. </a-col>
  37. <!-- 左侧父选择的数据展示在这里 -->
  38. <a-col :span="12">
  39. <j-vxe-table
  40. row-number
  41. :height="800"
  42. :columns="table1.columns"
  43. :dataSource="table1.selectedRows"
  44. style="margin-top: 40px;"
  45. />
  46. </a-col>
  47. </a-row>
  48. </a-card>
  49. </template>
  50. <script>
  51. import { getAction } from '@api/manage'
  52. import { JVXETypes } from '@/components/jeecg/JVxeTable'
  53. // 【多种布局模板】左侧上边是主表、下边是子表,右侧是选中数据
  54. export default {
  55. name: 'Template3',
  56. components: {},
  57. data() {
  58. return {
  59. // 主表的配置信息
  60. table1: {
  61. // 是否正在加载
  62. loading: false,
  63. // 分页器参数
  64. pagination: {
  65. // 当前页码
  66. current: 1,
  67. // 每页的条数
  68. pageSize: 200,
  69. // 可切换的条数
  70. pageSizeOptions: ['10', '20', '30', '100', '200'],
  71. // 数据总数(目前并不知道真实的总数,所以先填写0,在后台查出来后再赋值)
  72. total: 0,
  73. },
  74. // 最后选中的行
  75. lastRow: null,
  76. // 选择的行
  77. selectedRows: [],
  78. // 数据源,控制表格的数据
  79. dataSource: [],
  80. // 列配置,控制表格显示的列
  81. columns: [
  82. {key: 'num', title: '序号', width: '80px'},
  83. {
  84. // 字段key,跟后台数据的字段名匹配
  85. key: 'ship_name',
  86. // 列的标题
  87. title: '船名',
  88. // 列的宽度
  89. width: '180px',
  90. // 如果加上了该属性,就代表当前单元格是可编辑的,type就是表单的类型,input就是简单的输入框
  91. type: JVXETypes.input
  92. },
  93. {key: 'call', title: '呼叫', width: '80px', type: JVXETypes.input},
  94. {key: 'len', title: '长', width: '80px', type: JVXETypes.input},
  95. {key: 'ton', title: '吨', width: '120px', type: JVXETypes.input},
  96. {key: 'payer', title: '付款方', width: '120px', type: JVXETypes.input},
  97. {key: 'count', title: '数', width: '40px'},
  98. {key: 'company', title: '公司', width: '180px', type: JVXETypes.input},
  99. {key: 'trend', title: '动向', width: '120px', type: JVXETypes.input},
  100. ],
  101. },
  102. // 子表的配置信息 (配置和主表的完全一致,就不写冗余的注释了)
  103. table2: {
  104. loading: false,
  105. pagination: {current: 1, pageSize: 200, pageSizeOptions: ['100', '200'], total: 0},
  106. dataSource: [],
  107. columns: [
  108. {key: 'dd_num', title: '调度序号', width: '120px'},
  109. {key: 'tug', title: '拖轮', width: '180px', type: JVXETypes.input},
  110. {key: 'work_start_time', title: '作业开始时间', width: '180px', type: JVXETypes.input},
  111. {key: 'work_stop_time', title: '作业结束时间', width: '180px', type: JVXETypes.input},
  112. {key: 'type', title: '船舶分类', width: '120px', type: JVXETypes.input},
  113. {key: 'port_area', title: '所属港区', width: '120px', type: JVXETypes.input},
  114. ],
  115. },
  116. // 查询url地址
  117. url: {
  118. getData: '/mock/vxe/getData',
  119. },
  120. }
  121. },
  122. // 监听器
  123. watch: {
  124. // 监听table1 【主表】选择的数据发生了变化
  125. ['table1.lastRow'](row) {
  126. this.loadTable2Data()
  127. },
  128. },
  129. created() {
  130. this.loadTable1Data()
  131. },
  132. methods: {
  133. // 加载table1(主表)的数据
  134. loadTable1Data() {
  135. // 封装查询条件
  136. let formData = {
  137. pageNo: this.table1.pagination.current,
  138. pageSize: this.table1.pagination.pageSize
  139. }
  140. // 调用查询数据接口
  141. this.table1.loading = true
  142. getAction(this.url.getData, formData).then(res => {
  143. if (res.success) {
  144. // 后台查询回来的 total,数据总数量
  145. this.table1.pagination.total = res.result.total
  146. // 将查询的数据赋值给 dataSource
  147. this.table1.dataSource = res.result.records
  148. } else {
  149. this.$error({title: '主表查询失败', content: res.message})
  150. }
  151. }).finally(() => {
  152. // 这里是无论成功或失败都会执行的方法,在这里关闭loading
  153. this.table1.loading = false
  154. })
  155. },
  156. // 加载table2(子表)的数据,根据主表的id进行查询
  157. loadTable2Data() {
  158. // 如果主表没有选择,则不查询
  159. let selectedRows = this.table1.selectedRows
  160. if (!selectedRows || selectedRows.length === 0) {
  161. this.table2.pagination.total = 0
  162. this.table2.dataSource = []
  163. return
  164. } else if (this.table1.lastRow == null) {
  165. this.table1.lastRow = selectedRows[selectedRows.length - 1]
  166. }
  167. let formData = {
  168. parentId: this.table1.lastRow.id,
  169. pageNo: this.table2.pagination.current,
  170. pageSize: this.table2.pagination.pageSize
  171. }
  172. this.table2.loading = true
  173. getAction(this.url.getData, formData).then(res => {
  174. if (res.success) {
  175. this.table2.pagination.total = res.result.total
  176. this.table2.dataSource = res.result.records
  177. } else {
  178. this.$error({title: '子表查询失败', content: res.message})
  179. }
  180. }).finally(() => {
  181. this.table2.loading = false
  182. })
  183. },
  184. // table1【主表】当分页参数变化时触发的事件
  185. handleTable1PageChange(event) {
  186. // 重新赋值
  187. this.table1.pagination.current = event.current
  188. this.table1.pagination.pageSize = event.pageSize
  189. // 查询数据
  190. this.loadTable1Data()
  191. // 分页后重置选择
  192. this.table1.selectedRows = []
  193. this.loadTable2Data()
  194. },
  195. // table2【子表】当分页参数变化时触发的事件
  196. handleTable2PageChange(event) {
  197. // 重新赋值
  198. this.table1.pagination.current = event.current
  199. this.table1.pagination.pageSize = event.pageSize
  200. // 查询数据
  201. this.loadTable2Data()
  202. },
  203. // table1【主表】当选择的行变化时触发的事件
  204. handleTable1SelectRowChange(event) {
  205. this.handleTableSelectRowChange(this.table1, event)
  206. },
  207. /** 公共方法:处理表格选中变化事件 */
  208. handleTableSelectRowChange(table, event) {
  209. let {row, action, selectedRows, $table} = event
  210. // 获取最后一个选中的
  211. let lastSelected = selectedRows[selectedRows.length - 1]
  212. if (action === 'selected') {
  213. table.lastRow = row
  214. } else if (action === 'selected-all') {
  215. // 取消全选
  216. if (selectedRows.length === 0) {
  217. table.lastRow = null
  218. } else if (!table.lastRow) {
  219. table.lastRow = lastSelected
  220. }
  221. } else if (action === 'unselected' && row === table.lastRow) {
  222. table.lastRow = lastSelected
  223. }
  224. $table.setCurrentRow(table.lastRow)
  225. table.selectedRows = selectedRows
  226. },
  227. },
  228. }
  229. </script>
  230. <style scoped>
  231. </style>