<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"
              :key="item.car_number"
            />
          </el-select>
        </div>
        <div class="condition">
          <span>汇总日期 : </span>
          <el-date-picker
            v-model="searchInputHZ.date"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            unlink-panels
          />
          <!-- <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.route"
            class="m-2"
            placeholder="请选择路线"
          >
            <el-option
              :label="item.route"
              :value="item.route"
              v-for="item in pathNum.list"
              :key="item"
            />
          </el-select>
        </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"
              :key="item.car_number"
            />
          </el-select>
        </div>
        <div class="condition">
          <span>手机号 : </span>
          <el-input
            clearable
            v-model="searchInput.mobile"
            class="w-50 m-2"
            placeholder="请输入手机号"
          />
        </div>
        <div class="condition">
          <span>发车日期 : </span>
          <el-date-picker
            v-model="searchInput.ciCreateTime"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            unlink-panels
          />
          <!-- <el-date-picker
            v-model="searchInput.yy_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="searchInput.route"
            class="m-2"
            placeholder="请选择路线"
          >
            <el-option
              :label="item.route"
              :value="item.route"
              v-for="item in pathNum.list"
              :key="item"
            />
          </el-select>
        </div>
        <div class="condition">
          <span>下单时间 : </span>
          <el-date-picker
            v-model="searchInput.createTime"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            unlink-panels
          />
        </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-select>
        </div>
        <el-button
          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> <Refresh /> </el-icon><span>重置</span></el-button
        >
        <el-button
          style="margin-left: 20px"
          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>
    <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"
              :key="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%"
          :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 class="pagination">
        <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: -53px;
            font-size: 18px;
            z-index: 0;
          "
        >
          <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: 600px; 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>
                <!-- 汇总金额:
                <span style="color: red">{{ gobacknum.list1.account}}元</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.list2.route
              }}</span>
              <div
                style="display: inline-block; width: 600px; margin-left: 20px"
              >
                <span style="font-size: 16px; font-weight: 800">用户</span
                >&nbsp; 预约人数:
                <span style="color: red">{{ gobacknum.list2.yy_num }}</span> ,
                乘车人数:
                <span style="color: red">{{ gobacknum.list2.by_num }}</span>
                <!-- 汇总金额:
                <span style="color: red">{{ gobacknum.list2.account}}元</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 mingxi">
        <el-table
          :row-class-name="tableRowClassName"
          :data="tableData.list2"
          style="width: 100%"
          :header-cell-style="{
            background: 'rgba(240, 243, 247, 1)',
            border: 0,
          }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            align="center"
            width="200"
            prop="createTime"
            label="下单时间"
          />
          <el-table-column
            align="center"
            width="120"
            prop="ciDate"
            label="发车日期"
          />
          <el-table-column align="center" prop="ciTime" label="发车时间" />
          <el-table-column align="center" prop="username" label="预约人" />
          <el-table-column
            align="center"
            width="140"
            prop="mobile"
            label="手机号码"
          />

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

          <el-table-column
            align="center"
            width="180"
            prop="byTime"
            label="通行时间"
          />

          <el-table-column align="center" label="状态" width="100">
            <template #default="scope">
              <div v-if="scope.row.byState == 1" style="color: blue">
                预约成功
              </div>
              <div
                v-if="scope.row.byState == 2"
                style="color: rgb(50, 201, 110)"
              >
                已乘车
              </div>
              <div
                v-if="scope.row.byState == 3"
                style="color: rgb(236, 168, 22)"
              >
                未乘车
              </div>
              <div v-if="scope.row.byState == 4" style="color: #ccc">
                已取消
              </div>
              <div v-if="scope.row.byState == 5" style="color: rgb(255, 0, 0)">
                预约失败
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="payAmount" label="支付金额" />
          <el-table-column align="center" label="操作">
            <template #default="scope">
              <el-button v-if="scope.row.byState == 1" link type="primary" @click="refund(scope.row)"
                ><div class="look">退款</div></el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination">
        <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
          class="nowday"
          style="
            position: relative;
            width: 1200px;
            color: #000;
            top: -53px;
            font-size: 18px;
            z-index: 0;
          "
        >
          <div>
            <div style="display: inline-block; margin-left: 30px">
              <span
                style="font-size: 18px; font-weight: 800; margin-right: 20px"
                >汇总金额 :</span
              >
              <span style="color: red">{{ tableData.account }}</span> 元
            </div>
          </div>
        </div>
      </div>
    </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: "",
  route: "",
  date: "",
  car_number: "",
});
const gobacknum = reactive({ list1: {}, list2: {}, list3: {}, list4: {} }); // 当日黄家湖-墨轩湖人数

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

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

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

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.route) {
      data.set("route", searchInputHZ.route);
    }
    if (searchInputHZ.date) {
      data.set("startTime", searchInputHZ.date[0]);
      data.set("endTime", searchInputHZ.date[1]);
    }
    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);
    }
    // if (searchInput.yy_date) {
    //   data.set("yy_date", searchInput.yy_date);
    // }
    if (searchInput.ciCreateTime) {
      data.set("ciStartTime", searchInput.ciCreateTime[0]);
      data.set("ciEndTime", searchInput.ciCreateTime[1]);
    }
    data.set("state", searchInput.state);
    if (searchInput.ci_time) {
      data.set("ci_time", searchInput.ci_time);
    }
    if (searchInput.createTime) {
      data.set("startTime", searchInput.createTime[0]);
      data.set("endTime", searchInput.createTime[1]);
    }
    if (searchInput.route) {
      data.set("route", searchInput.route);
    }
    data.set("mobile", searchInput.mobile);
    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;
      tableData.account = res.data.account;
      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("startTime", searchInputHZ.date[0]);
  data.set("endTime", searchInputHZ.date[1]);
  // 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 == "靖安-南昌") {
      gobacknum.list1 = res.data.data[0]; // 教职工
    } else if (item.route == "南昌-靖安") {
      gobacknum.list2 = res.data.data[1]; // 教职工
    }
  });
};
// 汇总搜索按钮
const searchHZ = lodash.debounce(() => {
  getList("查询成功");
  goBackNum();
}, 300);
// 汇总重置搜索框
const resetInputHZ = lodash.debounce(() => {
  searchInputHZ.state = "";
  searchInputHZ.route = "";

  searchInputHZ.date = [
    dayjs().format("YYYY-MM-DD"),
    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.ciCreateTime = "";
  searchInput.car_number = "";
  searchInput.ci_time = "";
  searchInput.route = "";
  searchInput.createTime = "";
  searchInput.mobile = "";
  getList();
}, 300);
// 多选框功能
const handleSelectionChange = (val) => {
  console.log(val);
  selectData.list = val;
};

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

  // searchInputHZ.date = [
  //   dayjs().format("YYYY-MM-DD"),
  //   dayjs().format("YYYY-MM-DD"),
  // ];
  searchInputHZ.car_number = "";
  getList();
};

