|
|
|
@ -57,29 +57,25 @@ |
|
|
|
/> |
|
|
|
</view> |
|
|
|
|
|
|
|
<!-- <view class="form-item">--> |
|
|
|
<!-- <text class="label">课时数</text>--> |
|
|
|
<!-- <input --> |
|
|
|
<!-- class="form-input readonly"--> |
|
|
|
<!-- type="number"--> |
|
|
|
<!-- v-model="formData.total_hours"--> |
|
|
|
<!-- placeholder="请先选择课程"--> |
|
|
|
<!-- readonly--> |
|
|
|
<!-- disabled--> |
|
|
|
<!-- />--> |
|
|
|
<!-- </view>--> |
|
|
|
|
|
|
|
<!-- <view class="form-item">--> |
|
|
|
<!-- <text class="label">赠送课时</text>--> |
|
|
|
<!-- <input --> |
|
|
|
<!-- class="form-input readonly"--> |
|
|
|
<!-- type="number"--> |
|
|
|
<!-- v-model="formData.gift_hours"--> |
|
|
|
<!-- placeholder="请先选择课程"--> |
|
|
|
<!-- readonly--> |
|
|
|
<!-- disabled--> |
|
|
|
<!-- />--> |
|
|
|
<!-- </view>--> |
|
|
|
<view class="form-item" v-if="giftList.length > 0"> |
|
|
|
<text class="label">选择赠品</text> |
|
|
|
<view class="picker-wrapper" @click="showGiftPicker"> |
|
|
|
<text class="picker-text" :class="{ 'placeholder': !formData.gift_id }"> |
|
|
|
{{ selectedGift && selectedGift.label || '请选择赠品(可选)' }} |
|
|
|
</text> |
|
|
|
<text class="picker-arrow">▼</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
|
|
|
|
<view class="form-item" v-if="formData.gift_id"> |
|
|
|
<text class="label">赠品核销类型 <text class="required">*</text></text> |
|
|
|
<view class="picker-wrapper" @click="showGiftTypePicker"> |
|
|
|
<text class="picker-text" :class="{ 'placeholder': !formData.gift_type }"> |
|
|
|
{{ selectedGiftType && selectedGiftType.label || '请选择核销类型' }} |
|
|
|
</text> |
|
|
|
<text class="picker-arrow">▼</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
|
|
|
|
<view class="form-item"> |
|
|
|
<text class="label">备注</text> |
|
|
|
@ -148,6 +144,8 @@ export default { |
|
|
|
order_amount: '', |
|
|
|
total_hours: '', |
|
|
|
gift_hours: '', |
|
|
|
gift_id: '', // 赠品ID |
|
|
|
gift_type: '', // 赠品核销类型:1-减现, 2-赠课 |
|
|
|
remark: '', |
|
|
|
class_id: '1' // 临时设置默认班级ID,后续需要添加班级选择功能 |
|
|
|
}, |
|
|
|
@ -163,11 +161,18 @@ export default { |
|
|
|
courseSelectedIndex: -1, |
|
|
|
paymentSelectedIndex: -1, |
|
|
|
orderTypeSelectedIndex: -1, |
|
|
|
giftSelectedIndex: -1, |
|
|
|
giftTypeSelectedIndex: -1, |
|
|
|
|
|
|
|
// 数据选项 |
|
|
|
courseList: [], |
|
|
|
paymentTypes: [], // 从字典接口获取 |
|
|
|
orderTypes: [] // 从字典接口获取 |
|
|
|
orderTypes: [], // 从字典接口获取 |
|
|
|
giftList: [], // 可用赠品列表 |
|
|
|
giftTypes: [ // 赠品核销类型 |
|
|
|
{ value: '1', label: '减现' }, |
|
|
|
{ value: '2', label: '赠课' } |
|
|
|
] |
|
|
|
} |
|
|
|
}, |
|
|
|
computed: { |
|
|
|
@ -179,6 +184,12 @@ export default { |
|
|
|
}, |
|
|
|
selectedOrderType() { |
|
|
|
return this.orderTypes.find(item => item.value === this.formData.order_type) |
|
|
|
}, |
|
|
|
selectedGift() { |
|
|
|
return this.giftList.find(item => item.value == this.formData.gift_id) |
|
|
|
}, |
|
|
|
selectedGiftType() { |
|
|
|
return this.giftTypes.find(item => item.value === this.formData.gift_type) |
|
|
|
} |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
@ -189,6 +200,7 @@ export default { |
|
|
|
this.initForm() |
|
|
|
this.loadCourseList() |
|
|
|
this.loadDictionaries() // 加载字典数据 |
|
|
|
this.loadGiftList() // 加载可用赠品列表 |
|
|
|
} |
|
|
|
}, |
|
|
|
studentInfo: { |
|
|
|
@ -208,6 +220,7 @@ export default { |
|
|
|
console.log('组件挂载时 visible 为 true,开始加载数据') |
|
|
|
this.loadCourseList() |
|
|
|
this.loadDictionaries() |
|
|
|
this.loadGiftList() |
|
|
|
} |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
@ -220,6 +233,8 @@ export default { |
|
|
|
order_amount: '', |
|
|
|
total_hours: '', |
|
|
|
gift_hours: '', |
|
|
|
gift_id: '', |
|
|
|
gift_type: '', |
|
|
|
remark: '', |
|
|
|
class_id: '1' // 临时设置默认班级ID |
|
|
|
} |
|
|
|
@ -228,6 +243,8 @@ export default { |
|
|
|
this.courseSelectedIndex = -1 |
|
|
|
this.paymentSelectedIndex = -1 |
|
|
|
this.orderTypeSelectedIndex = -1 |
|
|
|
this.giftSelectedIndex = -1 |
|
|
|
this.giftTypeSelectedIndex = -1 |
|
|
|
}, |
|
|
|
|
|
|
|
async loadCourseList() { |
|
|
|
@ -323,6 +340,47 @@ export default { |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 加载可用赠品列表 |
|
|
|
*/ |
|
|
|
async loadGiftList() { |
|
|
|
console.log('开始加载赠品列表,资源ID:', this.resourceId) |
|
|
|
try { |
|
|
|
if (!this.resourceId) { |
|
|
|
console.warn('缺少资源ID,无法加载赠品列表') |
|
|
|
this.giftList = [] |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
const res = await apiRoute.xs_customerResourcesGetGiftRecordList({ |
|
|
|
resource_id: this.resourceId |
|
|
|
}) |
|
|
|
console.log('赠品列表API响应:', res) |
|
|
|
|
|
|
|
if (res.code === 1) { |
|
|
|
// 过滤gift_status=1的可用赠品 |
|
|
|
this.giftList = (res.data || []) |
|
|
|
.filter(gift => gift.gift_status === 1) |
|
|
|
.map(gift => ({ |
|
|
|
value: gift.id, |
|
|
|
label: gift.gift_name, |
|
|
|
gift_type: gift.gift_type, |
|
|
|
gift_type_text: gift.gift_type_text, |
|
|
|
gift_time: gift.gift_time, |
|
|
|
gift_time_formatted: gift.gift_time_formatted, |
|
|
|
giver_name: gift.giver_name |
|
|
|
})) |
|
|
|
console.log('可用赠品列表:', this.giftList) |
|
|
|
} else { |
|
|
|
console.error('获取赠品列表失败:', res.msg) |
|
|
|
this.giftList = [] |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('获取赠品列表异常:', error) |
|
|
|
this.giftList = [] |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
showCoursePicker() { |
|
|
|
this.currentPicker = 'course' |
|
|
|
this.pickerTitle = '选择课程' |
|
|
|
@ -377,6 +435,47 @@ export default { |
|
|
|
this.$refs.pickerPopup.open() |
|
|
|
}, |
|
|
|
|
|
|
|
showGiftPicker() { |
|
|
|
this.currentPicker = 'gift' |
|
|
|
this.pickerTitle = '选择赠品' |
|
|
|
|
|
|
|
// 添加一个"不选择"的选项 |
|
|
|
this.pickerOptions = [ |
|
|
|
{ value: '', label: '不选择赠品' }, |
|
|
|
...this.giftList |
|
|
|
] |
|
|
|
|
|
|
|
// 根据当前选中的赠品设置初始索引 |
|
|
|
if (this.formData.gift_id) { |
|
|
|
const currentIndex = this.pickerOptions.findIndex(item => item.id == this.formData.gift_id) |
|
|
|
this.giftSelectedIndex = currentIndex >= 0 ? currentIndex : 0 |
|
|
|
} else { |
|
|
|
this.giftSelectedIndex = 0 |
|
|
|
} |
|
|
|
|
|
|
|
this.pickerValue = [this.giftSelectedIndex] |
|
|
|
this.selectedIndex = this.giftSelectedIndex |
|
|
|
this.$refs.pickerPopup.open() |
|
|
|
}, |
|
|
|
|
|
|
|
showGiftTypePicker() { |
|
|
|
this.currentPicker = 'giftType' |
|
|
|
this.pickerTitle = '选择核销类型' |
|
|
|
this.pickerOptions = this.giftTypes |
|
|
|
|
|
|
|
// 根据当前选中的核销类型设置初始索引 |
|
|
|
if (this.formData.gift_type) { |
|
|
|
const currentIndex = this.giftTypes.findIndex(item => item.value === this.formData.gift_type) |
|
|
|
this.giftTypeSelectedIndex = currentIndex >= 0 ? currentIndex : 0 |
|
|
|
} else { |
|
|
|
this.giftTypeSelectedIndex = 0 |
|
|
|
} |
|
|
|
|
|
|
|
this.pickerValue = [this.giftTypeSelectedIndex] |
|
|
|
this.selectedIndex = this.giftTypeSelectedIndex |
|
|
|
this.$refs.pickerPopup.open() |
|
|
|
}, |
|
|
|
|
|
|
|
onPickerChange(e) { |
|
|
|
this.selectedIndex = e.detail.value[0] |
|
|
|
}, |
|
|
|
@ -409,6 +508,21 @@ export default { |
|
|
|
this.orderTypeSelectedIndex = this.selectedIndex |
|
|
|
this.formData.order_type = selectedOption.value |
|
|
|
break |
|
|
|
case 'gift': |
|
|
|
this.giftSelectedIndex = this.selectedIndex |
|
|
|
this.formData.gift_id = selectedOption.value |
|
|
|
// 如果选择了"不选择赠品",清空赠品类型 |
|
|
|
if (!selectedOption.id) { |
|
|
|
this.formData.gift_type = '' |
|
|
|
this.giftTypeSelectedIndex = -1 |
|
|
|
} |
|
|
|
console.log('赠品选择后更新表单数据:', this.formData) |
|
|
|
break |
|
|
|
case 'giftType': |
|
|
|
this.giftTypeSelectedIndex = this.selectedIndex |
|
|
|
this.formData.gift_type = selectedOption.value |
|
|
|
console.log('赠品类型选择后更新表单数据:', this.formData) |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
this.closePicker() |
|
|
|
@ -440,6 +554,10 @@ export default { |
|
|
|
uni.showToast({ title: '请输入有效的订单金额', icon: 'none' }) |
|
|
|
return false |
|
|
|
} |
|
|
|
if (this.formData.gift_id && !this.formData.gift_type) { |
|
|
|
uni.showToast({ title: '请选择赠品核销类型', icon: 'none' }) |
|
|
|
return false |
|
|
|
} |
|
|
|
return true |
|
|
|
}, |
|
|
|
|
|
|
|
@ -456,6 +574,14 @@ export default { |
|
|
|
order_status: 'pending' |
|
|
|
} |
|
|
|
|
|
|
|
// 如果没有选择赠品,确保传递空值而不是空字符串 |
|
|
|
if (!orderData.gift_id) { |
|
|
|
orderData.gift_id = null |
|
|
|
orderData.gift_type = null |
|
|
|
} |
|
|
|
|
|
|
|
console.log('准备提交的订单数据:', orderData) |
|
|
|
|
|
|
|
const res = await apiRoute.xs_orderTableAdd(orderData) |
|
|
|
|
|
|
|
if (res.code === 1) { |
|
|
|
|