文章目录
- 前言
- 一、商品列表
前言
商品详情页是展示商品详细信息的一个页面,承载在网站的大部分流量和订单的入口。京东商城目前有通用版、全球购、闪购、易车、惠买车、服装、拼购、今日抄底等许多套模板。各套模板的元数据是一样的,只是展示方式不一样。目前商品详情页个性化需求非常多,数据来源也是非常多的,而且许多基础服务做不了的都放我们这,因此我们需要一种架构能快速响应和优雅的解决这些需求问题。因此我们重新设计了商品详情页的架构,主要包括三部分:商品详情页系统、商品详情页统一服务系统和商品详情页动态服务系统;商品详情页系统负责静的部分,而统一服务负责动的部分,而动态服务负责给内网其他系统提供一些数据服务。
一、商品列表
<template><view class="goods-item"><!-- 左侧的盒子 --><view class="goods-item-left"><radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="radioClickHandler"></radio><image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image></view><!-- 右侧的盒子 --><view class="goods-item-right"><!-- 商品的名字 --><view class="goods-name">{{goods.goods_name}}</view><view class="goods-info-box"><view class="goods-price">¥{{goods.goods_price | tofixed}}</view><uni-number-box :min="1" :value="goods.goods_count" v-if="showNum" @change="numChangeHandler"></uni-number-box></view></view></view>
</template><script>export default {props: {goods: {type: Object,default: {}},showRadio: {type: Boolean,// 默认情况下,不会展示 radio 组件default: false},showNum: {type: Boolean,default: false}},data() {return {// 默认的图片defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'};},filters: {tofixed(num) {return Number(num).toFixed(2)}},methods: {// 这是 radio 组件的 点击事件处理函数radioClickHandler() {this.$emit('radio-change', {goods_id: this.goods.goods_id,goods_state: !this.goods.goods_state})},// 监听到了 NumberBox 组件数量变化的事件numChangeHandler(val) {this.$emit('num-change', {goods_id: this.goods.goods_id,goods_count: +val})}}}
</script><style lang="scss">.goods-item {width: 750rpx;box-sizing: border-box;display: flex;padding: 10px 5px;border-bottom: 1px solid #f0f0f0;.goods-item-left {margin-right: 5px;display: flex;justify-content: space-between;align-items: center;.goods-pic {width: 100px;height: 100px;display: block;}}.goods-item-right {display: flex;flex: 1;flex-direction: column;justify-content: space-between;.goods-name {font-size: 13px;}.goods-info-box {display: flex;justify-content: space-between;align-items: center;.goods-price {color: #C00000;font-size: 16px;}}}}
</style>
<template><view><view class="goods-list"><view v-for="(goods, i) in goodsList" :key="i" @click="gotoDetail(goods)"><my-goods :goods="goods"></my-goods></view></view></view>
</template><script>export default {data() {return {// 请求参数对象queryObj: {query: '',cid: '',pagenum: 1,pagesize: 10},goodsList: [],total: 0,// 节流阀isloading: false};},onLoad(options) {this.queryObj.query = options.query || ''this.queryObj.cid = options.cid || ''this.getGoodsList()},methods: {// 获取商品列表数据的方法async getGoodsList(cb) {// 打开节流阀this.isloading = trueconst { data: res } = await uni.$http.get('/api/public/v1/goods/search', this.queryObj)// 关闭节流阀this.isloading = falsecb && cb()if (res.meta.status !== 200) return uni.$showMsg()this.goodsList = [...this.goodsList, ...res.message.goods]this.total = res.message.total},gotoDetail(goods) {uni.navigateTo({url: '/subpkg/goods_detail/goods_detail?goods_id=' + goods.goods_id})}},onReachBottom() {if (this.queryObj.pagenum * this.queryObj.pagesize >= this.total) return uni.$showMsg('数据加载完毕!')if (this.isloading) return// 让页码值自增+1this.queryObj.pagenum++this.getGoodsList()},onPullDownRefresh() {// 重置关键数据this.queryObj.pagenum = 1this.total = 0this.isloading = falsethis.goodsList = []// 重新发起数据请求this.getGoodsList(() => uni.stopPullDownRefresh())}}
</script><style lang="scss"></style>