Browse Source

Merge branch 'master' of http://git.cc-lotus.info/ball-court/court-mobile

YY 3 years ago
parent
commit
0c2084b6ad
3 changed files with 141 additions and 109 deletions
  1. 62 83
      pages/createTeam/index.js
  2. 35 25
      pages/createTeam/index.wxml
  3. 44 1
      pages/createTeam/index.wxss

+ 62 - 83
pages/createTeam/index.js

@@ -8,24 +8,19 @@ Page({
      * 页面的初始数据
      */
     data: {
-        showModal: false,
         // 主体高度
         infoHeight: '',
         frameStyle: { useTop: true, name: '创建团队', leftArrow: true, useBar: false },
-        form: {
-            type: ['乒乓球', '足球', '篮球'],
-            objectType: [{ id: 0, name: '乒乓球' }, { id: 1, name: '足球' }, { id: 2, name: '篮球' },],
-            create_time: '2020-02-02',
-            create_id: '',
-            create_user: '',
-        },
+        form: {},
+        // 团队logo
+        logo: [],
+        // 团队类型
+        typeList: ['乒乓球', '足球', '篮球'],
         //成员
         members: [],
-        index: 0,
-        //选择成员列表
-        item: [],
-        // 上传图片
-        fileList: [],
+        show: false,
+        // 用户列表
+        userList: [],
     },
     //验证必填项
     initValidate() {
@@ -40,60 +35,60 @@ Page({
     //上传图片
     imgUpload: function (e) {
         const that = this;
-        let data = that.data.fileList;
+        let data = that.data.logo;
         data.push(e.detail)
-        that.setData({ fileList: data })
+        that.setData({ logo: data })
     },
     //删除图片
     imgDel: function (e) {
         const that = this;
-        let data = that.data.fileList;
+        let data = that.data.logo;
         let arr = data.filter((i, index) => index != e.detail.index)
-        that.setData({ fileList: arr })
+        that.setData({ logo: arr })
     },
-    //点击确定关闭弹窗
-    determine: function (e) {
-        this.setData({ showModal: false })
-    },
-    //显示对话框
-    clickme: function () {
-        this.setData({
-            showModal: true
-        })
+    // 选择团队类型
+    typeChange: function (e) {
+        const that = this;
+        let index = e.detail.value;
+        let data = that.data.typeList[index];
+        that.setData({ 'form.type': data })
     },
-    preventTouchMove: function () {
+    // 时间选择
+    dataChange: function (e) {
+        const that = this;
+        let value = e.detail.value;
+        that.setData({ 'form.create_time': value })
     },
-    //关闭弹窗
-    go: function () {
-        this.setData({
-            showModal: false
-        })
+    // 添加成员
+    createMem: function () {
+        const that = this;
+        that.setData({ show: true })
     },
-     //选择队
-     checkboxChange: function (e) {
+    // 选择成
+    memChange: function (e) {
         const that = this;
         let data = e.detail.value;
-        let item = that.data.item;
+        let user = that.data.userList;
         let members = [];
         for (const val of data) {
-            let arr = item.find((i) => i._id == val);
+            let arr = user.find((i) => i._id == val);
             if (arr) members.push({ id: arr._id, nickname: arr.nickname, icon: arr.icon })
         }
         that.setData({ members: members })
     },
-    //选择
-    bindPickerChange: function (e) {
-        this.setData({
-            index: e.detail.value
-        })
+    // 确认选择成员
+    memfirmSubmit: function () {
+        const that = this;
+        that.setData({ show: false });
     },
-    bindDateChange: function (e) {
-        this.setData({
-            ['form.create_time']: e.detail.value
-        })
+    // 取消选择成员
+    memClose: function () {
+        const that = this;
+        that.setData({ members: [] });
+        that.setData({ show: false });
     },
-    //点击减号删除
-    delList: function (e) {
+    //删除成员
+    memDel: function (e) {
         var id = e.currentTarget.dataset.id;
         var members = this.data.members;
         for (var i = 0; i < members.length; i++) {
@@ -105,39 +100,28 @@ Page({
     },
     //提交
     formSubmit: function (e) {
+        const that = this;
         const value = e.detail.value;
         if (!this.WxValidate.checkForm(value)) {
             const error = this.WxValidate.errorList[0];
             wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
             return false
         } else {
-            value.logo = this.data.fileList;
-            value.members = this.data.members;
-            value.create_id = this.data.form.create_id;
+            value.logo = that.data.logo;
+            value.members = that.data.members;
             wx.request({
-                url: `${app.globalData.publicUrl}/courtAdmin/api/team`, //接口地址
-                method: "post",//请求方法
-                //请求参数
+                url: `${app.globalData.publicUrl}/courtAdmin/api/team`,
+                method: "post",
                 data: value,
-                header: {},
                 success: res => {
                     if (res.data.errcode == 0) {
-                        wx.showToast({
-                            title: '创建团队成功',
-                            icon: 'success',
-                            duration: 2000//延迟两秒
-                        })
-                        return wx.redirectTo({ url: '/pages/me/index' })// 跳转页面
+                        wx.showToast({ title: '创建团队成功', icon: 'success', duration: 2000 })
+                        wx.redirectTo({ url: '/pages/me/index' })// 跳转页面
                     } else {
-                        wx.showToast({
-                            title: '创建团队失败',
-                            icon: 'error',
-                            duration: 2000
-                        })
+                        wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
                     }
                 },
-                error: err => {
-                }
+                error: err => { }
             })
         }
     },
@@ -169,30 +153,25 @@ Page({
         wx.getStorage({
             key: 'token',
             success: res => {
-                //数据请求
+                //查询用户列表
                 wx.request({
                     url: `${app.globalData.publicUrl}/courtAdmin/api/user`, //接口地址
                     method: "get",
-                    data: {},
+                    data: { status: '1' },
                     header: {},
-                    success: res => {
-                        that.setData({ item: res.data.data })
+                    success: arr => {
+                        let aee = arr.data.data.filter((i) => i.type == '2')
+                        if (aee) {
+                            that.setData({ userList: aee });
+                            // 过滤当前用户
+                            let user = arr.data.data.find((i) => i._id == res.data._id);
+                            if (user) that.setData({ 'form.create_user': user.nickname, 'form.create_id': user._id })
+
+                        }
                     },
                     error: err => {
                     }
                 })
-                wx.request({
-                    url: `${app.globalData.publicUrl}/courtAdmin/api/user/${res.data.id}`, //接口地址
-                    method: "get",//请求方法
-                    data: {},//请求参数
-                    header: {},
-                    success: res => {
-                        that.setData({ ['form.create_user']: res.data.data.nickname, ['form.create_id']: res.data.data.id })
-                    },
-                    error: err => {
-                    }
-                })
-
             },
             fail: res => {
                 wx.redirectTo({ url: '/pages/login/index', })

+ 35 - 25
pages/createTeam/index.wxml

@@ -5,41 +5,45 @@
                 <view class="top">
                     <view class="zero">
                         <view class="text">团队LOGO</view>
-                        <upload class="tou" list="{{fileList}}" count="{{1}}"  bind:imgUpload="imgUpload" bind:imgDel="imgDel"></upload>
+                        <upload class="tou" list="{{logo}}" count="{{1}}" bind:imgUpload="imgUpload" bind:imgDel="imgDel"></upload>
                     </view>
                     <view class="one">
                         <view class="text">团队名称</view>
-                        <input class="input" name="name" value="{{form.name}}" placeholder="" />
+                        <input class="input" name="name" value="{{form.name}}" placeholder="请输入团队名称" />
+                    </view>
+                    <view class="one" style="display: none;">
+                        <view class="text">团队创建人id</view>
+                        <input class="input" name="create_id" value="{{form.create_id}}" disabled />
                     </view>
                     <view class="one">
                         <view class="text">团队创建人</view>
-                        <input class="input" name="create_user" value="{{form.create_user}}" placeholder="" />
+                        <input class="input" name="create_user" value="{{form.create_user}}" placeholder="请输入团队创建人" />
                     </view>
                     <view class="one">
                         <view class="text">团队类型</view>
-                        <picker name="type" bindchange="bindPickerChange" value="{{index}}" range="{{form.type}}">
-                            <view class="input">{{form.type[index]}}
+                        <picker mode="selector" bindchange="typeChange" name="type" value="{{form.type}}" range="{{typeList}}">
+                            <view class="input">
+                                {{form.type||'请选择'}}
                                 <image class="back" src="/image/back.png"></image>
                             </view>
                         </picker>
                     </view>
                     <view class="one">
                         <view class="text">创建时间</view>
-                        <picker name="create_time" mode="date"  value="{{form.create_time}}" start="2015-09-01" end="3017-09-01" bindchange="bindDateChange">
+                        <picker mode="date" name="create_time" value="{{form.create_time}}" start="2022-01-01" end="2100-01-01" bindchange="dataChange">
                             <view class="input">
-                                {{form.create_time}}<image class="back" src="/image/back.png"></image>
+                                {{form.create_time||'选择时间'}}
+                                <image class="back" src="/image/back.png"></image>
                             </view>
                         </picker>
                     </view>
-                </view>
-                <view class="bottom" style="height:{{infoHeight-270}}px;">
                     <view class="two">
                         <view class="two_title"> 团队队员</view>
                         <view class="two_main">
-                            <view class="two_1" wx:key="item" wx:for="{{members}}">
+                            <view class="two_1" wx:for="{{members}}" wx:key="item">
                                 <view class="team_1">
                                     <image class="two_logo1" src="{{item.icon[0].url}}"></image>
-                                    <image bindtap='delList' data-id="{{item.id}}" class="two_jian" src="/image/jian.png"></image>
+                                    <image bindtap='memDel' data-id="{{item.id}}" class="two_jian" src="/image/jian.png"></image>
                                 </view>
                                 <view class="team_text">
                                     <text class="input1" value="{{item.nickname}}"></text>
@@ -48,29 +52,35 @@
                             <view class="two_1">
                                 <view class="team_1">
                                     <view class="tianjia">
-                                        <text bindtap='clickme' class=" icon iconfont icon-jia"></text>
+                                        <text bindtap='createMem' class=" icon iconfont icon-jia"></text>
                                     </view>
                                 </view>
                             </view>
                         </view>
                     </view>
                 </view>
-                <view class="mask" catchtouchmove="preventTouchMove" wx:if="{{showModal}}"></view>
-                <view class="modalDlg" wx:if="{{showModal}}">
-                    <text class="modal_text2">选择队员</text>
-                    <checkbox-group bindchange="checkboxChange">
-                        <label class="checkbox" wx:key="item" wx:for="{{item}}">
-                            <text class="modal_box">{{item.nickname}}</text>
-                            <checkbox class="box" value="{{item._id}}" checked="{{item.checked}}" />
-                        </label>
-                    </checkbox-group>
-                    <button bindtap="determine" class="modal_button">确定</button>
-                    <text bindtap="go" class="modal_text4">取消</text>
-                </view>
             </view>
             <view class="btn-area">
                 <button class="button" formType="submit">创建团队</button>
             </view>
         </form>
     </view>
-</mobile-main>
+</mobile-main>
+<van-dialog use-slot title="添加成员" show="{{ show }}" :showCancelButton="{{false}}" confirmButtonText="关闭" :closeOnClickOverlay="{{false}}">
+    <view class="dialog">
+        <view class="dialog_1">
+            <checkbox-group bindchange="memChange">
+                <view class="userList" wx:for="{{userList}}" wx:key="item">
+                    <label>
+                        <text>{{item.nickname}}</text>
+                        <checkbox value="{{item._id}}" checked="{{item.checked}}" />
+                    </label>
+                </view>
+            </checkbox-group>
+        </view>
+        <view class="dialog_2">
+            <button type="primary" size="mini" bindtap="memfirmSubmit">确定</button>
+            <button type="warn" size="mini" bindtap="memClose">取消</button>
+        </view>
+    </view>
+</van-dialog>

+ 44 - 1
pages/createTeam/index.wxss

@@ -191,9 +191,11 @@
 .box {
   padding: 10px 10px 0 0;
 }
-.modal_box{
+
+.modal_box {
   padding: 0 0 0 0;
 }
+
 .modal_text4 {
   font-size: 12px;
   margin: 10px 0 0 0;
@@ -207,4 +209,45 @@
   text-align: center;
   font-size: small;
   margin: 30px 0 0 0;
+}
+
+.dialog {
+  float: left;
+  width: 100%;
+  max-height: 300px;
+  overflow-y: auto;
+}
+
+.dialog .dialog_1 {
+  float: left;
+  width: 100%;
+  margin: 0 0 10px 0;
+}
+
+.dialog .dialog_1 .userList {
+  float: left;
+  width: 93%;
+  padding: 10px;
+  border-bottom: 1px solid #ccc;
+}
+
+.dialog .dialog_1 .userList text {
+  float: left;
+  text-align: left;
+  font-size: 14px;
+}
+.dialog .dialog_1 .userList checkbox {
+  float: right;
+}
+
+.dialog .dialog_2 {
+  float: left;
+  width: 100%;
+  text-align: center;
+  margin: 0 0 10px 0;
+}
+
+.dialog .dialog_2 button {
+  margin: 0 10px;
+  width: 30%;
 }