multiple.vue 4.6 KB
<!-- 多人配置 -->
<template>
  <div class="multiple-dialog">
    <baseDialog
      :dialog-config="dialogConfig"
      :is-show.sync="visible"
      class="accountDailog"
      :config="config"
      @handleClick="handleConfirm"
      @closeDialog="handleClose"
      v-loading="loading"
      element-loading-text="学习任务生成中,请稍后……"
      element-loading-spinner="el-icon-loading"
    >
      <glsx-combi-form
        label-width="160px"
        default-width="400px"
        :form-obj="multipleForm"
        :form-data="multipleFormData"
        :form-rules="infoRules"
      >
        <template slot="multiple" slot-scope="scope">
          <el-checkbox
            v-model="checkAll"
            @change="handleCheckAllChange"
            :disabled="disabled"
            >全选</el-checkbox
          >
          <div class="staff-list">
            <div
              :class="['staff-item', item.active ? 'active' : '']"
              v-for="(item, index) in selectStaffList"
              :key="index"
              @click="handleChooseStaff(index)"
            >
              {{ item.employeeName }}
            </div>
          </div>
        </template>
      </glsx-combi-form>
    </baseDialog>
  </div>
</template>
<script>
import { Util, deepClone } from "@/common/util"
export default {
  props: {
    multipleVisible: {
      type: Boolean,
      default: false
    },
    staffList: {
      type: Array,
      default: () => []
    },
    staffItem: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    staffList: {
      handler(val) {
        this.filterStaffList(deepClone(val))
      },
      deep: true,
      immediate: true
    }
  },
  computed: {
    visible: {
      get() {
        this.isFlag = true
        return this.multipleVisible
      },
      set(newVal) {
        this.$emit("dialogClose", {
          flag: newVal,
          attrName: "multipleVisible"
        })
      }
    }
  },
  data() {
    return {
      dialogConfig: {
        title: "多人配置",
        width: "720px"
      },
      loading: false,
      isFlag: true,
      config: {
        showClose: true,
        appendToBody: false, // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
        isShowFooter: true,
        cancel_name: "取 消",
        confirm_name: "确定配置"
      },
      disabled: false,
      checkAll: false,
      infoRules: {
        refundType: [
          {
            required: true,
            message: "请选择退款类型",
            trigger: "blur"
          }
        ]
      },
      multipleForm: {},
      multipleFormData: [
        {
          label: "本次课程配置同步给",
          name: "multiple",
          addHtml: "multiple"
        }
      ],
      selectStaffList: []
    }
  },
  methods: {
    reset() {
      this.checkAll = []
      this.selectStaffList = []
    },
    handleChooseStaff(index) {
      if (this.staffItem.phone != this.selectStaffList[index].phone) {
        this.selectStaffList[index].active = !this.selectStaffList[index].active
        this.checkAll = this.selectStaffList.every((item) => item.active)
      }
    },
    filterStaffList(val) {
      this.selectStaffList = []
      val.forEach((item) => {
        if (item.taskStatus != 2) {
          this.selectStaffList.push(item)
        }
      })
      this.checkAll = this.selectStaffList.every((item) => item.active)
      if (
        this.selectStaffList.length == 1 &&
        this.selectStaffList[0].phone == this.staffItem.phone
      ) {
        this.disabled = true
      } else {
        this.disabled = false
      }
    },
    handleCheckAllChange() {
      this.selectStaffList.forEach((item) => {
        if (item.phone == this.staffItem.phone) {
          item.active = true
        } else {
          item.active = this.checkAll
        }
      })
    },
    handleClose() {
      this.visible = false
    },
    handleConfirm() {
      this.loading = true
      if (this.isFlag) {
        this.isFlag = false
        let arr = this.selectStaffList.filter((item) => item.active)
        this.$emit("handleMultiple", arr)
        // this.visible = false
      }
    }
  }
}
</script>
<style scoped lang="scss">
.staff-list {
  display: flex;
  align-items: center;
  margin-top: 5px;
  flex-wrap: wrap;
  width: 480px;
  .staff-item {
    padding: 6px 12px;
    border-radius: 2px;
    color: #333333;
    font-size: 14px;
    font-weight: 400;
    background: #f2f3f5;
    margin-right: 8px;
    margin-bottom: 8px;
    box-sizing: border-box;
    line-height: 20px;
  }
  .active {
    color: #2a58ad;
    font-weight: 500;
    background: #2a58ad26;
  }
}
</style>