HomeLease/pages/lease/lease.vue

692 lines
17 KiB
Vue
Raw Normal View History

2025-08-13 11:43:35 +08:00
<template>
<view class="lease-page">
<!-- 头部区域 -->
2025-08-26 17:14:01 +08:00
<custom-nav-bar
:fill="false"
background-color="#FFDECB"
title="租赁申请"
title-align="center"
/>
2025-08-13 11:43:35 +08:00
<view class="header">
<image
:src="commonEnum.FIRE_BACKGROUND_FULL"
class="fire-background-full"
mode="aspectFill"
></image>
2025-08-13 11:43:35 +08:00
</view>
<!-- 主要内容区域 -->
<view class="main-content">
<!-- 租赁信息表单 -->
<view class="form-section">
<view class="section-header">
<view class="section-indicator"></view>
<text class="section-title">填写租赁信息</text>
</view>
<view class="form-fields">
<!-- 姓名 -->
<view class="form-item">
<text class="field-label">姓名</text>
2025-08-21 09:46:31 +08:00
<input v-model="formData.name" class="field-input" placeholder="请输入姓名" />
2025-08-13 11:43:35 +08:00
</view>
<!-- 手机号 -->
<view class="form-item">
<text class="field-label">手机号</text>
2025-08-13 14:37:35 +08:00
<input
v-model="formData.phone"
class="field-input"
placeholder="请填写手机号"
type="number"
/>
2025-08-13 11:43:35 +08:00
</view>
<!-- 地址 -->
2025-08-19 09:51:32 +08:00
<map-location
v-model="formData.address"
label="地址"
placeholder="请输入或选择收货地址"
2025-08-21 09:46:31 +08:00
@input="onAddressInput"
2025-08-19 09:51:32 +08:00
@location-success="onLocationSuccess"
@location-error="onLocationError"
@use-location="onUseLocation"
@map-opened="onMapOpened"
/>
2025-08-13 11:43:35 +08:00
<!-- 详细位置 -->
<view class="form-item">
<text class="field-label">详细位置</text>
2025-08-21 09:46:31 +08:00
<input
2025-08-21 16:14:36 +08:00
v-model="formData.detailed"
2025-08-21 09:46:31 +08:00
class="field-input"
2025-08-19 11:11:27 +08:00
placeholder="例:6栋201室"
@input="onDetailAddressInput"
/>
2025-08-13 11:43:35 +08:00
</view>
<!-- 租赁设备 -->
<view class="form-item">
<text class="field-label">租赁设备</text>
<view class="selector" @click="selectEquipment">
2025-08-19 10:11:19 +08:00
<text :class="['selector-text', { placeholder: !formData.equipment }]">
{{ formData.equipment || '选择设备类型' }}
</text>
2025-08-13 11:43:35 +08:00
<text class="arrow-icon">></text>
</view>
</view>
<!-- 租赁周期 -->
<view class="form-item">
<text class="field-label">租赁周期</text>
<view class="selector" @click="selectPeriod">
2025-08-19 10:11:19 +08:00
<text :class="['selector-text', { placeholder: !formData.period }]">
{{ formData.period || '请先选择设备类型' }}
</text>
2025-08-13 11:43:35 +08:00
<text class="arrow-icon">></text>
</view>
</view>
</view>
</view>
<!-- 支付区域 -->
<view class="payment-section">
2025-08-21 16:14:36 +08:00
<button :class="['pay-button']" @click="handlePayment">
{{ `立即支付 ¥${totalAmount}` }}
2025-08-19 10:11:19 +08:00
</button>
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
<view class="payment-details">
<view class="details-header" @click="toggleDetails">
<text class="details-title">明细</text>
2025-08-13 15:11:09 +08:00
<view :class="{ expanded: showDetails }" class="arrow-wrapper">
<image :src="commonEnum.DOWN_ARROW" class="details-arrow"></image>
</view>
2025-08-13 11:43:35 +08:00
</view>
2025-08-13 14:37:35 +08:00
<view v-if="showDetails" class="details-content">
2025-08-19 10:11:19 +08:00
<view v-if="selectedDevice" class="detail-item">
<text class="detail-label">设备类型</text>
<text class="detail-value">{{ selectedDevice.name }}</text>
</view>
<view v-if="selectedPackage" class="detail-item">
<text class="detail-label">租赁周期</text>
<text class="detail-value">{{ selectedPackage.name }}</text>
</view>
<view v-if="selectedPackage" class="detail-item">
<text class="detail-label">租赁天数</text>
<text class="detail-value">{{ selectedPackage.day }}</text>
</view>
2025-08-13 11:43:35 +08:00
<view class="detail-item">
<text class="detail-label">租金</text>
<text class="detail-value">¥{{ totalAmount }}</text>
</view>
</view>
</view>
</view>
</view>
<!-- 底部导航已由系统tabBar处理 -->
</view>
</template>
<script>
2025-08-13 14:37:35 +08:00
import commonEnum from '../../enum/commonEnum'
2025-08-19 09:51:32 +08:00
import MapLocation from '@/components/map-location/map-location.vue'
2025-08-19 11:04:01 +08:00
import {
getDeviceTypes as fetchDeviceTypes,
getPeriodPackages as fetchPeriodPackages,
2025-08-21 16:14:36 +08:00
createLeaseOrder,
2025-08-19 11:04:01 +08:00
} from '@/api/lease/lease.js'
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
export default {
name: 'LeasePage',
2025-08-19 09:51:32 +08:00
components: {
2025-08-19 11:04:01 +08:00
MapLocation,
2025-08-19 09:51:32 +08:00
},
2025-08-13 14:37:35 +08:00
computed: {
commonEnum() {
return commonEnum
},
2025-08-19 11:04:01 +08:00
// 检查是否可以支付 - 直接验证不依赖formData默认值
2025-08-13 14:37:35 +08:00
},
2025-08-13 18:06:47 +08:00
onLoad() {
2025-08-19 10:11:19 +08:00
// 页面加载时获取设备类型列表
this.getDeviceTypes()
2025-08-13 18:06:47 +08:00
},
2025-08-13 11:43:35 +08:00
data() {
return {
formData: {
2025-08-19 11:04:01 +08:00
name: '',
2025-08-13 11:43:35 +08:00
phone: '',
address: '',
2025-08-21 16:14:36 +08:00
detailed: '',
2025-08-13 11:43:35 +08:00
equipment: '',
2025-08-21 16:14:36 +08:00
devTypeId: '', // 设备类型ID
2025-08-19 10:11:19 +08:00
period: '',
2025-08-21 16:14:36 +08:00
suitId: '', // 租赁周期ID
2025-08-29 12:00:06 +08:00
channelId: '3', //渠道id
2025-08-21 16:14:36 +08:00
payAmount: 0,
2025-08-13 11:43:35 +08:00
},
showDetails: false,
2025-08-19 10:11:19 +08:00
totalAmount: '0.00',
deviceTypes: [], // 设备类型列表
periodPackages: [], // 租赁周期套餐列表
selectedDevice: null, // 选中的设备
selectedPackage: null, // 选中的套餐
2025-08-13 11:43:35 +08:00
}
},
methods: {
2025-08-19 11:11:27 +08:00
// 地址输入处理
onAddressInput(value) {
this.formData.address = value
},
2025-08-19 09:51:32 +08:00
// 地图组件事件处理
onLocationSuccess(location) {
console.log('位置获取成功:', location)
// 可以在这里处理位置获取成功后的逻辑
2025-08-19 09:31:43 +08:00
},
2025-08-19 09:51:32 +08:00
onLocationError(error) {
console.error('位置获取失败:', error)
// 可以在这里处理位置获取失败后的逻辑
2025-08-13 18:06:47 +08:00
},
2025-08-14 09:44:11 +08:00
2025-08-19 09:51:32 +08:00
onUseLocation(location) {
console.log('使用位置:', location)
// 可以在这里处理使用位置后的逻辑
2025-08-13 11:43:35 +08:00
},
2025-08-14 09:44:11 +08:00
2025-08-19 09:51:32 +08:00
onMapOpened() {
console.log('地图已打开')
// 可以在这里处理地图打开后的逻辑
2025-08-13 11:43:35 +08:00
},
2025-08-19 10:11:19 +08:00
// 获取设备类型列表
async getDeviceTypes() {
try {
const response = await fetchDeviceTypes()
2025-08-19 11:04:01 +08:00
2025-08-19 10:11:19 +08:00
if (response.code === 200) {
this.deviceTypes = response.data
console.log('设备类型列表:', this.deviceTypes)
} else {
throw new Error(response.message || '获取设备类型失败')
}
} catch (error) {
console.error('获取设备类型失败:', error)
uni.showToast({
title: error.message || '获取设备类型失败',
icon: 'error',
})
}
},
// 根据设备类型获取租赁套餐
async getPeriodPackages(typeId) {
try {
const response = await fetchPeriodPackages(typeId)
if (response.code === 200) {
this.periodPackages = response.data
console.log('租赁套餐列表:', this.periodPackages)
} else {
throw new Error(response.message || '获取租赁套餐失败')
}
} catch (error) {
console.error('获取租赁套餐失败:', error)
uni.showToast({
title: error.message || '获取租赁套餐失败',
icon: 'error',
})
}
},
2025-08-13 11:43:35 +08:00
selectEquipment() {
2025-08-19 10:11:19 +08:00
// 检查是否有设备类型数据
if (this.deviceTypes.length === 0) {
uni.showToast({
title: '暂无可租聘设备',
2025-08-19 10:11:19 +08:00
icon: 'none',
})
return
}
// 构建设备类型选项列表
const itemList = this.deviceTypes.map(item => item.name)
2025-08-19 11:04:01 +08:00
2025-08-13 11:43:35 +08:00
uni.showActionSheet({
2025-08-19 10:11:19 +08:00
itemList: itemList,
2025-08-13 14:37:35 +08:00
success: res => {
2025-08-19 10:11:19 +08:00
const selectedDevice = this.deviceTypes[res.tapIndex]
this.selectedDevice = selectedDevice
this.formData.equipment = selectedDevice.name
2025-08-21 16:14:36 +08:00
this.formData.devTypeId = selectedDevice.id
2025-08-19 10:19:46 +08:00
this.formData.equipmentSuitId = selectedDevice.suitId
2025-08-19 11:04:01 +08:00
2025-08-19 10:11:19 +08:00
// 清空之前选择的套餐
this.formData.period = ''
2025-08-21 16:14:36 +08:00
this.formData.suitId = ''
2025-08-19 11:04:01 +08:00
2025-08-19 10:11:19 +08:00
this.selectedPackage = null
this.totalAmount = '0.00'
2025-08-19 11:04:01 +08:00
2025-08-19 10:11:19 +08:00
// 根据选中的设备类型获取租赁套餐
2025-08-19 10:19:46 +08:00
this.getPeriodPackages(selectedDevice.suitId)
2025-08-19 11:04:01 +08:00
2025-08-19 10:11:19 +08:00
console.log('选中设备:', selectedDevice)
2025-08-13 14:37:35 +08:00
},
2025-08-13 11:43:35 +08:00
})
},
selectPeriod() {
2025-08-19 10:11:19 +08:00
// 检查是否已选择设备
2025-08-21 16:14:36 +08:00
if (!this.formData.devTypeId) {
2025-08-19 10:11:19 +08:00
uni.showToast({
title: '请先选择设备类型',
icon: 'none',
})
return
}
// 检查是否有套餐数据
if (this.periodPackages.length === 0) {
uni.showToast({
title: '套餐加载中,请稍后重试',
icon: 'none',
})
return
}
// 构建套餐选项列表
const itemList = this.periodPackages.map(item => `${item.name} ¥${item.amount}`)
2025-08-19 11:04:01 +08:00
2025-08-13 11:43:35 +08:00
uni.showActionSheet({
2025-08-19 10:11:19 +08:00
itemList: itemList,
2025-08-13 14:37:35 +08:00
success: res => {
2025-08-19 10:11:19 +08:00
const selectedPackage = this.periodPackages[res.tapIndex]
this.selectedPackage = selectedPackage
this.formData.period = selectedPackage.name
2025-08-21 16:14:36 +08:00
this.formData.suitId = selectedPackage.id
this.formData.payAmount = selectedPackage.amount
2025-08-19 10:11:19 +08:00
this.totalAmount = selectedPackage.amount.toFixed(2)
console.log('选中套餐:', selectedPackage)
2025-08-21 16:14:36 +08:00
console.log('选中租赁周期id:', this.formData.suitId)
2025-08-13 14:37:35 +08:00
},
2025-08-13 11:43:35 +08:00
})
},
toggleDetails() {
this.showDetails = !this.showDetails
},
handlePayment() {
2025-08-19 10:11:19 +08:00
// 表单验证
if (!this.formData.name.trim()) {
uni.showToast({
title: '请输入姓名',
icon: 'none',
})
return
}
if (!this.formData.phone.trim()) {
uni.showToast({
title: '请输入手机号',
icon: 'none',
})
return
}
if (!this.formData.address.trim()) {
uni.showToast({
title: '请选择地址',
icon: 'none',
})
return
}
2025-08-21 16:14:36 +08:00
if (!this.formData.detailed.trim()) {
uni.showToast({
title: '请输入详细地址',
icon: 'none',
})
return
}
if (!this.formData.devTypeId) {
2025-08-19 10:11:19 +08:00
uni.showToast({
title: '请选择设备类型',
icon: 'none',
})
return
}
2025-08-21 16:14:36 +08:00
if (!this.formData.suitId) {
2025-08-19 10:11:19 +08:00
uni.showToast({
title: '请选择租赁周期',
icon: 'none',
})
return
}
if (parseFloat(this.totalAmount) <= 0) {
uni.showToast({
title: '金额无效',
icon: 'none',
})
return
}
2025-08-13 11:43:35 +08:00
// 支付逻辑
uni.showModal({
title: '确认支付',
2025-08-19 10:11:19 +08:00
content: `确认支付 ¥${this.totalAmount} 吗?\n\n设备${this.formData.equipment}\n周期${this.formData.period}`,
2025-08-21 16:14:36 +08:00
success: async res => {
2025-08-13 11:43:35 +08:00
if (res.confirm) {
2025-08-19 10:11:19 +08:00
// 这里可以调用支付API
2025-08-21 16:14:36 +08:00
const response = await createLeaseOrder(this.formData)
2025-08-29 12:00:06 +08:00
//"17318322273"
2025-08-21 16:14:36 +08:00
if (response.code === 200) {
2025-08-29 12:00:06 +08:00
const data = response.data
console.log(data)
const payParams = {
package: response.data.payParams.packageVal, // 后端返回的字段名
timeStamp: response.data.payParams.timeStamp,
nonceStr: response.data.payParams.nonceStr,
signType: response.data.payParams.signType,
paySign: response.data.payParams.paySign,
}
console.log('支付后端回调数据', payParams)
wx.requestPayment({
...payParams,
success: function (res) {
uni.showToast({
title: '支付成功',
icon: 'success',
2025-08-29 14:50:22 +08:00
duration: 3000,
2025-08-29 12:00:06 +08:00
})
2025-08-29 14:50:22 +08:00
setTimeout(() => {
uni.navigateTo({
url: `/pages/myOrder/orderDetail?id=${data.pay.bstId}`,
})
}, 3000)
2025-08-29 12:00:06 +08:00
},
fail: function (res) {
uni.showToast({
title: '支付失败',
icon: 'fail',
})
},
complete: function (res) {
console.log('微信支付调用结束')
},
2025-08-21 16:14:36 +08:00
})
2025-08-29 12:00:06 +08:00
// uni.showToast({
// title: '支付成功',
// icon: 'success',
// })
2025-08-21 16:14:36 +08:00
} else {
uni.showToast({
title: response.msg || '添加失败',
icon: 'none',
})
}
2025-08-19 10:11:19 +08:00
console.log('支付信息:', {
...this.formData,
amount: this.totalAmount,
selectedDevice: this.selectedDevice,
2025-08-19 11:04:01 +08:00
selectedPackage: this.selectedPackage,
2025-08-19 10:11:19 +08:00
})
2025-08-13 11:43:35 +08:00
}
2025-08-13 14:37:35 +08:00
},
2025-08-13 11:43:35 +08:00
})
},
// 页面跳转现在由系统tabBar处理
goToHome() {
uni.switchTab({
2025-08-13 14:37:35 +08:00
url: '/pages/index/index',
2025-08-13 11:43:35 +08:00
})
},
goToProfile() {
uni.switchTab({
2025-08-13 14:37:35 +08:00
url: '/pages/profile/profile',
2025-08-13 11:43:35 +08:00
})
2025-08-13 14:37:35 +08:00
},
},
2025-08-13 11:43:35 +08:00
}
</script>
<style lang="scss" scoped>
.lease-page {
position: relative;
2025-08-14 09:57:19 +08:00
background: #f3f5f6;
//border: #120d0d solid 2rpx;
2025-08-13 11:43:35 +08:00
}
// 头部区域
.header {
position: relative;
2025-08-13 14:37:35 +08:00
//border: #120d0d solid 2rpx;
background: #fedfcd;
2025-08-14 09:57:19 +08:00
.fire-background-full {
position: relative;
left: 30rpx;
width: 750rpx;
height: 592rpx;
2025-08-13 11:43:35 +08:00
}
}
// 主要内容区域
.main-content {
position: relative;
top: -220rpx;
2025-08-13 14:37:35 +08:00
background: #ffffff;
2025-08-13 11:43:35 +08:00
border-radius: 40rpx 40rpx 0 0;
2025-08-13 14:37:35 +08:00
margin: 0 30rpx;
2025-08-13 11:43:35 +08:00
padding: 40rpx;
min-height: 60vh;
2025-08-13 15:35:49 +08:00
//border: #120d0d solid 2rpx;
2025-08-14 09:57:19 +08:00
//box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.3);
2025-08-13 11:43:35 +08:00
}
// 表单区域
.form-section {
margin-bottom: 60rpx;
2025-08-13 15:35:49 +08:00
//border: #0c1387 solid 2rpx;
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.section-header {
display: flex;
align-items: center;
margin-bottom: 40rpx;
2025-08-13 15:35:49 +08:00
//border: red solid 2rpx;
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.section-indicator {
width: 8rpx;
height: 40rpx;
background: #f15a04;
2025-08-13 11:43:35 +08:00
border-radius: 4rpx;
margin-right: 20rpx;
}
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
}
}
.form-fields {
.form-item {
2025-08-13 15:35:49 +08:00
//margin-bottom: 40rpx;
2025-08-13 14:37:35 +08:00
display: flex;
align-items: center;
border-bottom: 1rpx solid #d8d8d8;
2025-08-13 11:43:35 +08:00
.field-label {
display: block;
font-size: 28rpx;
color: #333;
2025-08-13 14:37:35 +08:00
font-weight: 400;
flex: 1;
2025-08-13 15:35:49 +08:00
//border: 2rpx solid #d81313;
2025-08-13 11:43:35 +08:00
}
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.field-input {
2025-08-25 17:56:17 +08:00
//border: 2rpx solid #d81313;
2025-08-13 14:54:55 +08:00
flex: 3;
2025-08-13 11:43:35 +08:00
height: 80rpx;
2025-08-13 14:54:55 +08:00
padding: 0 20rpx;
2025-08-13 11:43:35 +08:00
font-size: 28rpx;
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
&:focus {
border-color: #ff9a9e;
background: #fff;
}
}
}
}
// 选择器
.selector {
2025-08-13 14:54:55 +08:00
flex: 3;
2025-08-13 11:43:35 +08:00
display: flex;
justify-content: space-between;
align-items: center;
height: 80rpx;
border-radius: 12rpx;
padding: 0 20rpx;
2025-08-13 14:54:55 +08:00
transition: all 0.3s ease;
&:active {
background: #f0f0f0;
border-color: #ff6b6b;
}
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.selector-text {
font-size: 28rpx;
color: #666;
2025-08-19 11:04:01 +08:00
2025-08-19 10:11:19 +08:00
&.placeholder {
color: #999;
}
2025-08-13 11:43:35 +08:00
}
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.arrow-icon {
font-size: 24rpx;
2025-08-13 14:54:55 +08:00
color: #999;
transition: transform 0.3s ease;
}
&:active .arrow-icon {
transform: scale(1.2);
2025-08-13 11:43:35 +08:00
}
}
// 支付区域
.payment-section {
2025-08-13 15:11:09 +08:00
display: flex;
flex-direction: column;
2025-08-13 11:43:35 +08:00
.pay-button {
width: 100%;
2025-08-13 15:26:21 +08:00
height: 100%;
2025-08-13 14:37:35 +08:00
background: #f15a04;
2025-08-13 11:43:35 +08:00
color: #fff;
border: none;
2025-08-13 15:26:21 +08:00
border-radius: 10rpx;
2025-08-13 11:43:35 +08:00
font-size: 32rpx;
font-weight: bold;
margin-bottom: 40rpx;
box-shadow: 0 10rpx 30rpx rgba(255, 154, 158, 0.3);
2025-08-19 10:11:19 +08:00
transition: all 0.3s ease;
&.disabled {
background: #ccc;
color: #999;
box-shadow: none;
}
&:not(.disabled):active {
transform: translateY(2rpx);
box-shadow: 0 8rpx 20rpx rgba(255, 154, 158, 0.4);
}
2025-08-13 11:43:35 +08:00
}
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.payment-details {
.details-header {
display: flex;
align-items: center;
2025-08-13 15:26:21 +08:00
2025-08-13 11:43:35 +08:00
padding: 20rpx 0;
border-bottom: 2rpx solid #f0f0f0;
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.details-title {
font-size: 28rpx;
2025-08-13 15:11:09 +08:00
color: #f15a04;
2025-08-13 15:26:21 +08:00
padding-right: 10rpx;
2025-08-13 11:43:35 +08:00
}
2025-08-13 14:37:35 +08:00
2025-08-13 15:11:09 +08:00
.arrow-wrapper {
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.3s ease;
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
&.expanded {
transform: rotate(180deg);
}
}
2025-08-13 15:11:09 +08:00
.details-arrow {
width: 20rpx;
height: 10rpx;
}
2025-08-13 11:43:35 +08:00
}
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.details-content {
padding: 20rpx 0;
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.detail-item {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.detail-label {
font-size: 28rpx;
2025-08-13 15:26:21 +08:00
color: #868686;
2025-08-13 11:43:35 +08:00
}
2025-08-13 14:37:35 +08:00
2025-08-13 11:43:35 +08:00
.detail-value {
font-size: 28rpx;
2025-08-13 15:26:21 +08:00
color: #3d3d3d;
2025-08-13 11:43:35 +08:00
font-weight: bold;
}
}
}
}
}
// 底部导航样式已移除使用系统tabBar
// 动画
@keyframes pulse {
0% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.1);
opacity: 0.8;
}
100% {
transform: scale(1);
opacity: 1;
}
}
2025-08-13 14:37:35 +08:00
</style>