index.vue 9.9 KB

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