tableList.vue 3.07 KB
Newer Older
xiexingan's avatar
xiexingan committed
1 2 3 4 5 6
<template>
  <div class="en-table">
    <el-table
      stripe
      :data="tableData"
      style="width: 100%"
高超凡's avatar
高超凡 committed
7
      :row-class-name="differentStateColor"
xiexingan's avatar
xiexingan committed
8 9
      :header-cell-style="{
        background: 'rgba(0, 151, 255, 0.08)',
co_dengxiongwen's avatar
co_dengxiongwen committed
10
        color: '#333333'
xiexingan's avatar
xiexingan committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
      }"
    >
      <el-table-column align="center" label="序号" width="100">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <template v-for="item in tableColums">
        <el-table-column
          :key="item.id"
          v-if="item.slot"
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          :align="item.align"
xiexingan's avatar
xiexingan committed
26 27
          header-align="center"
          align="center"
xiexingan's avatar
xiexingan committed
28 29 30 31 32 33 34 35 36 37 38 39
        >
          <template slot-scope="scope">
            <slot :name="item.prop" :scope="scope.row"></slot>
          </template>
        </el-table-column>
        <el-table-column
          :key="item.id"
          v-else
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          :align="item.align"
co_dengxiongwen's avatar
co_dengxiongwen committed
40
          header-align="center"
xiexingan's avatar
xiexingan committed
41
          align="center"
xiexingan's avatar
xiexingan committed
42 43 44 45
        >
        </el-table-column>
      </template>

co_dengxiongwen's avatar
co_dengxiongwen committed
46 47 48 49 50 51 52
      <el-table-column
        v-if="showOpr"
        align="center"
        label="操作"
        fixed="right"
        :width="opNum * 80"
      >
xiexingan's avatar
xiexingan committed
53 54 55 56 57 58 59 60
        <template slot-scope="scope">
          <slot name="operation" :scope="scope.row"></slot>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

co_dengxiongwen's avatar
co_dengxiongwen committed
61
<script>
xiexingan's avatar
xiexingan committed
62 63 64 65 66 67 68 69 70 71 72 73
export default {
  name: 'table-list',
  props: {
    tableData: {
      type: Array
    },
    tableColums: {
      type: Array
    },
    opNum: {
      type: Number,
      default: 3
xiexingan's avatar
xiexingan committed
74 75 76 77
    },
    showOpr: {
      type: Boolean,
      default: true
高超凡's avatar
高超凡 committed
78 79 80 81
    },
    // 展示每行状态颜色
    showStateColor: {
      type: Boolean,
co_dengxiongwen's avatar
co_dengxiongwen committed
82
      default: false
高超凡's avatar
高超凡 committed
83 84 85 86 87
    },
    // 人工模式
    currentMode: {
      type: Number,
      default: null
xiexingan's avatar
xiexingan committed
88 89 90 91
    }
  },
  data() {
    return {}
高超凡's avatar
高超凡 committed
92
  },
co_dengxiongwen's avatar
co_dengxiongwen committed
93
  methods: {
高超凡's avatar
高超凡 committed
94
    // 不同状态颜色
co_dengxiongwen's avatar
co_dengxiongwen committed
95 96
    differentStateColor({ row, rowIndex }) {
      if (this.showStateColor == false) return
高超凡's avatar
高超凡 committed
97
      if (row.modeTypes === null || this.currentMode === 0) {
高超凡's avatar
高超凡 committed
98
        // 原有
co_dengxiongwen's avatar
co_dengxiongwen committed
99 100
        return ''
      } else if (row.modeTypes.includes(1) && this.currentMode == '1') {
高超凡's avatar
高超凡 committed
101
        // 供暖模式
co_dengxiongwen's avatar
co_dengxiongwen committed
102 103
        return 'table-row-mode'
      } else if (row.modeTypes.includes(2) && this.currentMode == '2') {
高超凡's avatar
高超凡 committed
104
        // 机械通风
co_dengxiongwen's avatar
co_dengxiongwen committed
105 106
        return 'table-row-mechanical'
      } else if (row.modeTypes.includes(3) && this.currentMode == '3') {
高超凡's avatar
高超凡 committed
107
        // 自然通风
co_dengxiongwen's avatar
co_dengxiongwen committed
108
        return 'table-row-natural'
高超凡's avatar
高超凡 committed
109
      }
co_dengxiongwen's avatar
co_dengxiongwen committed
110
    }
xiexingan's avatar
xiexingan committed
111 112 113
  }
}
</script>
co_dengxiongwen's avatar
co_dengxiongwen committed
114
<style lang="scss">
xiexingan's avatar
xiexingan committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
.record-color {
  color: #0097ff;
}
.marg_r_18 {
  margin-right: 18px;
}
.marg_r_8 {
  margin-right: 8px;
}
.en-table {
  .el-pagination.is-background .btn-next,
  .el-pagination.is-background .btn-prev,
  .el-pagination.is-background .el-pager li {
    margin: 0 !important;
  }
  /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
    color: #32a5ea !important;
    background-color: red !important;
  }
}
</style>