You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
7.2 KiB

1 year ago
<template>
<view class="container">
1 year ago
<image class="cbg" :src="base.imgHost('common_bg.png')"></image>
1 year ago
<!-- <u-divider>个人信息</u-divider> -->
<view class="wrap">
<applyForm ref="applyForm" @backForm="backForm" :course_forms="course_forms"></applyForm>
</view>
</view>
</template>
<script>
import applyForm from "@/components/applyForm/index.vue"
export default {
components: {
applyForm
},
data() {
return {
course_id: '',
1 year ago
1 year ago
is_fee: 0, //需不需要缴费这个课程
1 year ago
form: {},
apply_form: [],
1 year ago
course_forms: [],
sign_id:'', // 报名的id
opType:'add', // edit 修改
1 year ago
}
},
onReady() {
1 year ago
// this.$refs.uForm.setRules(this.rules);
1 year ago
},
onLoad(options) {
this.course_id = options.id
1 year ago
if (options.type === 'edit') {
this.opType = 'edit'
this.getSignDetail(options.id)
} else {
this.getCourseDetail(options.id)
}
1 year ago
let user = uni.getStorageSync("stbc1_lifeData") ? uni.getStorageSync("stbc1_lifeData").vuex_user : {}
1 year ago
this.form = user
1 year ago
// this.getPosition()
1 year ago
},
methods: {
async getCourseDetail(id) {
const res = await this.$u.api.courseDetail({
course_id: id
})
1 year ago
if (res.course_forms && res.course_forms.length > 0) {
res.course_forms.map(item => {
if (item.belong_user === 1) {
item.value = this.form[item.field]
}
if (item.value === null) {
item.value = ''
}
1 year ago
})
1 year ago
this.course_forms = res.course_forms.sort((a, b) => (a.sort - b.sort))
1 year ago
}
this.is_fee = res.is_fee
1 year ago
},
1 year ago
// 修改
async getSignDetail(id) {
const res = await this.$u.api.courseGetSign({
course_id: id
})
this.sign_id = res.detail.id
if (res.detail.data && res.detail.data.length > 0) {
res.detail.data.map(item => {
if (item.value === null) {
item.value = ''
}
})
this.course_forms = res.detail.data.sort((a, b) => (a.sort - b.sort))
}
},
1 year ago
backForm(e) {
let _arr = []
e.map(item => {
1 year ago
// _arr.push({
// name: item.name,
// field: item.field,
// value: item.value ? item.value : ''
1 year ago
// })
item.value = item.value ? item.value : ''
1 year ago
_arr.push(item)
1 year ago
// 更新扩展字段
1 year ago
if (item.belong_user === 1 && !this.base.isNull(item.value)) {
1 year ago
this.form[item.field] = item.value
1 year ago
}
1 year ago
})
this.apply_form = _arr
1 year ago
console.log("this.apply_form", this.apply_form, this.form)
1 year ago
// return
1 year ago
this.saveUser()
1 year ago
if(this.opType == 'edit'){
this.updateApplyCourse()
}else{
this.applyCourse()
}
1 year ago
// this.$refs.uForm.validate(valid => {
// if (valid) {
1 year ago
1 year ago
// } else {
// console.log('验证失败');
// // this.base.toast("验证失败")
// }
// });
1 year ago
},
1 year ago
async saveUser() {
1 year ago
let that = this
1 year ago
this.form.name = this.form.username
1 year ago
await this.$u.api.saveUser(this.form).then(res => {
console.log("user")
// this.$u.api.user().then(res => {
// this.$u.vuex('vuex_user', res.user)
// })
1 year ago
})
},
1 year ago
async applyCourse() {
1 year ago
let that = this
1 year ago
// let that = this
await this.$u.api.courseSign({
1 year ago
course_id: this.course_id,
data: this.apply_form
}).then(res => {
1 year ago
if (this.is_fee) {
this.newsSubscription()
1 year ago
} else {
that.base.toast("报名已提交", 1500, function() {
setTimeout(function() {
uni.redirectTo({
url: '/packages/mycourse/index'
})
}, 1500)
1 year ago
})
}
1 year ago
})
1 year ago
},
// 更新报名信息
async updateApplyCourse() {
1 year ago
let that = this
1 year ago
this.$u.api.courseUpdateSign({
id: this.sign_id,
data:this.apply_form
}).then(res => {
that.base.toast("修改成功", 1500, function() {
setTimeout(function() {
uni.redirectTo({
url: '/packages/mycourse/index'
1 year ago
})
1 year ago
}, 500)
})
})
},
// 订阅缴费
newsSubscription() {
let that = this
uni.getSetting({
withSubscriptions: true, //是否获取用户订阅消息的订阅状态默认false不返回
success(res) {
console.log("resdfg", res)
if (res.subscriptionsSetting.mainSwitch) {
if (res.subscriptionsSetting.itemSettings && res.subscriptionsSetting.itemSettings[
'6bkRNahvR88pG4Tpk0c2aY81kszvFpdaIV-CdC_ENTM'] === 'accept' &&
res.subscriptionsSetting.itemSettings[
'XsR1BJRdE8JtFUC1o3w7DDcscXkCEGu62J8_smMofZI'] === 'accept'
) {
console.log("accept")
// 用户已经订阅该消息模板,执行相应操作
that.base.toast("报名已提交", 1500, function() {
setTimeout(function() {
uni.redirectTo({
url: '/packages/mycourse/index'
})
}, 1500)
})
} else {
// 用户没有订阅该消息模板,显示订阅弹窗
uni.showModal({
title: '订阅消息',
content: '是否需要订阅预约结果消息',
success(res1) {
if (res1.confirm) {
uni.requestSubscribeMessage({
tmplIds: [
'6bkRNahvR88pG4Tpk0c2aY81kszvFpdaIV-CdC_ENTM',
'XsR1BJRdE8JtFUC1o3w7DDcscXkCEGu62J8_smMofZI',
],
success(res) {
that.base.toast("报名已提交", 1500, function() {
setTimeout(function() {
uni.redirectTo({
url: '/packages/mycourse/index'
})
}, 1500)
})
},
fail(err) {
that.base.toast("报名已提交", 1500, function() {
setTimeout(function() {
uni.redirectTo({
url: '/packages/mycourse/index'
})
}, 1500)
})
}
})
} else {
that.base.toast("报名已提交", 1500, function() {
setTimeout(function() {
uni.redirectTo({
url: '/packages/mycourse/index'
})
}, 1500)
})
}
}
})
}
} else {
console.log("9999")
that.base.toast("报名已提交", 1500, function() {
setTimeout(function() {
uni.redirectTo({
url: '/packages/mycourse/index'
})
}, 1500)
})
// 用户尚未开启订阅消息总开关,建议提醒用户开启
}
}
1 year ago
});
1 year ago
},
}
}
</script>
<style scoped lang="scss">
.container {
padding: 30rpx;
height: 100vh;
.cbg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
}
.wrap {
background-color: #fff;
padding: 20rpx 50rpx;
1 year ago
border-radius: 20rpx;
1 year ago
position: relative;
height: 100%;
overflow: scroll;
1 year ago
}
.form-btn {
width: 100%;
position: fixed;
left: 0;
bottom: 0;
padding: 20rpx 0;
&>view {
1 year ago
width: 70%;
text-align: center;
margin: 0 auto;
color: #fff;
background: linear-gradient(to right, #5e5fbc, #0d0398);
border-radius: 30rpx;
1 year ago
padding: 20rpx;
}
}
}
</style>