dataTable.vue 8.74 KB
<!-- 等级考试 -->
<template>
  <div class="data-table">
    <div class="header">
      <d2-search
        ref="showSearch"
        class="show-search"
        :search-form="searchForm"
        :label-width="'120px'"
        :form-data="showFormData"
      >
      </d2-search>
      <div class="up-btns">
        <el-button size="small" type="primary" @click="handleSearch">
          查询
        </el-button>
        <el-button size="small" @click="handleReset"> 重置 </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header>
        <el-button size="small" type="primary" @click="handleExport">
          导出
        </el-button>
      </d2-table-header>
      <d2-table
        ref="table"
        :get-list-api="getListApi"
        :search-form="searchFormSearch"
        :table-params="tableParams"
        :sortObj="sortObj"
        :before-search-fn="beforeSearchFn"
      >
        <!-- 门店名称 -->
        <div slot="departmentNameHtml" slot-scope="scope">
          <span v-if="scope.scope.departmentName.length < 28">{{
            scope.scope.departmentName.slice(0, 28)
          }}</span>
          <div v-else>
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.scope.merchantName"
              placement="top-start"
            >
              <span> {{ scope.scope.merchantName.slice(0, 28) }}...</span>
            </el-tooltip>
          </div>
        </div>
        <!-- 人员状态 -->
        <div slot="zzStatusHtml" slot-scope="scope">
          <div class="online-status">
            <span
              class="dot"
              :style="{
                background: getStatusColor(
                  scope && scope.scope && scope.scope.zzStatus,
                  'zzStatusMap'
                )
              }"
            ></span>
            {{
              getStatusItem(baseData, "zzStatusOpt", scope.scope, "zzStatus")
            }}
          </div>
        </div>
      </d2-table>
    </div>
  </div>
</template>

