index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. showModal: false,
  10. // 主体高度
  11. infoHeight: '',
  12. frameStyle: { useTop: true, name: '创建团队', leftArrow: true, useBar: false },
  13. form: {
  14. type: ['乒乓球', '足球', '篮球'],
  15. objectType: [{ id: 0, name: '乒乓球' }, { id: 1, name: '足球' }, { id: 2, name: '篮球' },],
  16. create_time: '2016-09-01',
  17. },
  18. lists: [],
  19. index: 0,
  20. item: [],
  21. menbers: [],
  22. // 上传图片
  23. fileList: [],
  24. },
  25. apply: function (e) {
  26. this.setData({ showModal: false })
  27. console.log(this.data.menbers);
  28. },
  29. //选择队员
  30. checkboxChange: function (e) {
  31. const that = this;
  32. let data = e.detail.value;
  33. let item = that.data.item;
  34. let menbers = [];
  35. for (const val of data) {
  36. let arr = item.find((i) => i._id == val);
  37. console.log(arr);
  38. if (arr) menbers.push({ id: arr._id, nickname: arr.nickname, icon: arr.icon })
  39. }
  40. that.setData({ menbers: menbers })
  41. },
  42. //显示对话框
  43. clickme: function () {
  44. this.setData({
  45. showModal: true
  46. })
  47. },
  48. preventTouchMove: function () {
  49. },
  50. //关闭弹窗
  51. go: function () {
  52. this.setData({
  53. showModal: false
  54. })
  55. },
  56. //选择
  57. bindPickerChange: function (e) {
  58. console.log('picker发送选择改变,携带值为', e.detail.value)
  59. this.setData({
  60. index: e.detail.value
  61. })
  62. },
  63. bindDateChange: function (e) {
  64. console.log('picker发送选择改变,携带值为', e.detail.value)
  65. this.setData({
  66. create_time: e.detail.value
  67. })
  68. },
  69. back: function () {
  70. wx.navigateBack({ url: '/pages/me/index' })
  71. },
  72. //点击减号删除
  73. delList: function () {
  74. var lists = this.data.lists;
  75. lists.pop(); //实质是删除lists数组内容,使for循环少一次
  76. this.setData({
  77. lists: lists,
  78. })
  79. },
  80. // //提交
  81. // formSubmit: function (e) {
  82. // const value = e.detail.value;
  83. // if (!this.WxValidate.checkForm(value)) {
  84. // const error = this.WxValidate.errorList[0];
  85. // wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  86. // return false
  87. // } else {
  88. // value.icon = this.data.fileList;
  89. // wx.getStorage({
  90. // key: 'token',
  91. // success: function (res) {
  92. // wx.request({
  93. // url: `${app.globalData.publicUrl}/courtAdmin/api/team`, //接口地址
  94. // method: "post",//请求方法
  95. // //请求参数
  96. // data: value,
  97. // header: {},
  98. // success: res => {
  99. // console.log(res);
  100. // if (res.data.errcode == 0) {
  101. // wx.showToast({
  102. // title: '创建团队成功',
  103. // icon: 'success',
  104. // duration: 2000//延迟两秒
  105. // })
  106. // } else {
  107. // wx.showToast({
  108. // title: '创建团队失败',
  109. // icon: 'error',
  110. // duration: 2000
  111. // })
  112. // }
  113. // },
  114. // error: err => {
  115. // console.log(err);
  116. // }
  117. // })
  118. // }
  119. // })
  120. // }
  121. // },
  122. //上传图片
  123. formSubmit(e) {
  124. console.log('form发生了submit事件,携带数据为:', e.detail.value)
  125. },
  126. afterRead: function (event) {
  127. const that = this;
  128. const { file } = event.detail;
  129. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式app.globalData.fileUrl:
  130. console.log(file);
  131. wx.uploadFile({
  132. url: `${app.globalData.imageUrl}/files/court/elimg/upload`,
  133. filePath: file.url,
  134. name: 'file',
  135. formData: {},
  136. success: (res) => {
  137. console.log(res);
  138. if (res.statusCode == '200') {
  139. let data = [{ name: JSON.parse(res.data).name, url: `${app.globalData.imageUrl}` + JSON.parse(res.data).uri }]
  140. // const { fileList = [] } = this.data;
  141. // fileList.push({ ...file, url: res.data });
  142. that.setData({ fileList: data });
  143. } else {
  144. wx.showToast({ title: `${res.data.errmsg}`, icon: 'fail', duration: 2000 })
  145. }
  146. },
  147. });
  148. },
  149. //验证必填项
  150. initValidate() {
  151. const rules = { name: { required: true }, type: { required: true }, create_user: { required: true }, }
  152. // 验证字段的提示信息,若不传则调用默认的信息
  153. const messages = { name: { required: '请输入团队名称' }, type: { required: '请输入团队类型' }, create_user: { required: '请输入团队创建人名称' }, };
  154. this.WxValidate = new WxValidate(rules, messages)
  155. },
  156. /**
  157. * 生命周期函数--监听页面加载
  158. */
  159. onLoad: function (options) {
  160. // 计算高度
  161. this.searchHeight()
  162. // 监听用户是否登录
  163. this.watchLogin();
  164. //验证规则函数
  165. this.initValidate()
  166. },
  167. // 监听用户是否登录
  168. watchLogin: function () {
  169. const that = this;
  170. wx.getStorage({
  171. key: 'token',
  172. success: res => {
  173. //数据请求
  174. wx.request({
  175. url: `${app.globalData.publicUrl}/courtAdmin/api/user`, //接口地址
  176. method: "get",
  177. data: {},
  178. header: {},
  179. success: res => {
  180. that.setData({ item: res.data.data })
  181. },
  182. error: err => {
  183. console.log(err);
  184. }
  185. })
  186. },
  187. fail: res => {
  188. wx.redirectTo({ url: '/pages/login/index', })
  189. }
  190. })
  191. },
  192. // 计算高度
  193. searchHeight: function () {
  194. let frameStyle = this.data.frameStyle;
  195. let client = app.globalData.client;
  196. // 减去状态栏
  197. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  198. // 是否减去底部菜单
  199. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  200. if (infoHeight) this.setData({ infoHeight: infoHeight })
  201. },
  202. /**
  203. * 生命周期函数--监听页面初次渲染完成
  204. */
  205. onReady: function () {
  206. },
  207. /**
  208. * 生命周期函数--监听页面显示
  209. */
  210. onShow: function () {
  211. },
  212. /**
  213. * 生命周期函数--监听页面隐藏
  214. */
  215. onHide: function () {
  216. },
  217. /**
  218. * 生命周期函数--监听页面卸载
  219. */
  220. onUnload: function () {
  221. },
  222. /**
  223. * 页面相关事件处理函数--监听用户下拉动作
  224. */
  225. onPullDownRefresh: function () {
  226. },
  227. /**
  228. * 页面上拉触底事件的处理函数
  229. */
  230. onReachBottom: function () {
  231. },
  232. /**
  233. * 用户点击右上角分享
  234. */
  235. onShareAppMessage: function () {
  236. }
  237. })