couponReceive.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. <template>
  2. <view class="container">
  3. <view class="b">
  4. <view v-if="status == 0" class="coupon-switch-block">
  5. <view
  6. :data-type="item.type"
  7. :class="'type-switch ' + (item.type === currentType ? 'active-switch' : '')"
  8. @tap="switchType"
  9. v-for="(item, index) in typeList"
  10. :key="index"
  11. >
  12. {{ item.name }}
  13. </view>
  14. </view>
  15. <scroll-view :scroll-y="true" :scroll-top="scrollTop" class="my-coupon-list">
  16. <!-- 未使用 -->
  17. <view class="my-coupon-item-valid" v-for="(item, index) in couponList" :key="index">
  18. <view class="coupon-top">
  19. <view class="coupon-top-left">
  20. <view class="coupon-value">
  21. <text v-if="item.voucherType == 1" class="coupon-flag">¥</text>
  22. <text :class="item.type == 4 ? 'coupon-value-member' : 'coupon-value-num'" v-if="item.voucherType == 1">{{ item.discount }}</text>
  23. <text :class="item.type == 4 ? 'coupon-value-member' : 'coupon-value-num'" v-if="item.voucherType == 2">{{ item.discount / 10 }}</text>
  24. <text v-if="item.voucherType == 2" :class="item.type == 4 ? 'coupon-unit-member' : 'coupon-unit'">折</text>
  25. </view>
  26. <view class="coupon-type">
  27. <text v-if="item.voucherType == 1" style="color: #555555">满{{ item.min }}可用</text>
  28. <text v-if="item.voucherType == 2" style="color: #555555">满{{ item.min }}可用</text>
  29. </view>
  30. </view>
  31. <view class="coupon-top-content">
  32. <view class="coupon-valid-name">{{ item.name }}</view>
  33. <view v-if="item.timeType == 1">有效期至:{{ item.endTime }}</view>
  34. <view v-if="item.timeType == 0">领券后:{{ item.days }}天有效</view>
  35. </view>
  36. </view>
  37. <view class="coupon-bottom">
  38. <text v-if="item.desc && item.name != item.desc" style="flex: 1">{{ item.desc }}</text>
  39. <text v-else-if=""></text>
  40. <view class="coupon-top-right" :data-id="item.id" @tap="goReceive">领取并使用</view>
  41. </view>
  42. </view>
  43. </scroll-view>
  44. <view class="no-list" v-if="couponList == 0">没有更多可领优惠券了</view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. var util = require('../../../utils/util.js');
  50. var api = require('../../../config/api.js');
  51. var app = getApp();
  52. export default {
  53. data() {
  54. return {
  55. options: '',
  56. couponList: [],
  57. scrollTop: 0,
  58. typeList: [
  59. {
  60. name: '全部',
  61. type: 0
  62. },
  63. {
  64. name: '立减券',
  65. type: 1
  66. },
  67. {
  68. name: '折扣券',
  69. type: 2
  70. }
  71. ],
  72. fraId: '',
  73. recCode: '',
  74. addressInfo: '',
  75. status: 0,
  76. currentType: ''
  77. };
  78. }
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */,
  82. onLoad: function (options) {
  83. if (this.options == '') {
  84. this.setData({
  85. options: options
  86. });
  87. }
  88. console.info(options);
  89. },
  90. /**
  91. * 生命周期函数--监听页面显示
  92. */
  93. onShow: function () {
  94. if (app.globalData.hasLogin == false) {
  95. uni.navigateTo({
  96. url: '/pages/auth/login/login'
  97. });
  98. return;
  99. }
  100. setTimeout(() => {
  101. this.getLocation();
  102. }, 500);
  103. },
  104. /**
  105. * 生命周期函数--监听页面初次渲染完成
  106. */
  107. onReady: function () {},
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide: function () {},
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload: function () {},
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function () {},
  120. /**
  121. * 页面上拉触底事件的处理函数
  122. */
  123. onReachBottom: function () {},
  124. /**
  125. * 用户点击右上角分享
  126. */
  127. onShareAppMessage: function () {},
  128. methods: {
  129. getCouponList() {
  130. let that = this;
  131. let options = that.options;
  132. that.setData({
  133. options: ''
  134. });
  135. let scene = decodeURIComponent(options.scene);
  136. var fraId;
  137. var recCode; //两种格式 一种加盟商推荐fraId: 一种服务者推荐:recCode:
  138. if (scene && scene.indexOf('fraId:') >= 0) {
  139. fraId = scene.split(':')[1];
  140. uni.setStorageSync('fraId', fraId);
  141. }
  142. if (scene && scene.indexOf('recCode:') >= 0) {
  143. recCode = scene.split(':')[1];
  144. }
  145. that.setData({
  146. fraId: fraId,
  147. recCode: recCode
  148. });
  149. util.request(api.CouponReceiveList, {
  150. city: that.addressInfo.city
  151. }).then(function (res) {
  152. if (res.errno === 0) {
  153. that.setData({
  154. couponList: res.data
  155. });
  156. console.info(that.couponList);
  157. }
  158. });
  159. },
  160. goReceive(e) {
  161. //点击领取按钮
  162. let that = this;
  163. let id = e.currentTarget.dataset.id;
  164. let coupon = null;
  165. let coupons = this.couponList;
  166. coupons.forEach((item) => {
  167. if (item.id == id) {
  168. coupon = item;
  169. }
  170. });
  171. let goodsvalue = coupon.goodsValue;
  172. util.request(
  173. api.CouponReceive,
  174. {
  175. couponId: id,
  176. fraId: that.fraId,
  177. recCode: that.recCode
  178. },
  179. 'POST'
  180. )
  181. .then((res) => {
  182. if (res.errno === 0) {
  183. that.goBuy(goodsvalue, id);
  184. } else {
  185. util.showErrorToast(res.errmsg);
  186. }
  187. })
  188. .catch((res) => {
  189. util.showErrorToast(res.errmsg);
  190. });
  191. },
  192. goBuy(goodsvalue, couponId) {
  193. // if (goodsvalue.length == 1) {
  194. // wx.navigateTo({
  195. // url: '/pages/goods/goods?id=' + goodsvalue[0],
  196. // })
  197. // } else
  198. if (goodsvalue.length >= 1) {
  199. uni.navigateTo({
  200. url: '/pages/ucenter/couponGoods/couponGoods?id=' + couponId
  201. });
  202. } else {
  203. uni.switchTab({
  204. url: '/pages/tabBar/catalog/catalog'
  205. });
  206. }
  207. },
  208. getLocation() {
  209. let that = this;
  210. //获取地理位置 缓存中是否有地址
  211. /**
  212. * 分2重判断
  213. * 1:缓存中是否有地址
  214. * 2:未登录 取当前地理位置判断
  215. */
  216. var addressInfo = uni.getStorageSync('addressInfo');
  217. console.info(addressInfo);
  218. if (addressInfo) {
  219. that.setData({
  220. addressInfo: addressInfo
  221. });
  222. that.getCouponList();
  223. } else {
  224. map.getCity()
  225. .then((res) => {
  226. that.setData({
  227. addressInfo: res
  228. });
  229. that.getCouponList();
  230. })
  231. .catch((res) => {
  232. //reject内容 1:未授权 2:不在服务范围 3:异常解析
  233. uni.showModal({
  234. title: '提醒',
  235. showCancel: false,
  236. content: '您未授权或非业务城市,无法获取优惠券信息'
  237. });
  238. });
  239. }
  240. },
  241. switchType() {
  242. console.log('占位:函数 switchType 未声明');
  243. }
  244. }
  245. };
  246. </script>
  247. <style>
  248. page {
  249. background: #f4f4f4;
  250. min-height: 100%;
  251. }
  252. .container {
  253. background: #f4f4f4;
  254. min-height: 100%;
  255. /* padding-top: 30rpx; */
  256. }
  257. .container .h {
  258. position: fixed;
  259. left: 0;
  260. top: 0;
  261. z-index: 1000;
  262. width: 100%;
  263. display: flex;
  264. background: #fff;
  265. height: 84rpx;
  266. border-bottom: 1px solid rgba(0, 0, 0, 0.15);
  267. }
  268. .container .h .item {
  269. display: inline-block;
  270. height: 82rpx;
  271. width: 50%;
  272. padding: 0 15rpx;
  273. text-align: center;
  274. }
  275. .container .h .item .txt {
  276. display: inline-block;
  277. height: 82rpx;
  278. padding: 0 20rpx;
  279. line-height: 82rpx;
  280. color: #333;
  281. font-size: 30rpx;
  282. width: 170rpx;
  283. }
  284. .container .h .item.active .txt {
  285. color: #ab2b2b;
  286. border-bottom: 4rpx solid #ab2b2b;
  287. }
  288. .container .b {
  289. padding-top: 12rpx;
  290. height: auto;
  291. border-top: 1rpx solid #ddd;
  292. }
  293. .container .b .coupon-form {
  294. height: 110rpx;
  295. width: 100%;
  296. background: #fff;
  297. padding-left: 30rpx;
  298. padding-right: 30rpx;
  299. padding-top: 20rpx;
  300. display: flex;
  301. }
  302. .container .b .input-box {
  303. flex: 1;
  304. height: 70rpx;
  305. color: #333;
  306. font-size: 24rpx;
  307. background: #fff;
  308. position: relative;
  309. border: 1px solid rgba(0, 0, 0, 0.15);
  310. border-radius: 35rpx;
  311. margin-right: 30rpx;
  312. }
  313. .container .b .input-box .coupon-sn {
  314. position: absolute;
  315. top: 10rpx;
  316. left: 30rpx;
  317. height: 50rpx;
  318. width: 100%;
  319. color: #000;
  320. line-height: 50rpx;
  321. font-size: 24rpx;
  322. }
  323. .container .b .clear-icon {
  324. position: absolute;
  325. top: 20rpx;
  326. right: 18rpx;
  327. z-index: 2;
  328. display: block;
  329. background: #fff;
  330. }
  331. .container .b .add-btn {
  332. height: 70rpx;
  333. border: none;
  334. width: 168rpx;
  335. /* background: #b4282d; */
  336. background: #4e4e4e;
  337. border-radius: 35rpx;
  338. line-height: 70rpx;
  339. color: #fff;
  340. font-size: 28rpx;
  341. text-align: center;
  342. }
  343. .container .b .add-btn.disabled {
  344. background: #ccc;
  345. }
  346. .container .b .help {
  347. height: 72rpx;
  348. line-height: 72rpx;
  349. text-align: right;
  350. padding-right: 30rpx;
  351. background-size: 28rpx;
  352. color: #999;
  353. font-size: 24rpx;
  354. }
  355. .container .b .coupon-list {
  356. width: 750rpx;
  357. height: 100%;
  358. overflow: hidden;
  359. }
  360. .container .b .item {
  361. position: relative;
  362. height: 290rpx;
  363. background: #ccc7c7;
  364. margin-bottom: 30rpx;
  365. margin-left: 30rpx;
  366. margin-right: 30rpx;
  367. padding-top: 52rpx;
  368. }
  369. .container .b .item.active {
  370. background: linear-gradient(to right, #cfa568, #e3bf79);
  371. }
  372. .container .b .tag {
  373. height: 32rpx;
  374. background: #a48143;
  375. padding-left: 16rpx;
  376. padding-right: 16rpx;
  377. position: absolute;
  378. left: 20rpx;
  379. color: #fff;
  380. top: 20rpx;
  381. font-size: 20rpx;
  382. text-align: center;
  383. line-height: 32rpx;
  384. }
  385. .container .b .content {
  386. margin-top: 24rpx;
  387. margin-left: 40rpx;
  388. display: flex;
  389. margin-right: 40rpx;
  390. flex-direction: row;
  391. }
  392. .container .b .content .left {
  393. flex: 1;
  394. }
  395. .container .b .discount {
  396. font-size: 50rpx;
  397. color: #b4282d;
  398. }
  399. .container .b .min {
  400. color: #fff;
  401. }
  402. .container .b .content .right {
  403. width: 400rpx;
  404. }
  405. .container .b .name {
  406. font-size: 44rpx;
  407. color: #fff;
  408. margin-bottom: 14rpx;
  409. }
  410. .container .b .time {
  411. font-size: 24rpx;
  412. color: #fff;
  413. line-height: 30rpx;
  414. }
  415. .container .b .condition {
  416. position: absolute;
  417. width: 100%;
  418. bottom: 0;
  419. left: 0;
  420. height: 78rpx;
  421. background: rgba(0, 0, 0, 0.08);
  422. padding: 24rpx 40rpx;
  423. display: flex;
  424. flex-direction: row;
  425. }
  426. .container .b .condition .txt {
  427. display: block;
  428. height: 30rpx;
  429. flex: 1;
  430. overflow: hidden;
  431. font-size: 24rpx;
  432. line-height: 30rpx;
  433. color: #fff;
  434. }
  435. .container .b .condition .icon {
  436. margin-left: 30rpx;
  437. width: 24rpx;
  438. height: 24rpx;
  439. }
  440. .container .b .page {
  441. width: 750rpx;
  442. height: 108rpx;
  443. background: #fff;
  444. margin-bottom: 20rpx;
  445. }
  446. .container .b .page view {
  447. height: 108rpx;
  448. width: 50%;
  449. float: left;
  450. font-size: 29rpx;
  451. color: #333;
  452. text-align: center;
  453. line-height: 108rpx;
  454. }
  455. .container .b .page .prev {
  456. border-right: 1px solid #d9d9d9;
  457. }
  458. .container .b .page .disabled {
  459. color: #ccc;
  460. }
  461. .b .no-list {
  462. margin: 16rpx 0 0;
  463. text-align: center;
  464. color: #999;
  465. font-size: 28rpx;
  466. }
  467. .my-coupon-list {
  468. padding: 20rpx 24rpx;
  469. width: auto;
  470. height: 100%;
  471. overflow: hidden;
  472. }
  473. .my-coupon-item {
  474. border-radius: 18rpx;
  475. background: #fff;
  476. height: 190rpx;
  477. margin: 0 0 20rpx;
  478. display: flex;
  479. justify-content: space-between;
  480. padding: 0 20rpx 0 0;
  481. width: 706rpx;
  482. }
  483. .coupon-left {
  484. background: rgba(9, 175, 255, 0.1);
  485. width: 230rpx;
  486. display: flex;
  487. flex-direction: column;
  488. align-items: center;
  489. justify-content: space-between;
  490. height: 190rpx;
  491. padding: 18rpx 0 30rpx;
  492. }
  493. .coupon-left .coupon-amount {
  494. font-size: 48rpx;
  495. font-weight: bold;
  496. }
  497. .coupon-left .coupon-type {
  498. font-size: 24rpx;
  499. font-weight: bold;
  500. white-space: nowrap;
  501. overflow: hidden;
  502. text-overflow: ellipsis;
  503. width: 220rpx;
  504. text-align: center;
  505. }
  506. .coupon-left .coupon-btn {
  507. background: #999999;
  508. color: #fff;
  509. width: 120rpx;
  510. height: 32rpx;
  511. line-height: 32rpx;
  512. font-size: 22rpx;
  513. margin-top: 10rpx;
  514. border-radius: 30rpx;
  515. text-align: center;
  516. }
  517. .coupon-left .coupon-btn.active-btn {
  518. background: #09afff;
  519. }
  520. .coupon-content {
  521. margin: 0 20rpx 0 30rpx;
  522. display: flex;
  523. flex-direction: column;
  524. justify-content: space-between;
  525. padding: 40rpx 0;
  526. flex: 1;
  527. }
  528. .coupon-content view.coupon-name {
  529. color: #999;
  530. font-size: 30rpx;
  531. font-weight: bold;
  532. white-space: nowrap;
  533. overflow: hidden;
  534. text-overflow: ellipsis;
  535. width: 330rpx;
  536. }
  537. .coupon-content view.coupon-date {
  538. color: #999;
  539. font-size: 20rpx;
  540. }
  541. .coupon-right {
  542. width: 84rpx;
  543. height: 114rpx;
  544. padding-top: 30rpx;
  545. }
  546. .coupon-status {
  547. width: 84rpx;
  548. height: 84rpx;
  549. }
  550. .my-coupon-item-valid {
  551. background: #fff;
  552. box-shadow: 0rpx 6rpx 14rpx 0px rgba(142, 142, 142, 0.03);
  553. border-radius: 20rpx;
  554. width: 696rpx;
  555. margin-bottom: 24rpx;
  556. padding: 0 30rpx;
  557. }
  558. .my-coupon-item-valid .marker {
  559. position: absolute;
  560. right: 10rpx;
  561. float: right;
  562. padding: 5rpx;
  563. width: 136rpx;
  564. /* border-radius: 1rpx solid #; */
  565. background: #f5da9e;
  566. color: #c8965a;
  567. text-align: center;
  568. border-bottom-left-radius: 20rpx;
  569. /* margin-right: -30rpx; */
  570. border-top-right-radius: 15rpx;
  571. }
  572. .coupon-top {
  573. display: flex;
  574. height: 152rpx;
  575. align-items: center;
  576. justify-content: space-between;
  577. padding: 0rpx 8rpx 0 0;
  578. }
  579. .coupon-top-left {
  580. width: 150rpx;
  581. color: #09afff;
  582. font-size: 22rpx;
  583. padding: 8rpx 0 0 4rpx;
  584. }
  585. .coupon-top-left .coupon-value {
  586. display: flex;
  587. align-items: flex-end;
  588. height: 54rpx;
  589. margin-bottom: 10rpx;
  590. font-size: 24rpx;
  591. font-weight: bold;
  592. }
  593. .coupon-top-left .coupon-value .coupon-value-num {
  594. font-size: 70rpx;
  595. line-height: 54rpx;
  596. }
  597. .coupon-top-left .coupon-value .coupon-unit {
  598. color: #09afff;
  599. margin-left: 4rpx;
  600. }
  601. .coupon-top-left .coupon-value .coupon-unit-member {
  602. color: #e9b06b;
  603. margin-left: 4rpx;
  604. }
  605. .coupon-top-left .coupon-value .coupon-flag {
  606. color: #09afff;
  607. margin-right: 4rpx;
  608. }
  609. .coupon-top-left .coupon-value .coupon-flag-member {
  610. color: #e9b06b;
  611. margin-right: 4rpx;
  612. }
  613. .coupon-top-left .coupon-value .coupon-value-member {
  614. font-size: 70rpx;
  615. line-height: 54rpx;
  616. color: #e9b06b;
  617. }
  618. .coupon-top-content {
  619. flex: 1;
  620. margin: 0 30rpx 0 20rpx;
  621. color: #b4b4b4;
  622. font-size: 22rpx;
  623. font-weight: normal;
  624. }
  625. .coupon-valid-name {
  626. font-weight: bold;
  627. color: #555555;
  628. font-size: 32rpx;
  629. margin-bottom: 10rpx;
  630. width: 380rpx;
  631. overflow: hidden;
  632. text-overflow: ellipsis;
  633. white-space: nowrap;
  634. }
  635. .coupon-top-right {
  636. /* writing-mode: vertical-lr; */
  637. width: 142rpx;
  638. height: 56rpx;
  639. background: #09afff;
  640. border-radius: 42rpx;
  641. text-align: center;
  642. color: #ffffff;
  643. line-height: 56rpx;
  644. font-size: 20rpx;
  645. letter-spacing: 3rpx;
  646. margin-left: 20rpx;
  647. }
  648. .coupon-top-member {
  649. width: 142rpx;
  650. height: 56rpx;
  651. background: #e9b06b;
  652. border-radius: 42rpx;
  653. text-align: center;
  654. color: #ffffff;
  655. line-height: 56rpx;
  656. font-size: 20rpx;
  657. letter-spacing: 3rpx;
  658. }
  659. .coupon-bottom {
  660. padding: 10rpx 4rpx 22rpx;
  661. color: #757575;
  662. font-size: 20rpx;
  663. line-height: 36rpx;
  664. border-top: 1rpx dashed #d4d4d4;
  665. letter-spacing: 2rpx;
  666. display: flex;
  667. justify-content: space-between;
  668. align-items: center;
  669. }
  670. .coupon-switch-block {
  671. height: 104rpx;
  672. padding: 0 27rpx;
  673. display: flex;
  674. align-items: center;
  675. margin-bottom: -20rpx;
  676. justify-content: center;
  677. }
  678. .van-tab--active.van-tab > view.van-ellipsis {
  679. color: #000 !important;
  680. letter-spacing: 2rpx;
  681. }
  682. .type-switch {
  683. width: 132rpx;
  684. height: 46rpx;
  685. line-height: 42rpx;
  686. border: 2rpx solid #b4b4b4;
  687. border-radius: 46rpx;
  688. text-align: center;
  689. color: #b4b4b4;
  690. font-size: 24rpx;
  691. margin: 10rpx;
  692. }
  693. .type-switch.active-switch {
  694. background: #4e4e4e;
  695. color: #fff;
  696. /* border: 2rpx solid #09AFFF; */
  697. }
  698. </style>