index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view>
  3. <u-navbar title="免费抽奖" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  4. <u-count-down :time="30 * 60 * 60 * 1000" 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>{{timeData.days}}&nbsp;天</text>
  8. <text>{{ timeData.hours>10?timeData.hours:'0'+timeData.hours}}&nbsp;:</text>
  9. <text>{{timeData.minutes}}&nbsp;:</text>
  10. <text>{{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}}</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}}</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" @click="exChange" 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. }
  110. },
  111. onLoad(opthios) {
  112. this.id = opthios.id
  113. this.getDetail()
  114. },
  115. onShow() {
  116. },
  117. methods: {
  118. getDetail() {
  119. uni.showLoading({
  120. title: '加载中'
  121. });
  122. $http.post(`/api/v1/mp/user/marketing/detail/${this.id}`, {}).then(res => {
  123. uni.hideLoading();
  124. console.log(res)
  125. if (res.code == 0) {
  126. this.info = res.data
  127. let awardsList = res.data.awardsList
  128. awardsList.forEach(item => {
  129. item.prizeList.forEach(itemTwo => {
  130. itemTwo.picUrl = (env.filePublic + itemTwo.picUrl.split(',')[0] +
  131. '?imageView2/2/w/750')
  132. })
  133. })
  134. this.awardsList = awardsList
  135. // let picUrlArr = res.data.picUrl.split(',')
  136. // picUrlArr.forEach(item => {
  137. // this.picUrlArr.push(env.filePublic + item + '?imageView2/2/w/750')
  138. // })
  139. // 处理富文本
  140. const description = res.data.description.replaceAll(".jpg\"", ".jpg?imageView2/2/w/750\"")
  141. .replaceAll(".jpeg\"", ".jpeg?imageView2/2/w/750\"").replaceAll(".png\"",
  142. ".png?imageView2/2/w/750\"");
  143. this.description = this.formatRichText(description);
  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. }
  159. })
  160. },
  161. close() {
  162. //弹出层收起
  163. this.popupShow = false
  164. },
  165. /**
  166. * 处理富文本里的图片宽度自适应
  167. * 1.去掉img标签里的style、width、height属性
  168. * 2.img标签添加style属性:max-width:100%;height:auto
  169. * 3.修改所有style里的width属性为max-width:100%
  170. * 4.去掉<br/>标签
  171. * @param html
  172. * @returns {void|string|*}
  173. */
  174. formatRichText(html) { //控制小程序中图片大小
  175. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  176. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  177. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  178. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  179. return match;
  180. });
  181. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  182. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
  183. 'max-width:100%;');
  184. return match;
  185. });
  186. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  187. newContent = newContent.replace(/\<img/gi,
  188. '<img style="max-width:100%;height:auto;font-size: 0;margin-top: -5px;"');
  189. return newContent;
  190. },
  191. },
  192. onShareAppMessage(res) {
  193. return {
  194. title: '超值宝贝免费抽,参与活动仅需3秒',
  195. path: `/pages/index/index?marketingId=${ this.info.id }?inviteCode=${ this.inviteCode }`
  196. }
  197. },
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. .data-btn {
  202. float: left;
  203. text {
  204. display: inline-block;
  205. width: 60rpx;
  206. }
  207. }
  208. .footer-fixed {
  209. position: fixed;
  210. bottom: var(--window-bottom);
  211. left: 0;
  212. right: 0;
  213. z-index: 11;
  214. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  215. background: #fff;
  216. // 设置ios刘海屏底部横线安全区域
  217. padding-bottom: constant(safe-area-inset-bottom);
  218. padding-bottom: env(safe-area-inset-bottom);
  219. .btn {
  220. padding: 20rpx 0;
  221. /deep/ button {
  222. width: 640rpx;
  223. height: 90rpx;
  224. line-height: 90rpx;
  225. font-size: 36rpx;
  226. color: #fff;
  227. background-color: $uni-bg-color;
  228. border: none;
  229. border-radius: 20rpx;
  230. }
  231. }
  232. }
  233. </style>