personnelManagement.vue 11.1 KB
<!-- 人员管理 -->
<template>
  <div style="paddingTop:5px;">
    <!-- <d2-container> -->
    <div class="header bg"
         slot="header"
         style="padding: 10px 20px;">
      <d2-search ref="showSearch"
                 class="show-search"
                 label-width="100px"
                 :search-form="searchForm"
                 :form-data="showFormData">
        <!-- <div slot="departments">
            <el-select v-model="searchForm.department"
                       filterable
                       remote
                       reserve-keyword
                       placeholder="请输入关键字"
                       :remote-method="remoteMethod_department"
                       :loading="loading">
              <el-option v-for="(opt, optIndex) in baseData.departments"
                         :key="optIndex"
                         :label="opt.merchantName+'/'+opt.merchantNo"
                         :value="opt.merchantNo">
              </el-option>
            </el-select>
          </div> -->
        <div slot="sourceMerchant">
          <el-select v-model="searchForm.merchantId"
                     filterable
                     remote
                     reserve-keyword
                     clearable
                     placeholder="请输入关键字"
                     :remote-method="remoteMethod_merchant"
                     :loading="loading">
            <el-option v-for="(opt, optIndex) in baseData.merchantList"
                       :key="optIndex"
                       :label="opt.merchantName + ' / ' + opt.merchantNo"
                       :value="opt.id">
            </el-option>
          </el-select>
        </div>
      </d2-search>
      <div class="up-btns">
        <el-button :id="tableParams.btnId"
                   size="small"
                   type="primary">
          查询
        </el-button>
        <el-button size="small"
                   @click="handleReset">
          重置
        </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header>
        <auth-button category="Button" />
      </d2-table-header>
      <d2-table ref="recordTable"
                :get-list-api="getListApi"
                :search-form="searchFormSearch"
                :table-params="tableParams"
                :before-search-fn="beforeSearchFn">
        <template slot="staffLabel"
                  slot-scope="scope">
          <span>
            <el-checkbox-group v-model="scope.scope.labelList">
              <el-checkbox v-for="(item, index) in sceneForPerson"
                           :key="index"
                           :label="item.confId"
                           @change="changgeCheck(scope.scope)">{{ item.confValue }}</el-checkbox>
            </el-checkbox-group>
          </span>
        </template>
        <auth-button slot="auth-button"
                     slot-scope="scope"
                     :data="scope.scope" />
      </d2-table>
    </div>
    <!-- </d2-container> -->
    <div class="btnCon">
      <el-button type="primary"
                 @click="handleSave"
                 :disabled="$store.state.d2admin.loading.value"
                 class="ok-btn">
        提交
      </el-button>
      <el-button class="cancel-btn"
                 @click="handleCancel">
        取消
      </el-button>
    </div>
  </div>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { mapActions, mapState } from 'vuex'
