tableDetail.vue 1.43 KB
Newer Older
何虹's avatar
何虹 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
<template>
  <el-dialog @opened="dialogOpen"
             title='明细'
             :visible.sync="dialogVisible"
             @closed="dialogClose"
             width="95%"
             :append-to-body='true'
             :close-on-click-modal='false'>
    <el-table :data="tableData"
              :header-row-style="setHeaderRowStyle"
              :row-style="setRowStyle"
              style="width: 100%">
      <el-table-column v-for="(prop,index) in tableHeader"
                       :prop="prop"
                       :label="prop"
                       :key="index">
      </el-table-column>
    </el-table>
  </el-dialog>
</template>
<script>
export default {
  name: 'tabelDetail',
  props: {
    value: Boolean,
    tableData: {
      type: Array,
      default() {
        return []
      }
    },
    cellDetailStyle: {

    }
  },
  watch: {
    value(val) {
      this.dialogVisible = val
    },
    dialogVisible(val) {
      this.$emit('input', val)
    }
  },
  data() {
    return {
      dialogVisible: false,
      tableHeader: []
    }
  },
  methods: {
    dialogOpen() {
      if (!this.tableData.length) return
      this.tableHeader = Object.keys(this.tableData[0])
    },
    setHeaderRowStyle() {
      const { headerRowStyle } = this.cellDetailStyle
      return headerRowStyle || {}
    },
    setRowStyle() {
      const { rowStyle } = this.cellDetailStyle
      return rowStyle || {}
    },
    dialogClose() { }
  }
}
</script>