You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

453 lines
13 KiB

6 months ago
  1. <template>
  2. <view>
  3. <view class="tabr" :style="{top:headerTop}">
  4. <view :class="{on:typeClass=='valid'}" @tap="switchType('valid')">待领取({{couponValidList.length}})</view><view :class="{on:typeClass=='invalid'}" @tap="switchType('invalid')">我的优惠券({{mycouponvalidList.length}})</view>
  5. <view class="border" :class="typeClass"></view>
  6. </view>
  7. <view class="place" ></view>
  8. <view class="list">
  9. <!-- 优惠券列表 -->
  10. <view class="sub-list valid" :class="subState">
  11. <view class="tis" v-if="couponValidList.length==0">暂无可领优惠券~</view>
  12. <view class="row" v-for="(row,index) in couponValidList" :key="index" >
  13. <!-- content -->
  14. <view class="carrier" :class="[typeClass=='valid'?theIndex==index?'open':oldIndex==index?'close':'':'']">
  15. <view class="left">
  16. <view class="title">
  17. {{row.lx}}
  18. </view>
  19. <view class="term">
  20. {{row.brq}} ~ {{row.erq}}
  21. </view>
  22. <view class="gap-top"></view>
  23. <view class="gap-bottom"></view>
  24. </view>
  25. <view class="right" @click="dogetcoupon(row.id)">
  26. <view class="ticket">
  27. <view class="num">
  28. {{row.jine}}
  29. </view>
  30. <view class="unit"></view>
  31. </view>
  32. <view class="criteria">
  33. {{row.manjine}}使用
  34. </view>
  35. <view class="use">
  36. 立即领取
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="sub-list invalid" :class="subState">
  43. <view class="tis" v-if="mycouponvalidList.length==0">暂无优惠券哦~</view>
  44. <view class="row" v-for="(row,index) in mycouponvalidList" :key="index" >
  45. <!-- content -->
  46. <view class="carrier" :class="[typeClass=='invalid'?theIndex==index?'open':oldIndex==index?'close':'':'']" >
  47. <view class="left">
  48. <view class="title">
  49. {{row.lx}}
  50. </view>
  51. <view class="term">
  52. {{row.brq}} ~ {{row.erq}}
  53. <view v-if="row.number>1" class="shengyu">剩余{{row.number}}</view>
  54. </view>
  55. <!-- <view class="icon shixiao">
  56. </view> -->
  57. <view class="gap-top"></view>
  58. <view class="gap-bottom"></view>
  59. </view>
  60. <view class="right invalid">
  61. <view class="ticket">
  62. <view class="num">
  63. {{row.jine}}
  64. </view>
  65. <view class="unit">
  66. </view>
  67. </view>
  68. <view class="criteria">
  69. {{row.manjine}}使用
  70. </view>
  71. <view class="use" v-if="fromchoose==1" >
  72. <span v-if="row.id==yid" @tap="chooseit(row.id,row.jine,row.manjine,0)" style="color: red;">取消</span>
  73. <span v-else @tap="chooseit(row.id,row.jine,row.manjine,1)">选择</span>
  74. </view>
  75. <view class="use" v-else>待使用</view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. export default {
  85. data() {
  86. return {
  87. couponValidList:[],
  88. mycouponvalidList:[],
  89. headerTop:0,
  90. //控制滑动效果
  91. typeClass:'valid',
  92. subState:'',
  93. theIndex:null,
  94. oldIndex:null,
  95. isStop:false,
  96. fromchoose:0,//是否过来选择优惠券的
  97. allmoney:0,//订单金额
  98. yid:0,//已选中的优惠券id
  99. }
  100. },
  101. onPageScroll(e){
  102. },
  103. //下拉刷新,需要自己在page.json文件中配置开启页面下拉刷新 "enablePullDownRefresh": true
  104. onPullDownRefresh() {
  105. setTimeout(function () {
  106. uni.stopPullDownRefresh();
  107. }, 1000);
  108. },
  109. onLoad(option) {
  110. this.fromchoose=parseInt(option.fromchoose);
  111. this.allmoney=parseInt(option.allmoney);
  112. this.yid=getApp().globalData.yid;
  113. //兼容H5下排序栏位置
  114. // #ifdef H5
  115. //定时器方式循环获取高度为止,这么写的原因是onLoad中head未必已经渲染出来。
  116. let Timer = setInterval(()=>{
  117. let uniHead = document.getElementsByTagName('uni-page-head');
  118. if(uniHead.length>0){
  119. this.headerTop = uniHead[0].offsetHeight+'px';
  120. clearInterval(Timer);//清除定时器
  121. }
  122. },1);
  123. // #endif
  124. this.couponlist();
  125. this.mycouponlist();
  126. },
  127. methods: {
  128. //领取优惠券
  129. dogetcoupon(id){
  130. uni.showLoading({title: '领取中...'});
  131. this.getcoupon(id)
  132. },
  133. //选择该优惠券
  134. chooseit(id,jine,maxjine,type){
  135. if(type==1){
  136. console.log(Number(parseFloat(this.allmoney*100)/100),'this.allmoney')
  137. console.log(Number(parseFloat(jine*100)/100),'jine')
  138. if(Number((parseFloat(maxjine*100)/100))>Number((parseFloat(this.allmoney*100)/100))){
  139. uni.showToast({
  140. title:'订单金额不满'+maxjine+'元,不可使用',icon:'none'
  141. })
  142. }else{
  143. getApp().globalData.yid=id;
  144. getApp().globalData.yhqjine=jine;
  145. getApp().globalData.useyhq=0;
  146. uni.navigateBack({
  147. delta:1
  148. })
  149. }
  150. }else{
  151. getApp().globalData.yid=0;
  152. getApp().globalData.yhqjine=0;
  153. getApp().globalData.useyhq=0;
  154. uni.navigateBack({
  155. delta:1
  156. })
  157. }
  158. },
  159. //获取优惠券列表
  160. async couponlist(){
  161. let getuserinfo=uni.getStorageSync('userinfo');
  162. let info= await this.$api.couponlist({action:'couponlist',uid:getuserinfo.uid,aid:getuserinfo.aid,aid:getuserinfo.aid});
  163. this.couponValidList=info.data;
  164. },
  165. //获取我的优惠券
  166. async mycouponlist(){
  167. let getuserinfo=uni.getStorageSync('userinfo');
  168. let info= await this.$api.mycouponlist({action:'mycouponlist',uid:getuserinfo.uid,aid:getuserinfo.aid});
  169. this.mycouponvalidList=info.data;
  170. },
  171. async getcoupon(id){
  172. let getuserinfo=uni.getStorageSync('userinfo');
  173. let info= await this.$api.getcoupon({action:'getcoupon',uid:getuserinfo.uid,id:id,aid:getuserinfo.aid});
  174. if(info.code==1){
  175. uni.hideLoading();
  176. uni.showToast({
  177. title:'领取成功',icon:'none',duration:2000
  178. })
  179. this.couponlist();
  180. }else{
  181. uni.showToast({
  182. title:'领取失败',icon:'fail',duration:1500
  183. })
  184. }
  185. },
  186. switchType(type){
  187. this.couponlist();
  188. this.mycouponlist();
  189. if(this.typeClass==type){
  190. return ;
  191. }
  192. uni.pageScrollTo({
  193. scrollTop:0,
  194. duration:0
  195. })
  196. this.typeClass = type;
  197. this.subState = this.typeClass==''?'':'show'+type;
  198. setTimeout(()=>{
  199. this.oldIndex = null;
  200. this.theIndex = null;
  201. this.subState = this.typeClass=='valid'?'':this.subState;
  202. },200)
  203. },
  204. }
  205. }
  206. </script>
  207. <style lang="scss">
  208. view{
  209. display: flex;
  210. flex-wrap: wrap;
  211. }
  212. page{position: relative;background-color: #f5f5f5;}
  213. @font-face {font-family:"HMfont-home";src:url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAYcAAsAAAAAC7AAAAXPAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCDMgqKTIgRATYCJAMUCwwABCAFhG0HShufCciemjxtEyiE0MJUUYjN7gIePI911ftJqrY61RxhAeHWc1taR0BXaRAvS0cGxd7FXycwvQF4WLxnP3czaSZwFdHkmjTO77s3Gq8T2hKtbaWhlUQDcsL+/+Ne1UzbGprPvsVxjwUYCnAsmHRvDnUssKU9L4hXRPoIr6uBbOALl0MAS25cYBo2vnuELAZbIlAwchg7gGxBi+mgCp7CbTjUIPNx8NQMdRvAvOj75TNe4oHC0di7th18Poajd/VebNbx/+gZoODNZwbEo0ADJQEYkPGN1pEkEnHJSGqbliepC2DxUKi5FjV4MezF5v+HTHgiuXWsoGb5wzMgLrY0CPi6MQPvIj0ECt5FI9Dwrg6BwLtl/CdG6uAhFsgEyC6Qn9iEguyVBIPgZBXzMrVu0DJLNGoTpYZt3nBJE4B77nE0j15iaRtNoDnP7WmILk+dSch0NAvOkvUzUtYKEisJRJoFE9kklrLa/GbLki7kXpUzI2UOvlliRIQQv2m0cFqFW+suTYOxLF7XcbZuGlzDLxN5qPp3n4NXKrzCzSQ6OA3qVpI5AuQ1fqXCTRPbC75Mjkz/BCydmynDWfnH77pKW27YMU2lvXokEMxDmWM1zEKJIwov6DErIqAU4gmtoqTdaZ+3zTBn2grUe/o2op+50ilTbcYgXgnibXCnFdXX71Lpxj3t2p0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WgkbVa283Sdtzdq5vWtFrRIkOeBhgQAyyIMUg5PkgdI1QUmGC6Rb7y9fcQLDYSA4yOjjrnM4SBCT8/4okbHgT0pVQhddxLeVccWDbphmEGpFrMV5FB4tBMSE5UBenUvJEAMcJildoRYY0d3HFSNVW6ur5cfox5f8Gu9qkdUaLFiCMugWnDTI73+IGaGO6Lk55LyUwYCpERZwMAAA==') format('woff2');}
  214. .icon {
  215. font-family:"HMfont-home" !important;
  216. font-size:60upx;
  217. font-style:normal;
  218. color:#000000;
  219. &.jia {
  220. &:before{content:"\e641";}
  221. }
  222. &.jian {
  223. &:before{content:"\e643";}
  224. }
  225. &.shixiao {
  226. &:before{content:"\e669";}
  227. }
  228. }
  229. .hidden{
  230. display: none !important;
  231. }
  232. .place{
  233. width: 100%;
  234. height: 95upx;
  235. }
  236. .tabr{
  237. background-color: #fff;
  238. width: 100%;
  239. height: 95upx;
  240. padding: 0 3%;
  241. border-bottom: solid 1upx #dedede;
  242. position: fixed;
  243. top: 0;
  244. z-index: 10;
  245. view{
  246. width: 50%;
  247. height: 90upx;
  248. justify-content: center;
  249. align-items: center;
  250. font-size: 32upx;
  251. color: #999;
  252. }
  253. .on{
  254. color: #f06c7a;
  255. }
  256. .border{
  257. height: 4upx;
  258. background-color: #f06c7a;
  259. transition: all .3s ease-out;
  260. &.invalid{
  261. transform: translate3d(100%,0,0);
  262. }
  263. }
  264. }
  265. .list{
  266. width: 100%;
  267. display: block;
  268. position: relative;
  269. }
  270. @keyframes showValid {
  271. 0% {transform: translateX(-100%);}100% {transform: translateX(0);}
  272. }
  273. @keyframes showInvalid {
  274. 0% {transform: translateX(0);}100% {transform: translateX(-100%);}
  275. }
  276. .sub-list{
  277. &.invalid{
  278. position: absolute;
  279. top: 0;
  280. left:100%;
  281. display: none;
  282. }
  283. &.showvalid{
  284. display: flex;
  285. animation: showValid 0.20s linear both;
  286. }
  287. &.showinvalid{
  288. display: flex;
  289. animation: showInvalid 0.20s linear both;
  290. }
  291. width: 100%;
  292. padding: 20upx 0 120upx 0;
  293. .tis{
  294. width: 100%;
  295. height: 60upx;
  296. justify-content: center;
  297. align-items: center;
  298. color: #C0C0C0;
  299. font-size: 32upx;
  300. }
  301. .row{
  302. width: 92%;
  303. height: 24vw;
  304. margin: 20upx auto 10upx auto;
  305. border-radius: 8upx;
  306. // box-shadow: 0upx 0 10upx rgba(0,0,0,0.1);
  307. align-items: center;
  308. position: relative;
  309. overflow: hidden;
  310. z-index: 4;
  311. border: 0;
  312. .menu{
  313. .icon{
  314. color: #fff;
  315. font-size:50upx;
  316. }
  317. position: absolute;
  318. width: 28%;
  319. height: 100%;
  320. right: 0;
  321. justify-content: center;
  322. align-items: center;
  323. background-color: red;
  324. color: #fff;
  325. z-index: 2;
  326. }
  327. .carrier{
  328. @keyframes showMenu {
  329. 0% {transform: translateX(0);}100% {transform: translateX(-28%);}
  330. }
  331. @keyframes closeMenu {
  332. 0% {transform: translateX(-28%);}100% {transform: translateX(0);}
  333. }
  334. &.open{
  335. animation: showMenu 0.25s linear both;
  336. }
  337. &.close{
  338. animation: closeMenu 0.15s linear both;
  339. }
  340. background-color: #fff;
  341. position: absolute;
  342. width: 100%;
  343. padding: 0 0;
  344. height: 100%;
  345. z-index: 3;
  346. flex-wrap: nowrap;
  347. .left{
  348. width: 100%;
  349. .title{
  350. padding-top: 3vw;
  351. width: 90%;
  352. margin: 0 5%;
  353. font-size: 36upx;
  354. }
  355. .term{
  356. width: 90%;
  357. margin: 0 5%;
  358. font-size: 26upx;
  359. color: #999;
  360. .shengyu{
  361. font-size: 30upx;
  362. color: red;
  363. }
  364. }
  365. position: relative;
  366. .gap-top,.gap-bottom{
  367. position: absolute;
  368. width: 20upx;
  369. height: 20upx;
  370. right: -10upx;
  371. border-radius: 100%;
  372. background-color: #f5f5f5;
  373. }
  374. .gap-top{
  375. top: -10upx;
  376. }
  377. .gap-bottom{
  378. bottom: -10upx;
  379. }
  380. .shixiao{
  381. position: absolute;
  382. right: 20upx;
  383. font-size: 150upx;
  384. z-index: 6;
  385. color: rgba(153,153,153,0.2)
  386. }
  387. }
  388. .right{
  389. flex-shrink: 0;
  390. width: 28%;
  391. color: #fff;
  392. background:linear-gradient(to right,#ec625c,#ee827f);
  393. &.invalid{
  394. background:linear-gradient(to right,#4D86C1,#5886B7);
  395. .use{
  396. color: #5886B7;
  397. }
  398. }
  399. justify-content: center;
  400. .ticket,.criteria{width: 100%;}
  401. .ticket{
  402. padding-top: 1vw;
  403. justify-content: center;
  404. align-items: baseline;
  405. height: 6vw;
  406. .num{
  407. font-size: 42upx;
  408. font-weight: 600;
  409. }
  410. .unit{
  411. font-size: 24upx;
  412. }
  413. }
  414. .criteria{
  415. justify-content: center;
  416. font-size: 28upx;
  417. }
  418. .use{
  419. width: 50%;
  420. height: 40upx;
  421. justify-content: center;
  422. align-items: center;
  423. font-size: 24upx;
  424. background-color: #fff;
  425. color: #ee827f;
  426. border-radius: 40upx;
  427. padding: 0 10upx;
  428. }
  429. }
  430. }
  431. }
  432. }
  433. </style>