index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. <template>
  2. <view class="common">
  3. <view class="body">
  4. <view class="top-class"></view>
  5. <view class="title">
  6. 梅山古镇
  7. </view>
  8. <view class="head">
  9. <u-swiper :list="list1"></u-swiper>
  10. </view>
  11. <view class="text">
  12. <image src="https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/text.png"
  13. class="textImage"></image>
  14. </view>
  15. <view class="content">
  16. <view class="chouka" style="width: 100%;">
  17. <view class="" style="margin-bottom: 10px;">
  18. <u-row justify="space-between"
  19. customStyle="margin-bottom: 5px;display: flex; align-items: center;">
  20. <u-col span="4">
  21. </u-col>
  22. <u-col span="4" class="center-col">
  23. <view class="text-1">翻卡抽盲盒</view>
  24. </u-col>
  25. <u-col span="4" class="right-col">
  26. <view class="text-2" @click="openDetail()">活动规则</view>
  27. </u-col>
  28. </u-row>
  29. </view>
  30. <template>
  31. <!-- 卡片区 -->
  32. <view class="cards">
  33. <view class="card" v-for="(item, idx) in cards" :key="idx" @click="flipCard(idx)"
  34. :class="{ 'flipping': item.isFlipping, 'flipped': item.flipped }">
  35. <view v-if="item.checkStauts" class="select-tag">
  36. 已选
  37. </view>
  38. <view class="card-inner">
  39. <view class="card-front">
  40. <image class="card-img" :src="item.front" mode="scaleToFill"></image>
  41. </view>
  42. <view class="card-back">
  43. <image class="card-img" :src="item.prizeType == 2 ? item.img : item.back"
  44. mode="scaleToFill"></image>
  45. <view class="card-back-text">
  46. <view v-show="item.prizeType == 0" class="card-text">很遗憾</view>
  47. <view v-show="item.prizeType == 1" class="card-text">{{item.money/100}}元红包
  48. </view>
  49. <view v-show="item.prizeType == 0" class="card-text">下次继续</view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. </view>
  57. </view>
  58. </view>
  59. <u-popup :show="showWin" :round="10" mode="center" @close="close" @open="open" closeable="true">
  60. <view class="popup-flex">
  61. <view class="popup-content-scroll">
  62. <!-- 这里放原来的内容部分(除返回按钮) -->
  63. <view class="popup-view">
  64. <image src="https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/win.png"
  65. class="winImgClss"></image>
  66. </view>
  67. <view class="popup-content">
  68. <u-row customStyle="margin-bottom: 5px">
  69. <u-col span="6">
  70. <image :src="prizeJson.img" class="prize"></image>
  71. </u-col>
  72. <u-col span="6">
  73. <view>{{prizeJson.prize_name}}</view>
  74. </u-col>
  75. </u-row>
  76. <view class="popup-text">
  77. 请留下联系方式,稍后工作人员会联系您!
  78. </view>
  79. <u--form labelPosition="left" :model="model1" :rules="rules" ref="uForm">
  80. <u-form-item label="姓名" prop="userInfo.name" ref="item1">
  81. <u--input v-model="model1.userInfo.name" border="none"></u--input>
  82. </u-form-item>
  83. <u-form-item label="电话" prop="userInfo.tel" ref="item1">
  84. <u--input v-model="model1.userInfo.tel" border="none"></u--input>
  85. </u-form-item>
  86. </u--form>
  87. </view>
  88. </view>
  89. <view class="popup-footer">
  90. <view class="save-button" @click="addWinDetail()">领取</view>
  91. </view>
  92. </view>
  93. </u-popup>
  94. <u-popup :show="showUnWin" :round="10" mode="center" @close="close" @open="open" closeable="true">
  95. <view class="popup-flex">
  96. <view class="popup-content-scroll">
  97. <!-- 这里放原来的内容部分(除返回按钮) -->
  98. <view class="popup-view">
  99. <image src="https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/unWin.png"
  100. class="winImgClss"></image>
  101. </view>
  102. <view class="popup-content">
  103. <view class="">
  104. <image class="productImg" mode="widthFix"
  105. src="https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/product.png ">
  106. </image>
  107. </view>
  108. <view class="">
  109. {{ randomText }}
  110. </view>
  111. </view>
  112. </view>
  113. <view class="popup-footer">
  114. <view class="save-button unWin" @click="close()">我知道了</view>
  115. </view>
  116. </view>
  117. </u-popup>
  118. <CustomTabbar />
  119. </view>
  120. </template>
  121. <script>
  122. import { randomTexts } from '../../../utils/randomTexts.js';
  123. import CustomTabbar from '@/components/tabbar.vue';
  124. import {
  125. addWinDetail,
  126. saveCardData
  127. } from '@/api/scan'
  128. export default {
  129. components: {
  130. CustomTabbar
  131. },
  132. data() {
  133. return {
  134. rules: {
  135. 'userInfo.name': {
  136. type: 'string',
  137. required: true,
  138. message: '请填写姓名',
  139. trigger: ['blur', 'change']
  140. },
  141. 'userInfo.tel': {
  142. type: 'string',
  143. required: true,
  144. message: '请填写手机号',
  145. trigger: ['blur', 'change']
  146. },
  147. },
  148. model1: {
  149. userInfo: {
  150. name: '',
  151. tel: '',
  152. qrcodeId: ''
  153. },
  154. },
  155. showUnWin: false,
  156. showWin: false,
  157. list1: [
  158. "https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/commodity/1.jpg",
  159. "https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/commodity/2.jpg",
  160. "https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/commodity/3.jpg",
  161. "https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/commodity/4.jpg",
  162. "https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/commodity/5.jpg",
  163. ],
  164. cards: [{
  165. front: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/one.png',
  166. back: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/bgiCard.png',
  167. flipped: false,
  168. prizeName: '',
  169. title: '',
  170. checkStauts: false,
  171. img: '',
  172. money: '',
  173. prizeType: '',
  174. isFlipping: false
  175. },
  176. {
  177. front: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/two.png',
  178. back: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/bgiCard.png',
  179. flipped: false,
  180. prizeName: '',
  181. title: '',
  182. checkStauts: false,
  183. img: '',
  184. money: '',
  185. prizeType: '',
  186. isFlipping: false
  187. },
  188. {
  189. front: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/three.png',
  190. back: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/bgiCard.png',
  191. flipped: false,
  192. prizeName: '',
  193. title: '',
  194. checkStauts: false,
  195. img: '',
  196. money: '',
  197. prizeType: '',
  198. isFlipping: false
  199. },
  200. {
  201. front: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/four.png',
  202. back: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/bgiCard.png',
  203. flipped: false,
  204. prizeName: '',
  205. title: '',
  206. checkStauts: false,
  207. img: '',
  208. money: '',
  209. prizeType: '',
  210. isFlipping: false
  211. },
  212. {
  213. front: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/five.png',
  214. back: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/bgiCard.png',
  215. flipped: false,
  216. prizeName: '',
  217. title: '',
  218. checkStauts: false,
  219. img: '',
  220. money: '',
  221. prizeType: '',
  222. isFlipping: false
  223. },
  224. {
  225. front: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/six.png',
  226. back: 'https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/bgiCard.png',
  227. flipped: false,
  228. prizeName: '',
  229. title: '',
  230. checkStauts: false,
  231. img: '',
  232. money: '',
  233. prizeType: '',
  234. isFlipping: false
  235. }
  236. ],
  237. totalDetail: '',
  238. prizeJson: {},
  239. saveData: {},
  240. scanCode: '',
  241. saveStatus: true,
  242. fankaStatu:false,
  243. randomText: ""
  244. }
  245. },
  246. onLoad() {
  247. this.setRandomText();
  248. let scanDetail = uni.getStorageSync('scanDetail');
  249. this.scanCode = uni.getStorageSync('scanCode');
  250. this.model1.userInfo.qrcodeId = this.scanCode;
  251. this.prizeJson = scanDetail.prizeJson;
  252. let planDetail = JSON.parse(scanDetail.planDetail);
  253. while (planDetail.length < 5) {
  254. planDetail.push({
  255. 'prizeType': 0,
  256. 'money': 0
  257. })
  258. }
  259. this.totalDetail = planDetail;
  260. console.log(planDetail);
  261. if (scanDetail.result.click) {
  262. this.initCardData(scanDetail.clickJson);
  263. }
  264. },
  265. methods: {
  266. setRandomText() {
  267. const randomIndex = Math.floor(Math.random() * randomTexts.length);
  268. this.randomText = randomTexts[randomIndex];
  269. },
  270. initCardData(clickJson) {
  271. let list = JSON.parse(clickJson);
  272. for (let i = 0; i < this.cards.length; i++) {
  273. if (i == list.index) {
  274. this.cards[i].checkStauts = true
  275. }
  276. this.cards[i].img = list['card' + i].img;
  277. this.cards[i].flipped = true;
  278. this.cards[i].prizeType = list['card' + i].prize_type == undefined ? list['card' + i].prizeType : list[
  279. 'card' + i].prize_type;
  280. this.cards[i].money = list['card' + i].money;
  281. this.cards[i].prizeName = list['card' + i].prizeName == undefined ? list['card' + i].prize_name : list[
  282. 'card' + i].prizeName;
  283. }
  284. this.$forceUpdate();
  285. },
  286. addWinDetail() {
  287. let that = this;
  288. this.$refs.uForm.validate().then(res => {
  289. addWinDetail(that.model1.userInfo).then(data => {
  290. this.showWin = false;
  291. if (data.code == 0) {
  292. that.saveStatus = false;
  293. // uni.redirectTo({
  294. // url: '/pages/lgz/index/claim' // 目标页面路径
  295. // })
  296. let params = {
  297. type: "success",
  298. title: "成功主题(带图标)",
  299. message: "提交成功",
  300. iconUrl: "https://uviewui.com/demo/toast/success.png",
  301. }
  302. that.$refs.uToast.show({
  303. ...params
  304. });
  305. } else {
  306. }
  307. })
  308. }).catch(errors => {
  309. })
  310. },
  311. open() {
  312. // console.log('open');
  313. },
  314. close() {
  315. this.showUnWin = false;
  316. this.showWin = false
  317. },
  318. flipCard(idx) {
  319. if(this.fankaStatu){
  320. return;
  321. }
  322. if (this.cards[idx].flipped) {
  323. return;
  324. }
  325. this.fankaStatu = true;
  326. setTimeout(() => {
  327. if (this.prizeJson.prizeType == 0 || this.prizeJson.prize_type == 0) {
  328. this.showUnWin = true;
  329. }
  330. if ((this.prizeJson.prizeType == 2 || this.prizeJson.prize_type == 2) && this.saveStatus) {
  331. this.showWin = true;
  332. }
  333. }, 2500); //弹框延迟3.5秒后显示弹框
  334. // 标记被点击的卡牌正在翻转
  335. this.cards[idx].isFlipping = true;
  336. this.cards[idx].checkStauts = true;
  337. let that = this;
  338. // 延迟翻转其他卡牌
  339. setTimeout(() => {
  340. that.cards[idx].flipped = true;
  341. that.cards[idx].isFlipping = false;
  342. // 其他未翻转的卡牌延迟2秒后同时翻转
  343. setTimeout(() => {
  344. that.cards.forEach((card, index) => {
  345. if (index !== idx && !card.flipped) {
  346. card.isFlipping = true;
  347. that.$forceUpdate();
  348. }
  349. });
  350. // 所有其他卡牌同时翻转
  351. setTimeout(() => {
  352. that.cards.forEach((card, index) => {
  353. if (index !== idx && !card.flipped) {
  354. card.flipped = true;
  355. card.isFlipping = false;
  356. that.$forceUpdate();
  357. }
  358. });
  359. }, 300); // 与其他卡牌翻转动画保持一致
  360. }, 1000); // 延迟2秒翻转其他卡牌
  361. // 处理数据逻辑
  362. that.totalDetail.splice(idx, 0, this.prizeJson);
  363. that.saveData.index = idx;
  364. for (let i = 0; i < that.totalDetail.length; i++) {
  365. that.saveData['card' + i] = that.totalDetail[i];
  366. that.cards[i].prizeType = that.totalDetail[i].prize_type == undefined ?
  367. that.totalDetail[i].prizeType :
  368. that.totalDetail[i].prize_type;
  369. that.cards[i].img = that.totalDetail[i].img;
  370. that.cards[i].money = that.totalDetail[i].money;
  371. that.cards[i].prizeName = that.totalDetail[i].prizeName == undefined ?
  372. that.totalDetail[i].prize_name :
  373. that.totalDetail[i].prizeName;
  374. }
  375. that.saveAllCardData();
  376. }, 100);
  377. },
  378. saveAllCardData() {
  379. let jsonStr = JSON.stringify(this.saveData);
  380. saveCardData(this.scanCode, jsonStr).then(res => {
  381. console.log(res)
  382. })
  383. },
  384. openDetail() {
  385. uni.navigateTo({
  386. url: '/pages/lgz/index/rules'
  387. });
  388. }
  389. }
  390. }
  391. </script>
  392. <style>
  393. @import url('../../../static/scss/common.css');
  394. .common {
  395. background-image:
  396. url("https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/bgi-two.png");
  397. }
  398. .head {
  399. background-image:
  400. url("https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/zhanshi.png");
  401. background-size: cover;
  402. background-position: center;
  403. background-repeat: no-repeat;
  404. height: 23vh;
  405. margin: 0px 40rpx;
  406. display: flex;
  407. justify-content: center;
  408. /* 水平居中 */
  409. align-items: center;
  410. /* 垂直居中 */
  411. }
  412. .text {
  413. height: 10vh;
  414. text-align: center;
  415. line-height: 13vh;
  416. margin-bottom: 10rpx;
  417. }
  418. .textImage {
  419. height: 80rpx;
  420. width: 400rpx;
  421. }
  422. .content {
  423. height: 42vh;
  424. background: rgba(131, 100, 71, 0.5);
  425. border-radius: 10rpx;
  426. margin: 0rpx 40rpx;
  427. padding: 10rpx 24rpx;
  428. overflow: auto;
  429. display: flex;
  430. align-items: center;
  431. justify-content: center;
  432. }
  433. .text-1 {
  434. text-align: center;
  435. font-size: 24rpx;
  436. font-weight: 600;
  437. color: white;
  438. background-color: #9A1712;
  439. width: 160rpx;
  440. border-radius: 4rpx;
  441. height: 40rpx;
  442. line-height: 40rpx;
  443. }
  444. .text-2 {
  445. text-align: center;
  446. font-size: 24rpx;
  447. font-weight: 600;
  448. color: #F9D395;
  449. background-color: #9A1712;
  450. width: 120rpx;
  451. border-radius: 4rpx;
  452. height: 40rpx;
  453. line-height: 40rpx;
  454. margin-left: 80rpx;
  455. }
  456. .cards {
  457. display: grid;
  458. grid-template-columns: repeat(3, 1fr);
  459. gap: 30rpx;
  460. width: 100%;
  461. }
  462. .card {
  463. width: 100%;
  464. height: 250rpx;
  465. position: relative;
  466. background: none;
  467. border-radius: 16rpx;
  468. margin: 0;
  469. perspective: 1000px;
  470. }
  471. .card-inner {
  472. position: relative;
  473. width: 100%;
  474. height: 100%;
  475. transition: transform 0.8s cubic-bezier(0.5, 1.5, 0.5, 1);
  476. transform-style: preserve-3d;
  477. }
  478. .card.flipping .card-inner {
  479. transform: rotateY(180deg);
  480. }
  481. .card.flipped .card-inner {
  482. transform: rotateY(180deg);
  483. }
  484. .card-front,
  485. .card-back {
  486. position: absolute;
  487. width: 100%;
  488. height: 100%;
  489. backface-visibility: hidden;
  490. }
  491. .card-back {
  492. transform: rotateY(180deg);
  493. }
  494. .card-back-text {
  495. position: absolute;
  496. top: 50%;
  497. left: 0;
  498. width: 100%;
  499. text-align: center;
  500. color: #9A1712;
  501. font-weight: bold;
  502. font-size: 28rpx;
  503. transform: translateY(-50%);
  504. z-index: 2;
  505. pointer-events: none;
  506. }
  507. .card-img {
  508. width: 100%;
  509. height: 100%;
  510. display: block;
  511. }
  512. ::v-deep .u-popup__content {
  513. height: 720rpx;
  514. width: 600rpx;
  515. background-color: rgba(0, 0, 0, 0) !important;
  516. background-image:
  517. url("https://hyscancode.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/guzhenganzi/bgiPopup.png");
  518. background-size: cover;
  519. background-position: center;
  520. background-repeat: no-repeat;
  521. }
  522. ::v-deep .u-popup__content__close--top-right {
  523. top: 720rpx !important;
  524. right: 288rpx !important;
  525. }
  526. .winImgClss {
  527. height: 60rpx;
  528. width: 320rpx;
  529. }
  530. .popup-view {
  531. text-align: center;
  532. margin-top: 100rpx;
  533. }
  534. .popup-content {
  535. margin: 15px 54px;
  536. overflow: auto;
  537. }
  538. .popup-text {
  539. font-weight: 400;
  540. font-size: 20rpx;
  541. color: #9B0000;
  542. }
  543. .prize {
  544. height: 130rpx;
  545. width: 130rpx;
  546. }
  547. ::v-deep .u-form-item__body {
  548. padding: 8rpx;
  549. }
  550. ::v-deep uni-view.u-form-item__body__left {
  551. background: #AD7F55;
  552. border-radius: 5px 0px 0px 5px;
  553. border: 2px solid #63462B;
  554. border-right: none;
  555. }
  556. ::v-deep .u-form-item__body__right {
  557. background-color: #fff;
  558. border-radius: 0px 5px 5px 0px;
  559. border: 2px solid #63462B;
  560. }
  561. ::v-deep uni-text.u-form-item__body__left__content__label {
  562. color: #fff !important;
  563. padding-left: 4px;
  564. letter-spacing: 2px;
  565. }
  566. .popup-flex {
  567. display: flex;
  568. flex-direction: column;
  569. height: 100%;
  570. /* 或具体高度如340px,确保撑满弹窗 */
  571. min-width: 600rpx;
  572. }
  573. .popup-content-scroll {
  574. flex: 1;
  575. }
  576. .popup-footer {
  577. flex-shrink: 0;
  578. padding: 0rpx 0 60rpx 0px;
  579. text-align: center;
  580. background: transparent;
  581. /* 可选,确保无背景遮挡 */
  582. }
  583. .save-button {
  584. width: 90rpx;
  585. margin: 0 auto;
  586. background: #b22222;
  587. color: #F9D395;
  588. border-radius: 12rpx;
  589. padding: 18rpx 0;
  590. font-size: 24rpx;
  591. font-weight: bold;
  592. height: 16rpx;
  593. line-height: 16rpx;
  594. letter-spacing: 4rpx;
  595. }
  596. .unWin {
  597. width: 130rpx !important;
  598. }
  599. .productImg {
  600. width: 400rpx;
  601. }
  602. ::v-deep .u-swiper {
  603. background-color: rgba(0, 0, 0, 0) !important;
  604. padding: 0px 20rpx !important;
  605. width: 90%;
  606. }
  607. ::v-deep .u-col-4 {
  608. display: flex !important;
  609. justify-content: center !important;
  610. /* 水平居中 */
  611. align-items: center !important;
  612. /* 垂直居中 */
  613. }
  614. ::v-deep .right-col .u-col-4 {
  615. display: flex !important;
  616. justify-content: flex-end !important;
  617. /* 水平居中 */
  618. align-items: center !important;
  619. /* 垂直居中 */
  620. }
  621. .card-img-f {
  622. height: 100rpx;
  623. width: 100rpx;
  624. }
  625. .card-text {
  626. font-size: 26rpx;
  627. }
  628. .select-tag {
  629. position: absolute;
  630. right: 0px;
  631. font-weight: 400;
  632. font-size: 20rpx;
  633. color: #FFFFFF;
  634. width: 40px;
  635. text-align: center;
  636. background-color: #11BC64;
  637. height: 15px;
  638. border-radius: 3px;
  639. line-height: 15px;
  640. z-index: 5;
  641. }
  642. </style>