<template>
  <div class="content-box">
    <div class="left">
      <!-- <el-icon :size="23" class="camera"><UserFilled /></el-icon> -->
      <div class="cameratxt">报表统计</div>
    </div>
    <!-- 汇总搜索框 -->
    <div class="middle" v-if="footerMenuIndex == 0">
      <div class="filter">
        <div class="condition">
          <span>车牌号 : </span>
          <!-- <el-input
            clearable
            v-model="searchInputHZ.car_number"
            class="w-50 m-2"
            placeholder="请输入车牌号"
            style="width: 150px"
          /> -->
          <el-select
            v-model="searchInputHZ.car_number"
            class="m-2"
            placeholder="请选择车牌号"
          >
            <el-option
              v-for="item in busNum.list"
              :label="item.car_number"
              :value="item.car_number"
            />
          </el-select>
        </div>
        <div class="condition">
          <span>汇总日期 : </span>
          <!-- <el-date-picker
            v-model="searchData.input5"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="YYYY-MM-DD HH:mm:ss"
            value-format="YYYY-MM-DD HH:mm:ss"
          /> -->
          <el-date-picker
            v-model="searchInputHZ.date"
            type="date"
            placeholder="请选择日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            :clearable="false"
          />
        </div>
        <div class="condition">
          <span>状态 : </span>
          <el-select
            v-model="searchInputHZ.state"
            class="m-2"
            placeholder="请选择状态"
          >
            <el-option label="预约中" value="1" />
            <el-option label="已截止" value="2" />
            <el-option label="候补中" value="3" />
            <el-option label="已分车" value="4" />
          </el-select>
        </div>

        <el-button
          style="margin-left: 20px"
          color="rgba(61, 81, 232, 1)"
          type="primary"
          class="search"
          @click="searchHZ"
          ><el-icon> <Search /> </el-icon><span>搜索</span></el-button
        >
        <el-button
          style="margin-left: 20px"
          color="rgba(61, 81, 232, 1)"
          type="primary"
          class="search"
          @click="resetInputHZ"
          ><el-icon> <Refresh /> </el-icon><span>重置</span></el-button
        >
      </div>
      <!-- <el-button
        color="rgba(61, 81, 232, 1)"
        class="import"
        type="primary"
        @click="downLoad"
        ><img
          src="@/assets/import.png"
          style="width: 14px; height: 14px; margin-right: 4px"
          alt=""
        />
        <span>导出表单</span></el-button
      > -->
    </div>
    <!-- 明细列表搜索框 -->
    <div class="middle" v-if="footerMenuIndex == 1">
      <div class="filter">
        <div class="condition">
          <span>车牌号 : </span>
          <!-- <el-input
            clearable
            v-model="searchInput.car_number"
            class="w-50 m-2"
            placeholder="请输入车牌号"
            style="width: 150px"
          /> -->
          <el-select
            v-model="searchInput.car_number"
            class="m-2"
            placeholder="请选择车牌号"
          >
            <el-option
              v-for="item in busNum.list"
              :label="item.car_number"
              :value="item.car_number"
            />
          </el-select>
        </div>
        <div class="condition">
          <span>发车日期 : </span>
          <!-- <el-date-picker
            v-model="searchData.input5"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="YYYY-MM-DD HH:mm:ss"
            value-format="YYYY-MM-DD HH:mm:ss"
          /> -->
          <el-date-picker
            v-model="searchInput.yy_date"
            type="date"
            placeholder="请选择日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
          />
        </div>
        <div class="condition">
          <span>发车时间 : </span>
          <el-time-picker
            v-model="searchInput.ci_time"
            placeholder="请选择发车时间"
            format="HH:mm"
            value-format="HH:mm"
            :disabled-hours="disabledQueryHours"
            :disabled-minutes="disabledQueryMinutes"
            :disabled-seconds="disabledQuerySeconds"
            @change="addQueryTime"
          />
        </div>
        <div class="condition">
          <span>状态 : </span>
          <el-select
            v-model="searchInput.state"
            class="m-2"
            placeholder="请选择状态"
          >
            <el-option label="预约成功" value="1" />
            <el-option label="上车" value="2" />
            <el-option label="候补" value="3" />
            <el-option label="取消" value="4" />
            <el-option label="爽约" value="5" />
            <el-option label="爽约已核销" value="6" />
          </el-select>
        </div>

        <el-button
          style="margin-left: 20px"
          color="rgba(61, 81, 232, 1)"
          type="primary"
          class="search"
          @click="search"
          ><el-icon> <Search /> </el-icon><span>搜索</span></el-button
        >
        <el-button
          style="margin-left: 20px"
          color="rgba(61, 81, 232, 1)"
          type="primary"
          class="search"
          @click="resetInput"
          ><el-icon> <Search /> </el-icon><span>重置</span></el-button
        >
      </div>
      <el-button
        color="rgba(61, 81, 232, 1)"
        class="import"
        type="primary"
        @click="downLoad"
        ><img
          src="@/assets/import.png"
          style="width: 14px; height: 14px; margin-right: 4px"
          alt=""
        />
        <span>导出表单</span></el-button
      >
    </div>
    <div class="footerMenu">
      <div
        class="menuList"
        @click="collectMenu"
        :class="footerMenuIndex == 0 ? 'menuListActive' : ''"
      >
        汇总
      </div>
      <div
        class="menuList"
        @click="detailMenu"
        :class="footerMenuIndex == 1 ? 'menuListActive' : ''"
      >
        明细列表
      </div>
    </div>
    <!-- 候补派车 -->
    <el-dialog
      class="sendBus"
      v-model="centerDialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="dialongTitle"
      align-center
      width="500"
      :before-close="editClose"
    >
      <el-form
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="100px"
        class="demo-ruleForm"
        :size="formSize"
        label-position="left"
        status-icon
      >
        <el-form-item label="车牌 :" prop="busname">
          <el-select-v2
            validate-event
            v-model="ruleForm.busname"
            :options="options"
            placeholder="请选择车牌号"
            style="width: 260px"
            multiple
          />
        </el-form-item>

        <el-form-item label="容量 :" prop="volume">
          <el-input
            v-model="ruleForm.volume"
            placeholder="请输入容量"
            clearable
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="路线 :" prop="route">
          <el-input
            v-model="ruleForm.route"
            placeholder="请输入路线"
            :disabled="true"
            clearable
          />
        </el-form-item>
        <el-form-item
          label="终点站 :"
          prop="destination"
          style="
            padding-bottom: 40px;
            border-bottom: 1px solid rgba(230, 230, 230, 1);
          "
        >
          <el-select
            v-model="ruleForm.destination"
            class="m-2"
            placeholder="请选择终点站"
          >
            <el-option
              :label="item"
              :value="item"
              v-for="item in endNum.list"
            />
          </el-select>
        </el-form-item>

        <el-form-item class="options">
          <el-button class="congzhi" @click="editClose(ruleFormRef)"
            >取消</el-button
          >
          <el-button
            color="rgba(61, 81, 232, 1)"
            class="queding"
            type="primary"
            @click="submitAdd(ruleFormRef)"
          >
            确定
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <div class="MingXi" v-if="footerMenuIndex == 0">
      <div class="footer mingxi">
        <el-table
          :row-class-name="tableRowClassName"
          :data="tableData.list"
          style="width: 100%; height: 500px"
          :header-cell-style="{
            background: 'rgba(240, 243, 247, 1)',
            border: 0,
          }"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column align="center" type="selection" width="80" /> -->
          <el-table-column
            align="center"
            width="250"
            prop="s_date"
            label="创建时间"
          />
          <el-table-column align="center" prop="ci_time" label="发车时间" />
          <el-table-column align="center" label="预约人数">
            <template #default="scope">
              <div
                v-if="scope.row.yy_num == scope.row.contain"
                style="color: red"
              >
                {{ scope.row.yy_num }}
              </div>
              <div v-else>{{ scope.row.yy_num }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="by_num" label="乘车人数" />
          <el-table-column align="center" prop="contain" label="容量" />
          <el-table-column align="center" prop="car_number" label="车牌号" />
          <el-table-column
            align="center"
            prop="route"
            width="250"
            label="路线"
          />
          <el-table-column align="center" label="状态">
            <template #default="scope">
              <div
                v-if="scope.row.state == 1"
                style="color: rgba(67, 207, 124, 1)"
              >
                预约中
              </div>
              <div
                v-if="scope.row.state == 2"
                style="color: rgba(212, 48, 48, 1)"
              >
                已截止
              </div>
              <div
                v-if="scope.row.state == 3"
                style="color: rgba(61, 81, 232, 1)"
              >
                候补中
              </div>
              <div
                v-if="scope.row.state == 4"
                style="color: rgba(77, 77, 77, 1)"
              >
                已分车
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template #default="scope">
              <el-button link type="primary" @click="info(scope.row)">
                <div class="look">详情</div>
              </el-button>
              <!-- <el-button
                v-if="scope.row.state == '候补'"
                link
                type="primary"
                @click="sendBus(scope.row)"
                ><div class="look">派车</div></el-button
              > -->
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div style="width: 100%; height: 34px">
        <el-pagination
          background
          v-model:page-size="pageSize"
          v-model:current-page="currentPage"
          layout="total, prev, pager, next, jumper"
          :total="total"
          @current-change="handleCurrentChange"
        />
        <!-- 往返校区预约和乘车人数 -->
        <div
          class="nowday"
          style="
            position: relative;
            width: 1200px;
            color: #000;
            top: -47px;
            font-size: 18px;
          "
        >
          <div>
            <div style="display: inline-block; margin-left: 30px">
              <span style="padding-right: 10px">{{
                gobacknum.list1.s_date
              }}</span>
              <span style="font-size: 18px; font-weight: 800">{{
                gobacknum.list1.route
              }}</span>
              <div
                style="display: inline-block; width: 320px; margin-left: 20px"
              >
                <span style="font-size: 16px; font-weight: 800">教职工</span
                >&nbsp; 预约人数:<span style="color: red">{{
                  gobacknum.list1.yy_num
                }}</span>
                , 乘车人数:<span style="color: red">{{
                  gobacknum.list1.by_num
                }}</span>
              </div>
            </div>
            <div style="display: inline-block">
              <span style="font-size: 16px; font-weight: 800">报备人员</span
              >&nbsp;&nbsp; 预约人数:<span style="color: red">{{
                gobacknum.list2.yy_num
              }}</span>
              , 乘车人数:<span style="color: red">{{
                gobacknum.list2.by_num
              }}</span>
            </div>
          </div>
          <div>
            <div style="display: inline-block; margin-left: 30px">
              <span style="color: transparent; padding-right: 10px">{{
                gobacknum.list3.s_date
              }}</span>
              <span style="font-size: 18px; font-weight: 800">{{
                gobacknum.list3.route
              }}</span>
              <div
                style="display: inline-block; width: 320px; margin-left: 20px"
              >
                <span style="font-size: 16px; font-weight: 800">教职工</span
                >&nbsp; 预约人数:<span style="color: red">{{
                  gobacknum.list3.yy_num
                }}</span>
                , 乘车人数:<span style="color: red">{{
                  gobacknum.list3.by_num
                }}</span>
              </div>
            </div>
            <div style="display: inline-block">
              <span style="font-size: 16px; font-weight: 800">报备人员</span
              >&nbsp;&nbsp; 预约人数:<span style="color: red">{{
                gobacknum.list4.yy_num
              }}</span>
              , 乘车人数:<span style="color: red">{{
                gobacknum.list4.by_num
              }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="MingXi" v-else-if="footerMenuIndex == 1">
      <div class="footers footer">
        <el-table
          :row-class-name="tableRowClassName"
          :data="tableData.list2"
          style="width: 100%; height: 550px"
          :header-cell-style="{
            background: 'rgba(240, 243, 247, 1)',
            border: 0,
          }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            align="center"
            width="200"
            prop="yy_time"
            label="下单时间"
          />
          <el-table-column
            align="center"
            width="120"
            prop="yy_date"
            label="发车日期"
          />
          <el-table-column align="center" prop="ci_time" label="发车时间" />
          <el-table-column align="center" prop="user_name" label="预约人" />
          <el-table-column align="center" prop="user_zz" label="身份" />
          <el-table-column
            align="center"
            width="150"
            prop="user_phone"
            label="手机号码"
          />

          <el-table-column
            width="130"
            align="center"
            prop="car_number"
            label="车牌号"
          />
          <el-table-column
            align="center"
            width="40"
            prop="contain"
            label="容量"
          />
          <el-table-column
            align="center"
            prop="route"
            width="200"
            label="路线"
          /><el-table-column
            align="center"
            prop="route_end"
            width="330"
            label="终点站"
          />
          <!-- <el-table-column
            align="center"
            prop="remark"
            width="450"
            label="变更信息"
          /> -->

          <el-table-column
            align="center"
            width="180"
            prop="by_time"
            label="通行时间"
          />
          <el-table-column align="center" label="状态" width="100">
            <template #default="scope">
              <div v-if="scope.row.state == 1" style="color: blue">
                预约成功
              </div>
              <div v-if="scope.row.state == 2" style="color: rgb(50, 201, 110)">
                上车
              </div>
              <div v-if="scope.row.state == 3" style="color: rgb(236, 168, 22)">
                候补
              </div>
              <div v-if="scope.row.state == 4" style="color: #ccc">取消</div>
              <div v-if="scope.row.state == 5" style="color: rgb(255, 0, 0)">
                爽约
              </div>
              <div v-if="scope.row.state == 6" style="color: rgb(42, 228, 200)">
                爽约已核销
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column align="center" label="操作">
            <template #default="scope">
              <el-button link type="primary" @click="look(scope.row)"
                ><div class="look">查看</div></el-button
              >
            </template>
          </el-table-column> -->
        </el-table>
      </div>
      <el-pagination
        background
        v-model:page-size="pageSize2"
        v-model:current-page="currentPage2"
        layout="total, prev, pager, next, jumper"
        :total="total2"
        @current-change="handleCurrentChange2"
      />
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, watch, onBeforeMount } from "vue";
import { useRouter } from "vue-router";
import { Select, Pointer, Upload } from "@element-plus/icons-vue";
import { JSEncrypt } from "jsencrypt"; // 加密密码
import { ElMessage, ElMessageBox } from "element-plus";
import { dayjs } from "element-plus";
import axios from "axios";
import lodash from "lodash";
import adminApi from "@/api/admin.js";
import { useStore } from "vuex";
const store = useStore();
const router = useRouter();

