drawCard_last.vue 18 KB

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