index.vue 9.6 KB

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