123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- const app = getApp()
- import WxValidate from '../../../utils/wxValidate';
- Page({
- data: {
- frameStyle: { useTop: true, name: '信息维护', leftArrow: true, useBar: false },
- // 教练和学校的关系
- schoolInfo: {},
- form: {},
- statusList: []
- },
- initValidate() {
- const rules = { title: { required: true }, start_date: { required: true }, start_time: { required: true }, end_date: { required: true }, end_time: { required: true }, brief: { required: true }, money: { required: true }, limit: { required: true }, refund_date: { required: false }, refund_time: { required: false } }
- // 验证字段的提示信息,若不传则调用默认的信息
- const messages = { title: { required: '课程标题' }, start_date: { required: '课程开始日期' }, start_time: { required: '课程开始时间' }, end_date: { required: '课程结束日期' }, end_time: { required: '课程结束时间' }, brief: { required: '请输入课程简介' }, money: { required: '报名费用' }, limit: { required: '人数限制' }, refund_date: { required: '退款期限日期' }, refund_time: { required: '退款期限时间' } };
- this.WxValidate = new WxValidate(rules, messages)
- },
- // 返回
- back: function () {
- wx.navigateBack({ delta: 1 })
- },
- // 课程开始日期
- startdChange: function (e) {
- const that = this;
- that.setData({ 'form.start_date': e.detail.value })
- },
- // 课程开始时间
- starttChange: function (e) {
- const that = this;
- that.setData({ 'form.start_time': e.detail.value })
- },
- // 课程结束日期
- enddChange: function (e) {
- const that = this;
- that.setData({ 'form.end_date': e.detail.value })
- },
- // 课程结束时间
- endtChange: function (e) {
- const that = this;
- that.setData({ 'form.end_time': e.detail.value })
- },
- // 退款期限日期
- refunddChange: function (e) {
- const that = this;
- that.setData({ 'form.refund_date': e.detail.value })
- },
- // 退款期限时间
- refundtChange: function (e) {
- const that = this;
- that.setData({ 'form.refund_time': e.detail.value })
- },
- // 选择状态
- statusChange: function (e) {
- const that = this;
- let data = that.data.statusList[e.detail.value];
- if (data) {
- that.setData({ 'form.status': data.value })
- that.setData({ 'form.zhStatus': data.label })
- }
- },
- //提交
- onSubmit: async function (e) {
- const that = this;
- const params = e.detail.value;
- if (!this.WxValidate.checkForm(params)) {
- const error = this.WxValidate.errorList[0];
- wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- return false
- } else {
- params.time_start = params.start_date + ' ' + params.start_time;
- params.time_end = params.end_date + ' ' + params.end_time;
- params.refund_hour = params.refund_date + ' ' + params.refund_time;
- let arr;
- if (params._id) { arr = await app.$post(`/lesson/${params._id}`, params) }
- else { arr = await app.$post(`/lesson`, params) }
- if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
- else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- const that = this;
- that.setData({ id: options.id || '' })
- //验证规则函数
- that.initValidate();
- // 查询其他信息
- await that.searchOther();
- // 监听用户是否登录
- await that.watchLogin();
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- let statusList = that.data.statusList;
- wx.getStorage({
- key: 'user',
- success: async res => {
- let data = res.data;
- let arr;
- // 教练与学校关系
- arr = await app.$get(`/rcs`, { coach_id: data.info._id });
- if (arr.errcode == '0' && arr.total > 0) that.setData({ schoolInfo: arr.data[0] });
- let form = { school_id: that.data.schoolInfo.school_id, type: '1' };
- if (that.data.id) {
- arr = await app.$get(`/lesson/${that.data.id}`);
- if (arr.errcode == '0') {
- arr.data.start_date = arr.data.time_start.slice(0, 10);
- arr.data.start_time = arr.data.time_start.slice(11, arr.data.time_start.length);
- arr.data.end_date = arr.data.time_end.slice(0, 10);
- arr.data.end_time = arr.data.time_end.slice(11, arr.data.time_end.length);
- arr.data.refund_date = arr.data.refund_hour.slice(0, 10);
- arr.data.refund_time = arr.data.refund_hour.slice(11, arr.data.refund_hour.length);
- // 查询状态
- let status = statusList.find(i => i.value = arr.data.status);
- if (status) arr.data.zhStatus = status.label;
- form = arr.data;
- }
- };
- that.setData({ form: form })
- },
- fail: async res => {
- wx.redirectTo({ url: '/pages/index/index' })
- }
- })
- },
- // 查询其他信息
- searchOther: async function () {
- const that = this;
- let arr;
- arr = await app.$get(`/dict`, { code: 'lesson_status' });
- if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|