d7cbbce4f6a33505e43c81b79b197904fce78c9a.svn-base 12 KB

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