index.vue 11 KB

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