WXL
2023-11-28 8a980bd32dc2dc70f90447eb6ba293a06a2d881c
src/components/SFtable/index.vue
@@ -1,100 +1,131 @@
<!-- 表格组件封装 -->
<template>
    <el-table
      :data="currentList"
      style="width: 1158px"
      :header-cell-style="{
        background: '#f3f6fb',
        color: '#666',
        height: '42px',
        'font-weight': 400,
      }"
      :highlight-current-row="true"
      empty-text="暂无数据"
  <el-table
    :data="currentList"
    @selection-change="handleSelectionChange"
    :header-cell-style="{
      background: '#f3f6fb',
      color: '#666',
      height: '42px',
      'font-weight': 400,
    }"
    :highlight-current-row="true"
    empty-text="暂无数据"
  >
    <el-table-column v-if="multiplechoice" type="selection" width="50" align="center" />
    <el-table-column label="序号" align="center" key="id" prop="id" />
    <el-table-column
      v-for="(item, index) in tableLabel"
      :key="index"
      :prop="item.prop"
      :width="item.width"
      :label="item.label"
      :formatter="formatData"
    >
      <el-table-column type="index" :index="indexMethod" label="序号" width="80">
      </el-table-column>
      <el-table-column
        v-for="(item, index) in tableLabel"
        :key="index"
        :prop="item.prop"
        :width="item.width"
        :label="item.label"
        :formatter="formatData"
      >
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" @click.native="$emit('details', scope.row)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </template>
  <script>
  import dayjs from "dayjs";
  export default {
    data() {
      return {};
    </el-table-column>
    <el-table-column
      label="操作"
      align="center"
      width="120"
      class-name="small-padding fixed-width"
    >
      <template slot-scope="scope">
        <el-button
          v-if="controlxz"
          size="medium"
          type="text"
          @click.native="$emit('handleUpdate', scope.row)"
          ><span class="button-zx"
            ><i class="el-icon-s-promotion"></i>选择</span
          ></el-button
        >
        <el-button
          v-if="controlsc"
          size="medium"
          type="text"
          @click.native="$emit('details', scope.row)"
          ><span style="color: red"
            ><i class="el-icon-delete"></i>删除</span
          ></el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
import dayjs from "dayjs";
export default {
  data() {
    return {
      ids: [],
    };
  },
  props: {
    currentList: {
      type: Array,
      required: true,
    },
    props: {
      currentList: {
        type: Array,
        required: true,
      },
      tableLabel: {
        type: Array,
        default: () => [],
      },
      currentIndex: {
        type: Number,
        required: true,
      },
    tableLabel: {
      type: Array,
      default: () => [],
    },
    created() {},
    methods: {
      indexMethod(index) {
        return parseInt(this.currentIndex) - 9 + index;
      },
    controlsc: {
      type: Boolean,
      default: true,
    },
    controlxz: {
      type: Boolean,
      default: true,
    },
    multiplechoice:{
      type: Boolean,
      default: true,
    }
  },
  created() {},
  methods: {
    //   数据过滤
      formatData(row, column, cellValue) {
        if (column.property === "createType") {
          if (cellValue === 1) {
            return "自动";
          }
          return "手动";
    formatData(row, column, cellValue) {
      if (column.property === "createType") {
        if (cellValue === 1) {
          return "自动";
        }
        if (column.property === "createTime") {
          return dayjs(cellValue).format("YYYY.MM.DD HH:mm:ss");
        }
        return cellValue;
      },
        return "手动";
      }
      if (column.property === "createTime") {
        return dayjs(cellValue).format("YYYY.MM.DD HH:mm:ss");
      }
      return cellValue;
    },
  };
  </script>
  <style lang="scss">
  .el-table td,
  .el-table th.is-leaf {
    border-bottom: unset;
  }
  .el-table td,
  .el-table th {
    padding: 5px 0;
  }
  .el-table thead {
    font-weight: 400;
    color: #666;
  }
  .dialog-footer {
    width: 100%;
    padding: 10px 20px 20px;
    text-align: center !important;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }
  </style>
    // 多选框选中数据
    handleSelectionChange(selection) {
      $emit("handleSelectionChange", selection);
    },
  },
};
</script>
<style lang="scss">
.el-table td,
.el-table th.is-leaf {
  border-bottom: unset;
}
.el-table td,
.el-table th {
  padding: 5px 0;
}
.el-table thead {
  font-weight: 400;
  color: #666;
}
.dialog-footer {
  width: 100%;
  padding: 10px 20px 20px;
  text-align: center !important;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
</style>