|
|
|
@ -138,8 +138,12 @@ |
|
|
|
<StudyPlanCard v-if="currentPopup === 'study_plan'" :plan-list="studyPlanList" @edit="openEditStudyPlan" /> |
|
|
|
|
|
|
|
<!-- 订单列表弹窗 --> |
|
|
|
<OrderListCard v-if="currentPopup === 'order_list'" :order-list="orderList" @add-order="openAddOrderDialog" |
|
|
|
@pay-order="handlePayOrder" @view-detail="viewOrderDetail" /> |
|
|
|
<OrderListCard |
|
|
|
v-if="currentPopup === 'order_list'" |
|
|
|
:student-id="currentStudent && currentStudent.id" |
|
|
|
:resource-id="clientInfo.resource_id" |
|
|
|
@payment-success="handlePaymentSuccess" |
|
|
|
/> |
|
|
|
|
|
|
|
<!-- 服务列表弹窗 --> |
|
|
|
<ServiceListCard v-if="currentPopup === 'service_list'" :service-list="serviceList" /> |
|
|
|
@ -170,57 +174,11 @@ |
|
|
|
@confirm="handleStudentEditConfirm" /> |
|
|
|
<StudyPlanPopup ref="studyPlanPopup" :student-id="currentStudent && currentStudent.id" |
|
|
|
@confirm="handleStudyPlanConfirm" /> |
|
|
|
|
|
|
|
<!-- 新增订单弹窗 --> |
|
|
|
<uni-popup ref="orderFormPopup" type="bottom"> |
|
|
|
<OrderFormPopup :visible="showOrderForm" :student-info="currentStudent" |
|
|
|
:resource-id="clientInfo.resource_id" @cancel="closeOrderForm" @confirm="handleOrderFormConfirm" /> |
|
|
|
</uni-popup> |
|
|
|
|
|
|
|
<!-- 二维码支付弹窗 --> |
|
|
|
<uni-popup ref="qrCodePopup" type="center" @close="closeQRCodeModal"> |
|
|
|
<view class="qrcode-payment-modal" v-if="qrCodePaymentData"> |
|
|
|
<!-- 弹窗头部 --> |
|
|
|
<view class="modal-header"> |
|
|
|
<text class="modal-title">扫码支付</text> |
|
|
|
<view class="close-btn" @click="closeQRCodeModal"> |
|
|
|
<text>✕</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
|
|
|
|
<!-- 订单信息 --> |
|
|
|
<view class="order-info"> |
|
|
|
<view class="info-row"> |
|
|
|
<text class="label">订单号:</text> |
|
|
|
<text class="value">{{ qrCodePaymentData.order.order_no }}</text> |
|
|
|
</view> |
|
|
|
<view class="info-row"> |
|
|
|
<text class="label">支付金额:</text> |
|
|
|
<text class="amount">¥{{ qrCodePaymentData.order.total_amount }}</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
|
|
|
|
<!-- 二维码区域 --> |
|
|
|
<view class="qrcode-container"> |
|
|
|
<image v-if="qrCodePaymentData.qrcodeImage" :src="qrCodePaymentData.qrcodeImage" |
|
|
|
class="qrcode-image" mode="aspectFit" /> |
|
|
|
<text v-else class="qrcode-placeholder">二维码加载中...</text> |
|
|
|
<text class="qrcode-tip">请使用微信扫码完成支付</text> |
|
|
|
</view> |
|
|
|
|
|
|
|
<!-- 操作按钮 --> |
|
|
|
<view class="modal-buttons"> |
|
|
|
<view class="btn secondary" @click="closeQRCodeModal">取消支付</view> |
|
|
|
<view class="btn primary" @click="confirmQRCodePayment">发送二维码给客户</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</uni-popup> |
|
|
|
</view> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script> |
|
|
|
import apiRoute from '@/api/apiRoute.js' |
|
|
|
import dictUtilSimple from '@/common/dictUtilSimple.js' |
|
|
|
// 组件导入 |
|
|
|
import ClientInfoCard from '@/components/client-info-card/client-info-card.vue' |
|
|
|
import StudentInfoCard from '@/components/student-info-card/student-info-card.vue' |
|
|
|
@ -234,7 +192,6 @@ |
|
|
|
import CourseInfoCard from '@/components/course-info-card/index.vue' |
|
|
|
import OrderListCard from '@/components/order-list-card/index.vue' |
|
|
|
import ServiceListCard from '@/components/service-list-card/index.vue' |
|
|
|
import OrderFormPopup from '@/components/order-form-popup/index.vue' |
|
|
|
// 编辑弹窗 |
|
|
|
import StudentEditPopup from '@/components/student-edit-popup/student-edit-popup.vue' |
|
|
|
import FitnessRecordPopup from '@/components/fitness-record-popup/fitness-record-popup.vue' |
|
|
|
@ -253,7 +210,6 @@ |
|
|
|
CourseInfoCard, |
|
|
|
OrderListCard, |
|
|
|
ServiceListCard, |
|
|
|
OrderFormPopup, |
|
|
|
StudentEditPopup, |
|
|
|
FitnessRecordPopup, |
|
|
|
StudyPlanPopup |
|
|
|
@ -281,19 +237,8 @@ |
|
|
|
// 底部弹窗相关 |
|
|
|
currentPopup: null, |
|
|
|
studyPlanList: [], |
|
|
|
orderList: [], |
|
|
|
serviceList: [], |
|
|
|
|
|
|
|
// 订单表单弹窗 |
|
|
|
showOrderForm: false, |
|
|
|
|
|
|
|
// 二维码支付弹窗 |
|
|
|
showQRCodeModal: false, |
|
|
|
qrCodePaymentData: null, |
|
|
|
|
|
|
|
// 字典数据 |
|
|
|
paymentTypeDict: [], // 支付方式字典 |
|
|
|
|
|
|
|
// 编辑相关 |
|
|
|
remark_content: '', |
|
|
|
currentRecord: null, |
|
|
|
@ -412,82 +357,8 @@ |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
|
|
|
|
/** |
|
|
|
* 加载字典数据 |
|
|
|
*/ |
|
|
|
async loadDictData() { |
|
|
|
try { |
|
|
|
console.log('开始加载支付方式字典数据') |
|
|
|
const dictResult = await dictUtilSimple.getBatchDict(['payment_type']) |
|
|
|
|
|
|
|
if (dictResult.payment_type && Array.isArray(dictResult.payment_type)) { |
|
|
|
this.paymentTypeDict = dictResult.payment_type |
|
|
|
console.log('支付方式字典加载成功:', this.paymentTypeDict) |
|
|
|
} else { |
|
|
|
console.warn('支付方式字典数据格式不正确:', dictResult.payment_type) |
|
|
|
// 使用备用数据 |
|
|
|
this.paymentTypeDict = [{ |
|
|
|
name: '现金支付', |
|
|
|
value: 'cash' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '扫码支付', |
|
|
|
value: 'scan_code' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '订阅支付', |
|
|
|
value: 'subscription' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '微信在线代付', |
|
|
|
value: 'wxpay_online' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '客户自行付款', |
|
|
|
value: 'client_wxpay' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '定金', |
|
|
|
value: 'deposit' |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('加载支付方式字典失败:', error) |
|
|
|
// 使用备用数据 |
|
|
|
this.paymentTypeDict = [{ |
|
|
|
name: '现金支付', |
|
|
|
value: 'cash' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '扫码支付', |
|
|
|
value: 'scan_code' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '订阅支付', |
|
|
|
value: 'subscription' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '微信在线代付', |
|
|
|
value: 'wxpay_online' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '客户自行付款', |
|
|
|
value: 'client_wxpay' |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '定金', |
|
|
|
value: 'deposit' |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
async init() { |
|
|
|
try { |
|
|
|
// 加载字典数据 |
|
|
|
await this.loadDictData() |
|
|
|
|
|
|
|
await this.getInfo() |
|
|
|
await Promise.all([ |
|
|
|
this.getUserInfo(), |
|
|
|
@ -673,7 +544,7 @@ |
|
|
|
this.currentPopup = 'study_plan' |
|
|
|
break |
|
|
|
case 'order_list': |
|
|
|
await this.getOrderList(student.id) |
|
|
|
// 订单列表由组件内部自动加载,只需打开弹窗 |
|
|
|
this.currentPopup = 'order_list' |
|
|
|
break |
|
|
|
case 'service_list': |
|
|
|
@ -688,7 +559,6 @@ |
|
|
|
this.currentPopup = null |
|
|
|
// 重置相关数据 |
|
|
|
this.studyPlanList = [] |
|
|
|
this.orderList = [] |
|
|
|
this.serviceList = [] |
|
|
|
this.courseInfo = [] |
|
|
|
this.fitnessRecords = [] |
|
|
|
@ -1295,574 +1165,12 @@ |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取订单列表 |
|
|
|
async getOrderList(studentId = null) { |
|
|
|
if (!this.clientInfo?.resource_id) return |
|
|
|
|
|
|
|
try { |
|
|
|
const targetStudentId = studentId || this.currentStudent?.id |
|
|
|
|
|
|
|
// 构建查询参数,优先使用student_id |
|
|
|
const params = {} |
|
|
|
if (targetStudentId) { |
|
|
|
params.student_id = targetStudentId |
|
|
|
} else if (this.clientInfo.resource_id) { |
|
|
|
params.resource_id = this.clientInfo.resource_id |
|
|
|
} else { |
|
|
|
console.warn('缺少查询参数') |
|
|
|
this.orderList = [] |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
const res = await apiRoute.xs_orderTableList(params) |
|
|
|
|
|
|
|
if (res.code === 1) { |
|
|
|
// 处理API返回的数据格式 |
|
|
|
this.orderList = this.processOrderData(res.data?.data || []) |
|
|
|
} else { |
|
|
|
console.error('获取订单列表失败:', res.msg) |
|
|
|
this.orderList = [] |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('获取订单列表异常:', error) |
|
|
|
this.orderList = [] |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 处理订单数据格式,适配前端组件 |
|
|
|
processOrderData(orders) { |
|
|
|
if (!Array.isArray(orders)) return [] |
|
|
|
|
|
|
|
return orders.map(order => ({ |
|
|
|
id: order.id, |
|
|
|
student_id: order.student_id, |
|
|
|
order_no: order.payment_id || `ORD${order.id}`, // 使用payment_id作为订单号 |
|
|
|
product_name: order.course_id_name || '课程', |
|
|
|
total_amount: order.order_amount || '0.00', |
|
|
|
paid_amount: order.order_status === 'paid' ? order.order_amount : '0.00', |
|
|
|
unpaid_amount: order.order_status === 'paid' ? '0.00' : order.order_amount, |
|
|
|
payment_method: this.formatPaymentType(order.payment_type), |
|
|
|
salesperson_name: order.staff_id_name || '未指定', |
|
|
|
course_count: order.total_hours || 0, // 使用课时数 |
|
|
|
status: this.mapOrderStatus(order.order_status), |
|
|
|
create_time: order.created_at, |
|
|
|
// 新增合同相关字段 |
|
|
|
contract_id: order.contract_id, |
|
|
|
contract_sign_id: order.contract_sign_id, |
|
|
|
// 保留原始数据 |
|
|
|
_raw: order |
|
|
|
})) |
|
|
|
}, |
|
|
|
|
|
|
|
// 格式化支付类型 |
|
|
|
formatPaymentType(paymentType) { |
|
|
|
if (!paymentType) return '未知' |
|
|
|
|
|
|
|
// 从字典数据中查找对应的支付方式名称 |
|
|
|
const paymentItem = this.paymentTypeDict.find(item => item.value === paymentType) |
|
|
|
if (paymentItem) { |
|
|
|
return paymentItem.name |
|
|
|
} |
|
|
|
|
|
|
|
// 如果字典数据未加载,使用备用映射 |
|
|
|
const fallbackMap = { |
|
|
|
'cash': '现金支付', |
|
|
|
'scan_code': '扫码支付', |
|
|
|
'subscription': '订阅支付', |
|
|
|
'wxpay_online': '微信在线代付', |
|
|
|
'client_wxpay': '客户自行付款', |
|
|
|
'deposit': '定金' |
|
|
|
} |
|
|
|
return fallbackMap[paymentType] || paymentType || '未知' |
|
|
|
}, |
|
|
|
|
|
|
|
// 映射订单状态 |
|
|
|
mapOrderStatus(orderStatus) { |
|
|
|
const statusMap = { |
|
|
|
'pending': 'pending', |
|
|
|
'paid': 'paid', |
|
|
|
'signed': 'completed', |
|
|
|
'completed': 'completed', |
|
|
|
'transfer': 'partial' |
|
|
|
} |
|
|
|
return statusMap[orderStatus] || 'pending' |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取服务列表 |
|
|
|
async getServiceList(studentId = null) { |
|
|
|
if (!this.clientInfo?.resource_id) return |
|
|
|
const targetStudentId = studentId || this.currentStudent?.id |
|
|
|
|
|
|
|
if (!targetStudentId) { |
|
|
|
uni.showToast({ |
|
|
|
title: '请先选择学生', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
const response = await apiRoute.getStudentServiceList({ |
|
|
|
student_id: targetStudentId |
|
|
|
}) |
|
|
|
|
|
|
|
if (response.code === 1) { |
|
|
|
this.serviceList = response.data || [] |
|
|
|
} else { |
|
|
|
console.error('获取服务记录失败:', response.msg) |
|
|
|
uni.showToast({ |
|
|
|
title: response.msg || '获取服务记录失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
this.serviceList = [] |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('获取服务记录异常:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '网络请求失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
this.serviceList = [] |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 打开新增订单弹窗 |
|
|
|
openAddOrderDialog() { |
|
|
|
if (!this.currentStudent) { |
|
|
|
uni.showToast({ |
|
|
|
title: '请先选择学生', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 先关闭订单列表弹窗,避免遮挡新增订单弹窗 |
|
|
|
this.closePopup() |
|
|
|
|
|
|
|
this.showOrderForm = true |
|
|
|
this.$refs.orderFormPopup.open() |
|
|
|
}, |
|
|
|
|
|
|
|
// 关闭新增订单弹窗 |
|
|
|
closeOrderForm() { |
|
|
|
this.showOrderForm = false |
|
|
|
this.$refs.orderFormPopup.close() |
|
|
|
}, |
|
|
|
|
|
|
|
// 订单表单确认处理 |
|
|
|
async handleOrderFormConfirm() { |
|
|
|
try { |
|
|
|
// 关闽弹窗 |
|
|
|
this.closeOrderForm() |
|
|
|
|
|
|
|
// 刷新订单列表 |
|
|
|
await this.getOrderList() |
|
|
|
|
|
|
|
uni.showToast({ |
|
|
|
title: '订单创建成功', |
|
|
|
icon: 'success' |
|
|
|
}) |
|
|
|
} catch (error) { |
|
|
|
console.error('处理订单确认失败:', error) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 处理订单支付 |
|
|
|
handlePayOrder(order) { |
|
|
|
// 关闭当前弹窗 |
|
|
|
this.closePopup() |
|
|
|
|
|
|
|
// 根据支付类型处理不同的支付流程 |
|
|
|
this.processPayment(order) |
|
|
|
}, |
|
|
|
|
|
|
|
// 处理支付流程 |
|
|
|
async processPayment(order) { |
|
|
|
const paymentType = order._raw?.payment_type || order.payment_type |
|
|
|
console.log('paymentType', paymentType) |
|
|
|
try { |
|
|
|
switch (paymentType) { |
|
|
|
case 'cash': |
|
|
|
// 现金支付 - 直接标记为已支付 |
|
|
|
await this.confirmCashPayment(order) |
|
|
|
break |
|
|
|
case 'scan_code': |
|
|
|
// 扫码支付 - 显示二维码 |
|
|
|
this.showQRCodePayment(order) |
|
|
|
break |
|
|
|
case 'subscription': |
|
|
|
// 订阅支付 - 分期支付流程 |
|
|
|
this.showSubscriptionPayment(order) |
|
|
|
break |
|
|
|
case 'wxpay_online': |
|
|
|
// 微信在线代付 - 调用微信支付 |
|
|
|
this.showWechatPayment(order) |
|
|
|
break |
|
|
|
default: |
|
|
|
uni.showToast({ |
|
|
|
title: '不支持的支付方式', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('支付处理失败:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '支付处理失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 现金支付确认 |
|
|
|
async confirmCashPayment(order) { |
|
|
|
uni.showModal({ |
|
|
|
title: '现金支付确认', |
|
|
|
content: `确认已收到现金支付 ¥${order.total_amount}?`, |
|
|
|
success: async (res) => { |
|
|
|
if (res.confirm) { |
|
|
|
try { |
|
|
|
// 调用API更新订单状态为已支付 |
|
|
|
const updateData = { |
|
|
|
order_id: order._raw?.id || order.id, |
|
|
|
order_status: 'paid', |
|
|
|
payment_id: `CASH${Date.now()}` // 生成现金支付单号 |
|
|
|
} |
|
|
|
|
|
|
|
const result = await apiRoute.xs_orderTableUpdatePaymentStatus(updateData) |
|
|
|
|
|
|
|
if (result.code === 1) { |
|
|
|
uni.showToast({ |
|
|
|
title: '支付确认成功', |
|
|
|
icon: 'success' |
|
|
|
}) |
|
|
|
// 刷新订单列表 |
|
|
|
await this.getOrderList() |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: result.msg || '支付确认失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('现金支付确认失败:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '支付确认失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 扫码支付 |
|
|
|
async showQRCodePayment(order) { |
|
|
|
console.log('扫码支付:', order) |
|
|
|
|
|
|
|
try { |
|
|
|
uni.showLoading({ |
|
|
|
title: '生成支付二维码...' |
|
|
|
}) |
|
|
|
|
|
|
|
// 调用接口获取支付二维码 |
|
|
|
const res = await apiRoute.getOrderPayQrcode({ |
|
|
|
order_id: order._raw?.id || order.id |
|
|
|
}) |
|
|
|
|
|
|
|
uni.hideLoading() |
|
|
|
|
|
|
|
if (res.code === 1 && res.data) { |
|
|
|
// 显示二维码支付弹窗 |
|
|
|
this.openQRCodeModal({ |
|
|
|
order: order, |
|
|
|
qrcode: res.data.code_url, |
|
|
|
// 优先使用base64编码的二维码(解决微信小程序无法访问localhost的问题) |
|
|
|
qrcodeImage: res.data.qrcode_base64 || res.data.qrcode_url |
|
|
|
}) |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: res.msg || '获取支付二维码失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
uni.hideLoading() |
|
|
|
console.error('获取支付二维码失败:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '获取支付二维码失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 打开二维码支付弹窗 |
|
|
|
openQRCodeModal(paymentData) { |
|
|
|
this.qrCodePaymentData = paymentData |
|
|
|
this.showQRCodeModal = true |
|
|
|
this.$refs.qrCodePopup.open() |
|
|
|
}, |
|
|
|
|
|
|
|
// 关闭二维码支付弹窗 |
|
|
|
closeQRCodeModal() { |
|
|
|
this.showQRCodeModal = false |
|
|
|
this.qrCodePaymentData = null |
|
|
|
this.$refs.qrCodePopup.close() |
|
|
|
}, |
|
|
|
|
|
|
|
// 确认二维码支付完成 |
|
|
|
async confirmQRCodePayment() { |
|
|
|
if (!this.qrCodePaymentData?.order) return |
|
|
|
|
|
|
|
const order = this.qrCodePaymentData.order |
|
|
|
|
|
|
|
uni.showModal({ |
|
|
|
title: '支付确认', |
|
|
|
content: '请确认是否已完成扫码支付?', |
|
|
|
success: async (res) => { |
|
|
|
if (res.confirm) { |
|
|
|
try { |
|
|
|
// 更新订单状态为已支付 |
|
|
|
await this.updateOrderStatus(order, 'paid', `QR${Date.now()}`) |
|
|
|
this.closeQRCodeModal() |
|
|
|
} catch (error) { |
|
|
|
console.error('支付确认失败:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '支付确认失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 订阅支付 |
|
|
|
showSubscriptionPayment(order) { |
|
|
|
uni.showActionSheet({ |
|
|
|
itemList: ['确认分期支付方案', '取消支付'], |
|
|
|
success: async (res) => { |
|
|
|
if (res.tapIndex === 0) { |
|
|
|
uni.showModal({ |
|
|
|
title: '分期支付确认', |
|
|
|
content: `确认使用分期支付方式支付 ¥${order.total_amount}?`, |
|
|
|
success: async (modalRes) => { |
|
|
|
if (modalRes.confirm) { |
|
|
|
// 这里可以设置为部分支付状态 |
|
|
|
await this.updateOrderStatus(order, 'partial', |
|
|
|
`SUB${Date.now()}`) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 微信支付 |
|
|
|
showWechatPayment(order) { |
|
|
|
uni.showModal({ |
|
|
|
title: '微信支付', |
|
|
|
content: `将调用微信支付 ¥${order.total_amount}`, |
|
|
|
confirmText: '确认支付', |
|
|
|
cancelText: '取消', |
|
|
|
success: async (res) => { |
|
|
|
if (res.confirm) { |
|
|
|
// 模拟微信支付流程 |
|
|
|
uni.showLoading({ |
|
|
|
title: '正在调用微信支付...' |
|
|
|
}) |
|
|
|
|
|
|
|
// 模拟支付延时 |
|
|
|
setTimeout(async () => { |
|
|
|
uni.hideLoading() |
|
|
|
|
|
|
|
// 模拟支付结果(实际应该调用微信支付API) |
|
|
|
uni.showModal({ |
|
|
|
title: '支付结果', |
|
|
|
content: '微信支付完成,请确认是否已收到款项?', |
|
|
|
success: async (confirmRes) => { |
|
|
|
if (confirmRes.confirm) { |
|
|
|
await this.updateOrderStatus(order, 'paid', |
|
|
|
`WX${Date.now()}`) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, 1500) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 统一的订单状态更新方法 |
|
|
|
async updateOrderStatus(order, status, paymentId = '') { |
|
|
|
try { |
|
|
|
const updateData = { |
|
|
|
order_id: order._raw?.id || order.id, |
|
|
|
order_status: status, |
|
|
|
payment_id: paymentId |
|
|
|
} |
|
|
|
|
|
|
|
const result = await apiRoute.xs_orderTableUpdatePaymentStatus(updateData) |
|
|
|
|
|
|
|
if (result.code === 1) { |
|
|
|
const statusText = { |
|
|
|
'paid': '支付成功', |
|
|
|
'partial': '分期支付确认成功', |
|
|
|
'cancelled': '支付已取消' |
|
|
|
} |
|
|
|
uni.showToast({ |
|
|
|
title: statusText[status] || '状态更新成功', |
|
|
|
icon: 'success' |
|
|
|
}) |
|
|
|
// 刷新订单列表 |
|
|
|
await this.getOrderList() |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: result.msg || '状态更新失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('更新订单状态失败:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '状态更新失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 查看订单详情 |
|
|
|
viewOrderDetail(order) { |
|
|
|
const orderInfo = order._raw || order |
|
|
|
const detailText = ` |
|
|
|
订单号:${order.order_no} |
|
|
|
课程:${order.product_name} |
|
|
|
金额:¥${order.total_amount} |
|
|
|
已付:¥${order.paid_amount} |
|
|
|
未付:¥${order.unpaid_amount} |
|
|
|
支付方式:${order.payment_method} |
|
|
|
销售顾问:${order.salesperson_name} |
|
|
|
课时数:${order.course_count}节 |
|
|
|
状态:${this.getOrderStatusText(order.status)} |
|
|
|
创建时间:${this.formatOrderTime(order.create_time)} |
|
|
|
${orderInfo.paid_at ? '支付时间:' + this.formatOrderTime(orderInfo.paid_at) : ''} |
|
|
|
`.trim() |
|
|
|
|
|
|
|
// 检查是否为已支付订单,显示不同的按钮 |
|
|
|
const isOrderPaid = order.status === 'paid' |
|
|
|
|
|
|
|
const buttons = isOrderPaid ? ['知道了', '合同签署'] : ['知道了'] |
|
|
|
console.log('订单数据', order) |
|
|
|
uni.showModal({ |
|
|
|
title: '订单详情', |
|
|
|
content: detailText, |
|
|
|
showCancel: isOrderPaid, |
|
|
|
cancelText: isOrderPaid ? '知道了' : '', |
|
|
|
confirmText: isOrderPaid ? '合同签署' : '知道了', |
|
|
|
success: (res) => { |
|
|
|
if (res.confirm && isOrderPaid) { |
|
|
|
// 点击了合同签署按钮 |
|
|
|
this.goToContractSign(order) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 跳转到合同签署页面 |
|
|
|
goToContractSign(order) { |
|
|
|
// 检查必要参数 |
|
|
|
const studentId = order.student_id || this.currentStudent?.id |
|
|
|
const contractId = order.contract_id || order._raw?.contract_id |
|
|
|
const contractSignId = order.contract_sign_id || order._raw?.contract_sign_id |
|
|
|
|
|
|
|
if (!studentId) { |
|
|
|
uni.showToast({ |
|
|
|
title: '缺少学生信息', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if (!contractId) { |
|
|
|
// 如果订单中没有合同模板ID,尝试从课程信息获取 |
|
|
|
this.getContractByOrder(order, studentId) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 构建跳转参数 |
|
|
|
let url = |
|
|
|
`/pages-student/contracts/sign?contract_id=${contractId}&student_id=${studentId}&contract_name=${encodeURIComponent(order.product_name + '合同')}&user_role=staff` |
|
|
|
|
|
|
|
// 如果有合同签署记录ID,也传递过去(用于已存在的签署记录) |
|
|
|
if (contractSignId) { |
|
|
|
url += `&contract_sign_id=${contractSignId}` |
|
|
|
} |
|
|
|
|
|
|
|
// 跳转到学员端合同签署页面 |
|
|
|
uni.navigateTo({ |
|
|
|
url: url |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 根据订单获取合同信息 |
|
|
|
async getContractByOrder(order, studentId) { |
|
|
|
try { |
|
|
|
uni.showLoading({ |
|
|
|
title: '获取合同信息...' |
|
|
|
}) |
|
|
|
|
|
|
|
// 调用API获取订单对应的合同 |
|
|
|
const res = await apiRoute.getContractByOrder({ |
|
|
|
order_id: order._raw?.id || order.id, |
|
|
|
student_id: studentId |
|
|
|
}) |
|
|
|
|
|
|
|
uni.hideLoading() |
|
|
|
|
|
|
|
if (res.code === 1 && res.data) { |
|
|
|
const contractInfo = res.data |
|
|
|
// 跳转到合同签署页面 |
|
|
|
uni.navigateTo({ |
|
|
|
url: `/pages-student/contracts/sign?contract_id=${contractInfo.contract_id}&student_id=${studentId}&contract_name=${encodeURIComponent(contractInfo.contract_name || order.product_name + '合同')}&user_role=staff` |
|
|
|
}) |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: res.msg || '未找到相关合同', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
uni.hideLoading() |
|
|
|
console.error('获取合同信息失败:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '获取合同信息失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取订单状态文本 |
|
|
|
getOrderStatusText(status) { |
|
|
|
const statusMap = { |
|
|
|
'pending': '待支付', |
|
|
|
'paid': '已支付', |
|
|
|
'partial': '部分支付', |
|
|
|
'cancelled': '已取消', |
|
|
|
'completed': '已完成', |
|
|
|
'refunded': '已退款' |
|
|
|
} |
|
|
|
return statusMap[status] || '未知状态' |
|
|
|
}, |
|
|
|
|
|
|
|
// 格式化订单时间 |
|
|
|
formatOrderTime(timeStr) { |
|
|
|
if (!timeStr) return '未知' |
|
|
|
try { |
|
|
|
const date = new Date(timeStr) |
|
|
|
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}` |
|
|
|
} catch (e) { |
|
|
|
return timeStr |
|
|
|
} |
|
|
|
/** |
|
|
|
* 订单支付成功回调 |
|
|
|
*/ |
|
|
|
handlePaymentSuccess(order) { |
|
|
|
console.log('订单支付成功:', order) |
|
|
|
// 可以在这里添加支付成功后的业务逻辑,例如刷新其他相关数据 |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取赠品记录列表 |
|
|
|
|