7bdec8020a5d21409e916ff32ce4f8044534f7e5.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <a-card :bordered="false">
  3. <j-vxe-table
  4. toolbar
  5. :toolbarConfig="toolbarConfig"
  6. row-number
  7. row-selection
  8. row-selection-type="radio"
  9. highlight-current-row
  10. click-select-row
  11. :height="tableHeight"
  12. :loading="table1.loading"
  13. :columns="table1.columns"
  14. :dataSource="table1.dataSource"
  15. :pagination="table1.pagination"
  16. :expand-config="expandConfig"
  17. style="margin-bottom: 8px"
  18. @pageChange="handleTable1PageChange"
  19. @selectRowChange="handleTable1SelectRowChange"
  20. ></j-vxe-table>
  21. <a-tabs v-show="subTabs.show" :class="{'sub-tabs':true, 'un-expand': !subTabs.expand}">
  22. <a-tab-pane tab="子表1" key="1">
  23. <j-vxe-table
  24. toolbar
  25. row-number
  26. row-selection
  27. height="auto"
  28. :maxHeight="350"
  29. :loading="table2.loading"
  30. :columns="table2.columns"
  31. :dataSource="table2.dataSource"
  32. :pagination="table2.pagination"
  33. @pageChange="handleTable2PageChange"
  34. @selectRowChange="handleTable2SelectRowChange"
  35. />
  36. </a-tab-pane>
  37. <a-tab-pane tab="子表2" key="2">
  38. <h1>这里是子表2</h1>
  39. <h1>这里是子表2</h1>
  40. <h1>这里是子表2</h1>
  41. <h1>这里是子表2</h1>
  42. <h1>这里是子表2</h1>
  43. <h1>这里是子表2</h1>
  44. </a-tab-pane>
  45. </a-tabs>
  46. </a-card>
  47. </template>
  48. <script>
  49. import { JVXETypes } from '@/components/jeecg/JVxeTable'
  50. import { getAction } from '@api/manage'
  51. export default {
  52. name: 'ErpTemplate',
  53. data() {
  54. return {
  55. toolbarConfig: {
  56. // prefix 前缀;suffix 后缀
  57. slot: ['prefix', 'suffix'],
  58. // add 新增按钮;remove 删除按钮;clearSelection 清空选择按钮
  59. btn: ['add', 'remove', 'clearSelection']
  60. },
  61. expandConfig: {
  62. // 是否只能同时展开一行
  63. accordion: true
  64. },
  65. // 子表 tabs
  66. subTabs: {
  67. show: false,
  68. // 是否展开
  69. expand: true,
  70. // 是否自动展开
  71. autoExpand: true,
  72. },
  73. table1: {
  74. // 是否正在加载
  75. loading: false,
  76. // 分页器参数
  77. pagination: {
  78. // 当前页码
  79. current: 1,
  80. // 每页的条数
  81. pageSize: 200,
  82. // 可切换的条数
  83. pageSizeOptions: ['10', '20', '30', '100', '200'],
  84. // 数据总数(目前并不知道真实的总数,所以先填写0,在后台查出来后再赋值)
  85. total: 0,
  86. showTotal: (total, range) => {
  87. // 此处为 jsx 语法
  88. let text = <span>{range[0] + '-' + range[1] + ' 共 ' + total + ' 条'}</span>
  89. // 判断子表是否显示,如果显示就渲染展开收起按钮
  90. if (this.subTabs.show) {
  91. let expand = (<span>
  92. <a-button type="link" onClick={this.handleToggleTabs}>
  93. <a-icon type={this.subTabs.expand ? 'up' : 'down'}/>
  94. <span>{this.subTabs.expand ? '收起' : '展开'}</span>
  95. </a-button>
  96. <a-checkbox vModel={this.subTabs.autoExpand}>自动展开</a-checkbox>
  97. </span>)
  98. // 返回多个dom用数组
  99. return [expand, text]
  100. } else {
  101. // 直接返回单个dom
  102. return text
  103. }
  104. },
  105. },
  106. // 选择的行
  107. selectedRows: [],
  108. // 数据源,控制表格的数据
  109. dataSource: [],
  110. // 列配置,控制表格显示的列
  111. columns: [
  112. {key: 'num', title: '序号', width: '80px'},
  113. {
  114. // 字段key,跟后台数据的字段名匹配
  115. key: 'ship_name',
  116. // 列的标题
  117. title: '船名',
  118. // 列的宽度
  119. width: '180px',
  120. // 如果加上了该属性,就代表当前单元格是可编辑的,type就是表单的类型,input就是简单的输入框
  121. type: JVXETypes.input
  122. },
  123. {key: 'call', title: '呼叫', width: '990px', type: JVXETypes.input},
  124. {key: 'len', title: '长', width: '80px', type: JVXETypes.inputNumber},
  125. {key: 'ton', title: '吨', width: '120px', type: JVXETypes.inputNumber},
  126. {key: 'payer', title: '付款方', width: '120px', type: JVXETypes.input},
  127. {key: 'count', title: '数', width: '40px'},
  128. {
  129. key: 'company',
  130. title: '公司',
  131. // 最小宽度,与宽度不同的是,这个不是固定的宽度,如果表格有多余的空间,会平均分配给设置了 minWidth 的列
  132. // 如果要做占满表格的列可以这么写
  133. minWidth: '180px',
  134. type: JVXETypes.input
  135. },
  136. {key: 'trend', title: '动向', width: '120px', type: JVXETypes.input},
  137. ],
  138. },
  139. // 子级表的配置信息 (配置和主表的完全一致,就不写冗余的注释了)
  140. table2: {
  141. currentRowId: null,
  142. loading: false,
  143. pagination: {current: 1, pageSize: 10, pageSizeOptions: ['5', '10', '20', '30'], total: 0},
  144. selectedRows: [],
  145. dataSource: [],
  146. columns: [
  147. {key: 'dd_num', title: '调度序号', width: '120px'},
  148. {key: 'tug', title: '拖轮', width: '180px', type: JVXETypes.input},
  149. {key: 'work_start_time', title: '作业开始时间', width: '180px', type: JVXETypes.input},
  150. {key: 'work_stop_time', title: '作业结束时间', width: '180px', type: JVXETypes.input},
  151. {key: 'type', title: '船舶分类', width: '120px', type: JVXETypes.input},
  152. {key: 'port_area', title: '所属港区', width: '120px', type: JVXETypes.input},
  153. ],
  154. },
  155. currentSubRow: null,
  156. // 查询url地址
  157. url: {
  158. getData: '/mock/vxe/getData',
  159. },
  160. }
  161. },
  162. computed: {
  163. tableHeight() {
  164. let {show, expand} = this.subTabs
  165. return show ? (expand ? 350 : 482) : 482
  166. },
  167. },
  168. created() {
  169. this.loadTable1Data()
  170. },
  171. methods: {
  172. // 加载table1【主表】的数据
  173. loadTable1Data() {
  174. // 封装查询条件
  175. let formData = {
  176. pageNo: this.table1.pagination.current,
  177. pageSize: this.table1.pagination.pageSize
  178. }
  179. // 调用查询数据接口
  180. this.table1.loading = true
  181. getAction(this.url.getData, formData).then(res => {
  182. if (res.success) {
  183. // 后台查询回来的 total,数据总数量
  184. this.table1.pagination.total = res.result.total
  185. // 将查询的数据赋值给 dataSource
  186. this.table1.dataSource = res.result.records
  187. // 重置选择
  188. this.table1.selectedRows = []
  189. } else {
  190. this.$error({title: '主表查询失败', content: res.message})
  191. }
  192. }).finally(() => {
  193. // 这里是无论成功或失败都会执行的方法,在这里关闭loading
  194. this.table1.loading = false
  195. })
  196. },
  197. // 查询子表数据
  198. loadSubData(row) {
  199. if (row) {
  200. // 这里一定要做限制,限制不能重复查询,否者会出现死循环
  201. if (this.table2.currentRowId === row.id) {
  202. return true
  203. }
  204. this.table2.currentRowId = row.id
  205. this.loadTable2Data()
  206. return true
  207. } else {
  208. return false
  209. }
  210. },
  211. // 查询子表数据
  212. loadTable2Data() {
  213. let table2 = this.table2
  214. let formData = {
  215. parentId: table2.currentRowId,
  216. pageNo: this.table2.pagination.current,
  217. pageSize: this.table2.pagination.pageSize
  218. }
  219. table2.loading = true
  220. getAction(this.url.getData, formData).then(res => {
  221. if (res.success) {
  222. // 将查询的数据赋值给 dataSource
  223. table2.selectedRows = []
  224. table2.dataSource = res.result.records
  225. table2.pagination.total = res.result.total
  226. } else {
  227. this.$error({title: '子表查询失败', content: res.message})
  228. }
  229. }).finally(() => {
  230. // 这里是无论成功或失败都会执行的方法,在这里关闭loading
  231. table2.loading = false
  232. })
  233. },
  234. // table1【主表】当选择的行变化时触发的事件
  235. handleTable1SelectRowChange(event) {
  236. this.table1.selectedRows = event.selectedRows
  237. this.subTabs.show = true
  238. if (this.subTabs.autoExpand) {
  239. this.subTabs.expand = true
  240. }
  241. this.loadSubData(event.selectedRows[0])
  242. },
  243. // table2【子表】当选择的行变化时触发的事件
  244. handleTable2SelectRowChange(event) {
  245. this.table2.selectedRows = event.selectedRows
  246. },
  247. handleTable1PageChange(event) {
  248. // 重新赋值
  249. this.table1.pagination.current = event.current
  250. this.table1.pagination.pageSize = event.pageSize
  251. // 查询数据
  252. this.loadTable1Data()
  253. },
  254. // 当table2【子表】分页参数变化时触发的事件
  255. handleTable2PageChange(event) {
  256. // 重新赋值
  257. this.table2.pagination.current = event.current
  258. this.table2.pagination.pageSize = event.pageSize
  259. // 查询数据
  260. this.loadTable2Data()
  261. },
  262. // 展开或收起子表tabs
  263. handleToggleTabs() {
  264. this.subTabs.expand = !this.subTabs.expand
  265. },
  266. },
  267. }
  268. </script>
  269. <style lang="less" scoped>
  270. .sub-tabs {
  271. &.un-expand {
  272. /deep/ .ant-tabs-content {
  273. height: 0 !important;
  274. }
  275. /deep/ .ant-tabs-bar {
  276. border-color: transparent !important;
  277. }
  278. /deep/ .ant-tabs-ink-bar {
  279. background-color: transparent !important;
  280. }
  281. /deep/ .ant-tabs-tab {
  282. display: none !important;
  283. }
  284. }
  285. }
  286. </style>