123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573 |
- <template>
- <view style="padding-bottom: 100upx;">
- <view style="background: white;padding-bottom: 10upx;">
- <view class="section carousel-wrapper">
- <swiper class="carousel" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000"
- circular>
- <swiper-item v-for="image in product.images">
- <view class="swiper-item">
- <image class="image" :src="image|imagesFilter" mode=""></image>
- </view>
- </swiper-item>
- </swiper>
- </view>
- <view class="row row-1">
- <text class="title"><text class="sxzg-icon">省心直供</text>{{product.name}}</text>
- </view>
- <view class="row row-2">
- <text class="org-price">¥{{product.org_price}}</text>
- <text class="stock">剩余库存{{product.stock}}</text>
- </view>
- <view class="row row-3">
- <text class="sxj-icon" style="padding: 0upx 6upx;">省心价</text>
- <text class="price">¥{{product.price}}</text>
- </view>
- </view>
- <view class="details">
- <view class="btn" @tap="detailsIsOpen=!detailsIsOpen">
- <view>点击查看商品详情</view>
- <view class="arrow" :class="{'rotate':detailsIsOpen}">
- <uni-icons type="arrowright"></uni-icons>
- </view>
- </view>
- <view class="content" :class="{'show':detailsIsOpen}">
- <rich-text :nodes="product.details"></rich-text>
- </view>
- </view>
- <view class="section" style="margin-top: 20upx;">
- <view class="col-img-title">
- <image src="../../static/images/like.png" mode="scaleToFill" style="height: 28rpx;width: 363rpx;">
- </image>
- </view>
- <view class="like">
- <scroll-view scroll-x="true" :show-scrollbar="false" :enable-flex="true" style="white-space: nowrap;">
- <template v-for="product in likeProducts">
- <product-item type="swiper" :id="product.id" :image="product.images|imagesFilter"
- :title="product.name" :org-price="product.org_price" :price="product.price"></product-item>
- </template>
- </scroll-view>
- </view>
- </view>
- <view class="footer">
- <view class="collect">
- <view>
- <uni-icons v-if="collectionStatus" @tap="delCollection()" type="heart-filled" size="24"
- color="#ff5d5b"></uni-icons>
- <uni-icons v-if="!collectionStatus" @tap="addCollection()" type="heart" size="24"></uni-icons>
- </view>
- <view v-if="collectionStatus" style="font-size: 24upx;color:#ff5d5b ;">已收藏</view>
- <view v-if="!collectionStatus" style="font-size: 24upx;">收藏</view>
- </view>
- <view class="btn-group">
- <view class="btn" @tap="option = 'addcart',popupVisible=true">
- <uni-icons type="cart" color="white" style="margin-right: 10upx;"></uni-icons>加入购物车
- </view>
- <view class="line"></view>
- <view class="btn" @tap="option = 'buy',popupVisible=true">立即下单</view>
- </view>
- </view>
- <view class="popup" v-if="popupVisible" @touchmove.stop.prevent>
- <view class="popup-wrapper">
- <view class="close" @tap="popupVisible=false">
- <uni-icons type="closeempty" size="30"></uni-icons>
- </view>
- <view class="row row-1">
- <view class="spec-image">
- <image class="image" :src="product.specs[curSpecIndex].image|imagesFilter" mode=""></image>
- </view>
- <view class="">
- <view class="title">
- 已选择 {{product.specs[curSpecIndex].name}}
- </view>
- <view class="org-price">
- ¥{{product.specs[curSpecIndex].org_price|priceFilter}}
- </view>
- <view>
- <text class="sxj-icon">省心价</text>
- <text class="price">¥{{product.specs[curSpecIndex].price|priceFilter}}</text>
- </view>
- </view>
- </view>
- <view class="row row-2">
- <view class="label">
- 选择规格
- </view>
- </view>
- <view class="row row-3 spec-list">
- <template v-for="(spec,i) in product.specs">
- <view class="spec-item" :class="{'active':curSpecIndex===i}" @tap="curSpecIndex=i">{{spec.name}}
- </view>
- </template>
- </view>
- <view class="row row-4">
- <view class="label">
- 选择数量
- </view>
- <view class="counter">
- <view class="sub" @tap="num>1?num--:0">-</view>
- <input class="num" type="text" v-model="num" />
- <view class="plus" @tap="num++">+</view>
- </view>
- </view>
- <view class="row row-5 total-price">
- 合计:<text class="total-price-text">¥{{totalPrice}}</text>
- </view>
- <view class="row row-6 option">
- <button v-if="option === 'addcart'" class="btn" type="default" @tap="addCart">加入购物车</button>
- <button v-if="option === 'buy'" class="btn" type="default" @tap="buy">立即下单</button>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- popupVisible: false,
- option: "addcart",
- likeProducts: [],
- product: {
- id: 0
- },
- detailsIsOpen: false,
- curSpecIndex: 0,
- num: 1,
- collectionStatus: false
- }
- },
- computed: {
- totalPrice() {
- return (this.product.specs[this.curSpecIndex].price * this.num).toFixed(2);
- }
- },
- onLoad(option) {
- this.getLikeProductsData();
- this.product.id = option.id;
- this.getProductData();
- this.getCollectionStatus();
- },
- methods: {
- getLikeProductsData() {
- this.$http.get({
- url: "/product/rand",
- data: {
- limit: 10
- },
- success: (res) => {
- this.likeProducts = res.data.data
- }
- })
- },
- getProductData() {
- this.$http.get({
- url: "/product",
- data: {
- id: this.product.id
- },
- success: (res) => {
- this.product = res.data.data
- this.product.images = this.product.images.split(",")
- this.product.specs = JSON.parse(this.product.specs)
- }
- })
- },
- getCollectionStatus() {
- this.$http.get({
- url: "/collection/status",
- data: {
- product_id: this.product.id
- },
- success: (res) => {
- this.collectionStatus = res.data.data
- }
- })
- },
- addCollection() {
- this.$http.post({
- url: "/collection/add",
- data: {
- product_id: this.product.id
- },
- success: (res) => {
- this.collectionStatus = true;
- uni.showToast({
- title: res.data.msg,
- icon: "none",
- })
- }
- })
- },
- delCollection() {
- this.$http.post({
- url: "/collection/del",
- data: {
- product_id: this.product.id
- },
- success: (res) => {
- this.collectionStatus = false;
- uni.showToast({
- title: res.data.msg,
- icon: "none",
- })
- }
- })
- },
- addCart() {
- this.$store.dispatch("cart/add", {
- id: this.product.id,
- num: this.num,
- specIndex: this.curSpecIndex
- }).then(uni.showToast({
- title: "加入购物车成功",
- icon: "none"
- }))
- },
- buy() {
- let data = {
- id: this.product.id,
- spec_index: this.curSpecIndex,
- num: this.num
- }
- this.$http.post({
- url: '/order/create',
- data: {
- 'products[]': JSON.stringify(data)
- },
- success: (res) => {
- uni.navigateTo({
- url: "/pages/order/cashier?order_no=" + res.data.data
- })
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .carousel-wrapper {
- .carousel {
- margin: auto;
- overflow: hidden;
- transform: translateY(0);
- width: 750rpx;
- height: 750rpx;
- .image {
- width: 750rpx;
- height: 750rpx;
- }
- }
- }
- .title {
- font-size: 30upx;
- font-weight: bold;
- color: #333333;
- display: inline-block;
- white-space: normal;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- overflow: hidden;
- }
- .sxzg-icon {
- color: $primary-color;
- font-size: 20rpx;
- width: 120rpx;
- text-align: center;
- line-height: normal;
- border: 2rpx solid $primary-color;
- border-radius: 20rpx;
- display: inline-block;
- position: relative;
- top: -4rpx;
- margin-right: 10upx;
- // transform: scale(0.9);
- }
- .sxj-icon {
- background: $primary-color;
- color: white;
- font-size: 20upx;
- padding: 0 5upx;
- border-radius: 5upx;
- vertical-align: middle;
- }
- .row {
- margin: 20upx;
- display: flex;
- align-items: center;
- }
- .row-2 {
- justify-content: space-between;
- }
- .org-price,
- .stock {
- font-size: 28rpx;
- color: #999999;
- }
- .org-price {
- text-decoration: line-through;
- }
- .price {
- font-size: 28rpx;
- color: $primary-color;
- font-weight: bold;
- }
- .details {
- background: white;
- margin-top: 20upx;
- font-size: 30upx;
- .btn {
- padding: 20upx;
- display: flex;
- justify-content: space-between;
- }
- }
- .col-img-title {
- text-align: center;
- background: white;
- height: 80upx;
- line-height: 80upx;
- margin-bottom: 10upx;
- }
- .like .product-item {
- margin: 5rpx;
- &:first-child {
- margin-left: 10upx;
- }
- &:last-child {
- margin-right: 10upx;
- }
- }
- .content {
- max-height: 0;
- overflow: hidden;
- transition: max-height 0.5s;
- &.show {
- max-height: 10000upx;
- }
- }
- .arrow {
- transform: rotate(0deg);
- transition: all 0.5s;
- }
- .arrow.rotate {
- transform: rotate(90deg);
- // animation:myRotate 10s linear infinite;
- }
- .footer {
- display: flex;
- position: fixed;
- height: 100upx;
- background: white;
- bottom: 0;
- width: 100%;
- box-shadow: 0 0 10upx #999999;
- align-items: center;
- // color: white;
- padding: 0upx 20upx;
- box-sizing: border-box;
- justify-content: space-between;
- .btn-group {
- background: $primary-color;
- display: flex;
- color: white;
- width: 580upx;
- border-radius: 50upx;
- height: 80upx;
- align-items: center;
- .btn {
- flex: 1;
- text-align: center;
- font-size: 30upx;
- font-weight: bold;
- }
- .line {
- background: white;
- width: 1upx;
- height: 60upx;
- }
- }
- .collect {
- width: 100upx;
- display: flex;
- flex-direction: column;
- align-items: center;
- & :last-child {
- margin-top: -8upx;
- }
- }
- }
- .popup {
- position: fixed;
- top: 0;
- left: 0;
- bottom: 0;
- width: 750upx;
- background: rgba(0, 0, 0, 0.6);
- overflow: hidden;
- .popup-wrapper {
- .close {
- position: absolute;
- right: 5upx;
- top: 0;
- transform: scale(0.6);
- }
- background: white;
- position: absolute;
- bottom: 0;
- width: 750upx;
- min-height: 300upx;
- border-radius: 20upx 20upx 0 0;
- }
- .spec-image {
- margin-right: 20upx;
- .image {
- width: 180upx;
- height: 180upx;
- background: #EEEEEE;
- }
- }
- .row-1 {
- align-items: flex-start;
- .org-price {
- margin-top: 20upx;
- }
- }
- .label {
- font-size: 28upx;
- }
- .spec-list {
- display: flex;
- justify-content: flex-start;
- flex-wrap: wrap;
- margin-bottom: 0;
- .spec-item {
- text-align: center;
- background: #CCCCCC;
- color: white;
- padding: 5upx 30upx;
- margin: 0 20upx 20upx 20upx;
- font-size: 28upx;
- border-radius: 10upx;
- &.active {
- background: $primary-color;
- }
- }
- }
- .row-4 {
- justify-content: space-between;
- }
- .counter {
- margin-right: 40upx;
- display: flex;
- border: 2upx solid #CCCCCC;
- font-size: 28upx;
- align-items: center;
- border-radius: 10upx;
- .sub,
- .plus {
- // transform: scale(0.5);
- font-weight: 0;
- width: 42upx;
- text-align: center;
- &:active {
- background: rgba(0, 0, 0, .1);
- }
- }
- .num {
- text-align: center;
- font-size: 24upx;
- border-left: 2upx solid #EEEEEE;
- border-right: 2upx solid #EEEEEE;
- width: 50upx;
- }
- }
- .total-price {
- font-size: 30upx;
- justify-content: flex-end;
- margin-right: 60upx;
- .total-price-text {
- color: $primary-color;
- font-weight: bold;
- }
- }
- .option {
- .btn {
- width: 600upx;
- line-height: 80upx;
- font-size: 30upx;
- background: $primary-color;
- color: white;
- border-radius: 40upx;
- font-weight: bold;
- }
- }
- }
- </style>
|