coupon.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <template>
  2. <view class="content">
  3. <view class="navbar">
  4. <view v-for="(item, index) in navList" :key="index" class="nav-item"
  5. :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  6. </view>
  7. <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
  8. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  9. <!-- 空白页 -->
  10. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  11. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData()">
  12. <view v-for="(item, index) in tabItem.orderList" :key="index" class="main-item">
  13. <view class="main-item-top flex">
  14. <view class="main-item-top-bg">
  15. <image src="../../static/img/cardTop.png" mode=""></image>
  16. </view>
  17. <view class="main-item-top-left">
  18. <view class="main-item-title">{{ item.name }}</view>
  19. <view class="main-item-time">购买时间{{ item.create_time }}</view>
  20. </view>
  21. <view class="main-item-type">{{ item.type == 1 ? '时效卡' : '次卡' }}</view>
  22. </view>
  23. <view class="main-item-bottom">
  24. <view class="main-item-bottom-bg">
  25. <image src="../../static/img/cardbottom.png" mode=""></image>
  26. </view>
  27. <view class="flex">
  28. <view class="main-item-price">
  29. <text class="fh">卡券码:</text>
  30. {{ item.card }}
  31. <text class="time" @click="copy(item.card)">复制</text>
  32. </view>
  33. <view class="main-item-bottom-type" v-if="tabCurrentIndex == 2">已过期</view>
  34. <view class="main-item-info-right" v-if="tabCurrentIndex == 0">
  35. <view class="main-item-info-font"
  36. @click="navTo('/pages/user/mycardDetail?id=' + item.id)">查看详情</view>
  37. <view class="main-item-info-icon">
  38. <image src="../../static/img/img39.png" mode=""></image>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="main-item-info flex">
  43. <view class="main-item-info-left" v-if="tabCurrentIndex == 1 && item.type == 1">
  44. {{ item.end_time }}后失效</view>
  45. <view class="main-item-info-left" v-if="tabCurrentIndex == 1 && item.type == 2">
  46. 总使用次数{{ item.number }}</view>
  47. <view class="flex" v-if="tabCurrentIndex == 0 && !item.show">
  48. <view class="info">
  49. 激活密码:
  50. <text v-for="l in item.pwd.length">*</text>
  51. </view>
  52. <image class="image" src="../../static/img/img43.png" @click="showPick(item)">
  53. </image>
  54. <!-- <view class="copy">复制</view> -->
  55. </view>
  56. <view class="flex" v-if="tabCurrentIndex == 0 && item.show">
  57. <view class="info">激活密码:{{ item.pwd }}</view>
  58. <image class="image" src="../../static/img/img29.png" @click="showPick(item)">
  59. </image>
  60. <view class="copy" @click="copy(item.pwd)">复制</view>
  61. </view>
  62. <view class="main-item-info-left" v-if="tabCurrentIndex == 2">卡券已被激活</view>
  63. <view class="main-item-info-btn" @click="jihuo(item)" v-if="tabCurrentIndex == 0">一键激活
  64. </view>
  65. <view class="main-item-info-right" v-if="tabCurrentIndex != 0">
  66. <view class="main-item-info-font"
  67. @click="navTo('/pages/user/mycardDetail?id=' + item.id)">查看详情</view>
  68. <view class="main-item-info-icon">
  69. <image src="../../static/img/img39.png" mode=""></image>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <uni-load-more :status="tabItem.loadingType"></uni-load-more>
  76. </scroll-view>
  77. </swiper-item>
  78. </swiper>
  79. <view class="btn" @click="openPopup()">卡券激活</view>
  80. <uni-popup ref="popup" type="center">
  81. <view class="img1">
  82. <image src="../../static/img/jh3.png" mode=""></image>
  83. </view>
  84. <view class="popup-box">
  85. <view class="img">
  86. <image src="../../static/img/jh1.png" mode=""></image>
  87. </view>
  88. <view class="mian">
  89. <view class="delivery">
  90. <view class="title">卡券激活</view>
  91. </view>
  92. <view class="comfirm-box">
  93. <view class="input"><input type="text" v-model="card" placeholder="请输入卡号" /></view>
  94. <view class="input"><input type="text" v-model="pwd" placeholder="请输入密码" /></view>
  95. </view>
  96. <view class="popup-btn" @click="jihuo()">立即激活</view>
  97. </view>
  98. </view>
  99. <view class="x" @click="cancel()">
  100. <image src="../../static/img/jh2.png" mode=""></image>
  101. </view>
  102. </uni-popup>
  103. </view>
  104. </template>
  105. <script>
  106. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  107. import empty from '@/components/empty';
  108. import {
  109. getCouponsList,
  110. use_card
  111. } from '@/api/jdr.js';
  112. import uniCopy from '@/utils/uni-copy.js';
  113. import {
  114. getTime
  115. } from '@/utils/rocessor.js';
  116. export default {
  117. components: {
  118. uniLoadMore,
  119. empty
  120. },
  121. data() {
  122. return {
  123. tabCurrentIndex: 0,
  124. pwd: '',
  125. card: '',
  126. navList: [{
  127. state: 1,
  128. text: '未使用',
  129. loadingType: 'more',
  130. orderList: [],
  131. page: 1, //当前页数
  132. limit: 10 //每次信息条数
  133. },
  134. {
  135. state: 2,
  136. text: '使用中',
  137. loadingType: 'more',
  138. orderList: [],
  139. page: 1, //当前页数
  140. limit: 10 //每次信息条数
  141. },
  142. {
  143. state: 3,
  144. text: '已失效',
  145. loadingType: 'more',
  146. orderList: [],
  147. page: 1, //当前页数
  148. limit: 10 //每次信息条数
  149. }
  150. ]
  151. };
  152. },
  153. onLoad(options) {
  154. this.loadData();
  155. },
  156. methods: {
  157. //返回首页
  158. navTo(url) {
  159. uni.navigateTo({
  160. url
  161. });
  162. },
  163. showPick(item) {
  164. item.show = !item.show;
  165. },
  166. //获取订单列表
  167. loadData(source) {
  168. //将订单挂载到tab列表下
  169. let index = this.tabCurrentIndex;
  170. let navItem = this.navList[index];
  171. let state = navItem.state;
  172. if (source === 'shua') {
  173. navItem.loaded = false;
  174. navItem.page = 1;
  175. navItem.limit = 10;
  176. navItem.loadingType = 'more';
  177. navItem.orderList = [];
  178. }
  179. if (source === 'tabChange' && navItem.loaded === true) {
  180. //tab切换只有第一次需要加载数据
  181. return;
  182. }
  183. if (navItem.loadingType === 'loading' || navItem.loadingType === 'noMore') {
  184. //防止重复加载
  185. return;
  186. }
  187. console.log(navItem.loadingType, '状态');
  188. //修改当前对象状态为加载中
  189. navItem.loadingType = 'loading';
  190. getCouponsList({
  191. page: navItem.page,
  192. limit: navItem.limit,
  193. status: state
  194. })
  195. .then(({
  196. data
  197. }) => {
  198. data.forEach(e => {
  199. e.show = false;
  200. e.end_time = getTime(e.end_time);
  201. });
  202. navItem.orderList = navItem.orderList.concat(data);
  203. console.log(navItem.orderList);
  204. navItem.page++;
  205. if (navItem.limit == data.length) {
  206. // 判断是否还有数据,有改为more,没有改为noMore
  207. navItem.loadingType = 'more';
  208. return;
  209. } else {
  210. navItem.loadingType = 'noMore';
  211. }
  212. uni.hideLoading();
  213. this.$set(navItem, 'loaded', true);
  214. })
  215. .catch(e => {
  216. console.log(e);
  217. });
  218. },
  219. //swiper 切换
  220. changeTab(e) {
  221. this.tabCurrentIndex = e.target.current;
  222. this.loadData('tabChange');
  223. },
  224. //顶部tab点击
  225. tabClick(index) {
  226. this.tabCurrentIndex = index;
  227. },
  228. copy(value) {
  229. let content = value; //需要复制的内容
  230. console.log('复制的内容:', content);
  231. // content = typeof content === 'string' ? content : content.toString(); // 复制内容,必须字符串,数字需要转换为字符串
  232. const result = uniCopy({
  233. content
  234. });
  235. if (result === false) {
  236. uni.showToast({
  237. title: '不支持'
  238. });
  239. } else {
  240. uni.showToast({
  241. title: '复制成功',
  242. icon: 'none'
  243. });
  244. }
  245. },
  246. openPopup() {
  247. this.$refs.popup.open();
  248. },
  249. // 弹窗 - 取消
  250. cancel() {
  251. this.card = '';
  252. this.pwd = '';
  253. this.$refs.popup.close();
  254. },
  255. jihuo(item) {
  256. const obj = this;
  257. let card = '';
  258. let pwd = '';
  259. if (item) {
  260. card = item.card;
  261. pwd = item.pwd;
  262. } else {
  263. card = this.card;
  264. pwd = this.pwd;
  265. }
  266. if (card == '') {
  267. return this.$api.msg('请填写卡号');
  268. }
  269. if (pwd == '') {
  270. return this.$api.msg('请填写密码');
  271. }
  272. uni.showModal({
  273. title: '提示',
  274. content: '是否激活该卡?',
  275. success: function(res) {
  276. if (res.confirm) {
  277. use_card({
  278. card: card,
  279. pwd: pwd
  280. }).then(e => {
  281. uni.showModal({
  282. title: '提示',
  283. content: '激活卡片成功'
  284. });
  285. obj.loadData('shua');
  286. });
  287. } else if (res.cancel) {
  288. console.log('用户点击取消');
  289. }
  290. }
  291. });
  292. }
  293. }
  294. };
  295. </script>
  296. <style lang="scss">
  297. // 卡卷可用时颜色
  298. $card-color-action: #fc4141;
  299. page,
  300. .content {
  301. background: $page-color-base;
  302. height: 100%;
  303. }
  304. .navbar {
  305. display: flex;
  306. height: 40px;
  307. background: #fff;
  308. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  309. position: relative;
  310. z-index: 10;
  311. .nav-item:first-child {
  312. border-left: none;
  313. }
  314. .nav-item {
  315. border-left: 1px solid #e7e7e7;
  316. flex: 1;
  317. display: flex;
  318. justify-content: center;
  319. align-items: center;
  320. height: 100%;
  321. font-size: 15px;
  322. color: $font-color-dark;
  323. position: relative;
  324. &.current {
  325. color: #24a17d;
  326. }
  327. }
  328. }
  329. .swiper-box {
  330. height: calc(100% - 100px);
  331. .tab-content {
  332. padding: 25rpx;
  333. }
  334. }
  335. // uni-load-more
  336. .uni-load-more {
  337. display: flex;
  338. flex-direction: row;
  339. height: 80rpx;
  340. align-items: center;
  341. justify-content: center;
  342. }
  343. .main-item {
  344. .main-item-top {
  345. align-items: flex-start;
  346. width: 702rpx;
  347. height: 150rpx;
  348. position: relative;
  349. .main-item-top-bg {
  350. position: absolute;
  351. top: 0;
  352. left: 0;
  353. right: 0;
  354. width: 702rpx;
  355. height: 150rpx;
  356. image {
  357. width: 100%;
  358. height: 100%;
  359. }
  360. }
  361. .main-item-top-left {
  362. position: relative;
  363. z-index: 2;
  364. padding: 40rpx 0 0 30rpx;
  365. line-height: 1;
  366. .main-item-title {
  367. font-size: 42rpx;
  368. font-family: PingFang SC;
  369. font-weight: bold;
  370. color: #c99f62;
  371. }
  372. .main-item-time {
  373. margin-top: 20rpx;
  374. font-size: 24rpx;
  375. font-family: PingFang SC;
  376. font-weight: 500;
  377. color: #d6d1d1;
  378. }
  379. }
  380. .main-item-type {
  381. padding: 56rpx 24rpx 0 0;
  382. position: relative;
  383. z-index: 2;
  384. font-size: 24rpx;
  385. font-family: PingFang SC;
  386. font-weight: bold;
  387. color: #d6d1d1;
  388. }
  389. }
  390. .main-item-bottom {
  391. width: 702rpx;
  392. height: 176rpx;
  393. position: relative;
  394. padding: 30rpx 30rpx 0;
  395. line-height: 1;
  396. .main-item-bottom-bg {
  397. position: absolute;
  398. top: 0;
  399. left: 0;
  400. right: 0;
  401. width: 702rpx;
  402. height: 176rpx;
  403. image {
  404. width: 100%;
  405. height: 100%;
  406. }
  407. }
  408. .main-item-price {
  409. width: 100%;
  410. position: relative;
  411. z-index: 2;
  412. font-size: 30rpx;
  413. font-family: PingFang SC;
  414. font-weight: bold;
  415. color: #ff6f0f;
  416. .fh {
  417. color: #333333;
  418. }
  419. .time {
  420. display: inline-block;
  421. margin-left: 4rpx;
  422. color: #333333;
  423. text-decoration: underline;
  424. }
  425. }
  426. .main-item-bottom-type {
  427. position: relative;
  428. z-index: 2;
  429. flex-shrink: 0;
  430. font-size: 26rpx;
  431. font-family: PingFang SC;
  432. font-weight: 500;
  433. color: #333333;
  434. }
  435. .main-item-info-right {
  436. position: relative;
  437. z-index: 2;
  438. flex-shrink: 0;
  439. display: flex;
  440. align-items: center;
  441. line-height: 1;
  442. .main-item-info-font {
  443. font-size: 24rpx;
  444. font-family: PingFang SC;
  445. font-weight: 500;
  446. color: #999999;
  447. margin-right: 10rpx;
  448. }
  449. .main-item-info-icon {
  450. position: relative;
  451. top: -10rpx;
  452. width: 19rpx;
  453. height: 19rpx;
  454. image {
  455. width: 100%;
  456. height: 100%;
  457. }
  458. }
  459. }
  460. .main-item-info {
  461. position: relative;
  462. z-index: 2;
  463. margin-top: 20rpx;
  464. .main-item-info-left {
  465. width: 100%;
  466. font-size: 24rpx;
  467. font-family: PingFang SC;
  468. font-weight: 500;
  469. color: #666666;
  470. }
  471. .main-item-info-btn {
  472. width: 127rpx;
  473. height: 44rpx;
  474. background: #ff6f0f;
  475. border-radius: 22rpx;
  476. font-size: 22rpx;
  477. font-family: PingFang SC;
  478. font-weight: 500;
  479. color: #ffffff;
  480. line-height: 44rpx;
  481. text-align: center;
  482. }
  483. }
  484. }
  485. }
  486. .image {
  487. width: 44rpx;
  488. height: 30rpx;
  489. }
  490. .info {
  491. width: 350rpx;
  492. margin-right: 10rpx;
  493. font-size: 26rpx;
  494. font-weight: 500;
  495. color: #666666;
  496. }
  497. .copy {
  498. margin-left: 10rpx;
  499. font-size: 22rpx;
  500. font-family: PingFang SC;
  501. font-weight: 500;
  502. text-decoration: underline;
  503. color: #333333;
  504. }
  505. .list-scroll-content {
  506. height: 100%;
  507. }
  508. .btn {
  509. margin: 10rpx auto 0;
  510. width: 622rpx;
  511. height: 85rpx;
  512. background: #ff6f0f;
  513. border-radius: 15rpx;
  514. line-height: 85rpx;
  515. text-align: center;
  516. font-size: 32rpx;
  517. font-family: PingFang SC;
  518. font-weight: bold;
  519. color: #ffffff;
  520. }
  521. .img1 {
  522. width: 560rpx;
  523. height: 182rpx;
  524. display: flex;
  525. justify-content: center;
  526. image {
  527. width: 462rpx;
  528. height: 182rpx;
  529. }
  530. }
  531. .popup-box {
  532. margin-top: -50rpx;
  533. width: 560rpx;
  534. background: #ffffff;
  535. border-radius: 30rpx;
  536. position: relative;
  537. padding-bottom: 50rpx;
  538. .img {
  539. position: relative;
  540. top: -80rpx;
  541. left: 0;
  542. width: 560rpx;
  543. height: 186rpx;
  544. display: flex;
  545. justify-content: center;
  546. image {
  547. width: 177rpx;
  548. height: 186rpx;
  549. }
  550. }
  551. .mian {
  552. margin-top: -44rpx;
  553. display: flex;
  554. flex-direction: column;
  555. align-items: center;
  556. // padding: 32rpx 32rpx;
  557. background-color: #ffffff;
  558. border-radius: 0 0 20rpx 20rpx;
  559. text-align: center;
  560. .delivery {
  561. font-size: 40rpx;
  562. color: #333333;
  563. display: flex;
  564. align-items: center;
  565. flex-direction: column;
  566. .title {}
  567. image {
  568. margin-top: 48rpx;
  569. width: 172rpx;
  570. height: 160rpx;
  571. }
  572. }
  573. .comfirm-box {
  574. margin-top: 30rpx;
  575. display: flex;
  576. flex-direction: column;
  577. justify-content: center;
  578. .input {
  579. font-size: 26rpx;
  580. font-family: PingFang SC;
  581. font-weight: 500;
  582. color: #999999;
  583. text-align: left;
  584. width: 439rpx;
  585. background: #f5f5f5;
  586. border-radius: 10rpx;
  587. margin-top: 20rpx;
  588. padding: 20rpx 26rpx;
  589. }
  590. }
  591. .popup-btn {
  592. width: 403rpx;
  593. height: 83rpx;
  594. background: #24a17d;
  595. border-radius: 42rpx;
  596. margin: 45rpx auto 0;
  597. font-size: 32rpx;
  598. font-family: PingFang SC;
  599. font-weight: bold;
  600. color: #ffffff;
  601. line-height: 83rpx;
  602. text-align: center;
  603. }
  604. }
  605. }
  606. .x {
  607. margin: 35rpx auto 0;
  608. width: 80rpx;
  609. height: 80rpx;
  610. image {
  611. width: 80rpx;
  612. height: 80rpx;
  613. }
  614. }
  615. </style>