index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="w-full h-400 relative z-10" :style="{'height': (186 + sysHeight) * 2 + 'rpx', 'background' : headerBg}">
  4. <view class="fixed-lt w-full z-20" :style="{'padding-top': sysHeight + 'px','background': pageScrollStatus ? 'var(--view-theme)' : 'transparent'}">
  5. <view class="w-full px-20 pl-20 h-80 flex-between-center">
  6. <text class="iconfont icon-ic_leftarrow fs-40 text--w111-fff" @tap="backPage"></text>
  7. <text class="fs-34 fw-500 text--w111-fff">领券中心</text>
  8. <text></text>
  9. </view>
  10. </view>
  11. <view class="abs-box flex-col">
  12. <image src="../static/get_coupon_text.png" class="w-184 h-46"></image>
  13. <text class="fs-24 lh-34rpx text--w111-fff pt-20">天天来领券,优惠看的见</text>
  14. </view>
  15. <image class="w-530 h-226 block abs-rb bottom-t20" :src="imgHost+'/statics/images/get_coupon_bg.png'"></image>
  16. </view>
  17. <view class="relative rd-t-40rpx bg--w111-f5f5f5 w-full content">
  18. <view class="_box flex-between-center text--w111-666 fs-30 lh-42rpx"
  19. :class="pageScrollStatus ? '' : 'rd-t-40rpx'"
  20. :style="{'top': (36 + sysHeight) * 2 + 'rpx'}">
  21. <text :class="current == 0 ? 'font-num fw-500' : ''" @tap="changeTab(0)">默认排序</text>
  22. <view class="flex-y-center" @tap="changeTab(1)">
  23. <text :class="current == 1 ? 'font-num fw-500' : ''">最新</text>
  24. <text v-show="params.timeOrder == 'desc'" class="iconfont icon-ic_down2 fs-14 ml-6 font-num"></text>
  25. <text v-show="params.timeOrder == 'asc'" class="iconfont icon-ic_up2 fs-14 ml-6 font-num"></text>
  26. <text v-show="params.timeOrder == ''" class="iconfont icon-ic_down2 fs-14 ml-6"></text>
  27. <!-- timeOrder -->
  28. </view>
  29. <view class="flex-y-center" @tap="changeTab(2)">
  30. <text :class="current == 2 ? 'font-num fw-500' : ''">价值</text>
  31. <text v-show="params.priceOrder == 'desc'" class="iconfont icon-ic_down2 fs-14 ml-6 font-num"></text>
  32. <text v-show="params.priceOrder == 'asc'" class="iconfont icon-ic_up2 fs-14 ml-6 font-num"></text>
  33. <text v-show="params.priceOrder == ''" class="iconfont icon-ic_down2 fs-14 ml-6"></text>
  34. </view>
  35. <view class="flex-y-center" @tap="showDrop = !showDrop">
  36. <text class="menu_line"></text>
  37. <text>筛选</text>
  38. <text class="iconfont icon-ic_sort pl-8"></text>
  39. </view>
  40. <view class="drop-box bg--w111-f5f5f5 flex justify-between" v-if="showDrop">
  41. <view class="inline-block h-52 rd-28rpx px-28 lh-52rpx text-center fs-24 bg--w111-fff"
  42. v-for="(item, index) in navList" :key="index"
  43. :class="params.type === item.type ? 'active-tab' : ''"
  44. @tap="setType(item.type)">{{item.name}}</view>
  45. </view>
  46. </view>
  47. <view class="px-20" v-if="couponsList.length">
  48. <view class="relative card-item" v-for="(item,index) in couponsList" :key="index">
  49. <view class="card w-full h-200 bg--w111-fff rd-24rpx p-20 flex justify-between"
  50. :class="{svip: item.receive_type === 4}">
  51. <view class="flex">
  52. <easy-loadimage
  53. mode="widthFix"
  54. :image-src="item.products[0].image"
  55. width="160rpx"
  56. height="160rpx"
  57. borderRadius="16rpx" v-if="item.products[0] && item.products[0].image"></easy-loadimage>
  58. <view class="w-160 h-160 rd-16rpx flex-center fs-22 text--w111-999" v-else>暂无商品</view>
  59. <view class="w-338 pl-24">
  60. <view class="w-286 h-72 lh-36rpx line2 fw-500" :class="item.is_use ? 'text--w111-ccc' : ''">{{item.title}}</view>
  61. <view class="fs-20 lh-28rpx mt-8" :class="item.is_use ? 'text--w111-ccc' : 'text--w111-666'"
  62. v-if="item.coupon_time">领取后{{item.coupon_time}}天内可用</view>
  63. <view class="fs-20 lh-28rpx mt-8" :class="item.is_use ? 'text--w111-ccc' : 'text--w111-666'"
  64. v-else>{{ item.start_time ? item.start_time + '-' : '' }}{{ item.end_time }}</view>
  65. <view class="flex-y-center fs-20 text--w111-999 lh-28rpx mt-20">
  66. <text>{{item.type | typeFilter}}</text>
  67. <view v-show="item.rule" @tap="toggleRule(item)">
  68. <text class="pl-8"> | 查看用券规则</text>
  69. <text class="iconfont icon-ic_downarrow fs-20 ml-4"></text>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <view class="flex-1 flex-col flex-center">
  75. <baseMoney
  76. :money="item.coupon_price"
  77. symbolSize="28"
  78. integerSize="44"
  79. decimalSize="28"
  80. :color="item.is_use ? '#cccccc' : item.receive_type === 4 ? '#333' : 'var(--view-theme)'"
  81. isCoupon
  82. v-if="item.coupon_type==1"></baseMoney>
  83. <view v-else class="fs-44 SemiBold"
  84. :style="{color: item.is_use ? '#cccccc' : item.receive_type === 4 ? '#333' : 'var(--view-theme)'}"
  85. >{{ parseFloat(item.coupon_price) / 10 }} <text class="pingfang fs-28 pl-4">折</text></view>
  86. <text class="fs-20 lh-28rpx mt-8"
  87. :class="item.is_use ? 'text--w111-ccc' : 'font-num'">满{{item.use_min_price}}可用</text>
  88. <view class="w-128 h-48 rd-30rpx flex-center fs-20 bg-hui text--w111-fff mt-16" v-if="item.is_use == true">已领取</view>
  89. <view class="w-128 h-48 rd-30rpx flex-center fs-20 bg-hui text--w111-fff mt-16" v-else-if="item.is_use == 2">已领完</view>
  90. <view class="w-128 h-48 rd-30rpx flex-center fs-20 bg-gradient text--w111-fff mt-16" v-else
  91. @tap="getCoupon(item.id, index)">立即领取</view>
  92. </view>
  93. </view>
  94. <view class="rule-desc" v-html="item.rule" v-show="item.ruleShow"></view>
  95. </view>
  96. </view>
  97. <view class='loadingicon flex-center' v-if="couponsList.length">
  98. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  99. </view>
  100. <view class="px-20" v-if="!couponsList.length">
  101. <emptyPage title="暂无优惠券,去看点别的吧~" src="/statics/images/noCoupon.gif"></emptyPage>
  102. </view>
  103. </view>
  104. <view class="mask" v-if="showDrop" @tap="showDrop = false"></view>
  105. </view>
  106. </template>
  107. <script>
  108. let sysHeight = uni.getSystemInfoSync().statusBarHeight;
  109. import { getCoupons, setCouponReceive } from '@/api/api.js';
  110. import emptyPage from '@/components/emptyPage.vue';
  111. import { toLogin } from '@/libs/login.js';
  112. import { mapGetters } from "vuex";
  113. import colors from '@/mixins/color.js';
  114. import {HTTP_REQUEST_URL} from '@/config/app';
  115. export default {
  116. mixins:[colors],
  117. components:{ emptyPage },
  118. data() {
  119. return {
  120. sysHeight:sysHeight,
  121. couponsList: [],
  122. loading: false,
  123. loadend: false,
  124. loadTitle: '加载更多', //提示语
  125. params:{
  126. page: 1,
  127. limit: 20,
  128. type: '',
  129. defaultOrder: 1,
  130. timeOrder: '',
  131. priceOrder: ''
  132. },
  133. isAuto: false, //没有授权的不会自动授权
  134. isShowAuth: false, //是否隐藏授权
  135. navList: [
  136. {name: '快过期',type: -1},
  137. {name: '通用券',type: 0},
  138. {name: '品类券',type: 1},
  139. {name: '商品券',type: 2},
  140. {name: '品牌券',type: 3},
  141. ],
  142. count: 0,
  143. imgHost:HTTP_REQUEST_URL,
  144. pageScrollStatus:false,
  145. showDrop: false,
  146. current:0,
  147. price: 0,
  148. };
  149. },
  150. computed:{
  151. ...mapGetters(['isLogin']),
  152. headerBg(){
  153. return 'linear-gradient(90deg, var(--view-gradient) 0%, var(--view-theme) 100%)'
  154. }
  155. },
  156. filters:{
  157. typeFilter(val){
  158. let obj = {
  159. 0: '通用券',
  160. 1: '品类券',
  161. 2: '商品券',
  162. 3: '品牌券',
  163. };
  164. return obj[val]
  165. }
  166. },
  167. onPageScroll(object) {
  168. if (object.scrollTop > 130) {
  169. this.pageScrollStatus = true;
  170. } else if (object.scrollTop < 130) {
  171. this.pageScrollStatus = false;
  172. }
  173. uni.$emit('scroll');
  174. },
  175. onLoad() {
  176. if (this.isLogin) {
  177. this.getUseCoupons();
  178. } else {
  179. toLogin()
  180. }
  181. },
  182. /**
  183. * 页面上拉触底事件的处理函数
  184. */
  185. onReachBottom() {
  186. this.getUseCoupons();
  187. },
  188. methods: {
  189. changeTab(val){
  190. this.current = val;
  191. if(val == 0){
  192. this.params.defaultOrder = 1;
  193. this.params.timeOrder = '';
  194. this.params.priceOrder = '';
  195. }else if(val == 1){
  196. if(this.params.timeOrder == '') {
  197. this.params.timeOrder = 'asc'
  198. }else if (this.params.timeOrder == 'asc'){
  199. this.params.timeOrder = 'desc'
  200. }else if(this.params.timeOrder == 'desc'){
  201. this.params.timeOrder = ''
  202. }
  203. this.params.defaultOrder = '';
  204. this.params.priceOrder = '';
  205. } else if(val == 2){
  206. if(this.params.priceOrder == '') {
  207. this.params.priceOrder = 'asc'
  208. }else if (this.params.priceOrder == 'asc'){
  209. this.params.priceOrder = 'desc'
  210. }else if(this.params.priceOrder == 'desc'){
  211. this.params.priceOrder = ''
  212. }
  213. this.params.defaultOrder = '';
  214. this.params.timeOrder = '';
  215. }
  216. this.params.page = 1;
  217. this.couponsList = [];
  218. this.loadend = false;
  219. this.loading = false;
  220. this.getUseCoupons();
  221. },
  222. toggleRule(item){
  223. item.ruleShow = !item.ruleShow
  224. },
  225. backPage(){
  226. uni.navigateBack()
  227. },
  228. goDetails(item){
  229. uni.navigateTo({
  230. url: '/pages/goods_details/index?id=' + item.id
  231. })
  232. },
  233. getCoupon: function(id, index) {
  234. let that = this;
  235. let list = that.couponsList;
  236. //领取优惠券
  237. setCouponReceive(id).then(function(res) {
  238. list[index].is_use = true;
  239. that.$set(that, 'couponsList', list);
  240. that.$util.Tips({
  241. title: '领取成功'
  242. });
  243. }).catch(error => {
  244. return that.$util.Tips({
  245. title: error
  246. });
  247. })
  248. },
  249. /**
  250. * 获取领取优惠券列表
  251. */
  252. getUseCoupons: function() {
  253. let that = this
  254. if (this.loadend) return false;
  255. if (this.loading) return false;
  256. that.loading = true;
  257. that.loadTitle = '加载更多';
  258. getCoupons(this.params).then(res => {
  259. let list = res.data.list,
  260. loadend = list.length < that.params.limit,
  261. countIndex = [];
  262. list.map(item=>{
  263. this.$set(item,'ruleShow',false);
  264. })
  265. let couponsList = that.$util.SplitArray(list, that.couponsList);
  266. that.$set(that, 'couponsList', couponsList);
  267. that.loadend = loadend;
  268. that.loading = false;
  269. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  270. that.params.page++;
  271. }).catch(err => {
  272. that.loading = false;
  273. that.loadTitle = '加载更多';
  274. });
  275. },
  276. setType(type) {
  277. if (this.params.type !== type) {
  278. this.params.type = type;
  279. this.couponsList = [];
  280. this.params.page = 1;
  281. this.loadend = false;
  282. this.showDrop = false;
  283. this.getUseCoupons();
  284. }
  285. }
  286. }
  287. };
  288. </script>
  289. <style scoped lang="scss">
  290. .abs-box{
  291. width: 264rpx;
  292. position: absolute;
  293. left: 48rpx;
  294. bottom: 80rpx;
  295. }
  296. .content{
  297. top: -44rpx;
  298. }
  299. .menu_line {
  300. width: 1rpx;
  301. height: 26rpx;
  302. background: #ccc;
  303. margin: 0 32rpx 0 20rpx;
  304. }
  305. ._box{
  306. padding: 28rpx 32rpx;
  307. background: #f5f5f5;
  308. position: sticky;
  309. z-index: 99;
  310. }
  311. .drop-box{
  312. width: 100%;
  313. height: 102rpx;
  314. position: absolute;
  315. left: 0;
  316. top: 92rpx;
  317. border-radius: 0 0 40rpx 40rpx;
  318. z-index: 199;
  319. padding: 16rpx 32rpx 0;
  320. }
  321. .active-tab{
  322. background: var(--view-minorColorT);
  323. color: var(--view-theme);
  324. border: 1px solid var(--view-theme);
  325. }
  326. .svip .font-num{
  327. color: #333333 !important;
  328. }
  329. .svip .bg-gradient{
  330. background: linear-gradient(90deg, #584834 0%, #32302D 100%);
  331. color: #FACC7D;
  332. }
  333. .bg-hui{
  334. color: #ffffff !important;
  335. background: #cccccc !important;
  336. }
  337. .indent{
  338. text-indent: 60rpx;
  339. }
  340. .card{
  341. background-image:
  342. radial-gradient(circle at 500rpx top, #f5f5f5, #f5f5f5 10rpx, transparent 11rpx),
  343. radial-gradient(circle at 500rpx bottom, #f5f5f5, #f5f5f5 10rpx, transparent 11rpx);
  344. position: relative;
  345. &:before{
  346. content: '';
  347. position: absolute;
  348. left: 500rpx;
  349. top: 16rpx;
  350. height: 168rpx;
  351. border-left: 2px dotted #ddd;
  352. }
  353. .name {
  354. width: 286rpx;
  355. height: 80rpx;
  356. line-height: 40rpx;
  357. color: #333;
  358. font-weight: 500;
  359. font-size: 28rpx;
  360. }
  361. .type-tag{
  362. display: inline-block;
  363. background: var(--view-minorColorT);
  364. color: var(--view-theme);
  365. border-radius: 14rpx;
  366. padding: 2rpx 10rpx;
  367. font-size: 20rpx;
  368. margin-right: 8rpx;
  369. vertical-align: middle;
  370. }
  371. }
  372. .card-item ~ .card-item{
  373. margin-top: 20rpx;
  374. }
  375. .rule-desc{
  376. margin-top: -16rpx;
  377. padding: 40rpx 24rpx 24rpx;
  378. white-space: pre-wrap;
  379. font-size: 20rpx;
  380. line-height: 28rpx;
  381. background: linear-gradient(180deg, #F7F7F7 0%, #FFFFFF 100%);
  382. border-radius: 0 0 24rpx 24rpx;
  383. color: #999;
  384. }
  385. .SemiBold{
  386. font-family: 'SemiBold'
  387. }
  388. .pingfang{
  389. font-family: PingFang SC, PingFang SC;
  390. }
  391. </style>