<template>
  <div>
    <div class="title">
      <el-select
        v-if="activeName == '电价配置'"
        v-model="Singlevalue"
        collapse-tags
        :placeholder="$t('Administration.SelectPlant')"
        popper-class="custom-header"
        :max-collapse-tags="1"
        size="large"
        class="Space_content"
        @change="postersDevice"
      >
        <template #prefix>
          {{ (cities.find(s => s.id === Singlevalue) || {}).stationName }}
        </template>

        <el-option v-for="(item, index) in cities" :key="index" :label="item.stationName" :value="item.id" />
      </el-select>
    </div>
    <div class="electricityprice">
      <el-card>
        <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
          <el-tab-pane :label="$t('Administration.Configuration')" name="电价配置">
            <el-card>
              <div class="price_allocation">
                <el-icon><WarningFilled /></el-icon>&ensp;
                {{ $t("Administration.prompt") }}
              </div>
            </el-card>

            <div class="datepicker">
              <div>
                {{ $t("Administration.year") }}：
                <el-date-picker
                  v-model="pickervalue"
                  type="year"
                  placeholder="选择时间"
                  size="large"
                  clearable
                  format="YYYY"
                  value-format="YYYY"
                  @change="pickerincome"
                />
              </div>
              <el-button type="primary" @click="onoverview()" size="large">{{ $t("Administration.Overview") }}</el-button>
            </div>
            <div class="all_ocation">
              <div class="allocation_1" v-for="(item, index) in tricitylist" :key="index">
                <div class="header" :style="index % 4 == 0 ? 'border-left: 1px solid #ebeef5;' : ''">
                  {{ item.imonth }}{{ $t("Administration.themoon") }}
                </div>
                <div class="body" :style="index % 4 == 0 ? 'border-left: 1px solid #ebeef5;' : ''">
                  <div class="body_content">{{ item.tmplName }}</div>
                  <div>
                    <div>
                      <el-button v-if="item.start == 1" type="primary" plain @click="configuration(item.tariffId)" size="small">
                        {{ $t("Administration.view") }}
                      </el-button>
                    </div>
                    <div class="bodycheckbox" v-if="BUTTONS.Administrationbinding">
                      <el-button type="primary" v-if="item.start == 1" plain @click="onUnbind(item)" size="small">
                        {{ $t("Administration.Unbind") }}
                      </el-button>
                      <el-button type="primary" v-else plain @click="ondetermine(item)" size="small">{{
                        $t("Administration.Bind")
                      }}</el-button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane :label="$t('Administration.templatemanagement')" name="模板管理">
            <div class="datepicker">
              <div>
                <el-button v-if="BUTTONS.Administrationadd" type="primary" size="large" color="#0052d9" @click="newaddition">
                  {{ $t("Administration.newlyadded") }}
                </el-button>
              </div>
              <div>
                <el-input
                  v-model="keyword"
                  style="width: 360px"
                  placeholder="请输入内容,例如模板名称，标签"
                  size="large"
                />&ensp;&ensp;
                <el-button type="primary" size="large" @click="gettmplpage" color="#0052d9">{{
                  $t("Administration.Query")
                }}</el-button>
                <el-button size="large" @click="onreset">{{ $t("Administration.Reset") }}</el-button>
              </div>
            </div>

            <div class="eltable templatebox">
              <el-table :data="tmplpagedata.records" border style="width: 100%" :show-overflow-tooltip="true">
                <el-table-column prop="name" :label="$t('Administration.Reset')" />
                <el-table-column prop="isUsing" :label="$t('Administration.Status')" align="center" width="140">
                  <template #default="scope">
                    <div v-if="scope.row.isUsing == 1">{{ $t("Administration.Referenced") }}</div>
                    <div v-else>{{ $t("Administration.Unreferenced") }}</div>
                  </template>
                </el-table-column>
                <el-table-column prop="tags" :label="$t('Administration.Tags')" />
                <el-table-column prop="createUserName" :label="$t('Administration.CreatedBy')" width="140" />
                <el-table-column prop="createTime" :label="$t('Administration.CreationTime')" />
                <el-table-column prop="tariffId" :label="$t('Administration.Actions')" width="180">
                  <template #default="scope">
                    <el-button class="bodycheck" @click="oncheck(scope.row.id)">{{ $t("Administration.View") }}</el-button>
                    <el-button class="bodycheck" @click="neweditition(scope.row.id)">{{ $t("Administration.Edit") }}</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="pagination">
              <div></div>
              <slot name="pagination">
                <Pagination
                  :pageable="pageable"
                  :handle-size-change="handleSizeChange"
                  :handle-current-change="handleCurrentChange"
                />
              </slot>
            </div>
          </el-tab-pane>
          <el-tab-pane :label="$t('Administration.timesharingmanagement')" name="分时电价管理">
            <div class="datepicker">
              <div class="selectsite_right">
                <div class="tabpane_1">地区：</div>
                <el-select
                  v-model="onlineStatus"
                  placeholder="选择地区"
                  size="large"
                  style="width: 240px"
                  @change="postemsDevice"
                >
                  <el-option
                    v-for="item in province"
                    :key="item.provinceid"
                    :label="item.provincename"
                    :value="item.provinceid"
                  />
                </el-select>
                &ensp;&ensp;&ensp;
                <div>
                  选择月份：
                  <el-date-picker
                    v-model="timedayslist"
                    type="month"
                    format="YYYY-MM"
                    value-format="YYYY-MM"
                    size="large"
                    placeholder="选择月份"
                    :disabled-date="pickerOptions"
                    @change="onpowerblur"
                  />
                </div>
                &ensp;&ensp;&ensp;
                <el-button type="primary" size="large" color="#0052d9" @click="newaddimport">数据回复</el-button>

                <!-- newition -->
              </div>
            </div>
            <div class="eltable templatebox">
              <el-table :data="proiceexcel" border style="width: 100%" :show-overflow-tooltip="true">
                <el-table-column prop="provincename" label="湖南" />
                <el-table-column prop="year" label="年" />
                <el-table-column prop="month" label="月份" />
                <el-table-column prop="createdate" label="创建时间" />
              </el-table>
            </div>
            <div class="pagination">
              <div></div>
              <slot name="pagination">
                <Pagination
                  :pageable="pageable"
                  :handle-size-change="handleSizeChange"
                  :handle-current-change="handleCurrentChange"
                />
              </slot>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
    <el-dialog v-model="dialogVisible" :title="$t('Administration.TemplateName')" width="1000" :before-close="handleClose" border>
      <div class="dialog_title">
        <div class="more_name">{{ $t("Administration.TemplateName") }}：</div>
        <div class="more_theme">{{ tytmplpagedetails.data[0].name }}</div>
      </div>
      <div class="dialog_title">
        <div class="more_name">{{ $t("Administration.Templatestatus") }}：</div>
        <div class="more_theme">{{ $t("Administration.inuse") }}</div>
      </div>
      <div class="dialog_title">
        <div class="more_name">{{ $t("Administration.usage") }}：</div>
        <div class="more_theme">
          <div class="dialog_11">
            <div class="dialog_1" v-for="(item, index) in tytmplpagedetails.stationUsing" :key="index">
              <span class="dialog_name">{{ item.tmplName }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="dialog_title">
        <div class="more_name">{{ $t("Administration.Templatelabel") }}：</div>
        <div class="more_theme">-</div>
      </div>
      <div class="eltable1">
        <el-table :data="tytmplpagedetails.scheduleVOS" border style="height: 300px">
          <el-table-column label="开始时间——结束时间" width="180" align="center">
            <template #default="scope">
              <span>{{ scope.row.startTime }}</span> -
              <span>{{ scope.row.endTime }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="periodType" :label="$t('Administration.Templatelabel')" width="180" align="center">
            <template #default="scope">
              <div v-if="scope.row.periodType == 2">峰</div>
              <div v-if="scope.row.periodType == 1">尖</div>
              <div v-if="scope.row.periodType == 4">谷</div>
              <div v-if="scope.row.periodType == 3">平</div>
            </template>
          </el-table-column>
          <el-table-column prop="buyPrice" :label="$t('Administration.Purchase')" align="center" />
          <el-table-column prop="salePrice" :label="$t('Administration.Sellingelectricity')" align="center" />
        </el-table>
      </div>
      <template #footer>
        <div class="dialog_footer">
          <el-button type="primary" @click="dialogVisible = false" color="#0052d9"> {{ $t("Administration.sure") }} </el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog
      v-model="dialogtmptariff"
      :title="$t('Administration.Templatedetails')"
      width="1000"
      :before-close="handleClose"
      border
    >
      <div class="dialog_title">
        <div class="more_name">{{ $t("Administration.TemplateName") }}：</div>
        <div class="more_theme">{{ tytmpltariff.data[0].name }}</div>
      </div>
      <div class="dialog_title">
        <div class="more_name">{{ $t("Administration.TemplateName") }}：</div>
        <div class="more_theme">{{ $t("Administration.inuse") }}</div>
      </div>
      <div class="dialog_title">
        <div class="more_name">{{ $t("Administration.usage") }}：</div>
        <div class="more_theme">
          <div class="dialog_11">
            <div class="dialog_1" v-for="(item, index) in tytmpltariff.stationUsing" :key="index">
              <span class="dialog_name">{{ item.tmplName }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="dialog_title">
        <div class="more_name">{{ $t("Administration.Templatelabel") }}：</div>
        <div class="more_theme">-</div>
      </div>
      <div class="eltable1">
        <el-table :data="tytmpltariff.scheduleVOS" border style="height: 300px">
          <el-table-column label="开始时间——结束时间" width="180" align="center">
            <template #default="scope">
              <span>{{ scope.row.startTime }}</span> -
              <span>{{ scope.row.endTime }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="periodType" :label="$t('Administration.periodoftime')" width="180" align="center">
            <template #default="scope">
              <div v-if="scope.row.periodType == 2">峰</div>
              <div v-if="scope.row.periodType == 1">尖</div>
              <div v-if="scope.row.periodType == 4">谷</div>
              <div v-if="scope.row.periodType == 3">平</div>
            </template>
          </el-table-column>
          <el-table-column prop="buyPrice" :label="$t('Administration.Purchase')" align="center" />
          <el-table-column prop="salePrice" :label="$t('Administration.Sellingelectricity')" align="center" />
        </el-table>
      </div>
      <template #footer>
        <div class="dialog_footer">
          <el-button type="primary" @click="dialogtmptariff = false" color="#0052d9"> {{ $t("Administration.sure") }} </el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog v-model="overview" title="电价时段总览" top="5vh" :before-close="handoverview" border>
      <div class="dialog">
        <div class="dialog_box">
          <div class="dialog_box111">
            <div class="dialog_box1">{{ $t("Administration.periodoftime") }}</div>
            <div class="overview_dox1" v-for="(itme, index) in headers" :key="index">{{ itme }}</div>
          </div>
          <div class="overview_title1" v-for="(item, index) in poweroverdata" :key="index">
            <div class="dialog_box1">{{ item.time }}- {{ getNextTime(index) }}</div>
            <div class="overview_title1">
              <div class="dialog_box11" v-for="(items, a) in 12" :key="a">
                <div class="overview_1dox" v-if="poweroverdata[index][items] == 1">高峰</div>
                <div class="overview_2dox" v-if="poweroverdata[index][items] == 2">尖峰</div>
                <div class="overview_3dox" v-if="poweroverdata[index][items] == 3">平段</div>
                <div class="overview_4dox" v-if="poweroverdata[index][items] == 4">低谷</div>
                <div class="overview_5dox" v-if="poweroverdata[index][items] == ''"></div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <template #footer>
        <div class="dialog_footer">
          <el-button type="primary" @click="overview = false" color="#0052d9"> {{ $t("Administration.sure") }} </el-button>
        </div>
      </template>
    </el-dialog>
    <!--    -->
    <el-dialog v-model="binding" title="绑定" :before-close="handbinding" width="600" border>
      <div class="overview_title">
        <div>{{ $t("Administration.TemplateName") }}：</div>
        <el-select
          v-model="onbindingvalue"
          filterable
          :placeholder="$t('Administration.TemplateName')"
          style="width: 300px"
          size="large"
        >
          <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </div>

      <template #footer>
        <div class="dialog_footer">
          <el-button type="primary" @click="onbinding" color="#0052d9"> {{ $t("Administration.sure") }} </el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog v-model="energystorage" title="大储导入" top="100px" width="40%" @close="handenergyClose">
      <div class="dialoglexce_box">
        <div class="dialoglexce_right">
          <el-upload class="upload-demo" :data="uploadData" drag :before-upload="beforeUpload" multiple>
            <el-icon class="el-icon--upload"><upload-filled /></el-icon>
            <div class="el-upload__text">点击上传 <em>拖拽上传</em></div>
            <template #tip>
              <div class="el-upload__tip">上传文件，文件大小500kb</div>
            </template>
          </el-upload>
        </div>
      </div>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handenergyClose">取消导出</el-button>
          <el-button type="primary" @click="handenergysure"> 确定 </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<!--   
  
-->
<script setup lang="ts">
import { onMounted, Ref, ref } from "vue";
import {
  stationstationName,
  electricitylist,
  electricitytmplpage,
  electricitytmplpagedetails,
  insertscheduletariffURL,
  selectelectURL,
  selectpoweroverviewURL,
  electricitytmptariff,
  selectproiceexcelURL,
  selectprovinceURL,
  priceanalysisURL
} from "@/api/home/Multisite";
import { other, Station } from "@/api/interface";
import Pagination from "@/components/ProTable/components/Pagination.vue";
import { useRouter, useRoute } from "vue-router";
import { ElNotification } from "element-plus";
import { useAuthButtons } from "@/hooks/useAuthButtons";
const { BUTTONS } = useAuthButtons();

const router = useRouter();
const route = useRoute();
const currentDate = ref();
const Singlevalue = ref("");
const cities: Ref<Station.todo[]> = ref([]);

const poststationstationName = async () => {
  const { data } = await stationstationName({});
  if (data.length > 0) {
    const firstElementId = data[0].id;
    Singlevalue.value = firstElementId;
  }

  cities.value = data;
  postersDevice(Singlevalue.value);
};
//浙江温州市1号电站
const postersDevice = async (value: any) => {
  console.log(value);
  getelectricitylist();
};

const handleClick = async (val: any) => {
  console.log(val);

  if (val.props.name == "电价配置") {
    getelectricitylist();
  } else if (val.props.name == "模板管理") {
    gettmplpage();
  } else if (val.props.name == "分时电价管理") {
    getselectprovince();
    getselectproiceexcel();
  }
};
// 电价配置
const activeName: Ref<any> = ref("");
const currentYear = new Date().getFullYear();
console.log(currentYear);

const pickervalue = ref();
pickervalue.value = currentYear + "";
// const pickerOptions = (time: { getTime: (arg0: Date) => number }) => {
//   return time.getTime(new Date()) > Date.now();
// };
// 选择日期
const pickerincome = async () => {
  getelectricitylist();
};

// 电价配置
const tricitylist: Ref<Station.electricity[]> = ref([]);

const getelectricitylist = async () => {
  const { data } = await electricitylist({}, pickervalue.value, Singlevalue.value);
  tricitylist.value = data;
  getselectpoweroverview();
};
// 模板管理查看
const dialogVisible = ref();
const oncheck = (tariffId: any) => {
  getelectricitytmplpagedetails(tariffId);
  dialogVisible.value = true;
};
// 模板配置详情
const tytmplpagedetails = ref();
const getelectricitytmplpagedetails = async (tariffId?: any) => {
  const { data } = await electricitytmplpagedetails({}, tariffId);
  tytmplpagedetails.value = data;
};
// 电价配置查看
const dialogtmptariff = ref();
const configuration = (tariffId: any) => {
  onelectricitytmptariff(tariffId);
  dialogtmptariff.value = true;
};
const tytmpltariff = ref();
const onelectricitytmptariff = async (tariffId?: any) => {
  const { data } = await electricitytmptariff({}, tariffId);
  tytmpltariff.value = data;
};

// 解绑弹窗
const gettariffid = ref();
const onUnbind = (itme: any) => {
  gettariffid.value = itme.tariffId;
  startvalue.value = 1;
  onbindingvalue.value = itme.tmplId;
  onbinding();
};
// 绑定弹窗
const ondetermine = (itme: any) => {
  gettariffid.value = itme.tariffId;
  onbindingvalue.value = itme.tmplId;
  startvalue.value = 0;

  binding.value = true;
};
const handleClose = () => {
  dialogVisible.value = false;
  dialogtmptariff.value = false;
};
// 模板管理表格数据
//
const tmplpagedata = ref();
const keyword = ref("");
const gettmplpage = async () => {
  let obj = {
    keyword: keyword.value,
    pn: pageable.value.pn,
    ps: pageable.value.ps
  };
  const { data } = await electricitytmplpage(obj);

  tmplpagedata.value = data;
  pageable.value.total = tmplpagedata.value.total;
};

const onreset = async () => {
  keyword.value = "";
  pageable.value.ps = 10;
  pageable.value.pn = 1;
  gettmplpage();
};
// 分页
const pageable = ref({
  pn: 1,
  ps: 10,
  total: 0
});
// 表格操作 Hooks
const handleSizeChange = async (e: any) => {
  pageable.value.ps = e;
  gettmplpage();
};
const handleCurrentChange = async (e: any) => {
  pageable.value.pn = e;

  gettmplpage();
};
const newaddition = () => {
  router.push({
    path: "/Administration/addition",
    query: {
      type: "模板新增", // 传递的参数
      id: ""
    }
  });
};
const neweditition = (id: any) => {
  router.push({
    path: "/Administration/addition",
    query: {
      type: "电价编辑", // 传递的参数
      id: id
    }
  });
};

// 年份总览
const overview = ref(false);
const onoverview = () => {
  overview.value = true;
};
const handoverview = () => {
  overview.value = false;
};
// 绑定
const binding = ref(false);
const handbinding = () => {
  binding.value = false;
};
// const value = ref("");
const options = ref();
// 绑定列表
const onbindingvalue = ref("");

const getselectelect = async () => {
  let obj = {
    name: ""
  };
  const { data } = await selectelectURL(obj);
  options.value = data;
};
// 绑定确认弹窗
const startvalue = ref();
const onbinding = async () => {
  console.log(onbindingvalue.value == " ");

  if (onbindingvalue.value == " " || onbindingvalue.value == "") {
    ElNotification({
      title: "温馨提示",
      message: "请选择模板并绑定！",
      type: "warning"
    });
    return;
  }
  let obj = {
    tmplId: onbindingvalue.value,
    start: startvalue.value,
    tariffId: gettariffid.value
  };
  await insertscheduletariffURL(obj);
  binding.value = false;
  getelectricitylist();
};
// 电价总览
let poweroverdata = ref();
const headers = ref(["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]); // 表头数据

const getselectpoweroverview = async () => {
  let obj = {
    powerId: Singlevalue.value,
    year: pickervalue.value
  };
  const { data } = await selectpoweroverviewURL(obj);
  // poweroverdata.value = data.data;

  const dato: other.Select = data;

  const getdata = [
    ...dato[1],
    ...dato[2],
    ...dato[3],
    ...dato[4],
    ...dato[5],
    ...dato[6],
    ...dato[7],
    ...dato[8],
    ...dato[9],
    ...dato[10],
    ...dato[11],
    ...dato[12]
  ];
  interface TableRow {
    time: string;
    [key: number]: string; // 列以月份为键
  }
  // 处理数据
  const timeSlots = [
    "23:00",
    "23:30",
    "00:00",
    "00:30",
    "01:00",
    "01:30",
    "02:00",
    "02:30",
    "03:00",
    "03:30",
    "04:00",
    "04:30",
    "05:00",
    "05:30",
    "06:00",
    "06:30",
    "07:00",
    "07:30",
    "08:00",
    "08:30",
    "09:00",
    "09:30",
    "10:00",
    "10:30",
    "11:00",
    "11:30",
    "12:00",
    "12:30",
    "13:00",
    "13:30",
    "14:00",
    "14:30",
    "15:00",
    "15:30",
    "16:00",
    "16:30",
    "17:00",
    "17:30",
    "18:00",
    "18:30",
    "19:00",
    "19:30",
    "20:00",
    "20:30",
    "21:00",
    "21:30",
    "22:00",
    "22:30",
    "23:00",
    "23:30"
  ];
  const months = Array.from({ length: 12 }, (_, i) => i + 1);
  // 初始化表格
  const table: TableRow[] = timeSlots.map(time => ({
    time,
    ...months.reduce((acc, month) => ({ ...acc, [month]: "" }), {})
  }));

  // 填充表格（优化版）
  getdata.forEach(item => {
    const startIndex = timeSlots.indexOf(item.startTime);
    let endIndex = timeSlots.indexOf(item.endTime);

    // 处理找不到时间的情况
    if (startIndex === -1 || endIndex === -1) {
      console.warn(`找不到时间: ${item.startTime} 或 ${item.endTime}`);
      return;
    }

    // 处理跨天情况（结束时间小于开始时间）
    if (endIndex < startIndex) {
      endIndex += timeSlots.length;
    }

    // 填充时间段
    for (let i = startIndex; i < endIndex && i < timeSlots.length; i++) {
      table[i % timeSlots.length][item.imonth] = item.periodType;
    }
  });
  console.log(getdata);
  console.log(table);
  poweroverdata.value = table;
  // 输出结果
};
// 计算下一个时间的函数
const getNextTime = (index: number) => {
  const nextIndex = index + 1;
  if (nextIndex < poweroverdata.value.length) {
    return poweroverdata.value[nextIndex].time;
  } else {
    return "24:00";
  }
};
// 分时电价管理
const proiceexcel = ref();
// 分页
const paging = ref({
  pn: 1,
  ps: 10,
  total: 0
});
const province = ref();
const timedayslist = ref("");
const iceexcelyear = ref("");
const iceexcelmonth = ref("");
const getselectprovince = async () => {
  let obj = {};
  const { data } = await selectprovinceURL(obj);
  console.log(data);
  province.value = data;
};
const getselectproiceexcel = async () => {
  let obj = {
    provincename: onlineStatus.value,
    year: iceexcelyear.value,
    month: iceexcelmonth.value
  };
  const { data } = await selectproiceexcelURL(obj);
  console.log(data);

  proiceexcel.value = data;
  paging.value.total = proiceexcel.value.total;
};
// 查询地址
const onlineStatus = ref();
const postemsDevice = async (value: any) => {
  onlineStatus.value = value;
};

// 查询月份
const pickerOptions = (time: { getTime: (arg0: Date) => number }) => {
  return time.getTime(new Date()) > Date.now();
};
const onpowerblur = (e: any) => {
  console.log(e);
  // e.substring(0, 4);
  iceexcelyear.value = e.substring(0, 4);
  iceexcelmonth.value = e.substring(5, 7);
  timedayslist.value = e;
};
const energystorage = ref();
const uploadData = ref();

const newaddimport = () => {
  energystorage.value = true;
};
const handenergyClose = async () => {
  energystorage.value = false;
  uploadData.value = "";
};
const beforeUpload = (file: Blob | MediaSource) => {
  // 获取文件的临时路径
  const filePath = URL.createObjectURL(file);
  console.log("文件临时路径:", filePath);
  console.log(file);
  uploadData.value = file;
  // 手动上传文件
  // uploadFile(file);

  // 返回 false，阻止默认上传行为
  return false;
};
const handenergysure = async () => {
  let obj = {};
  // 创建 FormData 对象
  const formData = new FormData();
  formData.append("file", uploadData.value); // 添加文件
  try {
    // 调用上传接口
    const { data } = await priceanalysisURL(obj, formData);
    console.log(data);
    energystorage.value = false;
  } catch (error) {
    console.error("上传失败:", error);
  }
};
onMounted(() => {
  const current = localStorage.getItem("currentDate");
  if (current) {
    currentDate.value = current;
  }
  poststationstationName();
  if (route.query.id) {
    activeName.value = route.query.id;
    gettmplpage();
  } else {
    activeName.value = "电价配置";
  }
  const today = new Date();
  const sevenDaysAgoDate = new Date(today);
  sevenDaysAgoDate.setDate(today.getDate() - 7);
  // const year = sevenDaysAgoDate.getFullYear();
  // const month = String(sevenDaysAgoDate.getMonth() + 1).padStart(2, "0"); // Months are zero-based
  // const formattedDate = `${year}-${month}`;

  // timedayslist.value = formattedDate;

  getselectelect();
});
</script>
<style scoped lang="scss">
@import "./index.scss";
</style>
<!--
  
 -->
