339aa5a057ea54931a24121c0f8d7b8922c0065b.svn-base 8.8 KB

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