index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. import { btn } from "../../utils/dict";
  4. const app = getApp()
  5. var url = app.globalData.url;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. frameStyle: { useTop: true, name: '我的', leftArrow: false, useBar: true },
  12. src: '/image/fen.jpg',
  13. src3: '/image/huang.png',
  14. src4: '/image/zan.png',
  15. showMore: false,
  16. // 主体高度
  17. infoHeight: '',
  18. total: '4',
  19. //上传比分
  20. item: {
  21. id: '1', head2: '/image/head2.png', head1: '/image/head1.png', fraction2: '0', groupname2: '马尼拉组', fraction1: '0', site: '第一场', groupname1: '哈拉海组', week: '星期五', time: '13:00',
  22. state: '已结束', date: '01.15', start: '未开始'
  23. },
  24. //个人信息详情
  25. item1: {},
  26. //团队列表
  27. list: [],
  28. //头像
  29. icon: '',
  30. showModal: false,
  31. jumpList: [],
  32. },
  33. // 跳转菜单
  34. tabPath(e) {
  35. let { route } = e.detail.detail;
  36. if (route) wx.redirectTo({ url: `/${route}` })
  37. },
  38. //展开
  39. listToggle: function () {
  40. this.setData({
  41. showMore: !this.data.showMore
  42. })
  43. },
  44. //修改个人信息
  45. modify: function () {
  46. wx.navigateTo({
  47. url: `/pages/information/index`,
  48. })
  49. },
  50. //上传比分
  51. upload: function () {
  52. wx.navigateTo({
  53. url: `/pages/score/index`,
  54. })
  55. },
  56. //创建团队
  57. create: function () {
  58. wx.navigateTo({
  59. url: `/pages/createTeam/index`,
  60. })
  61. },
  62. //团队创建人-团队详情
  63. //个人用户-团队详情
  64. ToDetails: function (e) {
  65. let id = e.currentTarget.dataset.id;
  66. let type = this.data.item1.type
  67. if (type == 1) {
  68. wx.navigateTo({
  69. url: `/pages/teamDetails/detail?id=` + id,
  70. })
  71. } else if (type == 2) {
  72. wx.navigateTo({
  73. url: `/pages/teamDetails/index?id=` + id,
  74. })
  75. }
  76. },
  77. // 我的服务-功能按钮
  78. toCommon: function (e) {
  79. let { route, method } = e.currentTarget.dataset;
  80. let list = JSON.stringify(e.currentTarget.dataset.item);
  81. let id = e.currentTarget.dataset.id;
  82. if (method == 'signout') {
  83. wx.showModal({
  84. title: '提示',
  85. content: '是否确认退出登录',
  86. success(res) {
  87. if (res.confirm) {
  88. wx.removeStorage({
  89. key: 'token',
  90. success(res) {
  91. return wx.redirectTo({ url: '/pages/index/index', })
  92. }
  93. })
  94. }
  95. }
  96. })
  97. } else {
  98. wx.navigateTo({ url: `/${route}?id=` + id + `&list=` + list })
  99. }
  100. },
  101. /**
  102. * 生命周期函数--监听页面加载
  103. */
  104. onLoad: function (options) {
  105. // 计算高度
  106. this.searchHeight()
  107. // 监听用户是否登录
  108. this.watchLogin();
  109. },
  110. // 监听用户是否登录
  111. watchLogin: function () {
  112. const that = this;
  113. wx.getStorage({
  114. key: 'token',
  115. success: res => {
  116. //数据请求
  117. //用户详情
  118. wx.request({
  119. url: `${app.globalData.publicUrl}/courtAdmin/api/user/${res.data.id}`, //接口地址
  120. method: "get",//请求方法
  121. data: {},//请求参数
  122. header: {},
  123. success: res => {
  124. that.setData({ item1: res.data.data })
  125. let type = res.data.data.type;
  126. let icon = res.data.data.icon[0];
  127. if (icon) this.setData({ icon: icon.url })
  128. else this.setData({ icon: '/image/tou.png' });
  129. // 判断用户身份显示不同功能按钮
  130. let jump = btn.filter((i) => i.type.includes(type));
  131. if (jump) that.setData({ jumpList: jump });
  132. },
  133. error: err => {
  134. }
  135. })
  136. let type = res.data.type
  137. if (type == 1) {
  138. //团队管理员-团队列表
  139. wx.request({
  140. url: `${app.globalData.publicUrl}/courtAdmin/api/team`, //接口地址
  141. method: "get",//请求方法
  142. data: {},//请求参数
  143. header: {},
  144. success: res => {
  145. that.setData({ list: res.data.data })
  146. },
  147. error: err => {
  148. }
  149. })
  150. } else if (type == 2) {
  151. //个人用户-所在团队列表
  152. wx.request({
  153. url: `${app.globalData.publicUrl}/courtAdmin/api/team/userteams`, //接口地址
  154. method: "get",//请求方法
  155. data: { user_id: res.data.id },//请求参数
  156. header: {},
  157. success: res => {
  158. console.log(res);
  159. that.setData({ list: res.data.data })
  160. },
  161. error: err => {
  162. }
  163. })
  164. }
  165. },
  166. fail: res => {
  167. wx.redirectTo({ url: '/pages/login/index', })
  168. }
  169. })
  170. },
  171. // 计算高度
  172. searchHeight: function () {
  173. let frameStyle = this.data.frameStyle;
  174. let client = app.globalData.client;
  175. let infoHeight = client.windowHeight;
  176. // 是否去掉状态栏
  177. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  178. // 是否减去底部菜单
  179. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  180. if (infoHeight) this.setData({ infoHeight: infoHeight })
  181. },
  182. /**
  183. * 生命周期函数--监听页面初次渲染完成
  184. */
  185. onReady: function () {
  186. },
  187. /**
  188. * 生命周期函数--监听页面显示
  189. */
  190. onShow: function () {
  191. },
  192. /**
  193. * 生命周期函数--监听页面隐藏
  194. */
  195. onHide: function () {
  196. },
  197. /**
  198. * 生命周期函数--监听页面卸载
  199. */
  200. onUnload: function () {
  201. },
  202. /**
  203. * 页面相关事件处理函数--监听用户下拉动作
  204. */
  205. onPullDownRefresh: function () {
  206. },
  207. /**
  208. * 页面上拉触底事件的处理函数
  209. */
  210. onReachBottom: function () {
  211. },
  212. /**
  213. * 用户点击右上角分享
  214. */
  215. onShareAppMessage: function () {
  216. }
  217. })