index.vue 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="page HuoDongXiangQing flex-v">
  3. <view class="flex-item">
  4. <view v-if="ActivityInfo !== null">
  5. <!-- 活动主要信息 -->
  6. <view class="MainInfo">
  7. <text>{{ActivityInfo.name}}</text>
  8. <view class="Line flex-h">
  9. <text>活动时间:</text>
  10. <text class="flex-item">{{ToolClass.DateFormat(new Date(ActivityInfo.startDate).getTime())}} 至 {{ToolClass.DateFormat(new Date(ActivityInfo.endDate).getTime())}}</text>
  11. </view>
  12. <view class="Line flex-h">
  13. <text>活动地址:</text>
  14. <text class="flex-item">{{ActivityInfo.address}}</text>
  15. </view>
  16. <view class="Line flex-h">
  17. <text>报名截止:</text>
  18. <text class="flex-item">{{ToolClass.DateFormat(new Date(ActivityInfo.enrollEnd).getTime())}}</text>
  19. </view>
  20. </view>
  21. <!-- 活动详情 -->
  22. <view class="DetailContainer">
  23. <image mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/huodongxiangqing.png"></image>
  24. <view class="Text">
  25. <rich-text :nodes="ActivityInfo.detail"></rich-text>
  26. </view>
  27. </view>
  28. <!-- 投票 -->
  29. <view class="VoteContainer" v-if="IsVote">
  30. <image mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/toupiao.png"></image>
  31. <view class="List">
  32. <view v-for="(item, index) in VoteList" :key="index" class="flex-h" @tap="VoteIndex = index">
  33. <text class="iconfont iconweigouxuan" v-if="VoteIndex !== index"></text>
  34. <text class="iconfont icongouxuan" v-else></text>
  35. <view class="flex-item">
  36. <text>{{item.name}}</text>
  37. </view>
  38. </view>
  39. </view>
  40. <text @tap="ToPostActivityVote">提交</text>
  41. <button open-type="getPhoneNumber" class="GetPhoneBtn" v-if="!DataLock && ShowGetPhoneBtn" @getphonenumber="GetPhoneNumber">授权手机号</button>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 底部栏 -->
  46. <view class="Bottom flex-h">
  47. <view class="flex-item" @tap="LinkTo('../../index')">
  48. <image class="centerLabel" mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/huishenghuo.png"></image>
  49. </view>
  50. <view class="flex-item">
  51. <image class="centerLabel" mode="heightFix" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/fenxiang.png"></image>
  52. </view>
  53. <image mode="heightFix" v-if="IsEnroll" src="https://cjgw.oss-cn-hangzhou.aliyuncs.com/ygcxxfb/image/lijibaomingbtn.png" @tap="ToJoin"></image>
  54. <button open-type="getPhoneNumber" class="GetPhoneBottomBtn" v-if="!DataLock && ShowGetPhoneBtn && IsEnroll" @getphonenumber="GetPhoneNumber">授权手机号</button>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import { getCurrentInstance } from '@tarojs/taro'
  60. import { createNamespacedHelpers } from 'vuex'
  61. const { mapActions: mapIndexActions } = createNamespacedHelpers('index')
  62. const { mapState: mapUserState, mapActions: mapUserActions, mapMutations: mapUserMutations } = createNamespacedHelpers('user')
  63. export default {
  64. name: 'HuoDongXiangQing',
  65. data () {
  66. return {
  67. ShowGetPhoneBtn: false,
  68. VoteIndex: null,
  69. VoteList: [],
  70. ActivityInfo: null,
  71. IsVote: false,
  72. IsEnroll: false,
  73. CurrnetId: null,
  74. DataLock: false
  75. }
  76. },
  77. computed: {
  78. ...mapUserState({
  79. UserInfo: x => x.UserInfo // 用户信息
  80. })
  81. },
  82. components: {
  83. },
  84. onShareAppMessage () {
  85. return {
  86. title: this.ActivityInfo.shareTitle,
  87. path: `/pages/HuiShengHuo/ActivityList/ActivityDetail/index?id=${this.ActivityInfo.activityId}`,
  88. imageUrl: this.ActivityInfo.shareImg
  89. }
  90. },
  91. created () {
  92. wx.showShareMenu({
  93. withShareTicket: true,
  94. menus: ['shareAppMessage', 'shareTimeline']
  95. })
  96. this.CurrnetId = getCurrentInstance().router.params.id
  97. this.$authed(() => {
  98. this.Init()
  99. })
  100. },
  101. methods: {
  102. ...mapUserActions([ // 活动投票
  103. 'PostActivityVote',
  104. 'GetUserPhone',
  105. 'PostActivityJoin',
  106. 'MainSignIn' // 获取用户信息
  107. ]),
  108. ...mapUserMutations([
  109. 'EditUserInfo' // 编辑用户信息
  110. ]),
  111. ...mapIndexActions([
  112. 'GetActivityDetail' // 获取活动详情
  113. ]),
  114. Init () {
  115. this.ShowGetPhoneBtn = this.UserInfo === null || this.UserInfo.Phone === undefined || this.UserInfo.Phone === null
  116. this.GetActivityDetail({ urlData: { id: this.CurrnetId } }).then((res) => {
  117. this.ActivityInfo = res.data.data
  118. this.IsEnroll = this.ActivityInfo.isEnroll
  119. if (this.ActivityInfo.isVote) {
  120. this.VoteList = this.ActivityInfo.voteItemList.slice(0)
  121. }
  122. this.IsVote = this.ActivityInfo.isVote
  123. wx.ShareAppMessage({
  124. title: this.ActivityInfo.shareTitle,
  125. imageUrl: this.ActivityInfo.shareImg
  126. })
  127. })
  128. },
  129. LinkTo (url) {
  130. wx.switchTab({ url })
  131. },
  132. ToJoin () { // 报名
  133. wx.navigateTo({ url: `./JoinIn/index?id=${this.ActivityInfo.activityId}` })
  134. },
  135. ToPostActivityVote () { // 活动投票
  136. if (this.DataLock || this.VoteIndex === null) return
  137. this.DataLock = true
  138. this.PostActivityVote({
  139. urlData: { id: this.ActivityInfo.activityId },
  140. data: { data: { itemId: this.VoteList[this.VoteIndex].itemId } }
  141. }).then(() => {
  142. this.DataLock = false
  143. wx.showToast({
  144. title: '投票成功',
  145. icon: 'none',
  146. duration: 2000
  147. })
  148. }).catch(() => {
  149. this.DataLock = false
  150. })
  151. },
  152. GetPhoneNumber (e) {
  153. if (this.DataLock) return
  154. this.DataLock = true
  155. this.GetUserPhone({
  156. urlData: { personId: this.UserInfo.PersonId },
  157. data: { data: { sessionKey: this.UserInfo.SessionKey, encryptedData: e.detail.encryptedData, iv: e.detail.iv } }
  158. }).then((res) => {
  159. this.ShowGetPhoneBtn = false
  160. this.EditUserInfo({ name: 'OpenId', value: res.data.data.openId })
  161. this.EditUserInfo({ name: 'Phone', value: res.data.data.phone })
  162. this.DataLock = false
  163. }).catch(() => {
  164. this.DataLock = false
  165. })
  166. }
  167. }
  168. }
  169. </script>
  170. <style lang="scss">
  171. @import "page.scss";
  172. </style>