|
@@ -0,0 +1,167 @@
|
|
|
+const app = getApp()
|
|
|
+import WxValidate from '../../../utils/wxValidate'
|
|
|
+
|
|
|
+Page({
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ frameStyle: { useTop: true, name: '课程信息', leftArrow: true, useBar: false },
|
|
|
+ id: '',
|
|
|
+ school_id: '',
|
|
|
+ form: {},
|
|
|
+ // 状态列表
|
|
|
+ statusList: [],
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { title: { required: true }, brief: { required: true }, limit: { required: true }, money: { required: true }, time_start: { required: true }, time_end: { required: true }, refund_hour: { required: true } }
|
|
|
+ // 验证字段的提示信息,若不传则调用默认的信息
|
|
|
+ const messages = { title: { required: '课程标题', }, brief: { required: '课程简介', }, limit: { required: '人数上限', }, money: { required: '课程费用', }, time_start: { required: '上课开始时间', }, time_end: { required: '上课结束时间', }, refund_hour: { 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 });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 时间确定选择
|
|
|
+ datetimeChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ [`form.${e.detail.name}`]: e.detail.datetime });
|
|
|
+ },
|
|
|
+ // 提交保存
|
|
|
+ onSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const params = e.detail.value;
|
|
|
+ let form = that.data.form;
|
|
|
+ params.school_id = that.data.school_id;
|
|
|
+ params.time_start = form.time_start;
|
|
|
+ params.time_end = form.time_end;
|
|
|
+ params.refund_hour = form.refund_hour;
|
|
|
+ if (!this.WxValidate.checkForm(params)) {
|
|
|
+ const error = this.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ let res;
|
|
|
+ if (form._id) { res = await app.$post(`/lesson/${form._id}`, params); }
|
|
|
+ else { res = await app.$post(`/lesson`, params); }
|
|
|
+ if (res.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
|
|
|
+ else wx.showToast({ title: res.errmsg, 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 });
|
|
|
+ await that.searchOther();
|
|
|
+ await that.searchInfo()
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index', })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 查询详细信息
|
|
|
+ async searchInfo() {
|
|
|
+ const that = this;
|
|
|
+ let id = that.data.id;
|
|
|
+ if (id) {
|
|
|
+ let res = await app.$get(`/lesson/${id}`);
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ let form = res.data;
|
|
|
+ form.zhstatus = that.searchStatus(form.status);
|
|
|
+ that.setData({ form })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ searchStatus(e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.statusList.find(i => i.value == e);
|
|
|
+ if (data) return data.label
|
|
|
+ },
|
|
|
+ // 查询其他信息
|
|
|
+ async searchOther() {
|
|
|
+ const that = this;
|
|
|
+ let res;
|
|
|
+ // 状态
|
|
|
+ res = await app.$get(`/dict`, { code: "lesson_status" });
|
|
|
+ if (res.errcode == '0' && res.total > 0) that.setData({ statusList: res.data[0].list });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage: function () {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|