<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="100px"
    >
      <el-form-item label="入场记录编号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入入场记录编号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="停车场编号" prop="parkNumber">
        <el-input
          v-model="queryParams.parkNumber"
          placeholder="请输入停车场编号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="操作员 Id" prop="operatorId">
        <el-input
          v-model="queryParams.operatorId"
          placeholder="请输入操作员 Id"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="操作员姓名" prop="operatorName">
        <el-input
          v-model="queryParams.operatorName"
          placeholder="请输入操作员姓名"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="发票号码" prop="invoiceNo">
        <el-input
          v-model="queryParams.invoiceNo"
          placeholder="请输入发票号码"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="车牌" prop="plate">
        <el-input
          v-model="queryParams.plate"
          placeholder="请输入车牌"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入证件号码"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="入场时间" prop="inTime">
        <el-date-picker
          v-model="queryParams.inTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="出场时间" prop="outTime">
        <el-date-picker
          v-model="queryParams.outTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
     <!-- <el-form-item label="入口通道名称" prop="inChannel">
        <el-input
          v-model="queryParams.inChannel"
          placeholder="请输入入口通道名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="出口通道名称" prop="outChannel">
        <el-input
          v-model="queryParams.outChannel"
          placeholder="请输入出口通道名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="抬杆模式" prop="openGateMode">
        <el-input
          v-model="queryParams.openGateMode"
          placeholder="请输入抬杆模式"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="匹配模式" prop="matchMode">
        <el-input
          v-model="queryParams.matchMode"
          placeholder="请输入匹配模式"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="总停车费" prop="charge">
        <el-input
          v-model="queryParams.charge"
          placeholder="请输入总停车费"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线上总收费" prop="onLineCharge">
        <el-input
          v-model="queryParams.onLineCharge"
          placeholder="请输入线上总收费"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线下总收费" prop="offLineCharge">
        <el-input
          v-model="queryParams.offLineCharge"
          placeholder="请输入线下总收费"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线上线下金额和时间优惠累计抵扣值" prop="profitChargeTotal">
        <el-input
          v-model="queryParams.profitChargeTotal"
          placeholder="请输入线上线下金额和时间优惠累计抵扣值"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线上累计优惠金额总面值" prop="onLineProfitChargeNum">
        <el-input
          v-model="queryParams.onLineProfitChargeNum"
          placeholder="请输入线上累计优惠金额总面值"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线上累计优惠金额总抵扣值" prop="onLineProfitChargeValue">
        <el-input
          v-model="queryParams.onLineProfitChargeValue"
          placeholder="请输入线上累计优惠金额总抵扣值"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线下累计优惠金额总面值" prop="offLineProfitChargeNum">
        <el-input
          v-model="queryParams.offLineProfitChargeNum"
          placeholder="请输入线下累计优惠金额总面值"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线下累计优惠金额总抵扣值" prop="offLineProfitChargeValue">
        <el-input
          v-model="queryParams.offLineProfitChargeValue"
          placeholder="请输入线下累计优惠金额总抵扣值"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线上累计优惠时间" prop="onLineProfitTimeNum">
        <el-input
          v-model="queryParams.onLineProfitTimeNum"
          placeholder="请输入线上累计优惠时间"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线上累计优惠时间总抵扣值" prop="onLineProfitTimeValue">
        <el-input
          v-model="queryParams.onLineProfitTimeValue"
          placeholder="请输入线上累计优惠时间总抵扣值"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线下累计优惠时间" prop="offLineProfitTimeNum">
        <el-input
          v-model="queryParams.offLineProfitTimeNum"
          placeholder="请输入线下累计优惠时间"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="线下累计优惠时间总抵扣值" prop="offLineProfitTimeValue">
        <el-input
          v-model="queryParams.offLineProfitTimeValue"
          placeholder="请输入线下累计优惠时间总抵扣值"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item> -->
