|
|
|
@ -2,35 +2,69 @@ import { ref } from 'vue' |
|
|
|
import { getFindCar } from '@/http/api/parking' |
|
|
|
import { HTTP_CODE } from '@/enums' |
|
|
|
import { isLicensePlate } from '@/utils/utils' |
|
|
|
import { useRootStore } from '@/store/root' |
|
|
|
import { useRouter } from 'vue-router' |
|
|
|
import Message from '@/base/Message/Message' |
|
|
|
|
|
|
|
export const useFindCar = () => { |
|
|
|
const showCarDetail = ref(false) |
|
|
|
const loading = ref(false) |
|
|
|
const result = ref<CarInfo>() |
|
|
|
async function confirm(plate: string) { |
|
|
|
if (!isLicensePlate(plate)) { |
|
|
|
Message({ text: '车牌错误,请重新输入', type: 'success' }) |
|
|
|
return |
|
|
|
} |
|
|
|
if (loading.value) { |
|
|
|
return |
|
|
|
} |
|
|
|
try { |
|
|
|
loading.value = true |
|
|
|
const { code, msg, data } = await getFindCar(plate) |
|
|
|
if (code === HTTP_CODE.ERR_OK) { |
|
|
|
result.value = data |
|
|
|
showCarDetail.value = true |
|
|
|
const store = useRootStore() |
|
|
|
const router = useRouter() |
|
|
|
async function confirm(plate: string, type: number) { |
|
|
|
if (!type) { |
|
|
|
if (!isLicensePlate(plate)) { |
|
|
|
Message({ text: '车牌错误,请重新输入', type: 'success' }) |
|
|
|
return |
|
|
|
} |
|
|
|
if (loading.value) { |
|
|
|
return |
|
|
|
} |
|
|
|
try { |
|
|
|
loading.value = true |
|
|
|
const { code, msg, data } = await getFindCar(plate) |
|
|
|
if (code === HTTP_CODE.ERR_OK) { |
|
|
|
result.value = { ...data, carCode: plate, parkingTime: toHoursAndMinutes(Number(data.parkingTime)) } |
|
|
|
showCarDetail.value = true |
|
|
|
} else { |
|
|
|
Message({ text: msg, type: 'success' }) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
Message({ text: error as string, type: 'success' }) |
|
|
|
} finally { |
|
|
|
loading.value = false |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (!plate.length) { |
|
|
|
Message({ type: 'success', text: '请输入正确的车位号' }) |
|
|
|
return |
|
|
|
} |
|
|
|
const info = window.Map_QM.pathPark({ shopNum: plate }) |
|
|
|
|
|
|
|
if (info?.node?.length) { |
|
|
|
const floor: any = store.buildingList[0].floorList.find(item => item.floorOrder === info.floor)?.floor |
|
|
|
const shop = { |
|
|
|
shopCode: '', |
|
|
|
shopName: plate, |
|
|
|
floorOrder: info.floor, |
|
|
|
floor, |
|
|
|
logoUrl: '/static/img/tcjf.png', |
|
|
|
yaxis: info.node |
|
|
|
} |
|
|
|
store.SET_SHOP(shop) |
|
|
|
router.push('/nav') |
|
|
|
} else { |
|
|
|
Message({ text: msg, type: 'success' }) |
|
|
|
Message({ text: `暂未查到相关信息`, type: 'success' }) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
Message({ text: error as string, type: 'success' }) |
|
|
|
} finally { |
|
|
|
loading.value = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 格式化停车时间
|
|
|
|
function toHoursAndMinutes(totalMinutes: number) { |
|
|
|
const hours = Math.floor(totalMinutes / 60) |
|
|
|
const minutes = totalMinutes % 60 |
|
|
|
return `${hours > 0 ? `${hours}小时` : ''}${minutes > 0 ? ` ${minutes}分钟` : ''}` |
|
|
|
} |
|
|
|
return { loading, result, showCarDetail, confirm } |
|
|
|
} |
|
|
|
|