197eae42ddc7310463e7ee69466e74fa7f92d1f1.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <a-card :bordered="false">
  3. <a-row :gutter="8">
  4. <!-- 这里是父级节点 -->
  5. <a-col :span="24" style="margin-bottom: 4px;">
  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="340"
  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. <!-- 这里是子级节点 -->
  24. <a-col :span="12">
  25. <j-vxe-table
  26. toolbar
  27. row-number
  28. row-selection
  29. click-select-row
  30. highlight-current-row
  31. :radio-config="{highlight: false}"
  32. :checkbox-config="{highlight: false}"
  33. :height="340"
  34. :loading="table2.loading"
  35. :columns="table2.columns"
  36. :dataSource="table2.dataSource"
  37. :pagination="table2.pagination"
  38. @pageChange="handleTable2PageChange"
  39. @selectRowChange="handleTable2SelectRowChange"
  40. >
  41. </j-vxe-table>
  42. </a-col>
  43. <!-- 这里是孙级节点 -->
  44. <a-col :span="12">
  45. <j-vxe-table
  46. toolbar
  47. row-number
  48. row-selection
  49. :height="340"
  50. :loading="table3.loading"
  51. :columns="table3.columns"
  52. :dataSource="table3.dataSource"
  53. :pagination="table3.pagination"
  54. @pageChange="handleTable3PageChange"
  55. >
  56. </j-vxe-table>
  57. </a-col>
  58. </a-row>
  59. </a-card>
  60. </template>
  61. <script>
  62. import { getAction } from '@api/manage'
  63. import { JVXETypes } from '@/components/jeecg/JVxeTable'
  64. // 【多种布局模板】上面父、左下子、右下孙
  65. export default {
  66. name: 'Template1',
  67. data() {
  68. return {
  69. table1: {
  70. // 是否正在加载
  71. loading: false,
  72. // 分页器参数
  73. pagination: {
  74. // 当前页码
  75. current: 1,
  76. // 每页的条数
  77. pageSize: 200,
  78. // 可切换的条数
  79. pageSizeOptions: ['10', '20', '30', '100', '200'],
  80. // 数据总数(目前并不知道真实的总数,所以先填写0,在后台查出来后再赋值)
  81. total: 0,
  82. },
  83. // 最后选中的行
  84. lastRow: null,
  85. // 选择的行
  86. selectedRows: [],
  87. // 数据源,控制表格的数据
  88. dataSource: [],
  89. // 列配置,控制表格显示的列
  90. columns: [
  91. {key: 'num', title: '序号', width: '80px'},
  92. {
  93. // 字段key,跟后台数据的字段名匹配
  94. key: 'ship_name',
  95. // 列的标题
  96. title: '船名',
  97. // 列的宽度
  98. width: '180px',
  99. // 如果加上了该属性,就代表当前单元格是可编辑的,type就是表单的类型,input就是简单的输入框
  100. type: JVXETypes.input,
  101. formatter({cellValue, row, column}) {
  102. let foo = ''
  103. if (row.company === '佧伒侾佯有限公司') {
  104. foo += '-233'
  105. }
  106. return cellValue + foo
  107. },
  108. },
  109. {key: 'call', title: '呼叫', width: '80px', type: JVXETypes.input},
  110. {key: 'len', title: '长', width: '80px', type: JVXETypes.inputNumber},
  111. {key: 'ton', title: '吨', width: '120px', type: JVXETypes.inputNumber},
  112. {key: 'payer', title: '付款方', width: '120px', type: JVXETypes.input},
  113. {key: 'count', title: '数', width: '40px'},
  114. {
  115. key: 'company',
  116. title: '公司',
  117. // 最小宽度,与宽度不同的是,这个不是固定的宽度,如果表格有多余的空间,会平均分配给设置了 minWidth 的列
  118. // 如果要做占满表格的列可以这么写
  119. minWidth: '180px',
  120. type: JVXETypes.input
  121. },
  122. {key: 'trend', title: '动向', width: '120px', type: JVXETypes.input},
  123. ],
  124. },
  125. // 子级表的配置信息 (配置和主表的完全一致,就不写冗余的注释了)
  126. table2: {
  127. loading: false,
  128. pagination: {current: 1, pageSize: 200, pageSizeOptions: ['100', '200'], total: 0},
  129. // 最后选中的行
  130. lastRow: null,
  131. selectedRows: [],
  132. dataSource: [],
  133. columns: [
  134. {key: 'dd_num', title: '调度序号', width: '120px'},
  135. {key: 'tug', title: '拖轮', width: '180px', type: JVXETypes.input},
  136. {key: 'work_start_time', title: '作业开始时间', width: '180px', type: JVXETypes.input},
  137. {key: 'work_stop_time', title: '作业结束时间', width: '180px', type: JVXETypes.input},
  138. {key: 'type', title: '船舶分类', width: '120px', type: JVXETypes.input},
  139. {key: 'port_area', title: '所属港区', width: '120px', type: JVXETypes.input},
  140. ],
  141. },
  142. // 孙级表的配置信息 (配置和主表的完全一致,就不写冗余的注释了)
  143. table3: {
  144. loading: false,
  145. pagination: {current: 1, pageSize: 200, pageSizeOptions: ['100', '200'], total: 0},
  146. selectedRows: [],
  147. dataSource: [],
  148. columns: [
  149. {key: 'dd_num', title: '调度序号', width: '120px'},
  150. {key: 'tug', title: '拖轮', width: '120px', type: JVXETypes.input},
  151. {key: 'power', title: '马力', width: '120px', type: JVXETypes.input},
  152. {key: 'nature', title: '性质', width: '120px', type: JVXETypes.input},
  153. {key: 'departure_time', title: '发船时间', width: '180px', type: JVXETypes.input},
  154. ],
  155. },
  156. // 查询url地址
  157. url: {
  158. getData: '/mock/vxe/getData',
  159. },
  160. }
  161. },
  162. // 监听器
  163. watch: {
  164. // 监听table1 【主表】选择的数据发生了变化
  165. ['table1.lastRow'](row) {
  166. this.loadTable2Data()
  167. },
  168. // 监听table2 【子表】选择的数据发生了变化
  169. ['table2.lastRow']() {
  170. this.loadTable3Data()
  171. },
  172. },
  173. created() {
  174. this.loadTable1Data()
  175. },
  176. methods: {
  177. // 加载table1【主表】的数据
  178. loadTable1Data() {
  179. // 封装查询条件
  180. let formData = {
  181. pageNo: this.table1.pagination.current,
  182. pageSize: this.table1.pagination.pageSize
  183. }
  184. // 调用查询数据接口
  185. this.table1.loading = true
  186. getAction(this.url.getData, formData).then(res => {
  187. if (res.success) {
  188. // 后台查询回来的 total,数据总数量
  189. this.table1.pagination.total = res.result.total
  190. // 将查询的数据赋值给 dataSource
  191. this.table1.dataSource = res.result.records
  192. // 重置选择
  193. this.table1.selectedRows = []
  194. } else {
  195. this.$error({title: '主表查询失败', content: res.message})
  196. }
  197. }).finally(() => {
  198. // 这里是无论成功或失败都会执行的方法,在这里关闭loading
  199. this.table1.loading = false
  200. })
  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. // table1【主表】当选择的行变化时触发的事件
  211. handleTable1SelectRowChange(event) {
  212. this.handleTableSelectRowChange(this.table1, event)
  213. },
  214. // 加载table2【子表】的数据,根据主表的id进行查询
  215. loadTable2Data() {
  216. // 如果主表没有选择,则不查询
  217. let selectedRows = this.table1.selectedRows
  218. if (!selectedRows || selectedRows.length === 0) {
  219. this.table2.pagination.total = 0
  220. this.table2.dataSource = []
  221. this.table2.selectedRows = []
  222. return
  223. } else if (this.table1.lastRow == null) {
  224. this.table1.lastRow = selectedRows[selectedRows.length - 1]
  225. }
  226. let formData = {
  227. parentId: this.table1.lastRow.id,
  228. pageNo: this.table2.pagination.current,
  229. pageSize: this.table2.pagination.pageSize
  230. }
  231. this.table2.loading = true
  232. getAction(this.url.getData, formData).then(res => {
  233. if (res.success) {
  234. this.table2.pagination.total = res.result.total
  235. this.table2.dataSource = res.result.records
  236. this.table2.selectedRows = []
  237. } else {
  238. this.$error({title: '子表查询失败', content: res.message})
  239. }
  240. }).finally(() => {
  241. this.table2.loading = false
  242. })
  243. },
  244. // table2【子表】当选择的行变化时触发的事件
  245. handleTable2SelectRowChange(event) {
  246. this.handleTableSelectRowChange(this.table2, event)
  247. },
  248. // 当table2【子表】分页参数变化时触发的事件
  249. handleTable2PageChange(event) {
  250. // 重新赋值
  251. this.table2.pagination.current = event.current
  252. this.table2.pagination.pageSize = event.pageSize
  253. // 查询数据
  254. this.loadTable2Data()
  255. },
  256. // 加载table3【孙表】的数据,根据子表的id进行查询
  257. loadTable3Data() {
  258. // 如果主表没有选择,则不查询
  259. let selectedRows = this.table2.selectedRows
  260. if (!selectedRows || selectedRows.length === 0) {
  261. this.table3.pagination.total = 0
  262. this.table3.dataSource = []
  263. this.table3.selectedRows = []
  264. return
  265. } else if (this.table2.lastRow == null) {
  266. this.table2.lastRow = selectedRows[selectedRows.length - 1]
  267. }
  268. let formData = {
  269. parentId: this.table2.lastRow.id,
  270. pageNo: this.table3.pagination.current,
  271. pageSize: this.table3.pagination.pageSize
  272. }
  273. this.table3.loading = true
  274. getAction(this.url.getData, formData).then(res => {
  275. if (res.success) {
  276. this.table3.pagination.total = res.result.total
  277. this.table3.dataSource = res.result.records
  278. } else {
  279. this.$error({title: '子表查询失败', content: res.message})
  280. }
  281. }).finally(() => {
  282. this.table3.loading = false
  283. })
  284. },
  285. // 当table3【孙表】分页参数变化时触发的事件
  286. handleTable3PageChange(event) {
  287. // 重新赋值
  288. this.table3.pagination.current = event.current
  289. this.table3.pagination.pageSize = event.pageSize
  290. // 查询数据
  291. this.loadTable3Data()
  292. },
  293. /** 公共方法:处理表格选中变化事件 */
  294. handleTableSelectRowChange(table, event) {
  295. let {row, action, selectedRows, $table} = event
  296. // 获取最后一个选中的
  297. let lastSelected = selectedRows[selectedRows.length - 1]
  298. if (action === 'selected') {
  299. table.lastRow = row
  300. } else if (action === 'selected-all') {
  301. // 取消全选
  302. if (selectedRows.length === 0) {
  303. table.lastRow = null
  304. } else if (!table.lastRow) {
  305. table.lastRow = lastSelected
  306. }
  307. } else if (action === 'unselected' && row === table.lastRow) {
  308. table.lastRow = lastSelected
  309. }
  310. $table.setCurrentRow(table.lastRow)
  311. table.selectedRows = selectedRows
  312. },
  313. }
  314. }
  315. </script>
  316. <style lang="less">
  317. </style>