<template>
  <div class="content-box">
    <div class="left">
      <!-- <el-icon :size="23" class="camera"><UserFilled /></el-icon> -->
      <span class="cameratxt">车辆调度</span>
    </div>
    <div class="filter">
      <div class="condition">
        <el-button
          style="margin: 0 0 0 30px"
          color="rgba(61, 81, 232, 1)"
          type="primary"
          class="search"
          @click="addQuery"
          ><el-icon><CirclePlus /></el-icon
          ><span> &nbsp;&nbsp;新增调度</span></el-button
        >
      </div>
      <div class="condition">
        <span>发车日期 : </span>
        <el-date-picker
          v-model="searchInput.startTime"
          type="date"
          placeholder="请选择发车日期"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          :clearable="false"
        />
        <!-- <el-select
          v-model="searchInput.startTime"
          class="m-2"
          placeholder="请选择发车日期"
        >
          <el-option
            :label="dayjs().format('YYYY-MM-DD')"
            :value="dayjs().format('YYYY-MM-DD')"
          />
          <el-option
            :label="
              dayjs(dayjs().format('YYYY-MM-DD'))
                .add(1, 'day')
                .format('YYYY-MM-DD')
            "
            :value="
              dayjs(dayjs().format('YYYY-MM-DD'))
                .add(1, 'day')
                .format('YYYY-MM-DD')
            "
          />
        </el-select> -->
      </div>

      <div class="condition">
        <span>车牌号 : </span>
        <el-select
          v-model="searchInput.car_number"
          class="m-2"
          placeholder="请选择车牌号"
          :clearable="true"
          @clear="search"
        >
          <el-option
            v-for="item in busNum.list"
            :key="item.id"
            :label="item.car_number"
            :value="item.car_number"
          />
        </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
      >
    </div>
    <div class="footer">
      <el-table
        :row-class-name="tableRowClassName"
        :data="tableData.list"
        style="width: 100%"
        :header-cell-style="{
          background: 'rgba(240, 243, 247, 1)',
          border: 0,
        }"
      >
        <el-table-column
          align="center"
          width="150"
          prop="s_date"
          label="发车日期"
        />
        <el-table-column
          align="center"
          width="100"
          prop="ci_time"
          label="发车时间"
        />
        <el-table-column align="center" width="100" label="预约人数">
          <template #default="props">
            <span
              v-if="props.row.yy_num == props.row.contain"
              style="color: red"
              >{{ props.row.yy_num }}</span
            >
            <span v-else>{{ props.row.yy_num }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          width="80"
          prop="by_num"
          label="乘车人数"
        />
        <el-table-column
          align="center"
          width="80"
          prop="contain"
          label="容量"
        />
        <el-table-column
          align="center"
          width="120"
          prop="car_number"
          label="车牌号"
        />

        <el-table-column align="center" prop="route" width="200" label="路线" />
        <el-table-column align="center" prop="route_end" label="终点" />

        <el-table-column align="center" label="状态" width="120">
          <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"
          prop="before_state"
          width="120"
          label="是否可提前预约"
        >
          <template #default="scope">
            <!-- <div>{{ scope.row.before_state == 1 ? "是" : "否" }}</div> -->
            <el-switch
              v-model="scope.row.before_state"
              size="large"
              active-value="1"
              inactive-value="0"
              @change="(val) => stateChange(scope.row, val)"
              style="
                --el-switch-on-color: rgba(61, 81, 232, 1);
                /* --el-switch-off-color: rgba(61, 81, 232, 1); */
              "
            />
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="220">
          <template #default="scope">
            <!-- <el-button
                link
                type="primary"
                @click="sendBus(scope.row)"
                v-if="scope.row.ci_time == 0"
                ><div class="look">候补</div></el-button
              > -->
            <el-button
              v-if="scope.row.state == 2"
              color="#909399"
              @click="sendBus(scope.row)"
              plain
              ><div class="look">调度</div></el-button
            >
            <el-button v-else color="#409EFF" plain @click="sendBus(scope.row)"
              ><div class="look">调度</div></el-button
            >
            <el-button
              v-if="scope.row.state == 2"
              color="#909399"
              plain
              @click="mergeBus(scope.row)"
              ><div class="lookcar">合车</div></el-button
            >
            <el-button v-else color="#E6A23C" plain @click="mergeBus(scope.row)"
              ><div class="lookcar">合车</div></el-button
            >
            <el-button type="danger" plain @click="del(scope.row)"
              ><div class="lookdel">删除</div></el-button
            >
            <!-- v-if="scope.row.state != 2" -->
            <!-- <el-button link type="primary" v-else :disabled="true"
                ><div class="look">删除</div></el-button
              > -->
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页数据 -->
    <el-pagination
      background
      :current-page="currentPage"
      :page-size="pageSize"
      layout="total, prev, pager, next, jumper, slot"
      :total="total"
      @update:current-page="handleCurrentChange"
    />
    <!-- 新增车辆调度 -->
    <el-dialog
      class="sendBus"
      v-model="addBusqueryVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="新增调度"
      align-center
      width="550"
      :before-close="editCloseQuery"
    >
      <el-form
        ref="ruleFormRefQuery"
        :model="ruleFormQuery"
        :rules="rulesQuery"
        label-width="150px"
        class="demo-ruleForm"
        :size="formSize"
        label-position="left"
        status-icon
      >
        <el-form-item label="发车日期 :" prop="startDate">
          <el-date-picker
            v-model="ruleFormQuery.startDate"
            type="date"
            placeholder="请选择发车日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
          />

          <!-- <el-select
            v-model="ruleFormQuery.startDate"
            class="m-2"
            placeholder="请选择发车日期"
            @change="startbusTime"
          >
            <el-option
              :label="dayjs().format('YYYY-MM-DD')"
              :value="dayjs().format('YYYY-MM-DD')"
            />
            <el-option
              :label="
                dayjs(dayjs().format('YYYY-MM-DD'))
                  .add(1, 'day')
                  .format('YYYY-MM-DD')
              "
              :value="
                dayjs(dayjs().format('YYYY-MM-DD'))
                  .add(1, 'day')
                  .format('YYYY-MM-DD')
              "
            />
          </el-select> -->
        </el-form-item>
        <el-form-item label="发车时间 :" prop="ci_time">
          <el-time-picker
            v-model="ruleFormQuery.ci_time"
            placeholder="请选择发车时间"
            format="HH:mm"
            value-format="HH:mm"
            :disabled-hours="disabledQueryHours"
            :disabled-minutes="disabledQueryMinutes"
            @change="addQueryTime"
          />
        </el-form-item>
        <el-form-item label="预约截止时间 :" prop="yy_end">
          <el-time-picker
            v-model="ruleFormQuery.yy_end"
            placeholder="请选择预约截止时间"
            format="HH:mm"
            value-format="HH:mm"
          />
        </el-form-item>
        <!-- <el-form-item label="扫码时间 :" prop="codeTime">
          <el-time-picker
            v-model="ruleFormQuery.codeTime"
            format="HH:mm"
            value-format="HH:mm"
            is-range
            range-separator="-"
            start-placeholder="开始时间"
            end-placeholder="截止时间"
          />
        </el-form-item> -->
        <el-form-item label="车牌号 :" prop="busname">
          <el-select
            v-model="ruleFormQuery.busname"
            class="m-2"
            placeholder="请选择车牌号"
          >
            <el-option
              :label="item.car_number"
              :value="item.car_number"
              v-for="item in busNum.list"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="容量 :" prop="volume">
          <el-input
            v-model="ruleFormQuery.volume"
            placeholder="请输入容量"
            clearable
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="路线 :" prop="route">
          <el-select
            v-model="ruleFormQuery.route"
            class="m-2"
            placeholder="请选择路线"
            @change="changeRouteQuery"
          >
            <el-option
              :label="item.route"
              :value="item.route"
              v-for="item in pathNum.list"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="终点站 :" prop="destination">
          <el-select
            v-model="ruleFormQuery.destination"
            class="m-2"
            placeholder="请选择终点站"
          >
            <el-option
              :label="item.route_end"
              :value="item.route_end"
              v-for="item in addendNum.list"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          label="是否可提前一周预约"
          prop="yesterday"
          class="yesterday"
          style="
            padding-bottom: 20px;
            border-bottom: 1px solid rgba(230, 230, 230, 1);
          "
        >
          <el-switch
            v-model="ruleFormQuery.yesterday"
            size="large"
            style="
              --el-switch-on-color: rgba(61, 81, 232, 1);
              /* --el-switch-off-color: rgba(61, 81, 232, 1); */
            "
          />
        </el-form-item>
        <el-form-item class="options">
          <el-button class="congzhi" @click="editCloseQuery(ruleFormRefQuery)"
            >取消</el-button
          >
          <el-button
            color="rgba(61, 81, 232, 1)"
            class="queding"
            type="primary"
            @click="submitAddQuery(ruleFormRefQuery)"
          >
            确定
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 候补派车 -->
    <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="120px"
        class="demo-ruleForm"
        :size="formSize"
        label-position="left"
        status-icon
      >
        <el-form-item label="发车日期 :" prop="startDate">
          <el-date-picker
            v-model="ruleForm.startDate"
            type="date"
            placeholder="请选择发车日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="发车时间 :" prop="ci_time">
          <el-time-picker
            v-model="ruleForm.ci_time"
            placeholder="请选择时间"
            :disabled="ruleForm.state == 2 ? true : false"
            format="HH:mm"
            value-format="HH:mm"
            :disabled-hours="disabledHours"
            :disabled-minutes="disabledMinutes"
            :disabled-seconds="disabledSeconds"
            @change="updataSmTime"
          />
        </el-form-item>
        <el-form-item label="扫码时间 :" prop="codeTime">
          <el-time-picker
            v-model="ruleForm.codeTime"
            format="HH:mm"
            value-format="HH:mm"
            is-range
            range-separator="-"
            start-placeholder="开始时间"
            end-placeholder="截止时间"
          />
        </el-form-item>
        <el-form-item label="预约截止时间 :" prop="yy_end">
          <el-time-picker
            v-model="ruleForm.yy_end"
            placeholder="请选择预约截止时间"
            format="HH:mm"
            value-format="HH:mm"
          />
        </el-form-item>
        <!-- <el-form-item
          label="发车时间 :"
          v-if="ruleForm.state != 3"
          prop="ci_time"
        >
          <el-time-picker
            v-model="ruleForm.ci_time"
            placeholder="请选择发车时间"
            format="HH:mm"
            value-format="HH:mm"
          />
        </el-form-item> -->
        <el-form-item label="车牌 :" prop="busname">
          <!-- <el-select-v2
            validate-event
            v-model="ruleForm.busname"
            :options="options"
            placeholder="请选择车牌号"
            style="width: 260px"
            multiple
          /> -->
          <el-select
            v-model="ruleForm.busname"
            multiple
            placeholder="请选择车牌号"
            style="width: 240px"
          >
            <el-option
              v-for="item in busNum.list"
              :key="item.id"
              :label="item.car_number"
              :value="item.car_number"
            />
          </el-select>
        </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-select
            v-model="ruleForm.route"
            class="m-2"
            placeholder="请选择路线"
            @change="changeRoute"
          >
            <el-option
              :label="item.route"
              :value="item.route"
              v-for="item in pathNum.list"
            />
          </el-select>
        </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.route_end"
              :value="item.route_end"
              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>

    <!--合车 -->
    <el-dialog
      class="mergeBus"
      v-model="mergeBusDialog"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="车辆合车"
      align-center
      width="1300"
      :before-close="mergeBusClose"
    >
      <div v-loading="mergeBusloading">
        <!-- 上半部分表格 -->
        <el-table
          :row-class-name="tableRowClassName"
          :data="mergeTable.list1"
          :header-cell-style="{
            background: 'rgba(240, 243, 247, 1)',
            border: 0,
          }"
          style="margin-bottom: 30px"
        >
          <el-table-column
            align="center"
            width="150"
            prop="s_date"
            label="发车日期"
          />
          <el-table-column
            align="center"
            width="120"
            prop="ci_time"
            label="发车时间"
          />
          <el-table-column align="center" width="100" label="预约人数">
            <template #default="props">
              <span
                v-if="props.row.yy_num == props.row.contain"
                style="color: red"
                >{{ props.row.yy_num }}</span
              >
              <span v-else>{{ props.row.yy_num }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column align="center" width="100" label="剩余人数">
          <template #default="props">
            <span style="color: red">{{ selectData.sy_num }}</span>
          </template>
        </el-table-column> -->
          <el-table-column
            align="center"
            width="100"
            prop="by_num"
            label="乘车人数"
          />
          <el-table-column
            align="center"
            width="100"
            prop="contain"
            label="容量"
          />
          <el-table-column
            align="center"
            width="120"
            prop="car_number"
            label="车牌号"
          />

          <el-table-column align="center" prop="route" label="路线" />
          <el-table-column align="center" prop="route_end" label="终点" />
        </el-table>
        <!-- 下半部分表格 -->
        <el-table
          :row-class-name="tableRowClassName"
          :header-cell-class-name="selectionClass"
          :data="mergeTable.list2"
          style="width: 100%; height: 580px"
          :header-cell-style="{
            background: 'rgba(240, 243, 247, 1)',
            border: 0,
          }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            align="center"
            width="150"
            prop="s_date"
            label="发车日期"
          />
          <el-table-column
            align="center"
            width="120"
            prop="ci_time"
            label="发车时间"
          />
          <!-- <el-table-column align="center" width="100" label="预约人数">
          <template #default="props">
            <span
              v-if="props.row.yy_num == props.row.contain"
              style="color: red"
              >{{ props.row.yy_num }}</span
            >
            <span v-else>{{ props.row.yy_num }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          width="100"
          prop="by_num"
          label="乘车人数"
        />
        <el-table-column
          align="center"
          width="100"
          prop="contain"
          label="容量"
        /> -->
          <el-table-column align="center" width="100" label="剩余容量">
            <template #default="props">
              <span>{{ props.row.sy_num }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column align="center" width="100" label="合车人数">
          <template #default="props">
            <span style="color: red" v-if="props.row.hc_num"
              >+{{ props.row.hc_num }}</span
            >
          </template>
        </el-table-column> -->
          <el-table-column
            align="center"
            width="120"
            prop="car_number"
            label="车牌号"
          />

          <el-table-column align="center" prop="route" label="路线" />
          <el-table-column align="center" prop="route_end" label="终点" />
          <el-table-column label="操作" width="80" align="center">
            <template #default="props">
              <el-checkbox
                v-model="props.row.checkbox"
                size="large"
                @change="selectable(props.row)"
                :disabled="props.row.selectClose"
              /> </template
          ></el-table-column>
        </el-table>
        <div class="btn">
          <div>
            <el-button
              style="margin-left: 20px"
              color="rgba(61, 81, 232, 1)"
              type="primary"
              class="search"
              @click="mergesubmit"
              ><span>确定</span></el-button
            >
            <el-button
              style="margin-left: 20px"
              class="search"
              @click="mergeBusClose"
              ><span>取消</span></el-button
            >
          </div>
          <!-- <div class="txt" v-if="selectData.allNum > mergeTable.list1[0].yy_num">
          已选
          <span style="color: red">{{ selectData.list.length }}</span>
          辆，需要分配的人数
          <span style="color: red">{{ mergeTable.list1[0].yy_num }}</span>
          小于剩余容量
          <sapn style="color: red">{{ selectData.allNum }}</sapn>
          可保存
        </div> 
        <div
          class="txt"
          v-else-if="selectData.allNum == mergeTable.list1[0].yy_num"
        >
          已选
          <span style="color: red">{{ selectData.list.length }}</span>
          辆，需要分配的人数
          <span style="color: red">{{ mergeTable.list1[0].yy_num }}</span>
          等于剩余容量
          <sapn style="color: red">{{ selectData.allNum }}</sapn>
          可保存
        </div>
        <div
          class="txt"
          v-else-if="selectData.allNum < mergeTable.list1[0].yy_num"
        >
          已选
          <span style="color: red">{{ selectData.list.length }}</span>
          辆，需要分配的人数
          <span style="color: red">{{ mergeTable.list1[0].yy_num }}</span>
          大于剩余容量
          <sapn style="color: red">{{ selectData.allNum }}</sapn>
          不可保存，请选多辆
        </div> -->
          <!-- <div class="txt" v-if="selectData.allNum > mergeTable.list1[0].yy_num">
          已选
          <span style="color: red">{{ selectData.list.length }}</span>
          辆，所选车剩余容量总和
          <sapn style="color: red">{{ selectData.allNum }}</sapn>
          大于需要分配的预约人数
          <span style="color: red">{{ mergeTable.list1[0].yy_num }}</span>
          可保存
        </div>
        <div class="txt" v-if="selectData.allNum == mergeTable.list1[0].yy_num">
          已选
          <span style="color: red">{{ selectData.list.length }}</span>
          辆，所选车剩余容量总和
          <sapn style="color: red">{{ selectData.allNum }}</sapn>
          等于需要分配的预约人数
          <span style="color: red">{{ mergeTable.list1[0].yy_num }}</span>
          可保存
        </div>
        <div class="txt" v-if="selectData.allNum < mergeTable.list1[0].yy_num">
          已选
          <span style="color: red">{{ selectData.list.length }}</span>
          辆，所选车剩余容量总和
          <sapn style="color: red">{{ selectData.allNum }}</sapn>
          小于需要分配的预约人数
          <span style="color: red">{{ mergeTable.list1[0].yy_num }}</span>
          不可保存
        </div> -->
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, watch, onBeforeMount, onMounted } 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 api = ref("");
// 搜索框数据
const searchInput = reactive({
  startTime: dayjs().format("YYYY-MM-DD"),
  car_number: "",
});

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

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

const addBusqueryVisible = ref(false); // 新增车辆调度弹窗
const mergeBusDialog = ref(false); // 车辆合车弹窗
const mergeBusloading = ref(false); // 合车等待加载控制

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(10);
const currentPage = ref(1); // 当前页
const total = ref(10); // 当前总数
const selectData = reactive({ list: [], allNum: 0, sy_num: 0 }); // 多选框选择的数据

// 表单数据
const formSize = ref("default");
const ruleFormRef = ref(); // 调度表单
const ruleFormRefQuery = ref(); // 新增调度表单
// 派车调度数据
const ruleForm = reactive({
  startDate: "", // 发车日期
  busname: [], // 调度 车牌号
  volume: "", // 车子容量
  route: "黄家湖校区-墨轩湖校区", // 线路选择
  destination: "", // 终点站
  ci_time: "", // 发车时间
  state: "", // 状态
  codeTime: [], // 扫码时间
  repair_end: "", // 候补时间
  yy_end: "", // 预约截止时间
  id: "",
});
// 新增车辆调度数据
const ruleFormQuery = reactive({
  startDate: "", // 发车日期
  busname: "", //候补弹窗车牌绑定数据
  ci_time: "", // 发车时间
  volume: "", // 车子容量
  route: "", // 线路选择
  destination: "", // 终点站
  yesterday: true, // 是否提前预约
  yy_end: "", // 预约截止时间
});
// 调度表单验证
const rules = reactive({
  startDate: [
    {
      required: true,
      message: "发车日期不能为空",
      trigger: "blur",
    },
  ],
  ci_time: [
    {
      required: true,
      message: "发车时间不能为空",
      trigger: "blur",
    },
  ],
  codeTime: [
    {
      required: true,
      message: "扫码时间不能为空",
      trigger: "blur",
    },
  ],
  yy_end: [
    {
      required: true,
      message: "预约截止时间不能为空",
      trigger: "blur",
    },
  ],
  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: "blur",
    },
  ],
});
// 新增调度表单验证
const rulesQuery = reactive({
  startDate: [
    {
      required: true,
      message: "发车日期不能为空",
      trigger: "blur",
    },
  ],
  ci_time: [
    {
      required: true,
      message: "发车时间不能为空",
      trigger: "blur",
    },
  ],
  yy_end: [
    {
      required: true,
      message: "预约截止时间不能为空",
      trigger: "blur",
    },
  ],
  busname: [
    {
      required: true,
      message: "车牌号不能为空",
      trigger: "blur",
    },
  ],
  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: "blur",
    },
  ],
});

