123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- const app = getApp()
- import WxValidate from '../../utils/wxValidate'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- team_id: "",
- id: '',
- form: {},
- // 状态
- userList: [],
- red_disabled: false,
- blue_disabled: false
- },
- // 过滤字典表
- getDict(value, model) {
- const that = this;
- if (model == 'winner') {
- if (value) {
- let list = that.data[model + 'List']
- let data = list.find(i => i._id == value);
- if (data) return data.name
- else return '暂无'
- }
- }
- },
- // 提交保存
- async toSave(e) {
- const that = this;
- const parmas = e.detail.value;
- if (!this.WxValidate.checkForm(parmas)) {
- const error = that.WxValidate.errorList[0];
- wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- return false
- } else {
- // 判断id使用
- let form = that.data.form;
- let res;
- if (form._id) res = await app.$api(`course/${form._id}`, 'POST', parmas);
- else res = await app.$api('course', 'POST', parmas);
- if (res.errcode == '0') {
- wx.showToast({ title: `信息提交成功`, icon: 'success' });
- wx.navigateBack({ delta: 1 });
- } else {
- wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
- }
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- async onLoad(options) {
- const that = this;
- that.setData({ id: options.id, team_id: options.team_id });
- wx.showLoading({ title: '加载中', mask: true })
- //验证规则函数
- that.initValidate();
- await that.searchOther()
- await that.search()
- wx.hideLoading()
- },
- initValidate() {
- const rules = { red_score: { required: true }, blue_score: { required: true } }
- const messages = { red_score: { required: '请输入红方比分' }, blue_score: { required: '请输入蓝方比分' } };
- this.WxValidate = new WxValidate(rules, messages)
- },
- // 查询其他信息
- async searchOther() {
- const that = this;
- let res;
- // 团队
- res = await app.$api('team', 'GET', { status: '1' })
- if (res.errcode == '0') that.setData({ userList: res.data })
- },
- search() {
- const that = this;
- wx.getStorage({
- key: 'user',
- async success(res) {
- let form = {}
- let aee = await app.$api(`course/${that.data.id}`, 'GET', {})
- if (aee.errcode == '0') {
- form = aee.data;
- if (form && form._id) {
- if (form.red_team_id == that.data.team_id) that.setData({ blue_disabled: true })
- else if (form.blue_team_id == that.data.team_id) that.setData({ red_disabled: true })
- }
- } else {
- wx.showToast({ title: `${aee.errmsg}`, icon: 'error' });
- }
- that.setData({ form })
- },
- fail(err) {
- // console.log(err);
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|