|
@@ -1,66 +1,154 @@
|
|
|
-
|
|
|
+const app = getApp();
|
|
|
+import WxValidate from '../../utils/wxValidate';
|
|
|
+import { matchType } from '../../utils/dict';
|
|
|
Page({
|
|
|
-
|
|
|
-
|
|
|
- * 页面的初始数据
|
|
|
- */
|
|
|
data: {
|
|
|
-
|
|
|
+ frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
|
|
|
+ id: '',
|
|
|
+ form: {},
|
|
|
+ typeList: matchType,
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { name: { required: true } }
|
|
|
+
|
|
|
+ const messages = { name: { required: '请输入场地名称' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
+ },
|
|
|
+ back: function () {
|
|
|
+ wx.navigateBack({ delta: 1 })
|
|
|
+ },
|
|
|
+
|
|
|
+ imgUpl: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.form.logo;
|
|
|
+ data.push(e.detail)
|
|
|
+ that.setData({ 'form.logo': data })
|
|
|
+ },
|
|
|
+
|
|
|
+ imgDel: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let list = that.data.form.logo;
|
|
|
+ let arr = list.filter((i, index) => index != e.detail.index)
|
|
|
+ that.setData({ 'form.logo': arr })
|
|
|
+ },
|
|
|
+
|
|
|
+ typeChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.typeList[e.detail.value];
|
|
|
+ if (data) that.setData({ 'form.type': data.label })
|
|
|
+ },
|
|
|
+
|
|
|
+ startChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.start_time': e.detail.value });
|
|
|
+ },
|
|
|
+
|
|
|
+ endChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.end_time': e.detail.value });
|
|
|
+ },
|
|
|
+
|
|
|
+ dateChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.sign_date': e.detail.value });
|
|
|
+ },
|
|
|
+
|
|
|
+ timeChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ 'form.sign_time': e.detail.value });
|
|
|
+ },
|
|
|
+ toSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const form = that.data.form;
|
|
|
+ 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 {
|
|
|
+ let arr;
|
|
|
+ if (form._id) arr = await app.$post(`/newCourt/api/match/${form._id}`, params);
|
|
|
+ else arr = await app.$post(`/newCourt/api/match`, 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(options) {
|
|
|
-
|
|
|
+ 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 => {
|
|
|
+ let arr;
|
|
|
+ if (that.data.id) {
|
|
|
+ arr = await app.$get(`/newCourt/api/match/${that.data.id}`);
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ that.setData({ form: arr.data });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: async res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' })
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
-
|
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
- onReady() {
|
|
|
+ onReady: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
- onShow() {
|
|
|
+ onShow: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
- onHide() {
|
|
|
+ onHide: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
- onUnload() {
|
|
|
+ onUnload: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
- onPullDownRefresh() {
|
|
|
+ onPullDownRefresh: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
- onReachBottom() {
|
|
|
+ onReachBottom: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
- onShareAppMessage() {
|
|
|
+ onShareAppMessage: function () {
|
|
|
|
|
|
}
|
|
|
})
|