// 监控派车弹窗选择车牌时容量发生变化
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;
  }
);
// 监控车牌号
watch(
  () => ruleFormQuery.busname,
  (newValue, oldValue) => {
    console.log(newValue);
    if (!newValue == "") {
      let arr = busNum.list.filter((item) => {
        return item.car_number == newValue;
      });
      // console.log(arr);
      if (arr == []) {
      } else {
        ruleFormQuery.volume = arr[0].contain;
      }
    }
  }
);

// 关闭合车里面table表格的全选按钮
// const selectionClass = (row) => {
//   if (row.columnIndex === 7) {
//     return "disabledsele";
//   }
// };

// 监控新增车辆调度路线
// watch(
//   () => ruleFormQuery.route,
//   (newValue, oldValue) => {
//     console.log(newValue);
//     let arr = JSON.parse(sessionStorage.getItem("route_endSelect"));
//     ruleFormQuery.destination = "";
//     // console.log(arr);

//     addendNum.list = arr.filter((item) => {
//       return item.route == newValue;
//     });
//   }
// );

// 根据路线自动分配好站点（新增调度）
const changeRouteQuery = (val) => {
  let arr = JSON.parse(sessionStorage.getItem("route_endSelect"));
  ruleFormQuery.destination = "";
  // console.log(arr);

  addendNum.list = arr.filter((item) => {
    return item.route == val;
  });
};

