detail.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '比赛信息', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. // 数据id
  13. id: '',
  14. //详情数据
  15. info: {},
  16. // 现场图片
  17. match_file: [],
  18. showModal: false,
  19. //修改比分
  20. form: [],
  21. //判断用户类别
  22. type: '',
  23. //用户信息
  24. userdata: {},
  25. //团队id
  26. blue_id: '',
  27. red_id: '',
  28. },
  29. //验证是否输入
  30. initValidate() {
  31. const rules = { blue_branch: { required: true }, red_branch: { required: true, }, blue_integral: { required: true }, red_integral: { required: true, } }
  32. // 验证字段的提示信息,若不传则调用默认的信息
  33. const messages = { blue_branch: { required: '请输入蓝方比分', }, red_branch: { required: '请输入红方比分', }, blue_integral: { required: '请输入蓝方积分', }, red_integral: { required: '请输入红方积分', } };
  34. this.WxValidate = new WxValidate(rules, messages)
  35. },
  36. back: function () {
  37. wx.navigateBack({ url: '/pages/home/index' })
  38. },
  39. //显示对话框
  40. clickme: function () {
  41. this.setData({
  42. showModal: true
  43. })
  44. },
  45. //关闭弹窗
  46. go: function () {
  47. this.setData({
  48. showModal: false
  49. })
  50. },
  51. //上传图片
  52. imgUpload: async function (e) {
  53. const that = this;
  54. if (that.data.type == '0') {
  55. return wx.showToast({
  56. title: '不可上传',
  57. duration: 2000,
  58. icon: 'error',
  59. })
  60. } else if (that.data.type == '1') {
  61. let red_id = that.data.red_id
  62. let blue_id = that.data.blue_id
  63. let user_id = that.data.userdata.id
  64. let create_id_one = ''
  65. let create_id_two = ''
  66. const res = await app.$get('/courtAdmin/api/team', { id: red_id });
  67. if (res.errcode === 0) create_id_one = res.data[0].create_id;
  68. const arr = await app.$get('/courtAdmin/api/team', { id: blue_id });
  69. if (arr.errcode === 0) create_id_two = arr.data[0].create_id;
  70. if (create_id_one == user_id || create_id_two == user_id) {
  71. let data = that.data.match_file;
  72. let id = that.data.id;
  73. data.push(e.detail)
  74. wx.request({
  75. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  76. method: 'post',
  77. data: { match_file: data },
  78. success(res) {
  79. if (res.data.errcode == 0) {
  80. wx.showToast({
  81. title: '添加成功',
  82. duration: 2000,
  83. icon: 'success',
  84. })
  85. that.setData({ match_file: data })
  86. } else {
  87. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  88. }
  89. }
  90. })
  91. } else {
  92. return wx.showToast({
  93. title: '不可上传',
  94. duration: 2000,
  95. icon: 'error',
  96. })
  97. }
  98. } else if (that.data.type == '2') {
  99. let userid = that.data.userdata.id
  100. let red_members = that.data.info.red_members;
  101. let blue_members = that.data.info.blue_members;
  102. var item = red_members.find(item => item.id == userid)
  103. var items = blue_members.find(item => item.id == userid)
  104. if (item || items) {
  105. let data = that.data.match_file;
  106. let id = that.data.id;
  107. data.push(e.detail)
  108. wx.request({
  109. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  110. method: 'post',
  111. data: { match_file: data },
  112. success(res) {
  113. if (res.data.errcode == 0) {
  114. wx.showToast({
  115. title: '添加成功',
  116. duration: 2000,
  117. icon: 'success',
  118. })
  119. that.setData({ match_file: data })
  120. } else {
  121. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  122. }
  123. }
  124. })
  125. } else {
  126. return wx.showToast({
  127. title: '不可删除',
  128. duration: 2000,
  129. icon: 'error',
  130. })
  131. }
  132. }
  133. },
  134. //删除图片
  135. imgDel: async function (e) {
  136. const that = this;
  137. if (that.data.type == '0') {
  138. return wx.showToast({
  139. title: '不可删除',
  140. duration: 2000,
  141. icon: 'error',
  142. })
  143. } else if (that.data.type == '1') {
  144. let red_id = that.data.red_id
  145. let blue_id = that.data.blue_id
  146. let user_id = that.data.userdata.id
  147. let create_id_one = ''
  148. let create_id_two = ''
  149. const res = await app.$get('/courtAdmin/api/team', { id: red_id });
  150. if (res.errcode === 0) create_id_one = res.data[0].create_id;
  151. const arr = await app.$get('/courtAdmin/api/team', { id: blue_id });
  152. if (arr.errcode === 0) create_id_two = arr.data[0].create_id;
  153. if (create_id_one == user_id || create_id_two == user_id) {
  154. let data = that.data.match_file;
  155. let id = that.data.id;
  156. let arr = data.filter((i, index) => index != e.detail.index)
  157. wx.request({
  158. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  159. method: 'post',
  160. data: { match_file: arr },
  161. success(res) {
  162. if (res.data.errcode == 0) {
  163. wx.showToast({
  164. title: '删除成功',
  165. duration: 2000,
  166. icon: 'success',
  167. })
  168. that.setData({ match_file: arr })
  169. } else {
  170. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  171. }
  172. }
  173. })
  174. } else {
  175. return wx.showToast({
  176. title: '不可删除',
  177. duration: 2000,
  178. icon: 'error',
  179. })
  180. }
  181. } else if (that.data.type == '2') {
  182. let userid = that.data.userdata.id
  183. let red_members = that.data.info.red_members;
  184. let blue_members = that.data.info.blue_members;
  185. var item = red_members.find(item => item.id == userid)
  186. var items = blue_members.find(item => item.id == userid)
  187. if (item || items) {
  188. let data = that.data.match_file;
  189. let id = that.data.id;
  190. let arr = data.filter((i, index) => index != e.detail.index)
  191. wx.request({
  192. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  193. method: 'post',
  194. data: { match_file: arr },
  195. success(res) {
  196. if (res.data.errcode == 0) {
  197. wx.showToast({
  198. title: '删除成功',
  199. duration: 2000,
  200. icon: 'success',
  201. })
  202. that.setData({ match_file: arr })
  203. } else {
  204. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  205. }
  206. }
  207. })
  208. } else {
  209. return wx.showToast({
  210. title: '不可删除',
  211. duration: 2000,
  212. icon: 'error',
  213. })
  214. }
  215. }
  216. },
  217. // 提交登录
  218. formSubmit: function (e) {
  219. const that = this;
  220. let id = that.data.id;
  221. const params = e.detail.value;
  222. params.match_file = that.data.match_file;
  223. if (!this.WxValidate.checkForm(params)) {
  224. const error = this.WxValidate.errorList[0];
  225. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  226. return false
  227. } else {
  228. wx.request({
  229. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  230. method: 'post',
  231. data: params,
  232. success(res) {
  233. if (res.data.errcode == 0) {
  234. wx.showToast({
  235. title: '保存成功',
  236. duration: 2000,
  237. icon: 'success',
  238. success: (res) => { that.back() }
  239. })
  240. } else {
  241. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  242. }
  243. }
  244. })
  245. }
  246. },
  247. /**
  248. * 生命周期函数--监听页面加载
  249. */
  250. onLoad: function (options) {
  251. const that = this;
  252. that.setData({ id: options.id })
  253. //验证规则函数
  254. this.initValidate();
  255. // 计算高度
  256. this.searchHeight();
  257. // 监听用户是否登录
  258. this.watchLogin();
  259. },
  260. // 监听用户是否登录
  261. watchLogin: async function () {
  262. const that = this;
  263. let id = that.data.id;
  264. wx.getStorage({
  265. key: 'token',
  266. success: async res => {
  267. that.setData({ type: res.data.type, userdata: res.data })
  268. const arr = await app.$get(`/courtAdmin/api/schedule/${id}`);
  269. if (arr.errcode === 0) {
  270. that.setData({
  271. info: arr.data,
  272. blue_id: arr.data.blue_id,
  273. red_id: arr.data.red_id
  274. })
  275. that.setData({ match_file: arr.data.match_file })
  276. }
  277. },
  278. fail: res => {
  279. return wx.redirectTo({ url: '/pages/login/index', })
  280. }
  281. })
  282. },
  283. // 计算高度
  284. searchHeight: function () {
  285. let frameStyle = this.data.frameStyle;
  286. let client = app.globalData.client;
  287. // 减去状态栏
  288. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  289. // 是否减去底部菜单
  290. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  291. if (infoHeight) this.setData({ infoHeight: infoHeight })
  292. },
  293. /**
  294. * 生命周期函数--监听页面初次渲染完成
  295. */
  296. onReady: function () {
  297. },
  298. /**
  299. * 生命周期函数--监听页面显示
  300. */
  301. onShow: function () {
  302. },
  303. /**
  304. * 生命周期函数--监听页面隐藏
  305. */
  306. onHide: function () {
  307. },
  308. /**
  309. * 生命周期函数--监听页面卸载
  310. */
  311. onUnload: function () {
  312. },
  313. /**
  314. * 页面相关事件处理函数--监听用户下拉动作
  315. */
  316. onPullDownRefresh: function () {
  317. },
  318. /**
  319. * 页面上拉触底事件的处理函数
  320. */
  321. onReachBottom: function () {
  322. },
  323. /**
  324. * 用户点击右上角分享
  325. */
  326. onShareAppMessage: function () {
  327. }
  328. })