上传订单

This commit is contained in:
WindowBird 2025-08-21 16:14:36 +08:00
parent b3c938c0a5
commit 5746c31584
3 changed files with 69 additions and 89 deletions

View File

@ -22,8 +22,33 @@ export function getPeriodPackages(typeId) {
url: '/app/suit/list', url: '/app/suit/list',
method: 'GET', method: 'GET',
params: { params: {
typeId: typeId typeId: typeId,
}, },
loadingText: '加载套餐中...', loadingText: '加载套餐中...',
}) })
} }
/**
* 创建租赁订单
* @param {Object} orderData - 订单数据
* @param {string} orderData.name - 用户姓名
* @param {string} orderData.phone - 手机号
* @param {string} orderData.address - 地址
* @param {string} orderData.lot - 经度
* @param {string} orderData.lat - 纬度
* @param {string} orderData.detailed - 详细地址
* @param {string} orderData.devTypeId - 设备类型ID
* @param {string} orderData.suitId - 套餐ID
* @param {string} orderData.appId - 应用ID
* @param {string} orderData.payAmount - 支付金额
* @param {string} orderData.channelId - 渠道ID
* @returns {Promise} 返回订单创建结果
*/
export function createLeaseOrder(orderData) {
return request({
url: '/app/order',
method: 'POST',
data: orderData,
loadingText: '创建订单中...',
})
}

View File