<!--      <el-form-item label="时间" prop="costTime">
        <el-date-picker
          v-model="queryParams.costTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker
          v-model="queryParams.createTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
        <el-button
          type="primary"
          plain
          @click="openForm('create')"
          v-hasPermi="['parking:appearance-record:create']"
        >
          <Icon icon="ep:plus" class="mr-5px" /> 新增
        </el-button>
        <el-button
          type="success"
          plain
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['parking:appearance-record:export']"
        >
          <Icon icon="ep:download" class="mr-5px" /> 导出
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="入场记录编号" align="center" prop="orderId"  width='110px'	 />
      <el-table-column label="停车场编号" align="center" prop="parkNumber" width='110px'/>
      <el-table-column label="操作员 Id" align="center" prop="operatorId" width='110px' />
      <el-table-column label="操作员姓名" align="center" prop="operatorName" width='110px' />
      <el-table-column label="发票号码" align="center" prop="invoiceNo" />
      <el-table-column label="车牌" align="center" prop="plate" />
      <el-table-column label="证件号码" align="center" prop="idCard" />
      <el-table-column label="入场时间" align="center" prop="inTime" />
      <el-table-column label="出场时间" align="center" prop="outTime" />
      <el-table-column label="入场图片名" align="center" prop="inImage" width='110px'/>
      <el-table-column label="出场图片名" align="center" prop="outImage" width='110px'/>
      <el-table-column label="入口通道名称" align="center" prop="inChannel" width='110px'/>
      <el-table-column label="出口通道名称" align="center" prop="outChannel" width='110px'/>
      <el-table-column label="抬杆模式" align="center" prop="openGateMode" />
      <el-table-column label="匹配模式" align="center" prop="matchMode" />
      <el-table-column label="总停车费" align="center" prop="charge" />
      <el-table-column label="线上总收费" align="center" prop="onLineCharge" width='110px'/>
      <el-table-column label="线下总收费" align="center" prop="offLineCharge" width='110px'/>
     <!-- <el-table-column label="线上线下金额和时间优惠累计抵扣值" align="center" prop="profitChargeTotal" />
      <el-table-column label="线上累计优惠金额总面值" align="center" prop="onLineProfitChargeNum" />
      <el-table-column label="线上累计优惠金额总抵扣值" align="center" prop="onLineProfitChargeValue" />
      <el-table-column label="线下累计优惠金额总面值" align="center" prop="offLineProfitChargeNum" />
      <el-table-column label="线下累计优惠金额总抵扣值" align="center" prop="offLineProfitChargeValue" />
      <el-table-column label="线上累计优惠时间" align="center" prop="onLineProfitTimeNum" />
      <el-table-column label="线上累计优惠时间总抵扣值" align="center" prop="onLineProfitTimeValue" />
      <el-table-column label="线下累计优惠时间" align="center" prop="offLineProfitTimeNum" />
      <el-table-column label="线下累计优惠时间总抵扣值" align="center" prop="offLineProfitTimeValue" /> -->
      <el-table-column label="时间" align="center" prop="costTime" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="操作" align="center"  fixed="right" width="110">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('update', scope.row.id)"
            v-hasPermi="['parking:appearance-record:update']"
          >
            编辑
          </el-button>
          <el-button
            link
            type="danger"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['parking:appearance-record:delete']"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <AppearanceRecordForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { AppearanceRecordApi, AppearanceRecordVO } from '@/api/parking/appearancerecord'
import AppearanceRecordForm from './AppearanceRecordForm.vue'

/** 出场记录 列表 */
defineOptions({ name: 'AppearanceRecord' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<AppearanceRecordVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  orderId: undefined,
  parkNumber: undefined,
  operatorId: undefined,
  operatorName: undefined,
  invoiceNo: undefined,
  plate: undefined,
  idCard: undefined,
  inTime: [],
  outTime: [],
  inImage: undefined,
  outImage: undefined,
  inChannel: undefined,
  outChannel: undefined,
  openGateMode: undefined,
  matchMode: undefined,
  charge: undefined,
  onLineCharge: undefined,
  offLineCharge: undefined,
  profitChargeTotal: undefined,
  onLineProfitChargeNum: undefined,
  onLineProfitChargeValue: undefined,
  offLineProfitChargeNum: undefined,
  offLineProfitChargeValue: undefined,
  onLineProfitTimeNum: undefined,
  onLineProfitTimeValue: undefined,
  offLineProfitTimeNum: undefined,
  offLineProfitTimeValue: undefined,
  costTime: [],
  createTime: [],
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await AppearanceRecordApi.getAppearanceRecordPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await AppearanceRecordApi.deleteAppearanceRecord(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await AppearanceRecordApi.exportAppearanceRecord(queryParams)
    download.excel(data, '出场记录.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>