drawCard_last.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <template>
  2. <view class="container">
  3. <view class="head">
  4. <image class="img" :src="detail.prizeIcon" mode="aspectFill"></image>
  5. <view class="info">
  6. <view class="title row">
  7. {{ detail.name }}
  8. </view>
  9. <view class="row">
  10. <view class="price">
  11. ¥{{ detail.price }}
  12. <span class="text">/张明信片</span>
  13. </view>
  14. <image
  15. @click="$navigateTo('/pages/rule/rule', { type: 5 })"
  16. class="button"
  17. :src="$fileUrl() + '/invite/button1.png'"
  18. mode="widthFix"
  19. ></image>
  20. </view>
  21. <view class="row">
  22. <view class="users">
  23. <image
  24. class="photo"
  25. :style="'left:' + index * 11 + 'px'"
  26. :src="$fileUrl() + '/Frame1.png'"
  27. v-for="(item, index) in userList"
  28. mode="widthFix"
  29. ></image>
  30. </view>
  31. <!-- <view class="hot">
  32. <image :src="$fileUrl() + /first/hot.png" mode="widthFix"></image>
  33. {{ detail.hotNum }}
  34. </view> -->
  35. </view>
  36. </view>
  37. </view>
  38. <view class="cardList">
  39. <image class="bk" :src="$fileUrl() + '/first/bk1.png'" mode="widthFix"></image>
  40. <view class="leftButton" @click="left"></view>
  41. <view class="rightButton" @click="right"></view>
  42. <view class="list">
  43. <view :class="['item', item.check ? 'active' : '']" v-for="(item, index) in cardList" @click="clickCard(item)">
  44. <image
  45. v-if="item.check"
  46. class="kaBkActive"
  47. :src="$fileUrl() + '/ka/kabk' + cardType(2, item) + 'Active.png'"
  48. mode="heightFix"
  49. ></image>
  50. <image class="kaBk" :src="$fileUrl() + '/ka/kabk' + cardType(2, item) + '.png'" mode="widthFix"></image>
  51. <numImg class="num" :value="item" :type="2" />
  52. </view>
  53. </view>
  54. </view>
  55. <view class="buttons">
  56. <image class="button1" @click="toKnapsack" :src="$fileUrl() + '/first/button6.png'" mode="widthFix"></image>
  57. <view class="">
  58. <image class="button2" @click="submit" :src="$fileUrl() + '/first/button4.png'" mode="widthFix"></image>
  59. <!-- <image class="button2" :src="$fileUrl() + /first/button1.png" mode="widthFix"></image> -->
  60. </view>
  61. <image @click="toWinningRecord" class="button1" :src="$fileUrl() + '/first/button3.png'" mode="widthFix"></image>
  62. </view>
  63. <view class="lockBox">
  64. <view class="text" v-if="!lockData.userId">本福袋连续购买10发,即开启保护机制</view>
  65. <view class="info" v-else>
  66. <image class="photo" :src="lockData.userAvtar" mode="aspectFill"></image>
  67. <view class="right">
  68. <view class="row">
  69. <view class="name">{{ lockData.userName }}</view>
  70. <view class="tip">目前已开启自动保护机制</view>
  71. </view>
  72. <view class="row">
  73. 保护倒计时:
  74. <span v-if="lockHour != '00'">
  75. <span class="time">{{ lockHour }}</span>
  76. :
  77. </span>
  78. <span>
  79. <span class="time">{{ lockMin }}</span>
  80. :
  81. </span>
  82. <span>
  83. <span class="time">{{ lockSecond }}</span>
  84. </span>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. <view class="prizes">
  90. <image class="title" :src="$fileUrl() + '/first/title.png'" mode="widthFix"></image>
  91. <view class="prizesList" v-for="(item, index) in prizeList">
  92. <image class="bk" :src="$fileUrl() + '/first/bk2.png'" mode="scaleToFill"></image>
  93. <view class="prizesTitle">
  94. {{ $selectDictLabel(rewardType, item.type) }}
  95. </view>
  96. <view class="prizesImgOne" v-if="item.type == 22">
  97. <view class="image" v-for="(item2, index2) in item.prizeList">
  98. <image :class="item2.leftNum == 0 ? 'grey' : ''" :src="item2.icon" mode="aspectFill"></image>
  99. </view>
  100. </view>
  101. <view class="prizesImg" v-else>
  102. <view class="image" v-for="(item2, index2) in item.prizeList">
  103. <image :class="item2.leftNum == 0 ? 'grey' : ''" :src="item2.icon" mode="aspectFill"></image>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. <image class="refresh" @click="refresh" :src="$fileUrl() + '/first/refresh.png'" mode="widthFix"></image>
  109. <paymentPopup ref="paymentPopup" @callBack="paymentSuccess" />
  110. </view>
  111. </template>
  112. <script>
  113. import { rewardType } from '@/utils/commonConfig.js'
  114. import { prizePoolStatusApi, drawCardSubmitApi, raffleDetailApi, prizeListApi, getLockInfoApi } from '@/api/drawCard.js'
  115. import { cardType, formatSeconds } from '@/utils/utils.js'
  116. import numImg from '@/component/numImg.vue'
  117. import paymentPopup from '@/component/paymentPopup.vue'
  118. const { v4: uuidv4 } = require('uuid')
  119. export default {
  120. components: {
  121. numImg,
  122. paymentPopup,
  123. },
  124. data() {
  125. return {
  126. userId: wx.getStorageSync('userId'),
  127. uuid: '',
  128. socketTimer: null,
  129. lockTimeCountdown: null,
  130. lockData: null,
  131. lockTime: '',
  132. cardType: cardType,
  133. rewardType: rewardType,
  134. params: {
  135. raffleId: '',
  136. limit: 12,
  137. page: 1,
  138. },
  139. detail: {},
  140. total: 0,
  141. userList: 8,
  142. cardList: [],
  143. selectIndex: [],
  144. prizeList: [],
  145. }
  146. },
  147. onLoad(query) {
  148. if (query.id) {
  149. this.params.raffleId = query.id
  150. this.init()
  151. }
  152. this.paymentSuccess()
  153. },
  154. onHide() {
  155. this.leave()
  156. },
  157. onUnload() {
  158. this.leave()
  159. },
  160. computed: {
  161. // 锁箱小时
  162. lockHour() {
  163. let tiem = this.lockTime * 1000
  164. let timeText = formatSeconds(tiem)
  165. timeText = timeText.split(':')[0]
  166. return timeText
  167. },
  168. // 锁箱分钟
  169. lockMin() {
  170. let tiem = this.lockTime * 1000
  171. let timeText = formatSeconds(tiem)
  172. timeText = timeText.split(':')[1]
  173. return timeText
  174. },
  175. // 锁箱秒
  176. lockSecond() {
  177. let tiem = this.lockTime * 1000
  178. let timeText = formatSeconds(tiem)
  179. timeText = timeText.split(':')[2]
  180. return timeText
  181. },
  182. },
  183. methods: {
  184. init() {
  185. // 获取卡牌商品列表
  186. this.getCardList()
  187. // 获取卡包详情
  188. this.getDetail()
  189. //获取奖池
  190. this.getPrizeList()
  191. // 初始化锁箱
  192. this.initLock()
  193. // 连接锁箱Socket
  194. this.connectSocket()
  195. },
  196. leave() {
  197. console.log('离开页面')
  198. // 离开页面
  199. // 关闭倒计时
  200. clearInterval(this.lockTimeCountdown)
  201. // 关闭心跳测试
  202. clearInterval(this.socketTimer)
  203. // 关闭对话连接
  204. wx.closeSocket()
  205. },
  206. initLock() {
  207. // 获取锁箱信息
  208. let _this = this
  209. let params = {
  210. raffleId: this.params.raffleId,
  211. }
  212. getLockInfoApi(params).then(res => {
  213. console.log(res, '锁箱')
  214. if (res.data.userId) {
  215. _this.lockData = res.data
  216. _this.lockTime = res.data.expireTime
  217. _this.initLockTimeCountdown()
  218. } else {
  219. _this.lockData = {}
  220. _this.lockTime = ''
  221. }
  222. })
  223. },
  224. initLockTimeCountdown() {
  225. let _this = this
  226. if (_this.lockTimeCountdown) {
  227. clearInterval(_this.lockTimeCountdown)
  228. _this.lockTimeCountdown = null
  229. }
  230. _this.lockTimeCountdown = setInterval(() => {
  231. console.log('22')
  232. _this.lockTime = _this.lockTime - 1
  233. if (_this.lockTime <= 0) {
  234. clearInterval(_this.lockTimeCountdown)
  235. _this.lockTimeCountdown = null
  236. _this.initLock()
  237. }
  238. }, 1000)
  239. },
  240. connectSocket() {
  241. let _this = this
  242. let uuid = uuidv4()
  243. let url = 'wss://mall.rongtongh.cn/websocket/raffleId' + this.params.raffleId + ':' + uuid
  244. function connect() {
  245. wx.connectSocket({
  246. url: url,
  247. })
  248. wx.onSocketOpen(function (res) {
  249. console.log(res, 'WebSocket连接已打开!')
  250. // wx.sendSocketMessage({
  251. // data: JSON.stringify(user),
  252. // })
  253. _this.socketTimer = setInterval(function () {
  254. console.log('发送消息')
  255. wx.sendSocketMessage({
  256. data: '12313',
  257. })
  258. }, 30 * 1000)
  259. })
  260. wx.onSocketMessage(function (res) {
  261. console.log(data, 'WebSocket接受信息')
  262. let data = JSON.parse(res.data)
  263. if (res.data.userId) {
  264. _this.lockData = data
  265. _this.lockTime = data.expireTime
  266. _this.initLockTimeCountdown()
  267. }
  268. })
  269. wx.onSocketClose(function (res) {
  270. console.log('WebSocket连接已关闭!')
  271. setTimeout(() => {
  272. console.log('re connect')
  273. // connect()
  274. }, 2000)
  275. })
  276. }
  277. connect()
  278. },
  279. toKnapsack() {
  280. // 跳转背包界面
  281. wx.navigateTo({
  282. url: '/pages/knapsack/knapsack',
  283. })
  284. },
  285. refresh() {
  286. wx.showLoading()
  287. setTimeout(function () {
  288. wx.hideLoading()
  289. }, 1000)
  290. this.init()
  291. this.selectIndex = []
  292. for (var i = 0; i < this.cardList.length; i++) {
  293. this.cardList[i].check = false
  294. }
  295. },
  296. getPrizeList() {
  297. let params = {
  298. raffleId: this.params.raffleId,
  299. }
  300. prizeListApi(params).then(res => {
  301. console.log(res, '奖池预览')
  302. let newArray = res.data
  303. for (var i = 0; i < res.data.length; i++) {
  304. if (res.data[i].type == 22) {
  305. newArray = []
  306. newArray.push(res.data[i])
  307. res.data.splice(i, 1)
  308. newArray.push(...res.data)
  309. break
  310. }
  311. }
  312. this.prizeList = newArray
  313. })
  314. },
  315. toWinningRecord() {
  316. let params = {
  317. raffleId: this.params.raffleId,
  318. }
  319. this.$navigateTo('/pages/winningRecord/winningRecord', params)
  320. },
  321. getDetail() {
  322. let params = {
  323. raffleId: this.params.raffleId,
  324. }
  325. raffleDetailApi(params).then(res => {
  326. console.log(res, '详情')
  327. this.detail = res.data
  328. })
  329. },
  330. submit() {
  331. // 购买时判断锁箱
  332. if (this.lockData?.userId && this.userId != this.lockData.userId) {
  333. wx.showToast({
  334. title: '锁箱中无法购买。',
  335. icon: 'none',
  336. })
  337. return
  338. }
  339. if (this.selectIndex.length == 0) {
  340. wx.showToast({
  341. title: '请选则要购买的卡牌。',
  342. icon: 'none',
  343. })
  344. return
  345. }
  346. let params = {
  347. raffleId: this.params.raffleId,
  348. }
  349. this.$refs.paymentPopup.show(params, number, this.detail)
  350. },
  351. // 支付成功后回调
  352. paymentSuccess() {
  353. let _this = this
  354. console.log('刷新抽卡界面')
  355. // 刷新界面
  356. _this.refresh()
  357. },
  358. // 选中取消选中卡牌
  359. clickCard(item) {
  360. if (item.status == 0) {
  361. item.check = !item.check
  362. }
  363. // 如果是选中
  364. let index = this.selectIndex.indexOf(item.number)
  365. if (item.check && index == -1) {
  366. this.selectIndex.push(item.number)
  367. } else if (!item.check && index != -1) {
  368. this.selectIndex.splice(index, 1)
  369. }
  370. },
  371. // 标记已经选中卡牌
  372. selectFormat() {
  373. for (var i = 0; i < this.cardList.length; i++) {
  374. if (this.selectIndex.includes(this.cardList[i].number)) {
  375. this.cardList[i].check = true
  376. }
  377. }
  378. },
  379. getCardList() {
  380. prizePoolStatusApi(this.params).then(res => {
  381. console.log(res, '卡牌分页')
  382. for (var i = 0; i < res.data.list.length; i++) {
  383. res.data.list[i].check = false
  384. }
  385. this.cardList = res.data.list
  386. this.selectFormat()
  387. this.total = res.data.total
  388. })
  389. },
  390. left() {
  391. console.log('上一页')
  392. if (this.params.page > 1) {
  393. this.params.page = this.params.page - 1
  394. }
  395. this.getCardList()
  396. },
  397. right() {
  398. console.log('下一页')
  399. let pages = Math.ceil(this.total / this.params.limit)
  400. if (this.params.page < pages) {
  401. this.params.page = this.params.page + 1
  402. }
  403. this.getCardList()
  404. },
  405. },
  406. }
  407. </script>
  408. <style scoped lang="scss">
  409. .container {
  410. background: #9ec8f9;
  411. padding-top: 15px;
  412. overflow: auto;
  413. .refresh {
  414. position: fixed;
  415. right: 4px;
  416. top: 55%;
  417. width: 45px;
  418. }
  419. .head {
  420. background: #fff;
  421. border: 10px;
  422. padding: 15px;
  423. border-radius: 10px 10px 0 0;
  424. display: flex;
  425. justify-content: space-between;
  426. .img {
  427. width: 106px;
  428. height: 106px;
  429. border-radius: 5px;
  430. overflow: hidden;
  431. margin-right: 10px;
  432. }
  433. .info {
  434. display: flex;
  435. flex-direction: column;
  436. justify-content: space-around;
  437. flex: 1;
  438. .row {
  439. display: flex;
  440. justify-content: space-between;
  441. color: #999999;
  442. .button {
  443. width: 67px;
  444. }
  445. .hot {
  446. display: flex;
  447. font-size: 12px;
  448. color: #999999;
  449. image {
  450. width: 16px;
  451. }
  452. }
  453. .users {
  454. position: relative;
  455. .photo {
  456. position: absolute;
  457. width: 20px;
  458. height: 20px;
  459. border-radius: 50%;
  460. }
  461. }
  462. }
  463. .title {
  464. font-weight: 600;
  465. color: #000;
  466. }
  467. .price {
  468. font-size: 14px;
  469. font-weight: 600;
  470. color: #ff2c43;
  471. .text {
  472. color: #999999;
  473. font-weight: 500;
  474. }
  475. }
  476. }
  477. }
  478. .cardList {
  479. margin: 10px 0;
  480. position: relative;
  481. .bk {
  482. width: 100%;
  483. }
  484. .leftButton {
  485. position: absolute;
  486. top: 50%;
  487. transform: translateY(-50%);
  488. left: 20px;
  489. height: 40px;
  490. width: 20px;
  491. z-index: 5;
  492. }
  493. .rightButton {
  494. position: absolute;
  495. top: 50%;
  496. transform: translateY(-50%);
  497. right: 20px;
  498. height: 40px;
  499. width: 20px;
  500. z-index: 5;
  501. }
  502. .list {
  503. padding: 35px 40px;
  504. width: calc(100% - 80px);
  505. height: calc(100% - 70px);
  506. position: absolute;
  507. top: 0;
  508. display: grid;
  509. grid-template-columns: 1fr 1fr 1fr 1fr;
  510. grid-template-rows: 1fr 1fr 1fr;
  511. .item {
  512. display: inline-flex;
  513. justify-content: center;
  514. align-items: center;
  515. position: relative;
  516. .kaBkActive {
  517. height: 132%;
  518. width: 100%;
  519. position: absolute;
  520. z-index: 1;
  521. }
  522. .kaBk {
  523. width: 70%;
  524. border-radius: 4px;
  525. z-index: 2;
  526. }
  527. .num {
  528. position: absolute;
  529. width: 100%;
  530. height: 100%;
  531. top: 0;
  532. z-index: 2;
  533. }
  534. }
  535. .active {
  536. .kaBk {
  537. // box-shadow: 0px 1px 6px 3px rgba(255,77,0,0.65);
  538. }
  539. }
  540. }
  541. }
  542. .buttons {
  543. display: flex;
  544. justify-content: space-between;
  545. align-items: flex-start;
  546. .button1 {
  547. width: 25vw;
  548. }
  549. .button2 {
  550. width: 35vw;
  551. margin-bottom: 5px;
  552. }
  553. }
  554. .lockBox {
  555. margin: 10px 20px;
  556. padding: 10px;
  557. height: 16vw;
  558. background: #fff;
  559. border-radius: 15px;
  560. display: flex;
  561. justify-content: center;
  562. align-items: center;
  563. box-shadow: 1px 2px 2px #459bff;
  564. .text {
  565. color: #459bff;
  566. font-weight: 600;
  567. font-size: 14px;
  568. }
  569. .info {
  570. display: flex;
  571. width: 100%;
  572. justify-content: center;
  573. .photo {
  574. width: 14vw;
  575. height: 14vw;
  576. border-radius: 50%;
  577. }
  578. .right {
  579. margin-left: 10px;
  580. flex: 1;
  581. display: flex;
  582. flex-direction: column;
  583. align-items: center;
  584. justify-content: center;
  585. .row {
  586. width: 100%;
  587. color: #459bff;
  588. font-size: 14px;
  589. margin-bottom: 10px;
  590. position: relative;
  591. display: flex;
  592. align-items: center;
  593. .time {
  594. padding: 5px;
  595. color: #fff;
  596. background: #459bff;
  597. margin: 0 8px;
  598. border-radius: 5px;
  599. font-weight: 600;
  600. font-size: 16px;
  601. }
  602. .name {
  603. font-size: 15px;
  604. font-weight: 600;
  605. color: #459bff;
  606. width: 40%;
  607. white-space: nowrap;
  608. text-overflow: ellipsis;
  609. overflow: hidden;
  610. }
  611. .tip {
  612. font-size: 11px;
  613. position: absolute;
  614. right: 0;
  615. font-weight: 500;
  616. color: #459bff;
  617. }
  618. }
  619. }
  620. }
  621. }
  622. .prizes {
  623. .title {
  624. width: 103px;
  625. margin: 0 auto;
  626. }
  627. .prizesList {
  628. margin: 20px;
  629. position: relative;
  630. overflow: hidden;
  631. // z-index: 5;
  632. .bk {
  633. width: 100%;
  634. height: 100%;
  635. position: absolute;
  636. top: 0;
  637. }
  638. .prizesTitle {
  639. position: relative;
  640. height: 30px;
  641. line-height: 30px;
  642. width: 100%;
  643. margin-left: 1px;
  644. margin-top: 15px;
  645. padding-left: 15px;
  646. color: #fff;
  647. font-weight: 800;
  648. background: linear-gradient(90deg, rgba(89, 166, 255, 0.8) 0%, rgba(158, 200, 249, 0) 100%);
  649. }
  650. .prizesImg {
  651. position: relative;
  652. display: grid;
  653. grid-template-columns: 1fr 1fr;
  654. margin: 15px;
  655. white-space: wrap;
  656. text-align: center;
  657. // overflow: auto;
  658. .image {
  659. text-align: center;
  660. image {
  661. display: inline-block;
  662. width: 36vw;
  663. height: 36vw;
  664. border-radius: 10px;
  665. margin: 0 5px;
  666. }
  667. }
  668. }
  669. .prizesImgOne {
  670. position: relative;
  671. display: flex;
  672. justify-content: center;
  673. margin: 15px;
  674. .image {
  675. text-align: center;
  676. image {
  677. display: inline-block;
  678. width: 45vw;
  679. height: 45vw;
  680. border-radius: 10px;
  681. margin: 0 5px;
  682. }
  683. }
  684. }
  685. }
  686. }
  687. }
  688. </style>