detail.js 10 KB

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