// 汇总搜索框数据
const searchInputHZ = reactive({
  state: "",
  date: dayjs().format("YYYY-MM-DD"),
  car_number: "",
});
const gobacknum = reactive({ list1: {}, list2: {}, list3: {}, list4: {} }); // 当日黄家湖-墨轩湖人数

const api = ref("");
// 明细列表搜索框数据
const searchInput = reactive({
  ci_time: "",
  state: "",
  yy_date: "",
  car_number: "",
});

const busNum = reactive({ list: [] }); // 车牌号
const pathNum = reactive({ list: [] }); // 路线
const endNum = reactive({ list: [] }); // 终点站

// 表格数据
const tableData = reactive({
  list: [], //汇总数据
  list2: [], //明细列表数据
});

const dialongTitle = ref("候补派车"); // 弹窗标题
const centerDialogVisible = ref(false); // 候补弹窗显示
const initials = reactive({
  list: [],
}); // 候补弹窗多选车牌号数据
const options = ref(
  Array.from({ length: initials.list.length }).map((_, idx) => ({
    value: `${initials.list[idx % 10]}`,
    label: `${initials.list[idx % 10]}`,
  }))
); //候补弹窗多选车牌号逻辑

// 汇总
const pageSize = ref(9);
const currentPage = ref(1); // 当前页
const total = ref(10); // 当前总数
const selectData = reactive({ list: [] }); // 多选框选择的数据
// 明细列表
const pageSize2 = ref(10);
const currentPage2 = ref(1); // 当前页
const total2 = ref(10); // 当前总数

