Commit d5f50ff98c145702402225fc43833401186a84da
1 parent
91af2c97
网家家工会,优惠券领取组件~ 完成~
Showing
9 changed files
with
298 additions
and
4 deletions
src/components/getCouponCom/getCouponCom.less
0 → 100644
| 1 | +@charset "UTF-8"; | |
| 2 | + | |
| 3 | +.coupon-com { | |
| 4 | + background-color: transparent; | |
| 5 | + .box { | |
| 6 | + display: flex; | |
| 7 | + justify-content: space-between; | |
| 8 | + align-items: center; | |
| 9 | + .coupons-box { | |
| 10 | + display: flex; | |
| 11 | + justify-content: space-between; | |
| 12 | + align-items: center; | |
| 13 | + background-repeat: no-repeat; | |
| 14 | + background-size: 100% 100%; | |
| 15 | + margin: 0 auto; | |
| 16 | + width: 256px; | |
| 17 | + height: 120px; | |
| 18 | + .left-box { | |
| 19 | + background-repeat: no-repeat; | |
| 20 | + background-size: 100% 100%; | |
| 21 | + margin-left: 25px; | |
| 22 | + font-weight: 400; | |
| 23 | + width: 170px; | |
| 24 | + height: 120px; | |
| 25 | + .discount-box { | |
| 26 | + display: flex; | |
| 27 | + justify-content: flex-start; | |
| 28 | + align-items: baseline; | |
| 29 | + margin-top: 20px; | |
| 30 | + line-height: 42px; | |
| 31 | + .sy { | |
| 32 | + font-size: 20px; | |
| 33 | + font-weight: 600; | |
| 34 | + } | |
| 35 | + .discount { | |
| 36 | + font-size: 50px; | |
| 37 | + font-weight: 600; | |
| 38 | + white-space: nowrap; | |
| 39 | + text-overflow: ellipsis; | |
| 40 | + overflow: hidden; | |
| 41 | + } | |
| 42 | + } | |
| 43 | + .filled-box { | |
| 44 | + font-size: 24px; | |
| 45 | + font-weight: 400; | |
| 46 | + white-space: nowrap; | |
| 47 | + text-overflow: ellipsis; | |
| 48 | + overflow: hidden; | |
| 49 | + } | |
| 50 | + } | |
| 51 | + } | |
| 52 | + } | |
| 53 | + &.usable { | |
| 54 | + .box { | |
| 55 | + .coupons-box { | |
| 56 | + .left-box { | |
| 57 | + .discount-box { | |
| 58 | + .sy { | |
| 59 | + color: #EA162D; | |
| 60 | + } | |
| 61 | + .discount { | |
| 62 | + color: #EA162D; | |
| 63 | + } | |
| 64 | + } | |
| 65 | + .filled-box { | |
| 66 | + color: #966F4A; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + } | |
| 70 | + } | |
| 71 | + } | |
| 72 | + &.disable { | |
| 73 | + .box { | |
| 74 | + .coupons-box { | |
| 75 | + .left-box { | |
| 76 | + .discount-box { | |
| 77 | + .sy { | |
| 78 | + color: #B4B4B4; | |
| 79 | + } | |
| 80 | + .discount { | |
| 81 | + color: #B4B4B4; | |
| 82 | + } | |
| 83 | + } | |
| 84 | + .filled-box { | |
| 85 | + color: #B4B4B4; | |
| 86 | + } | |
| 87 | + } | |
| 88 | + } | |
| 89 | + } | |
| 90 | + } | |
| 91 | +} | |
| 0 | 92 | \ No newline at end of file | ... | ... |
src/components/getCouponCom/getCouponCom.vue
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="coupon-com" :class="{'usable': coupons.state == '0', 'disable': coupons.state == '1'}" v-if="coupons"> | |
| 3 | + <div class="box"> | |
| 4 | + <div class="coupons-box" :style="{'backgroundImage': 'url(' + (coupons.state == '1' ? couponsLeftBgDisable : couponsLeftBgUsable) + ')'}" @click="todo(coupons, index)"> | |
| 5 | + <div class="left-box"> | |
| 6 | + <div class="discount-box"> | |
| 7 | + <div class="sy">¥</div> | |
| 8 | + <div class="discount">{{parseFloat(coupons.discount) === parseInt(coupons.discount) ? parseInt(coupons.discount) : coupons.discount}}</div> | |
| 9 | + </div> | |
| 10 | + <div class="filled-box"> | |
| 11 | + 满{{parseFloat(coupons.filled) === parseInt(coupons.filled) ? parseInt(coupons.filled) : coupons.filled}}元可用 | |
| 12 | + </div> | |
| 13 | + </div> | |
| 14 | + <div class="right-box"> | |
| 15 | + | |
| 16 | + </div> | |
| 17 | + </div> | |
| 18 | + </div> | |
| 19 | + </div> | |
| 20 | +</template> | |
| 21 | + | |
| 22 | +<script> | |
| 23 | + export default { | |
| 24 | + name: 'couponCom', | |
| 25 | + data: function () { | |
| 26 | + return { | |
| 27 | + couponsLeftBgUsable: 'static/img/coupon_usable.png', // 优惠券左侧背景(可使用) | |
| 28 | + couponsLeftBgDisable: 'static/img/coupon_disable.png' // 优惠券左侧背景(不可用) | |
| 29 | + } | |
| 30 | + }, | |
| 31 | + props: ["coupons", "index"], | |
| 32 | + methods: { | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 优惠券点击事件 | |
| 36 | + * @param {Object} coupons [优惠券对象] | |
| 37 | + * @param {Number} index [对象位置索引] | |
| 38 | + */ | |
| 39 | + todo(coupons, index) { | |
| 40 | + | |
| 41 | + // 抛出优惠券选择事件 | |
| 42 | + this.$emit('todo', coupons, index); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + } | |
| 46 | +</script> | |
| 47 | + | |
| 48 | +<!-- Add "scoped" attribute to limit CSS to this component only --> | |
| 49 | +<style rel="stylesheet/less" lang="less"> | |
| 50 | + @import './getCouponCom'; | |
| 51 | +</style> | |
| 0 | 52 | \ No newline at end of file | ... | ... |
src/components/horizList/horizList.less
| ... | ... | @@ -139,5 +139,22 @@ |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | + &.com-coupon { | |
| 143 | + .h-box { | |
| 144 | + .scroll-box { | |
| 145 | + > .box { | |
| 146 | + display: block; | |
| 147 | + white-space: nowrap; | |
| 148 | + width: 100%; | |
| 149 | + .item-box { | |
| 150 | + padding-right: 30px; | |
| 151 | + &:last-child { | |
| 152 | + padding-right: 0; | |
| 153 | + } | |
| 154 | + } | |
| 155 | + } | |
| 156 | + } | |
| 157 | + } | |
| 158 | + } | |
| 142 | 159 | } |
| 143 | 160 | } | ... | ... |
src/components/horizList/horizList.vue
| ... | ... | @@ -30,9 +30,14 @@ |
| 30 | 30 | com=tab:titleSubTitleCom组件,无pid参数 |
| 31 | 31 | 事件: |
| 32 | 32 | @changeTab:切换tab事件 |
| 33 | + | |
| 33 | 34 | com=tab2:tabsCom组件,无pid参数 |
| 34 | 35 | 事件: |
| 35 | 36 | @change:切换tab事件 |
| 37 | + | |
| 38 | + com=coupon:couponCom组件,无pid参数 | |
| 39 | + 事件: | |
| 40 | + @todo:优惠券点击事件 | |
| 36 | 41 | |
| 37 | 42 | --> |
| 38 | 43 | |
| ... | ... | @@ -80,6 +85,12 @@ |
| 80 | 85 | :index="index" |
| 81 | 86 | :active="pid"> |
| 82 | 87 | </tabs-com> |
| 88 | + | |
| 89 | + <!-- 优惠券 --> | |
| 90 | + <get-coupon-com v-if="com === 'coupon'" @todo="todo" | |
| 91 | + :coupons="item" | |
| 92 | + :index="index"> | |
| 93 | + </get-coupon-com> | |
| 83 | 94 | </div> |
| 84 | 95 | </div> |
| 85 | 96 | </div> |
| ... | ... | @@ -99,6 +110,7 @@ |
| 99 | 110 | import shopDarenHot from "@/components/shopDarenHot/shopDarenHot"; |
| 100 | 111 | import titleSubTitleCom from "@/components/titleSubTitleCom/titleSubTitleCom"; |
| 101 | 112 | import tabsCom from "@/components/tabsCom/tabsCom"; |
| 113 | + import getCouponCom from "@/components/getCouponCom/getCouponCom"; | |
| 102 | 114 | |
| 103 | 115 | export default { |
| 104 | 116 | name: "horizList", |
| ... | ... | @@ -117,7 +129,8 @@ |
| 117 | 129 | swiperItem, |
| 118 | 130 | shopDarenHot, |
| 119 | 131 | titleSubTitleCom, |
| 120 | - tabsCom | |
| 132 | + tabsCom, | |
| 133 | + getCouponCom | |
| 121 | 134 | }, |
| 122 | 135 | methods: { |
| 123 | 136 | |
| ... | ... | @@ -179,6 +192,17 @@ |
| 179 | 192 | }, |
| 180 | 193 | |
| 181 | 194 | /** |
| 195 | + * 优惠券点击事件 | |
| 196 | + * @param {Object} coupons [优惠券对象] | |
| 197 | + * @param {Number} index [对象位置索引] | |
| 198 | + */ | |
| 199 | + todo(coupons, index) { | |
| 200 | + | |
| 201 | + // 抛出优惠券选择事件 | |
| 202 | + this.$emit('todo', coupons, index); | |
| 203 | + }, | |
| 204 | + | |
| 205 | + /** | |
| 182 | 206 | * 设置横向滚动 |
| 183 | 207 | * @param {object} wrapper [需要设置滚动的对象] |
| 184 | 208 | */ | ... | ... |
src/pages/optimization2/optimization2.vue
| ... | ... | @@ -252,7 +252,7 @@ |
| 252 | 252 | <!-- 热销排行 --> |
| 253 | 253 | <div class="section hot-box" ref="hotBox" v-if="sales && sales.length" @click="toHotSaleList"> |
| 254 | 254 | |
| 255 | - <!-- 商品样式 2 滑动 --> | |
| 255 | + <!-- 商品样式 10 滑动 --> | |
| 256 | 256 | <!-- <horiz-list class="components-box" |
| 257 | 257 | :lists="sales" |
| 258 | 258 | com="10" | ... | ... |
src/pages/shopList/shopList.less
| ... | ... | @@ -49,6 +49,21 @@ |
| 49 | 49 | &.banner-box { |
| 50 | 50 | margin-top: 30px; |
| 51 | 51 | } |
| 52 | + &.coupon-box { | |
| 53 | + margin: 30px auto 0 auto; | |
| 54 | + overflow: hidden; | |
| 55 | + /deep/.coupon-horiz-box { | |
| 56 | + width: 690px; | |
| 57 | + > .box { | |
| 58 | + width: 690px; | |
| 59 | + } | |
| 60 | + } | |
| 61 | + } | |
| 62 | + } | |
| 63 | + .dividing-line { | |
| 64 | + background-color: #F9F9F9; | |
| 65 | + width: 100%; | |
| 66 | + height: 10px; | |
| 52 | 67 | } |
| 53 | 68 | .tabs-box { |
| 54 | 69 | background-color: #ffffff; | ... | ... |
src/pages/shopList/shopList.vue
| ... | ... | @@ -32,6 +32,19 @@ |
| 32 | 32 | }"> |
| 33 | 33 | </swiper-box> |
| 34 | 34 | </div> |
| 35 | + | |
| 36 | + <!-- 节 --> | |
| 37 | + <div class="section coupon-box" v-if="coupons && coupons.length"> | |
| 38 | + | |
| 39 | + <!-- 优惠券列表 滑动 --> | |
| 40 | + <horiz-list class="coupon-horiz-box" @todo="todo" | |
| 41 | + :lists="coupons" | |
| 42 | + com="coupon"> | |
| 43 | + </horiz-list> | |
| 44 | + </div> | |
| 45 | + | |
| 46 | + <!-- 分割线 --> | |
| 47 | + <div class="dividing-line" v-if="coupons && coupons.length"></div> | |
| 35 | 48 | |
| 36 | 49 | <!-- tab导航 --> |
| 37 | 50 | <div class="tabs-box" :class="{'is-cnlive': isCNLive.value, 'is-open-app': $parent.isOpenApp.value, 'is-hide': $route.query.hideBack == true, 'tabsFixed': tabs.fixed}" ref='tabsBox'> |
| ... | ... | @@ -97,6 +110,7 @@ |
| 97 | 110 | LOAD_MORE: "loadMore" // 加载更多 |
| 98 | 111 | }, |
| 99 | 112 | swipers: null, // 主Banner |
| 113 | + coupons: null, // 优惠券数据对象 | |
| 100 | 114 | tabs: { // tabs设置 |
| 101 | 115 | fixed: false, // 是否吸顶 |
| 102 | 116 | offsetTop: 0, // 距离顶部距离 |
| ... | ... | @@ -277,7 +291,8 @@ |
| 277 | 291 | |
| 278 | 292 | // 获取证书请求接口 |
| 279 | 293 | this.http("/Api/" + (this.getApiVersion().index) + "/getActShopIndex", { |
| 280 | - id: this.$route.query.shop_id | |
| 294 | + id: this.$route.query.shop_id, | |
| 295 | + uid: this.$route.query.uid || 0 | |
| 281 | 296 | }, this.getActShopIndexCallback, { |
| 282 | 297 | method: "POST" |
| 283 | 298 | }); |
| ... | ... | @@ -322,6 +337,13 @@ |
| 322 | 337 | this.$set(this, 'swipers', datas.banner); |
| 323 | 338 | } |
| 324 | 339 | |
| 340 | + // 如果有优惠券,设置优惠券信息 | |
| 341 | + if (datas.coupon && datas.coupon.length) { | |
| 342 | + | |
| 343 | + // 设置优惠券 | |
| 344 | + this.$set(this, 'coupons', datas.coupon); | |
| 345 | + } | |
| 346 | + | |
| 325 | 347 | // 获取tabs数据 |
| 326 | 348 | if (datas.list && datas.list.length) { |
| 327 | 349 | |
| ... | ... | @@ -435,6 +457,58 @@ |
| 435 | 457 | }, |
| 436 | 458 | |
| 437 | 459 | /** |
| 460 | + * 领取优惠券 | |
| 461 | + * @param {Object} coupons [优惠券对象] | |
| 462 | + */ | |
| 463 | + getUserCoupon(coupons) { | |
| 464 | + | |
| 465 | + // 判断必要参数 | |
| 466 | + if (this.$route.query.uid && coupons.id) { | |
| 467 | + | |
| 468 | + // 加载中提示 | |
| 469 | + Indicator.open("加载中..."); | |
| 470 | + | |
| 471 | + // 获取证书请求接口 | |
| 472 | + this.http("/Api/" + (this.getApiVersion().index) + "/getUserCoupon", { | |
| 473 | + coupon_id: coupons.id, | |
| 474 | + uid: this.$route.query.uid | |
| 475 | + }, this.getUserCouponCallback, { | |
| 476 | + method: "POST", | |
| 477 | + coupons | |
| 478 | + }); | |
| 479 | + } | |
| 480 | + }, | |
| 481 | + | |
| 482 | + /** | |
| 483 | + * 领取优惠券回调 | |
| 484 | + * @param {Object} res [服务器返回数据] | |
| 485 | + * @param {Object} ext [扩展参数] | |
| 486 | + */ | |
| 487 | + getUserCouponCallback(res, ext) { | |
| 488 | + | |
| 489 | + // 加载完成 | |
| 490 | + Indicator.close(); | |
| 491 | + | |
| 492 | + // 返回处理 | |
| 493 | + if (res.code == 200) { | |
| 494 | + | |
| 495 | + // 设置优惠券状态(不能再领取) | |
| 496 | + this.$set(ext.coupons, 'state', '1'); | |
| 497 | + | |
| 498 | + // 领取成功提示 | |
| 499 | + Toast('领取成功'); | |
| 500 | + } else if (res.code == 400) { | |
| 501 | + | |
| 502 | + // 获取数据失败 | |
| 503 | + Toast(res.message); | |
| 504 | + } else { | |
| 505 | + | |
| 506 | + // 获取数据失败 | |
| 507 | + Toast("获取数据失败"); | |
| 508 | + } | |
| 509 | + }, | |
| 510 | + | |
| 511 | + /** | |
| 438 | 512 | * swiper跳转事件 |
| 439 | 513 | * @param {Object} item [数据对象] |
| 440 | 514 | */ |
| ... | ... | @@ -462,6 +536,28 @@ |
| 462 | 536 | this.openApp(); |
| 463 | 537 | } |
| 464 | 538 | }, |
| 539 | + | |
| 540 | + /** | |
| 541 | + * 优惠券点击事件 | |
| 542 | + * @param {Object} coupons [优惠券对象] | |
| 543 | + */ | |
| 544 | + todo(coupons) { | |
| 545 | + | |
| 546 | + // 判断必要参数 | |
| 547 | + if (coupons.id) { | |
| 548 | + | |
| 549 | + // 判断优惠券状态 | |
| 550 | + if (coupons.state == '0') { | |
| 551 | + | |
| 552 | + // 领取优惠券 | |
| 553 | + this.getUserCoupon(coupons); | |
| 554 | + } else if (coupons.state == '1') { | |
| 555 | + | |
| 556 | + // 已经领取过优惠券提示 | |
| 557 | + Toast('您已领取该优惠劵'); | |
| 558 | + } | |
| 559 | + } | |
| 560 | + }, | |
| 465 | 561 | |
| 466 | 562 | /** |
| 467 | 563 | * 跳转商品详情 |
| ... | ... | @@ -671,7 +767,7 @@ |
| 671 | 767 | if (document.hidden === false && this.$route.name == 'shopList') { |
| 672 | 768 | |
| 673 | 769 | // 获取页面头部数据 |
| 674 | - // this.ghIndex(); | |
| 770 | + this.getActShopIndex(); | |
| 675 | 771 | } |
| 676 | 772 | }); |
| 677 | 773 | } | ... | ... |
static/img/coupon_disable.png
0 → 100644
4.3 KB
static/img/coupon_usable.png
0 → 100644
11.3 KB