guhongwei 2 years ago
parent
commit
56ecac5230
3 changed files with 124 additions and 144 deletions
  1. 68 89
      pages/match/schedule.js
  2. 53 53
      pages/match/schedule.wxml
  3. 3 2
      pages/match/schedule.wxss

+ 68 - 89
pages/match/schedule.js

@@ -10,17 +10,16 @@ Page({
         frameStyle: { useTop: true, name: '比赛信息', leftArrow: true, useBar: false },
         // 主体高度
         infoHeight: '',
+        // 用户信息
+        user: {},
         // 数据id
         id: '',
-        //详情数据
-        info: {},
-        //用户信息
-        userdata: {},
-        //判断用户类别
-        type: '',
-        //团队id
-        blueTeam: {},
+        // 赛程信息
+        form: {},
+        // 红方团队
         redTeam: {},
+        // 蓝方团队
+        blueTeam: {},
         // 现场图片
         match_file: [],
     },
@@ -30,78 +29,62 @@ Page({
     //上传图片
     imgUpload: async function (e) {
         const that = this;
-        let type = that.data.type;
-        let redTeam = that.data.redTeam;
-        let blueTeam = that.data.blueTeam;
-        let user = that.data.userdata;
-        let info = that.data.info;
-        if (type == '0') {
+        const user = that.data.user;
+        const red = that.data.redTeam;
+        const blue = that.data.blueTeam;
+        const data = that.data.form;
+        let list = that.data.match_file;
+        if (user.type == '0') {
             wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
-        } else if (type == '1') {
-            if (redTeam || blueTeam) {
-                if (redTeam && redTeam.create_id == user._id || blueTeam && blueTeam.create_id == user._id) {
-                    let data = that.data.match_file;
-                    let id = that.data.id;
-                    data.push(e.detail);
-                    const arr = await app.$post(`/courtAdmin/api/schedule/${id}`, { match_file: data });
-                    if (arr.errcode === 0) {
-                        wx.showToast({ title: `上传图片成功`, icon: 'success', duration: 2000 })
-                        that.watchLogin();
-                    } else {
-                        wx.showToast({ title: arr.errmsg, icon: 'success', duration: 2000 })
-                    }
-                } else {
-                    wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
-                }
-            }
-        } else if (type == '2') {
-            let redM = info.red_members.find((i) => i.id == user._id);
-            let blueM = info.blue_members.find((i) => i.id == user._id);
-            if (redM || blueM) {
-                let data = that.data.match_file;
-                let id = that.data.id;
-                data.push(e.detail);
-                const arr = await app.$post(`/courtAdmin/api/schedule/${id}`, { match_file: data });
-                if (arr.errcode === 0) {
-                    wx.showToast({ title: `上传图片成功`, icon: 'success', duration: 2000 })
-                    that.watchLogin();
-                } else {
-                    wx.showToast({ title: arr.errmsg, icon: 'success', duration: 2000 })
-                }
-            } else {
-                wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
+        } else if (user.type == '1') {
+            // 判断当前红方团队创建人是否为当前用户
+            if (red.create_id == user._id) { list.push(e.detail); that.commonUpload(list); }
+            else {
+                // 判断当前蓝方团队创建人是否为当前用户
+                if (blue.create_id == user._id) { list.push(e.detail); that.commonUpload(list); }
+                else wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
             }
+        } else if (user.type == '2') {
+            let memebers = [...data.red_members, ...data.blue_members];
+            let memebersInfo = memebers.find((i) => i.user_id == user._id);
+            if (memebersInfo) { list.push(e.detail); that.commonUpload(list); }
+            else wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
+        }
+    },
+    // 公共上传图片方法
+    commonUpload: async function (data) {
+        const that = this;
+        const arr = await app.$post(`/courtAdmin/api/schedule/${that.data.id}`, { match_file: data });
+        if (arr.errcode == '0') {
+            wx.showToast({ title: `上传图片成功`, duration: 2000, icon: 'success', })
+            this.watchLogin();
+        } else {
+            wx.showToast({ title: `${arr.errmsg}`, duration: 2000, icon: 'error', })
         }
     },
     //删除图片
     imgDel: async function (e) {
         const that = this;
-        let type = that.data.type;
-        let redTeam = that.data.redTeam;
-        let blueTeam = that.data.blueTeam;
-        let user = that.data.userdata;
-        let info = that.data.info;
-        if (type == '0') {
+        const user = that.data.user;
+        const red = that.data.redTeam;
+        const blue = that.data.blueTeam;
+        const data = that.data.form;
+        let list = that.data.match_file;
+        if (user.type == '0') {
             wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', })
-        } else if (type == '1') {
-            if (redTeam || blueTeam) {
-                if (redTeam && redTeam.create_id == user._id || blueTeam && blueTeam.create_id == user._id) {
-                    let id = that.data.id;
-                    let data = that.data.match_file;
-                    let arr = data.filter((i, index) => index != e.detail.index)
-                    const res = await app.$post(`/courtAdmin/api/schedule/${id}`, { match_file: arr });
-                    if (res.errcode === 0) {
-                        wx.showToast({ title: `删除图片成功`, icon: 'success', duration: 2000 })
-                        that.watchLogin();
-                    } else {
-                        wx.showToast({ title: arr.errmsg, icon: 'success', duration: 2000 })
-                    }
-                } else {
-                    wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
-                }
+        } else if ((user.type == '1')) {
+            // 判断当前红方团队创建人是否为当前用户
+            if (red.create_id == user._id) { let match_file = list.filter((i, index) => index != e.detail.index); that.commonUpload(match_file); }
+            else {
+                // 判断当前蓝方团队创建人是否为当前用户
+                if (blue.create_id == user._id) { let match_file = list.filter((i, index) => index != e.detail.index); that.commonUpload(match_file); }
+                else wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', })
             }
-        } else if (type == '2') {
-            wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', })
+        } else if (user.type == '2') {
+            let memebers = [...data.red_members, ...data.blue_members];
+            let memebersInfo = memebers.find((i) => i.user_id == user._id);
+            if (memebersInfo) { let match_file = list.filter((i, index) => index != e.detail.index); that.commonUpload(match_file); }
+            else wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', })
         }
     },
     /**
@@ -109,7 +92,7 @@ Page({
      */
     onLoad: function (options) {
         const that = this;
-        that.setData({ id: options.id })
+        that.setData({ id: options.id || '62a04673b3fcf97310b3e9b9' })
         // 计算高度
         this.searchHeight()
         // 监听用户是否登录
@@ -118,26 +101,22 @@ Page({
     // 监听用户是否登录
     watchLogin: async function () {
         const that = this;
-        let id = that.data.id;
         wx.getStorage({
             key: 'token',
             success: async res => {
-                // 用户类别,用户信息
-                that.setData({ type: res.data.type, userdata: res.data })
-                const arr = await app.$get(`/courtAdmin/api/schedule/${id}`);
-                if (arr.errcode === 0) {
-                    // 比赛信息,红方id,蓝方id
-                    that.setData({ info: arr.data })
-                    // 现场图片
-                    that.setData({ match_file: arr.data.match_file })
-                    // 查询红方,蓝方信息
-                    const p1 = await app.$get(`/courtAdmin/api/team/${arr.data.red_id}`);
-                    const p2 = await app.$get(`/courtAdmin/api/team/${arr.data.blue_id}`);
-                    if (p1.errcode === 0 && p2.errcode === 0) {
-                        that.setData({ redTeam: p1.data })
-                        that.setData({ blueTeam: p2.data })
-                    }
-                }
+                let arr;
+                // 用户信息
+                that.setData({ user: res.data });
+                // 赛程信息
+                arr = await app.$get(`/courtAdmin/api/schedule/${that.data.id}`);
+                let schedule = arr.data;
+                if (arr.errcode == '0') that.setData({ form: schedule }); that.setData({ match_file: schedule.match_file || [] });
+                // 红方
+                arr = await app.$get(`/courtAdmin/api/team/${schedule.red_id}`);
+                if (arr.errcode == '0') that.setData({ redTeam: arr.data });
+                // 蓝方
+                arr = await app.$get(`/courtAdmin/api/team/${schedule.blue_id}`);
+                if (arr.errcode == '0') that.setData({ blueTeam: arr.data });
             },
             fail: res => {
                 return wx.redirectTo({ url: '/pages/login/index', })

+ 53 - 53
pages/match/schedule.wxml

@@ -1,61 +1,61 @@
 <mobile-main frameStyle="{{frameStyle}}" bind:back="back">
-  <view slot="info" class="main" style="height:{{infoHeight}}px;">
-    <view class="one">
-      <view class="one_1">
-        <view class="one_1_1">
-          <image src="{{info.blue_logo[0].url}}"></image>
-          <view class="textOver">{{info.blue_name}}</view>
-        </view>
-        <view class="one_1_1 one_1_2">
-          <view class="time">{{info.match_time}}</view>
-          <view class="branch">
-            <text>{{info.blue_branch||0}}</text>
-            <text>:</text>
-            <text>{{info.red_branch||0}}</text>
-          </view>
-          <view class="status">{{info.status=='0'?'未开始':info.status=='1'?'进行中':'已结束'}}</view>
-        </view>
-        <view class="one_1_1">
-          <image src="{{info.red_logo[0].url}}"></image>
-          <view class="textOver">{{info.red_name}}</view>
+    <view slot="info" class="main" style="height:{{infoHeight}}px;">
+        <view class="one">
+            <view class="one_1">
+                <view class="one_1_1">
+                    <image src="{{form.red_logo[0].url}}"></image>
+                    <view class="textOver">{{form.red_name}}</view>
+                </view>
+                <view class="one_1_1 one_1_2">
+                    <view class="time">{{form.match_time}}</view>
+                    <view class="branch">
+                        <text>{{form.red_branch||0}}</text>
+                        <text>:</text>
+                        <text>{{form.blue_branch||0}}</text>
+                    </view>
+                    <view class="status">{{form.status=='0'?'未开始':form.status=='1'?'进行中':'已结束'}}</view>
+                </view>
+                <view class="one_1_1">
+                    <image src="{{form.blue_logo[0].url}}"></image>
+                    <view class="textOver">{{form.blue_name}}</view>
+                </view>
+            </view>
+            <view class="one_2">{{form.match_name}}</view>
         </view>
-      </view>
-      <view class="one_2">{{info.match_name}}</view>
-    </view>
-    <view class="two">
-      <view class="two_1">参赛阵容</view>
-      <view class="two_2">
-        <view class="two_2_1">
-          <view class="two_2_1_logo">
-            <image src="{{info.blue_logo[0].url}}"></image>
-            <view class="bname">{{info.blue_name}}</view>
-          </view>
-          <view class="two_2_1_members">
-            <view class="list" wx:for="{{info.blue_members}}" wx:key="item">
-              <image class="img" src="{{item.icon[0].url}}"></image>
-              <view class="nickname">{{item.nickname}}</view>
+        <view class="two">
+            <view class="two_1">参赛阵容</view>
+            <view class="two_2">
+                <view class="two_2_1">
+                    <view class="two_2_1_logo">
+                        <image src="{{form.red_logo[0].url}}"></image>
+                        <view class="bname">{{form.red_name}}</view>
+                    </view>
+                    <view class="two_2_1_members">
+                        <view class="list" wx:for="{{form.red_members}}" wx:key="item">
+                            <image class="img" src="{{item.icon[0].url}}"></image>
+                            <view class="nickname">{{item.nickname}}</view>
+                        </view>
+                    </view>
+                </view>
+                <view class="two_2_1 two_2_2">
+                    <view class="two_2_1_logo">
+                        <image src="{{form.blue_logo[0].url}}"></image>
+                        <view class="bname">{{form.blue_name}}</view>
+                    </view>
+                    <view class="two_2_1_members">
+                        <view class="list" wx:for="{{form.blue_members}}" wx:key="item">
+                            <image class="img" src="{{item.icon[0].url}}"></image>
+                            <view class="nickname">{{item.nickname}}</view>
+                        </view>
+                    </view>
+                </view>
             </view>
-          </view>
         </view>
-        <view class="two_2_1 two_2_2">
-          <view class="two_2_1_logo">
-            <image src="{{info.red_logo[0].url}}"></image>
-            <view class="bname">{{info.red_name}}</view>
-          </view>
-          <view class="two_2_1_members">
-            <view class="list" wx:for="{{info.red_members}}" wx:key="item">
-              <image class="img" src="{{item.icon[0].url}}"></image>
-              <view class="nickname">{{item.nickname}}</view>
+        <view class="thr">
+            <view class="thr_1">现场图片</view>
+            <view class="thr_2">
+                <upload list="{{match_file}}" count="{{4}}" previewSize="{{170}}" bind:imgUpload="imgUpload" bind:imgDel="imgDel"></upload>
             </view>
-          </view>
         </view>
-      </view>
-    </view>
-    <view class="thr">
-      <view class="thr_1">现场图片</view>
-      <view class="thr_2">
-        <upload list="{{match_file}}" count="{{4}}" previewSize="{{170}}" bind:imgUpload="imgUpload" bind:imgDel="imgDel"></upload>
-      </view>
     </view>
-  </view>
 </mobile-main>

+ 3 - 2
pages/match/schedule.wxss

@@ -8,6 +8,7 @@
     width: 100%;
     background-color: #fff;
     margin: 0 0 10px 0;
+    overflow-x: hidden;
 }
 
 .main .one .one_1 {
@@ -46,13 +47,13 @@
 }
 
 .main .one .one_1 .one_1_2 .branch text:nth-child(1) {
-    color: #0000ff;
+    color: #ff0000;
     font-weight: bold;
     background-color: #f1f1f1;
 }
 
 .main .one .one_1 .one_1_2 .branch text:nth-child(3) {
-    color: #ff0000;
+    color: #0000ff;
     font-weight: bold;
     background-color: #f1f1f1;
 }