index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <view>
  3. <!-- 非H5撑高元素 -->
  4. <!-- <view class="status_bar"></view> -->
  5. <view class="box">
  6. <view class="box-top">
  7. <view class="box-top-action">
  8. <view class="box-top-action-item" @click="toPrize">
  9. <view class="flex box-top-action-item-cir">
  10. <image src="../../static/icon/index_prize.png" mode=""></image>
  11. </view>
  12. <view class="box-top-action-item-txt">奖品库</view>
  13. </view>
  14. </view>
  15. <view class="box-top-tip">
  16. <view class="flex box-top-tip-txt" @click="toRule">
  17. <text>规则说明</text>
  18. </view>
  19. <view class="flex box-top-tip-txt" @click="toTicket">
  20. <text>所有盲票</text>
  21. </view>
  22. </view>
  23. <view class="box-top-news">
  24. <prize-news :list="prizeNewsListOne" duration="20" v-if="prizeNewsListOne.length" />
  25. <prize-news :list="prizeNewsListTwo" duration="15" v-if="prizeNewsListTwo.length" />
  26. </view>
  27. </view>
  28. <view class="box-ticket">
  29. <swiper class="image-container" circular :vertical="true" :current="currentIndex" :autoplay="false"
  30. @change="swiperChange" v-if="imgList.length">
  31. <swiper-item class="swiper-item" v-for="(item, index) in imgList" :key="item.picUrl">
  32. <view class="flex image-wrap">
  33. <image class="img" :src="item.picUrl" lazy-load mode=""></image>
  34. </view>
  35. </swiper-item>
  36. </swiper>
  37. <swiper class="image-container" circular :vertical="true" :autoplay="false" v-else>
  38. <swiper-item class="swiper-item">
  39. <view class="flex image-wrap">
  40. <image class="img" src="../../static/icon/ticket_index.png" lazy-load mode=""></image>
  41. </view>
  42. </swiper-item>
  43. </swiper>
  44. <swiper class="prize-container" previous-margin="270rpx" next-margin="270rpx" circular :duration="15000"
  45. :interval="1500" easing-function="easeOutCubic" :current="currentPrizeIndex" :disable-touch="true"
  46. :autoplay="true">
  47. <swiper-item class="swiper-item" v-for="(item, index) in prizeList" :key="index">
  48. <view class="flex image-wrap">
  49. <image class="img" :src="item.picUrl" lazy-load mode="aspectFill"></image>
  50. </view>
  51. </swiper-item>
  52. </swiper>
  53. <image class="box-img" src="../../static/icon/index_box.png" mode=""></image>
  54. <image class="index-left" src="../../static/icon/index_left.png" mode="" @click="ticketLeft"></image>
  55. <image class="index-right" src="../../static/icon/index_right.png" mode="" @click="ticketRight"></image>
  56. </view>
  57. <view class="flex box-ticket-btn">
  58. <view class="box-ticket-btn-content" @click="exchange">
  59. <image src="../../static/icon/index_btn.png" mode=""></image>
  60. <view class="flex title">
  61. <text>{{ payInfo.salePrice / 100 }}元立即开刮</text>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <custom-tab-bar :activeValue="'index'" />
  67. <pay-popup :pay-show="payShow" :pay-info="payInfo" @close="close" @success="toProcess" />
  68. </view>
  69. </template>
  70. <script>
  71. import env from '../../config/env.js'
  72. import $http from '@/utils/request.js'
  73. import CustomTabBar from '../../components/custom-tab-bar/custom-tab-bar.vue'
  74. import Carousel from '../../components/vear-carousel/vear-carousel'
  75. import PayPopup from '../../components/pay-popup/pay-popup.vue'
  76. import PrizeNews from '../../components/prize-news/prize-news.vue'
  77. export default {
  78. components: {
  79. CustomTabBar,
  80. Carousel,
  81. PayPopup,
  82. PrizeNews
  83. },
  84. data() {
  85. return {
  86. imgList: [],
  87. value: 1,
  88. payShow: false,
  89. checked: false,
  90. pageNum: 1,
  91. total: 100,
  92. list: [],
  93. currentIndex: 0,
  94. currentPrizeIndex: 2,
  95. payInfo: {},
  96. prizeList: [],
  97. prizeNewsListOne: [],
  98. prizeNewsListTwo: [],
  99. };
  100. },
  101. onLoad(opthios) {
  102. if (opthios.scene) {
  103. let sceneStr = decodeURIComponent(opthios.scene)
  104. this.sceneArr = sceneStr.split('&')
  105. uni.setStorageSync('shareUid', this.sceneArr[0])
  106. uni.setStorageSync('shareType', this.sceneArr[1])
  107. }
  108. },
  109. onShow(opthios) {
  110. this.loginState = uni.getStorageSync('token') ? true : false
  111. this.getList()
  112. this.getPrizeNews()
  113. },
  114. methods: {
  115. swiperChange(e) {
  116. this.dontFirstAnimation = false
  117. this.currentIndex = e.detail.current
  118. this.getPrize(this.imgList[this.currentIndex].boxId)
  119. },
  120. prizeChange(e) {
  121. let ticketNum = this.imgList.length - 1
  122. let num = this.prizeList.length - 1
  123. let index = this.currentPrizeIndex = e.detail.current
  124. let acIndex = this.currentIndex
  125. if (num == index) {
  126. acIndex++
  127. if (acIndex < ticketNum) {
  128. this.currentIndex++
  129. } else if (acIndex == ticketNum) {
  130. this.currentIndex = ticketNum
  131. } else {
  132. this.currentIndex = 0
  133. }
  134. this.currentPrizeIndex = 2
  135. this.getPrize(this.imgList[this.currentIndex].boxId)
  136. }
  137. },
  138. getPrizeNews() {
  139. $http.post('/api/v1/mp/user/ticket/hitPrizeBarrage', { noToken: true }).then(res => {
  140. const { listOne, listTwo } = res && res.data
  141. listOne.forEach(item => {
  142. item.avatar = env.filePublic + item.avatar
  143. item.prizeInfo = item.prizeInfo && (item.prizeInfo.length > 14) ? item.prizeInfo.substring(0, 15) + '...' : item.prizeInfo
  144. })
  145. listTwo.forEach(item => {
  146. item.avatar = env.filePublic + item.avatar
  147. item.prizeInfo = item.prizeInfo && (item.prizeInfo.length > 14) ? item.prizeInfo.substring(0, 15) + '...' : item.prizeInfo
  148. })
  149. this.prizeNewsListOne = listOne
  150. this.prizeNewsListTwo = listTwo
  151. })
  152. },
  153. clickImg(item) {
  154. console.log(item);
  155. },
  156. ticketLeft() {
  157. if ((this.currentIndex >= 0) && (this.currentIndex < (this.imgList.length - 1))) {
  158. this.currentIndex++
  159. } else if (this.currentIndex == (this.imgList.length - 1)) {
  160. this.currentIndex = 0
  161. }
  162. },
  163. ticketRight() {
  164. if (this.currentIndex > 0) {
  165. this.currentIndex--
  166. } else if (this.currentIndex == 0) {
  167. this.currentIndex = this.imgList.length - 1
  168. }
  169. },
  170. getList() {
  171. uni.showLoading({
  172. title: '加载中'
  173. });
  174. let data = {
  175. categoryId: '',
  176. tagId: '',
  177. type: 'online',
  178. noToken: true
  179. }
  180. $http.post(`/api/v1/mp/user/mall/ticket/list?pageNum=${this.pageNum}&pageSize=100`, data).then(
  181. res => {
  182. uni.hideLoading();
  183. if (res.code == 0) {
  184. res.rows.forEach(item => item.picUrl = env.filePublic + item.picUrl.split(',')[0])
  185. this.total = res.total
  186. this.imgList = res.rows
  187. this.getPrize(this.imgList[0].boxId)
  188. }
  189. }).catch(() => {
  190. uni.hideLoading();
  191. })
  192. },
  193. getPrize(id) {
  194. this.prizeList = []
  195. $http.post('/api/v1/mp/user/mall/ticket/detail', {
  196. boxId: id,
  197. noToken: true
  198. }).then(res => {
  199. uni.hideLoading();
  200. if (res.code == 0) {
  201. let prizeList = res.data.prizeList
  202. prizeList.forEach(item => {
  203. let picUrlArr = item.picUrl.split(',')
  204. item.picUrl = env.filePublic + picUrlArr[0]
  205. })
  206. this.prizeList = prizeList
  207. this.currentPrizeIndex = 2
  208. this.payInfo = this.imgList[this.currentIndex]
  209. }
  210. }).catch(() => {
  211. uni.hideLoading();
  212. })
  213. },
  214. selectedBanner(item, index) {
  215. uni.navigateTo({
  216. url: `/pages/ticketBox/detail?boxId=${ item.boxId }`
  217. })
  218. },
  219. getTicket(index) {
  220. this.currentIndex = index
  221. },
  222. close() {
  223. this.payShow = false
  224. },
  225. toProcess(id) {
  226. this.payShow = false
  227. uni.navigateTo({
  228. url: `/pages/process/index?id=${ id }`
  229. })
  230. },
  231. exchange() {
  232. this.payInfo = this.imgList[this.currentIndex]
  233. let data = {
  234. couponIds: [],
  235. autoCoupon: 1,
  236. boxId: this.payInfo.boxId,
  237. orderNum: 1
  238. }
  239. $http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
  240. if (res.code == 0) {
  241. let info = {
  242. ...res.data,
  243. ...this.payInfo
  244. }
  245. this.payInfo = info
  246. this.payShow = true
  247. }
  248. }).catch(() => {
  249. uni.$u.toast('开刮失败,请重试!');
  250. })
  251. },
  252. toTicket() {
  253. uni.navigateTo({
  254. url: '/pages/ticketBox/index'
  255. })
  256. },
  257. toPrize() {
  258. if (!this.loginState) {
  259. uni.navigateTo({
  260. url: "/pages/login/index"
  261. })
  262. return
  263. }
  264. uni.navigateTo({
  265. url: '/pages/prize/index'
  266. })
  267. },
  268. toRule() {
  269. uni.navigateTo({
  270. url: '/pages/about/rule'
  271. })
  272. }
  273. }
  274. }
  275. </script>
  276. <style lang="scss" scoped>
  277. .status_bar {
  278. width: 100%;
  279. height: var(--status-bar-height);
  280. }
  281. /deep/ .u-tabbar__placeholder {
  282. display: none;
  283. }
  284. </style>
  285. <style lang="scss" scoped>
  286. .image-container {
  287. width: 750rpx;
  288. height: 40vh;
  289. .swiper-item {
  290. position: relative;
  291. width: 61vw;
  292. height: 40vh;
  293. display: flex;
  294. justify-content: center;
  295. align-items: center;
  296. }
  297. .image-wrap {
  298. position: relative;
  299. width: 61vw;
  300. height: 40vh;
  301. .img {
  302. width: 61vw;
  303. height: 40vh;
  304. }
  305. }
  306. }
  307. .prize-container {
  308. width: 750rpx;
  309. height: 13vh;
  310. margin-top: 2vh;
  311. .swiper-item {
  312. width: 100rpx;
  313. height: 13vh;
  314. display: flex;
  315. justify-content: flex-start;
  316. align-items: center;
  317. .image-wrap {
  318. width: 160rpx;
  319. height: 13vh;
  320. border-radius: 20rpx;
  321. background: linear-gradient(0deg, #BBBBBB, #FFFFFF);
  322. .img {
  323. width: 100%;
  324. height: 76%;
  325. }
  326. }
  327. }
  328. }
  329. .box {
  330. width: 100%;
  331. height: calc(100vh - 50px);
  332. background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/index_bg.jpeg) center center;
  333. &-top {
  334. position: relative;
  335. display: flex;
  336. justify-content: space-between;
  337. padding: 130rpx 0 0 40rpx;
  338. &-action {
  339. z-index: 20;
  340. display: flex;
  341. &-item {
  342. margin-right: 76rpx;
  343. &-cir {
  344. width: 72rpx;
  345. height: 72rpx;
  346. background-color: #FFC320;
  347. border-radius: 50%;
  348. margin-bottom: 14rpx;
  349. image {
  350. width: 40rpx;
  351. height: 36rpx;
  352. }
  353. }
  354. &-txt {
  355. font-size: 24rpx;
  356. text-align: center;
  357. color: #FFFFFF;
  358. }
  359. }
  360. }
  361. &-tip {
  362. z-index: 20;
  363. display: flex;
  364. flex-direction: column;
  365. align-items: flex-end;
  366. justify-content: flex-end;
  367. &-txt {
  368. font-size: 24rpx;
  369. width: 152rpx;
  370. height: 48rpx;
  371. background-color: #FFC320;
  372. border-radius: 24rpx 0 0 24rpx;
  373. margin-top: 40rpx;
  374. }
  375. &-txt:last-child {
  376. background-color: #FFFFCC;
  377. }
  378. }
  379. &-news {
  380. position: absolute;
  381. left: 0;
  382. bottom: 0;
  383. z-index: 10;
  384. width: 100vw;
  385. }
  386. }
  387. &-ticket {
  388. position: relative;
  389. margin: 40rpx 0 0;
  390. .index-left {
  391. position: absolute;
  392. width: 100rpx;
  393. height: 100rpx;
  394. top: 380rpx;
  395. left: 10rpx;
  396. z-index: 20;
  397. }
  398. .index-right {
  399. position: absolute;
  400. width: 100rpx;
  401. height: 100rpx;
  402. top: 380rpx;
  403. right: 10rpx;
  404. z-index: 20;
  405. }
  406. .box-img {
  407. position: absolute;
  408. top: 0;
  409. z-index: 10;
  410. width: 100vw;
  411. height: 70vw;
  412. }
  413. }
  414. &-ticket-btn {
  415. margin-top: 30rpx;
  416. &-content {
  417. position: relative;
  418. width: 420rpx;
  419. height: 142rpx;
  420. image {
  421. width: 420rpx;
  422. height: 142rpx;
  423. }
  424. .title {
  425. position: absolute;
  426. top: 0;
  427. width: 100%;
  428. height: 142rpx;
  429. text {
  430. font-size: 56rpx;
  431. font-weight: bold;
  432. color: #C44906;
  433. text-shadow: 0px 1px 0px rgba(255, 255, 255, 0.76);
  434. }
  435. }
  436. }
  437. }
  438. }
  439. </style>