<script setup lang="ts">
import { nextTick, onMounted, ref, watch } from "vue";
import contentConfig from "./config/year.config";
import { ElOption } from "element-plus";
import dayjs from "dayjs";

const companies = [
  { value: "GS2203161855277894", label: "平台公司: 万宇" },
  { value: "GS2302231125079621", label: "业务公司: 百辰" },
  { value: "GS2302231323386950", label: "业务公司: 泓源" },
  { value: "GS2302231124114965", label: "业务公司: 普润&锦兴&知事" },
  { value: "GS2402020907088731", label: "平台公司: 泰文创" }
];

const companyRef = ref<any>(null);

const monthState = ref({ companyNo: "", daytime: "" });

onMounted(() => {
  const daytime = dayjs(new Date()).format("YYYY-MM-DD");
  monthState.value.daytime = daytime;
  monthState.value.companyNo = companies[0].value;
});

watch(
  () => monthState.value,
  ({ daytime, companyNo }) => {
    nextTick(() => companyRef.value.getPageData({ daytime, companyNo }));
  },
  { deep: true, immediate: true }
);
</script>

<template>
  <div w-full>
    <div
      class="flex justify-between px-[15px] pt-[10px] mt-[10px] mb-[-10px] bg-white"
    >
      年度完成情况
      <div class="flex">
        <ElDatePicker
          v-model="monthState.daytime"
          :clearable="false"
          class="mr-[10px]"
          placeholder="选择日期"
          value-format="YYYY-MM-DD"
          format="YYYY-MM-DD"
        />

        <ElSelect v-model="monthState.companyNo" placeholder="业务公司">
          <ElOption
            v-for="option in companies"
            :key="option.value"
            :label="option.label"
            :value="option.value"
          />
        </ElSelect>
      </div>
    </div>
    <PageContainer
      :get-content-ref="ref => (companyRef = ref)"
      :contentConfig="contentConfig"
    />
  </div>
</template>
