252 lines
5.8 KiB
JavaScript
252 lines
5.8 KiB
JavaScript
import {
|
|
renewDevice,
|
|
createLeaseOrder,
|
|
getOrderList,
|
|
getOrderDetail,
|
|
cancelOrder,
|
|
confirmReceive,
|
|
applyRefund
|
|
} from '@/api/order/order.js'
|
|
|
|
/**
|
|
* 设备续费示例
|
|
*/
|
|
export async function renewDeviceExample() {
|
|
try {
|
|
const renewData = {
|
|
suitId: "3", // 套餐ID
|
|
appId: "1", // 应用ID
|
|
payAmount: "365", // 支付金额
|
|
channelId: "2", // 渠道ID
|
|
devId: "1" // 设备ID
|
|
}
|
|
|
|
const response = await renewDevice(renewData)
|
|
|
|
if (response.code === 200) {
|
|
console.log('续费成功:', response.data)
|
|
uni.showToast({
|
|
title: '续费成功',
|
|
icon: 'success'
|
|
})
|
|
} else {
|
|
throw new Error(response.message || '续费失败')
|
|
}
|
|
} catch (error) {
|
|
console.error('续费失败:', error)
|
|
uni.showToast({
|
|
title: error.message || '续费失败',
|
|
icon: 'error'
|
|
})
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 创建租赁订单示例
|
|
*/
|
|
export async function createLeaseOrderExample(formData) {
|
|
try {
|
|
const orderData = {
|
|
name: formData.name,
|
|
phone: formData.phone,
|
|
address: formData.address,
|
|
detailAddress: formData.detailAddress,
|
|
equipmentId: formData.equipmentId,
|
|
periodId: formData.periodId,
|
|
amount: formData.amount
|
|
}
|
|
|
|
const response = await createLeaseOrder(orderData)
|
|
|
|
if (response.code === 200) {
|
|
console.log('订单创建成功:', response.data)
|
|
uni.showToast({
|
|
title: '订单创建成功',
|
|
icon: 'success'
|
|
})
|
|
return response.data
|
|
} else {
|
|
throw new Error(response.message || '订单创建失败')
|
|
}
|
|
} catch (error) {
|
|
console.error('订单创建失败:', error)
|
|
uni.showToast({
|
|
title: error.message || '订单创建失败',
|
|
icon: 'error'
|
|
})
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取订单列表示例
|
|
*/
|
|
export async function getOrderListExample() {
|
|
try {
|
|
const params = {
|
|
page: 1,
|
|
size: 10,
|
|
status: 'all' // 可选: pending, paid, shipped, completed, cancelled
|
|
}
|
|
|
|
const response = await getOrderList(params)
|
|
|
|
if (response.code === 200) {
|
|
console.log('订单列表:', response.data)
|
|
return response.data
|
|
} else {
|
|
throw new Error(response.message || '获取订单列表失败')
|
|
}
|
|
} catch (error) {
|
|
console.error('获取订单列表失败:', error)
|
|
uni.showToast({
|
|
title: error.message || '获取订单列表失败',
|
|
icon: 'error'
|
|
})
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取订单详情示例
|
|
*/
|
|
export async function getOrderDetailExample(orderId) {
|
|
try {
|
|
const response = await getOrderDetail(orderId)
|
|
|
|
if (response.code === 200) {
|
|
console.log('订单详情:', response.data)
|
|
return response.data
|
|
} else {
|
|
throw new Error(response.message || '获取订单详情失败')
|
|
}
|
|
} catch (error) {
|
|
console.error('获取订单详情失败:', error)
|
|
uni.showToast({
|
|
title: error.message || '获取订单详情失败',
|
|
icon: 'error'
|
|
})
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 取消订单示例
|
|
*/
|
|
export async function cancelOrderExample(orderId) {
|
|
try {
|
|
const response = await cancelOrder(orderId)
|
|
|
|
if (response.code === 200) {
|
|
console.log('订单取消成功:', response.data)
|
|
uni.showToast({
|
|
title: '订单取消成功',
|
|
icon: 'success'
|
|
})
|
|
return response.data
|
|
} else {
|
|
throw new Error(response.message || '订单取消失败')
|
|
}
|
|
} catch (error) {
|
|
console.error('订单取消失败:', error)
|
|
uni.showToast({
|
|
title: error.message || '订单取消失败',
|
|
icon: 'error'
|
|
})
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 确认收货示例
|
|
*/
|
|
export async function confirmReceiveExample(orderId) {
|
|
try {
|
|
const response = await confirmReceive(orderId)
|
|
|
|
if (response.code === 200) {
|
|
console.log('确认收货成功:', response.data)
|
|
uni.showToast({
|
|
title: '确认收货成功',
|
|
icon: 'success'
|
|
})
|
|
return response.data
|
|
} else {
|
|
throw new Error(response.message || '确认收货失败')
|
|
}
|
|
} catch (error) {
|
|
console.error('确认收货失败:', error)
|
|
uni.showToast({
|
|
title: error.message || '确认收货失败',
|
|
icon: 'error'
|
|
})
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 申请退款示例
|
|
*/
|
|
export async function applyRefundExample(orderId, reason, amount) {
|
|
try {
|
|
const refundData = {
|
|
orderId: orderId,
|
|
reason: reason,
|
|
amount: amount
|
|
}
|
|
|
|
const response = await applyRefund(refundData)
|
|
|
|
if (response.code === 200) {
|
|
console.log('退款申请成功:', response.data)
|
|
uni.showToast({
|
|
title: '退款申请成功',
|
|
icon: 'success'
|
|
})
|
|
return response.data
|
|
} else {
|
|
throw new Error(response.message || '退款申请失败')
|
|
}
|
|
} catch (error) {
|
|
console.error('退款申请失败:', error)
|
|
uni.showToast({
|
|
title: error.message || '退款申请失败',
|
|
icon: 'error'
|
|
})
|
|
throw error
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 在租赁页面中使用API的示例
|
|
*/
|
|
export function useInLeasePage() {
|
|
// 在租赁页面的支付按钮点击事件中调用
|
|
async function handlePayment() {
|
|
try {
|
|
// 1. 创建租赁订单
|
|
const orderResult = await createLeaseOrderExample({
|
|
name: '张三',
|
|
phone: '13800138000',
|
|
address: '北京市朝阳区',
|
|
detailAddress: '某某小区1号楼101室',
|
|
equipmentId: '1',
|
|
periodId: '3',
|
|
amount: '365.00'
|
|
})
|
|
|
|
// 2. 如果订单创建成功,可以进行支付
|
|
if (orderResult) {
|
|
console.log('订单创建成功,订单号:', orderResult.orderId)
|
|
// 这里可以调用支付接口
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('支付流程失败:', error)
|
|
}
|
|
}
|
|
|
|
return {
|
|
handlePayment
|
|
}
|
|
}
|