123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577 |
- <template>
- <view>
- <u-navbar title="商品详情" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
- <view class="detail" style="margin-bottom: 90rpx;">
- <view class="detail-top">
- <u-swiper :list="picUrlArr" height="375" radius="0" :indicator="true" :circular="true"></u-swiper>
- </view>
- <view class="detail-title">
- <view class="txt">{{ info.title }}</view>
- <view class="coin">
- <image src="../../static/icon/bean.png" mode=""></image>
- <view>× {{ info.exchangePrice }}</view>
- </view>
- </view>
- <view class="detail-goods">商品详情</view>
- <view class="detail-description">
- <view class="" v-html="description"></view>
- </view>
- <view style="detail-merchant" @click="toCompanyData" v-if="info.merchantInfo?true:false">
- <view class="detail-merchant-warp">
- <view class="detail-merchant-warp-one">商家信息</view>
- <view class="detail-merchant-warp-two">
- <view style="float: left;">前往查看</view>
- <u-icon style="float: right;" name="arrow-right" size="18"></u-icon>
- </view>
- </view>
- </view>
- </view>
- <view class="footer-fixed">
- <view class="flex btn">
- <button type="default" @click="exChange">立即兑换</button>
- </view>
- </view>
- <!-- 兑换选择 -->
- <u-popup :show="choiceShow" mode="bottom" @close="close" :closeable="true">
- <view class="choiceShow-wrap">
- <view class="flex goods">
- <view class="flex image-wrap">
- <image :src="payInfo.picUrl" mode="aspectFill"></image>
- </view>
- <view class="info">
- <view class="info-title">{{ info.title }}</view>
- <view class="info-coin">
- <image src="../../static/icon/bean.png" mode=""></image>
- <view>× {{ payInfo.exValue }}</view>
- </view>
- <view class="info-stock">库存:{{ payInfo.quantity }}</view>
- </view>
- </view>
- <view class="sku" v-for="(item, index) in skuList" :key="index">
- <view class="sku-title">{{ item.name }}</view>
- <view class="flex sku-list">
- <view
- :class="{'action': item.actionIndex == indexs, 'sku-list-item': item.actionIndex != indexs}"
- v-for="(ele, indexs) in item.value" :key="indexs" @click="getSku(ele, item, indexs)">
- {{ ele }}
- </view>
- </view>
- </view>
- <view class="flex quantity">
- <view class="quantity-title">兑换数量</view>
- <view class="quantity-title">
- <u-number-box v-model="orderNum" :min="1" :disabledInput="true"
- @change="valChange($event, payInfo)"></u-number-box>
- </view>
- </view>
- <view class="flex btn">
- <view class="flex btn-left">
- <view class="title">应付:</view>
- <view class="flex coin">
- <image src="../../static/icon/bean.png" mode=""></image>
- <view>× {{ payInfo.exchangePrice }}</view>
- </view>
- </view>
- <view class="btn-right">
- <view class="confirm" @click="confirmPrize">立即兑换</view>
- </view>
- </view>
- </view>
- </u-popup>
- <u-popup :show="tipShow" mode="center">
- <view class="tip-show">
- <view class="flex tip-show-title">
- <u-icon name="checkmark-circle" color="#EB7009" size="24"></u-icon>
- <text>兑换成功,已放入奖品库</text>
- </view>
- <view class="flex tip-show-btn">
- <view class="close" @click="tipShow = false">关闭</view>
- <navigator class="prize" :url="`/packagePrize/prize/index`" hover-class="navigator-hover"
- @click="tipShow = false">前往查看</navigator>
- </view>
- </view>
- </u-popup>
- </view>
- </template>
- <script>
- import env from '../../config/env.js'
- import $http from '@/utils/request.js'
- export default {
- data() {
- return {
- goodsId: '',
- boxId: '',
- picUrlArr: [],
- info: {},
- prizeList: [],
- description: '',
- choiceShow: false,
- initData: {},
- orderNum: 1,
- skuList: [],
- skuListInit: [],
- payInfo: {},
- tipShow: false
- };
- },
- onLoad(opthios) {
- this.goodsId = opthios.id
- },
- onShow() {
- this.getDetail()
- },
- methods: {
- getDetail() {
- uni.showLoading({
- title: '加载中'
- });
- $http.post('/api/v1/mp/user/exchange/goods/detail', {
- goodsId: this.goodsId,
- noToken: true
- }).then(res => {
- uni.hideLoading();
- if (res.code == 0) {
- this.info = res.data
- let picUrlArr = res.data.picUrl.split(',')
- picUrlArr.forEach(item => {
- this.picUrlArr.push(env.filePublic + item + '?imageView2/2/w/750')
- })
- // 处理富文本
- const description = res.data.description.replaceAll(".jpg\"", ".jpg?imageView2/2/w/750\"")
- .replaceAll(".jpeg\"", ".jpeg?imageView2/2/w/750\"").replaceAll(".png\"",
- ".png?imageView2/2/w/750\"");
- this.description = this.formatRichText(description);
- this.skuListInit = res.data.skuList
- if (res.data.skuList.length) {
- let skuProp = JSON.parse(res.data.skuProp)
- skuProp.forEach(item => {
- item.actionIndex = 0,
- item.txt = `${item.name}:${item.value[0]}`
- })
- let actionSku = skuProp.map(item => {
- return item.txt
- }).join(';')
- let sku = res.data.skuList.find(item => {
- return item.properties == actionSku
- })
- this.payInfo = {
- ...sku,
- exValue: sku.exchangePrice,
- picUrl: env.filePublic + sku.picUrl
- }
- this.skuList = skuProp
- } else {
- this.payInfo = {
- ...res.data,
- exValue: this.info.exchangePrice,
- picUrl: this.picUrlArr[0]
- }
- }
- }
- }).catch(() => {
- uni.hideLoading();
- })
- },
- getBean() {
- uni.showLoading({
- title: '加载中'
- });
- $http.post('/api/v1/mp/user/mine/init', {}).then(res => {
- uni.hideLoading();
- if (res.code == 0) {
- this.initData = res.data
- }
- }).catch(() => {
- uni.hideLoading();
- })
- },
- exChange() {
- this.choiceShow = true
- },
- close() {
- this.choiceShow = false
- },
- valChange(e, item) {
- let value = e.value
- this.$set(item, 'exchangePrice', value * item.exValue)
- if (this.payInfo.quantity < value) {
- uni.$u.toast('库存不足');
- }
- },
- getSku(e, item, indexs) {
- this.$set(item, 'txt', `${item.name}:${e}`)
- this.$set(item, 'actionIndex', indexs)
- this.orderNum = 1
- let actionSku = this.skuList.map(item => {
- return item.txt
- }).join(';')
- let sku = this.skuListInit.find(item => {
- return item.properties == actionSku
- })
- this.payInfo = {
- ...sku,
- exValue: sku.exchangePrice,
- picUrl: env.filePublic + sku.picUrl
- }
- },
- confirmPrize() {
- let flag = false
- let data = {
- goodsId: this.payInfo.goodsId,
- skuId: this.payInfo.skuId,
- orderNum: this.orderNum,
- }
- if (flag) return
- if (this.payInfo.quantity == 0) {
- uni.$u.toast('库存不足');
- return
- }
- if (this.payInfo.quantity < this.orderNum) {
- uni.$u.toast('库存不足');
- return
- }
- uni.showLoading({
- title: '兑换中'
- });
- flag = true
- $http.post('/api/v1/mp/user/exchange/submit', data).then(res => {
- uni.hideLoading();
- flag = false
- if (res.code == 0) {
- this.choiceShow = false
- this.tipShow = true
- this.getDetail()
- } else if (res.code == 1021) {
- uni.$u.toast(res.msg);
- }
- }).catch(() => {
- flag = false
- uni.hideLoading();
- })
- },
-
- toCompanyData(){
- uni.navigateTo({
- url:`/packageGoods/goods/company?goodsId=${ this.goodsId }`
- })
- },
- /**
- * 处理富文本里的图片宽度自适应
- * 1.去掉img标签里的style、width、height属性
- * 2.img标签添加style属性:max-width:100%;height:auto
- * 3.修改所有style里的width属性为max-width:100%
- * 4.去掉<br/>标签
- * @param html
- * @returns {void|string|*}
- */
- formatRichText(html) { //控制小程序中图片大小
- let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
- match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
- match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
- match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
- return match;
- });
- newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
- match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
- 'max-width:100%;');
- return match;
- });
- newContent = newContent.replace(/<br[^>]*\/>/gi, '');
- newContent = newContent.replace(/\<img/gi,
- '<img style="max-width:100%;height:auto;margin:10rpx auto;"');
- return newContent;
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- </style>
- <style lang="scss" scoped>
- .detail {
- padding-bottom: 100rpx;
- &-top {
- height: 750rpx;
- background-color: #FFFFFF;
- }
- &-title {
- padding: 24rpx;
- background-color: #FFFFFF;
- margin-bottom: 10rpx;
- .txt {
- font-size: 32rpx;
- line-height: 44rpx;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- margin-bottom: 24rpx;
- font-weight: bold;
- }
- .coin {
- display: flex;
- align-items: center;
- font-size: 32rpx;
- line-height: 44rpx;
- color: rgba(235, 112, 9, 100);
- }
- image {
- width: 42rpx;
- height: 42rpx;
- margin-right: 20rpx;
- }
- }
- &-goods {
- height: 88rpx;
- text-align: center;
- line-height: 88rpx;
- font-weight: bold;
- background-color: #FFFFFF;
- }
- &-merchant {
- height: 88rpx;
- // text-align: center;
- line-height: 88rpx;
- font-weight: bold;
- background-color: #FFFFFF;
- &-warp {
- height: 88rpx;
- width: 100%;
- background-color: #ffffff;
- // margin-top: 10rpx;
- &-one {
- float: left;
- margin: 20rpx;
- font-weight: 600;
- }
- &-two {
- float: right;
- margin: 20rpx;
- font-weight: 600;
- }
- }
- }
- &-description {
- image {
- width: 100%;
- }
- }
- }
- .choiceShow-wrap {
- min-height: 400rpx;
- padding: 80rpx 20rpx 60rpx;
- .goods {
- justify-content: space-between;
- margin-bottom: 20rpx;
- .image-wrap {
- width: 220rpx;
- height: 220rpx;
- border: 1px solid rgba(236, 236, 236, 100);
- border-radius: 10rpx;
- image {
- width: 174rpx;
- height: 174rpx;
- }
- }
- .info {
- flex: 1;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- padding-left: 26rpx;
- height: 220rpx;
- &-title {
- font-size: 32rpx;
- line-height: 44rpx;
- font-weight: bold;
- }
- &-coin {
- display: flex;
- align-items: center;
- font-size: 32rpx;
- line-height: 44rpx;
- color: rgba(235, 112, 9, 100);
- font-weight: bold;
- image {
- width: 42rpx;
- height: 42rpx;
- margin-right: 20rpx;
- }
- }
- &-stock {
- line-height: 44rpx;
- }
- }
- }
- .sku {
- margin-bottom: 30rpx;
- &-title {
- line-height: 42rpx;
- }
- &-list {
- justify-content: flex-start;
- &-item {
- line-height: 44rpx;
- padding: 0 20rpx;
- border: 1px solid rgba(187, 187, 187, 100);
- margin-left: 36rpx;
- }
- .action {
- line-height: 44rpx;
- padding: 0 20rpx;
- margin-left: 36rpx;
- border: 1px solid $uni-bg-color;
- }
- }
- }
- .quantity {
- justify-content: space-between;
- margin-bottom: 40rpx;
- }
- .btn {
- justify-content: space-between;
- &-left {
- .coin {
- display: flex;
- align-items: center;
- font-size: 32rpx;
- line-height: 44rpx;
- color: rgba(235, 112, 9, 100);
- font-weight: bold;
- margin-left: 20rpx;
- image {
- width: 42rpx;
- height: 42rpx;
- margin-right: 20rpx;
- }
- }
- }
- &-right {
- .confirm {
- width: 280rpx;
- height: 90rpx;
- font-size: 36rpx;
- line-height: 90rpx;
- border-radius: 10rpx;
- background-color: rgba(235, 112, 9, 100);
- color: rgba(255, 255, 255, 100);
- text-align: center;
- }
- }
- }
- }
- .tip-show {
- width: 80vw;
- background-color: #FFFFFF;
- border-radius: 10rpx;
- padding: 60rpx 40rpx;
- &-title {
- margin-bottom: 64rpx;
- text {
- margin-left: 20rpx;
- }
- }
- &-btn {
- justify-content: space-around;
- .close {
- width: 160rpx;
- height: 60rpx;
- line-height: 60rpx;
- border-radius: 8rpx;
- color: rgba(235, 112, 9, 100);
- font-size: 28rpx;
- text-align: center;
- border: 1px solid rgba(235, 112, 9, 100);
- }
- .prize {
- width: 160rpx;
- height: 60rpx;
- line-height: 60rpx;
- border-radius: 8rpx;
- color: rgba(235, 112, 9, 100);
- font-size: 28rpx;
- text-align: center;
- background-color: rgba(235, 112, 9, 100);
- color: rgba(255, 255, 255, 100);
- font-size: 14px;
- }
- }
- }
- .footer-fixed {
- position: fixed;
- bottom: var(--window-bottom);
- left: 0;
- right: 0;
- z-index: 11;
- box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
- background: #fff;
- // 设置ios刘海屏底部横线安全区域
- padding-bottom: constant(safe-area-inset-bottom);
- padding-bottom: env(safe-area-inset-bottom);
- .btn {
- padding: 20rpx 0;
- /deep/ button {
- width: 640rpx;
- height: 90rpx;
- line-height: 90rpx;
- font-size: 36rpx;
- color: #fff;
- background-color: $uni-bg-color;
- border: none;
- border-radius: 20rpx;
- }
- }
- }
- </style>
|