|
@@ -0,0 +1,211 @@
|
|
|
+const app = getApp()
|
|
|
+import WxValidate from '../../utils/wxValidate'
|
|
|
+
|
|
|
+Page({
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ frameStyle: { useTop: true, name: '公开课信息', leftArrow: true, useBar: false },
|
|
|
+ id: '',
|
|
|
+ school_id: '',
|
|
|
+ form: {
|
|
|
+ // 教练
|
|
|
+ coach_id: [],
|
|
|
+ },
|
|
|
+ // 状态列表
|
|
|
+ statusList: [],
|
|
|
+ coachForm: {},
|
|
|
+
|
|
|
+ // dialog弹框
|
|
|
+ dialog: { title: '添加教练', show: false, type: '1' },
|
|
|
+ // 教练列表
|
|
|
+ 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({ 'coachForm.coach_id': data.coach_id });
|
|
|
+ that.setData({ 'coachForm.zhcoach': data.coach_id_name });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 添加教练
|
|
|
+ toChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ dialog: { title: '添加教练', show: true, type: '1' } })
|
|
|
+ },
|
|
|
+ // 保存教练
|
|
|
+ coachSubmit: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = e.detail.value;
|
|
|
+ let coachList = that.data.coachList;
|
|
|
+ let coach_id = [...that.data.form.coach_id];
|
|
|
+ let arr = coachList.find((i) => i.coach_id == data.coach_id);
|
|
|
+ if (arr) coach_id.push({ id: arr.coach_id, name: arr.coach_id_name, money: data.money })
|
|
|
+ that.setData({ 'form.coach_id': coach_id })
|
|
|
+ that.setData({ coachForm: {} })
|
|
|
+ that.setData({ dialog: { title: '添加教练', show: false, type: '1' } })
|
|
|
+ },
|
|
|
+ // 关闭弹框
|
|
|
+ toClose: function () {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ form: {} })
|
|
|
+ that.setData({ dialog: { title: '账号绑定', show: false, type: '1' } })
|
|
|
+ },
|
|
|
+ // 开始上课日期
|
|
|
+ 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;
|
|
|
+ params.coach_id = form.coach_id;
|
|
|
+ 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(`/lessonPublic/${form._id}`, params); }
|
|
|
+ else { arr = await app.$post(`/lessonPublic`, 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(`/lessonPublic/${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;
|
|
|
+ // 开始时间
|
|
|
+ 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 () {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|