const footerMenuIndex = ref(0); // 控制汇总和明细列表
// 表单数据
const formSize = ref("default");
const ruleFormRef = ref();

const ruleForm = reactive({
  busname: [], //候补弹窗车牌绑定数据
  volume: "",
  route: "黄家湖校区-墨轩湖校区",
  destination: "",
});
// 表单验证
const rules = reactive({
  busname: [
    {
      required: true,
      message: "至少选择一个车牌号",
      trigger: "change",
    },
  ],
  volume: [
    {
      required: true,
      message: "容量不能为空",
      trigger: "blur",
    },
    {
      pattern: /^(0|[1-9][0-9]*)$/,
      message: "请输入正确数字",
      trigger: "blur",
    },
  ],
  route: [
    {
      required: true,
      message: "路线不能为空",
      trigger: "blur",
    },
  ],
  destination: [
    {
      required: true,
      message: "请选择终点站",
      trigger: "change",
    },
  ],
});

// 获取数据列表
const getList = async (message) => {
  if (footerMenuIndex.value == 0) {
    let data = new FormData();
    if (searchInputHZ.state) {
      data.set("state", searchInputHZ.state);
    }
    if (searchInputHZ.date) {
      data.set("date", searchInputHZ.date);
    }
    data.set("car_number", searchInputHZ.car_number); //前面的key记得对应！
    data.set("page", currentPage.value);
    data.set("rows", pageSize.value); //前面的key记得对应！
    let res = await axios({
      method: "post",
      url: api.value + "/carBook/schelist.action",
      headers: {
        token: sessionStorage.getItem("token"),
      },
      data: data,
    });
    console.log(res);
    if (res.status == 200) {
      if (message) {
        ElMessage({
          type: "success",
          showClose: true,
          message: message,
          center: true,
        });
      }
      tableData.list = res.data.rows;
      // currentPage.value = res.data.currentPage;
      total.value = res.data.total;
    } else {
      tableData.list2 = res.data.rows;
      currentPage.value = 1;
      total.value = res.data.total;
      ElMessage({
        type: "error",
        showClose: true,
        message: res.data.message,
        center: true,
      });
      if (res.data.message == "token错误") {
        router.push({
          path: `/login`,
        });
      }
    }
    // 单独获取今日预约人数和乘车人数
    // {
    //   let datas = new FormData();
    //   datas.set("page", 1);
    //   datas.set("rows", 100); //前面的key记得对应！
    //   // if (searchInputHZ.date) {
    //   //   datas.set("date", searchInputHZ.date);
    //   // }
    //   let resdata = await axios({
    //     method: "post",
    //     url: api.value + "/carBook/schelist.action",
    //     headers: {
    //       token: sessionStorage.getItem("token"),
    //     },
    //     data: datas,
    //   });
    //   console.log(resdata.data.rows, "单独数据");
    //   nowDayH_M.H_Mby = 0;
    //   nowDayH_M.H_Myy = 0;
    //   nowDayM_H.M_Hyy = 0;
    //   nowDayM_H.M_Hby = 0;
    //   resdata.data.rows.forEach((item) => {
    //     if (item.route == "黄家湖校区-墨轩湖校区") {
    //       nowDayH_M.H_Myy = nowDayH_M.H_Myy + Number(item.yy_num);
    //       nowDayH_M.H_Mby = nowDayH_M.H_Mby + Number(item.by_num);
    //     } else if (item.route == "墨轩湖校区-黄家湖校区") {
    //       nowDayM_H.M_Hyy = nowDayM_H.M_Hyy + Number(item.yy_num);
    //       nowDayM_H.M_Hby = nowDayM_H.M_Hby + Number(item.by_num);
    //     }
    //   });
    // }
  } else if (footerMenuIndex.value == 1) {
    let data = new FormData();
    // if (searchInput.createTime == null) {
    //   searchInput.createTime = "";
    // }
    if (searchInput.car_number) {
      data.set("car_number", searchInput.car_number);
    }
    data.set("state", searchInput.state);
    if (searchInput.ci_time) {
      data.set("ci_time", searchInput.ci_time);
    }
    if (searchInput.yy_date) {
      data.set("yy_date", searchInput.yy_date);
    }
    data.set("page", currentPage2.value);
    data.set("rows", pageSize2.value); //前面的key记得对应！
    let res = await axios({
      method: "post",
      url: api.value + "/carBook/brecblist.action",
      headers: {
        token: sessionStorage.getItem("token"),
      },
      data: data,
    });
    console.log(res);
    if (res.status == 200) {
      if (message) {
        ElMessage({
          type: "success",
          showClose: true,
          message: message,
          center: true,
        });
      }
      tableData.list2 = res.data.rows;
      if (res.data.currentPage) {
        currentPage2.value = res.data.currentPage;
      } else {
        currentPage2.value = 1;
      }

      total2.value = res.data.total;
    } else {
      tableData.list2 = res.data.rows;
      currentPage2.value = 1;
      total2.value = res.data.total;
      ElMessage({
        type: "error",
        showClose: true,
        message: res.data.message,
        center: true,
      });
      if (res.data.message == "token错误") {
        router.push({
          path: `/login`,
        });
      }
    }
  }
};
// 获取往返黄家湖-墨轩湖的预约人数乘车人数
const goBackNum = async () => {
  let data = new FormData();
  data.set("date", searchInputHZ.date); //日期参数
  let res = await axios({
    method: "post",
    url: api.value + "/carBook/scheroutetj.action",
    headers: {
      token: sessionStorage.getItem("token"),
    },
    data: data,
  });
  console.log(res, "往返校区的人数");

  // 墨轩湖 到 黄家湖
  res.data.data.forEach((item) => {
    if (item.route == "靖安-南昌") {
      if (item.user_zz == "教职工") {
        gobacknum.list1 = res.data.data[0]; // 教职工
      } else if (item.user_zz == "报备人员") {
        gobacknum.list2 = res.data.data[1]; // 报备人员
      }
    } else if (item.route == "南昌-靖安") {
      if (item.user_zz == "教职工") {
        gobacknum.list3 = res.data.data[2]; // 教职工
      } else if (item.user_zz == "报备人员") {
        gobacknum.list4 = res.data.data[3]; // 报备人员
      }
    }
  });
};
// 汇总搜索按钮
const searchHZ = lodash.debounce(() => {
  getList("查询成功");
  goBackNum();
}, 300);
// 汇总重置搜索框
const resetInputHZ = lodash.debounce(() => {
  searchInputHZ.state = "";
  searchInputHZ.date = dayjs().format("YYYY-MM-DD");
  searchInputHZ.car_number = "";
  getList();
  goBackNum();
}, 300);

