drawCard_last.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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 fontPFR">/张明信片</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="false">本福袋连续购买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. // 离开页面
  156. // 关闭倒计时
  157. clearInterval(this.lockTimeCountdown)
  158. // 关闭心跳
  159. clearInterval(this.socketTimer)
  160. // 关闭对话连接
  161. wx.closeSocket()
  162. },
  163. computed: {
  164. // 锁箱小时
  165. lockHour() {
  166. let tiem = this.lockTime * 1000
  167. let timeText = formatSeconds(tiem)
  168. timeText = timeText.split(':')[0]
  169. return timeText
  170. },
  171. // 锁箱分钟
  172. lockMin() {
  173. let tiem = this.lockTime * 1000
  174. let timeText = formatSeconds(tiem)
  175. timeText = timeText.split(':')[1]
  176. return timeText
  177. },
  178. // 锁箱秒
  179. lockSecond() {
  180. let tiem = this.lockTime * 1000
  181. let timeText = formatSeconds(tiem)
  182. timeText = timeText.split(':')[2]
  183. return timeText
  184. },
  185. },
  186. methods: {
  187. init() {
  188. // 获取卡牌商品列表
  189. this.getCardList()
  190. // 获取卡包详情
  191. this.getDetail()
  192. //获取奖池
  193. this.getPrizeList()
  194. // 初始化锁箱
  195. this.initLock()
  196. // 连接锁箱Socket
  197. this.connectSocket()
  198. },
  199. initLock() {
  200. // 获取锁箱信息
  201. let _this = this
  202. let params = {
  203. raffleId: this.params.raffleId,
  204. }
  205. getLockInfoApi(params).then(res => {
  206. console.log(res, '锁箱')
  207. if (res.data.userId) {
  208. _this.lockData = res.data
  209. _this.lockTime = res.data.expireTime
  210. if (_this.lockTimeCountdown) {
  211. clearInterval(_this.lockTimeCountdown)
  212. _this.lockTimeCountdown = null
  213. }
  214. _this.lockTimeCountdown = setInterval(() => {
  215. _this.lockTime = _this.lockTime - 1
  216. }, 1000)
  217. }
  218. })
  219. },
  220. connectSocket() {
  221. // wss://mall.rongtongh.cn/websocket/raffleId38:uuid1122
  222. let _this = this
  223. let uuid = uuidv4()
  224. let url = 'wss://mall.rongtongh.cn/websocket/raffleId' + this.params.raffleId + ':' + uuid
  225. function connect() {
  226. wx.connectSocket({
  227. url: url,
  228. })
  229. wx.onSocketOpen(function (res) {
  230. console.log(res, 'WebSocket连接已打开!')
  231. // wx.sendSocketMessage({
  232. // data: JSON.stringify(user),
  233. // })
  234. _this.socketTimer = setInterval(function () {
  235. wx.sendSocketMessage({
  236. data: '1',
  237. })
  238. }, 50 * 1000)
  239. })
  240. wx.onSocketMessage(function (res) {
  241. let data = JSON.parse(res.data)
  242. console.log(data, 'WebSocket接受信息')
  243. _this.lockData = res.data
  244. _this.lockTime = res.data.expireTime
  245. })
  246. wx.onSocketClose(function (res) {
  247. console.log('WebSocket连接已关闭!')
  248. setTimeout(() => {
  249. console.log('re connect')
  250. // connect()
  251. }, 2000)
  252. })
  253. }
  254. connect()
  255. },
  256. toKnapsack() {
  257. // 跳转背包界面
  258. wx.navigateTo({
  259. url: '/pages/knapsack/knapsack',
  260. })
  261. },
  262. refresh() {
  263. wx.showLoading()
  264. setTimeout(function () {
  265. wx.hideLoading()
  266. }, 1000)
  267. this.init()
  268. this.selectIndex = []
  269. for (var i = 0; i < this.cardList.length; i++) {
  270. this.cardList[i].check = false
  271. }
  272. },
  273. getPrizeList() {
  274. let params = {
  275. raffleId: this.params.raffleId,
  276. }
  277. prizeListApi(params).then(res => {
  278. console.log(res, '奖池预览')
  279. let newArray = res.data
  280. for (var i = 0; i < res.data.length; i++) {
  281. if (res.data[i].type == 22) {
  282. newArray = []
  283. newArray.push(res.data[i])
  284. res.data.splice(i, 1)
  285. newArray.push(...res.data)
  286. break
  287. }
  288. }
  289. this.prizeList = newArray
  290. })
  291. },
  292. toWinningRecord() {
  293. let params = {
  294. raffleId: this.params.raffleId,
  295. }
  296. this.$navigateTo('/pages/winningRecord/winningRecord', params)
  297. },
  298. getDetail() {
  299. let params = {
  300. raffleId: this.params.raffleId,
  301. }
  302. raffleDetailApi(params).then(res => {
  303. console.log(res, '详情')
  304. this.detail = res.data
  305. })
  306. },
  307. submit() {
  308. // 购买时判断锁箱
  309. if (this.lockData.userId && this.userId != this.lockData) {
  310. wx.showToast({
  311. title: '锁箱中无法购买。',
  312. icon: 'none',
  313. })
  314. return
  315. }
  316. if (this.selectIndex.length == 0) {
  317. wx.showToast({
  318. title: '请选则要购买的卡牌。',
  319. icon: 'none',
  320. })
  321. return
  322. }
  323. this.$refs.paymentPopup.show(this.params.raffleId, this.selectIndex, this.detail)
  324. },
  325. // 支付成功后回调
  326. paymentSuccess() {
  327. let _this = this
  328. console.log('刷新抽卡界面')
  329. // 刷新界面
  330. _this.refresh()
  331. },
  332. // 选中取消选中卡牌
  333. clickCard(item) {
  334. if (item.status == 0) {
  335. item.check = !item.check
  336. }
  337. // 如果是选中
  338. let index = this.selectIndex.indexOf(item.number)
  339. if (item.check && index == -1) {
  340. this.selectIndex.push(item.number)
  341. } else if (!item.check && index != -1) {
  342. this.selectIndex.splice(index, 1)
  343. }
  344. },
  345. // 标记已经选中卡牌
  346. selectFormat() {
  347. for (var i = 0; i < this.cardList.length; i++) {
  348. if (this.selectIndex.includes(this.cardList[i].number)) {
  349. this.cardList[i].check = true
  350. }
  351. }
  352. },
  353. getCardList() {
  354. prizePoolStatusApi(this.params).then(res => {
  355. console.log(res, '卡牌分页')
  356. for (var i = 0; i < res.data.list.length; i++) {
  357. res.data.list[i].check = false
  358. }
  359. this.cardList = res.data.list
  360. this.selectFormat()
  361. this.total = res.data.total
  362. })
  363. },
  364. left() {
  365. console.log('上一页')
  366. if (this.params.page > 1) {
  367. this.params.page = this.params.page - 1
  368. }
  369. this.getCardList()
  370. },
  371. right() {
  372. console.log('下一页')
  373. let pages = Math.ceil(this.total / this.params.limit)
  374. if (this.params.page < pages) {
  375. this.params.page = this.params.page + 1
  376. }
  377. this.getCardList()
  378. },
  379. },
  380. }
  381. </script>
  382. <style scoped lang="scss">
  383. .container {
  384. background: #9ec8f9;
  385. padding-top: 15px;
  386. overflow: auto;
  387. .refresh {
  388. position: fixed;
  389. right: 4px;
  390. top: 55%;
  391. width: 45px;
  392. }
  393. .head {
  394. background: #fff;
  395. border: 10px;
  396. padding: 15px;
  397. border-radius: 10px 10px 0 0;
  398. display: flex;
  399. justify-content: space-between;
  400. .img {
  401. width: 106px;
  402. height: 106px;
  403. border-radius: 5px;
  404. overflow: hidden;
  405. margin-right: 10px;
  406. }
  407. .info {
  408. display: flex;
  409. flex-direction: column;
  410. justify-content: space-around;
  411. flex: 1;
  412. .row {
  413. display: flex;
  414. justify-content: space-between;
  415. color: #999999;
  416. .button {
  417. width: 67px;
  418. }
  419. .hot {
  420. display: flex;
  421. font-size: 12px;
  422. color: #999999;
  423. image {
  424. width: 16px;
  425. }
  426. }
  427. .users {
  428. position: relative;
  429. .photo {
  430. position: absolute;
  431. width: 20px;
  432. height: 20px;
  433. border-radius: 50%;
  434. }
  435. }
  436. }
  437. .title {
  438. font-weight: 600;
  439. color: #000;
  440. }
  441. .price {
  442. font-size: 14px;
  443. font-weight: 600;
  444. color: #ff2c43;
  445. .text {
  446. color: #999999;
  447. font-weight: 500;
  448. }
  449. }
  450. }
  451. }
  452. .cardList {
  453. margin: 10px 0;
  454. position: relative;
  455. .bk {
  456. width: 100%;
  457. }
  458. .leftButton {
  459. position: absolute;
  460. top: 50%;
  461. transform: translateY(-50%);
  462. left: 20px;
  463. height: 40px;
  464. width: 20px;
  465. z-index: 5;
  466. }
  467. .rightButton {
  468. position: absolute;
  469. top: 50%;
  470. transform: translateY(-50%);
  471. right: 20px;
  472. height: 40px;
  473. width: 20px;
  474. z-index: 5;
  475. }
  476. .list {
  477. padding: 35px 40px;
  478. width: calc(100% - 80px);
  479. height: calc(100% - 70px);
  480. position: absolute;
  481. top: 0;
  482. display: grid;
  483. grid-template-columns: 1fr 1fr 1fr 1fr;
  484. grid-template-rows: 1fr 1fr 1fr;
  485. .item {
  486. display: inline-flex;
  487. justify-content: center;
  488. align-items: center;
  489. position: relative;
  490. .kaBkActive {
  491. height: 132%;
  492. width: 100%;
  493. position: absolute;
  494. z-index: 1;
  495. }
  496. .kaBk {
  497. width: 70%;
  498. border-radius: 4px;
  499. z-index: 2;
  500. }
  501. .num {
  502. position: absolute;
  503. width: 100%;
  504. height: 100%;
  505. top: 0;
  506. z-index: 2;
  507. }
  508. }
  509. .active {
  510. .kaBk {
  511. // box-shadow: 0px 1px 6px 3px rgba(255,77,0,0.65);
  512. }
  513. }
  514. }
  515. }
  516. .buttons {
  517. display: flex;
  518. justify-content: space-between;
  519. align-items: flex-start;
  520. .button1 {
  521. width: 25vw;
  522. }
  523. .button2 {
  524. width: 35vw;
  525. margin-bottom: 5px;
  526. }
  527. }
  528. .lockBox {
  529. margin: 10px 20px;
  530. padding: 10px;
  531. height: 16vw;
  532. background: #fff;
  533. border-radius: 15px;
  534. display: flex;
  535. justify-content: center;
  536. align-items: center;
  537. box-shadow: 1px 2px 2px #459bff;
  538. .text {
  539. color: #459bff;
  540. font-weight: 600;
  541. font-size: 14px;
  542. }
  543. .info {
  544. display: flex;
  545. width: 100%;
  546. justify-content: center;
  547. .photo {
  548. width: 14vw;
  549. height: 14vw;
  550. border-radius: 50%;
  551. }
  552. .right {
  553. margin-left: 10px;
  554. flex: 1;
  555. display: flex;
  556. flex-direction: column;
  557. align-items: center;
  558. justify-content: center;
  559. .row {
  560. width: 100%;
  561. color: #459bff;
  562. font-size: 14px;
  563. margin-bottom: 10px;
  564. position: relative;
  565. display: flex;
  566. align-items: center;
  567. .time {
  568. padding: 5px;
  569. color: #fff;
  570. background: #459bff;
  571. margin: 0 8px;
  572. border-radius: 5px;
  573. font-weight: 600;
  574. font-size: 16px;
  575. }
  576. .name {
  577. font-size: 15px;
  578. font-weight: 600;
  579. color: #459bff;
  580. width: 40%;
  581. white-space: nowrap;
  582. text-overflow: ellipsis;
  583. overflow: hidden;
  584. }
  585. .tip {
  586. font-size: 11px;
  587. position: absolute;
  588. right: 0;
  589. font-weight: 500;
  590. color: #459bff;
  591. }
  592. }
  593. }
  594. }
  595. }
  596. .prizes {
  597. .title {
  598. width: 103px;
  599. margin: 0 auto;
  600. }
  601. .prizesList {
  602. margin: 20px;
  603. position: relative;
  604. overflow: hidden;
  605. // z-index: 5;
  606. .bk {
  607. width: 100%;
  608. height: 100%;
  609. position: absolute;
  610. top: 0;
  611. }
  612. .prizesTitle {
  613. position: relative;
  614. height: 30px;
  615. line-height: 30px;
  616. width: 100%;
  617. margin-left: 1px;
  618. margin-top: 15px;
  619. padding-left: 15px;
  620. color: #fff;
  621. font-weight: 800;
  622. background: linear-gradient(90deg, rgba(89, 166, 255, 0.8) 0%, rgba(158, 200, 249, 0) 100%);
  623. }
  624. .prizesImg {
  625. position: relative;
  626. display: grid;
  627. grid-template-columns: 1fr 1fr;
  628. margin: 15px;
  629. white-space: wrap;
  630. text-align: center;
  631. // overflow: auto;
  632. .image {
  633. text-align: center;
  634. image {
  635. display: inline-block;
  636. width: 36vw;
  637. height: 36vw;
  638. border-radius: 10px;
  639. margin: 0 5px;
  640. }
  641. }
  642. }
  643. .prizesImgOne {
  644. position: relative;
  645. display: flex;
  646. justify-content: center;
  647. margin: 15px;
  648. .image {
  649. text-align: center;
  650. image {
  651. display: inline-block;
  652. width: 45vw;
  653. height: 45vw;
  654. border-radius: 10px;
  655. margin: 0 5px;
  656. }
  657. }
  658. }
  659. }
  660. }
  661. }
  662. </style>