table.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div>
  3. <el-table ref="tables" @select="aaaa" @select-all="selectAll" v-loading="loading" highlight-current-row :data="data" :header-cell-style="{background:'#EEEEEE',color:'#333'}" size="mini" :height="height" style="width:100%" border>
  4. <el-table-column
  5. type="selection"
  6. width="45"
  7. align="center"
  8. fixed>
  9. </el-table-column>
  10. <el-table-column :show-overflow-tooltip="col.title == '来源' || col.title == '地址' || col.title == '备注'" v-for="col in layout" :key="col.tablecolid" :prop="col.columnname" :label="col.title" :width="col.width" :fixed="col.columnname === fixedName?'right':false">
  11. <template slot-scope="scope">
  12. <!-- 自定义表格显示内容 -->
  13. <slot v-if="custom" name="customcol" :column="{data:scope.row,columnname:col.columnname}"></slot>
  14. <!-- 否则就是默认 -->
  15. <span v-else>{{scope.row[col.columnname]}}</span>
  16. <!-- 操作结构内容 -->
  17. <slot v-if="col.columnname === 'operation'" name="opreation" :data="scope.row"></slot>
  18. </template>
  19. </el-table-column>
  20. </el-table>
  21. </div>
  22. </template>
  23. <script>
  24. import {mapGetters} from "vuex"
  25. export default {
  26. /*
  27. layout:表结构数据;
  28. data:表渲染数据;
  29. custom:是否启用自定义结构;
  30. opwidth:操作列宽度
  31. */
  32. props:['layout','data','custom','height','fixedName'],
  33. data () {
  34. return {
  35. list:[],
  36. allArr:[]
  37. }
  38. },
  39. computed:{
  40. ...mapGetters({
  41. loading:'loading'
  42. })
  43. },
  44. watch: {
  45. data (val) {
  46. this.data.forEach((row) => {
  47. this.allArr.forEach(item => {
  48. if (row.itemid == item.itemid) {
  49. this.$nextTick(() => {
  50. this.$refs["tables"].toggleRowSelection(row, true);
  51. })
  52. }
  53. })
  54. });
  55. },
  56. allArr (val) {
  57. this.$emit('upDateData',val)
  58. }
  59. },
  60. methods:{
  61. aaaa(e,a) {
  62. let index = this.allArr.findIndex(v=>v.itemid == a.itemid)
  63. if(index == -1) {
  64. this.allArr.push(a)
  65. } else {
  66. this.allArr.splice(index,1)
  67. }
  68. },
  69. selectAll (val) {
  70. if (val.length == 0) {
  71. this.data.forEach(item => {
  72. this.allArr.splice(item,1)
  73. })
  74. } else {
  75. val.forEach(item => {
  76. let res = this.allArr.every(item2 => item.itemid != item2.itemid)
  77. res ? this.allArr.push(item) : ''
  78. })
  79. }
  80. },
  81. },
  82. }
  83. </script>
  84. <style scoped>
  85. /deep/.el-table__header .DisableSelection > .cell {
  86. display: none !important;
  87. }
  88. </style>