// 搜索按钮
const search = lodash.debounce(() => {
  getList("查询成功");
}, 300);
// 重置搜索框
const resetInput = lodash.debounce(() => {
  searchInput.state = "";
  searchInput.yy_date = "";
  searchInput.car_number = "";
  searchInput.ci_time = "";
  getList();
}, 300);
// 多选框功能
const handleSelectionChange = (val) => {
  console.log(val);
  selectData.list = val;
};

// 汇总按钮
const collectMenu = () => {
  footerMenuIndex.value = 0;
  searchInput.yy_date = "";
  searchInput.car_number = "";
  searchInput.state = "";
  getList();
};
//明细列表按钮
const detailMenu = () => {
  footerMenuIndex.value = 1;
  getList();
};

// 详情按钮
const info = (row) => {
  console.log(row);
  searchInput.yy_date = row.s_date;
  searchInput.ci_time = row.ci_time;
  searchInput.car_number = row.car_number;
  footerMenuIndex.value = 1;
  currentPage2.value = 1;
  getList();
};
// 派车按钮
const sendBus = (row) => {
  console.log(row);
  centerDialogVisible.value = true;
};
// 派车弹窗关闭
const editClose = () => {
  centerDialogVisible.value = false;
  ruleFormRef.value.resetFields();
};
// 确认派车
const submitAdd = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      if (dialongTitle.value == "候补派车") {
        let data = new FormData();
        data.set("car_number", ruleForm.busname.join(",f"));
        data.set("route", ruleForm.route); //前面的key记得对应！
        data.set("contain", ruleForm.volume);
        data.set("route_end", ruleForm.destination); //前面的key记得对应！
        let res = await axios({
          method: "post",
          url: api.value + "/carBook/brecfen.action",
          headers: {
            token: sessionStorage.getItem("token"),
          },
          data: data,
        });
        // console.log(res, "添加账号");
        if (res.data.code == 200) {
          getList();
          ElMessage({
            type: "success",
            showClose: true,
            message: res.data.message,
            center: true,
          });
          addDialogVisible.value = false;
          ruleFormRef.value.resetFields();
        } else {
          ElMessage({
            type: "error",
            showClose: true,
            message: res.data.message,
            center: true,
          });
        }
      } else {
      }
    } else {
      console.log("error submit!", fields);
    }
  });
};

