index.vue 10.0 KB

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