index.vue 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="page HuoDongXiangQing flex-v">
  3. <view class="flex-item">
  4. <view v-if="ActivityDetail !== null">
  5. <!-- 活动主要信息 -->
  6. <view class="MainInfo">
  7. <text>{{ActivityDetail.name}}</text>
  8. <view class="SubInfo flex-h">
  9. <view class="flex-item">
  10. <text class="iconfont iconxianshi"></text>
  11. <text>{{ActivityDetail.pv || ''}}</text>
  12. </view>
  13. <view class="Time">
  14. <text class="iconfont iconshijian"></text>
  15. <text>{{ToolClass.DateFormat(new Date(ActivityDetail.createDate).getTime())}}</text>
  16. </view>
  17. </view>
  18. <view class="Line flex-h">
  19. <text>活动时间:</text>
  20. <text class="flex-item">{{ToolClass.DateFormat(new Date(ActivityDetail.startDate).getTime())}} 至 {{ToolClass.DateFormat(new Date(ActivityDetail.endDate).getTime())}}</text>
  21. </view>
  22. <view class="Line flex-h">
  23. <text>活动地址:</text>
  24. <text class="flex-item">{{ActivityDetail.address}}</text>
  25. </view>
  26. <view class="Line flex-h" v-if="IsEnroll">
  27. <text>报名截止:</text>
  28. <text class="flex-item">{{ToolClass.DateFormat(new Date(ActivityDetail.enrollEnd).getTime())}}</text>
  29. </view>
  30. </view>
  31. <!-- 活动详情 -->
  32. <view class="DetailContainer">
  33. <image mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/huodongxiangqing.png"></image>
  34. <view class="Text">
  35. <!-- <rich-text :nodes="ActivityDetail.detail"></rich-text> -->
  36. <Markdown :value="ActivityDetail.detail" />
  37. </view>
  38. </view>
  39. <!-- 投票 -->
  40. <view class="VoteContainer" v-if="IsVote">
  41. <image mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/toupiao.png"></image>
  42. <view class="List" v-if="!ShowVoteRes">
  43. <view v-for="(item, index) in VoteList" :key="index" class="flex-h" @tap="VoteIndex = index">
  44. <text class="iconfont iconweigouxuan" v-if="VoteIndex !== index"></text>
  45. <text class="iconfont icongouxuan" v-else></text>
  46. <view class="flex-item">
  47. <text>{{item.name}}</text>
  48. </view>
  49. </view>
  50. </view>
  51. <text @tap="ToPostActivityVote" v-if="!ShowVoteRes && (ActivityDetail.status - 0 !== 2)">提交</text>
  52. <button open-type="getPhoneNumber" class="GetPhoneBtn" v-if="!DataLock && ShowGetPhoneBtn && !ShowVoteRes && (ActivityDetail.status - 0 !== 2)" @getphonenumber="GetPhoneNumber">授权手机号</button>
  53. <view class="ResList" v-if="ShowVoteRes">
  54. <view v-for="(item, index) in VoteResList" :key="index">
  55. <view class="Text flex-h">
  56. <text class="flex-item">{{item.name}}({{item.num}}/{{item.total}})</text>
  57. <text>{{item.selfVoted ? '我投过的' : ''}}</text>
  58. </view>
  59. <view class="Line">
  60. <view>
  61. <view :style="{width: `${item.pec}%`}"></view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 底部栏 -->
  70. <view class="Bottom flex-h">
  71. <view class="flex-item" @tap="LinkTo('../../index')">
  72. <image class="centerLabel" mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/huishenghuo.png"></image>
  73. </view>
  74. <view class="flex-item" @tap="ToShare">
  75. <image class="centerLabel" mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/fenxiang.png"></image>
  76. </view>
  77. <button open-type="share" class="ShareBottomBtn" :class="{'active': IsEnroll}">分享</button>
  78. <image mode="heightFix" v-if="IsEnroll && !HasEnroll && (ActivityDetail.status - 0 !== 2)" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/lijibaomingbtn.png" @tap="ToJoin"></image>
  79. <button open-type="getPhoneNumber" class="GetPhoneBottomBtn" v-if="!DataLock && ShowGetPhoneBtn && IsEnroll && !HasEnroll && (ActivityDetail.status - 0 !== 2)" @getphonenumber="GetPhoneNumber">授权手机号</button>
  80. <text v-if="IsEnroll && HasEnroll && (ActivityDetail.status - 0 !== 2)">已报名</text>
  81. <text v-if="!(ActivityDetail.status - 0 !== 2)">已过期</text>
  82. </view>
  83. <!-- 授权头像获取弹窗 -->
  84. <GetUserIcon></GetUserIcon>
  85. </view>
  86. </template>
  87. <script>
  88. import GetUserIcon from '../../../../components/GetUserIcon/index'
  89. import { getCurrentInstance } from '@tarojs/taro'
  90. import { createNamespacedHelpers } from 'vuex'
  91. const { mapState: mapIndexState, mapActions: mapIndexActions } = createNamespacedHelpers('index')
  92. const { mapState: mapUserState, mapActions: mapUserActions, mapMutations: mapUserMutations } = createNamespacedHelpers('user')
  93. export default {
  94. name: 'HuoDongXiangQing',
  95. data () {
  96. return {
  97. From: null,
  98. HasEnroll: false,
  99. ShowVoteRes: false,
  100. VoteResList: [],
  101. ShowGetPhoneBtn: false,
  102. VoteIndex: null,
  103. VoteList: [],
  104. IsVote: false,
  105. IsEnroll: false,
  106. CurrnetId: null,
  107. DataLock: false
  108. }
  109. },
  110. computed: {
  111. ...mapUserState({
  112. UserInfo: x => x.UserInfo // 用户信息
  113. }),
  114. ...mapIndexState({
  115. ActivityDetail: x => x.ActivityDetail // 活动详情
  116. })
  117. },
  118. components: {
  119. GetUserIcon
  120. },
  121. onShareAppMessage () {
  122. return {
  123. title: this.ActivityDetail.shareTitle,
  124. path: `/pages/HuiShengHuo/ActivityList/ActivityDetail/index?id=${this.ActivityDetail.activityId}&from=life`,
  125. imageUrl: this.ActivityDetail.shareImg
  126. }
  127. },
  128. created () {
  129. this.CurrnetId = getCurrentInstance().router.params.id
  130. this.From = getCurrentInstance().router.params.from
  131. let _that = this
  132. wx.setNavigationBarTitle({
  133. title: _that.From === 'love' ? '荟 · 爱心' : '荟 · 生活'
  134. })
  135. this.$authed(() => {
  136. this.Init()
  137. })
  138. },
  139. mounted () {
  140. },
  141. methods: {
  142. ...mapUserActions([ // 活动投票
  143. 'PostActivityVote',
  144. 'GetUserPhone',
  145. 'PostActivityJoin',
  146. 'MainSignIn' // 获取用户信息
  147. ]),
  148. ...mapUserMutations([
  149. 'EditUserInfo' // 编辑用户信息
  150. ]),
  151. ...mapIndexActions([
  152. 'GetActivityDetail' // 获取活动详情
  153. ]),
  154. Init () {
  155. this.ShowGetPhoneBtn = this.UserInfo === null || this.UserInfo.Phone === undefined || this.UserInfo.Phone === null
  156. this.GetActivityDetail({ urlData: { id: this.CurrnetId } }).then((res) => {
  157. this.IsEnroll = this.ActivityDetail.isEnroll
  158. if (this.IsEnroll) {
  159. this.HasEnroll = this.ActivityDetail.isSelfEnrolled
  160. }
  161. if (this.ActivityDetail.isVote) {
  162. this.VoteList = this.ActivityDetail.voteItemList.slice(0)
  163. this.CreateVoteResList()
  164. this.ShowVoteRes = !!this.ActivityDetail.selfVoted
  165. }
  166. this.IsVote = this.ActivityDetail.isVote
  167. })
  168. },
  169. CreateVoteResList () { // 计算投票结果
  170. this.VoteResList = []
  171. let VoteTotal = 0
  172. this.VoteList.map((item) => {
  173. VoteTotal += item.voteNum - 0
  174. })
  175. this.VoteList.map((item) => {
  176. this.VoteResList.push({ name: item.name, pec: Math.floor((item.voteNum / VoteTotal) * 100), total: VoteTotal, num: item.voteNum, selfVoted: this.ActivityDetail.selfVoted === item.itemId })
  177. })
  178. },
  179. ToShare () {
  180. wx.showShareMenu({
  181. withShareTicket: true,
  182. menus: ['shareAppMessage', 'shareTimeline']
  183. })
  184. },
  185. LinkTo (url) {
  186. wx.switchTab({ url })
  187. },
  188. ToJoin () { // 报名
  189. wx.navigateTo({ url: `./JoinIn/index?id=${this.ActivityDetail.activityId}` })
  190. },
  191. ToPostActivityVote () { // 活动投票
  192. if (this.DataLock || this.VoteIndex === null) return
  193. this.DataLock = true
  194. this.PostActivityVote({
  195. urlData: { id: this.ActivityDetail.activityId },
  196. data: { data: { itemId: this.VoteList[this.VoteIndex].itemId } }
  197. }).then(() => {
  198. this.DataLock = false
  199. wx.showToast({
  200. title: '投票成功',
  201. icon: 'none',
  202. duration: 2000
  203. })
  204. this.ActivityDetail.selfVoted = this.VoteList[this.VoteIndex].itemId
  205. this.CreateVoteResList()
  206. this.ShowVoteRes = true
  207. }).catch(() => {
  208. this.DataLock = false
  209. })
  210. },
  211. GetPhoneNumber (e) {
  212. if (this.DataLock) return
  213. this.DataLock = true
  214. this.GetUserPhone({
  215. urlData: { personId: this.UserInfo.PersonId },
  216. data: { data: { sessionKey: this.UserInfo.SessionKey, encryptedData: e.detail.encryptedData, iv: e.detail.iv } }
  217. }).then((res) => {
  218. this.ShowGetPhoneBtn = false
  219. this.EditUserInfo({ name: 'OpenId', value: res.data.data.openId })
  220. this.EditUserInfo({ name: 'Phone', value: res.data.data.phone })
  221. this.DataLock = false
  222. }).catch(() => {
  223. this.DataLock = false
  224. })
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss">
  230. @import "page.scss";
  231. </style>