// 导出按钮
const downLoad = lodash.debounce(async () => {
  let data = new FormData();
  if (searchInput.car_number) {
    data.set("car_number", searchInput.car_number);
  }
  data.set("state", searchInput.state);
  data.set("yy_date", searchInput.yy_date);
  let res = await axios({
    method: "post",
    url: api.value + "/carBook/brectoExcel.action",
    headers: {
      token: sessionStorage.getItem("token"),
    },
    data: data,
  });
  console.log(res);
  if (res.status == 200) {
    // const elt = document.createElement("a");
    // elt.setAttribute(
    //   "href",
    //   "https://chtech.ncjti.edu.cn/carstop" + res.data.downurl
    // );
    // elt.setAttribute("download", "file.png");
    // elt.style.display = "none";
    // document.body.appendChild(elt);
    // elt.click();
    var downloadPath = "https://chtech.ncjti.edu.cn/carstop" + res.data.downurl;
    console.log("获得地址数据:", downloadPath);
    var downloadLink = document.createElement("a");
    downloadLink.style.display = "none"; // 使其隐藏
    downloadLink.href = downloadPath;
    downloadLink.download = "";
    downloadLink.click();
    document.body.appendChild(downloadLink);
    document.body.removeChild(downloadLink);
    ElMessage({
      type: "success",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
}, 300);

// 表格斑马纹颜色修改
const tableRowClassName = ({ row, rowIndex }) => {
  if (rowIndex % 2 === 0) {
    return "even";
  } else if (rowIndex % 2 !== 0) {
    return "odd";
  }
  return "";
};
// 分页
const handleCurrentChange = (value) => {
  currentPage.value = value;
  getList();
};
// 分页
const handleCurrentChange2 = (value) => {
  console.log(value);
  currentPage2.value = value;
  getList();
};
// 监控派车弹窗选择车牌时容量发生变化
watch(
  () => ruleForm.busname,
  (newValue, oldValue) => {
    // console.log("person的job变化了", newValue);
    let volume = 0;
    newValue.forEach((item) => {
      busNum.list.forEach((i) => {
        if (item == i.car_number) {
          volume = volume + i.contain;
        }
      });
    });
    // console.log(volume);
    ruleForm.volume = volume;
  }
);
onBeforeMount(() => {
  api.value = store.state.user.api;
  pathNum.list = JSON.parse(sessionStorage.getItem("pathSelect"));
  busNum.list = JSON.parse(sessionStorage.getItem("busSelect"));
  // busNum.list = JSON.parse(sessionStorage.getItem("busSelect"));
  let route_endSelect = JSON.parse(sessionStorage.getItem("route_endSelect"));
  route_endSelect.forEach((item) => {
    endNum.list.push(item.route_end);
  });
  busNum.list.forEach((item) => {
    initials.list.push(item.car_number);
  });
  options.value = Array.from({ length: initials.list.length }).map(
    (_, idx) => ({
      value: `${initials.list[idx % 10]}`,
      label: `${initials.list[idx % 10]}`,
    })
  );
  getList();
  goBackNum();
});
</script>

<style scoped lang="scss">
.content-box {
  width: 97.5%;
  height: 89%;
  margin: 20px auto;
  background-color: #fff;
  color: #fff;
  display: flex;
  flex-direction: column;

  .left {
    width: calc(100wh - 40px);
    display: flex;
    align-items: center;
    height: 60px !important;
    margin: 0 30px;
    // padding: 10px 0;
    border-bottom: 1px solid #ccc;
    color: #000;
    font-size: 18px;
    font-weight: 600;

    .cameratxt {
      margin-right: 15px;
      display: flex;
      align-items: center;
      height: 60px !important;
    }
  }

  :deep(.sendBus) {
    //   height: 420px;
    border-radius: 11px;

    .el-dialog__header {
      border-radius: 11px 11px 0 0;
      background: rgba(237, 241, 245, 1);
      font-weight: 600;
      margin: 0;

      .el-dialog__headerbtn {
        outline: none;
      }
    }

    .el-dialog__body {
      padding: 30px 20px 10px 20px;

      .el-form-item--feedback {
        .el-input__validateIcon {
          color: rgba(61, 81, 232, 1);
        }
      }

      .el-form-item.is-error .el-input__validateIcon {
        color: red;
      }

      .el-input {
        width: 200px;
      }

      .options {
        margin-left: 200px;
      }
    }
  }

  .middle {
    width: 96%;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    color: #000;
    border-bottom: 1px solid rgb(231, 231, 231);
    padding: 10px 0;
    // 添加员工弹窗样式

    .filter {
      display: flex;
      flex-wrap: wrap;
      align-items: center;

      //   width: 100%;
      .condition {
        display: flex;
        align-items: center;
        margin: 10px 20px 10px 0;

        :deep(.el-input .el-input__inner) {
          font-size: 16px;
        }

        span {
          margin: 0 5px 0 0;
        }
      }
    }

    .import {
      margin: 10px 0;
    }

    .gongneng {
      margin: 10px 0;
    }

    :deep(.cont) {
      width: 60%;
      margin: 20px auto;
    }

    :deep(.download) {
      display: flex;
      align-items: center;
      margin: 10px;
    }

    :deep(.download span) {
      font-size: 16px;
      margin-left: 20px;
    }

    :deep(.cont .el-button) {
      margin-left: 60px;
      margin-bottom: 30px;
    }

    :deep(.cont .accomplish) {
      width: 100%;
      display: flex;
      justify-content: center;
    }

    :deep(.cont .accomplish .el-button) {
      width: 50%;
      margin: 0;
    }
  }

  .footerMenu {
    width: 96%;
    margin: 10px auto 0;
    display: flex;
    align-items: center;

    // height: 40px;
    .menuList {
      padding: 5px 12px;
      border-bottom: 2px solid transparent;
      //   color: rgba(61, 81, 232, 1);
      color: rgba(128, 128, 128, 1);
      cursor: pointer;
      //   font-size: 16px;
      font-weight: 600;
    }

    .menuListActive {
      border-bottom: 2px solid rgba(61, 81, 232, 1);
      color: rgba(61, 81, 232, 1);
      font-size: 17px;
    }
  }

  .footer.mingxi {
    :deep(.el-table__header-wrapper) {
      height: 50px;

      .el-table__header {
        height: 50px;
      }
    }

    .el-table--fit {
      height: 100%;

      :deep(.el-table__row) {
        height: 50px;
      }
    }
  }

  .footer {
    width: 96%;
    height: 510px;
    margin: 20px auto 20px;

    :deep(.el-table__header-wrapper) {
      height: 48px;

      .el-table__header {
        height: 48px;
        font-size: 16px;
        color: #000;
      }
    }

    .el-table--fit {
      height: 100%;

      :deep(.el-table__row) {
        height: 48px;
        font-size: 16px;
        color: #000;
      }

      :deep(.el-table__row td) {
        padding: 0;
        border: 0;
      }

      :deep(.look) {
        padding: 3px 10px;
        border-radius: 40px;
        border: 0.74px solid rgba(30, 125, 251, 1);
      }

      // 输出链接弹窗样式
      :deep(.link .el-dialog__header) {
        text-align: left;
        font-size: 20px;
        font-weight: 600;
      }

      :deep(.link .el-dialog__body) {
        padding: 10px 20px;
        height: 100px;
        margin-bottom: 10px;
      }

      .link {
        .linkcontent {
          text-align: left;
          height: 100px;
          border: 1px solid #ccc;

          p {
            margin: 5px 10px;
          }
        }
      }

      :deep(.playVideo .el-dialog__header) {
        text-align: left;
        font-size: 20px;
        font-weight: 600;
        background-color: #ccc;
        margin-right: 0;
      }

      :deep(.playVideo .el-dialog__body) {
        height: 600px;
      }

      .el-button--primary {
        margin-left: 5px;
      }

      :deep(.el-table__body .even) {
        background-color: #fff;
      }

      :deep(.el-table__body .odd) {
        background-color: rgba(240, 243, 247, 1);
      }
    }
  }

  .footers {
    width: 96%;
    height: 550px;
    margin: 20px auto 20px;

    :deep(.el-table__header-wrapper) {
      height: 48px;

      .el-table__header {
        height: 48px;
        font-size: 16px;
        color: #000;
      }
    }

    .el-table--fit {
      height: 100%;

      :deep(.el-table__row) {
        height: 48px;
        font-size: 16px;
        color: #000;
      }

      :deep(.el-table__row td) {
        padding: 0;
        border: 0;
      }

      :deep(.look) {
        padding: 3px 10px;
        border-radius: 40px;
        border: 0.74px solid rgba(30, 125, 251, 1);
      }

      // 输出链接弹窗样式
      :deep(.link .el-dialog__header) {
        text-align: left;
        font-size: 20px;
        font-weight: 600;
      }

      :deep(.link .el-dialog__body) {
        padding: 10px 20px;
        height: 100px;
        margin-bottom: 10px;
      }

      .link {
        .linkcontent {
          text-align: left;
          height: 100px;
          border: 1px solid #ccc;

          p {
            margin: 5px 10px;
          }
        }
      }

      :deep(.playVideo .el-dialog__header) {
        text-align: left;
        font-size: 20px;
        font-weight: 600;
        background-color: #ccc;
        margin-right: 0;
      }

      :deep(.playVideo .el-dialog__body) {
        height: 600px;
      }

      .el-button--primary {
        margin-left: 5px;
      }

      :deep(.el-table__body .even) {
        background-color: #fff;
      }

      :deep(.el-table__body .odd) {
        background-color: rgba(240, 243, 247, 1);
      }
    }
  }

  .el-pagination {
    // width: 1600px;
    width: 96%;
    margin: 0 auto 18px;
    justify-content: flex-end;

    :deep(.el-pagination__total) {
      color: #000;
    }

    :deep(.el-pagination__goto) {
      color: #000;
    }

    :deep(.el-pagination__classifier) {
      color: #000;
    }

    :deep(.el-input__wrapper) {
      border: 1px solid rgba(0, 0, 0, 1);
      border-radius: 5px;
      box-shadow: none;
    }

    :deep(.el-pager li) {
      margin: 0 5px;
      border: 1px solid rgba(0, 0, 0, 1);
      border-radius: 5px;
      background-color: transparent;
    }

    :deep(.el-pager li.is-active) {
      background-color: rgba(30, 125, 251, 1);
    }

    :deep(.btn-prev) {
      margin-right: 5px;
      border: 1px solid rgba(0, 0, 0, 1);
      border-radius: 5px;
      background-color: transparent;
    }

    :deep(.btn-next) {
      margin-left: 5px;
      border: 1px solid rgba(0, 0, 0, 1);
      border-radius: 5px;
      background-color: transparent;
    }
  }
}

.el-input {
  width: 192px;
}
</style>
