coupon.vue 14 KB

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