table.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <div class="eventTable height_100" v-DivHeight="getDivHeight" >
  3. <el-table :data="tableData" header-row-class-name="custom-table-header" @sort-change="sortChange"
  4. v-if="showTable" :maxHeight="tableHeight" v-el-table-infinite-scroll="getList" :infinite-scroll-distance="10"
  5. :infinite-scroll-disabled="disabled" :height="row ? '300' : ''">
  6. <el-table-column label="#" width="60" type="index" align="center">
  7. <template slot-scope="scope">
  8. <span>{{ (scope.$index + 1) + ((queryParams.current - 1) * queryParams.size) }}</span>
  9. </template>
  10. </el-table-column>
  11. <el-table-column v-for="item in column" :key="item.value" :prop="item.value" :label="item.name" align="center"
  12. sortable="custom">
  13. <template slot-scope="scope">
  14. <div v-if="['name', 'reportProjectNum', 'patentProjectNum'].includes(item.value)">
  15. <el-link @click="handleItem(scope.row, item.value)">{{ scope.row[item.value] }}</el-link>
  16. </div>
  17. <div v-else-if="['scenarioId', 'eventDate'].includes(item.value)" v-html="getColumnData(scope.row, item.value)">
  18. </div>
  19. <div v-else>{{ scope.row[item.value] ? scope.row[item.value] : '--' }}</div>
  20. </template>
  21. </el-table-column>
  22. <el-table-column v-if="[1].indexOf(isOperate) == -1" label="操作" align="center" width="150px" >
  23. <template slot-scope="scope">
  24. <el-dropdown split-button type="primary" size="small" @click="handleClick(scope.row)"
  25. @command="handleCommand($event,scope.row)">
  26. <span>编 辑</span>
  27. <el-dropdown-menu slot="dropdown" style="text-align:center">
  28. <el-dropdown-item command="0">新增专题库</el-dropdown-item>
  29. <el-dropdown-item>
  30. <el-dropdown trigger="hover" placement="right-start">
  31. <span class="el-dropdown-link"> 新增报告 </span>
  32. <el-dropdown-menu class="children_item" v-if="dictMessage.REPORT_TYPE">
  33. <el-dropdown-item v-for="item in dictMessage.REPORT_TYPE.filter(item=>!['6'].includes(item.dictChildValue))" :key="item.dictChildLabel" @click.native="handleAnalyse(item.dictChildValue,scope.row)" v-if="$permission('/pcs/report/add/' + item.permission)">{{item.dictChildLabel}}</el-dropdown-item>
  34. </el-dropdown-menu>
  35. </el-dropdown>
  36. </el-dropdown-item>
  37. <el-dropdown-item command="10" divided style="color:red">删 除</el-dropdown-item>
  38. </el-dropdown-menu>
  39. </el-dropdown>
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <el-alert v-if="isFlag" title="正在努力加载中..." type="success" center :closable="false" show-icon></el-alert>
  44. <el-alert v-if="isMore" title="没有更多啦!" type="warning" center show-icon></el-alert>
  45. </div>
  46. </template>
  47. <script>
  48. import { getTableHeight } from '@/views/components/mixins'
  49. import mixins from '../mixins';
  50. export default {
  51. mixins: [mixins,getTableHeight],
  52. props: {
  53. isOperate: {//控制显示
  54. type: String,
  55. default: ''
  56. },
  57. column: {//显示栏位管理数组
  58. type: Array,
  59. default: () => {
  60. return [
  61. {
  62. ifGroup: false,
  63. ifSearch: true,
  64. name: "事件名称",
  65. type: "String",
  66. value: "name",
  67. },
  68. {
  69. name: "创建人",
  70. type: "String",
  71. value: "createName",
  72. ifSearch: true,
  73. ifGroup: false
  74. },
  75. {
  76. name: "创建时间",
  77. type: "DateTime",
  78. value: "createTime",
  79. ifSearch: true,
  80. ifGroup: true
  81. },
  82. {
  83. name: "发生时间",
  84. type: "DateTime",
  85. value: "eventDate",
  86. ifSearch: true,
  87. ifGroup: true
  88. },
  89. {
  90. name: "描述",
  91. type: "String",
  92. value: "description",
  93. ifSearch: true,
  94. ifGroup: false
  95. },
  96. {
  97. name: "应用场景",
  98. type: "Integer",
  99. value: "scenarioId",
  100. ifSearch: true,
  101. ifGroup: true
  102. }
  103. ]
  104. }
  105. },
  106. row: null,
  107. editData:null,
  108. addEditData:null,
  109. },
  110. data() {
  111. return {
  112. //正在努力加载中
  113. isFlag: false,
  114. //没有更多啦!
  115. isMore: false,
  116. //禁用懒加载
  117. disabled: true,
  118. params: {
  119. size: 5,
  120. current: 0
  121. },
  122. // 排序数组
  123. sort: [],
  124. };
  125. },
  126. watch: {
  127. // 分组时新增或编辑事件处理
  128. 'addEditData'(val) {
  129. let a = this.tableData.findIndex(item => {
  130. return item.id == val[0].id
  131. })
  132. if (a != -1) {
  133. this.$set(this.tableData,[a],val[0])
  134. } else {
  135. this.$set(this.tableData, [this.tableData.length], val[0])
  136. }
  137. },
  138. 'deleData'(val) {
  139. let a = this.tableData.findIndex(item => {
  140. return item.id == val[0].id
  141. })
  142. if (a != -1) {
  143. this.tableData.splice(a, 1)
  144. console.log(this.tableData);
  145. // 分组时若删除当前分组最后一条数据时重新请求分组接口
  146. if (this.tableData.length==0) {
  147. this.$emit('getData',true)
  148. }
  149. }
  150. },
  151. },
  152. mounted() {
  153. if (!this.row) {
  154. this.disabled = true
  155. } else {
  156. this.disabled = false
  157. }
  158. },
  159. methods: {
  160. getList() {
  161. if (!this.row) return;
  162. if (this.params.current * this.params.size >= this.params.total) {
  163. this.isMore = true
  164. this.disabled = true
  165. setTimeout(() => {
  166. this.isMore = false;
  167. this.isFlag = false
  168. }, 1000)
  169. }
  170. if (this.disabled) return;
  171. this.params.current += 1
  172. let params = {
  173. ...this.params,
  174. ...this.row.searchOption,//检索条件
  175. orderDTOList: this.sort,//排序
  176. groupField: this.row.groupBy,
  177. groupFieldValue: this.row.row.value,
  178. }
  179. this.isMore = false;
  180. this.isFlag = true;
  181. this.$api.queryEvent(params).then(res => {
  182. if (res.code == 200) {
  183. this.tableData.push(...res.data.data)
  184. this.params.total = res.data.total
  185. }
  186. }).catch(err => {
  187. })
  188. setTimeout(() => {
  189. this.isMore = false;
  190. this.isFlag = false
  191. }, 1000)
  192. },
  193. // 排序
  194. sortChange({ column, prop, order }) {
  195. this.handleSort({ column, prop, order })
  196. this.$emit('on-sort', { column, prop, order })
  197. },
  198. // 排序方法
  199. handleSort({ column, prop, order }) {
  200. this.sort=[]//如需要多个字段排序,则不需要清空
  201. if (order == 'null') {
  202. return;
  203. }
  204. var orderType = {
  205. ascending: 0,
  206. descending: 1
  207. }
  208. var params = this.sort.find(item => {
  209. return item.orderBy == prop
  210. })
  211. if (params) {
  212. params.orderType = orderType[order]
  213. } else {
  214. params = {}
  215. params.orderBy = prop
  216. params.orderType = orderType[order]
  217. this.sort.push(params)
  218. }
  219. this.params.current = 0
  220. this.disabled = false
  221. this.tableData.splice(0)
  222. },
  223. // 数据处理
  224. getColumnData(row, key) {
  225. if (key == 'scenarioId') {
  226. if (row.scenarioName) {
  227. return row.scenarioName
  228. } else {
  229. return '--'
  230. }
  231. }else if (key == 'eventDate') {
  232. if (row.eventDate) {
  233. return row.eventDate.slice(0, 10)
  234. } else {
  235. return '--'
  236. }
  237. }
  238. },
  239. },
  240. };
  241. </script>
  242. <style lang="scss">
  243. .eventTable {}
  244. </style>
  245. <style lang="scss" scoped></style>