table.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="eventTable height_100" v-DivHeight="getDivHeight" >
  3. <el-table :data="tableData" border 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" style="width: 100%">
  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.filter(item=>!item.ifHidden)" :render-header=" $commonJS.renderHeaderMethods" :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,Number],
  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. //操作信息
  108. handleMessage:''
  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. "orderBy": "createTime",
  126. "orderType": 1
  127. }
  128. ],
  129. //事件类型及所选
  130. action:{
  131. type:'',//1表示删除,2表示其他,3表示新增
  132. id:''
  133. }
  134. };
  135. },
  136. watch: {
  137. handleMessage(val){
  138. if(val){
  139. this.updateData()
  140. }
  141. }
  142. },
  143. mounted() {
  144. if (!this.row) {
  145. this.disabled = true
  146. } else {
  147. this.disabled = false
  148. }
  149. },
  150. methods: {
  151. //更新数据
  152. updateData(){
  153. if(this.action.type == 1){
  154. if(this.tableData.length == 1){
  155. return false
  156. }
  157. var startIndex = this.tableData.findIndex(item=>{
  158. return item.id == this.action.id
  159. })
  160. this.tableData.splice(startIndex,1)
  161. let params = {
  162. ...this.params,
  163. searchQuery:this.$commonJS.objectToString(this.row.searchOption || {}),//检索条件
  164. orderDTOList: this.sort,//排序
  165. groupField: this.row.groupBy,
  166. groupFieldValue: this.row.row.value,
  167. }
  168. this.getList2(params,1)
  169. }else if(this.action.type == 2){
  170. let params = {
  171. ...this.params,
  172. searchQuery:`id=${this.action.id}`,//检索条件
  173. groupField: this.row.groupBy,
  174. groupFieldValue: this.row.row.value,
  175. }
  176. this.getList2(params,2)
  177. }
  178. },
  179. getList2(params,type){
  180. this.$api.queryEvent(params).then(res => {
  181. if (res.code == 200) {
  182. if(type == 1){
  183. var startIndex = (params.current-1)*size
  184. var endIndex = this.tableData.length
  185. var len = endIndex - startIndex
  186. this.tableData.splice(startIndex,len,...res.data.data)
  187. this.params.total = res.data.total
  188. }else if(type == 2){
  189. var startIndex = this.tableData.findIndex(item=>{
  190. return item.id == this.action.id
  191. })
  192. this.tableData.splice(startIndex,1,...res.data.data)
  193. }
  194. }
  195. }).catch(err => {
  196. })
  197. },
  198. getList() {
  199. if (!this.row) return;
  200. if (this.params.current * this.params.size >= this.params.total) {
  201. this.isMore = true
  202. this.disabled = true
  203. setTimeout(() => {
  204. this.isMore = false;
  205. this.isFlag = false
  206. }, 1000)
  207. }
  208. if (this.disabled) return;
  209. this.params.current += 1
  210. let params = {
  211. ...this.params,
  212. searchQuery:this.$commonJS.objectToString(this.row.searchOption || {}),//检索条件
  213. orderDTOList: this.sort,//排序
  214. groupField: this.row.groupBy,
  215. groupFieldValue: this.row.row.value,
  216. }
  217. this.isMore = false;
  218. this.isFlag = true;
  219. this.$api.queryEvent(params).then(res => {
  220. if (res.code == 200) {
  221. this.tableData.push(...res.data.data)
  222. this.params.total = res.data.total
  223. }
  224. }).catch(err => {
  225. })
  226. setTimeout(() => {
  227. this.isMore = false;
  228. this.isFlag = false
  229. }, 1000)
  230. },
  231. // 排序
  232. sortChange({ column, prop, order }) {
  233. this.handleSort({ column, prop, order })
  234. if(!this.row){
  235. this.$emit('on-sort', { column, prop, order })
  236. }
  237. },
  238. // 排序方法
  239. handleSort({ column, prop, order }) {
  240. //如需要多个字段排序,则不需要清空
  241. var params = {
  242. sort:this.sort,
  243. column,
  244. prop,
  245. order,
  246. }
  247. this.sort = this.$commonJS.getSortData(params)
  248. this.params.current = 0
  249. this.disabled = false
  250. this.tableData.splice(0)
  251. this.getList()
  252. },
  253. // 数据处理
  254. getColumnData(row, key) {
  255. if (key == 'scenarioId') {
  256. if (row.scenarioName) {
  257. return row.scenarioName
  258. } else {
  259. return '--'
  260. }
  261. }else if (key == 'eventDate') {
  262. if (row.eventDate) {
  263. return row.eventDate.slice(0, 10)
  264. } else {
  265. return '--'
  266. }
  267. }
  268. },
  269. },
  270. };
  271. </script>
  272. <style lang="scss">
  273. .eventTable {}
  274. </style>
  275. <style lang="scss" scoped></style>