index.vue 11 KB

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