diff --git a/api/park.js b/api/park.js new file mode 100644 index 00000000..3906fe5d --- /dev/null +++ b/api/park.js @@ -0,0 +1,20 @@ +export const apiArr = { + carList: '/api/v2/wechat/smart-parking/car/list', // 车辆列表 + carAdd: '/api/v2/wechat/smart-parking/car/add', // 车辆添加 + + monthCardCreate: '/api/v2/wechat/smart-parking/month-card/create', // 月卡订单创建 + monthCardOrderList: '/api/v2/wechat/smart-parking/month-card/order/list', // 包月订单列表 + monthCardOrderPreorder: '/api/v2/wechat/smart-parking/month-card/order/preorder', // 月卡充值预下单 + monthCardOrderQuery: '/api/v2/wechat/smart-parking/month-card/order/trade_query', // 月卡充值订单交易查询 + billingRulesList: '/api/v2/wechat/smart-parking/billing-rules/list', // 月卡计费规则列表 + + tempParkingCreate: '/api/v2/wechat/smart-parking/temp-parking/create', // 临时车缴费订单创建 + tempParkingInfo: '/api/v2/wechat/smart-parking/temp-parking/info', // 临时车缴费信息 + tempParkingOrderDelete: '/api/v2/wechat/smart-parking/temp-parking/order/delete', // 临时车停车订单删除 + tempParkingOrderInfo: '/api/v2/wechat/smart-parking/temp-parking/order/info', // 临时车停车订单信息 + tempParkingOrderList: '/api/v2/wechat/smart-parking/temp-parking/order/list', // 临时车停车订单列表 + tempParkingOrderPreorder: '/api/v2/wechat/smart-parking/temp-parking/preorder', // 临时车缴费订单预下单 + tempParkingOrderQuery: '/api/v2/wechat/smart-parking/temp-parking/trade_query', // 临时车缴费订单交易查询 + + parkList: '/api/v2/wechat/smart-parking/parking/list', // 停车场列表 +} \ No newline at end of file diff --git a/packages/park/addCar/index.vue b/packages/park/addCar/index.vue index a2aaa383..1ff2c2b7 100644 --- a/packages/park/addCar/index.vue +++ b/packages/park/addCar/index.vue @@ -2,7 +2,7 @@ 请输入车牌号码 - + 车牌颜色 @@ -19,13 +19,8 @@ 选择车牌颜色 - + {{ item }} @@ -40,6 +35,15 @@ diff --git a/packages/park/monthlyPayment/index.css b/packages/park/monthlyPayment/index.css index 30e3a42d..12527d3b 100644 --- a/packages/park/monthlyPayment/index.css +++ b/packages/park/monthlyPayment/index.css @@ -292,4 +292,103 @@ page { .order-record-text { font-size: 28rpx; color: #ff3f11; +} + +/* 弹窗通用样式 */ +.car-plate-popup { + padding: 30rpx; + box-sizing: border-box; + background-color: #ffffff; + border-radius: 30rpx 30rpx 0 0; + max-height: 80vh; /* 限制弹窗最大高度 */ +} + +.popup-header { + text-align: center; + margin-bottom: 30rpx; + padding-bottom: 20rpx; + border-bottom: 1rpx solid #f0f0f0; +} + +.popup-title { + font-size: 36rpx; + font-weight: bold; + color: #333333; +} + +.car-plate-list { + max-height: 600rpx; + overflow-y: auto; + padding-right: 10rpx; /* 为滚动条留出空间 */ +} + +/* 美化滚动条样式 */ +.car-plate-list::-webkit-scrollbar { + width: 8rpx; +} + +.car-plate-list::-webkit-scrollbar-track { + background: #f1f1f1; + border-radius: 4rpx; +} + +.car-plate-list::-webkit-scrollbar-thumb { + background: #ccc; + border-radius: 4rpx; +} + +.car-plate-list::-webkit-scrollbar-thumb:hover { + background: #999; +} + +.car-plate-item { + display: flex; + align-items: center; + justify-content: space-between; + padding: 20rpx; + margin-bottom: 20rpx; + background-color: #f5f7fb; + border-radius: 20rpx; + transition: all 0.3s ease; +} + +.car-plate-item.selected { + background-color: #ff431923; + border: 2rpx solid #ff4219; +} + +.plate-number { + font-size: 28rpx; + font-weight: 500; + color: #333333; + flex: 1; + } + + .rule-price { + font-size: 32rpx; + font-weight: bold; + color: #ff4219; + margin-right: 20rpx; + } + +.popup-footer { + margin-top: 30rpx; + padding-top: 20rpx; + border-top: 1rpx solid #f0f0f0; +} + +.close-btn { + width: 100%; + height: 90rpx; + line-height: 90rpx; + background-color: #ff4219; + color: #ffffff; + border: none; + border-radius: 45rpx; + font-size: 32rpx; + font-weight: 500; +} + +.close-btn:active { + background-color: #e03a16; } \ No newline at end of file diff --git a/packages/park/monthlyPayment/index.vue b/packages/park/monthlyPayment/index.vue index ac87732e..7a0623f2 100644 --- a/packages/park/monthlyPayment/index.vue +++ b/packages/park/monthlyPayment/index.vue @@ -19,14 +19,14 @@ - + 剩余车位 - {{ park.remainingSpaces }} + {{ park.space_count }} - {{ park.name }} - {{ park.distance }}km + {{ park.parking_name }} + {{ getParkDistance(park.lng, park.lat) }}km {{ park.address }} @@ -43,9 +43,9 @@ - - 衡水市市民服务中心地下停车场 - 地下 + + {{ headerTitle }} + {{ selectedParkType == 1 ? '地上' : '地下' }} @@ -76,7 +76,7 @@ - + {{ monthPrice + '元/月' }} @@ -105,7 +105,7 @@ - + 开始时间 {{ startTime }} @@ -113,7 +113,7 @@ - + 结束时间 {{ endTime || '--年--月--日' }} @@ -130,6 +130,61 @@ 订单记录>> + + + + + + 选择车牌 + + + + {{ plate.car_number }} + + + + + + + + + + + 计费规则 + + + + {{ rule.billing_rule_name }} + ¥{{ rule.month_price }}/月 + + + + + + + + + + + 选择包月月数 + + + + {{ month.label }} + + + + + @@ -141,60 +196,43 @@ import { upload, NavgateTo } from '../../../utils'; +import { apiArr } from '@/api/park.js' export default { data() { return { // 页面数据 - selectedCarPlate: '鄂FW3337', - monthCount: 8, - startTime: '2025-08-05 00:00:00', + selectedCarPlate: '', + monthCount: '', + startTime: '', endTime: '', paymentAmount: 2400.00, - monthPrice: 300.00, + monthPrice: '', // 下拉列表相关 isDropdownOpen: false, - headerTitle: '衡水市民服务中心地下停车场', - parkingLots: [ - { - id: 1, - name: '衡水市民服务中心地下停车场', - distance: '0.45', - address: '衡水市中心街123号', - remainingSpaces: 124, - isSelected: true - }, - { - id: 2, - name: '衡水市民服务中心地下停车场', - distance: '0.45', - address: '衡水市中心街123号', - remainingSpaces: 124, - isSelected: false - }, - { - id: 3, - name: '衡水市民服务中心地下停车场', - distance: '0.45', - address: '衡水市中心街123号', - remainingSpaces: 124, - isSelected: false - }, - { - id: 4, - name: '衡水市民服务中心地下停车场', - distance: '0.45', - address: '衡水市中心街123号', - remainingSpaces: 124, - isSelected: false - } - ] + headerTitle: '请选择停车场', + selectedParkType: '', + selectedParkId: '',//停车场id + parkingLots: [], + // 选中车牌 + showCarPlatePopup: false, + carPlateList: [], + selectedCarPlateId: '',//选中的车牌id + //计费规则 + billingRulesPopup: false, + billingRulesList: [], + selectedBillingRule: '',// 选中的计费规则 + // 包月月数 + showMonthCountPopup: false, + monthList: Array.from({ length: 12 }, (_, i) => ({ + value: i + 1, + label: (i + 1) + '个月' + })) } }, computed: { - // 计算是否所有必填项都已填写 isAllFilled() { - return this.selectedCarPlate && this.monthCount > 0 && this.startTime; + return this.selectedParkId && this.selectedCarPlateId && this.monthCount > 0 && this.startTime; } }, methods: { @@ -205,61 +243,196 @@ export default { // 选择停车场 selectParkingLot(park) { - // 先取消所有选中状态 + // 取消所有选中状态 this.parkingLots.forEach(item => { item.isSelected = false; }); // 设置当前选中 park.isSelected = true; - // 更新头部标题 - this.$set(this, 'headerTitle', park.name); - // 关闭下拉列表 + this.$set(this, 'headerTitle', park.parking_name); + this.$set(this, 'selectedParkType', park.space_type); + this.selectedParkId = park.id; this.isDropdownOpen = false; }, - // 选择车牌 selectCarPlate() { - console.log('选择车牌'); + this.showCarPlatePopup = true; + }, + + onCloseCarPlatePopup() { + this.showCarPlatePopup = false; + }, + + // 选择车牌 + onSelectCarPlate(plate) { + this.selectedCarPlate = plate.car_number; + this.selectedCarPlateId = plate.id; + this.showCarPlatePopup = false; }, // 显示计费规则 showPriceRule() { - console.log('显示计费规则'); + if (!this.selectedParkId) { + uni.showToast({ + title: '请选择停车场', + icon: 'none' + }) + return; + } + this.getBillingRulesList(); + this.billingRulesPopup = true; + }, + + // 关闭计费规则弹窗 + onCloseBillingRulesPopup() { + this.billingRulesPopup = false; + }, + + // 选择计费规则 + onSelectBillingRule(rule) { + this.selectedBillingRule = rule.billing_rule_name; + this.monthPrice = rule.month_price; + this.paymentAmount = this.monthCount * this.monthPrice; + this.billingRulesPopup = false; }, // 选择包月月数 selectMonthCount() { - console.log('选择包月月数'); + this.showMonthCountPopup = true; }, - // 选择开始时间 - selectStartTime() { - console.log('选择开始时间'); + // 关闭包月月数弹窗 + onCloseMonthCountPopup() { + this.showMonthCountPopup = false; }, - // 选择结束时间 - selectEndTime() { - console.log('选择结束时间'); + // 选择具体月数 + onSelectMonthCount(month) { + this.monthCount = month.value; + + if (this.startTime) { + const startDate = new Date(this.startTime); + // 正确计算结束日期:从开始日期加上指定月数 + const endDate = new Date(startDate); + endDate.setMonth(endDate.getMonth() + this.monthCount); + // 减去一天,确保是完整的月份 + endDate.setDate(endDate.getDate() - 1); + // 设置为最后一天的 23:59:59 + endDate.setHours(23, 59, 59, 999); + // 使用手动构建日期字符串的方式,避免时区问题 + const endYear = endDate.getFullYear(); + const endMonth = String(endDate.getMonth() + 1).padStart(2, '0'); + const endDay = String(endDate.getDate()).padStart(2, '0'); + const endHours = String(endDate.getHours()).padStart(2, '0'); + const endMinutes = String(endDate.getMinutes()).padStart(2, '0'); + const endSeconds = String(endDate.getSeconds()).padStart(2, '0'); + this.endTime = `${endYear}-${endMonth}-${endDay} ${endHours}:${endMinutes}:${endSeconds}`; + } + + this.paymentAmount = this.monthCount * this.monthPrice; + this.showMonthCountPopup = false; }, // 下一步 goToNextStep() { if (!this.isAllFilled) { + uni.showModal({ + title: "提示", + content: "请填写完整信息", + showCancel: false, + }); return; } - NavgateTo('../parkOrderDetail/index'); + // 构建跳转参数 + const params = { + headerTitle: this.headerTitle, + selectedParkType: this.selectedParkType, + selectedParkId: this.selectedParkId, + selectedCarPlateId: this.selectedCarPlateId, + selectedCarPlate: this.selectedCarPlate, + monthPrice: this.monthPrice, + monthCount: this.monthCount, + startTime: this.startTime, + endTime: this.endTime, + paymentAmount: this.paymentAmount, + selectedBillingRule: this.selectedBillingRule, + }; + NavgateTo(`../parkOrderDetail/index?item=${encodeURIComponent(JSON.stringify(params))}`); }, // 查看订单记录 viewOrderRecords() { NavgateTo('../monthlyPaymentOrder/index'); - } + }, + + // 获取停车场列表 + getParkList() { + request(apiArr.parkList, "POST", {}).then((res) => { + this.parkingLots = res.parking_list; + }) + }, + // 获取车牌列表 + getCarPlateList() { + request(apiArr.carList, "POST", {}).then((res) => { + this.carPlateList = res.car_list; + }) + }, + + // 获取计费规则列表 + getBillingRulesList() { + const params = { + parking_id: this.selectedParkId, + } + request(apiArr.billingRulesList, "POST", params).then((res) => { + this.billingRulesList = res.billing_rules_list; + }) + }, + + // 根据经纬度计算距离 + getParkDistance(parkLng, parkLat) { + try { + let locationData = uni.getStorageSync('location'); + if (!locationData) { + return '未知'; + } + + let location= locationData; + + const userLat = location.lat; + const userLng = location.lng; + + // 使用Haversine公式计算距离(单位:千米) + const R = 6371; // 地球半径(千米) + const dLat = (parkLat - userLat) * Math.PI / 180; + const dLng = (parkLng - userLng) * Math.PI / 180; + const a = + Math.sin(dLat / 2) * Math.sin(dLat / 2) + + Math.cos(userLat * Math.PI / 180) * Math.cos(parkLat * Math.PI / 180) * + Math.sin(dLng / 2) * Math.sin(dLng / 2); + const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + const distance = R * c; + + // 保留一位小数 + return distance.toFixed(1); + } catch (error) { + console.error('计算距离时出错:', error); + return '未知'; + } + }, }, onLoad() { - // 页面加载时的初始化逻辑 - console.log('包月支付页面加载'); + // 设置开始时间为今天的 0:00:00 + const today = new Date(); + const year = today.getFullYear(); + const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要+1 + const day = String(today.getDate()).padStart(2, '0'); + // 直接构建格式为 'YYYY-MM-DD HH:mm:ss' 的字符串 + this.startTime = `${year}-${month}-${day} 00:00:00`; + // 初始化支付金额 this.paymentAmount = this.monthCount * this.monthPrice; + this.getParkList(); + this.getCarPlateList(); } } diff --git a/packages/park/monthlyPaymentOrder/index.vue b/packages/park/monthlyPaymentOrder/index.vue index a3685749..241edce1 100644 --- a/packages/park/monthlyPaymentOrder/index.vue +++ b/packages/park/monthlyPaymentOrder/index.vue @@ -9,62 +9,56 @@ - + - 订单编号:{{ order.orderNumber }} - - {{ order.statusText }} + 订单编号:{{ order.order_no }} + + {{ order.order_status == '1' ? '待支付' : order.order_status == '2' ? '使用中' : order.order_status == + '3' ? '已过期' : '' }} 车场名称 - {{ order.parkName }} + {{ order.Parking.parking_name }} 车牌号 - {{ order.carPlate }} + {{ order.community_car.car_number }} 包月月数 - {{ order.monthCount }}个月 + {{ order.month_count }}个月 开始时间 - {{ order.startTime }} + {{ order.start_time }} 到期时间 - {{ order.endTime }} + {{ order.end_time }} 订单金额 - ¥{{ order.amount }} + ¥{{ order.total_amount }} - + - + 付款时间 - {{ order.payTime }} + {{ order.pay_time }} - - + + 支付状态 - + 取消订单 @@ -83,6 +77,7 @@ import { upload, NavgateTo } from '../../../utils'; +import { apiArr } from '@/api/park.js' export default { data() { @@ -106,73 +101,13 @@ export default { }, ], selectedTab: 0, - orders: [ - // 待支付订单 - { - id: 1, - orderNumber: '123456789145', - status: 'pending', - statusText: '待支付', - parkName: '智行光彩生态停车场', - carPlate: '冀T11033', - monthCount: 1, - startTime: '2025-06-04 00:00:00', - endTime: '2025-06-04 23:59:59', - amount: '360.00' - }, - // 使用中订单 - { - id: 2, - orderNumber: '123456789145', - status: 'using', - statusText: '使用中', - parkName: '智行光彩生态停车场', - carPlate: '冀T11033', - monthCount: 1, - startTime: '2025-06-04 00:00:00', - endTime: '2025-06-04 23:59:59', - amount: '360.00', - payTime: '2025-06-04 23:59:59' - }, - // 已过期订单 - { - id: 3, - orderNumber: '123456789145', - status: 'expired', - statusText: '已过期', - parkName: '智行光彩生态停车场', - carPlate: '冀T11033', - monthCount: 1, - startTime: '2025-06-04 00:00:00', - endTime: '2025-06-04 23:59:59', - amount: '360.00', - payTime: '2025-06-04 23:59:59' - } - ] - } - }, - computed: { - // 根据选中的tab过滤订单 - filteredOrders() { - if (this.selectedTab === 0) { - // 全部订单 - return this.orders; - } else if (this.selectedTab === 1) { - // 待支付订单 - return this.orders.filter(order => order.status === 'pending'); - } else if (this.selectedTab === 2) { - // 使用中订单 - return this.orders.filter(order => order.status === 'using'); - } else if (this.selectedTab === 3) { - // 已过期订单 - return this.orders.filter(order => order.status === 'expired'); - } - return this.orders; + orders: [] } }, methods: { selectTab(index, item) { this.selectedTab = index; + this.getOrderList() }, // 取消订单 cancelOrder(order) { @@ -181,8 +116,24 @@ export default { // 去支付 goToPayment(order) { NavgateTo('../parkOrderDetail/index'); + }, + // 获取订单列表 + getOrderList() { + const params = { + user_id: uni.getStorageSync('userId'), + order_status: this.selectedTab, + } + if (params.order_status == 0) { + params.order_status = '' + } + request(apiArr.monthCardOrderList, "POST", params).then(res => { + this.orders = res.month_card_order_list; + }) + }, + onLoad() { + this.getOrderList() } - } + }, } diff --git a/packages/park/orderDetail/index.vue b/packages/park/orderDetail/index.vue index 76bc9417..63ec54c4 100644 --- a/packages/park/orderDetail/index.vue +++ b/packages/park/orderDetail/index.vue @@ -4,7 +4,7 @@ 订单已支付 - 上海公馆停车场 + {{ orderDetail.parking.parking_name }} 实付金额 - ¥{{ orderDetail.actualAmount }} + ¥{{ orderDetail.pay_method }} 订单金额 - ¥{{ orderDetail.orderAmount }} + ¥{{ orderDetail.pay_method }} @@ -34,33 +34,33 @@ 车牌号码 - {{ orderDetail.carNumber }} + {{ orderDetail.parking_record.car_number }} 交易时间 - {{ orderDetail.transactionTime }} + {{ orderDetail.pay_time }} 停车时长 - {{ orderDetail.parkingDuration }} + {{ calculateParkingDuration() }} 订单类型 - {{ orderDetail.orderType }} + 停车 支付方式 - {{ orderDetail.paymentMethod }} + {{ orderDetail.pay_method == 1 ? '微信' : orderDetail.pay_method == 2 ? '支付宝' : '其他' }} 订单号 - {{ orderDetail.orderNumber }} + {{ orderDetail.order_no }} @@ -70,22 +70,22 @@ diff --git a/packages/park/parkOrder/index.vue b/packages/park/parkOrder/index.vue index 5dff6484..d94970f5 100644 --- a/packages/park/parkOrder/index.vue +++ b/packages/park/parkOrder/index.vue @@ -3,8 +3,8 @@ - {{ monthGroup.month }} - 支出¥{{ monthGroup.totalExpense }}元 + {{ monthGroup.pay_time }} + 支出¥{{ monthGroup.amount }}元 @@ -17,20 +17,21 @@ mode="aspectFit"> 停车 - {{ order.statusText }} + {{ order.status == 1 ? '待支付' : '已支付' }} - {{ order.parkName }} + {{ order.parking.parking_name }} ¥{{ order.amount }} - {{ order.carNumber }} - {{ order.carType }} + {{ order.parking_record.car_number }} + {{ order.parking_record.car_billing_type == 1 ? '贵宾车' : + (order.parking_record.car_billing_type == 2) ? '月租车' : '临时车' }} - {{ order.time }} + {{ order.pay_time }} @@ -55,89 +56,99 @@ import { upload, NavgateTo } from '../../../utils'; +import { apiArr } from '@/api/park.js' export default { data() { return { - // 模拟订单数据,实际项目中可能从API获取 - orderData: [ - { - month: '2025年08月', - totalExpense: '16.00', - orders: [ - { - id: 1, - parkName: '上海公馆停车场', - amount: '8.00', - carNumber: '冀TQ2F09', - carType: '临时车', - carTypeClass: 'temporary', - time: '2025-08-04 18:46', - status: 'paid', - statusText: '已支付' - }, - { - id: 2, - parkName: '上海公馆停车场', - amount: '8.00', - carNumber: '冀TQ2F09', - carType: '临时车', - carTypeClass: 'temporary', - time: '2025-08-04 18:46', - status: 'paid', - statusText: '已支付' - } - ] - }, - { - month: '2025年08月', - totalExpense: '16.00', - orders: [ - { - id: 3, - parkName: '上海公馆停车场', - amount: '8.00', - carNumber: '冀TQ2F09', - carType: '月租卡', - carTypeClass: 'monthly', - time: '2025-08-04 18:46', - status: 'paid', - statusText: '已支付' - } - ] - } - ] + orderData: [] } }, methods: { // 查看订单详情 viewOrderDetail(order) { - NavgateTo('../orderDetail/index') + NavgateTo('../orderDetail/index?order=' + JSON.stringify(order)) }, // 删除订单方法 deleteOrder(order) { - console.log("🚀 ~ deleteOrder ~ order:", order) + const that = this; uni.showModal({ title: '确认删除订单', content: '你确定删除订单吗?删除之后你将无法再找回该订单', success: function (res) { if (res.confirm) { - //确认删除 - uni.showToast({ - title: '删除成功', - icon: 'success', - duration: 2000 - }); - } else if (res.cancel) { - // + const params = { + order_id: order.id + } + request(apiArr.tempParkingOrderDelete, "POST", params).then((res) => { + uni.showToast({ + title: '删除成功', + icon: 'success', + duration: 2000 + }); + setTimeout(() => { + that.getOrderData(); + }, 1000); + }) } } }); }, + // 按月份对订单进行分组的方法 + groupOrdersByMonth(orderList) { + const monthMap = new Map(); + + orderList.forEach(order => { + let payTime; + try { + payTime = new Date(order.pay_time); + } catch (error) { + payTime = new Date(order.pay_time.replace(/T/, ' ').replace(/\+.*$/, '')); + } + + // 获取年月作为分组键 + const year = payTime.getFullYear(); + const month = payTime.getMonth() + 1; + const monthKey = `${year}-${month.toString().padStart(2, '0')}`; + + // 如果该月份还没有分组,创建一个新分组 + if (!monthMap.has(monthKey)) { + monthMap.set(monthKey, { + month: monthKey, + pay_time: `${year}年${month}月`, + amount: 0, + orders: [] + }); + } + + // 将当前订单添加到对应月份的分组中 + const monthGroup = monthMap.get(monthKey); + monthGroup.orders.push(order); + monthGroup.amount += parseFloat(order.amount || 0); + }); + + // 将Map转换为数组,并按月份降序排序 + const groupedArray = Array.from(monthMap.values()); + groupedArray.sort((a, b) => b.month.localeCompare(a.month)); + + // 格式化总金额,保留两位小数 + groupedArray.forEach(group => { + group.amount = group.amount.toFixed(2); + }); + + return groupedArray; + }, + // 获取订单数据 getOrderData() { + const params = { + user_id: uni.getStorageSync('userId') + } + request(apiArr.tempParkingOrderList, "POST", params).then((res) => { + this.orderData = this.groupOrdersByMonth(res.order_list); + }) } }, onLoad() { diff --git a/packages/park/parkOrderDetail/index.vue b/packages/park/parkOrderDetail/index.vue index 24ef3010..2994a786 100644 --- a/packages/park/parkOrderDetail/index.vue +++ b/packages/park/parkOrderDetail/index.vue @@ -4,7 +4,7 @@ ¥ - 4704.00 + {{ itemObj.paymentAmount }} 待付款 @@ -15,27 +15,27 @@ 停车场 - 地下 - 衡水市民服务中心地下停车场 + {{ itemObj.selectedParkType == 1 ? '地上' : '地下' }} + {{ itemObj.headerTitle }} 车牌号 - 冀T11855 + {{ itemObj.selectedCarPlate }} 开始时间 - 2025-03-08 00:00:00 + {{ itemObj.startTime }} 结束时间 - 2025-03-08 23:59:59 + {{ itemObj.endTime }} @@ -56,7 +56,7 @@ mode="aspectFit" style="width: 40rpx; height: 40rpx;"> --> + mode="aspectFit" style="width: 30rpx; height: 30rpx;"> @@ -64,7 +64,7 @@ 合计¥ - 4900.00 + {{ itemObj.paymentAmount }} 立即支付 @@ -74,20 +74,101 @@ diff --git a/packages/park/temporaryOrder/index.vue b/packages/park/temporaryOrder/index.vue index 2b77339c..ba81c95f 100644 --- a/packages/park/temporaryOrder/index.vue +++ b/packages/park/temporaryOrder/index.vue @@ -18,14 +18,14 @@ - + 剩余车位 - {{ park.remainingSpaces }} + {{ park.space_count }} - {{ park.name }} - {{ park.distance }}km + {{ park.parking_name }} + {{ getParkDistance(park.lng, park.lat) }}km {{ park.address }} @@ -46,7 +46,7 @@ - {{ car }} + {{ car.car_number }} @@ -67,7 +67,7 @@ - + 立即付款 - - 未找到停车记录 + + 未找到停车记录 @@ -145,46 +145,14 @@ import { upload, NavgateTo } from '../../../utils'; +import { apiArr } from '@/api/park.js' export default { data() { return { isDropdownOpen: false, - headerTitle: '衡水市民服务中心地下停车场', - parkingLots: [ - { - id: 1, - name: '衡水市民服务中心地下停车场', - distance: '0.45', - address: '衡水市中心街123号', - remainingSpaces: 124, - isSelected: true - }, - { - id: 2, - name: '衡水市民服务中心地下停车场', - distance: '0.45', - address: '衡水市中心街123号', - remainingSpaces: 124, - isSelected: false - }, - { - id: 3, - name: '衡水市民服务中心地下停车场', - distance: '0.45', - address: '衡水市中心街123号', - remainingSpaces: 124, - isSelected: false - }, - { - id: 4, - name: '衡水市民服务中心地下停车场', - distance: '0.45', - address: '衡水市中心街123号', - remainingSpaces: 124, - isSelected: false - } - ], + headerTitle: '请选择停车场', + parkingLots: [], defaultNum: '', color: '请选择', @@ -197,16 +165,30 @@ export default { // 车辆选择相关数据 isCarDropdownOpen: false, selectedCar: '', - cars: ['冀A01233', '冀T01234', '其他车辆'], + cars: [], // 停车费相关数据 - showCost: false, + showCost1: false, + showCost2: false, parkingLotName: '上海公馆停车场', costAmount: '280.00', currentCarNumber: '冀T11033', entryTime: '2025-08-05 12:00:00', billingTime: '3天12时37分44秒', - paymentMethod: 'wechat' + paymentMethod: 'wechat', + // 定时器ID,用于清除定时器 + timerId: null + } + }, + onLoad() { + this.getParkList(); + }, + + // 在组件卸载时清除定时器 + onUnload() { + if (this.timerId) { + clearInterval(this.timerId); + this.timerId = null; } }, methods: { @@ -224,7 +206,7 @@ export default { // 设置当前选中 park.isSelected = true; // 更新头部标题 - this.$set(this, 'headerTitle', park.name); + this.$set(this, 'headerTitle', park.parking_name); // 关闭下拉列表 this.isDropdownOpen = false; }, @@ -254,6 +236,34 @@ export default { onClose() { this.show = false; }, + // 更新计费时间 + updateBillingTime() { + const entryDateTime = new Date(this.entryTime); + const currentDateTime = new Date(); + const diff = currentDateTime - entryDateTime; + + // 计算天、时、分、秒 + const days = Math.floor(diff / (1000 * 60 * 60 * 24)); + const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); + const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); + const seconds = Math.floor((diff % (1000 * 60)) / 1000); + + // 格式化时间显示 + let timeStr = ''; + if (days > 0) { + timeStr += days + '天'; + } + if (hours > 0 || days > 0) { + timeStr += hours + '时'; + } + if (minutes > 0 || hours > 0 || days > 0) { + timeStr += minutes + '分'; + } + timeStr += seconds + '秒'; + + this.billingTime = timeStr; + }, + // 选择颜色 selectColor(index) { this.selectedColorIndex = index; @@ -265,8 +275,6 @@ export default { } this.show = false; }, - onLoad() { - }, // 切换车辆下拉列表显示状态 toggleCarDropdown() { @@ -275,17 +283,65 @@ export default { // 选择车辆 selectCar(car) { - this.selectedCar = car; + this.selectedCar = car.car_number; this.isCarDropdownOpen = false; - if (car == '其他车辆') { + if (car.car_number == '其他车辆') { NavgateTo('../addCar/index') } - this.numberInputResult(car) + this.numberInputResult(car.car_number) }, // 查询停车费 selectCost() { - this.showCost = true; + const selectedParkingLot = this.parkingLots.find(park => park.isSelected); + if (!selectedParkingLot) { + uni.showToast({ + title: '请先选择停车场', + icon: 'none' + }); + return; + } + if (!this.defaultNum) { + uni.showToast({ + title: '请输入车牌号', + icon: 'none' + }); + return; + } + const params = { + parking_id: selectedParkingLot.id, + car_number: this.defaultNum, + } + request(apiArr.tempParkingInfo, "POST", params).then((res) => { + if (res) { + this.parkingLotName = res.parking.parking_name; + this.costAmount = res.fee_amount; + this.currentCarNumber = res.car_number; + this.entryTime = res.in_time; + // 清除之前可能存在的定时器 + if (this.timerId) { + clearInterval(this.timerId); + this.timerId = null; + } + + if (res.car_billing_type == 1) { + this.billingTime = '免费车'; + } else if (res.car_billing_type == 2) { + this.billingTime = '月租车'; + } else { + // 计算并实时更新进场时间到现在的时长 + this.updateBillingTime(); + // 设置定时器,每秒更新一次 + this.timerId = setInterval(() => { + this.updateBillingTime(); + }, 1000); + } + + this.showCost1 = true; + } else { + this.showCost2 = true; + } + }) }, // 选择支付方式 @@ -295,10 +351,128 @@ export default { // 确认付款 confirmPayment() { - console.log('确认付款', this.paymentMethod); - // 这里可以添加实际的支付逻辑 - // 例如调用支付API等 + const selectedParkingLot = this.parkingLots.find(park => park.isSelected); + const params = { + car_number: this.defaultNum, + parking_id: selectedParkingLot.id, + user_id: uni.getStorageSync('userId'), + } + request(apiArr.tempParkingCreate, "POST", params).then((resVal) => { + // 根据平台设置不同的trans_type值 + // 小程序: 71, App: 51 + const systemInfo = uni.getSystemInfoSync(); + let trans_type = 51; // 默认App环境 + + // 运行时判断是否为小程序环境 + if (systemInfo.platform === 'devtools' || systemInfo.platform === 'unknown') { + trans_type = 71; // 开发工具或未知环境默认为小程序 + } + + // 条件编译:针对不同平台设置不同值 + // #ifdef MP + trans_type = 71; // 所有小程序平台 + // #endif + + // #ifdef APP-PLUS + trans_type = 51; // App平台 + // #endif + + const param = { + order_id: resVal.order_id, + user_id: uni.getStorageSync('userId'), + trans_type: trans_type + } + request(apiArr.tempParkingOrderPreorder, "POST", param).then(res => { + if (res && res.timeStamp && res.nonceStr && res.package && res.signType && res.paySign) { + // 调用微信支付 + uni.requestPayment({ + timeStamp: res.timeStamp, + nonceStr: res.nonceStr, + package: res.package, + signType: res.signType, + paySign: res.paySign, + success: (payRes) => { + const params = { + order_id: resVal.order_id, + } + request(apiArr.tempParkingOrderQuery, "POST", params).then(res => { + this.boxshadow1 = true + }) + + }, + fail: (payErr) => { + console.log("支付失败", payErr) + uni.showToast({ + title: payErr.errMsg || '支付失败', + icon: 'none' + }) + }, + complete: () => { + // 支付完成后的回调,无论成功失败都会执行 + } + }) + } else { + console.error("获取支付参数失败,缺少必要参数") + uni.showToast({ + title: '获取支付信息失败', + icon: 'none' + }) + } + }) + }) }, + // 获取车辆列表 + getCarList() { + const params = { + user_id: uni.getStorageSync('userId') + } + request(apiArr.carList, "POST", params).then((res) => { + this.cars = res.car_list; + this.cars.push({ + car_number: '其他车辆' + }) + }) + }, + // 获取停车场列表 + getParkList() { + request(apiArr.parkList, "POST", {}).then((res) => { + this.parkingLots = res.parking_list; + }) + }, + // 根据经纬度计算距离 + getParkDistance(parkLng, parkLat) { + try { + let locationData = uni.getStorageSync('location'); + if (!locationData) { + return '未知'; + } + + let location = locationData; + + const userLat = location.lat; + const userLng = location.lng; + + // 使用Haversine公式计算距离(单位:千米) + const R = 6371; // 地球半径(千米) + const dLat = (parkLat - userLat) * Math.PI / 180; + const dLng = (parkLng - userLng) * Math.PI / 180; + const a = + Math.sin(dLat / 2) * Math.sin(dLat / 2) + + Math.cos(userLat * Math.PI / 180) * Math.cos(parkLat * Math.PI / 180) * + Math.sin(dLng / 2) * Math.sin(dLng / 2); + const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + const distance = R * c; + + // 保留一位小数 + return distance.toFixed(1); + } catch (error) { + console.error('计算距离时出错:', error); + return '未知'; + } + }, + }, + onShow() { + this.getCarList(); } } diff --git a/packages/shop/groupPurchaseSubmit/index.css b/packages/shop/groupPurchaseSubmit/index.css index c71a67a1..c9cca426 100644 --- a/packages/shop/groupPurchaseSubmit/index.css +++ b/packages/shop/groupPurchaseSubmit/index.css @@ -431,6 +431,15 @@ page { margin-top: 30rpx; } +.shadowBox1Item_btn{ + width: 110rpx; + height: 150rpx; + border: 1rpx solid red; + position: absolute; + left: 50rpx; + opacity:0; +} + .shadowBox1Item { flex: 1; display: flex; diff --git a/packages/shop/groupPurchaseSubmit/index.vue b/packages/shop/groupPurchaseSubmit/index.vue index f0c3d640..c57f42d4 100644 --- a/packages/shop/groupPurchaseSubmit/index.vue +++ b/packages/shop/groupPurchaseSubmit/index.vue @@ -43,7 +43,7 @@ ¥{{ item.commodity_goods_info.sales_price }}/{{ item.commodity_goods_info.goods_unit - }} + }} 运费 ¥{{ item.commodity_goods_info.freight }} @@ -240,6 +240,7 @@ +