拓恒河湖长制全民护河平台WEB端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
3.9KB

  1. // package_first/pages/VolunteerDetail/index.js
  2. import {api_westreamActivity,activitySubmit,api_getApply} from '../../../api/volunteer';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. status:false,
  9. activityInfo:{},
  10. dataSource: {},
  11. list:[],
  12. userPage:{
  13. page:1,
  14. limit:10
  15. },
  16. total:0,
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. let data = JSON.parse(decodeURIComponent(options.data))
  23. data.applyBeginTime = this.formatDate(data.applyBeginTime)
  24. data.applyEndTime = this.formatDate(data.applyEndTime)
  25. this.setData({
  26. activityInfo:data
  27. })
  28. let imgs=data.intro.match(/<img.*?src="(.*)".*?\/>/g);
  29. if(!imgs){
  30. this.setData({'dataSource.content': data.intro})
  31. } else {
  32. for(let img of imgs){
  33. let temp
  34. temp=img.replace(/(width=".*?"|height=".*?")/g,"");
  35. if(/style="(.*?)"/.test(temp)){
  36. temp=temp.replace(RegExp.$1,RegExp.$1+"width:100% !important;height:auto;display:block")
  37. }else{
  38. temp=temp.replace(/<img/,"<img style='width:100% !important;height:auto;display:block'")
  39. }
  40. data.intro=data.intro.replace(img,temp)
  41. }
  42. this.setData({'dataSource.content': data.intro})
  43. }
  44. this.getApplyStatus()
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady() {
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow() {
  55. // this.activitySubmit()
  56. this.getApplyStatus()
  57. },
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide() {
  62. },
  63. /**
  64. * 生命周期函数--监听页面卸载
  65. */
  66. onUnload() {
  67. },
  68. /**
  69. * 页面相关事件处理函数--监听用户下拉动作
  70. */
  71. onPullDownRefresh() {
  72. },
  73. /**
  74. * 页面上拉触底事件的处理函数
  75. */
  76. onReachBottom() {
  77. },
  78. getApplyStatus(){
  79. const openid = wx.getStorageSync('openid')
  80. const params = {
  81. openid,
  82. activityId: this.data.activityInfo.id,
  83. }
  84. api_getApply(params).then(res=>{
  85. if(res.code==0){
  86. let status = res.data?.status || 3
  87. this.setData({
  88. status
  89. })
  90. }
  91. })
  92. },
  93. activitySubmit(){
  94. let tenantObj = wx.getStorageSync('tenant')
  95. let openid = wx.getStorageSync('openid')
  96. let data = {
  97. openid:openid,
  98. activityId: this.data.activityInfo.id,
  99. tenantId:tenantObj.tenantId,
  100. nickname:'',
  101. applyPhone:'',
  102. applyName:'',
  103. activityTitle:this.data.activityInfo.activityTitle
  104. }
  105. activitySubmit(data).then(res=>{
  106. console.log(res);
  107. }).catch(res=>{
  108. console.log(res);
  109. })
  110. },
  111. formatDate(dateString) {
  112. const date = new Date(dateString);
  113. const year = date.getFullYear();
  114. const month = ("0" + (date.getMonth() + 1)).slice(-2);
  115. const day = ("0" + date.getDate()).slice(-2);
  116. return `${year}年${month}月${day}日`;
  117. },
  118. goApply(e){
  119. if(this.data.status === 1){
  120. wx.showToast({
  121. title: '您已参加该活动',
  122. icon:"none"
  123. })
  124. return
  125. }
  126. if(this.data.status === 3){
  127. let activityInfo = JSON.stringify(this.data.activityInfo)
  128. wx.navigateTo({
  129. url:"/package_first/pages/ActivityApply/index?activityInfo=" + encodeURIComponent(activityInfo)
  130. })
  131. }
  132. },
  133. /**
  134. * 用户点击右上角分享
  135. */
  136. onShareAppMessage() {
  137. }
  138. })