// 监控调度路线;
// watch(
//   () => ruleForm.route,
//   (newValue, oldValue) => {
//     console.log(oldValue);
//     let arr = JSON.parse(sessionStorage.getItem("route_endSelect"));
//     console.log(arr);
//     endNum.list = arr.filter((item) => {
//       return item.route == newValue;
//     });
//   }
// );

// 根据路线自动分配好站点（派车调度）
const changeRoute = (val) => {
  let arr = JSON.parse(sessionStorage.getItem("route_endSelect"));
  // console.log(arr);
  ruleForm.destination = "";
  endNum.list = arr.filter((item) => {
    return item.route == val;
  });
};

// 派车调度选择发车时间自动修改扫码时间
const updataSmTime = () => {
  console.log("扫码时间", ruleForm.codeTime);
  let sm_start = sessionStorage.getItem("sm_start");
  let sm_end = sessionStorage.getItem("sm_end");
  let dateTime = ruleForm.startDate + " " + ruleForm.ci_time;
  let start = dayjs(dateTime)
    .subtract(sm_start, "minute")
    .format("YYYY-MM-DD HH:mm");
  let end = dayjs(dateTime).add(sm_end, "minute").format("YYYY-MM-DD HH:mm");
  if (end > ruleForm.startDate + " " + "23:59") {
    end = "23:59";
  } else {
    end = dayjs(end).format("HH:mm");
  }
  if (start < ruleForm.startDate + " " + "00:00") {
    start = "00:00";
  } else {
    start = dayjs(start).format("HH:mm");
  }
  ruleForm.codeTime[0] = start;
  ruleForm.codeTime[1] = end;

  // 联动预约截止时间
  let yy_end = sessionStorage.getItem("yy_end");
  let ci_time = dayjs().format("YYYY-MM-DD") + " " + ruleForm.ci_time;
  let YYend = dayjs(ci_time)
    .subtract(yy_end, "minute")
    .format("YYYY-MM-DD HH:mm");
  if (YYend < dayjs().format("YYYY-MM-DD") + " " + "00:00") {
    YYend = "00:00";
  } else {
    YYend = dayjs(YYend).format("HH:mm");
  }
  ruleForm.yy_end = YYend;
};

