import request from '@/utils/request' import {httpRequest} from '@/utils/request/axios' const baseUrl = 'https://api.1024api.com/api-interface/app' // api地址 const api = { todoCounts: 'order/todoCounts', list: 'order/list', detail: 'order/detail', express: 'order/express', cancel: 'order/cancel', receipt: 'order/receipt', pay: 'order/pay' } // 当前用户待处理的订单数量 export function todoCounts(param, option) { return request.get(api.todoCounts, param, option) } // 我的订单列表 export function list(param, option) { return request.get(api.list, param, option) } // 订单详情 export function detail(orderId, param) { return request.get(api.detail, { orderId, ...param }) } // 获取物流信息 export function express(orderId, param) { return request.get(api.express, { orderId, ...param }) } // 取消订单 export function cancel(orderId, data) { return request.post(api.cancel, { orderId, ...data }) } // 确认收货 export function receipt(orderId, data) { return request.post(api.receipt, { orderId, ...data }) } // 获取买家地址 export const apiGetAddressList = (data) => { return httpRequest.post( `${baseUrl}/buyer/address/list`, data ); } // 新增或更新买家地址 export const apiInsertOrUpdateAddress = (data) => { return httpRequest.post( `${baseUrl}/buyer/address/insertOrUpdate`, data ); } // 下单 export const apiOrderAdd = (data) => { return httpRequest.post( `${baseUrl}/order/add`, data ); } // 获取订单列表 export const apiGetOrderList = (data) => { return httpRequest.post( `${baseUrl}/order/list`, data ); } // 订单操作 export const apiActionOrder = (url, data) => { url = url.startsWith('/app') ? url.substring(4) : url return httpRequest.post( `${baseUrl}${url}`, data ); } // 获取购物车列表 export const apiGetCartList = (data) => { return httpRequest.post( `${baseUrl}/shipping/cart/list`, data ); } // 删除购物车 export const apiDeleteCart = (data) => { return httpRequest.post( `${baseUrl}/shipping/cart/delete`, data ); } // 获取订单详情 export const apiGetOrderDetail = (data) => { return httpRequest.post( `${baseUrl}/order/detail`, data ); } // 获取订单物流信息 export const apiGetOrderLogistics = (data) => { return httpRequest.post( `${baseUrl}/logistics/query`, data ); } // 我的个人中心获取订单数量 export const apiGetOrderCount = (data) => { return httpRequest.post( `${baseUrl}/order/count`, data ); } // 申请退款 export const apiApplyRefund = (data) => { return httpRequest.post( `${baseUrl}/reverse/add`, data ); } // 申请评价 export const apiApplyComment = (data) => { return httpRequest.post( `${baseUrl}/comment/add`, data ); } // 上传图片(支持批量上传) export const apiUploadFile = (fileList) => { // uni.request不支持FormData和文件上传,需要使用uni.uploadFile // fileList应该是文件对象数组,格式:[{path:'xxx'}] 或 [{tempFilePath:'xxx'}] return new Promise((resolve, reject) => { // 获取用户信息用于添加token let user_info = uni.getStorageSync("user_info") || {}; if (typeof user_info === "string") { try { user_info = JSON.parse(user_info) || {}; } catch (e) { user_info = {}; } } // 批量上传所有文件 const uploadPromises = fileList.map((file, index) => { return new Promise((fileResolve, fileReject) => { const filePath = file.path || file.tempFilePath || file.path || file; if (!filePath) { fileReject({ msg: `第${index + 1}个文件路径无效` }); return; } uni.uploadFile({ url: `${baseUrl}/upload/file`, filePath: filePath, name: 'files', header: { token: user_info.token || '', buyerId: user_info.buyerId || '', flag: user_info.flag || '' }, success: (res) => { try { const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data; if (res.statusCode === 200) { fileResolve(data); } else { fileReject({ code: res.statusCode, msg: data.msg || '上传失败', data }); } } catch (e) { fileReject({ code: res.statusCode, msg: '解析响应数据失败', data: res.data }); } }, fail: (err) => { fileReject({ msg: err.errMsg || '上传失败', err }); } }); }); }); // 等待所有文件上传完成 Promise.all(uploadPromises) .then(results => { resolve(results); }) .catch(err => { reject(err); }); }); }