f913664d9329b7a82b7340de2f54ab8e1bb329de.svn-base 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <a-card title="弹出子表示例" :bordered="false">
  3. <!--
  4. 【弹出子表大体思路】
  5. 1. 必须要有 click-row-show-sub-form 属性,如果该属性设为false,那么就不会弹出子表
  6. 2. 必须要有 sub-form 插槽,用于规定弹出子表的内容
  7. 3. highlight-current-row 属性可有可无,如果有则点击一行的时候,该行会背景色会常亮
  8. -->
  9. <!--
  10. 【弹出详细信息(既有主表的数据也有子表的)大体思路】
  11. 1. 必须要有 click-row-show-main-form 属性,如果该属性设为false,那么就不会弹出详细信息
  12. 2. 必须要有 main-form 插槽,用于规定弹出子表的内容
  13. 3. 可选 click-row-show-sub-form 属性,如果有该属性,就会显示子表,否者不显示
  14. -->
  15. <j-vxe-table
  16. toolbar
  17. row-number
  18. row-selection
  19. highlight-current-row
  20. click-row-show-sub-form
  21. click-row-show-main-form
  22. :height="750"
  23. :loading="loading"
  24. :columns="columns"
  25. :dataSource="dataSource"
  26. @detailsConfirm="handleDetailsConfirm"
  27. >
  28. <!-- 主表单 -->
  29. <template v-slot:mainForm="{row}">
  30. <template v-if="row">
  31. <a-form-model
  32. ref="form2"
  33. :model="row"
  34. :rules="rules"
  35. :label-col="labelCol"
  36. :wrapper-col="wrapperCol"
  37. >
  38. <a-row :gutter="8">
  39. <a-col :span="8">
  40. <a-form-model-item label="ID" prop="id">
  41. <a-input v-model="row.id" disabled/>
  42. </a-form-model-item>
  43. </a-col>
  44. <a-col :span="8">
  45. <a-form-model-item label="序号" prop="num">
  46. <a-input v-model="row.num"/>
  47. </a-form-model-item>
  48. </a-col>
  49. <a-col :span="8">
  50. <a-form-model-item label="船名" prop="ship_name">
  51. <a-input v-model="row.ship_name"/>
  52. </a-form-model-item>
  53. </a-col>
  54. <a-col :span="8">
  55. <a-form-model-item label="呼叫" prop="call">
  56. <a-input v-model="row.call"/>
  57. </a-form-model-item>
  58. </a-col>
  59. <a-col :span="8">
  60. <a-form-model-item label="长" prop="len">
  61. <a-input v-model="row.len"/>
  62. </a-form-model-item>
  63. </a-col>
  64. <a-col :span="8">
  65. <a-form-model-item label="吨" prop="ton">
  66. <a-input v-model="row.ton"/>
  67. </a-form-model-item>
  68. </a-col>
  69. <a-col :span="8">
  70. <a-form-model-item label="付款方" prop="payer">
  71. <a-input v-model="row.payer"/>
  72. </a-form-model-item>
  73. </a-col>
  74. <a-col :span="8">
  75. <a-form-model-item label="数" prop="count">
  76. <a-input v-model="row.count"/>
  77. </a-form-model-item>
  78. </a-col>
  79. <a-col :span="8">
  80. <a-form-model-item label="公司" prop="company">
  81. <a-input v-model="row.company"/>
  82. </a-form-model-item>
  83. </a-col>
  84. <a-col :span="8">
  85. <a-form-model-item label="动向" prop="trend">
  86. <a-input v-model="row.trend"/>
  87. </a-form-model-item>
  88. </a-col>
  89. </a-row>
  90. </a-form-model>
  91. </template>
  92. </template>
  93. <!-- 子表单 -->
  94. <template v-slot:subForm="{row}">
  95. <template v-if="loadSubData(row)">
  96. <j-vxe-table
  97. ref="subFormTable"
  98. height="auto"
  99. :max-height="350"
  100. :loading="subTable.loading"
  101. :columns="subTable.columns"
  102. :dataSource="subTable.dataSource"
  103. />
  104. </template>
  105. </template>
  106. </j-vxe-table>
  107. </a-card>
  108. </template>
  109. <script>
  110. import { getAction } from '@api/manage'
  111. import { JVXETypes } from '@/components/jeecg/JVxeTable'
  112. // 弹出子表示例
  113. export default {
  114. name: 'PopupSubTable',
  115. data() {
  116. return {
  117. loading: false,
  118. dataSource: [],
  119. columns: [
  120. {key: 'num', title: '序号', width: '80px'},
  121. {key: 'ship_name', title: '船名', width: '180px', type: JVXETypes.input},
  122. {key: 'call', title: '呼叫', width: '80px'},
  123. {key: 'len', title: '长', width: '80px'},
  124. {key: 'ton', title: '吨', width: '120px'},
  125. {key: 'payer', title: '付款方', width: '120px'},
  126. {key: 'count', title: '数', width: '40px'},
  127. {
  128. key: 'company',
  129. title: '公司',
  130. minWidth: '180px',
  131. // 是否点击显示详细信息
  132. // 只有当前单元格不能编辑的时候才能生效
  133. // 如果不设的话,点击就只弹出子表,不会弹出主表的详细信息
  134. showDetails: true
  135. },
  136. {key: 'trend', title: '动向', width: '120px'},
  137. ],
  138. // 子表的信息
  139. subTable: {
  140. currentRowId: null,
  141. loading: false,
  142. pagination: {current: 1, pageSize: 200, pageSizeOptions: ['100', '200'], total: 0},
  143. selectedRows: [],
  144. dataSource: [],
  145. columns: [
  146. {key: 'dd_num', title: '调度序号', width: '120px'},
  147. {key: 'tug', title: '拖轮', width: '180px', type: JVXETypes.input},
  148. {key: 'work_start_time', title: '作业开始时间', width: '180px', type: JVXETypes.input},
  149. {key: 'work_stop_time', title: '作业结束时间', width: '180px', type: JVXETypes.input},
  150. {key: 'type', title: '船舶分类', width: '120px', type: JVXETypes.input},
  151. {key: 'port_area', title: '所属港区', minWidth: '120px', type: JVXETypes.input},
  152. ],
  153. },
  154. // 查询url地址
  155. url: {
  156. getData: '/mock/vxe/getData',
  157. },
  158. // 主表form表单字段
  159. mainForm: {
  160. id: '',
  161. num: '',
  162. ship_name: '',
  163. call: '',
  164. len: '',
  165. ton: '',
  166. payer: '',
  167. count: '',
  168. company: '',
  169. trend: '',
  170. },
  171. // form表单 col
  172. labelCol: {span: 4},
  173. wrapperCol: {span: 20},
  174. rules: {
  175. num: [
  176. {required: true, message: '必须输入序号'},
  177. ],
  178. },
  179. }
  180. },
  181. created() {
  182. this.loadData()
  183. },
  184. methods: {
  185. log: console.log,
  186. // 加载数据
  187. loadData() {
  188. // 封装查询条件
  189. let formData = {pageNo: 1, pageSize: 30}
  190. // 调用查询数据接口
  191. this.loading = true
  192. getAction(this.url.getData, formData).then(res => {
  193. if (res.success) {
  194. // 将查询的数据赋值给 dataSource
  195. this.dataSource = res.result.records
  196. // 重置选择
  197. this.selectedRows = []
  198. } else {
  199. this.$error({title: '主表查询失败', content: res.message})
  200. }
  201. }).finally(() => {
  202. // 这里是无论成功或失败都会执行的方法,在这里关闭loading
  203. this.loading = false
  204. })
  205. },
  206. // 查询子表数据
  207. loadSubData(row) {
  208. if (row) {
  209. // 这里一定要做限制,限制不能重复查询,否者会出现死循环
  210. if (this.subTable.currentRowId === row.id) {
  211. return true
  212. }
  213. this.subTable.currentRowId = row.id
  214. let formData = {pageNo: 1, pageSize: 30, parentId: row.id}
  215. this.subTable.loading = true
  216. getAction(this.url.getData, formData).then(res => {
  217. if (res.success) {
  218. // 将查询的数据赋值给 dataSource
  219. this.subTable.dataSource = res.result.records
  220. } else {
  221. this.$error({title: '主表查询失败', content: res.message})
  222. }
  223. }).finally(() => {
  224. // 这里是无论成功或失败都会执行的方法,在这里关闭loading
  225. this.subTable.loading = false
  226. })
  227. return true
  228. } else {
  229. return false
  230. }
  231. },
  232. // 详细信息里点了确认按钮
  233. handleDetailsConfirm({row, $table, callback}) {
  234. console.log('保存的数据:', row)
  235. // 校验当前行
  236. $table.validate(row).then((errMap) => {
  237. // 校验通过
  238. if (!errMap) {
  239. // 校验子表,如果需要的话,可以操作下面这个对象:
  240. // this.$refs.subFormTable
  241. callback(true)
  242. this.loading = true
  243. setTimeout(() => {
  244. this.loading = false
  245. this.$message.success('保存成功')
  246. }, 1000)
  247. } else {
  248. callback(false)
  249. this.$message.warn('校验失败')
  250. }
  251. })
  252. },
  253. },
  254. }
  255. </script>
  256. <style scoped>
  257. </style>