第一次提交
This commit is contained in:
181
pages/sharp/goods/components/SkuPopup.vue
Executable file
181
pages/sharp/goods/components/SkuPopup.vue
Executable file
@@ -0,0 +1,181 @@
|
||||
<template>
|
||||
<goods-sku-popup :value="value" @input="onChangeValue" border-radius="20" :localdata="goodsInfo" :mode="skuMode" :maskCloseAble="true"
|
||||
:priceColor="appTheme.mainBg" :buyNowBackgroundColor="appTheme.mainBg" :addCartColor="appTheme.viceText" :addCartBackgroundColor="appTheme.viceBg"
|
||||
:activedStyle="{ color: appTheme.mainBg, borderColor: appTheme.mainBg, backgroundColor: activedBtnBackgroundColor }" @open="openSkuPopup"
|
||||
@close="closeSkuPopup" @buy-now="buyNow" buyNowText="立即购买" :maxBuyNum="goods.limit_num" :noStockText="noStockText" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { hex2rgba } from '@/utils/color'
|
||||
import * as TaskApi from '@/api/bargain/task'
|
||||
import GoodsSkuPopup from '@/components/goods-sku-popup'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
GoodsSkuPopup
|
||||
},
|
||||
model: {
|
||||
prop: 'value',
|
||||
event: 'input'
|
||||
},
|
||||
props: {
|
||||
// true 组件显示 false 组件隐藏
|
||||
value: {
|
||||
Type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 模式 1:都显示 2:只显示购物车 3:只显示立即购买
|
||||
skuMode: {
|
||||
type: Number,
|
||||
default: 1
|
||||
},
|
||||
// 砍价活动详情
|
||||
active: {
|
||||
type: Object,
|
||||
default: {}
|
||||
},
|
||||
// 该商品已抢完时的按钮文字
|
||||
noStockText: {
|
||||
Type: String,
|
||||
default: "该商品已抢完"
|
||||
},
|
||||
// 商品详情信息
|
||||
goods: {
|
||||
type: Object,
|
||||
default: {}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
goodsInfo: {}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
// 规格按钮选中时的背景色
|
||||
activedBtnBackgroundColor() {
|
||||
return hex2rgba(this.appTheme.mainBg, 0.1)
|
||||
}
|
||||
},
|
||||
created() {
|
||||
const app = this
|
||||
const { goods } = app
|
||||
app.goodsInfo = {
|
||||
_id: goods.goods_id,
|
||||
name: goods.goods_name,
|
||||
goods_thumb: goods.goods_image,
|
||||
sku_list: app.getSkuList(),
|
||||
spec_list: app.getSpecList()
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
// 监听组件显示隐藏
|
||||
onChangeValue(val) {
|
||||
this.$emit('input', val)
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取商品信息
|
||||
* 这里可以看到每次打开SKU都会去重新请求商品信息,为的是每次打开SKU组件可以实时看到剩余库存
|
||||
*/
|
||||
findGoodsInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(goodsInfo)
|
||||
})
|
||||
},
|
||||
|
||||
// 整理商品SKU列表
|
||||
getSkuList() {
|
||||
const app = this
|
||||
const { goods: { goods_name, goods_image, skuList } } = app
|
||||
const skuData = []
|
||||
skuList.forEach(item => {
|
||||
skuData.push({
|
||||
_id: item.id,
|
||||
goods_sku_id: item.goods_sku_id,
|
||||
goods_id: item.goods_id,
|
||||
goods_name: goods_name,
|
||||
image: item.image_url ? item.image_url : goods_image,
|
||||
price: item.seckill_price * 100,
|
||||
stock: item.seckill_stock,
|
||||
spec_value_ids: item.spec_value_ids,
|
||||
sku_name_arr: app.getSkuNameArr(item.spec_value_ids)
|
||||
})
|
||||
})
|
||||
return skuData
|
||||
},
|
||||
|
||||
// 获取sku记录的规格值列表
|
||||
getSkuNameArr(specValueIds) {
|
||||
const app = this
|
||||
const defaultData = ['默认']
|
||||
const skuNameArr = []
|
||||
if (specValueIds) {
|
||||
specValueIds.forEach((valueId, groupIndex) => {
|
||||
const specValueName = app.getSpecValueName(valueId, groupIndex)
|
||||
skuNameArr.push(specValueName)
|
||||
})
|
||||
}
|
||||
return skuNameArr.length ? skuNameArr : defaultData
|
||||
},
|
||||
|
||||
// 获取指定的规格值名称
|
||||
getSpecValueName(valueId, groupIndex) {
|
||||
const app = this
|
||||
const { goods: { specList } } = app
|
||||
const res = specList[groupIndex].valueList.find(specValue => {
|
||||
return specValue.spec_value_id == valueId
|
||||
})
|
||||
return res.spec_value
|
||||
},
|
||||
|
||||
// 整理规格数据
|
||||
getSpecList() {
|
||||
const { goods: { specList } } = this
|
||||
const defaultData = [{ name: '默认', list: [{ name: '默认' }] }]
|
||||
const specData = []
|
||||
specList.forEach(group => {
|
||||
const children = []
|
||||
group.valueList.forEach(specValue => {
|
||||
children.push({ name: specValue.spec_value })
|
||||
})
|
||||
specData.push({
|
||||
name: group.spec_name,
|
||||
list: children
|
||||
})
|
||||
})
|
||||
return specData.length ? specData : defaultData
|
||||
},
|
||||
|
||||
// sku组件 开始-----------------------------------------------------------
|
||||
openSkuPopup() {
|
||||
// console.log("监听 - 打开sku组件")
|
||||
},
|
||||
|
||||
closeSkuPopup() {
|
||||
// console.log("监听 - 关闭sku组件")
|
||||
},
|
||||
|
||||
// 立即购买
|
||||
buyNow(selectShop) {
|
||||
const app = this
|
||||
// 跳转到订单结算页
|
||||
app.$navTo('pages/checkout/index', {
|
||||
mode: 'sharp',
|
||||
activeTimeId: app.active.active_time_id,
|
||||
sharpGoodsId: app.goods.sharp_goods_id,
|
||||
goodsSkuId: selectShop.goods_sku_id,
|
||||
goodsNum: selectShop.buy_num
|
||||
})
|
||||
// 隐藏当前弹窗
|
||||
app.onChangeValue(false)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
||||
339
pages/sharp/goods/index.vue
Executable file
339
pages/sharp/goods/index.vue
Executable file
@@ -0,0 +1,339 @@
|
||||
<template>
|
||||
<view v-show="!isLoading" class="container" :style="appThemeStyle">
|
||||
<!-- 商品图片轮播 -->
|
||||
<SlideImage v-if="!isLoading" :video="goods.video" :videoCover="goods.videoCover" :images="goods.goods_images" />
|
||||
|
||||
<!-- 商品信息 -->
|
||||
<view v-if="!isLoading" class="goods-info m-top20">
|
||||
<!-- 价格、销量 -->
|
||||
<view class="info-item info-item__top dis-flex flex-x-between flex-y-end">
|
||||
<view class="block-left dis-flex flex-y-center">
|
||||
<view class="active-tag">
|
||||
<text>限时秒杀</text>
|
||||
</view>
|
||||
<!-- 秒杀价 -->
|
||||
<text class="floor-price__samll">¥</text>
|
||||
<text class="floor-price">{{ goods.seckill_price }}</text>
|
||||
<!-- 商品原价 -->
|
||||
<text class="original-price">¥{{ goods.original_price }}</text>
|
||||
</view>
|
||||
<view class="block-right dis-flex">
|
||||
<!-- 销量 -->
|
||||
<view class="goods-sales">
|
||||
<text>已抢{{ active.sales_actual }}件</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 标题、分享 -->
|
||||
<view class="info-item info-item__name dis-flex flex-y-center">
|
||||
<view class="goods-name flex-box">
|
||||
<text class="twoline-hide">{{ goods.goods_name }}</text>
|
||||
</view>
|
||||
<view class="goods-share__line"></view>
|
||||
<view class="goods-share">
|
||||
<button class="share-btn dis-flex flex-dir-column" @click="onShowShareSheet()">
|
||||
<text class="share__icon iconfont icon-fenxiang"></text>
|
||||
<text class="f-24">分享</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 商品卖点 -->
|
||||
<view v-if="goods.selling_point" class="info-item info-item_selling-point">
|
||||
<text>{{ goods.selling_point }}</text>
|
||||
</view>
|
||||
<!-- 活动倒计时 -->
|
||||
<view v-if="active.active_status != GoodsStatusEnum.STATE_END.value" class="info-item info-item_status info-item_countdown dis-flex flex-y-center">
|
||||
<text class="countdown-icon iconfont icon-naozhong"></text>
|
||||
<text>距离秒杀{{ active.active_status == GoodsStatusEnum.STATE_SOON.value ? '开始' : '结束' }}</text>
|
||||
<text class="m-r-10">还剩</text>
|
||||
<count-down :date="active.count_down_time" separator="zh" theme="text" />
|
||||
</view>
|
||||
<!-- 活动已结束 -->
|
||||
<view v-else class="info-item info-item_status info-item_end">
|
||||
<text class="countdown-icon iconfont icon-naozhong"></text>
|
||||
<text>秒杀活动已结束,下次记得早点来哦~</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 选择商品规格 -->
|
||||
<view v-if="goods.spec_type == 20" class="goods-choice m-top20 b-f" @click="onShowSkuPopup()">
|
||||
<view class="spec-list">
|
||||
<view class="flex-box">
|
||||
<text class="col-8">选择:</text>
|
||||
<text class="spec-name" v-for="(item, index) in goods.specList" :key="index">{{ item.spec_name }}</text>
|
||||
</view>
|
||||
<view class="f-26 col-9 t-r">
|
||||
<text class="iconfont icon-arrow-right"></text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品服务 -->
|
||||
<!-- <Service v-if="!isLoading" :goods-id="goods.goods_id" /> -->
|
||||
|
||||
<!-- 商品SKU弹窗 -->
|
||||
<SkuPopup v-if="!isLoading" v-model="showSkuPopup" :skuMode="skuMode" :active="active" :goods="goods" :noStockText="noStockText" />
|
||||
|
||||
<!-- 商品评价 -->
|
||||
<Comment v-if="!isLoading" :goods-id="goods.goods_id" :limit="2" />
|
||||
|
||||
<!-- 商品描述 -->
|
||||
<view v-if="!isLoading" class="goods-content m-top20">
|
||||
<view class="item-title b-f">
|
||||
<text>商品描述</text>
|
||||
</view>
|
||||
<block v-if="goods.content != ''">
|
||||
<view class="goods-content__detail b-f">
|
||||
<mp-html :content="goods.content" />
|
||||
</view>
|
||||
</block>
|
||||
<empty v-else tips="亲,暂无商品描述" />
|
||||
</view>
|
||||
|
||||
<!-- 底部选项卡 -->
|
||||
<view class="footer-fixed">
|
||||
<view class="footer-container">
|
||||
<!-- 导航图标 -->
|
||||
<view class="foo-item-fast">
|
||||
<!-- 首页 -->
|
||||
<view class="fast-item fast-item--home" @click="onTargetHome">
|
||||
<view class="fast-icon">
|
||||
<text class="iconfont icon-shouye"></text>
|
||||
</view>
|
||||
<view class="fast-text">
|
||||
<text>首页</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 客服 -->
|
||||
<customer-btn v-if="isShowCustomerBtn">
|
||||
<view class="fast-item">
|
||||
<view class="fast-icon">
|
||||
<text class="iconfont icon-kefu1"></text>
|
||||
</view>
|
||||
<view class="fast-text">
|
||||
<text>客服</text>
|
||||
</view>
|
||||
</view>
|
||||
</customer-btn>
|
||||
<!-- 购物车 (客服按钮不显示时) -->
|
||||
<view v-if="!isShowCustomerBtn" class="fast-item fast-item--cart" @click="onTargetCart">
|
||||
<view v-if="cartTotal > 0" class="fast-badge fast-badge--fixed">{{ cartTotal > 99 ? '99+' : cartTotal }}
|
||||
</view>
|
||||
<view class="fast-icon">
|
||||
<text class="iconfont icon-gouwuche"></text>
|
||||
</view>
|
||||
<view class="fast-text">
|
||||
<text>购物车</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="foo-item-btn">
|
||||
<view class="btn-wrapper">
|
||||
<view v-if="active.active_status == GoodsStatusEnum.STATE_BEGIN.value" class="btn-item btn--main" @click="onShowSkuPopup()">
|
||||
<text>立即购买</text>
|
||||
</view>
|
||||
<button v-else class="btn-item btn--gray">
|
||||
<text>{{ active.active_status == GoodsStatusEnum.STATE_SOON.value ? '活动未开始' : '活动已结束' }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分享菜单 -->
|
||||
<share-sheet v-model="showShareSheet" :shareTitle="goods.goods_name" :shareImageUrl="goods.goods_image" :posterApiCall="posterApiCall" :posterApiParam="{ activeTimeId, sharpGoodsId }" />
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getSceneData } from '@/core/app'
|
||||
import ShareSheet from '@/components/share-sheet'
|
||||
import CustomerBtn from '@/components/customer-btn'
|
||||
import SkuPopup from './components/SkuPopup'
|
||||
import SlideImage from '../../goods/components/SlideImage'
|
||||
import Comment from '../../goods/components/Comment'
|
||||
// import Service from '../../goods/components/Service'
|
||||
import CountDown from '@/components/countdown'
|
||||
import * as SharpGoodsApi from '@/api/sharp/goods'
|
||||
import * as CartApi from '@/api/cart'
|
||||
import SettingModel from '@/common/model/Setting'
|
||||
import { ActiveStatusEnum, GoodsStatusEnum } from '@/common/enum/sharp'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
ShareSheet,
|
||||
CustomerBtn,
|
||||
// Shortcut,
|
||||
SlideImage,
|
||||
SkuPopup,
|
||||
Comment,
|
||||
// Service,
|
||||
CountDown
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 正在加载
|
||||
isLoading: true,
|
||||
// 枚举类
|
||||
ActiveStatusEnum,
|
||||
GoodsStatusEnum,
|
||||
// 显示/隐藏SKU弹窗
|
||||
showSkuPopup: false,
|
||||
// 模式 1:都显示 2:只显示购物车 3:只显示立即购买
|
||||
skuMode: 3,
|
||||
// 活动未开始时的文字
|
||||
noStockText: '该商品已抢完',
|
||||
// 显示/隐藏分享菜单
|
||||
showShareSheet: false,
|
||||
// 获取商品海报图api方法
|
||||
posterApiCall: SharpGoodsApi.poster,
|
||||
// 当前秒杀场次ID
|
||||
activeTimeId: null,
|
||||
// 当前秒杀商品ID
|
||||
sharpGoodsId: null,
|
||||
// 秒杀活动详情
|
||||
active: {},
|
||||
// 秒杀商品详情
|
||||
goods: {},
|
||||
// 购物车总数量
|
||||
cartTotal: 0,
|
||||
// 是否显示在线客服按钮
|
||||
isShowCustomerBtn: false
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
async onLoad(options) {
|
||||
// 记录query参数
|
||||
this.onRecordQuery(options)
|
||||
// 加载页面数据
|
||||
this.onRefreshPage()
|
||||
// 是否显示在线客服按钮
|
||||
this.isShowCustomerBtn = await SettingModel.isShowCustomerBtn()
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
// 记录query参数
|
||||
onRecordQuery(query) {
|
||||
const scene = getSceneData(query)
|
||||
this.activeTimeId = query.activeTimeId ? parseInt(query.activeTimeId) : parseInt(scene.aid)
|
||||
this.sharpGoodsId = query.sharpGoodsId ? parseInt(query.sharpGoodsId) : parseInt(scene.gid)
|
||||
},
|
||||
|
||||
// 刷新页面数据
|
||||
onRefreshPage() {
|
||||
const app = this
|
||||
app.isLoading = true
|
||||
Promise.all([app.getActiveDetail(), app.getCartTotal()])
|
||||
.then(() => {
|
||||
const activeStatus = app.active.active_status
|
||||
if (activeStatus != GoodsStatusEnum.STATE_BEGIN.value) {
|
||||
app.skuMode = 4
|
||||
app.noStockText = activeStatus == GoodsStatusEnum.STATE_SOON.value ? '活动未开始' : '活动已结束'
|
||||
}
|
||||
})
|
||||
.finally(() => app.isLoading = false)
|
||||
},
|
||||
|
||||
// 获取秒杀活动详情
|
||||
getActiveDetail() {
|
||||
const app = this
|
||||
return new Promise((resolve, reject) => {
|
||||
SharpGoodsApi.detail(app.activeTimeId, app.sharpGoodsId)
|
||||
.then(result => {
|
||||
app.active = result.data.active
|
||||
app.goods = result.data.goods
|
||||
resolve(result)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
},
|
||||
|
||||
// 获取购物车总数量
|
||||
getCartTotal() {
|
||||
const app = this
|
||||
return new Promise((resolve, reject) => {
|
||||
CartApi.total()
|
||||
.then(result => {
|
||||
app.cartTotal = result.data.cartTotal
|
||||
resolve(result)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 显示/隐藏SKU弹窗
|
||||
*/
|
||||
onShowSkuPopup() {
|
||||
this.showSkuPopup = !this.showSkuPopup
|
||||
|
||||
},
|
||||
|
||||
// 显示隐藏分享菜单
|
||||
onShowShareSheet() {
|
||||
this.showShareSheet = !this.showShareSheet
|
||||
},
|
||||
|
||||
// 跳转到首页
|
||||
onTargetHome(e) {
|
||||
this.$navTo('pages/index/index')
|
||||
},
|
||||
|
||||
// 跳转到购物车页
|
||||
onTargetCart() {
|
||||
this.$navTo('pages/cart/index')
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 分享当前页面
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
// 构建页面参数
|
||||
const app = this
|
||||
const params = app.$getShareUrlParams({
|
||||
activeTimeId: app.activeTimeId,
|
||||
sharpGoodsId: app.sharpGoodsId
|
||||
})
|
||||
return {
|
||||
title: app.goods.goods_name,
|
||||
path: `/pages/sharp/goods/index?${params}`
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 分享到朋友圈
|
||||
* 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
|
||||
* https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
|
||||
*/
|
||||
onShareTimeline() {
|
||||
// 构建页面参数
|
||||
const app = this
|
||||
const params = app.$getShareUrlParams({
|
||||
activeTimeId: app.activeTimeId,
|
||||
sharpGoodsId: app.sharpGoodsId
|
||||
})
|
||||
return {
|
||||
title: app.goods.goods_name,
|
||||
path: `/pages/sharp/goods/index?${params}`
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
page {
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
<style lang="scss" scoped>
|
||||
@import "./style.scss";
|
||||
</style>
|
||||
306
pages/sharp/goods/style.scss
Executable file
306
pages/sharp/goods/style.scss
Executable file
@@ -0,0 +1,306 @@
|
||||
.container {
|
||||
// 设置ios刘海屏底部横线安全区域
|
||||
// 110 - 18 + 4
|
||||
padding-bottom: calc(constant(safe-area-inset-bottom) + 106rpx + 6rpx);
|
||||
padding-bottom: calc(env(safe-area-inset-bottom) + 106rpx + 6rpx);
|
||||
}
|
||||
|
||||
/* 商品信息 */
|
||||
|
||||
.goods-info {
|
||||
background: #fff;
|
||||
padding: 25rpx 30rpx;
|
||||
}
|
||||
|
||||
.info-item__top {
|
||||
min-height: 40rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.info-item__top .active-tag {
|
||||
color: #fff;
|
||||
background: $main-bg;
|
||||
padding: 4rpx 10rpx;
|
||||
border-radius: 15rpx;
|
||||
font-size: 26rpx;
|
||||
text-align: center;
|
||||
margin-right: 15rpx;
|
||||
}
|
||||
|
||||
.floor-price__samll {
|
||||
font-size: 26rpx;
|
||||
line-height: 1;
|
||||
color: $main-bg;
|
||||
margin-bottom: -10rpx;
|
||||
}
|
||||
|
||||
/* 商品价 */
|
||||
.floor-price {
|
||||
color: $main-bg;
|
||||
margin-right: 15rpx;
|
||||
font-size: 42rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.original-price {
|
||||
font-size: 26rpx;
|
||||
line-height: 1;
|
||||
text-decoration: line-through;
|
||||
color: #959595;
|
||||
margin-bottom: -6rpx;
|
||||
}
|
||||
|
||||
.goods-sales {
|
||||
font-size: 24rpx;
|
||||
color: #959595;
|
||||
}
|
||||
|
||||
.info-item__name .goods-name {
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
/* 商品分享 */
|
||||
|
||||
.goods-share__line {
|
||||
border-left: 1rpx solid #f4f4f4;
|
||||
height: 60rpx;
|
||||
margin: 0 30rpx;
|
||||
}
|
||||
|
||||
.goods-share .share-btn {
|
||||
line-height: normal;
|
||||
padding: 0;
|
||||
background: none;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
font-size: 8pt;
|
||||
border: none;
|
||||
color: #191919;
|
||||
}
|
||||
|
||||
.goods-share .share-btn::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.goods-share .share__icon {
|
||||
font-size: 40rpx;
|
||||
margin-bottom: 5rpx;
|
||||
}
|
||||
|
||||
/* 商品卖点 */
|
||||
|
||||
.info-item_selling-point {
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: #808080;
|
||||
}
|
||||
|
||||
// 选择商品规格
|
||||
.goods-choice {
|
||||
padding: 26rpx 30rpx;
|
||||
font-size: 28rpx;
|
||||
|
||||
.spec-list {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.spec-name {
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 商品详情 */
|
||||
|
||||
.goods-content .item-title {
|
||||
padding: 26rpx 30rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
/* 底部操作栏 */
|
||||
|
||||
.footer-fixed {
|
||||
position: fixed;
|
||||
bottom: var(--window-bottom);
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
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);
|
||||
}
|
||||
|
||||
.footer-container {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
height: 106rpx;
|
||||
}
|
||||
|
||||
// 快捷菜单
|
||||
.foo-item-fast {
|
||||
box-sizing: border-box;
|
||||
width: 256rpx;
|
||||
line-height: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.fast-item {
|
||||
position: relative;
|
||||
padding: 4rpx 10rpx;
|
||||
line-height: 1;
|
||||
// text-align: center;
|
||||
|
||||
.fast-icon {
|
||||
margin-bottom: 6rpx;
|
||||
}
|
||||
|
||||
&--home {
|
||||
margin-right: 30rpx;
|
||||
}
|
||||
|
||||
&--cart {
|
||||
.fast-icon { padding-left: 3px; }
|
||||
}
|
||||
|
||||
// 角标
|
||||
.fast-badge {
|
||||
display: inline-block;
|
||||
box-sizing: border-box;
|
||||
min-width: 16px;
|
||||
padding: 0 3px;
|
||||
color: #fff;
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
font-family: -apple-system-font, Helvetica Neue, Arial, sans-serif;
|
||||
line-height: 1.2;
|
||||
text-align: center;
|
||||
background-color: #ee0a24;
|
||||
border: 1px solid #fff;
|
||||
border-radius: 999px;
|
||||
}
|
||||
.fast-badge--fixed {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
transform-origin: 100%
|
||||
}
|
||||
|
||||
.fast-icon {
|
||||
font-size: 46rpx;
|
||||
}
|
||||
|
||||
.fast-text {
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 操作按钮
|
||||
.foo-item-btn {
|
||||
flex: 1;
|
||||
|
||||
.btn-wrapper {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.btn-item {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
// 立即砍价
|
||||
.btn-item {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
font-size: 30rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
&.btn--main {
|
||||
background: linear-gradient(to right, $main-bg, $main-bg2);
|
||||
color: $main-text;
|
||||
}
|
||||
&.btn--gray {
|
||||
background-color: #ccc;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 活动状态
|
||||
.info-item_status {
|
||||
margin-top: 20rpx;
|
||||
padding: 15rpx 20rpx;
|
||||
font-size: 24rpx;
|
||||
border-radius: 6rpx;
|
||||
}
|
||||
|
||||
.info-item_status .countdown-icon {
|
||||
font-size: 28rpx;
|
||||
margin-right: 15rpx;
|
||||
}
|
||||
|
||||
// 活动倒计时
|
||||
.info-item_countdown {
|
||||
background: #f0f9ff;
|
||||
color: #8f8f8f;
|
||||
}
|
||||
|
||||
.info-item_countdown .countdown-icon {
|
||||
color: #1397d8;
|
||||
}
|
||||
|
||||
// 活动已结束
|
||||
.info-item_end {
|
||||
background: #ccc;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
// 砍价玩法
|
||||
.bargain-rules {
|
||||
padding: 20rpx 0;
|
||||
font-size: 29rpx;
|
||||
|
||||
.item-title {
|
||||
padding: 0 30rpx;
|
||||
}
|
||||
|
||||
.rule-simple {
|
||||
margin-top: 35rpx;
|
||||
color: #737373;
|
||||
}
|
||||
|
||||
.i-number {
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
border-radius: 50%;
|
||||
margin-bottom: 15rpx;
|
||||
border: 1rpx dashed #c0c0c0;
|
||||
}
|
||||
}
|
||||
|
||||
// 砍价规则(弹窗)
|
||||
.pops-content {
|
||||
padding: 30rpx 48rpx;
|
||||
font-size: 28rpx;
|
||||
line-height: 44rpx;
|
||||
text-align: left;
|
||||
color: #606266;
|
||||
min-height: 320rpx;
|
||||
max-height: 640rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
460
pages/sharp/index.vue
Executable file
460
pages/sharp/index.vue
Executable file
@@ -0,0 +1,460 @@
|
||||
<template>
|
||||
<view class="container" :style="appThemeStyle">
|
||||
<mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ native: true, auto: false }" @down="downCallback" :up="upOption"
|
||||
@up="upCallback">
|
||||
<!-- 秒杀会场场次tab -->
|
||||
<view class="sharp-tabs">
|
||||
<scroll-view :scroll-x="true" :scroll-left="scrollLeft" @scroll="scroll">
|
||||
<view class="sharp-tabs--container dis-flex">
|
||||
<view v-for="(item, index) in tabbar" :key="index" class="tabs-item dis-flex flex-dir-column flex-x-center flex-y-center"
|
||||
:class="{ active: curTabIndex == index }" @click="handleTab(index)">
|
||||
<block v-if="item.status == ActiveStatusEnum.STATE_NOTICE.value">
|
||||
<view class="item-title">{{ item.status_text }}</view>
|
||||
</block>
|
||||
<block v-else>
|
||||
<view class="item-time">{{ item.active_time }}</view>
|
||||
<view class="item-status">{{ item.status_text }}</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<!-- 秒杀活动 -->
|
||||
<view v-if="tabbar.length" class="sharp-active dis-flex flex-dir-column flex-y-center">
|
||||
<!-- 活动状态 -->
|
||||
<view class="active-status">
|
||||
<text class="active-status--icon iconfont icon-artboard"></text>
|
||||
<text v-if="tabbar[curTabIndex].status != ActiveStatusEnum.STATE_NOTICE.value"
|
||||
class="active-status--time">{{ tabbar[curTabIndex].active_time }}</text>
|
||||
<text class="active-status--text">{{ tabbar[curTabIndex].status_text2 }}</text>
|
||||
</view>
|
||||
<!-- 倒计时 -->
|
||||
<view class="active--count-down dis-flex flex-y-center">
|
||||
<text class="m-r-10">{{ tabbar[curTabIndex].status == ActiveStatusEnum.STATE_BEGIN.value ? '距结束' : '距开始' }}</text>
|
||||
<count-down :date="tabbar[curTabIndex].count_down_time" separator="colon" theme="custom" />
|
||||
</view>
|
||||
</view>
|
||||
<!-- 秒杀商品列表 -->
|
||||
<view class="goods-hall">
|
||||
<view class="goods-item" v-for="(item, index) in goodsList.data" :key="index" @click="handleTargetGoods(item.sharp_goods_id)">
|
||||
<view class="goods-item--container dis-flex">
|
||||
<!-- 商品图片 -->
|
||||
<view class="goods-image">
|
||||
<image :src="item.goods_image"></image>
|
||||
</view>
|
||||
<view class="goods-info">
|
||||
<!-- 商品名称 -->
|
||||
<view class="goods-name">
|
||||
<text class="twoline-hide">{{ item.goods_name }}</text>
|
||||
</view>
|
||||
<!-- 秒杀进度条 -->
|
||||
<view class="sharp-progress dis-flex flex-y-center">
|
||||
<view class="yoo-progress" :style="{ backgroundColor: progressBackgroundColor }">
|
||||
<view class="yoo-progress--portion" :style="{ width: `${item.progress}%` }">
|
||||
</view>
|
||||
<text class="yoo-progress--text">{{ item.progress }}%</text>
|
||||
</view>
|
||||
<view class="sharp-sales">已抢{{ item.sales_actual }}件</view>
|
||||
</view>
|
||||
<!-- 秒杀活动价格 -->
|
||||
<view class="sharp-price dis-flex flex-y-end">
|
||||
<view class="seckill-price">
|
||||
<text class="f-24">¥</text>
|
||||
<text class="money">{{ item.seckill_price_min }}</text>
|
||||
</view>
|
||||
<view class="original-price">
|
||||
<text class="f-24">¥</text>
|
||||
<text class="money">{{ item.original_price }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="opt-touch">
|
||||
<view class="touch-btn">
|
||||
<text>{{ tabbar[curTabIndex].status == ActiveStatusEnum.STATE_BEGIN.value ? '马上抢' : '查看商品' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</mescroll-body>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CountDown from '@/components/countdown'
|
||||
import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
|
||||
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
|
||||
import { hex2rgba } from '@/utils/color'
|
||||
import { getEmptyPaginateObj, getMoreListData } from '@/core/app'
|
||||
import { ActiveStatusEnum } from '@/common/enum/sharp'
|
||||
import * as HomeApi from '@/api/sharp/home'
|
||||
import * as GoodsApi from '@/api/sharp/goods'
|
||||
|
||||
const pageSize = 15
|
||||
|
||||
export default {
|
||||
components: {
|
||||
MescrollBody,
|
||||
CountDown
|
||||
},
|
||||
mixins: [MescrollMixin],
|
||||
data() {
|
||||
return {
|
||||
// 是否正在加载中
|
||||
isLoading: true,
|
||||
// 当前tab索引
|
||||
curTabIndex: 0,
|
||||
// tab组件的左侧距离
|
||||
scrollLeft: 0,
|
||||
// 上拉加载配置
|
||||
upOption: {
|
||||
// 首次自动执行
|
||||
auto: false,
|
||||
// 每页数据的数量; 默认10
|
||||
page: { size: pageSize },
|
||||
// 数量要大于3条才显示无更多数据
|
||||
noMoreSize: 3,
|
||||
},
|
||||
// 枚举类
|
||||
ActiveStatusEnum,
|
||||
// 秒杀活动场次
|
||||
tabbar: [],
|
||||
// 秒杀商品列表
|
||||
goodsList: [],
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
// 进度条背景颜色
|
||||
progressBackgroundColor() {
|
||||
return hex2rgba(this.appTheme.mainBg, 0.2)
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
this.onRefreshPage()
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
// 加载页面数据
|
||||
onRefreshPage() {
|
||||
const app = this
|
||||
return new Promise((resolve, reject) => {
|
||||
HomeApi.data()
|
||||
.then(result => {
|
||||
app.tabbar = result.data.tabbar
|
||||
app.goodsList = result.data.goodsList
|
||||
app.curTabIndex = 0
|
||||
app.scrollLeft = 0
|
||||
if (!app.goodsList.data.length) {
|
||||
app.mescroll.showEmpty()
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取商品列表
|
||||
* @param {Number} pageNo 页码
|
||||
*/
|
||||
getListData(pageNo = 1) {
|
||||
const app = this
|
||||
const activeTimeId = app.getCurTabbarId()
|
||||
return new Promise((resolve, reject) => {
|
||||
GoodsApi.list(activeTimeId, { page: pageNo }, { load: false })
|
||||
.then(result => {
|
||||
// 合并新数据
|
||||
const newList = result.data.list
|
||||
app.goodsList.data = getMoreListData(newList, app.goodsList, pageNo)
|
||||
resolve(newList)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
},
|
||||
|
||||
// 下拉刷新的回调
|
||||
downCallback() {
|
||||
this.onRefreshPage()
|
||||
.finally(() => this.mescroll.endSuccess())
|
||||
},
|
||||
|
||||
/**
|
||||
* 上拉加载的回调
|
||||
* 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
|
||||
* @param {Object} page
|
||||
*/
|
||||
upCallback(page) {
|
||||
const app = this
|
||||
// 设置列表数据
|
||||
app.getListData(page.num)
|
||||
.then(list => {
|
||||
const curPageLen = list.data.length
|
||||
const totalSize = list.data.total
|
||||
app.mescroll.endBySize(curPageLen, totalSize)
|
||||
})
|
||||
.catch(() => app.mescroll.endErr())
|
||||
},
|
||||
|
||||
// 监听tab组件滚动
|
||||
scroll({ detail }) {
|
||||
this.scrollLeft = detail.scrollLeft
|
||||
},
|
||||
|
||||
// 点击切换标签(会场场次)
|
||||
handleTab(index) {
|
||||
const app = this
|
||||
app.curTabIndex = index
|
||||
// 刷新列表数据
|
||||
app.goodsList = getEmptyPaginateObj()
|
||||
app.mescroll.resetUpScroll()
|
||||
},
|
||||
|
||||
// 获取当前选择的会场
|
||||
getCurTabbar() {
|
||||
return this.tabbar[this.curTabIndex]
|
||||
},
|
||||
|
||||
// 获取当前会场场次ID
|
||||
getCurTabbarId() {
|
||||
const curTabbar = this.getCurTabbar()
|
||||
return curTabbar ? curTabbar.active_time_id : 0
|
||||
},
|
||||
|
||||
// 跳转到秒杀商品详情
|
||||
handleTargetGoods(sharpGoodsId) {
|
||||
this.$navTo('pages/sharp/goods/index', {
|
||||
activeTimeId: this.getCurTabbarId(),
|
||||
sharpGoodsId
|
||||
})
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 分享当前页面
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
// 构建页面参数
|
||||
const params = this.$getShareUrlParams()
|
||||
return {
|
||||
title: '整点秒杀会场',
|
||||
path: `/pages/sharp/index?${params}`
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 分享到朋友圈
|
||||
* 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
|
||||
* https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
|
||||
*/
|
||||
onShareTimeline() {
|
||||
// 构建页面参数
|
||||
const params = this.$getShareUrlParams()
|
||||
return {
|
||||
title: '整点秒杀会场',
|
||||
path: `/pages/sharp/index?${params}`
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
page {
|
||||
background: #efeff4;
|
||||
}
|
||||
</style>
|
||||
<style lang="scss" scoped>
|
||||
.container {
|
||||
background: #efeff4;
|
||||
}
|
||||
|
||||
// 秒杀会场 (选项卡)
|
||||
.sharp-tabs {
|
||||
background: #fff;
|
||||
|
||||
.sharp-tabs--container {
|
||||
background: #30353c;
|
||||
}
|
||||
|
||||
// .sharp-tabs--empty {
|
||||
// padding-bottom: 30rpx;
|
||||
// }
|
||||
|
||||
.tabs-item {
|
||||
position: relative;
|
||||
min-width: 170rpx;
|
||||
height: 110rpx;
|
||||
background: #30353c;
|
||||
color: #fff;
|
||||
padding: 15rpx 45rpx;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
white-space: nowrap;
|
||||
|
||||
.item-time {
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.item-status {
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.item-title {
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: $main-bg;
|
||||
|
||||
&::after {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
z-index: 999;
|
||||
bottom: -15rpx;
|
||||
left: 50%;
|
||||
margin-left: -12rpx;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 20rpx solid $main-bg;
|
||||
border-left-color: transparent;
|
||||
border-right-color: transparent;
|
||||
border-bottom-color: transparent;
|
||||
border-bottom-width: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 活动状态
|
||||
.sharp-active {
|
||||
background: #fff;
|
||||
padding: 26rpx 0;
|
||||
|
||||
.active-status {
|
||||
font-size: 32rpx;
|
||||
color: $main-bg;
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
.active-status--icon {
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
|
||||
.active-status--time {
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 倒计时
|
||||
.active--count-down {
|
||||
font-size: 26rpx;
|
||||
height: 40rpx;
|
||||
}
|
||||
|
||||
// 商品列表
|
||||
.goods-hall {
|
||||
padding-top: 20rpx;
|
||||
|
||||
.goods-item {
|
||||
background: #fff;
|
||||
padding: 30rpx 16rpx;
|
||||
border-bottom: 1rpx solid #e7e7e7;
|
||||
|
||||
.goods-image {
|
||||
image {
|
||||
display: block;
|
||||
width: 220rpx;
|
||||
height: 220rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.goods-info {
|
||||
width: 498rpx;
|
||||
padding-top: 8rpx;
|
||||
margin-left: 15rpx;
|
||||
position: relative;
|
||||
|
||||
.goods-name {
|
||||
font-size: 28rpx;
|
||||
min-height: 72rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 秒杀进度条
|
||||
.yoo-progress {
|
||||
position: relative;
|
||||
width: 70%;
|
||||
height: 28rpx;
|
||||
border-radius: 12rpx;
|
||||
background: #f8b6b6;
|
||||
|
||||
&--portion {
|
||||
width: 0%;
|
||||
height: 100%;
|
||||
border-radius: 12rpx;
|
||||
background: linear-gradient(to right, $main-bg2, $main-bg);
|
||||
}
|
||||
|
||||
&--text {
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.6;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 秒杀商品销量
|
||||
.sharp-sales {
|
||||
margin-left: 30rpx;
|
||||
font-size: 24rpx;
|
||||
color: $main-bg;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
// 秒杀价格
|
||||
.sharp-price {
|
||||
margin-top: 40rpx;
|
||||
line-height: 1;
|
||||
|
||||
.seckill-price {
|
||||
font-size: 32rpx;
|
||||
color: $main-bg;
|
||||
margin-bottom: -2rpx;
|
||||
}
|
||||
|
||||
.original-price {
|
||||
margin-left: 5rpx;
|
||||
font-size: 24rpx;
|
||||
color: #818181;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
}
|
||||
|
||||
// 立即参加按钮
|
||||
.opt-touch {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 10rpx;
|
||||
|
||||
.touch-btn {
|
||||
font-size: 26rpx;
|
||||
background: linear-gradient(to right, $main-bg, $main-bg2);
|
||||
color: $main-text;
|
||||
border-radius: 30rpx;
|
||||
padding: 10rpx 30rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user