// 详情按钮
const info = (row) => {
  console.log(row);
  // searchInput.yy_date = row.s_date;
  searchInput.ciCreateTime = [row.s_date, row.s_date];
  searchInput.ci_time = row.ci_time;
  searchInput.car_number = row.car_number;
  footerMenuIndex.value = 1;
  currentPage2.value = 1;
  getList();
};
const refund = (row) => {
  ElMessageBox.confirm("确定退款?", "提示!!!", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
    
  })
    .then(async () => {
      let data = new FormData();
      data.set("order_num", row.orderNo);
      data.set("id", row.id);
      // let data = {
      //   order_num: row.orderNo, // 当前页
      // };
      let res = await axios({
        method: "post",
        url: api.value + "/tApprefund.action",
        headers: {
          token: sessionStorage.getItem("token"),
        },
        data: data,
      });
      console.log(res);
      if (res.data.code == 200) {
        ElMessage({
          type: "success",
          showClose: true,
          message: res.data.message,
          center: true,
        });
        getList();
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.data.message,
          center: true,
        });
      }
    })
    .catch(() => {});
};
// 派车按钮
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);
  }
  if (searchInput.yy_date) {
    data.set("yy_date", searchInput.yy_date);
  }
  if (searchInput.createTime) {
    data.set("startTime", searchInput.createTime[0]);
    data.set("endTime", searchInput.createTime[1]);
  }
  if (searchInput.route) {
    data.set("route", searchInput.route);
  }
  data.set("mobile", searchInput.mobile);
  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.data.code == 200) {
    // const elt = document.createElement("a");
    // elt.setAttribute(
    //   "href",
    //   "https://car.meiyishuoo.com/ride-sharing" + res.data.downurl
    // );
    // elt.setAttribute("download", "file.png");
    // elt.style.display = "none";
    // document.body.appendChild(elt);
    // elt.click();
    var downloadPath =
      "https://car.meiyishuoo.com/ride-sharing" + 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(() => {
  searchInputHZ.date = [
    dayjs().format("YYYY-MM-DD"),
    dayjs().format("YYYY-MM-DD"),
  ];
  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: calc(100% - 40px);
  height: calc(100% - 105px);
  margin: 20px auto;
  background-color: #fff;
  color: #fff;
  display: flex;
  flex-direction: column;

  .left {
    width: calc(100% - 60px);
    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: calc(100% - 60px);
    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: calc(100% - 60px);
    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;
    }
  }
  .MingXi {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: auto;
    .mingxi {
      flex: 1;
      overflow: auto;
      :deep(.el-table__header-wrapper) {
        height: 50px;

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

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

        :deep(.el-table__row) {
          height: 50px;
        }
      }
    }
    .pagination {
      width: 100%;
      height: 70px;
      .el-pagination {
        position: relative;
        z-index: 999;
      }
    }
  }

  .footer {
    width: calc(100% - 60px);
    // height: 510px;
    margin: 20px auto 0;

    :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: calc(100% - 60px);
    height: 60px;
    margin: 0 30px;
    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>
