<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="编码" prop="encoding">
        <el-input
          v-model="queryParams.encoding"
          placeholder="请输入编码"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆号码" prop="vehicleNumber">
        <el-input
          v-model="queryParams.vehicleNumber"
          placeholder="请输入车辆号码"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区间距离" prop="zoneDistance">
        <el-input
          v-model="queryParams.zoneDistance"
          placeholder="请输入区间距离"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区间限速" prop="intervalSpeedLimit">
        <el-input
          v-model="queryParams.intervalSpeedLimit"
          placeholder="请输入区间限速"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="超速等级  1:10%-20%  2:20%-30% 3:30%-40% 4:40%--50%....." prop="overspeedLevel">
        <el-input
          v-model="queryParams.overspeedLevel"
          placeholder="请输入超速等级  1:10%-20%  2:20%-30% 3:30%-40% 4:40%--50%....."
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="超速等级信息(20%-30%)" prop="overspeedLevelInformation">
        <el-input
          v-model="queryParams.overspeedLevelInformation"
          placeholder="请输入超速等级信息(20%-30%)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="通过开始设备的时间" prop="startDeviceTime">
        <el-date-picker clearable
          v-model="queryParams.startDeviceTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择通过开始设备的时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="通过结束设备的时间" prop="endDeviceTime">
        <el-date-picker clearable
          v-model="queryParams.endDeviceTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择通过结束设备的时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="行使时长" prop="exerciseDuration">
        <el-input
          v-model="queryParams.exerciseDuration"
          placeholder="请输入行使时长"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平均速度" prop="averageSpeed">
        <el-input
          v-model="queryParams.averageSpeed"
          placeholder="请输入平均速度"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="待休息时长" prop="restDuration">
        <el-input
          v-model="queryParams.restDuration"
          placeholder="请输入待休息时长"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="暂扣时间" prop="detainTime">
        <el-date-picker clearable
          v-model="queryParams.detainTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择暂扣时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="放行时间" prop="releaseTime">
        <el-date-picker clearable
          v-model="queryParams.releaseTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择放行时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="暂扣执法部门id" prop="detainDepartmentId">
        <el-input
          v-model="queryParams.detainDepartmentId"
          placeholder="请输入暂扣执法部门id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="暂扣执法人员id" prop="detainWorkId">
        <el-input
          v-model="queryParams.detainWorkId"
          placeholder="请输入暂扣执法人员id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="过车时间 用以确定数据查询的时间" prop="queryTime">
        <el-date-picker clearable
          v-model="queryParams.queryTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择过车时间 用以确定数据查询的时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="放行执法部门id" prop="releaseDepartmentId">
        <el-input
          v-model="queryParams.releaseDepartmentId"
          placeholder="请输入放行执法部门id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="放行执法人员id" prop="releaseWorkId">
        <el-input
          v-model="queryParams.releaseWorkId"
          placeholder="请输入放行执法人员id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['system:SpeedingVehicleInformation:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:SpeedingVehicleInformation:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:SpeedingVehicleInformation:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['system:SpeedingVehicleInformation:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="SpeedingVehicleInformationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" />
      <el-table-column label="编码" align="center" prop="encoding" />
      <el-table-column label="车辆号码" align="center" prop="vehicleNumber" />
      <el-table-column label="车辆号牌类别  1蓝色  2黄色  3绿色  4其他" align="center" prop="vehicleNumberType" />
      <el-table-column label="区间距离" align="center" prop="zoneDistance" />
      <el-table-column label="区间限速" align="center" prop="intervalSpeedLimit" />
      <el-table-column label="区间设备基本信息 json" align="center" prop="intervalInformationJson" />
      <el-table-column label="超速等级  1:10%-20%  2:20%-30% 3:30%-40% 4:40%--50%....." align="center" prop="overspeedLevel" />
      <el-table-column label="超速等级信息(20%-30%)" align="center" prop="overspeedLevelInformation" />
      <el-table-column label="通过开始设备的时间" align="center" prop="startDeviceTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.startDeviceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="通过结束设备的时间" align="center" prop="endDeviceTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.endDeviceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="行使时长" align="center" prop="exerciseDuration" />
      <el-table-column label="平均速度" align="center" prop="averageSpeed" />
      <el-table-column label="待休息时长" align="center" prop="restDuration" />
      <el-table-column label="开始进入区间照片" align="center" prop="startDeviceImage" width="100">
        <template #default="scope">
          <image-preview :src="scope.row.startDeviceImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="离开区间的照片" align="center" prop="endDeviceImage" width="100">
        <template #default="scope">
          <image-preview :src="scope.row.endDeviceImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="车辆状态  1正常  2超速   3暂扣  4放行" align="center" prop="status" />
      <el-table-column label="暂扣时间" align="center" prop="detainTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.detainTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="暂扣照片" align="center" prop="detainStartImage" width="100">
        <template #default="scope">
          <image-preview :src="scope.row.detainStartImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="放行时间" align="center" prop="releaseTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.releaseTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="放行照片" align="center" prop="releaseImage" width="100">
        <template #default="scope">
          <image-preview :src="scope.row.releaseImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="暂扣执法部门id" align="center" prop="detainDepartmentId" />
      <el-table-column label="暂扣执法部门信息" align="center" prop="detainDepartmentJson" />
      <el-table-column label="暂扣执法人员id" align="center" prop="detainWorkId" />
      <el-table-column label="暂扣执法人员信息" align="center" prop="detainWorkJson" />
      <el-table-column label="暂扣驾驶员基本信息  驾照，行驶证等信息json保存" align="center" prop="detainDriverJson" />
      <el-table-column label="数据查询状态 1半年内的数据   2半年以前的数据" align="center" prop="queryType" />
      <el-table-column label="过车时间 用以确定数据查询的时间" align="center" prop="queryTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.queryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据状态  1正常  2隐藏" align="center" prop="delStatus" />
      <el-table-column label="放行执法部门id" align="center" prop="releaseDepartmentId" />
      <el-table-column label="放行执法部门信息" align="center" prop="releaseDepartmentJson" />
      <el-table-column label="放行执法人员id" align="center" prop="releaseWorkId" />
      <el-table-column label="放行执法人员信息" align="center" prop="releaseWorkJson" />
      <el-table-column label="暂扣驾驶员基本信息  驾照，行驶证等信息json保存" align="center" prop="releaseDriverJson" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:SpeedingVehicleInformation:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:SpeedingVehicleInformation:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改过车信息对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="SpeedingVehicleInformationRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="编码" prop="encoding">
          <el-input v-model="form.encoding" placeholder="请输入编码" />
        </el-form-item>
        <el-form-item label="车辆号码" prop="vehicleNumber">
          <el-input v-model="form.vehicleNumber" placeholder="请输入车辆号码" />
        </el-form-item>
        <el-form-item label="区间距离" prop="zoneDistance">
          <el-input v-model="form.zoneDistance" placeholder="请输入区间距离" />
        </el-form-item>
        <el-form-item label="区间限速" prop="intervalSpeedLimit">
          <el-input v-model="form.intervalSpeedLimit" placeholder="请输入区间限速" />
        </el-form-item>
        <el-form-item label="区间设备基本信息 json" prop="intervalInformationJson">
          <el-input v-model="form.intervalInformationJson" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="超速等级  1:10%-20%  2:20%-30% 3:30%-40% 4:40%--50%....." prop="overspeedLevel">
          <el-input v-model="form.overspeedLevel" placeholder="请输入超速等级  1:10%-20%  2:20%-30% 3:30%-40% 4:40%--50%....." />
        </el-form-item>
        <el-form-item label="超速等级信息(20%-30%)" prop="overspeedLevelInformation">
          <el-input v-model="form.overspeedLevelInformation" placeholder="请输入超速等级信息(20%-30%)" />
        </el-form-item>
        <el-form-item label="通过开始设备的时间" prop="startDeviceTime">
          <el-date-picker clearable
            v-model="form.startDeviceTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择通过开始设备的时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="通过结束设备的时间" prop="endDeviceTime">
          <el-date-picker clearable
            v-model="form.endDeviceTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择通过结束设备的时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="行使时长" prop="exerciseDuration">
          <el-input v-model="form.exerciseDuration" placeholder="请输入行使时长" />
        </el-form-item>
        <el-form-item label="平均速度" prop="averageSpeed">
          <el-input v-model="form.averageSpeed" placeholder="请输入平均速度" />
        </el-form-item>
        <el-form-item label="待休息时长" prop="restDuration">
          <el-input v-model="form.restDuration" placeholder="请输入待休息时长" />
        </el-form-item>
        <el-form-item label="开始进入区间照片" prop="startDeviceImage">
          <image-upload v-model="form.startDeviceImage"/>
        </el-form-item>
        <el-form-item label="离开区间的照片" prop="endDeviceImage">
          <image-upload v-model="form.endDeviceImage"/>
        </el-form-item>
        <el-form-item label="暂扣时间" prop="detainTime">
          <el-date-picker clearable
            v-model="form.detainTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择暂扣时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="暂扣照片" prop="detainStartImage">
          <image-upload v-model="form.detainStartImage"/>
        </el-form-item>
        <el-form-item label="放行时间" prop="releaseTime">
          <el-date-picker clearable
            v-model="form.releaseTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择放行时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="放行照片" prop="releaseImage">
          <image-upload v-model="form.releaseImage"/>
        </el-form-item>
        <el-form-item label="暂扣执法部门id" prop="detainDepartmentId">
          <el-input v-model="form.detainDepartmentId" placeholder="请输入暂扣执法部门id" />
        </el-form-item>
        <el-form-item label="暂扣执法部门信息" prop="detainDepartmentJson">
          <el-input v-model="form.detainDepartmentJson" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="暂扣执法人员id" prop="detainWorkId">
          <el-input v-model="form.detainWorkId" placeholder="请输入暂扣执法人员id" />
        </el-form-item>
        <el-form-item label="暂扣执法人员信息" prop="detainWorkJson">
          <el-input v-model="form.detainWorkJson" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="暂扣驾驶员基本信息  驾照，行驶证等信息json保存" prop="detainDriverJson">
          <el-input v-model="form.detainDriverJson" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="过车时间 用以确定数据查询的时间" prop="queryTime">
          <el-date-picker clearable
            v-model="form.queryTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择过车时间 用以确定数据查询的时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="放行执法部门id" prop="releaseDepartmentId">
          <el-input v-model="form.releaseDepartmentId" placeholder="请输入放行执法部门id" />
        </el-form-item>
        <el-form-item label="放行执法部门信息" prop="releaseDepartmentJson">
          <el-input v-model="form.releaseDepartmentJson" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="放行执法人员id" prop="releaseWorkId">
          <el-input v-model="form.releaseWorkId" placeholder="请输入放行执法人员id" />
        </el-form-item>
        <el-form-item label="放行执法人员信息" prop="releaseWorkJson">
          <el-input v-model="form.releaseWorkJson" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="暂扣驾驶员基本信息  驾照，行驶证等信息json保存" prop="releaseDriverJson">
          <el-input v-model="form.releaseDriverJson" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="SpeedingVehicleInformation">
