table.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div>
  3. <el-table ref="tables"
  4. :fit="tool.calculatedColumnWidth($refs.tables,layout)"
  5. :row-class-name="tableClassName"
  6. v-loading="loading" highlight-current-row
  7. :data="data"
  8. :header-cell-style="{background:'#EEEEEE',color:'#333'}" size="mini"
  9. :height="height" @row-click="rowClick" style="width:100%"
  10. border
  11. @select="select"
  12. >
  13. <el-table-column
  14. type="selection"
  15. width="55" @handleSelectionChange="handleSelectionChange" v-if="checkbox">
  16. </el-table-column>
  17. <el-table-column :show-overflow-tooltip="col.title == '来源' || col.title == '地址' || col.title == '备注'" v-for="(col,index) in layout" :key="col.tablecolid" :prop="col.columnname" :label="col.title" :min-width="col.width || 150">
  18. <template slot-scope="scope">
  19. <!-- 自定义表格显示内容 -->
  20. <slot v-if="custom" name="customcol" :column="{data:scope.row,columnname:col.columnname}"></slot>
  21. <!-- 否则就是默认 -->
  22. <span v-else>{{scope.row[col.columnname]}}</span>
  23. <!-- 操作结构内容 -->
  24. <slot v-if="col.columnname === 'operation'" name="opreation" :data="scope.row"></slot>
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. </div>
  29. </template>
  30. <script>
  31. import {mapGetters} from "vuex"
  32. export default {
  33. /*
  34. layout:表结构数据;
  35. data:表渲染数据;
  36. custom:是否启用自定义结构;
  37. opwidth:操作列宽度
  38. */
  39. props:['layout','data','custom','height','checkbox','onRow'],
  40. data () {
  41. return {
  42. list:[],
  43. bill_id:""
  44. }
  45. },
  46. computed:{
  47. ...mapGetters({
  48. loading:'loading'
  49. })
  50. },
  51. methods:{
  52. rowClick (row) {
  53. this.$emit('rowClick',row)
  54. },
  55. tableClassName ({row,rowIndex}) {
  56. row.index = rowIndex
  57. },
  58. select(selection, row){
  59. console.log(row)
  60. this.bill_id = row.id;
  61. this.$emit("onRow",row)
  62. // 清除 所有勾选项
  63. this.$refs.tables.clearSelection()
  64. // 当表格数据都没有被勾选的时候 就返回
  65. // 主要用于将当前勾选的表格状态清除
  66. if(selection.length === 0) return
  67. this.$refs.tables.toggleRowSelection(row, true);
  68. },
  69. handleSelectionChange(val) {
  70. if (val.length >= 2){
  71. this.$refs.tables.clearSelection();
  72. }
  73. this.$emit('checkboxCallBack',val)
  74. },
  75. isCheck(row,rowIndex) {
  76. }
  77. },
  78. mounted () {
  79. // this.listData()
  80. }
  81. }
  82. </script>
  83. <style>
  84. </style>