dataView.vue 10.6 KB
<!-- 课程培训计划数据 -->
<template>
  <d2-container class="course-wrap">
    <div class="header" slot="header">
      <d2-search
        ref="showSearch"
        class="show-search"
        :search-form="searchForm"
        :label-width="'85px'"
        :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>
        <span>
          <el-button size="small" type="primary" @click="handleExport">
            导出
          </el-button>
        </span>
      </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="empStatusHtml" slot-scope="scope">
          <div class="online-status">
            <span
              class="dot"
              :style="{
                background: getStatusColor(
                  scope && scope.scope && scope.scope.personStatus,
                  'empStatusOptMap'
                )
              }"
            ></span>
            {{
              getStatusItem(
                baseData,
                "empStatusOpt",
                scope.scope,
                "personStatus"
              )
            }}
          </div>
        </div>
        <div slot="auth-button" slot-scope="scope">
          <!-- 编辑 -->
          <span style="margin-right: 10px">
            <el-button
              :data="scope.scope"
              type="text"
              :disabled="scope.scope.openOrderStatus == 1"
              @click="handleUnlock(scope.scope)"
              >解锁开单</el-button
            >
          </span>
        </div>
      </d2-table>
    </div>
  </d2-container>
</template>

<script>
import { mapActions, mapState } from "vuex"
import {
  getTrainingPlanPersonList,
  unlockTrainingPlanPersonOrder,
  exportTrainingPlanPerson,
  getOrganizationList,
  getBeisenJobList
} from "@api/serviceCentre"
import {
  empStatusOpt,
  empStatusOptMap,
  openOrderStatusOpt
} from "@/common/constants.js"
import { Util, deepClone } from "@/common/util"
export default {
  data() {
    return {
      getListApi: getTrainingPlanPersonList,
      sortObj: {
        entryDate: {
          ascending: 0,
          descending: 1
        }
      },
      tableParams: {
        listName: "list",
        tableOption: {
          width: "120"
        },
        tableColumns: [
          {
            label: "员工",
            prop: "personName",
            width: "200px"
          },
          {
            label: "手机号",
            prop: "phoneNumber"
          },
          {
            label: "所属部门",
            prop: "departmentName",
            width: 200
          },
          {
            label: "职务",
            prop: "positionName"
          },
          {
            label: "人员状态",
            prop: "personStatus",
            width: 160,
            addHtml: "empStatusHtml"
          },
          {
            label: "入职日期",
            prop: "entryDate",
            sortable: "custom",
            width: 160
          },
          {
            label: "已完成课程数量",
            prop: "completedCourseCount",
            width: 200,
            formatter: function (cellValue) {
              return cellValue.completedCourseCount ||
                cellValue.completedCourseCount === 0
                ? cellValue.completedCourseCount
                : "-"
            }
          },
          {
            label: "开单权限",
            prop: "openOrderStatus",
            formatter: (cellValue) => {
              return cellValue.openOrderStatus == 1 ? "已解锁" : "已锁定"
            }
          }
        ]
      },
      searchFormSearch: {},
      searchForm: {
        personName: "",
        phoneNumber: "",
        departId: "",
        jobId: "",
        personStatus: "",
        openOrderStatus: "",
        entryDate: []
      },
      showFormData: [
        {
          label: "员工",
          name: "personName",
          type: "input",
          isClear: true
        },
        {
          label: "手机号",
          name: "phoneNumber",
          type: "input",
          isClear: true
        },
        {
          label: "所属部门",
          name: "departId",
          type: "select",
          isClear: true,
          optionList: [],
          optionId: "oid",
          optionLabel: "name",
          optionsName: "organizationOpt"
        },
        {
          label: "职务",
          name: "jobId",
          type: "select",
          isClear: true,
          optionList: [],
          optionId: "oid",
          optionLabel: "name",
          optionsName: "postTypeOpt"
        },
        {
          label: "人员状态",
          name: "personStatus",
          type: "select",
          isClear: true,
          optionList: [],
          optionId: "confId",
          optionLabel: "confValue",
          optionsName: "empStatusOpt"
        },
        {
          label: "开单权限",
          name: "openOrderStatus",
          type: "select",
          isClear: true,
          optionList: [],
          optionId: "confId",
          optionLabel: "confValue",
          optionsName: "openOrderStatusOpt"
        },
        {
          label: "入职时间",
          name: "entryDate",
          type: "datePicker",
          isClear: true
        }
      ],
      baseData: {
        empStatusOpt: deepClone(empStatusOpt),
        postTypeOpt: [],
        openOrderStatusOpt: deepClone(openOrderStatusOpt),
        empStatusOptMap: deepClone(empStatusOptMap),
        organizationOpt: []
      }
    }
  },
  props: {
    queryData: {
      type: Object,
      default: () => {}
    }
  },
  mounted() {
    this.fetchOnboardingPlans()
  },
  methods: {
    getStatusColor(status, optKey) {
      if (status === null || status === undefined) return "#C0C4CC"
      const map = (this.baseData && this.baseData[optKey]) || {}
      return map[status] || ""
    },
    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) || "-"
    },
    //解锁开单
    handleUnlock(row) {
      console.log(row)
      this.$confirm(`确认解锁${row.personName}开单权限吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        closeOnClickModal: false //
      }).then(async () => {
        // 确认解锁
        let ok = await unlockTrainingPlanPersonOrder({
          planId: row.planId,
          personId: row.personId
        })
        if (ok) {
          this.$message.success("解锁该员工开单权限,开单权限更改为“已解锁”")
          this.handleSearch()
        }
      })
    },
    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 [organizationOpt, postTypeOpt] = await Promise.all([
          getOrganizationList(),
          getBeisenJobList()
        ])
        // 处理返回的数据
        this.baseData.organizationOpt = organizationOpt.list
        this.baseData.postTypeOpt = postTypeOpt.list
        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
      exportTrainingPlanPerson(params).then((res) => {
        if (res) {
          this.$open(res)
        }
      })
    },
    getParams() {
      let params = deepClone(this.searchForm)
      //   申请时间
      if (params?.entryDate?.length) {
        let [start, end] = params.entryDate
        params.entryStartDate = Util.dateFormate(start, "YYYY-MM-DD HH:mm:ss")
        params.entryEndDate = Util.dateFormate(end, "YYYY-MM-DD") + " 23:59:59"
      }
      params.planId = this.queryData.id
      delete params.entryDate
      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">
.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>