<script setup>
import { ref, reactive } from "vue";
import { getTemplateInfoList } from "@/api/templateInfo";
import { userPageWhitOrganization } from "@/api/userSetting";
import { getAssessmentPageList } from "@/api/manage";
import { postListTree } from "@/api/department";
import { postPageGroup } from "@/api/userGroup";
const $emit = defineEmits(["handClick"]);

const dataList = reactive({
  teplist: [],
  userList: [],
  magList: [],
  params: {
    assessmentId: "",
    assessmentModelId: "",
    deptCode: "",
    assessmentObjectId: ""
  }
});
// 考核模板
const getTemplateInfoListApi = async () => {
  const { data, code } = await getTemplateInfoList({
    pageNumber: 1,
    pageSize: 1000
  });
  if (code === 200) {
    dataList.teplist = data.records;
  }
};
getTemplateInfoListApi();

// 考核活动
const getAssessmentPageListApi = async () => {
  const { data, code } = await getAssessmentPageList({
    pageNumber: 1,
    pageSize: 1000
  });
  if (code === 200) {
    dataList.magList = data.records;
  }
  console.log("await", data);
};
getAssessmentPageListApi();
// 用户组-用户组-医疗组
const postPageGroupApi = async () => {
  const { data, code } = await postPageGroup({
    pageNumber: 1,
    pageSize: 1000
  });
  if (code === 200) {
    dataList.userList = data.records;
  }
};
postPageGroupApi();
// -----------------------
const init = reactive({
  assessmentName: "",
  assessmentModelName: "",
  deptName: "",
  assessmentObjectName: "",
  dimensionName: ""
});
const handClickInit1 = value => {
  if (value) {
    const selectedItem = dataList.magList.find(item => item.id === value);
    init.assessmentName = selectedItem.name;
  }
  $emit("handClick", {
    ...dataList.params,
    ...init
  });
};
const handClickInit2 = value => {
  if (value) {
    const selectedItem = dataList.teplist.find(item => item.id === value);
    init.assessmentModelName = selectedItem.tpName;
  }
  $emit("handClick", {
    ...dataList.params,
    ...init
  });
};
const handClickInit3 = value => {
  if (value) {
    const selectedItem = dataList.magList.find(
      item => item.groupCode === value
    );
    init.assessmentName = selectedItem.groupName;
  }
  $emit("handClick", {
    ...dataList.params,
    ...init
  });
};
</script>

<template>
  <div class="w-full">
    <div class="mb-2 flex gap-2 justify-between flex-wrap">
      <div class="w-[100%] flex mt-2">
        <div class="flex mr-2">
          <div class="text-sm leading-8 mr-3">考核活动</div>
          <el-select
            v-model="dataList.params.assessmentId"
            clearable
            filterable
            placeholder="请选择"
            style="width: 200px"
            @change="handClickInit1"
          >
            <el-option
              v-for="item in dataList.magList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </div>
        <div class="flex mr-2">
          <div class="text-sm leading-8 mr-3">考核模板</div>
          <el-select
            v-model="dataList.params.assessmentModelId"
            clearable
            filterable
            placeholder="请选择"
            style="width: 200px"
            @change="handClickInit2"
          >
            <el-option
              v-for="item in dataList.teplist"
              :key="item.id"
              :label="item.tpName"
              :value="item.id"
            />
          </el-select>
        </div>
        <div class="flex mr-2">
          <div class="text-sm leading-8 mr-3">医疗组</div>
          <el-select
            v-model="dataList.params.assessmentModelId"
            clearable
            filterable
            placeholder="请选择"
            style="width: 200px"
            @change="handClickInit3"
          >
            <el-option
              v-for="item in dataList.userList"
              :key="item.groupCode"
              :label="item.groupName"
              :value="item.groupCode"
            />
          </el-select>
        </div>
      </div>
    </div>
  </div>
</template>
