| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- <template>
- <view class="content">
- <view class="cont-box">
- <view class="goods-banner" @click="showImg()">
- <view class="cartbox" @click.stop="goCart()">
- <view class="box">
- <u-badge type="error" max="99" :value="cartNum" bgColor="#2BC7B9"></u-badge>
- </view>
- <u-icon name="shopping-cart" color="#2BC7B9" size="68rpx"></u-icon>
- </view>
- <swiper class="swiper" :indicator-dots="false" :circular="true" :autoplay="true" :interval="3000"
- :duration="1000" indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#ffffff"
- @change="swiperChange">
- <swiper-item class="swiper-item" v-for="(item,index) in imgs" :key="index">
- <image :src="item" mode="aspectFit"></image>
- </swiper-item>
- </swiper>
- <!-- 数量 -->
- <view class="num-box">{{ activeImg }}/{{ imgs.length }}</view>
- </view>
- <view class="integral-box">
- <view class="title">{{items.goodsName}}</view>
- <view class="num-box">
- <view class="x-ac">
- <view class="price">{{items.integral}} 积分</view>
- <view class="price-val" v-if="items.cash>0">+{{items.cash.toFixed(2)}} 元</view>
- </view>
- <view class="count">价值:{{items.otPrice.toFixed(2)}}元</view>
- </view>
- </view>
- <view class="desc-box">
- <view class="desc" v-html="items.descs">
- </view>
- </view>
- </view>
- <view class="btn-foot">
- <view class="p-price-box">
- <!-- <view class="p-name">兑换积分: </view> -->
- <view class="p-price">{{items.integral}}<text style="font-size: 20rpx;">积分</text></view>
- <view class="p-price" v-if="items.cash > 0">+{{items.cash.toFixed(2)}}<text
- style="font-size: 20rpx;">元</text></view>
- </view>
- <view class="btn-box">
- <view class="btn add" @click="openPop">
- 加入购物车
- </view>
- <view class="btn buy" @click="submit()">
- 立即兑换
- </view>
- </view>
- </view>
- <u-popup :show="show" mode="bottom" closeable @close="close">
- <view class="popbox">
- <view class="x-f">
- <image class="popbox-img" :src="items.imgUrl" mode="aspectFill"></image>
- <view class="info-text">
- <view class="price">
- <text class="unit">¥</text>
- <text class="num">{{items.cash.toFixed(2)}}</text>
- <text class="oldprice"> ¥{{items.otPrice.toFixed(2)}}</text>
- </view>
- <view class="text es-mt-16">所需积分:{{items.integral}}</view>
- <view class="desc-box es-mt-16">
- <text class="text">库存:{{items.stock>0?items.stock:'售罄'}} </text>
- </view>
- </view>
- </view>
- <!-- 数量 -->
- <view class="price-num x-bc" style="margin-top: 30rpx;">
- <view class="label">数量</view>
- <view class="num-box">
- <u-number-box v-model="num" integer :step="1" :min="1" :max="100000"></u-number-box>
- </view>
- </view>
- <view class="es-max-btn x-c" @click="addCart">
- 加入购物车
- </view>
- </view>
- </u-popup>
- </view>
- </template>
- <script>
- import {
- getIntegralGoodsById,
- createOrder,
- addOrUpdateCart,
- getCartCount
- } from '@/api/integral.js'
- export default {
- data() {
- return {
- imgs: [],
- activeImg: 1,
- goodsId: null,
- items: {
- cash: 0,
- otPrice: 0,
- integral: 0,
- goodsName: '',
- imgUrl: '',
- stock: 0,
- descs: ''
- },
- show: false,
- num: 1,
- cartNum: 0
- };
- },
- onLoad(option) {
- this.goodsId = option.goodsId;
- },
- onShow() {
- this.getIntegralGoodsById();
- this.getcartNum()
- },
- methods: {
- goCart() {
- uni.navigateTo({
- url: './cart'
- })
- },
- getcartNum() {
- getCartCount().then(res => {
- if (res.code == 200) {
- this.cartNum = res.data || 0
- }
- })
- },
- close() {
- this.show = false
- },
- openPop() {
- this.num = 1
- this.show = true
- },
- addCart() {
- if(this.cartNum>=this.items.stock){
- uni.showToast({
- title: '库存不足',
- icon: 'none'
- })
- this.show = false
- return;
- }
- uni.showLoading({
- title: '处理中'
- })
- addOrUpdateCart({
- cartNum: this.num,
- goodsId: this.goodsId,
- isCart: 0
- }).then(res => {
- uni.hideLoading()
- if (res.code == 200) {
- this.show = false
- uni.showToast({
- title: '加入购物车成功',
- icon: 'none'
- })
- this.getcartNum()
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- })
- },
- submit() {
- this.utils.isLogin().then(
- res => {
- if (res) {
- uni.navigateTo({
- url: "./integralOrderPay?goodsId=" + this.goodsId
- })
- } else {
- uni.navigateTo({
- url: '/pages/auth/login'
- })
- }
- }
- );
- },
- swiperChange(event) {
- this.activeImg = event.detail.current + 1
- },
- showImg() {
- //预览图片
- uni.previewImage({
- urls: this.imgs,
- current: this.imgs[0]
- });
- },
- getIntegralGoodsById() {
- let data = {
- goodsId: this.goodsId
- };
- getIntegralGoodsById(data).then(
- res => {
- if (res.code == 200) {
- this.items = res.data;
- console.log("全部是", this.items)
- if (res.data.images != null) {
- this.imgs = res.data.images.split(",")
- } else {
- this.activeImg = 0;
- }
- console.log(this.imgs)
- } else {
- uni.showToast({
- icon: 'none',
- title: "请求失败",
- });
- }
- },
- rej => {}
- );
- },
- }
- }
- </script>
- <style lang="scss">
- page {
- height: 100%;
- }
- .cartbox {
- position: fixed;
- bottom: 180rpx;
- right: 20rpx;
- z-index: 99;
- background-color: #fff;
- box-shadow: 0 2px 4px rgba(150, 150, 150, 0.6);
- padding: 10rpx;
- border-radius: 50%;
- .box {
- position: absolute;
- top: -10rpx;
- right: 0;
- z-index: 99;
- }
- }
- .es-mt-16 {
- margin-top: 16rpx;
- }
- .content {
- height: 100%;
- display: flex;
- flex-direction: column;
- .cont-box {
- padding-bottom: 121rpx;
- .integral-box {
- background-color: #fff;
- padding: 20rpx;
- width: 100%;
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- justify-content: flex-start;
- .title {
- font-weight: bold;
- font-size: 34rpx;
- font-family: PingFang SC;
- color: #111;
- }
- .desc {
- margin-top: 15rpx;
- display: flex;
- align-items: flex-start;
- justify-content: flex-start;
- .cycle {
- background-color: #eee;
- border-radius: 30rpx;
- padding: 5rpx 15rpx;
- font-size: 26rpx;
- font-family: PingFang SC;
- color: #2BC7B9;
- }
- .duration {
- margin-left: 10rpx;
- background-color: #eee;
- border-radius: 30rpx;
- padding: 5rpx 15rpx;
- font-size: 26rpx;
- font-family: PingFang SC;
- color: #2BC7B9;
- }
- }
- .num-box {
- margin-top: 15rpx;
- flex: 1;
- display: flex;
- align-items: flex-end;
- justify-content: space-between;
- width: 100%;
- .price {
- padding: 5rpx 10rpx;
- background-color: #2BC7B9;
- border-radius: 30rpx;
- font-size: 20rpx;
- font-family: PingFang SC;
- color: #ffffff;
- }
- .price-val {
- font-weight: bold;
- font-size: 28rpx;
- font-family: PingFang SC;
- color: #2BC7B9;
- }
- .count {
- font-size: 24rpx;
- font-family: PingFang SC;
- color: #333333;
- }
- }
- }
- .desc-box {
- background-color: #fff;
- padding: 20rpx;
- margin-top: 10rpx;
- .title-box {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: flex-start;
- .title {
- font-size: 32rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #111111;
- }
- .line {
- margin-right: 15rpx;
- height: 30rpx;
- width: 6rpx;
- background-color: #2BC7B9;
- }
- }
- .desc {
- margin-top: 15rpx;
- font-size: 28rpx;
- font-family: PingFang SC;
- color: #9a9a9c;
- }
- }
- }
- }
- .btn-foot {
- box-sizing: border-box;
- width: 100%;
- height: 121rpx;
- background: #FFFFFF;
- padding: 0 32rpx 0 28rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- position: fixed;
- left: 0;
- bottom: 0;
- z-index: 99;
- .p-price-box {
- .p-name {
- font-size: 28rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #666666;
- }
- .p-price {
- margin-left: 10rpx;
- color: #FF6633;
- font-size: 32rpx;
- font-family: PingFang SC;
- font-weight: bold;
- }
- }
- .btn-box {
- display: flex;
- align-items: center;
- .btn {
- width: 200rpx;
- height: 88rpx;
- line-height: 88rpx;
- text-align: center;
- border-radius: 44rpx;
- margin-left: 20rpx;
- font-size: 30rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #FFFFFF;
- &:first-child {
- margin-left: 0;
- }
- &.buy {
- background: #2BC7B9;
- }
- &.add {
- color: #2BC7B9 !important;
- border: 1rpx solid #2BC7B9;
- }
- }
- }
- }
- .goods-banner {
- height: 756rpx;
- background-color: #FFFFFF;
- position: relative;
- .swiper-item {
- box-sizing: border-box;
- }
- .swiper,
- .swiper-item,
- .swiper-item image {
- width: 100%;
- height: 100%;
- }
- .num-box {
- width: 80rpx;
- height: 44rpx;
- line-height: 44rpx;
- text-align: center;
- font-size: 24rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #FFFFFF;
- background: rgba(0, 0, 0, .3);
- border-radius: 22rpx;
- position: absolute;
- right: 30rpx;
- bottom: 30rpx;
- z-index: 10;
- }
- }
- .popbox {
- padding: 40rpx 32rpx;
- &-img {
- width: 200rpx;
- height: 200rpx;
- border-radius: 20rpx;
- margin-right: 24rpx;
- }
- .oldprice {
- font-size: 28rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #999999;
- margin-top: 27rpx;
- line-height: 1;
- text-decoration: line-through;
- margin-left: 24rpx;
- }
- .info-text {
- height: 200rpx;
- .price {
- display: flex;
- align-items: flex-end;
- .unit {
- font-size: 32rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #2BC7B9;
- line-height: 1.2;
- margin-right: 10rpx;
- }
- .num {
- font-size: 50rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #2BC7B9;
- line-height: 1;
- }
- }
- .text {
- font-size: 28rpx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #2BC7B9;
- }
- .desc-box {
- display: flex;
- flex-direction: column;
- padding-bottom: 9rpx;
- .text {
- font-size: 28rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #999999;
- margin-top: 27rpx;
- line-height: 1;
- &:first-child {
- margin-top: 0;
- }
- }
- }
- }
- }
- .es-max-btn {
- width: 100%;
- background-color: #2BC7B9;
- border-radius: 60rpx;
- margin-top: 50rpx;
- color: #fff;
- padding: 20rpx 0;
- box-sizing: border-box;
- }
- </style>
|