index.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // pages/detail/index.js
  2. const app = getApp();
  3. let touchDotX = 0; //X按下时坐标
  4. let touchDotY = 0; //y按下时坐标
  5. let interval; //计时器
  6. let time = 0; //从按下到松开共多少时间*100
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. navHeight: '',
  13. //swiper
  14. background: ['bg1', 'bg2', 'bg3'],
  15. vertical: false,
  16. autoplay: false,
  17. interval: 2000,
  18. duration: 500,
  19. current: 0,
  20. //下啦
  21. isScroll: false,
  22. //地图
  23. markers: [{
  24. latitude: 0,
  25. longitude: 0,
  26. }],
  27. BASEIMGURL: app.globalData.BASEIMGURL, //图片域名
  28. BASEIMGURL1: app.globalData.BASEIMGURL1, //图片域名
  29. currentActivity: {}, //详情
  30. userInfo: {},
  31. scrollTop: 0,
  32. hideGetInfo: true,
  33. loading: true
  34. },
  35. add(e) {
  36. //参加活动
  37. if (!app.globalData.userInfo.avatar) {
  38. return this.setData({
  39. hideGetInfo: false
  40. })
  41. }
  42. if (this.data.currentActivity.isoverdue) {
  43. return wx.showToast({
  44. title: '活动时间已截止,您可以参加其它活动哦~',
  45. icon: 'none'
  46. })
  47. }
  48. let actid = this.data.currentActivity.id;
  49. app.globalData.api.activity_attend({
  50. phone: app.globalData.userInfo.phone,
  51. actid
  52. }).then(res => {
  53. //获取最新数据
  54. this.getAcDetail(actid);
  55. wx.showToast({
  56. title: '您已成功参加活动!',
  57. icon: 'none'
  58. })
  59. })
  60. },
  61. getAcDetail(actid) {
  62. app.globalData.api.activity_id(actid).then(res => {
  63. let v = res.data;
  64. //判断当前时间是否大于活动结束时间
  65. let myDate = new Date();
  66. let now = myDate.valueOf();
  67. let time = new Date(v.endtime).valueOf();
  68. if (app.globalData.systemInfo.platform == 'ios') {
  69. let _date = v.endtime.replace(/\.|\-/g, '/');
  70. time = new Date(_date).valueOf();
  71. }
  72. if (now > time) {
  73. v.isoverdue = true;
  74. } else {
  75. v.isoverdue = false;
  76. }
  77. v.starttime = v.starttime.substr(0, 16);
  78. v.deadline = v.deadline.substr(0, 16);
  79. v.endtime = v.endtime.substr(0, 16);
  80. v.shareMember = 0;
  81. v.content && (v.content = v.content.split('&hc').join('\n'));
  82. v.attention && (v.attention = v.attention.split('&hc').join('\n'));
  83. if (v.images) {
  84. try {
  85. v.imgList = JSON.parse(v.images);
  86. } catch (error) {
  87. }
  88. }
  89. let someOne = v.members.some(v => {
  90. return v.phone == app.globalData.userInfo.phone;
  91. });
  92. if (someOne) {
  93. v.shareMember = 1;
  94. }
  95. // if (v.members) {
  96. // v.membersList = v.members.split(';').filter(v => {
  97. // return v != '';
  98. // })
  99. // if (v.membersList.indexOf(app.globalData.userInfo.phone || '0') > -1) {
  100. // v.shareMember = 1;
  101. // }
  102. // }
  103. this.setData({
  104. currentActivity: v,
  105. markers: [{
  106. latitude: v.latitude || 0,
  107. longitude: v.longitude || 0
  108. }],
  109. loading: false
  110. })
  111. })
  112. },
  113. async getPhoneNumber(e) {
  114. const that = this;
  115. if (e.detail.errMsg == "getPhoneNumber:ok") {
  116. let res = await app.globalData.api.bindphone({
  117. "openid": app.globalData.userInfo.openid,
  118. "encryptedData": e.detail.encryptedData,
  119. "iv": e.detail.iv,
  120. "invitor": app.globalData.shareOpenId
  121. })
  122. app.globalData.userInfo.phone = res.data.phone;
  123. that.setData({
  124. userInfo: {
  125. ...this.data.userInfo,
  126. 'phone': res.data.phone
  127. }
  128. });
  129. //参加活动
  130. that.add(e);
  131. // wx.showToast({
  132. // title: '参加成功!',
  133. // icon: 'none'
  134. // })
  135. } else {
  136. wx.showToast({
  137. title: '请授权您的手机号!',
  138. icon: 'none'
  139. })
  140. }
  141. },
  142. change(e) {
  143. this.setData({
  144. current: e.detail.current
  145. })
  146. },
  147. scroll(e) {
  148. if (e.detail.scrollTop > 1) {
  149. if (this.data.isScroll) return;
  150. this.setData({
  151. isScroll: true
  152. })
  153. } else {
  154. if (!this.data.isScroll) return;
  155. this.setData({
  156. isScroll: false
  157. })
  158. }
  159. // else if (e.detail.scrollTop < 1 && this.data.isScroll == true) {
  160. // this.setData({
  161. // isScroll: false
  162. // })
  163. // }
  164. },
  165. /**
  166. * 生命周期函数--监听页面加载
  167. */
  168. onLoad: function (options) {
  169. if (options.openid) {
  170. app.globalData.shareOpenId = options.openid;
  171. }
  172. if (app.globalData.userInfo) {
  173. this.setData({
  174. userInfo: app.globalData.userInfo
  175. }, () => {
  176. if (options.actid) {
  177. this.getAcDetail(options.actid);
  178. } else {
  179. this.setData({
  180. currentActivity: app.globalData.currentActivity,
  181. markers: [{
  182. latitude: app.globalData.currentActivity.latitude || 0,
  183. longitude: app.globalData.currentActivity.longitude || 0
  184. }]
  185. })
  186. }
  187. })
  188. } else {
  189. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  190. // 所以此处加入 callback 以防止这种情况
  191. app.userInfoReadyCallback = res => {
  192. this.setData({
  193. userInfo: res
  194. }, () => {
  195. if (options.actid) {
  196. this.getAcDetail(options.actid);
  197. } else {
  198. this.setData({
  199. currentActivity: app.globalData.currentActivity,
  200. markers: [{
  201. latitude: app.globalData.currentActivity.latitude || 0,
  202. longitude: app.globalData.currentActivity.longitude || 0
  203. }]
  204. })
  205. }
  206. })
  207. }
  208. };
  209. },
  210. /**
  211. * 生命周期函数--监听页面初次渲染完成
  212. */
  213. onReady: function () {
  214. },
  215. /**
  216. * 生命周期函数--监听页面显示
  217. */
  218. onShow: function () {
  219. this.setData({
  220. isScroll: false
  221. })
  222. },
  223. /**
  224. * 生命周期函数--监听页面隐藏
  225. */
  226. onHide: function () {
  227. },
  228. /**
  229. * 生命周期函数--监听页面卸载
  230. */
  231. onUnload: function () {
  232. this.setData({
  233. loading: true
  234. })
  235. },
  236. /**
  237. * 页面相关事件处理函数--监听用户下拉动作
  238. */
  239. onPullDownRefresh: function () {
  240. },
  241. /**
  242. * 页面上拉触底事件的处理函数
  243. */
  244. onReachBottom: function () {
  245. },
  246. /**
  247. * 用户点击右上角分享
  248. */
  249. onShareAppMessage() {
  250. const openid = wx.getStorageSync('openid')
  251. let param = openid && typeof openid === 'string' ? `pages/detail/index?openid=${ openid }&actid=${this.data.currentActivity.id}` : `pages/index/index`
  252. return {
  253. title: this.data.currentActivity.title,
  254. desc: '快来参加活动吧~',
  255. // imageUrl: 'https://cirraybucket.oss-cn-shanghai.aliyuncs.com/nowwa-h5/aboutUs/share.jpg',
  256. path: param
  257. }
  258. },
  259. onPageScroll(e) {},
  260. userInfoHandler(e) {
  261. const that = this;
  262. if (e.detail.errMsg == "getUserInfo:ok") {
  263. let userInfo = e.detail.userInfo;
  264. let params = Object.assign({}, {
  265. openid: app.globalData.userInfo.openid,
  266. nickName: userInfo.nickName,
  267. gender: userInfo.gender,
  268. avatarUrl: userInfo.avatarUrl
  269. });
  270. app.globalData.api.binduserinfo(params).then(res => {
  271. let newUserInfo = app.globalData.userInfo;
  272. newUserInfo.avatar = userInfo.avatarUrl;
  273. newUserInfo.gender = userInfo.gender;
  274. newUserInfo.nickname = userInfo.nickName;
  275. app.globalData.userInfo = newUserInfo;
  276. that.setData({
  277. userInfo: newUserInfo,
  278. hideGetInfo: true
  279. })
  280. that.add();
  281. })
  282. } else {
  283. wx.showToast({
  284. title: '请授权您的头像!',
  285. icon: 'none'
  286. })
  287. }
  288. },
  289. })