PermissionDialog.vue 7.09 KB
<!-- 权限管理 -->
<template>
  <d2-dialog title="权限管理" :is-visible="isShow" class="accountDailog" @closeDialog="handleClose" width="600px"
    @confirmDialog="handleAddConfirm">
    <div class="content">
      <el-form ref="form" :model="form" :rules="rules" label-suffix=":" label-width="140px">
        <el-form-item label="选择员工" prop="staffIds">
          <el-select multiple collapse-tags v-model="form.staffIds" value-key="id" filterable remote reserve-keyword
            placeholder="请选择员工(多选)" style="width: 350px" :remote-method="remoteMethod" @change="changeOpt"
            :loading="loading">
            <el-option class="option" v-for="(item, index) in options" :key="item.id" :label="item.staffName"
              :value="item">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="权限名称" prop="checkList">
          <el-checkbox-group v-model="form.checkList">
            <el-checkbox v-for="(item, index) in optionsSelectList" :label="JSON.stringify(item)" :key="index"
              :value="item">{{ item.name }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
    </div>
  </d2-dialog>
</template>

<script>
import { getResidentListApi, getPermissionsList, addBatchPermissions, getEmployee } from "@api/resident"
import { deepClone } from '@/common/util'
import { merchantClassifyList } from '@/common/constants'
export default {
  name: 'PermissionDialog',
  data() {
    return {
      merchantClassifyList,
      optionsSelectList: [
        // {
        //   name: "预约客户",
        //   code: 'YUYUEKEHU'
        // },
        // {
        //   // 创建施工单            CHUANGJIANSHIGONGDAN
        //   name: "创建施工单",
        //   code: "CHUANGJIANSHIGONGDAN"
        // },
        // // 施工确认             SHIGONGQUEREN
        // {
        //   name: "施工确认",
        //   code: "SHIGONGQUEREN"
        // },
        // // 物料出库             WULIAOCHUKU
        // {
        //   name: "物料出库",
        //   code: "WULIAOCHUKU"
        // },
        // // 完成施工             WANCHENGSHIGONG
        // {
        //   name: "完成施工",
        //   code: "WANCHENGSHIGONG"
        // },
        // // 审核施工单            SHENHESHIGONGDAN
        // {
        //   name: "审核施工单",
        //   code: "SHENHESHIGONGDAN"
        // }

      ],
      userInfo: this.$store.state.d2admin.user.info,
      form: {
        checkList: [],
        staffIds: []
      },
      // tableData: [],
      subShopMerchantList: [],
      timeout: null,
      loading: false,
      options: [],
      // 短信模块
      isSend: false,
      rules: {
        checkList: [{ required: true, type: 'array', message: '请选择权限', trigger: 'change' }],
        staffIds: [{ required: true, type: 'array', message: '请选择员工', trigger: 'change' }]
      },
      isShowOkbtn: true,
      num: 0
    }
  },

  props: {
    permissionVisible: {
      type: Boolean,
      default: true
    },
    subShopMerchantInfo: {
      type: Object,
      default: null
    }
  },
  computed: {
    isShow: {
      get() {
        return this.permissionVisible
      },
      set(val) {
        this.$emit('update:permissionVisible', false)
      }
    }
  },
  created() {
    this.getResidentList()
    this.getPermissionsList()
  },
  mounted() {
  },

  methods: {
    getPermissionsList() {
      getPermissionsList({
      }).then(res => {
        console.log(res, 'getPermissionsList')
        this.optionsSelectList = res
      }).catch((err) => {
        console.log(err)
      })
    },
    getResidentList() {
      getEmployee({
        pageSize: 20,
        currentPage: 1
      }).then(res => {
        console.log(res)
        this.options = res.list
      }).catch((err) => {
        console.log(err)
      })
    },

    handleAddConfirm() {
      this.$refs.form.validate(valid2 => {
        if (valid2) {
          const list = this.form.staffIds.reduce((acc, cur) => {
            this.form.checkList.forEach(item => {
              acc.push({
                staffPhone: cur.staffPhone,
                permissionId: JSON.parse(item).id
              })
            })
            return acc
          }, [])
          var params = {
            type: 1,
            relations: list
          }
          addBatchPermissions(params).then(res => {
            this.notice.okTips('新增成功')
            this.handleClose()
          })
        }
      })
    },

    handleAddMerchant() {
      this.options = []
      this.form.tableData.push({
        // merchantName: '',
        merchantId: ''
      })
    },

    handleDelMerchant(index) {
      this.form.tableData.splice(index, 1)
    },

    remoteMethod(queryString) {
      if (queryString) {
        this.loading = true
        setTimeout(() => {
          this.loading = false
          var params = { currentPage: 1, pageSize: 100, staffName: queryString }
          getEmployee(params).then(res => {
            const list = this.form.staffIds || []
            const options = [...list, ...res.list || []]
            // // 对数据对象去重过滤
            this.options = Array.from(new Map(
              options.map(item => [item.id, item]) // [key, value],key 是 merchantId,value 是整个对象
            ).values())
            // this.options = res.list
          })
        }, 200)
      } else {
        // console.log()
        this.options = deepClone(this.form.staffIds)
      }
    },

    setDisabled(val) {
      const info = this.form.tableData.find(item => item.merchantId == val)
      if (info) {
        return true
      } else {
        return false
      }
    },

    changeOpt(val) {
      // const info = this.options.find(item => item.merchantId == val)
      // console.log(info)
      // this.form.tableData = this.form.tableData.map(item => {
      //   if (item.merchantId == info.merchantId) {
      //     const id = deepClone(item.id)
      //     delete info.id
      //     item = deepClone(info)
      //     if (id) {
      //       item.id = id
      //     }
      //   }
      //   return item
      // })
      // console.log(this.form.tableData)
    },

    handleClose(flag) {
      // this.$emit('dialogClose', flag)
      this.isShow = false
    }
  }
}
</script>
<style scoped lang="scss">
.container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.add-btn {
  width: 100%;
  display: flex;
  margin-top: 15px;
}

.accountDailog .el-dialog {
  margin-top: 20vh !important;
  min-width: 1000px;
}

.accountDailog .el-select-dropdown__item {
  width: 395px !important;
}

.inputCol {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 20px;
  line-height: 80px;

  ::v-deep.el-form-item__content {
    margin-left: 0 !important;
  }
}

.yseUserCode {
  height: 40px;
  background: #f6f9ff;
  line-height: 40px;
  padding-left: 16px;
  font-family: PingFangSC-Medium;
  font-weight: 500;
}

.tips {
  margin: 10px 0 5px;
  font-size: 12px;
  color: #666666;
}

.option {
  // width: 26%;
}
</style>