table.vue 2.5 KB

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