index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view>
  3. <u-navbar title="免费抽奖" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  4. <u-count-down :time="activityTime" format="DD:HH:mm:ss" autoStart millisecond @change="onChange">
  5. <view style="height: 98rpx;background-color: #fff;margin: 0 30rpx;line-height: 98rpx;overflow: hidden;">
  6. <view class="data-btn">距离开奖时间:
  7. <text v-if="timeData.days != 0" >{{timeData.days}}&nbsp;天</text>
  8. <text>{{ timeData.hours>10?timeData.hours:'0'+timeData.hours}}&nbsp;:</text>
  9. <text>{{timeData.minutes>10?timeData.minutes:'0'+timeData.minutes}}&nbsp;:</text>
  10. <text>{{timeData.seconds>10?timeData.seconds:'0'+timeData.seconds}}</text>
  11. </view>
  12. <view style="float: right;"><span style="font-weight: 600;">{{info.fakeNum}}</span>人已参与</view>
  13. </view>
  14. </u-count-down>
  15. <view>
  16. <view v-for="(item,index) in awardsList" :key="index">
  17. <view v-if="item.name == '一等奖'">
  18. <view style="height: 90rpx;">
  19. <view style="float: left;">
  20. <text
  21. style="display: inline-block; background-color: #bbbbbb;width: 200rpx;height: 90rpx;line-height:90rpx;text-align: center;">{{item.name}}</text>
  22. </view>
  23. <view style="float: right;line-height: 90rpx;">{{item.quantity}}个名额</view>
  24. </view>
  25. <view v-for="(itemTwo,index) in item.prizeList" :key="index">
  26. <view style="text-align: center;">
  27. <image :src="itemTwo.picUrl" mode="" style="width: 400rpx;"></image>
  28. <view>{{itemTwo.title}}</view>
  29. <view>¥{{itemTwo.value / 100}}</view>
  30. </view>
  31. </view>
  32. <view v-if="item.prizeList.length > 1 " style="text-align: center;">以上奖品随机获得一件</view>
  33. </view>
  34. </view>
  35. <view v-for="(item,index) in awardsList" :key="index">
  36. <view v-if="item.name != '一等奖'">
  37. <view style="height: 60rpx;">
  38. <view style="float: left;">
  39. <text style="display: inline-block; background-color: #bbbbbb;width: 200rpx;height: 60rpx;line-height:60rpx;text-align: center;">{{item.name}}</text>
  40. </view>
  41. <view style="float: right;line-height: 60rpx;">{{item.quantity}}个名额</view>
  42. </view>
  43. <view v-for="(itemTwo,index) in item.prizeList" :key="index">
  44. <view style="overflow: hidden; width: 100%;padding: 10rpx 20rpx;">
  45. <view style="display: inline-block;">
  46. <image :src="itemTwo.picUrl" mode="" style="width: 100rpx;height: 100rpx;"></image>
  47. </view>
  48. <view style="display: inline-block;width: 60%;margin-left: 20rpx;">
  49. <view>{{itemTwo.title}}</view>
  50. <view>¥{{itemTwo.value / 100}}</view>
  51. </view>
  52. </view>
  53. </view>
  54. <view v-if="item.prizeList.length > 1 " style="text-align: center;">以上奖品随机获得一件</view>
  55. </view>
  56. </view>
  57. </view>
  58. <view>
  59. <view style="height: 90rpx;line-height: 90rpx;">
  60. <text
  61. style="display: inline-block; background-color: #bbbbbb;width: 200rpx;text-align: center;">图文介绍</text>
  62. </view>
  63. <view v-html="description">{{description}} </view>
  64. </view>
  65. <view v-if="false"> 关注公众号:获取抽奖码和开奖提醒 > </view>
  66. <view>
  67. <view>我的抽奖码</view>
  68. <view style="text-align: center;margin-top: 20rpx;margin-bottom: 50rpx;">
  69. <view v-if="info.codeList.length > 0">
  70. <view v-for="(item,index) in info.codeList">{{item}}</view>
  71. </view>
  72. <view v-else>还没有抽奖码</view>
  73. </view>
  74. <view style="text-align: center;line-height: 90rpx;border-top: 2rpx solid #555;">抽奖码越多,中奖概率越大</view>
  75. </view>
  76. <view style="height: 200rpx;"></view>
  77. <view class="footer-fixed">
  78. <view class="flex btn">
  79. <button type="default" @click="exChange">获取抽奖码</button>
  80. </view>
  81. </view>
  82. <u-popup :show="popupShow" mode="bottom" @close="close" closeable>
  83. <view
  84. style="height: 98rpx;width: 100%; border-bottom: 2rpx solid #bbbbbb;text-align: center;line-height: 98rpx;">
  85. 获取抽奖码</view>
  86. <view style="padding: 30rpx 20rpx;">
  87. <view style="color: #101010; line-height: 50rpx;">邀请好友助力,获取抽奖码</view>
  88. <text style="color: #8c8c8c; font-size: 24rpx;">每邀请一位好友助力成功,即可获得1个抽奖码,没有上限</text>
  89. </view>
  90. <view style="padding: 0rpx 20rpx 50rpx ; ">
  91. <button type="default" style="background-color: #f7682b; color: #fff;" open-type="share">立即邀请好友助力</button>
  92. </view>
  93. </u-popup>
  94. </view>
  95. </template>
  96. <script>
  97. import env from '../../config/env.js'
  98. import $http from '@/utils/request.js'
  99. export default {
  100. data() {
  101. return {
  102. popupShow: false,
  103. id: '',
  104. description: '', //富文本
  105. info: {}, //列表
  106. timeData: {}, //时间
  107. awardsList: [], //奖品
  108. inviteCode: '', //邀请码
  109. activityTime: 0
  110. }
  111. },
  112. onLoad(opthios) {
  113. this.id = opthios.id
  114. this.getDetail()
  115. },
  116. onShow() {
  117. },
  118. methods: {
  119. getDetail() {
  120. uni.showLoading({
  121. title: '加载中'
  122. });
  123. $http.post(`/api/v1/mp/user/marketing/detail/${this.id}`, {}).then(res => {
  124. uni.hideLoading();
  125. console.log(res)
  126. if (res.code == 0) {
  127. this.info = res.data
  128. let awardsList = res.data.awardsList
  129. awardsList.forEach(item => {
  130. item.prizeList.forEach(itemTwo => {
  131. itemTwo.picUrl = (env.filePublic + itemTwo.picUrl.split(',')[0] +
  132. '?imageView2/2/w/750')
  133. })
  134. })
  135. this.awardsList = awardsList
  136. // 处理富文本
  137. const description = res.data.description.replaceAll(".jpg\"", ".jpg?imageView2/2/w/750\"")
  138. .replaceAll(".jpeg\"", ".jpeg?imageView2/2/w/750\"").replaceAll(".png\"",
  139. ".png?imageView2/2/w/750\"");
  140. this.description = this.formatRichText(description);
  141. let timestamp = parseInt(new Date().getTime())
  142. this.activityTime = this.info.endTime - timestamp
  143. console.log(this.activityTime);
  144. }
  145. }).catch(() => {
  146. uni.hideLoading();
  147. })
  148. },
  149. onChange(e) {
  150. this.timeData = e
  151. },
  152. exChange() {
  153. //弹出层打开
  154. this.popupShow = true
  155. $http.post('/api/v1/mp/user/marketing/inviteCode', {}).then(res=>{
  156. if(res.code == 0){
  157. this.inviteCode = res.data
  158. console.log(this.inviteCode);
  159. }
  160. })
  161. uni.requestSubscribeMessage({
  162. tmplIds:['3y_My-yRmqmGd3-f-vAwNaK4LQeehzXBSNDi_5wcnFI','FGcPOV1j9ApESr3VUlWjFr6E1vF4X_h0LLN82T2CLL0','92xxL8XTRPLROyNUtmN04OT0kyq4iwSCH3sz-j6zbZs'],
  163. success (res) {
  164. console.log(res);
  165. }
  166. })
  167. },
  168. close() {
  169. //弹出层收起
  170. this.popupShow = false
  171. },
  172. /**
  173. * 处理富文本里的图片宽度自适应
  174. * 1.去掉img标签里的style、width、height属性
  175. * 2.img标签添加style属性:max-width:100%;height:auto
  176. * 3.修改所有style里的width属性为max-width:100%
  177. * 4.去掉<br/>标签
  178. * @param html
  179. * @returns {void|string|*}
  180. */
  181. formatRichText(html) { //控制小程序中图片大小
  182. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  183. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  184. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  185. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  186. return match;
  187. });
  188. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  189. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
  190. 'max-width:100%;');
  191. return match;
  192. });
  193. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  194. newContent = newContent.replace(/\<img/gi,
  195. '<img style="max-width:100%;height:auto;font-size: 0;margin-top: -5px;"');
  196. return newContent;
  197. },
  198. },
  199. onShareAppMessage(res) {
  200. return {
  201. title: '超值宝贝免费抽,参与活动仅需3秒',
  202. path: `/pages/index/index?marketingId=${ this.info.id }?inviteCode=${ this.inviteCode }`
  203. }
  204. },
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. .data-btn {
  209. float: left;
  210. text {
  211. display: inline-block;
  212. width: 60rpx;
  213. }
  214. }
  215. .footer-fixed {
  216. position: fixed;
  217. bottom: var(--window-bottom);
  218. left: 0;
  219. right: 0;
  220. z-index: 11;
  221. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  222. background: #fff;
  223. // 设置ios刘海屏底部横线安全区域
  224. padding-bottom: constant(safe-area-inset-bottom);
  225. padding-bottom: env(safe-area-inset-bottom);
  226. .btn {
  227. padding: 20rpx 0;
  228. /deep/ button {
  229. width: 640rpx;
  230. height: 90rpx;
  231. line-height: 90rpx;
  232. font-size: 36rpx;
  233. color: #fff;
  234. background-color: $uni-bg-color;
  235. border: none;
  236. border-radius: 20rpx;
  237. }
  238. }
  239. // 设置ios刘海屏底部横线安全区域
  240. padding-bottom: constant(safe-area-inset-bottom);
  241. padding-bottom: env(safe-area-inset-bottom);
  242. }
  243. </style>