<script>
import {
  getLevelExamDataPersonPage,
  getLevelExamDataExport
} from "@api/serviceCentre"
import { zzStatusOpt, zzStatusMap } from "@/common/constants.js"
import { Util, deepClone } from "@/common/util"
export default {
  data() {
    return {
      isRejectVisible: false,
      summaryObj: {},
      detailInfo: {},
      getListApi: getLevelExamDataPersonPage,
      sortObj: {
        score: {
          ascending: 0,
          descending: 1
        }
      },
      tableParams: {
        listName: "list",
        tableColumns: [
          {
            label: "员工",
            prop: "personName"
          },
          {
            label: "手机号",
            prop: "mobilePhone"
          },
          {
            label: "所属部门",
            prop: "departmentName",
            width: 200,
            addHtml: "departmentNameHtml"
          },
          {
            label: "职务",
            prop: "jobPostName"
          },
          {
            label: "人员状态",
            prop: "zzStatus",
            addHtml: "zzStatusHtml"
          },

          {
            label: "得分",
            prop: "score",
            sortable: "custom"
          },
          {
            label: "考试等级",
            prop: "levelName"
          }
          // {
          //   label: "提交时间",
          //   prop: "createdDate",
          //   width: "150px",
          //   formatter: (row, column) => {
          //     return Util.dateFormate(row.createdDate, "YYYY-MM-DD HH:mm:ss")
          //   }
          // }
        ]
      },
      searchFormSearch: {},
      searchForm: {
        personName: "",
        mobilePhone: "",
        zzStatus: "",
        createdDate: [],
        levelId: ""
      },
      showFormData: [
        {
          label: "员工",
          name: "personName",
          type: "input",
          isClear: true
        },
        {
          label: "手机号",
          name: "mobilePhone",
          type: "input",
          isClear: true
        },
        {
          label: "人员状态",
          name: "zzStatus",
          type: "select",
          isClear: true,
          optionList: [],
          optionId: "confId",
          optionLabel: "confValue",
          optionsName: "zzStatusOpt"
        },
        {
          label: "考试等级",
          name: "levelId",
          type: "select",
          isClear: true,
          optionList: [],
          optionId: "id",
          optionLabel: "levelName",
          optionsName: "levelOpt"
        }
      ],
      baseData: {
        zzStatusOpt: deepClone(zzStatusOpt),
        levelOpt: [],
        zzStatusMap: deepClone(zzStatusMap)
      }
    }
  },
  props: {
    dataView: {
      type: Object,
      default: () => {}
    },
    queryData: {
      type: Object,
      default: () => {}
    }
  },
  mounted() {
    // this.getOptionsList(this, "showFormData", true)
    this.fetchOnboardingPlans()
  },
  methods: {
    handleClose() {
      this.$emit("handleClose")
    },
    handleConfirm() {
      const ids = Array.from(this.selectedIds)
      this.$emit("handleConfirm", ids)
    },
    getOptionsList(that, formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = that[formName].find((k) => k.name == refreshSigle)
        var index = that[formName].findIndex((k) => k.name == refreshSigle)
        that.$set(
          that[formName][index],
          "optionList",
          deepClone(that.baseData[item.optionsName])
        )
        if (
          hasAll &&
          that.baseData[item.optionsName].length &&
          that.baseData[item.optionsName][0][
            that[formName][index].optionLabel
          ] !== "全部"
        ) {
          const temp = {}
          temp[that[formName][index].optionId] = ""
          temp[that[formName][index].optionLabel] = "全部"
          that[formName][index].optionList.unshift(temp)
        }
      } else {
        that[formName].forEach((item, index) => {
          if (
            item.type === "select" &&
            that.baseData[item.optionsName]?.length
          ) {
            that.$set(
              that[formName][index],
              "optionList",
              deepClone(that.baseData[item.optionsName])
            )
            if (
              hasAll &&
              that.baseData[item.optionsName].length &&
              that.baseData[item.optionsName][0][
                that[formName][index].optionLabel
              ] !== "全部"
            ) {
              const temp = {}
              temp[that[formName][index].optionId] = ""
              temp[that[formName][index].optionLabel] = "全部"
              that[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },
    async fetchOnboardingPlans() {
      try {
        //   const [levelOpt] = await Promise.all([
        //     getDictList({
        //       businessCode: "recruitment",
        //       typeCode: "recruitment_type"
        //     })
        //   ])
        // 处理返回的数据
        this.baseData.levelOpt = this.queryData.examLevelDTOS
        this.getOptionsList(this, "showFormData", true)
      } catch (error) {
        console.error(error)
      }
    },
    handleExport() {
      var params = this.getParams()
      if (this.$refs.table.sort) {
        params.orderByType = this.$refs.table.orderByType
      }
      params.currentPage = 1
      getLevelExamDataExport(params).then((res) => {
        this.$open(res)
      })
    },
    getStatusColor(status, optKey) {
      if (status === null || status === undefined) return "#C0C4CC"
      const map = (this.baseData && this.baseData[optKey]) || {}
      return map[status] || "#C0C4CC"
    },
    getStatusItem(baseData, optKey, row, rowKey) {
      if (!baseData || !baseData[optKey] || !row) return null
      let item = baseData[optKey].find((item) => item.confId == row[rowKey])
      return (item && item.confValue) || "-"
    },

    getParams() {
      let params = deepClone(this.searchForm)
      console.log(this.queryData)
      params.examId = this.queryData.id
      return params
    },
    beforeSearchFn() {
      return new Promise((resolve, reject) => {
        this.searchFormSearch = this.getParams()
        resolve()
      })
    },
    handleSearch() {
      this.page = this.$options.data.call(this).page
      this.$refs.table.refreshTable(true, true)
    },
    handleReset() {
      this.searchForm = this.$options.data.call(this).searchForm
      this.handleSearch()
    }
  }
}
</script>

<style scoped lang="scss">
.data-table {
  margin-top: 20px;
}
.online-status {
  display: flex;
  justify-content: center;
  align-items: center;

  .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
  }
}
</style>