// 获取数据列表
const getList = async (message) => {
  {
    let data = new FormData();
    let time = dayjs().format("YYYY-MM-DD");
    data.set("car_number", searchInput.car_number);
    if (searchInput.startTime) {
      data.set("date", searchInput.startTime);
    }
    data.set("page", currentPage.value);
    data.set("rows", pageSize.value);
    let res = await axios({
      method: "post",
      url: api.value + "/carBook/schequeryYlist.action",
      headers: {
        token: sessionStorage.getItem("token"),
      },
      data: data,
    });
    console.log(res, "调度数据");
    if (res.status == 200) {
      tableData.list = res.data.rows;
      // currentPage.value = res.data.currentPage;
      if (message) {
        ElMessage({
          type: "success",
          showClose: true,
          message: message,
          center: true,
        });
      }
      total.value = res.data.total;
    } else {
      tableData.list = 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`,
        });
      }
    }
  }
};

// 搜索按钮
const search = lodash.debounce(() => {
  getList("查询成功");
}, 300);
// 重置搜索框
const resetSearch = lodash.debounce(() => {
  searchInput.startTime = "";
  searchInput.car_number = "";
  getList();
}, 300);

// 合车下半部分表格复选框禁用;
// const selectable = (row) => {};

// 新增车辆调度
const addQuery = () => {
  addBusqueryVisible.value = true;
};
const makeRange = (start, end) => {
  const result = [];
  for (let i = start; i <= end; i++) {
    result.push(i);
  }
  return result;
};
const startbusTime = (val) => {
  let dateTime = dayjs().format("YYYY-MM-DD");
  let hour = dayjs().format("YYYY-MM-DD HH:mm");
  if (ruleFormQuery.ci_time && dateTime == val) {
    console.log("发车时间已存在");

    if (dateTime + " " + ruleFormQuery.ci_time <= hour) {
      ruleFormQuery.ci_time = "";
      ruleFormQuery.yy_end = "";
      ElMessage({
        type: "warning",
        showClose: true,
        message: "发车时间必须大于当前时间,请重新选择",
        center: true,
      });
    }
  }
};
// // 控制新增调度发车时间    小时
// const disabledQueryHours = () => {
//   let dateTime = dayjs().format("YYYY-MM-DD");
//   if (ruleFormQuery.startDate == dateTime) {
//     // console.log("当天时间");
//     let hour = dayjs().hour();
//     return makeRange(0, hour - 1);
//   }
// };
// // 控制新增调度发车时间    分钟
// const disabledQueryMinutes = (hour) => {
//   let hours = dayjs().hour();
//   let dateTime = dayjs().format("YYYY-MM-DD");
//   let minute = dayjs().minute();
//   if (ruleFormQuery.startDate == dateTime) {
//     if (hour == hours) {
//       return makeRange(0, minute);
//     }
//   }
// };
//  控制新增调度发车时间 (修改后预约截止时间联动)
const addQueryTime = (val) => {
  let dateTime = dayjs().format("YYYY-MM-DD");
  let hour = dayjs().format("YYYY-MM-DD HH:mm");
  if (
    ruleFormQuery.startDate == dateTime &&
    dateTime + " " + ruleFormQuery.ci_time <= hour
  ) {
    ruleFormQuery.ci_time = "";
    ruleFormQuery.yy_end = "";
    ElMessage({
      type: "warning",
      showClose: true,
      message: "发车时间必须大于当前时间,请重新选择",
      center: true,
    });
  } else {
    let yy_end = sessionStorage.getItem("yy_end");
    let ci_time = dayjs().format("YYYY-MM-DD") + " " + ruleFormQuery.ci_time;
    let end = dayjs(ci_time)
      .subtract(yy_end, "minute")
      .format("YYYY-MM-DD HH:mm");
    if (end < dayjs().format("YYYY-MM-DD") + " " + "00:00") {
      end = "00:00";
    } else {
      end = dayjs(end).format("HH:mm");
    }
    ruleFormQuery.yy_end = end;
    console.log(ci_time, yy_end, end);
  }
};
// // 控制调度发车时间    小时
// const disabledHours = () => {
//   if (ruleForm.state == 2) {
//   } else {
//     let dateTime = dayjs().format("YYYY-MM-DD");
//     if (ruleForm.startDate == dateTime) {
//       // console.log("当天时间");
//       let hour = dayjs().hour();
//       return makeRange(0, hour - 1);
//     }
//   }
// };
// // 控制调度发车时间    分钟
// const disabledMinutes = (hour) => {
//   if (ruleForm.state == 2) {
//   } else {
//     let hours = dayjs().hour();
//     let dateTime = dayjs().format("YYYY-MM-DD");
//     let minute = dayjs().minute();
//     if (ruleForm.startDate == dateTime) {
//       if (hour == hours) {
//         return makeRange(0, minute);
//       }
//     }
//   }
// };

// 派车按钮
const sendBus = (row) => {
  console.log(row);

  let arr = JSON.parse(sessionStorage.getItem("route_endSelect"));
  endNum.list = arr.filter((item) => {
    return item.route == row.route;
  });
  centerDialogVisible.value = true;
  ruleForm.startDate = row.s_date;
  ruleForm.id = row.id;
  ruleForm.state = row.state;
  if (row.car_number == 0) {
    ruleForm.busname = [];
  } else {
    ruleForm.busname = [row.car_number];
  }
  ruleForm.route = row.route;
  ruleForm.yy_end = row.yy_end;
  ruleForm.destination = row.route_end;
  ruleForm.codeTime = [row.sm_start, row.sm_end];
  if (row.ci_time == 0) {
    // dialongTitle.value = "车辆候补调度";
    ruleForm.ci_time = "";
  } else {
    // dialongTitle.value = "车辆调度";
    ruleForm.ci_time = row.ci_time;
  }
};
// 派车弹窗关闭
const editClose = () => {
  centerDialogVisible.value = false;
  ruleFormRef.value.resetFields();
};

// 合车按钮
const mergeBus = async (row) => {
  mergeBusDialog.value = true;
  selectData.list = [];
  // 上半部分表格数据
  mergeTable.list1 = [{ ...row }];
  selectData.sy_num = row.yy_num;
  let data = new FormData();
  // data.set("car_number", searchInput.car_number);
  data.set("date", row.s_date);
  data.set("page", 1);
  data.set("rows", 100);
  let res = await axios({
    method: "post",
    url: api.value + "/carBook/schequeryYlist.action",
    headers: {
      token: sessionStorage.getItem("token"),
    },
    data: data,
  });
  console.log(res, "调度数据");
  res.data.rows.forEach((item) => {
    item.sy_num = item.contain - item.yy_num;
    item.checkbox = false;
    item.selectClose = false;
  });
  // 将需要合车的那辆车排除
  let arr = res.data.rows.filter((item) => {
    return item.id != row.id;
  });
  // 将排除后的所有车辆路线相同的选出来作为下半部分数据
  arr = arr.filter((item) => {
    return item.route == row.route;
  });
  mergeTable.list2 = arr;
};

// 合车下半部分表格多选框功能
const selectable = (row) => {
  if (row.checkbox == true) {
    selectData.list.push(row);
  } else {
    selectData.list = selectData.list.filter((item) => {
      return item.id != row.id;
    });
  }
  let bid = [];
  selectData.list.forEach((item) => {
    bid.push(item.id);
  });
  console.log(selectData.list, bid);
};

// 确定合车按钮
const mergesubmit = async () => {
  // ElMessageBox.confirm("是否允许给用户发送通知信息？", "提示", {
  //   confirmButtonText: "确认",
  //   cancelButtonText: "取消",
  //   type: "warning",
  // })
  //   .then(async () => {
  //     mergeBusloading.value = true;
  //     let bid = [];
  //     selectData.list.forEach((item) => {
  //       bid.push(item.id);
  //     });
  //     let data = {
  //       id: mergeTable.list1[0].id,
  //       bid: bid.join(","),
  //       send_state: 1,
  //     };
  //     let res = await axios({
  //       method: "post",
  //       url: api.value + "/carBook/schemerge.action",
  //       headers: {
  //         token: sessionStorage.getItem("token"),
  //         admin_name: sessionStorage.getItem("username"),
  //       },
  //       data: data,
  //     });
  //     if (res.data.code == 200) {
  //       getList();
  //       mergeBusDialog.value = false;
  //       mergeBusloading.value = false;
  //       ElMessage({
  //         type: "success",
  //         showClose: true,
  //         message: res.data.message,
  //         center: true,
  //       });
  //     } else {
  //       mergeBusloading.value = false;
  //       ElMessage({
  //         type: "error",
  //         showClose: true,
  //         message: res.data.message,
  //         center: true,
  //       });
  //     }
  //   })
  //   .catch(async () => {
  //     mergeBusloading.value = true;
  //     let bid = [];
  //     selectData.list.forEach((item) => {
  //       bid.push(item.id);
  //     });
  //     let data = {
  //       id: mergeTable.list1[0].id,
  //       bid: bid.join(","),
  //       send_state: 0,
  //     };
  //     let res = await axios({
  //       method: "post",
  //       url: api.value + "/carBook/schemerge.action",
  //       headers: {
  //         token: sessionStorage.getItem("token"),
  //         admin_name: sessionStorage.getItem("username"),
  //       },
  //       data: data,
  //     });
  //     if (res.data.code == 200) {
  //       getList();
  //       mergeBusDialog.value = false;
  //       mergeBusloading.value = false;
  //       ElMessage({
  //         type: "success",
  //         showClose: true,
  //         message: res.data.message,
  //         center: true,
  //       });
  //     } else {
  //       mergeBusloading.value = false;
  //       ElMessage({
  //         type: "error",
  //         showClose: true,
  //         message: res.data.message,
  //         center: true,
  //       });
  //     }
  //   });
  mergeBusloading.value = true;
  let bid = [];
  selectData.list.forEach((item) => {
    bid.push(item.id);
  });
  let data = {
    id: mergeTable.list1[0].id,
    bid: bid.join(","),
    // send_state: 0,
  };
  let res = await axios({
    method: "post",
    url: api.value + "/carBook/schemerge.action",
    headers: {
      token: sessionStorage.getItem("token"),
      admin_name: sessionStorage.getItem("username"),
    },
    data: data,
  });
  if (res.data.code == 200) {
    getList();
    mergeBusDialog.value = false;
    mergeBusloading.value = false;
    ElMessage({
      type: "success",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  } else {
    mergeBusloading.value = false;
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

// 车辆合车弹窗关闭
const mergeBusClose = () => {
  mergeBusDialog.value = false;
  selectData.list = [];
  selectData.allNum = 0;
  selectData.sy_num = 0;
  // ruleFormMerge.value.resetFields();
};

// 确认派车
const submitAdd = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      // ElMessageBox.confirm("是否允许给用户发送通知信息？", "提示", {
      //   confirmButtonText: "确认",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(async () => {
      //     // 允许发送通知信息  --------------------------
      //     let data = {
      //       car_number: ruleForm.busname.join(","),
      //       route: ruleForm.route,
      //       contain: ruleForm.volume,
      //       route_end: ruleForm.destination,
      //       ci_time: ruleForm.ci_time,
      //       sm_start: ruleForm.codeTime[0],
      //       sm_end: ruleForm.codeTime[1],
      //       yy_end: ruleForm.yy_end,
      //       id: ruleForm.id,
      //       send_state: 1,
      //     };
      //     let res = await axios({
      //       method: "post",
      //       url: api.value + "/carBook/scheupdate.action",
      //       headers: {
      //         "Content-Type": "application/json;charset=utf-8",
      //         token: sessionStorage.getItem("token"),
      //         admin_name: sessionStorage.getItem("username"),
      //       },
      //       data: data,
      //     });
      //     if (res.data.code == 200) {
      //       getList();
      //       ElMessage({
      //         type: "success",
      //         showClose: true,
      //         message: res.data.message,
      //         center: true,
      //       });
      //       centerDialogVisible.value = false;
      //       ruleFormRef.value.resetFields();
      //     } else {
      //       ElMessage({
      //         type: "error",
      //         showClose: true,
      //         message: res.data.message,
      //         center: true,
      //       });
      //     }
      //   })
      //   .catch(async () => {
      //     // 取消发送通知信息 -----------------------
      //     let data = {
      //       car_number: ruleForm.busname.join(","),
      //       route: ruleForm.route,
      //       contain: ruleForm.volume,
      //       route_end: ruleForm.destination,
      //       ci_time: ruleForm.ci_time,
      //       sm_start: ruleForm.codeTime[0],
      //       sm_end: ruleForm.codeTime[1],
      //       yy_end: ruleForm.yy_end,
      //       id: ruleForm.id,
      //       send_state: 0,
      //     };
      //     let res = await axios({
      //       method: "post",
      //       url: api.value + "/carBook/scheupdate.action",
      //       headers: {
      //         "Content-Type": "application/json;charset=utf-8",
      //         token: sessionStorage.getItem("token"),
      //         admin_name: sessionStorage.getItem("username"),
      //       },
      //       data: data,
      //     });
      //     if (res.data.code == 200) {
      //       getList();
      //       ElMessage({
      //         type: "success",
      //         showClose: true,
      //         message: res.data.message,
      //         center: true,
      //       });
      //       centerDialogVisible.value = false;
      //       ruleFormRef.value.resetFields();
      //     } else {
      //       ElMessage({
      //         type: "error",
      //         showClose: true,
      //         message: res.data.message,
      //         center: true,
      //       });
      //     }
      //   });
      let data = {
        car_number: ruleForm.busname.join(","),
        route: ruleForm.route,
        contain: ruleForm.volume,
        route_end: ruleForm.destination,
        ci_time: ruleForm.ci_time,
        sm_start: ruleForm.codeTime[0],
        sm_end: ruleForm.codeTime[1],
        yy_end: ruleForm.yy_end,
        id: ruleForm.id,
        // send_state: 0,
      };
      let res = await axios({
        method: "post",
        url: api.value + "/carBook/scheupdate.action",
        headers: {
          "Content-Type": "application/json;charset=utf-8",
          token: sessionStorage.getItem("token"),
          admin_name: sessionStorage.getItem("username"),
        },
        data: data,
      });
      if (res.data.code == 200) {
        getList();
        ElMessage({
          type: "success",
          showClose: true,
          message: res.data.message,
          center: true,
        });
        centerDialogVisible.value = false;
        ruleFormRef.value.resetFields();
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.data.message,
          center: true,
        });
      }
    } else {
      console.log("error submit!", fields);
    }
  });
};

// 新增车辆调度弹窗关闭
const editCloseQuery = () => {
  addBusqueryVisible.value = false;
  ruleFormRefQuery.value.resetFields();
};
// 确认新增车辆调度
const submitAddQuery = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      let yesterday = 0;
      if (ruleFormQuery.yesterday == true) {
        yesterday = 1;
      } else if (ruleFormQuery.yesterday == false) {
        yesterday = 0;
      }
      let data = {
        car_number: ruleFormQuery.busname,
        ci_time: ruleFormQuery.ci_time,
        contain: ruleFormQuery.volume,
        route: ruleFormQuery.route,
        route_end: ruleFormQuery.destination,
        before_state: yesterday,
        s_date: ruleFormQuery.startDate,
        yy_end: ruleFormQuery.yy_end,
      };
      let res = await axios({
        method: "post",
        url: api.value + "/carBook/scheinsert.action",
        headers: {
          "Content-Type": "application/json;charset=utf-8",
          token: sessionStorage.getItem("token"),
          admin_name: sessionStorage.getItem("username"),
        },
        data: data,
      });
      if (res.data.code == 200) {
        getList();
        ElMessage({
          type: "success",
          showClose: true,
          message: res.data.message,
          center: true,
        });
        addBusqueryVisible.value = false;
        ruleFormRefQuery.value.resetFields();
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.data.message,
          center: true,
        });
      }
    } else {
      console.log("error submit!", fields);
    }
  });
};

// 是否可提前预约
const stateChange = async (row, val) => {
  let data = new FormData();
  data.set("id", row.id);
  data.set("beforeState", row.before_state);

  let res = await axios({
    method: "post",
    url: api.value + "/scheubs.action",
    headers: {
      token: sessionStorage.getItem("token"),
      admin_name: sessionStorage.getItem("username"),
    },
    data: data,
  });
  if (res.data.code == 200) {
    getList();
    ElMessage({
      type: "success",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  } else {
    getList();
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

//删除按钮
const del = async (row) => {
  console.log(row);
  ElMessageBox.confirm(`是否删除 ${row.car_number} 车辆?`, "提示", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      // ElMessageBox.confirm("是否允许给用户发送通知信息？", "提示", {
      //   confirmButtonText: "确认",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(async () => {
      //     let data = new FormData();
      //     data.set("id", row.id);
      //     data.set("send_state", 1);
      //     let res = await axios({
      //       method: "post",
      //       url: api.value + "/carBook/schedel.action",
      //       headers: {
      //         token: sessionStorage.getItem("token"),
      //         admin_name: sessionStorage.getItem("username"),
      //       },
      //       data: data,
      //     });
      //     if (res.data.code == 200) {
      //       if (tableData.list.length == 1 && currentPage.value != 1) {
      //         currentPage.value = currentPage.value - 1;
      //       }
      //       getList();
      //       ElMessage({
      //         type: "success",
      //         showClose: true,
      //         message: res.data.message,
      //         center: true,
      //       });
      //     } else {
      //       ElMessage({
      //         type: "error",
      //         showClose: true,
      //         message: res.data.message,
      //         center: true,
      //       });
      //     }
      //   })
      //   .catch(async () => {
      //     let data = new FormData();
      //     data.set("id", row.id);
      //     data.set("send_state", 0);
      //     let res = await axios({
      //       method: "post",
      //       url: api.value + "/carBook/schedel.action",
      //       headers: {
      //         token: sessionStorage.getItem("token"),
      //         admin_name: sessionStorage.getItem("username"),
      //       },
      //       data: data,
      //     });
      //     if (res.data.code == 200) {
      //       if (tableData.list.length == 1 && currentPage.value != 1) {
      //         currentPage.value = currentPage.value - 1;
      //       }
      //       getList();
      //       ElMessage({
      //         type: "success",
      //         showClose: true,
      //         message: res.data.message,
      //         center: true,
      //       });
      //     } else {
      //       ElMessage({
      //         type: "error",
      //         showClose: true,
      //         message: res.data.message,
      //         center: true,
      //       });
      //     }
      //   });
      let data = new FormData();
      data.set("id", row.id);
      // data.set("send_state", 1);
      let res = await axios({
        method: "post",
        url: api.value + "/carBook/schedel.action",
        headers: {
          token: sessionStorage.getItem("token"),
          admin_name: sessionStorage.getItem("username"),
        },
        data: data,
      });
      if (res.data.code == 200) {
        console.log(res.data);

        if (tableData.list.length == 1 && currentPage.value != 1) {
          currentPage.value = currentPage.value - 1;
        }
        getList();
        ElMessage({
          type: "success",
          showClose: true,
          message: res.data.message,
          center: true,
        });
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.data.message,
          center: true,
        });
      }
    })
    .catch(() => {
      // ElMessage({
      //   type: "info",
      //   message: "已取消删除",
      // });
    });
};

// 导出按钮
// 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://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();
};

onMounted(() => {
  api.value = store.state.user.api;
  pathNum.list = JSON.parse(sessionStorage.getItem("pathSelect"));
  busNum.list = JSON.parse(sessionStorage.getItem("busSelect"));
  console.log(busNum.list, "车辆列表");

  // let route_endSelect = JSON.parse(sessionStorage.getItem("route_endSelect"));
  // console.log(route_endSelect);
  // endNum.list = route_endSelect.filter((item) => {
  //   return item.route == ruleForm.route;
  // });

  if (busNum.list) {
    busNum.list.forEach((item) => {
      initials.list.push(item.car_number);
    });
  }
  console.log(initials.list, "候补弹窗多选车牌号数据");

  // options.value = Array.from({ length: initials.list.length }).map(
  //   (_, idx) => ({
  //     value: `${initials.list[idx % 10]}`,
  //     label: `${initials.list[idx % 10]}`,
  //   })
  // );
  // console.log(options.value, "候补弹窗多选车牌号逻辑");

  getList();
});
</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(100wh - 40px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    margin: 0 30px;
    // padding: 10px 0;
    border-bottom: 1px solid #ccc;
    color: #000;
    font-size: 18px;
    font-weight: 600;
    .camera {
      margin-right: 15px;
      color: #4392f7;
    }
  }

  .filter {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    //   width: 100%;
    .condition {
      display: flex;
      align-items: center;
      margin: 10px 20px 10px 0;
      color: #000;
      span {
        margin: 0 10px 0 0;
      }
    }
  }
  .footer {
    width: calc(100% - 60px);
    flex: 1;
    margin: 0 auto;
    overflow: auto;
    :deep(.el-table__header-wrapper) {
      height: 48px;

      .el-table__header {
        height: 48px;
        font-size: 16px;
      }
    }
    .el-table--fit {
      height: 100%;

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

      :deep(.el-button) {
        width: 50px;
        height: 26px;
        border-radius: 40px;
        font-size: 15px;
      }
      :deep(.look) {
        padding: 3px 10px;
        border-radius: 40px;
        // border: 0.74px solid rgba(30, 125, 251, 1);
      }
      :deep(.lookcar) {
        padding: 3px 10px;
        border-radius: 40px;
        // border: 0.74px solid #e6a23c;
      }
      :deep(.lookdel) {
        padding: 3px 5px;
        border-radius: 40px;
        // border: 0.74px solid #fa7070;
      }
      // 输出链接弹窗样式
      :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: calc(100% - 60px);
    height: 60px;
    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;
    }
  }
  :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;
      }
    }
  }

  :deep(.mergeBus) {
    //   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-table__header {
        font-size: 17px;
      }
      .el-table__body-wrapper {
        .el-table__row {
          height: 48px;
          font-size: 17px;
          color: #000;
          td {
            padding: 0;
          }
        }
      }

      .el-table__inner-wrapper::before {
        height: 0;
      }
      .el-table__inner-wrapper {
        .el-table__header-wrapper {
          .el-table__header {
            .disabledsele .cell .el-checkbox__inner {
              display: none !important;
            }
            .disabledsele .cell::before {
              content: "操作";
              text-align: center;
              line-height: 37px;
            }
          }
        }
      }

      .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;
      }
    }

    .btn {
      width: 100%;
      height: 40px;
      margin-bottom: 20px;
      display: flex;
      flex-direction: row-reverse;
      align-items: center;
      justify-content: space-between;
      .txt {
        font-size: 18px;
        color: #000;
      }
    }
  }
}
.el-input {
  width: 192px;
}
</style>
