|
|
|
@ -120,6 +120,7 @@ |
|
|
|
|
|
|
|
<script> |
|
|
|
import apiRoute from '@/api/apiRoute.js' |
|
|
|
import dictUtilSimple from '@/common/dictUtilSimple.js' |
|
|
|
|
|
|
|
export default { |
|
|
|
name: 'OrderFormPopup', |
|
|
|
@ -158,19 +159,15 @@ export default { |
|
|
|
pickerOptions: [], |
|
|
|
selectedIndex: 0, |
|
|
|
|
|
|
|
// 为每个选择器维护独立的索引状态 |
|
|
|
courseSelectedIndex: -1, |
|
|
|
paymentSelectedIndex: -1, |
|
|
|
orderTypeSelectedIndex: -1, |
|
|
|
|
|
|
|
// 数据选项 |
|
|
|
courseList: [], |
|
|
|
paymentTypes: [ |
|
|
|
{ value: 'cash', label: '现金支付' }, |
|
|
|
{ value: 'scan_code', label: '扫码支付' }, |
|
|
|
{ value: 'subscription', label: '订阅支付' }, |
|
|
|
{ value: 'wxpay_online', label: '微信在线代付' } |
|
|
|
], |
|
|
|
orderTypes: [ |
|
|
|
{ value: '1', label: '新订单' }, |
|
|
|
{ value: '2', label: '续费订单' }, |
|
|
|
{ value: '3', label: '内部员工订单' } |
|
|
|
] |
|
|
|
paymentTypes: [], // 从字典接口获取 |
|
|
|
orderTypes: [] // 从字典接口获取 |
|
|
|
} |
|
|
|
}, |
|
|
|
computed: { |
|
|
|
@ -188,9 +185,10 @@ export default { |
|
|
|
visible(newVal) { |
|
|
|
console.log('visible changed:', newVal) |
|
|
|
if (newVal) { |
|
|
|
console.log('开始初始化表单和加载课程列表') |
|
|
|
console.log('开始初始化表单和加载数据') |
|
|
|
this.initForm() |
|
|
|
this.loadCourseList() |
|
|
|
this.loadDictionaries() // 加载字典数据 |
|
|
|
} |
|
|
|
}, |
|
|
|
studentInfo: { |
|
|
|
@ -205,10 +203,11 @@ export default { |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
console.log('OrderFormPopup mounted, visible:', this.visible) |
|
|
|
// 如果组件挂载时 visible 为 true,主动加载课程列表 |
|
|
|
// 如果组件挂载时 visible 为 true,主动加载数据 |
|
|
|
if (this.visible) { |
|
|
|
console.log('组件挂载时 visible 为 true,开始加载课程列表') |
|
|
|
console.log('组件挂载时 visible 为 true,开始加载数据') |
|
|
|
this.loadCourseList() |
|
|
|
this.loadDictionaries() |
|
|
|
} |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
@ -224,6 +223,11 @@ export default { |
|
|
|
remark: '', |
|
|
|
class_id: '1' // 临时设置默认班级ID |
|
|
|
} |
|
|
|
|
|
|
|
// 重置选择器索引状态 |
|
|
|
this.courseSelectedIndex = -1 |
|
|
|
this.paymentSelectedIndex = -1 |
|
|
|
this.orderTypeSelectedIndex = -1 |
|
|
|
}, |
|
|
|
|
|
|
|
async loadCourseList() { |
|
|
|
@ -256,12 +260,84 @@ export default { |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 加载字典数据 - 支付方式和订单类型 |
|
|
|
*/ |
|
|
|
async loadDictionaries() { |
|
|
|
console.log('开始加载字典数据') |
|
|
|
try { |
|
|
|
const dictResult = await dictUtilSimple.getBatchDict(['payment_type', 'order_type']) |
|
|
|
console.log('字典数据获取结果:', dictResult) |
|
|
|
|
|
|
|
// 处理支付方式字典 |
|
|
|
if (dictResult.payment_type && Array.isArray(dictResult.payment_type)) { |
|
|
|
this.paymentTypes = dictResult.payment_type.map(item => ({ |
|
|
|
value: item.value, |
|
|
|
label: item.name |
|
|
|
})) |
|
|
|
console.log('支付方式字典加载成功:', this.paymentTypes) |
|
|
|
} else { |
|
|
|
console.warn('支付方式字典数据格式不正确:', dictResult.payment_type) |
|
|
|
// 使用备用数据 |
|
|
|
this.paymentTypes = [ |
|
|
|
{ value: 'cash', label: '现金支付' }, |
|
|
|
{ value: 'scan_code', label: '扫码支付' }, |
|
|
|
{ value: 'subscription', label: '订阅支付' }, |
|
|
|
{ value: 'wxpay_online', label: '微信在线代付' } |
|
|
|
] |
|
|
|
} |
|
|
|
|
|
|
|
// 处理订单类型字典 |
|
|
|
if (dictResult.order_type && Array.isArray(dictResult.order_type)) { |
|
|
|
this.orderTypes = dictResult.order_type.map(item => ({ |
|
|
|
value: item.value, |
|
|
|
label: item.name |
|
|
|
})) |
|
|
|
console.log('订单类型字典加载成功:', this.orderTypes) |
|
|
|
} else { |
|
|
|
console.warn('订单类型字典数据格式不正确:', dictResult.order_type) |
|
|
|
// 使用备用数据 |
|
|
|
this.orderTypes = [ |
|
|
|
{ value: '1', label: '新订单' }, |
|
|
|
{ value: '2', label: '续费订单' }, |
|
|
|
{ value: '3', label: '内部员工订单' } |
|
|
|
] |
|
|
|
} |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
console.error('加载字典数据失败:', error) |
|
|
|
|
|
|
|
// 使用备用数据 |
|
|
|
this.paymentTypes = [ |
|
|
|
{ value: 'cash', label: '现金支付' }, |
|
|
|
{ value: 'scan_code', label: '扫码支付' }, |
|
|
|
{ value: 'subscription', label: '订阅支付' }, |
|
|
|
{ value: 'wxpay_online', label: '微信在线代付' } |
|
|
|
] |
|
|
|
|
|
|
|
this.orderTypes = [ |
|
|
|
{ value: '1', label: '新订单' }, |
|
|
|
{ value: '2', label: '续费订单' }, |
|
|
|
{ value: '3', label: '内部员工订单' } |
|
|
|
] |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
showCoursePicker() { |
|
|
|
this.currentPicker = 'course' |
|
|
|
this.pickerTitle = '选择课程' |
|
|
|
this.pickerOptions = this.courseList |
|
|
|
this.pickerValue = [0] |
|
|
|
this.selectedIndex = 0 // 重置选择索引 |
|
|
|
|
|
|
|
// 根据当前选中的课程设置初始索引 |
|
|
|
if (this.formData.course_id) { |
|
|
|
const currentIndex = this.courseList.findIndex(item => item.id == this.formData.course_id) |
|
|
|
this.courseSelectedIndex = currentIndex >= 0 ? currentIndex : 0 |
|
|
|
} else { |
|
|
|
this.courseSelectedIndex = 0 |
|
|
|
} |
|
|
|
|
|
|
|
this.pickerValue = [this.courseSelectedIndex] |
|
|
|
this.selectedIndex = this.courseSelectedIndex |
|
|
|
this.$refs.pickerPopup.open() |
|
|
|
}, |
|
|
|
|
|
|
|
@ -269,8 +345,17 @@ export default { |
|
|
|
this.currentPicker = 'payment' |
|
|
|
this.pickerTitle = '选择支付方式' |
|
|
|
this.pickerOptions = this.paymentTypes |
|
|
|
this.pickerValue = [0] |
|
|
|
this.selectedIndex = 0 // 重置选择索引 |
|
|
|
|
|
|
|
// 根据当前选中的支付方式设置初始索引 |
|
|
|
if (this.formData.payment_type) { |
|
|
|
const currentIndex = this.paymentTypes.findIndex(item => item.value === this.formData.payment_type) |
|
|
|
this.paymentSelectedIndex = currentIndex >= 0 ? currentIndex : 0 |
|
|
|
} else { |
|
|
|
this.paymentSelectedIndex = 0 |
|
|
|
} |
|
|
|
|
|
|
|
this.pickerValue = [this.paymentSelectedIndex] |
|
|
|
this.selectedIndex = this.paymentSelectedIndex |
|
|
|
this.$refs.pickerPopup.open() |
|
|
|
}, |
|
|
|
|
|
|
|
@ -278,8 +363,17 @@ export default { |
|
|
|
this.currentPicker = 'orderType' |
|
|
|
this.pickerTitle = '选择订单类型' |
|
|
|
this.pickerOptions = this.orderTypes |
|
|
|
this.pickerValue = [0] |
|
|
|
this.selectedIndex = 0 // 重置选择索引 |
|
|
|
|
|
|
|
// 根据当前选中的订单类型设置初始索引 |
|
|
|
if (this.formData.order_type) { |
|
|
|
const currentIndex = this.orderTypes.findIndex(item => item.value === this.formData.order_type) |
|
|
|
this.orderTypeSelectedIndex = currentIndex >= 0 ? currentIndex : 0 |
|
|
|
} else { |
|
|
|
this.orderTypeSelectedIndex = 0 |
|
|
|
} |
|
|
|
|
|
|
|
this.pickerValue = [this.orderTypeSelectedIndex] |
|
|
|
this.selectedIndex = this.orderTypeSelectedIndex |
|
|
|
this.$refs.pickerPopup.open() |
|
|
|
}, |
|
|
|
|
|
|
|
@ -293,6 +387,7 @@ export default { |
|
|
|
|
|
|
|
switch (this.currentPicker) { |
|
|
|
case 'course': |
|
|
|
this.courseSelectedIndex = this.selectedIndex |
|
|
|
this.formData.course_id = selectedOption.id |
|
|
|
// 自动填充课程相关信息 |
|
|
|
if (selectedOption.price !== undefined) { |
|
|
|
@ -307,9 +402,11 @@ export default { |
|
|
|
console.log('课程选择后更新表单数据:', this.formData) |
|
|
|
break |
|
|
|
case 'payment': |
|
|
|
this.paymentSelectedIndex = this.selectedIndex |
|
|
|
this.formData.payment_type = selectedOption.value |
|
|
|
break |
|
|
|
case 'orderType': |
|
|
|
this.orderTypeSelectedIndex = this.selectedIndex |
|
|
|
this.formData.order_type = selectedOption.value |
|
|
|
break |
|
|
|
} |
|
|
|
|