haoxuan
2024-04-29 801f3ec14a04ed7fb8309953155c620882b90cea
src/views/employeeSalary/apprenticeshipManage/index.vue
@@ -1,21 +1,244 @@
<template>
  <div class="container"></div>
  <div class="container">
    <div class="filter-card">
      <CommonSearch ref="searchRef" :show-add="false" :amount-view="false" placeholder="请输入关键词" @searchClick="onFilterSearch">
        <template slot="leftButton">
          <el-button size="small" type="primary" @click="addBtnClick" >新增</el-button>
          <!-- <el-button size="small" type="primary" @click="exportClick">导入</el-button> -->
        </template>
      </CommonSearch>
    </div>
    <div class="body-card">
      <div class="list-view">
        <TableCommonView
          :table-list="tableList"
          @selTableCol="selTableCol"
          @tableRowClick="tableRowClick"
          v-loading="loading"
        >
          <template slot="tableButton">
            <el-table-column label="操作" width="180">
              <template slot-scope="scope">
                <el-button @click.stop="handleClick(scope.row, '修改')" type="text" size="small">修改</el-button>
                <el-button @click.stop="delClick(scope.row)" type="text" size="small">删除</el-button>
              </template>
            </el-table-column>
          </template>
        </TableCommonView>
      </div>
      <AddDialog
       ref="add"
        :editRow="editRow"  @refresh="refreshClick"
      />
      <div class="btn-pager">
        <PagerView class="page" :pager-options="pagerOptions" v-on="pagerEvents" />
      </div>
    </div>
  </div>
</template>
<script>
import { getMentorList, deleteMentorInfo } from "@/api/employeeSalary/apprenticeshipManage.js"
import AddDialog from "@/views/employeeSalary/apprenticeshipManage/components/addDialog.vue"
import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
import Date from "@/api/date";
const { formatDate2 } = Date;
export default {
  name: "apprenticeshipManage",
  props: {},
  components: {},
  mixins: [],
  components: {AddDialog},
  mixins: [pageMixin],
  computed: {},
  data() {
    return {}
    return {
      tableList: {},
      showCol: ["月份", "员工编码", "员工姓名", "带徒天数", "添加时间", "添加人"],
      tableColumn: [
        { label: "月份", prop: "month",min:90,},
        { label: "员工编码", prop: "workerId", min:120,},
        { label: "员工姓名", prop: "name" },
        { label: "带徒天数", prop: "days" , min:110,},
        { label: "添加时间", prop: "created_at", min:140, },
        { label: "添加人", prop: "creator", },
      ],
      editRow:{},
      loading: false,
      getDataParams: {
        keyWord: '',
      },
    }
  },
  created() {},
  methods: {}
  created() {
    this.setTable()
    this.getData(this.getDataParams.keyWord)
  },
  methods: {
    setTable() {
      // top 明细单列表
      this.tableList = {
        selectIndex: true,
        tableInfomation: [],
        allcol: [],
        showcol: this.showCol,
        tableColumn: this.setColumnVisible(this.showCol, this.tableColumn)
      }
      this.setTableList(this.tableList)
    },
    setColumnVisible(showCol, tableColumn) {
      return tableColumn.map((ele) => {
        return {
          ...ele,
          isShowColumn: showCol.includes(ele.label)
        }
      })
    },
    setTableList(tableList) {
      tableList.allcol = tableList.tableColumn.filter((ele) => !ele.default).map((ele) => ele.label)
      this.searchOptions = []
      for (let i = 0; i < tableList.tableColumn.length; i++) {
        const label = tableList.tableColumn[i].label
        const value = tableList.tableColumn[i].prop
        this.searchOptions.push({ value: value, label: label })
      }
    },
    selTableCol(val) {
      this.showcol = val
      this.tableList.tableColumn = this.setColumnVisible(val, this.tableColumn)
    },
    // 请求数据
    async getData() {
      this.loading = true
      await getMentorList({
        keyWord:this.getDataParams.keyWord,
        page: this.pagerOptions.currPage,
        pageSize: this.pagerOptions.pageSize
      })
        .then((res) => {
          if (res.code === 200) {
            if (res.data) {
              const list = res.data.map(item=>{
                return {
                  ...item,
                  name:item.worker?item.worker.name:'',
                  created_at:item.CreatedAt?formatDate2(item.CreatedAt).split(' ')[0]:''
                }
              })
              this.tableList.tableInfomation = list || []
              this.pagerOptions.totalCount = res.total
            } else {
              this.tableList.tableInfomation = []
            }
          } else {
            this.tableList.tableInfomation = []
          }
          this.loading = false
        })
        .catch((err) => {
          console.log(err)
          this.tableList.tableInfomation = []
          this.loading = false
        })
    },
    // 新增
    addBtnClick() {
      this.editRow = { title:'新建',type:'add' }
      this.$refs.add.islook = true;
    },
    // 搜索
    onFilterSearch(searchText) {
      this.getDataParams.keyWord = searchText,
      this.pagerOptions.currPage = 1
      this.getData()
    },
    // 刷新
    refreshClick() {
      this.getData()
    },
    // 打印
    exportClick() { },
    // 表格行点击
    tableRowClick(row) {
      console.log(row, "row")
    },
     // 编辑
     handleClick(row) {
      let config=JSON.parse(JSON.stringify(row));
      this.editRow = {
        ...config,
        title:'编辑',
        type:'edit',
        id:config.ID
      }
      this.$refs.add.islook = true;
    },
    // 删除
    delClick(row) {
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteMentorInfo({ id: row.ID }).then((response) => {
            if (response.code === 200) {
              this.$message.success("删除成功")
              this.getData()
            }
          })
        })
        .catch(() => {})
    },
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped></style>
<style lang="scss" scoped>
.container {
  height: 100%;
  .filter-card {
    margin: 20px 30px;
    height: 80px;
    display: flex;
    align-items: center;
    padding: 0 20px 0 20px;
    border-radius: 4px;
    background-color: #fff;
  }
  .body-card {
    margin: 0 30px;
    background-color: #fff;
    padding: 10px 15px;
    height: calc(100% - 180px);
    border-radius: 4px;
    .edit-save {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      .edit-save-icon {
        font-size: 24px;
        color: #5582f3;
        cursor: pointer;
      }
      .edit-sace-label {
        margin-left: 10px;
        font-size: 14px;
        color: #000000d8;
      }
    }
  }
}
.list-view {
  height: calc(100% - 60px);
  overflow: hidden;
}
.btn-pager {
  display: flex;
  margin-top: 10px;
  .page {
    margin-left: auto;
  }
}
</style>