<template>
  <demandVue
    ref="demandRef"
    @visibleDialog="visibleDialog"
    @loadTableForm="loadTableForm"
    @changeForm="changeFun"
    :hideKeys="hideKeys"
    :deptOptions="deptOptions"
  >
  </demandVue>
</template>
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import demandVue from '@/views/task/simulationTask/newDemand/index.vue';
import { CommonStore } from '@/stores/common';
import { listDeptApi } from '@/api/system/departMent';

const commonStore = CommonStore();
const demandRef = ref();

const visibleDialog = ({ isCreate, row }: any) => {
  if (!isCreate) {
    if (row) {
      if (row.demandType) {
        setHideKeys(row.demandType);
      }
    }
  }
};
const loadTableForm = () => {};

const hideKeys = ref(['downAttachments']);

/**
 * DEMAND_TYPE1 机器人仿真
 * DEMAND_TYPE2 有限元仿真
 * DEMAND_TYPE3 动画
 * DEMAND_TYPE4 物流仿真
 * @param val
 * @param type
 */
const changeFun = async (val: any) => {
  if (val.type === 'form') {
    if (val.val.key === 'demandType') {
      const formData = demandRef.value.tableFormRef.getFormDataFun();
      const simTypeList: any = commonStore.getDictData(val.val.data.demandType);
      demandRef.value.tableFormRef.setOptionsFun('simType', simTypeList.A);
      // const formData = tableFormRef.value.getFormDataFun();
      // tableFormRef.value.setFormDataFun({ ...formData, simType: '' });
      demandRef.value.editFormInfo = { ...formData, simType: '' };
      setHideKeys(val.val.val);
    }
  }
};
const setHideKeys = (key: string) => {
  if (key === 'DEMAND_TYPE1') {
    hideKeys.value = [
      'downAttachments',
      'simulationPurpose',
      'animationPurpose',
      'simulationDemand',
    ];
  } else if (key === 'DEMAND_TYPE2') {
    hideKeys.value = ['downAttachments', 'animationPurpose', 'simulationDemand'];
  } else if (key === 'DEMAND_TYPE3') {
    hideKeys.value = ['downAttachments', 'simulationPurpose', 'simulationDemand'];
  } else if (key === 'DEMAND_TYPE4') {
    hideKeys.value = ['downAttachments', 'simulationPurpose', 'animationPurpose'];
  }
};

const deptOptions = ref<any[]>([]);

const getListDept = async () => {
  const res: any = await listDeptApi({ current: 1, size: 999 });
  if (res.code === 200) {
    deptOptions.value = res.data.data.map((item: { deptName: any; userId: any }) => {
      return {
        label: item.deptName,
        value: String(item.userId),
      };
    });
  }
};
onMounted(() => {
  getListDept();
});
</script>
<style lang="scss" scoped></style>
