|
@@ -10,17 +10,16 @@ Page({
|
|
|
frameStyle: { useTop: true, name: '比赛信息', leftArrow: true, useBar: false },
|
|
|
|
|
|
infoHeight: '',
|
|
|
+
|
|
|
+ user: {},
|
|
|
|
|
|
id: '',
|
|
|
-
|
|
|
- info: {},
|
|
|
-
|
|
|
- userdata: {},
|
|
|
-
|
|
|
- type: '',
|
|
|
-
|
|
|
- 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) {
|
|
|
-
|
|
|
- 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', })
|