import { listSpeedingVehicleInformation, getSpeedingVehicleInformation, delSpeedingVehicleInformation, addSpeedingVehicleInformation, updateSpeedingVehicleInformation } from "@/api/system/SpeedingVehicleInformation"

const { proxy } = getCurrentInstance()

const SpeedingVehicleInformationList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    encoding: null,
    vehicleNumber: null,
    vehicleNumberType: null,
    zoneDistance: null,
    intervalSpeedLimit: null,
    intervalInformationJson: null,
    overspeedLevel: null,
    overspeedLevelInformation: null,
    startDeviceTime: null,
    endDeviceTime: null,
    exerciseDuration: null,
    averageSpeed: null,
    restDuration: null,
    startDeviceImage: null,
    endDeviceImage: null,
    status: null,
    detainTime: null,
    detainStartImage: null,
    releaseTime: null,
    releaseImage: null,
    detainDepartmentId: null,
    detainDepartmentJson: null,
    detainWorkId: null,
    detainWorkJson: null,
    detainDriverJson: null,
    queryType: null,
    queryTime: null,
    delStatus: null,
    releaseDepartmentId: null,
    releaseDepartmentJson: null,
    releaseWorkId: null,
    releaseWorkJson: null,
    releaseDriverJson: null
  },
  rules: {
    encoding: [
      { required: true, message: "编码不能为空", trigger: "blur" }
    ],
    vehicleNumber: [
      { required: true, message: "车辆号码不能为空", trigger: "blur" }
    ],
    vehicleNumberType: [
      { required: true, message: "车辆号牌类别  1蓝色  2黄色  3绿色  4其他不能为空", trigger: "change" }
    ],
    zoneDistance: [
      { required: true, message: "区间距离不能为空", trigger: "blur" }
    ],
    intervalSpeedLimit: [
      { required: true, message: "区间限速不能为空", trigger: "blur" }
    ],
    intervalInformationJson: [
      { required: true, message: "区间设备基本信息 json不能为空", trigger: "blur" }
    ],
    startDeviceTime: [
      { required: true, message: "通过开始设备的时间不能为空", trigger: "blur" }
    ],
    startDeviceImage: [
      { required: true, message: "开始进入区间照片不能为空", trigger: "blur" }
    ],
    status: [
      { required: true, message: "车辆状态  1正常  2超速   3暂扣  4放行不能为空", trigger: "change" }
    ],
    delStatus: [
      { required: true, message: "数据状态  1正常  2隐藏不能为空", trigger: "change" }
    ],
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询过车信息列表 */
function getList() {
  loading.value = true
  listSpeedingVehicleInformation(queryParams.value).then(response => {
    SpeedingVehicleInformationList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    encoding: null,
    vehicleNumber: null,
    vehicleNumberType: null,
    zoneDistance: null,
    intervalSpeedLimit: null,
    intervalInformationJson: null,
    overspeedLevel: null,
    overspeedLevelInformation: null,
    startDeviceTime: null,
    endDeviceTime: null,
    exerciseDuration: null,
    averageSpeed: null,
    restDuration: null,
    startDeviceImage: null,
    endDeviceImage: null,
    status: null,
    detainTime: null,
    detainStartImage: null,
    releaseTime: null,
    releaseImage: null,
    detainDepartmentId: null,
    detainDepartmentJson: null,
    detainWorkId: null,
    detainWorkJson: null,
    detainDriverJson: null,
    queryType: null,
    queryTime: null,
    delStatus: null,
    releaseDepartmentId: null,
    releaseDepartmentJson: null,
    releaseWorkId: null,
    releaseWorkJson: null,
    releaseDriverJson: null
  }
  proxy.resetForm("SpeedingVehicleInformationRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加过车信息"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getSpeedingVehicleInformation(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改过车信息"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["SpeedingVehicleInformationRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateSpeedingVehicleInformation(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addSpeedingVehicleInformation(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除过车信息编号为"' + _ids + '"的数据项？').then(function() {
    return delSpeedingVehicleInformation(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/SpeedingVehicleInformation/export', {
    ...queryParams.value
  }, `SpeedingVehicleInformation_${new Date().getTime()}.xlsx`)
}

getList()
</script>
