<style>

</style>
<template>
  <div>
    <q-card flat class="q-pa-lg q-my-lg" v-loading="loading">
      <div class="text-h6 text-weight-bold" style="margin-bottom:20px;">分配给以下成员</div>
      <q-select class="col-6 q-pb" v-model="dictObjEmp.Code" style="width:300px;" clearable filled stack-label use-input
        option-value="Id" option-label="EmployeeName" ref="ManagerId" :options="EmployeeList" label="教学主管"
        :dense="false" emit-value map-options @filter="filterFn">
        <template v-slot:no-option>
          <q-item>
            <q-item-section class="text-grey">
              未找到相关数据
            </q-item-section>
          </q-item>
        </template>
      </q-select>
      <q-select class="col-6 q-pb" v-model="dictObjEmp.Content" style="width:300px;margin-top:20px;" clearable filled
        stack-label use-input option-value="Id" option-label="EmployeeName" ref="ManagerId" :options="EmployeeList"
        label="教务主管" :dense="false" emit-value map-options @filter="filterFn">
        <template v-slot:no-option>
          <q-item>
            <q-item-section class="text-grey">
              未找到相关数据
            </q-item-section>
          </q-item>
        </template>
      </q-select>
      <q-btn class="q-mt-xl q-px-lg" unelevated color="primary" :loading="saving" @click="saveHandler">立即保存</q-btn>
    </q-card>
  </div>
</template>

<script>
  import {
    getDictValue
  } from "../../api/administration/administration";
  import {
    saveDict
  } from "../../api/system/notiveSysSet";
  import {
    queryEmployee
  } from "../../api/users/user"; //获取员工
  export default {
    data() {
      return {
        dictObjEmp: {
          ID: 0,
          Code: "",
          Content: "",
          DictKey: "TEACHER_ASSESSMENT",
          Mask: "",
          Name: "教师考评审核配置",
        },
        saving: false,
        loading: false,
        EmployeeList: [], // 员工
        AllemployeeList: [],
      };
    },
    created() {
      this.getEmployee();
    },
    mounted() {
      this.init();
    },
    methods: {
      //获取业务员
      getEmployee() {
        var qMsg = {
          EmployeeName: '',
          IsLeave: 1,
        }
        queryEmployee(qMsg).then(res => {
          if (res.Code == 1) {
            this.EmployeeList = res.Data;
            this.AllemployeeList = res.Data;
          }
        })
      },
      //筛选员工
      filterFn(val, update) {
        update(() => {
          if (val === '') {
            this.EmployeeList = JSON.parse(JSON.stringify(this.AllemployeeList))
          } else {
            const needle = val.toLowerCase();
            this.EmployeeList = this.AllemployeeList.filter(v => v.EmployeeName.toLowerCase().indexOf(needle) > -1);
          }
        })
      },
      //获取数据
      init() {
        this.loading = true;
        getDictValue({
          Key: this.dictObjEmp.DictKey
        }).then(res => {
          this.loading = false;
          if (res.Code == 1) {
            var tempObj = res.Data;
            if (tempObj) {
              this.dictObjEmp.ID = tempObj.ID;
              if (tempObj.Code && tempObj.Code != '') {
                this.dictObjEmp.Code = Number(tempObj.Code);
              }
              if (tempObj.Content && tempObj.Content != '') {
                this.dictObjEmp.Content = Number(tempObj.Content);
              }
            }
          }
        });
      },
      //保存配置
      saveHandler() {
        this.saving = true;
        saveDict(this.dictObjEmp).then(r => {
          this.saving = false;
          if (r.Code == 1) {
            this.$q.notify({
              icon: "iconfont icon-chenggong",
              color: "accent",
              timeout: 2000,
              message: "数据保存成功！",
              position: "top"
            });
            this.init();
          } else {
            this.saving = false;
          }
        });
      }
    }
  };
</script>

<style></style>