上传订单

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',
method: 'GET',
params: {
typeId: typeId
typeId: typeId,
},
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 = {
// 临时token用于开发测试
TEMP_TOKEN:
'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImE5MGVlZDdmLWYwOTAtNDExMS05ZWMzLTZkMTM2ZjkwODg1NSJ9.s_IYhjbS_tPxJq28I4EN4H3wHLB1BezfJg-Ee4MeaOamx4jMkn376oVXQ24HaKGz4-4t5-ioPndRaOqxDa53JA',
'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImZjMDRiYWQ0LWVjMGQtNDJiMi05NGJkLTQxZGVhMmNmZGE3OCJ9.YyzEJIfPuy2ZrmKRuoWWWHArGxpY9U5kmAM1CFHHrOietHfjWN3rsK0WNxOWTkIDvRiWyAqkTrNwDtWP3ClyQA',
// 是否使用临时token
USE_TEMP_TOKEN: true,

View File

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