<template>
    <div>
        <el-card :body-style="cardBodyStyle">
            <SearchBox ref="SearchBoxRef" formName="计划号" :formData="query" @PopupNo="PopupNo" @reset="reset">
            </SearchBox>
        </el-card>
        <ButtonBar @search="handleSearch"></ButtonBar>

        <el-card :body-style="cardBodyStyle">
            <el-table :data="tableData" border highlight-current-row>
                <el-table-column type="index" label="序号" align="center" width="60">
                    <template #default="scope">
                        <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
                    </template>
                </el-table-column>

                <el-table-column v-if="true" prop="fsubbillno" label="计划号" width="120" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="true" prop="fitemname" label="物料名称" width="150" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>



                <el-table-column v-if="false" prop="fsndstation" label="发货单位编码/港口编码" width="150" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="fsndname" label="发货单位名称/港口" width="150" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="false" prop="frcvstation" label="收货单位编码" width="360" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="frcvname" label="收货单位名称" width="150" header-align="center"
                    align="center" show-overflow-tooltip>
                </el-table-column>

                <el-table-column v-if="true" prop="mustrcv" label="是否收货确认" width="150" header-align="center"
                    align="center" show-overflow-tooltip>
                    <template #default="scope">
                        {{ scope.row.mustrcv == 'Y' ? '是' : '否' }}
                    </template>
                </el-table-column>
                <el-table-column v-if="true" prop="mustsnd" label="是否发货确认" width="150" header-align="center"
                    align="center" show-overflow-tooltip>
                    <template #default="scope">
                        {{ scope.row.mustsnd == 'Y' ? '是' : '否' }}
                    </template>
                </el-table-column>

                <el-table-column v-if="true" prop="gbms" label="过磅模式" width="100" header-align="center" align="center"
                    show-overflow-tooltip>
                    <template #default="scope">
                        {{ gbmstype.find(x => x.id == scope.row.gbms).name == '' ? '' :
                            gbmstype.find(x => x.id == scope.row.gbms).name }}
                    </template>
                </el-table-column>
                <el-table-column v-if="true" prop="jhbj" label="计划标记" width="100" header-align="center" align="center"
                    show-overflow-tooltip>
                    <template #default="scope">
                        {{ scope.row.jhbj == '1' ? '内部计划' : '其他计划' }}
                    </template>
                </el-table-column>
                <el-table-column v-if="true" prop="ftc" label="创建时间" width="200" header-align="center" align="center"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="fpc" label="创建人姓名" width="100" header-align="center" align="center"
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column v-if="true" prop="fuc" label="创建人账号" width="100" header-align="center" align="center"
                    show-overflow-tooltip>
                </el-table-column>


                <el-table-column label="操作" header-align="center" align="center" fixed="right" width="200px">
                    <template #default="scope">
                        <el-button plain type="primary" @click="handleDispatchCar(scope.row, 1)">派车</el-button>
                        <el-button plain type="info" @click="handleDispatchCar2(scope.row, 2)">查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
        <el-card :body-style="cardBodyStyle">
            <el-pagination :current-page="currentPage" :page-size="pageSize" :page-sizes="pageSizes" :total="totalRows"
                background="background" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
                @current-change="handleCurrentChange">
            </el-pagination>
        </el-card>

        <el-dialog fullscreen :close-on-click-modal="false" draggable v-model="dialogVisible" width="1200px" top="5vh"
            @open="openDialog">
            <el-card :body-style="cardBodyStyle" v-if="diaName === '派车'">

                <div>
                    <h2>派车操作台</h2>
                    <span style="margin-left:1250px;margin-bottom:50px;font-weight: 900;">
                        班次：<el-select v-model="bcqueren" placeholder="请先选择班次..." size="large" style="width: 240px"
                            @change="bcChange">
                            <el-option v-for="item in bcAll" :key="item.id" :label="item.name" :value="item.name" />
                        </el-select>
                        发车日期：<el-date-picker v-model="selecttime" type="date" value-format="YYYY-MM-DD"
                            format="YYYY-MM-DD" style="width: 200px;" :disabled-date="disabledDate"></el-date-picker>
                    </span>

                    <div style="display:flex;align-items:flex-start;justify-content:center;">
                        <div style="height: 100%;width: 40.5%;">
                            <div style="display:flex;align-items:center;">
                                车号：<el-input v-model="queryCl.carno" clearable style="width: 220px;"
                                    placeholder="请输入车号..." />
                                &nbsp&nbsp<el-button type="primary" @click="handleSearchCl">查询</el-button>
                            </div>
                            <br />

                            <el-table height="220px" :data="tableDataCl" border highlight-current-row
                                @selection-change="handleSelectionChange">
                                <el-table-column type="index" label="序号" align="center" width="60">
                                    <template #default="scope">
                                        <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column v-if="true" prop="carno" label="车号" width="120" header-align="center"
                                    align="center" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column v-if="true" prop="carStatus" label="车辆状态" width="80"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column v-if="false" prop="carTypeid" label="车型id" width="120"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column v-if="true" prop="carType" label="车型" width="120" header-align="center"
                                    align="center" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column v-if="true" prop="carFdjh" label="发动机号" width="120"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column v-if="true" prop="carPfbz" label="排放标准" width="80"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column v-if="true" prop="carBearing" label="轴承" width="80"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>

                                <el-table-column fixed="right" label="操作" header-align="center" align="center"
                                    width="100px">
                                    <template #default="scope">
                                        <el-button type="info" @click="handleSelectCl(scope.row)">选择</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <el-card :body-style="cardBodyStyle">
                                <el-pagination :current-page="currentPageCl" :page-size="pageSizeCl"
                                    :page-sizes="pageSizesCl" :total="totalRowsCl" background="background"
                                    layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChangeCl"
                                    @current-change="handleCurrentChangeCl">
                                </el-pagination>
                            </el-card>
                        </div>
                        <div style="height: 100%;width: 43.4%;margin-left:100px;">
                            <div style="display:flex;align-items:center;">
                                司机姓名:<el-input v-model="queryCl.carno" clearable style="width: 220px;"
                                    placeholder="请输入司机姓名..." />
                                &nbsp&nbsp<el-button type="primary" @click="handleSearchSj">查询</el-button>
                            </div>
                            <br />
                            <el-table height="220px" :data="tableDataSj" border highlight-current-row
                                @selection-change="handleSelectionChange">
                                <el-table-column type="index" label="序号" align="center" width="60">
                                    <template #default="scope">
                                        <span>{{ scope.$index + (currentPageSj - 1) * pageSizeSj + 1 }}</span>
                                    </template>
                                </el-table-column>

                                <el-table-column v-if="true" prop="drivername" label="司机姓名" width="100"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column v-if="true" prop="driverstatus" label="司机状态" width="80"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column v-if="true" prop="driveridcard" label="身份证号" width="180"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>


                                <el-table-column v-if="true" prop="tel" label="司机电话" width="120" header-align="center"
                                    align="center" show-overflow-tooltip>
                                </el-table-column>

                                <el-table-column v-if="true" prop="carJszbh" label="驾驶证编号" width="100"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>

                                <el-table-column v-if="true" prop="xingbie" label="驾驶人员性别" width="70"
                                    header-align="center" align="center" show-overflow-tooltip>
                                </el-table-column>


                                <el-table-column fixed="right" label="操作" header-align="center" align="center"
                                    width="100px">
                                    <template #default="scope">
                                        <el-button type="info" @click="handleSelectSj(scope.row)">选择</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <el-card :body-style="cardBodyStyle">
                                <el-pagination :current-page="currentPageSj" :page-size="pageSizeSj"
                                    :page-sizes="pageSizesSj" :total="totalRowsSj" background="background"
                                    layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChangeSj"
                                    @current-change="handleCurrentChangeSj">
                                </el-pagination>
                            </el-card>
                        </div>
                    </div>
                    <el-divider />
                    <div>
                        <h2>派车单</h2>
                        <div style="display:flex;align-items:flex-start;justify-content:space-between;">
                            <div v-show="tableDataPcB" style="width: 33%;">

                                <el-card>
                                    <h2>白班</h2>
                                    <el-table height="200px" :data="tableDataPcB" border highlight-current-row
                                        @selection-change="handleSelectionChange">
                                        <el-table-column type="index" label="序号" align="center" width="60">
                                            <template #default="scope">
                                                <span>{{ scope.$index + (currentPagePc - 1) * pageSizePc + 1 }}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="id" label="主键" width="120"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="planNumber" label="计划号" width="120"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="carNumber" label="车号" width="120"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="driverName" label="司机姓名" width="100"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="false" prop="timeEffective" label="有效时间" width="150"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="driverPhone" label="司机联系方式" width="150"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="classes" label="班次" width="70"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="timeEffective" label="有效时间" width="180"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="startTime" label="开始时间" width="180"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="endTime" label="结束时间" width="180"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" label="操作" width="172" header-align="center"
                                            align="center" show-overflow-tooltip fixed="right">
                                            <template #default="{ row }">
                                                <el-button type="primary" @click="savePc(row)">去保存</el-button>
                                                <el-button type="info" plain @click="DeletePc(row)">取消</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </el-card>


                                <!-- <el-card :body-style="cardBodyStyle">
                                    <el-pagination :current-page="currentPagePc" :page-size="pageSizePc"
                                        :page-sizes="pageSizesPc" :total="totalRowsPc" background="background"
                                        layout="total, sizes, prev, pager, next, jumper"
                                        @size-change="handleSizeChangePc" @current-change="handleCurrentChangePc">
                                    </el-pagination>
                                </el-card> -->
                            </div>

                            <div v-show="tableDataPcZ" style="width: 33%;">

                                <el-card>
                                    <h2>中班</h2>
                                    <el-table height="200px" :data="tableDataPcZ" border highlight-current-row
                                        @selection-change="handleSelectionChange">
                                        <el-table-column type="index" label="序号" align="center" width="60">
                                            <template #default="scope">
                                                <span>{{ scope.$index + (currentPagePc - 1) * pageSizePc + 1 }}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="id" label="主键" width="120"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="planNumber" label="计划号" width="120"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="carNumber" label="车号" width="120"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="driverName" label="司机姓名" width="100"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="false" prop="timeEffective" label="有效时间" width="150"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="driverPhone" label="司机联系方式" width="150"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="classes" label="班次" width="70"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="timeEffective" label="有效时间" width="180"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="startTime" label="开始时间" width="180"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="endTime" label="结束时间" width="180"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" label="操作" width="172" header-align="center"
                                            align="center" show-overflow-tooltip fixed="right">
                                            <template #default="{ row }">
                                                <el-button type="primary" @click="savePc(row)">去保存</el-button>
                                                <el-button type="info" plain @click="DeletePc(row)">取消</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </el-card>


                                <!-- <el-card :body-style="cardBodyStyle">
                                    <el-pagination :current-page="currentPagePc" :page-size="pageSizePc"
                                        :page-sizes="pageSizesPc" :total="totalRowsPc" background="background"
                                        layout="total, sizes, prev, pager, next, jumper"
                                        @size-change="handleSizeChangePc" @current-change="handleCurrentChangePc">
                                    </el-pagination>
                                </el-card> -->
                            </div>

                            <div v-show="tableDataPcY" style="width: 33%;">

                                <el-card>
                                    <h2>夜班</h2>
                                    <el-table height="200px" :data="tableDataPcY" border highlight-current-row
                                        @selection-change="handleSelectionChange">
                                        <el-table-column type="index" label="序号" align="center" width="60">
                                            <template #default="scope">
                                                <span>{{ scope.$index + (currentPagePc - 1) * pageSizePc + 1 }}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="id" label="主键" width="120"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="planNumber" label="计划号" width="120"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="carNumber" label="车号" width="120"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="driverName" label="司机姓名" width="100"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="false" prop="timeEffective" label="有效时间" width="150"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="driverPhone" label="司机联系方式" width="150"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="classes" label="班次" width="70"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="timeEffective" label="有效时间" width="180"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="startTime" label="开始时间" width="180"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" prop="endTime" label="结束时间" width="180"
                                            header-align="center" align="center" show-overflow-tooltip>
                                        </el-table-column>
                                        <el-table-column v-if="true" label="操作" width="172" header-align="center"
                                            align="center" show-overflow-tooltip fixed="right">
                                            <template #default="{ row }">
                                                <el-button type="primary" @click="savePc(row)">去保存</el-button>
                                                <el-button type="info" plain @click="DeletePc(row)">取消</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </el-card>


                                <!-- <el-card :body-style="cardBodyStyle">
                                    <el-pagination :current-page="currentPagePc" :page-size="pageSizePc"
                                        :page-sizes="pageSizesPc" :total="totalRowsPc" background="background"
                                        layout="total, sizes, prev, pager, next, jumper"
                                        @size-change="handleSizeChangePc" @current-change="handleCurrentChangePc">
                                    </el-pagination>
                                </el-card> -->
                            </div>
                        </div>
                    </div>
                </div>
            </el-card>
            <div v-if="diaName === '查看'" :body-style="cardBodyStyle">
                <el-card>
                    <h1>派车单</h1>
                    <el-table height="200" :data="tableDataPc" border highlight-current-row
                        @selection-change="handleSelectionChange">
                        <el-table-column type="index" label="序号" align="center" width="60">
                            <template #default="scope">
                                <span>{{ scope.$index + (currentPagePc - 1) * pageSizePc + 1 }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="true" prop="id" label="主键" width="120" header-align="center"
                            align="center" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="planNumber" label="计划号" width="120" header-align="center"
                            align="center" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="carNumber" label="车号" width="120" header-align="center"
                            align="center" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="driverName" label="司机姓名" width="100" header-align="center"
                            align="center" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="false" prop="timeEffective" label="有效时间" width="150"
                            header-align="center" align="center" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="driverPhone" label="司机联系方式" width="150" header-align="center"
                            align="center" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" prop="classes" label="班次" width="70" header-align="center"
                            align="center" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column v-if="true" label="操作" width="172" header-align="center" align="center"
                            show-overflow-tooltip fixed="right">
                            <template #default="{ row }">
                                <el-button type="primary" @click="savePc(row)">去保存</el-button>
                                <el-button type="info" plain @click="DeletePc(row)">取消</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-card>


                <!-- <el-card :body-style="cardBodyStyle">
                                    <el-pagination :current-page="currentPagePc" :page-size="pageSizePc"
                                        :page-sizes="pageSizesPc" :total="totalRowsPc" background="background"
                                        layout="total, sizes, prev, pager, next, jumper"
                                        @size-change="handleSizeChangePc" @current-change="handleCurrentChangePc">
                                    </el-pagination>
                                </el-card> -->
            </div>
            <el-card v-if="false" :body-style="cardBodyStyle">
                <template #footer>
                    <div v-if="diaName === '派车'" class="dialog-footer" style="display: flex;justify-content: center;">
                        <el-button type="success" @click="handleSave(ruleFormRef)">保存</el-button>
                        <div style="width: 100px"></div>
                        <el-button type="danger" @click="handleCancelSave">取消</el-button>
                    </div>
                </template>
            </el-card>
        </el-dialog>


    </div>
</template>

<script setup>


import {
    ref,
    reactive,
    onMounted,
    getCurrentInstance
} from 'vue'

const {
    proxy
} = getCurrentInstance()

import tools from '@/tools'
const cardBodyStyle = ref(tools.style.card)
const inputStyle = ref(tools.style.input)




/**
 * 头信息
 */

const deptCode = ref('')
const deptName = ref('')
const deptId = ref('')

/**
 * 头信息
 */
onMounted(() => {
    const temp = JSON.parse(localStorage.getItem('deptTree'))
    deptCode.value = temp[0].deptCode
    deptName.value = temp[0].deptName
    deptId.value = temp[0].id
    handleSearch()
    handleSearchCl()
    handleSearchSj()
    handleSearchPc()
})
const form = ref({
    frcvname: '',
    fsndname: '',
    gbms: '',
    mustrcv: '',
    mustsnd: '',
    wuzibm: '',
    wuzimc: '',
    deptCode: '',
    deptName: '',
    deptId: '',
})
const gbmstype = ref([
    { id: '1', name: '固定车皮' },
    { id: '2', name: '先皮后毛' },
    { id: '3', name: '先毛后皮' },
])
const timeKey1 = ref(null)
const timeKey2 = ref(null)
const timeKey3 = ref(null)

const PopupRef = ref(null)
const PopupRef2 = ref(null)
const PopupRefTwo = ref(null)

import ButtonBar from '@/components/ButtonBar.vue'
import Popup_base_wl from "@/views/bas/Popup_base_wl.vue"
import Popup_base_ks from "@/views/bas/Popup_base_ks.vue"

/**
 *   查询
 */
const tem2 = ref('')
const tem3 = ref('')
const retu = (a) => {
    form.value.wuzibm = a.itemCd
    form.value.wuzimc = a.itemNm
}

const retu2 = (a) => {
    tem2.value = a
    form.value.frcvname = a.shortname
}

const retu3 = (a) => {
    tem3.value = a
    form.value.fsndname = a.shortname
}



const query = ref({
    fsubbillno: '',
})
const tableData = ref([])
const handleSearch = () => {
    currentPage.value = 1
    getTableData()
}

const getTableData = () => {
    var url = 'tms/OrderTrans/query'
    var param = {
        page: currentPage.value,
        rows: pageSize.value,
        params: JSON.stringify(query.value)
    }
    proxy.$axios.get(url, param).then(response => {
        if (response.data.code == '0') {
            tableData.value = response.data.data.records
            totalRows.value = response.data.data.total
        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}
/**
 *   查询
 */

/**
 * 分页
 */
const currentPage = ref(1)
const totalRows = ref(0)
const pageSizes = ref([5, 10, 20, 30, 40])
const pageSize = ref(5)
const handleSizeChange = (val) => {
    pageSize.value = val
    getTableData()
}
const handleCurrentChange = (val) => {
    currentPage.value = val
    getTableData()
}
/**
 * 分页
 */


/**
 * 新增
 */
const dialogVisible = ref(false)

const ruleFormRef = ref()
/**
 * 新增
 */


/**
 * 保存、修改、删除
 */

const openDialog = () => {
}

const rowTemp = ref([])
const selectOp = ref('')

const handleSave = (ruleFormRef) => {
    form.value.deptId = deptId.value
    form.value.deptCode = deptCode.value
    form.value.deptName = deptName.value

    if (form.value.mustrcv) {
        form.value.mustrcv = 'Y'
    } else {
        form.value.mustrcv = 'N'
    }
    if (form.value.mustsnd) {
        form.value.mustsnd = 'Y'
    } else {
        form.value.mustsnd = 'N'
    }
    if (form.value.frcvname == '' || form.value.fsndname == '' ||
        form.value.gbms == '' || form.value.mustrcv == '' ||
        form.value.mustsnd == '' || form.value.wuzimc == ''
    ) {
        ElMessage.warning('警告：有未录入的数据，请重新录入！')

        return
    }
    ruleFormRef.validate((valid, fields) => {
        if (valid) {
            var url = 'tms/OrderTrans/save'
            var param = {
                json: JSON.stringify(form.value),
            }
            proxy.$axios.post(url, param).then(response => {
                if (response.data.code == 0) {
                    form.value = response.data.data
                    ElMessage({
                        message: '保存成功',
                        type: 'success',
                    })
                    getTableData()
                    dialogVisible.value = false
                } else {
                    // ElMessage.error('操作失败！' + response.data.msg)
                    ElMessage({
                        message: '操作失败' + response.data.msg,
                        type: 'error'
                    })
                }
            })
        } else {
            console.log('error submit!', fields)
        }
    })
}
const handleCancelSave = () => {
    dialogVisible.value = false
}
/**
 * 保存、修改、删除
 */

const multipleSelection = ref([])
const handleSelectionChange = (val) => {
    multipleSelection.value = val
}

/**
 * 以下汽车表
 */
/**
     *   查询车辆
     */
/**
 * 派车
 */
const diaName = ref('派车')
const handleDispatchCar = (row, t) => {
    jhhSure.value = row.fsubbillno
    console.log("tableDataPc", tableDataPc.value)
    tableDataPcB.value = tableDataPc.value.filter(x => x.classes === '白班' && x.planNumber === jhhSure.value)
    tableDataPcZ.value = tableDataPc.value.filter(x => x.classes === '中班' && x.planNumber === jhhSure.value)
    tableDataPcY.value = tableDataPc.value.filter(x => x.classes === '夜班' && x.planNumber === jhhSure.value)
    dialogVisible.value = true
    if (t === 1) {
        //派车
        console.log('t', t)
        diaName.value = '派车'
    } else if (t === 2) {
        //查看
        console.log('t', t)
        diaName.value = '查看'
    }
}
const handleDispatchCar2 = (row, t) => {
    jhhSure.value = row.fsubbillno
    console.log("tableDataPc", tableDataPc.value)
    
    tableDataPcB.value = tableDataPc.value.filter(x => x.classes === '白班' && x.planNumber === jhhSure.value)
    tableDataPcZ.value = tableDataPc.value.filter(x => x.classes === '中班' && x.planNumber === jhhSure.value)
    tableDataPcY.value = tableDataPc.value.filter(x => x.classes === '夜班' && x.planNumber === jhhSure.value)
    dialogVisible2.value = true
    
}
//可用司机查询
const kySjAll = ref([])
//可用车辆查询
const kyClAll = ref([])
/**
 * 派车
 */
const queryCl = ref({
    carno: ''
})
const tableDataCl = ref([])
const handleSearchCl = () => {
    currentPageCl.value = 1
    getTableDataCl()
}

const getTableDataCl = () => {
    var url = 'tms/Incarinfo/query'
    var param = {
        page: currentPageCl.value,
        rows: pageSizeCl.value,
        params: JSON.stringify(queryCl.value)
    }
    proxy.$axios.get(url, param).then(response => {
        if (response.data.code == '0') {
            tableDataCl.value = response.data.data.records
            totalRowsCl.value = response.data.data.total
        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}
/**
 *   查询车辆
 */
/**
 * 分页车辆
 */
const currentPageCl = ref(1)
const totalRowsCl = ref(0)
const pageSizesCl = ref([5, 10, 20, 30, 40])
const pageSizeCl = ref(5)
const handleSizeChangeCl = (val) => {
    pageSizeCl.value = val
    getTableDataCl()
}
const handleCurrentChangeCl = (val) => {
    currentPageCl.value = val
    getTableDataCl()
}
/**
 * 分页车辆
 */

/**
 * 以下司机表
 */
/**
*   查询司机
*/
const queryInSj = ref({
    drivername: ''
})
const tableDataSj = ref([])
const handleSearchSj = () => {
    currentPageSj.value = 1
    getTableDataSj()
}

const getTableDataSj = () => {
    var url = 'tms/Driver/queryIn'
    var param = {
        page: currentPageSj.value,
        rows: pageSizeSj.value,
        params: JSON.stringify(queryInSj.value)
    }
    proxy.$axios.get(url, param).then(response => {
        if (response.data.code == '0') {
            tableDataSj.value = response.data.data.records
            totalRowsSj.value = response.data.data.total
        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}
/**
 *   查询司机
 */
/**
 * 分页司机
 */
const currentPageSj = ref(1)
const totalRowsSj = ref(0)
const pageSizesSj = ref([5, 10, 20, 30, 40])
const pageSizeSj = ref(5)
const handleSizeChangeSj = (val) => {
    pageSizeSj.value = val
    getTableDataSj()
}
const handleCurrentChangeSj = (val) => {
    currentPageSj.value = val
    getTableDataSj()
}
/**
 * 分页司机
 */

/**
 * 以下派车表
 */
/**
     *   查询派车
     */
const queryPc = ref({
})
const tableDataPc = ref([])
const tableDataPcB = ref([])
const tableDataPcZ = ref([])
const tableDataPcY = ref([])
const handleSearchPc = () => {
    currentPagePc.value = 1
    getTableDataPc()
}

const getTableDataPc = () => {
    var url = 'tms/Indispatchcar/query'
    var param = {

    }
    proxy.$axios.get(url, param).then(response => {
        if (response.data.code == '0') {
            tableDataPc.value = response.data.data
            console.log("tableDataPc",tableDataPc.value)

            
            tableDataPcB.value = tableDataPc.value.filter(x => x.classes === '白班' && x.planNumber === jhhSure.value)
            tableDataPcZ.value = tableDataPc.value.filter(x => x.classes === '中班' && x.planNumber === jhhSure.value)
            tableDataPcY.value = tableDataPc.value.filter(x => x.classes === '夜班' && x.planNumber === jhhSure.value)
        } else {
            ElMessage.error('操作失败！' + response.data.msg)
        }
    })
}
/**
 *   查询派车
 */

/**
 * 分页派车
 */
const currentPagePc = ref(1)
const totalRowsPc = ref(0)
const pageSizesPc = ref([5, 10, 20, 30, 40])
const pageSizePc = ref(5)
const handleSizeChangePc = (val) => {
    pageSizePc.value = val
    getTableDataPc()
}
const handleCurrentChangePc = (val) => {
    currentPagePc.value = val
    getTableDataPc()
}
/**
 * 分页派车
 */

/**
 * 派车
 */
const bcqueren = ref('')
const jhhSure = ref('')
const bcAll = ref([
    { id: '1', name: '白班' },
    { id: '2', name: '中班' },
    { id: '3', name: '夜班' },
])
/**传到后端保存的 */
const tableRowForm = ref({
    planNumber: '',
    carNumber: '',
    driverName: '',
    timeEffective: '',
    driverPhone: '',
    classes: '',
    typeDay: '',
    typeWeek: '',
    typeForever: '',

})
const handleSelectCl = (clall) => {
    if (bcqueren.value === '') {
        ElMessage.error('操作失败，清先选择班次！')
        return
    }
    if (clall.carStatus != '空闲') {
        ElMessage.error('操作失败,该辆车非空闲状态！')
        return
    }
    formall.value.carNumber = clall.carno

    bcChangea()
}
const handleSelectSj = (sjall) => {
    if (bcqueren.value === '') {
        ElMessage.error('操作失败，清先选择班次！')
        return
    }
    if (sjall.driverstatus != '空闲') {
        ElMessage.error('操作失败,该司机非空闲状态！')
        return
    }

    formall.value.driverName = sjall.drivername
    formall.value.driverPhone = sjall.tel
    bcChangea()
}

//班次改变，添加一条记录
const formall = ref({
    planNumber: '',
    carNumber: '',
    driverName: '',
    timeEffective: '',
    driverPhone: '',
    classes: '',
    typeDay: '',
    typeWeek: '',
    typeForever: '',
    deptCode: '',
    deptName: '',
    selecttime: '',
})
const selecttime = ref(null)
const testq = ref([])
const bcChange = (val) => {
    bcqueren.value = val
    formall.value.planNumber = jhhSure.value
    formall.value.classes = bcqueren.value
    formall.value.deptId = deptId.value
    formall.value.deptCode = deptCode.value
    formall.value.deptName = deptName.value
    formall.value.selecttime = selecttime.value
    var url = 'tms/Indispatchcar/save'
    var param = {
        json: JSON.stringify(formall.value),
    }
    proxy.$axios.post(url, param).then(response => {
        if (response.data.code == 0) {
            formall.value = response.data.data
            ElMessage({
                message: '保存成功',
                type: 'success',
            })
            handleSearchPc()
        } else {
            // ElMessage.error('操作失败！' + response.data.msg)
            ElMessage({
                message: '操作失败' + response.data.msg,
                type: 'error'
            })
        }
    })
}

const bcChangea = () => {
    formall.value.planNumber = jhhSure.value
    formall.value.deptId = deptId.value
    formall.value.deptCode = deptCode.value
    formall.value.deptName = deptName.value
    formall.value.selecttime = selecttime.value
    formall.value.classes = bcqueren.value
    var url = 'tms/Indispatchcar/save'
    var param = {
        json: JSON.stringify(formall.value),
    }
    proxy.$axios.post(url, param).then(response => {
        if (response.data.code == 0) {
            formall.value = response.data.data
            ElMessage({
                message: '保存成功',
                type: 'success',
            })
            handleSearchPc()
        } else {
            // ElMessage.error('操作失败！' + response.data.msg)
            ElMessage({
                message: '操作失败' + response.data.msg,
                type: 'error'
            })
        }
    })
}

//取消记录
const DeletePc = (row) => {
    ElMessageBox.confirm(
        '确定删除本条记录?',
        '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
    }
    )
        .then(() => {
            var url = 'tms/Indispatchcar/remove'
            var param = {
                id: row.id
            }
            proxy.$axios.post(url, param).then(response => {
                if (response.data.code == 0) {
                    ElMessage({
                        type: 'success',
                        message: '删除成功',
                    })
                    handleSearchPc()
                } else {
                    ElMessage({
                        type: 'error',
                        message: '删除失败' + response.data.msg
                    });
                }
            });
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '已取消',
            })
        })
}

/**
 * 派车
 */

const disabledDate = (time) => {
    // 禁止选择今天之前的日期
    return time.getTime() < Date.now() - 24 * 60 * 60 * 1000;
}

//去保存
const savePc = () => {

}
</script>

<style></style>