<template>
  <a-card :bordered="false">
    <a-form ref="searchFormRef" :model="searchFormState" class="ant-advanced-search-form">
      <a-row :gutter="24">
        <a-col :span="6">
          <a-form-item label="姓名" name="name">
            <a-input v-model:value="searchFormState.name" placeholder="请输入姓名" allow-clear/>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="性别" name="gender">
            <a-select v-model:value="searchFormState.gender" placeholder="请选择性别"
                      :options="sexOptions" show-search allow-clear optionFilterProp="label"/>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="身份证号" name="idNo">
            <a-input v-model:value="searchFormState.idNo" placeholder="请输入身份证号" allow-clear/>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="国籍" name="nationality">
            <a-select v-model:value="searchFormState.nationality" placeholder="请选择国籍"
                      :options="cityOptions" show-search allow-clear optionFilterProp="label"/>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="居住地" name="address">
            <a-input v-model:value="searchFormState.address" placeholder="请输入居住地" allow-clear/>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="车次/航班号" name="travelNo">
            <a-input v-model:value="searchFormState.travelNo" placeholder="请输入车次/航班号" allow-clear/>
          </a-form-item>
        </a-col>
        <a-col :span="7">
          <a-form-item label="航/车次(班)日期" name="travelTime">
            <a-range-picker v-model:value="searchFormState.travelTime" show-time allow-clear/>
          </a-form-item>
        </a-col>
          <a-col :span="5">
              <a-form-item label="类型" name="checkType">
                  <a-select v-model:value="searchFormState.checkType" placeholder="请选择类型"
                            :options="checkTypeOptions" show-search allow-clear optionFilterProp="label"/>
              </a-form-item>
          </a-col>
        <a-col :span="7">
          <a-form-item label="入场时间" name="admissionTime">
            <a-range-picker v-model:value="searchFormState.admissionTime" show-time allow-clear/>
          </a-form-item>
        </a-col>
        <a-col :span="7">
          <a-form-item label="放行时间" name="passTime">
            <a-range-picker v-model:value="searchFormState.passTime" show-time allow-clear/>
          </a-form-item>
		</a-col>
        <a-col :span="6">
          <a-button type="primary" @click="onSearch()">查询</a-button>
          <a-button style="margin: 0 8px" @click="reset">重置</a-button>
        </a-col>
      </a-row>
    </a-form>
    <s-table
      ref="tableRef"
      :columns="columns"
      :data="loadData"
      bordered
      :row-key="(record) => record.id"
      :tool-config="toolConfig"
      v-model:filterParam="filterParam"
      :scroll="{ x: 2000 }"
    >
      <template #bodyCell="{ column, record }">
        <template v-if="column.dataIndex === 'gender'">
          {{ $TOOL.dictTypeData('lvke_sex', record.gender) }}
        </template>
        <template v-if="column.dataIndex === 'nationality'">
          {{ $TOOL.dictTypeData('lvke_city', record.nationality) }}
        </template>
        <template v-if="column.dataIndex === 'checkType'">
          {{ $TOOL.dictTypeData('lvke_checkType', record.checkType) }}
        </template>
        <template v-if="column.dataIndex === 'action'">
          <a-space>
            <a @click="ref_detail.onOpen(record)">查看</a>
          </a-space>
        </template>
      </template>
    </s-table>
  </a-card>
  <Detail ref="ref_detail"/>
</template>

<script setup name="demo2">
import tool from '@/utils/tool'
import {cloneDeep} from 'lodash-es'
import Detail from './detail.vue'
import basicApi from '@/api/gsc/basic'

const {proxy} = getCurrentInstance()
const searchFormState = ref({})
const searchFormStateReal = ref({}) // 点击搜索后备份的查询参数
const searchFormRef = ref()
const tableRef = ref()
const filterParam = ref({})
const ref_detail = ref()
const toolConfig = {refresh: true, height: true, columnSetting: true, striped: false}
const columns = [
  {
    title: '姓名',
    dataIndex: 'name',
  },
  {
    title: '性别',
    dataIndex: 'gender',
  },
  {
    title: '身份证号',
    dataIndex: 'idNo',
  },
  {
    title: '国籍',
    dataIndex: 'nationality',
  },
  {
    title: '居住地',
    dataIndex: 'address',
  },
  {
    title: '车次/航班号',
    dataIndex: 'travelNo',
  },
  {
    title: '航/车次(班)日期',
    dataIndex: 'travelTime',
  },
  {
    title: '类型',
    dataIndex: 'checkType',
  },
  {
    title: '入场时间',
    dataIndex: 'admissionTime',
  },
  {
    title: '放行时间',
    dataIndex: 'passTime',
  },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'center',
    width: 100,
    fixed: 'right',
  }
]
const selectedRowKeys = ref([])
// 列表选择配置
const options = {
  // columns数字类型字段加入 needTotal: true 可以勾选自动算账
  alert: {
    show: true,
    clear: () => {
      selectedRowKeys.value = ref([])
    }
  },
  rowSelection: {
    onChange: (selectedRowKey, selectedRows) => {
      selectedRowKeys.value = selectedRowKey
    }
  }
}
const loadData = (parameter) => {
  if (searchFormStateReal.value.travelTime?.length > 0) {
    searchFormStateReal.value.travelTimeStart = proxy.$util.YMDHms(searchFormStateReal.value.travelTime[0])
    searchFormStateReal.value.travelTimeEnd = proxy.$util.YMDHms(searchFormStateReal.value.travelTime[1])
    delete searchFormStateReal.value.travelTime
  }
  if (searchFormStateReal.value.admissionTime?.length > 0) {
    searchFormStateReal.value.admissionTimeStart = proxy.$util.YMDHms(searchFormStateReal.value.admissionTime[0])
    searchFormStateReal.value.admissionTimeEnd = proxy.$util.YMDHms(searchFormStateReal.value.admissionTime[1])
    delete searchFormStateReal.value.admissionTime
  }
  if (searchFormStateReal.value.passTime?.length > 0) {
    searchFormStateReal.value.passTimeStart = proxy.$util.YMDHms(searchFormStateReal.value.passTime[0])
    searchFormStateReal.value.passTimeEnd = proxy.$util.YMDHms(searchFormStateReal.value.passTime[1])
    delete searchFormStateReal.value.passTime
  }
  return basicApi.passengerInfoPage(Object.assign(parameter, searchFormStateReal.value, {queryType: 3})).then((data) => {
    return data
  })
}
// 搜索同时备份参数
const onSearch = (parameter) => {
  searchFormStateReal.value = cloneDeep(searchFormState.value)
  tableRef.value.refresh(parameter)
}
// 重置
const reset = () => {
  searchFormRef.value.resetFields()
  onSearch(true)
}
const sexOptions = tool.dictList('lvke_sex')
const cityOptions = tool.dictList('lvke_city')
const isNoOptions = tool.dictList('lvke_isNo')
const departurePortOptions = tool.dictList('lvke_departurePort')
const arrivingPortOptions = tool.dictList('lvke_arrivingPort')
const checkTypeOptions = tool.dictList('lvke_checkType')
</script>
