exportPerformanceDialog.vue 8.05 KB
<!-- 导出员工业绩 -->
<template>
  <baseDialog :dialog-config="dialogConfig" :is-show.sync="visible"
    @handleClick="handleAddConfirm">
    <div class="detail-dialog">
      <glsx-combi-form class="edit-form-container"
                    ref="editFormRef"
                    label-width="154px"
                    :is-block="true"
                    form-ref="editChildRef"
                    :form-obj="infoForm"
                    :form-data="formData"
                    :form-rules="formRules">
        <template slot="monthPicker">
          <el-date-picker
            v-model="infoForm.month"
            type="month"
            style="width: 432px;"
            :picker-options="monthPickerOptions"
            popper-class="statement-of-export-performance-month-picker">
          </el-date-picker>
        </template>
        <template slot="sceneType">
          <el-checkbox-group v-model="infoForm.sceneType" class="sceneTypes_check">
            <el-checkbox v-for="item in baseData.sceneTypesList" :key="item.confId" :label="item.confId">{{item.confValue}}</el-checkbox>
          </el-checkbox-group>
        </template>
        <template slot="exportBtn">
          <el-button type="primary" class="export_btn" size="small" plain @click="exportData">导出</el-button>
        </template>
        <template slot="titleBox2">
          <div class="title_box">修正业绩</div>
        </template>
        <template slot="importSalary">
          <el-button size="small" class="import_btn">
            <input type="file"
                       id="fileUpload"
                       class="import_input"
                       accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
                       @change="importFile($event)" />
            <i class="el-icon-plus"></i>上传文件</el-button>
          <el-button type="text" size="small" @click="downloadTemplate">模板下载</el-button>
          <div class="file_box" v-if="fileName">
            <div class="file_name">{{fileName}}</div>
            <i class="el-icon-delete"
                           @click="handleFileDelete"></i>
          </div>
          <el-button class="handle_import" size="small" type="primary" plain @click="importData">导入更新</el-button>
        </template>
      </glsx-combi-form>
    </div>
  </baseDialog>
</template>