import { findStaffByPage, findMerchantListByPage, findDictData, updateStaffBatch } from '@/api/shopConfig.js'
import { sceneForShop, staffBusinessType, sceneForPerson } from '@/common/constants.js'
export default {
  name: 'PersonnelManagement',
  components: {

  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      sceneForPerson: deepClone(sceneForPerson),
      searchForm: {
        merchantNoList: [],
        status: 0,
        staffName: '',
        staffPhone: '',
        merchantId: '',
        roleName: '',
        department: '',
        staffLabel: ''
      },
      searchFormSearch: {},
      showFormData: [{
        label: '员工',
        name: 'staffName',
        type: 'input',
        maxlength: '20',
        isClear: true
      },
      {
        label: '手机号',
        name: 'staffPhone',
        type: 'input',
        inputType: "number",
        maxlength: '11',
        isClear: true
      }, {
        label: '角色',
        name: 'roleName',
        type: 'input',
        maxlength: '20',
        isClear: true
      }, {
        label: '部门',
        name: 'department',
        type: 'select',
        optionList: [],
        optionId: 'dictValue',
        optionLabel: 'dictLabel',
        optionsName: 'departments'
      }, {
        label: '来源商户',
        addHtml: 'sourceMerchant'
      }, {
        label: '场景标签',
        name: 'staffLabel',
        type: 'select',
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'sceneForShop'
      }
        // {
        //   label: '商户号',
        //   name: 'partnerMerchantName',
        //   type: 'input',
        //   inputType: "number",
        //   maxlength: '9',
        //   isClear: true
        // },
      ],
      getListApi: findStaffByPage,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: false,
        tableColumns: [{
          label: '员工',
          prop: 'staffName',
          width: '200px'
        }, {
          label: '手机号',
          prop: 'staffPhone',
          width: '120px'
        }, {
          label: '角色',
          prop: 'roleName',
          width: '120px'
        }, {
          label: '部门',
          prop: 'departmentName',
          width: '150px'
        },
        // {
        //   label: '类型',
        //   prop: 'merchantType',
        //   width: '100px',
        //   formatter: (cellValue) => {
        //     return {
        //       1: '服务中心',
        //       2: '客户'
        //     }[cellValue.merchantType]
        //   }
        // },
        {
          label: '来源商户',
          prop: 'merchantName',
          width: '200px'
        }, {
          label: '业务场景标签',
          addHtml: 'staffLabel'
        }, {
          label: '更新时间',
          prop: 'updatedTime',
          width: '150px'
          // formatter: (cellValue) => {
          //   return cellValue.createdDate ? Util.dateFormate(cellValue.createdDate, 'YYYY-MM-DD HH:mm:ss') : ''
          // }
        }
        ]
      },
      baseData: {
        sceneForShop: deepClone(sceneForShop),
        // staffBusinessType: staffBusinessType,
        merchantList: [],
        departments: []
      },
      loading: false,
      checkRowList: []
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  props: {
    merchantNoList: {
      type: Array,
      default: () => []
    }
  },
  mounted() {
    this.getDepartment()
    this.getBaseData()
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get',
      close: 'd2admin/page/close'
    }),
    ...mapActions('d2admin/user', ['actionSetDownloadList']),

    async getBaseData() {
      this.getOptionsList()
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = deepClone(this.searchForm)
        this.searchFormSearch.merchantNoList = this.merchantNoList
        console.log('sceneForPerson', this.sceneForPerson)
        resolve()
      })
    },

    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === 'select') {
          if (this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部') {
            const temp = {}
            temp[this.showFormData[index].optionId] = ''
            temp[this.showFormData[index].optionLabel] = '全部'
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
        }
      })
    },
    // 来源商户
    remoteMethod_merchant(queryString) {
      if (queryString) {
        this.loading = true
        setTimeout(() => {
          this.loading = false
          const _params = { channelType: 1, pageNum: 1, pageSize: 100, merchantNoOrName: queryString }
          findMerchantListByPage(_params).then(res => {
            this.baseData.merchantList = res.data || []
            console.log(this.baseData.merchantList)
          })
        }, 200)
      } else {
        this.baseData.merchantList = []
      }
    },
    // 部门
    // remoteMethod_department(queryString) {
    //   if (queryString) {
    //     this.loading = true
    //     setTimeout(() => {
    //       this.loading = false
    //       let _params = { dictType: 'staff_department', pageNum: 1, pageSize: 100, dictName: queryString }
    //       findDictData(_params).then(res => {
    //         this.baseData.departments = res.data || []
    //       })
    //     }, 200)
    //   } else {
    //     this.baseData.departments = []
    //   }
    // },
    getDepartment() {
      const _params = { dictType: 'staff_department', pageNum: 1, pageSize: 100 }
      findDictData(_params).then(res => {
        this.baseData.departments = res.data || []
        this.getOptionsList()
      })
    },

    handleSearch() {
      this.$refs.recordTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        staffName: '',
        staffPhone: '',
        merchantId: '',
        roleName: '',
        department: '',
        staffLabel: ''
      }
      this.$refs.recordTable.refreshTable()
    },

    changgeCheck(row) {
      let _obj = {}
      _obj = this.checkRowList.find(item => item.id == row.id)
      if (!_obj) {
        this.checkRowList.push(row)
      }
      console.log(this.checkRowList)
    },

    /**
     * 保存信息
     */
    handleSave() {
      const _params = {}
      const _staffList = []
      if (this.checkRowList.length > 0) {
        let _obj
        this.checkRowList.forEach(item => {
          _obj = {
            id: item.id,
            staffName: item.staffName,
            staffLabel: item.labelList.join(",")
          }
          _staffList.push(_obj)
        })
      }
      _params.staffList = _staffList
      console.log(_params)
      this.$confirm(`该操作会保存所有操作过的场景标签配置,是否保存?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        updateStaffBatch(_params).then(res => {
          this.notice.okTips()
          this.handleCancel()
        })
      }).catch(err => {
        console.log(err)
      })
    },
    handleCancel() {
      this.close({ tagName: '/personnelManagementIndex' })
      this.$router.push({ name: 'shopConfig' })
    }
  }
}

</script>
<style lang="scss" scoped>
.btnCon {
  padding-top: 40px;
  width: 100%;
  text-align: center;
}

.bg {
  background: #ffffff;
}
</style>