123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- const app = getApp()
- import WxValidate from '../../utils/wxValidate'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- frameStyle: { useTop: true, name: '私教课信息', leftArrow: true, useBar: false },
- id: '',
- school_id: '',
- form: {},
- // 状态列表
- statusList: [],
- // 教练列表
- coachList: [],
- },
- initValidate() {
- const rules = { title: { required: true }, brief: { required: true }, coach_id: { required: true }, limit: { required: true }, start_date: { required: true }, start_time: { required: true }, end_date: { required: true }, end_time: { required: true }, status: { required: true } }
- // 验证字段的提示信息,若不传则调用默认的信息
- const messages = { title: { required: '请输入课程标题', }, brief: { required: '请输入简介', }, coach_id: { required: '请选择教练', }, limit: { required: '请输入人数上限', }, start_date: { required: '请选择开始日期', }, start_time: { required: '请选择开始时间', }, end_date: { required: '请选择结束日期', }, end_time: { required: '请选择结束时间', }, status: { required: '请选择状态', } };
- this.WxValidate = new WxValidate(rules, messages)
- },
- // 返回
- back: function () {
- wx.navigateBack({ delta: 1 })
- },
- // 选择性别
- 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 });
- }
- },
- // 选择教练
- coachChange: function (e) {
- const that = this;
- let data = that.data.coachList[e.detail.value];
- if (data) {
- that.setData({ 'form.coach_id': data.coach_id });
- that.setData({ 'form.zhcoach': data.coach_id_name });
- }
- },
- // 开始上课日期
- startdateChange: function (e) {
- const that = this;
- that.setData({ 'form.start_date': e.detail.value })
- },
- // 开始上课时间
- starttimeChange: function (e) {
- const that = this;
- that.setData({ 'form.start_time': e.detail.value })
- },
- // 结束上课日期
- enddateChange: function (e) {
- const that = this;
- that.setData({ 'form.end_date': e.detail.value })
- },
- // 结束上课时间
- endtimeChange: function (e) {
- const that = this;
- that.setData({ 'form.end_time': e.detail.value })
- },
- // 提交保存
- onSubmit: async function (e) {
- const that = this;
- const params = e.detail.value;
- const form = that.data.form;
- params.school_id = that.data.school_id;
- params.time_start = form.start_date + '-' + form.start_time;
- params.time_end = form.end_date + '-' + form.end_time;
- if (!this.WxValidate.checkForm(params)) {
- const error = this.WxValidate.errorList[0];
- wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- return false
- } else {
- let arr;
- if (form._id) { arr = await app.$post(`/lessonPrivate/${form._id}`, params); }
- else { arr = await app.$post(`/lessonPrivate`, params); }
- if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
- else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const that = this;
- that.setData({ id: options.id || '' })
- //验证规则函数
- that.initValidate();
- // 监听用户是否登录
- that.watchLogin();
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- wx.getStorage({
- key: 'user',
- success: async res => {
- that.setData({ school_id: res.data.info.id })
- const aee = await app.$get(`/dict`, { code: "lesson_status" });
- if (aee.errcode == '0' && aee.total > 0) that.setData({ statusList: aee.data[0].list });
- const abb = await app.$get(`/rcs`, { school_id: res.data.info.id });
- if (abb.errcode == '0' && aee.total > 0) {
- that.setData({ coachList: abb.data })
- }
- if (that.data.id) {
- const arr = await app.$get(`/lessonPrivate/${that.data.id}`);
- if (arr.errcode == '0') {
- // 状态
- let status = that.data.statusList.find(i => i.value == arr.data.status)
- if (status) arr.data.zhstatus = status.label;
- // 教练
- let coach_id = that.data.coachList.find(i => i.coach_id == arr.data.coach_id)
- if (coach_id) arr.data.zhcoach = coach_id.coach_id_name;
- // 开始时间
- 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);
- that.setData({ form: arr.data });
- }
- }
- },
- fail: res => {
- wx.redirectTo({ url: '/pages/index/index', })
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|