@ -2,7 +2,7 @@
export const DEV_CONFIG = { export const DEV_CONFIG = {
// 临时token用于开发测试 // 临时token用于开发测试
TEMP_TOKEN: TEMP_TOKEN:
'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImE5MGVlZDdmLWYwOTAtNDExMS05ZWMzLTZkMTM2ZjkwODg1NSJ9.s_IYhjbS_tPxJq28I4EN4H3wHLB1BezfJg-Ee4MeaOamx4jMkn376oVXQ24HaKGz4-4t5-ioPndRaOqxDa53JA', 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImZjMDRiYWQ0LWVjMGQtNDJiMi05NGJkLTQxZGVhMmNmZGE3OCJ9.YyzEJIfPuy2ZrmKRuoWWWHArGxpY9U5kmAM1CFHHrOietHfjWN3rsK0WNxOWTkIDvRiWyAqkTrNwDtWP3ClyQA',
// 是否使用临时token // 是否使用临时token
USE_TEMP_TOKEN: true, USE_TEMP_TOKEN: true,

View File

@ -53,7 +53,7 @@
<view class="form-item"> <view class="form-item">
<text class="field-label">详细位置</text> <text class="field-label">详细位置</text>
<input <input
v-model="formData.detailAddress" v-model="formData.detailed"
class="field-input" class="field-input"
placeholder="例:6栋201室" placeholder="例:6栋201室"
@input="onDetailAddressInput" @input="onDetailAddressInput"
@ -86,12 +86,8 @@
<!-- 支付区域 --> <!-- 支付区域 -->
<view class="payment-section"> <view class="payment-section">
<button <button :class="['pay-button']" @click="handlePayment">
:class="['pay-button', { disabled: !canPay }]" {{ `立即支付 ¥${totalAmount}` }}
:disabled="!canPay"
@click="handlePayment"
>
{{ canPay ? `立即支付 ¥${totalAmount}` : '请完善信息' }}
</button> </button>
<view class="payment-details"> <view class="payment-details">
@ -134,6 +130,7 @@ import MapLocation from '@/components/map-location/map-location.vue'
import { import {
getDeviceTypes as fetchDeviceTypes, getDeviceTypes as fetchDeviceTypes,
getPeriodPackages as fetchPeriodPackages, getPeriodPackages as fetchPeriodPackages,
createLeaseOrder,
} from '@/api/lease/lease.js' } from '@/api/lease/lease.js'
export default { export default {
@ -146,66 +143,6 @@ export default {
return commonEnum return commonEnum
}, },
// - formData // - formData
canPay() {
const nameValid = this.formData.name.trim().length > 0
const phoneValid = this.formData.phone.trim().length > 0
const addressValid = this.formData.address.trim().length > 0
const detailAddressValid = this.formData.detailAddress.trim().length > 0
const equipmentSelected = !!this.formData.equipmentId
const packageSelected = !!this.formData.periodId
const amountValid = parseFloat(this.totalAmount) > 0
const canPayResult =
nameValid &&
phoneValid &&
addressValid &&
detailAddressValid &&
equipmentSelected &&
packageSelected &&
amountValid
//
console.log('🔍 canPay 实时检查:', {
nameValid,
phoneValid,
addressValid: addressValid,
addressValue: `"${this.formData.address}"`,
addressLength: this.formData.address.length,
detailAddressValid: detailAddressValid,
detailAddressValue: `"${this.formData.detailAddress}"`,
detailAddressLength: this.formData.detailAddress.length,
equipmentSelected,
packageSelected,
amountValid,
canPay: canPayResult,
})
return canPayResult
},
},
watch: {
//
'formData.name'() {
console.log('🔍 姓名变化:', this.formData.name)
},
'formData.phone'() {
console.log('🔍 手机号变化:', this.formData.phone)
},
'formData.address'() {
console.log('🔍 地址变化:', this.formData.address)
},
'formData.detailAddress'() {
console.log('🔍 详细位置变化:', this.formData.detailAddress)
},
'formData.equipmentId'() {
console.log('🔍 设备ID变化:', this.formData.equipmentId)
},
'formData.periodId'() {
console.log('🔍 套餐ID变化:', this.formData.periodId)
},
totalAmount() {
console.log('🔍 总金额变化:', this.totalAmount)
},
}, },
onLoad() { onLoad() {
// //
@ -217,11 +154,13 @@ export default {
name: '', name: '',
phone: '', phone: '',
address: '', address: '',
detailAddress: '', detailed: '',
equipment: '', equipment: '',
equipmentId: '', // ID devTypeId: '', // ID
period: '', period: '',
periodId: '', // ID suitId: '', // ID
channelId: '2', //id
payAmount: 0,
}, },
showDetails: false, showDetails: false,
totalAmount: '0.00', totalAmount: '0.00',
@ -234,10 +173,7 @@ export default {
methods: { methods: {
// //
onAddressInput(value) { onAddressInput(value) {
console.log('🔍 地址输入变化:', value)
console.log('🔍 地址输入前 formData.address:', this.formData.address)
this.formData.address = value this.formData.address = value
console.log('🔍 地址输入后 formData.address:', this.formData.address)
}, },
// //
@ -319,12 +255,12 @@ export default {
const selectedDevice = this.deviceTypes[res.tapIndex] const selectedDevice = this.deviceTypes[res.tapIndex]
this.selectedDevice = selectedDevice this.selectedDevice = selectedDevice
this.formData.equipment = selectedDevice.name this.formData.equipment = selectedDevice.name
this.formData.equipmentId = selectedDevice.id this.formData.devTypeId = selectedDevice.id
this.formData.equipmentSuitId = selectedDevice.suitId this.formData.equipmentSuitId = selectedDevice.suitId
// //
this.formData.period = '' this.formData.period = ''
this.formData.periodId = '' this.formData.suitId = ''
this.selectedPackage = null this.selectedPackage = null
this.totalAmount = '0.00' this.totalAmount = '0.00'
@ -338,7 +274,7 @@ export default {
}, },
selectPeriod() { selectPeriod() {
// //
if (!this.formData.equipmentId) { if (!this.formData.devTypeId) {
uni.showToast({ uni.showToast({
title: '请先选择设备类型', title: '请先选择设备类型',
icon: 'none', icon: 'none',
@ -364,10 +300,11 @@ export default {
const selectedPackage = this.periodPackages[res.tapIndex] const selectedPackage = this.periodPackages[res.tapIndex]
this.selectedPackage = selectedPackage this.selectedPackage = selectedPackage
this.formData.period = selectedPackage.name this.formData.period = selectedPackage.name
this.formData.periodId = selectedPackage.id this.formData.suitId = selectedPackage.id
this.formData.payAmount = selectedPackage.amount
this.totalAmount = selectedPackage.amount.toFixed(2) this.totalAmount = selectedPackage.amount.toFixed(2)
console.log('选中套餐:', selectedPackage) console.log('选中套餐:', selectedPackage)
console.log('选中时长:', this.formData.periodId) console.log('选中租赁周期id:', this.formData.suitId)
}, },
}) })
}, },
@ -400,7 +337,15 @@ export default {
return return
} }
if (!this.formData.equipmentId) { if (!this.formData.detailed.trim()) {
uni.showToast({
title: '请输入详细地址',
icon: 'none',
})
return
}
if (!this.formData.devTypeId) {
uni.showToast({ uni.showToast({
title: '请选择设备类型', title: '请选择设备类型',
icon: 'none', icon: 'none',
@ -408,7 +353,7 @@ export default {
return return
} }
if (!this.formData.periodId) { if (!this.formData.suitId) {
uni.showToast({ uni.showToast({
title: '请选择租赁周期', title: '请选择租赁周期',
icon: 'none', icon: 'none',
@ -428,20 +373,30 @@ export default {
uni.showModal({ uni.showModal({
title: '确认支付', title: '确认支付',
content: `确认支付 ¥${this.totalAmount} 吗?\n\n设备${this.formData.equipment}\n周期${this.formData.period}`, content: `确认支付 ¥${this.totalAmount} 吗?\n\n设备${this.formData.equipment}\n周期${this.formData.period}`,
success: res => { success: async res => {
if (res.confirm) { if (res.confirm) {
// API // API
const response = await createLeaseOrder(this.formData)
if (response.code === 200) {
uni.showToast({
title: '支付成功',
icon: 'success',
})
} else {
uni.showToast({
title: response.msg || '添加失败',
icon: 'none',
})
}
console.log('支付信息:', { console.log('支付信息:', {
...this.formData, ...this.formData,
amount: this.totalAmount, amount: this.totalAmount,
selectedDevice: this.selectedDevice, selectedDevice: this.selectedDevice,
selectedPackage: this.selectedPackage, selectedPackage: this.selectedPackage,
}) })
uni.showToast({
title: '支付成功',
icon: 'success',
})
} }
}, },
}) })