<script>
import { getLevelStaffListApi } from '@api/resident'
import { staffSceneLabelList } from '@/common/constants'
import { deepClone } from '@/common/util'
export default {
  name: 'exportPerformanceDialog',
  data() {
    return {
      formData: [
        {
          label: '选择员工',
          name: 'staffPhoneList',
          type: 'select',
          optionList: [],
          multiple: true,
          collapseTags: true,
          optionId: 'staffPhone',
          optionLabel: 'staffName',
          optionsName: 'staffList'
        },
        {
          label: '选择时间',
          name: 'month',
          addHtml: 'monthPicker',
          rules: [{ required: true, message: '请选择时间', trigger: 'change' }]
        },
        {
          label: '',
          addHtml: 'exportBtn'
        },
        {
          label: '',
          addHtml: 'titleBox2'
        },
        {
          label: '导入修正实发工资',
          name: '',
          addHtml: 'importSalary'
        }
      ],
      formRules: {
        staffPhoneList: [
          { required: true, message: '请选择员工', trigger: 'change' }
        ]
      },
      monthPickerOptions: {
        disabledDate(date) {
          const today = new Date()
          const currentYear = today.getFullYear()
          const currentMonth = today.getMonth()
          const month = date.getMonth()
          const year = date.getFullYear()
          // 当前年份
          if (year === currentYear) {
            return month >= currentMonth || month < currentMonth - 3
          } else if (year === currentYear - 1) {
            return month > 11 || month < 9
          } else {
            return year >= currentYear
          }
        }
      },
      infoForm: {
        staffPhoneList: [],
        sceneType: [],
        month: ''
      },
      baseData: {
        sceneTypesList: deepClone(staffSceneLabelList),
        staffList: []
      },
      dialogConfig: {
        title: '导出员工业绩',
        width: '720px'
      },
      fileName: ''
    }
  },
  props: {
    exportPerformanceVisible: {
      type: Boolean,
      default: false
    },
  },
  computed: {
    visible: {
      get() {
        return this.exportPerformanceVisible
      },
      set(newVal) {
        this.$emit('dialogClose', { flag: newVal, attrName: 'exportPerformanceVisible' })
      }
    }
  },
  mounted() {
    this.getStaffList()
    this.getOptions()
  },
  methods: {
    // 获取员工下拉框数据
    getStaffList() {
      getLevelStaffListApi({pageSize: 9999, currentPage: 1}).then(res => {
        this.baseData.staffList = res?.list || []
        this.getOptions()
      })
    },
    // 导出
    exportData() {
      this.$refs.editFormRef?.$refs?.editChildRef?.validate((valid) => {
        if (valid) { 
          this.$emit('handleExport', this.infoForm)
        }
      })
    },

    // 下载模板
    downloadTemplate() {
      this.$refs.editFormRef?.$refs?.editChildRef?.validate((valid) => {
        if (valid) {
          this.$emit('handleDownloadTemplate', this.infoForm)
        }
      })
    },

    // 上传文件
    importFile(e) {
      const size = e.target.files[0].size / 1024 / 1024
      if (size < 9) {
        this.fileName = e.target.files[0].name
        // // 转码base64
        const reader = new FileReader()
        reader.readAsDataURL(e.target.files[0])
        reader.onload = (event) => {
          const imgFile = event.target.result
          const arrBase64 = imgFile.split(",")
          this.fileInfo =
            e.target.files[0].name.split(".")[1] + "@" + arrBase64[1]
          document.getElementById("fileUpload").value = ""
        }
      } else {
        this.notice.errorTips("上传文件不可超过9M")
      }
    },
    // 删除文件
    handleFileDelete() {
      this.fileInfo = null
      this.fileName = ''
    },
    // 导入更新
    importData() {
      if (!this.fileInfo) return this.$message.warning('请上传导入文件')
      this.$emit('handleImport', this.fileInfo, this.fileName)
    },
    
    getOptions() {
      this.formData.forEach((item, index) => {
        if (item.type === "select") {
          this.$set(
            this.formData[index],
            "optionList",
            this.baseData[item.optionsName]
          )
        }
      })
      this.$nextTick(() => {
        this.$refs.editFormRef?.$refs?.editChildRef?.clearValidate()
      })
    },
    handleAddConfirm() {
      this.$emit('dialogClose')
    }
  }
}
</script>

<style lang="scss" scoped>
.sceneTypes_check{
  margin-right: 20px;
}
.export_btn{
  margin-left: 154px;
}
.title_box{
  font-size: 15px;
  color: #1D1D1D;
  font-weight: 600;
  border-bottom: 1px solid #E5E5E5;
  padding: 8px;
  margin-bottom: 16px;
}
.import_btn{
  position: relative;
  margin-bottom: 10px;
  .import_input{
    opacity: 0;
    position: absolute;
    right: 0;
    top: 0;
    width: 98px;
    height: 36px;
    cursor: pointer;
    font-size: 0;
  }
}
.file_box{
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  .file_name{
    border-radius: 4px;
    width: 320px;
    height: 26px;
    line-height: 26px;
    background: #F5F7FA;
    color: #333333;
    padding: 0 12px;
    margin-right: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.handle_import{
  display: block;
  margin: 0 !important;
}
</style>
<style lang="scss">
.statement-of-export-performance-month-picker {
  .el-month-table .in-range .cell:hover {
    color: #FFFFFF;
  }
  .el-month-table td.today .cell {
    color: #C0C4CC;
  }
} 
.el-tag.el-tag--info{
  border-color: #2A58AD !important;
}
.detail-dialog{
  .glsx-combi-form .el-tag.el-tag--info .el-tag__close{
    background: #C0C4CC !important;
    color: #2A58AD !important;
  }
}
</style>