|
@@ -1,6 +1,7 @@
|
|
|
// pages/login/login.js
|
|
|
import WxValidate from '../../utils/wxValidate'
|
|
|
const app = getApp()
|
|
|
+
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
@@ -11,37 +12,14 @@ Page({
|
|
|
infoHeight: '',
|
|
|
frameStyle: { useTop: true, name: '创建团队', leftArrow: true, useBar: false },
|
|
|
form: {
|
|
|
- src: '/image/tou.png',
|
|
|
- ranks: '比赛第一名队',
|
|
|
- mechanism: '吉佳通达',
|
|
|
- type: ['乒乓球', '足球'],
|
|
|
- objectSex: [{ id: 0, name: '乒乓球' }, { id: 1, name: '足球' },],
|
|
|
-
|
|
|
+ type: ['乒乓球', '足球', '篮球'],
|
|
|
+ objectType: [{ id: 0, name: '乒乓球' }, { id: 1, name: '足球' }, { id: 2, name: '篮球' },],
|
|
|
},
|
|
|
- lists: [
|
|
|
- {
|
|
|
- id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
|
|
|
- },
|
|
|
- {
|
|
|
- id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
|
|
|
- },
|
|
|
- {
|
|
|
- id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
|
|
|
- },
|
|
|
- {
|
|
|
- id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
|
|
|
- },
|
|
|
- {
|
|
|
- id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
|
|
|
- },
|
|
|
- {
|
|
|
- id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
|
|
|
- },
|
|
|
- {
|
|
|
- id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
|
|
|
- },
|
|
|
- ],
|
|
|
+ lists: [{ id: '1', menbers: '' }],
|
|
|
+ menbers:[],
|
|
|
index: 0,
|
|
|
+ // 上传图片
|
|
|
+ fileList: [],
|
|
|
},
|
|
|
//选择
|
|
|
bindPickerChange: function (e) {
|
|
@@ -56,7 +34,7 @@ Page({
|
|
|
//点击加号添加
|
|
|
addList: function () {
|
|
|
var lists = this.data.lists;
|
|
|
- var newData = {};
|
|
|
+ var newData = [];
|
|
|
lists.push(newData);//实质是添加lists数组内容,使for循环多一次
|
|
|
this.setData({
|
|
|
lists: lists,
|
|
@@ -72,7 +50,46 @@ Page({
|
|
|
},
|
|
|
//提交
|
|
|
formSubmit: function (e) {
|
|
|
- console.log('form发生了submit事件,携带数据为:', e.detail.value)
|
|
|
+ const value = e.detail.value;
|
|
|
+ const that = this;
|
|
|
+ if (!this.WxValidate.checkForm(value)) {
|
|
|
+ const error = this.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ value.icon = this.data.fileList;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ success: function (res) {
|
|
|
+ wx.request({
|
|
|
+ url: `${app.globalData.publicUrl}/courtAdmin/api/team`, //接口地址
|
|
|
+ method: "post",//请求方法
|
|
|
+ data: value,//请求参数
|
|
|
+ header: {},
|
|
|
+ success: res => {
|
|
|
+ // var menbers = JSON.parse(res.data.menbers)
|
|
|
+ console.log(res);
|
|
|
+ if (res.data.errcode == 0) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '创建团队成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 2000//延迟两秒
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '创建团队失败',
|
|
|
+ icon: 'error',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: err => {
|
|
|
+ console.log(err);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
//上传图片
|
|
|
afterRead: function (event) {
|
|
@@ -88,9 +105,9 @@ Page({
|
|
|
console.log(res);
|
|
|
if (res.statusCode == '200') {
|
|
|
let data = [{ name: JSON.parse(res.data).name, url: `${app.globalData.imageUrl}` + JSON.parse(res.data).uri }]
|
|
|
- const { fileList = [] } = this.data;
|
|
|
- fileList.push({ ...file, url: res.data });
|
|
|
- this.setData({ fileList });
|
|
|
+ // const { fileList = [] } = this.data;
|
|
|
+ // fileList.push({ ...file, url: res.data });
|
|
|
+ that.setData({ fileList: data });
|
|
|
} else {
|
|
|
wx.showToast({ title: `${res.data.errmsg}`, icon: 'fail', duration: 2000 })
|
|
|
}
|
|
@@ -98,12 +115,37 @@ Page({
|
|
|
});
|
|
|
},
|
|
|
|
|
|
+ //验证必填项
|
|
|
+ initValidate() {
|
|
|
+ const rules = { name: { required: true }, type: { required: true }, create_user: { required: true }, }
|
|
|
+ // 验证字段的提示信息,若不传则调用默认的信息
|
|
|
+ const messages = { name: { required: '请输入团队名称' }, type: { required: '请输入团队类型' }, create_user: { required: '请输入团队创建人名称' }, };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
+ },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
// 计算高度
|
|
|
this.searchHeight()
|
|
|
+ // 监听用户是否登录
|
|
|
+ this.watchLogin();
|
|
|
+ //验证规则函数
|
|
|
+ this.initValidate()
|
|
|
+
|
|
|
+ },
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: function () {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ success: res => {
|
|
|
+ //数据请求
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ wx.redirectTo({ url: '/pages/login/index', })
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
// 计算高度
|
|
|
searchHeight: function () {
|