Files
lilishop-uniapp/pages/tabbar/user/similarGoods.vue
pikachu1995@126.com dc2bef455a refactor: 移动端升级 Vue3 + uView Plus
将 lilishop-uniapp 从 Vue2/uView 1.6 迁移到 Vue3/uview-plus,优先支持 H5/微商城与微信小程序;移除 vendored uview-ui,改用 npm 依赖、Vuex4 与迁移脚本/补丁,并补充 VUE3_MIGRATION.md 回归清单。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 18:50:38 +08:00

188 lines
4.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="similar-goods">
<view class="goods" @click="goDetail(goods.goods_id)">
<image :src="goods.goods_img" mode=""></image>
<view class="goods-intro">
<view>{{goods.goodsName}}</view>
<view>{{goods.goods_sn}}</view>
<view>¥{{unitPrice(goods.goods_price)}}</view>
</view>
<!-- <button>找相似</button> -->
</view>
<view class="title">相似好货&nbsp;为您推荐</view>
<view class="scroll-con">
<view v-if="nomsg">没有相似商品</view>
<view v-else class="con" v-for="(item,index) in goodsList" :key="index" @click="goDetail(item)">
<image :src="item.thumbnail" mode=""></image>
<view class="nowrap">{{item.name}}</view>
<view>
<text>{{unitPrice(item.price)}}
<!-- <text v-if="item.point">+{{item.point || 0}}积分</text> -->
</text>
<text>{{item.mktprice}}</text>
</view>
<view>
<text>已售{{item.buy_count}}</text>
<text>{{item.grade}}%好评</text>
</view>
</view>
</view>
<uni-load-more :status="loadStatus"></uni-load-more>
</view>
</template>
<script>
import {
getGoodsList
} from '@/api/goods.js';
export default {
data() {
return {
loadStatus: 'more',
params: {
pageNumber: 1,
pageSize: 10,
keyword: ''
},
goods: {},
goodsList: [],
nomsg: false,
};
},
methods: {
getList() {
uni.showLoading({
title: "加载中"
})
this.params.keyword = this.goods.goodsName;
getGoodsList(this.params).then(res => {
if (this.$store.state.isShowToast){ uni.hideLoading() }
if (res.statusCode == 200) {
let data = res.data;
if (data.data_total == 0) {
// this.nomsg = true;
this.loadStatus = 'noMore';
} else if (data.data_total < 10) {
this.loadStatus = 'noMore'
this.goodsList.push(...data.data)
} else {
this.goodsList.push(...data.data);
if (data.data.length < 10) this.loadStatus = 'noMore'
}
}
})
},
goDetail(item) {
uni.navigateTo({
url: '/pages/product/goods?id=' + item.id + "&goodsId=" +item.goodsId
})
},
loadData() {
if(this.loadStatus!='noMore'){
this.params.pageNumber++;
this.getList()
}
},
},
onLoad(option) {
this.goods = JSON.parse(decodeURIComponent(option.goods))
this.getList()
},
onReachBottom() { //触底事件,页面整个滚动使用
this.loadData()
}
}
</script>
<style lang="scss" scoped>
@import './collect.scss';
.title {
height: 110rpx;
line-height: 110rpx;
text-align: center;
color: #333;
background-color: #F1F1F1;
margin-top: 20rpx;
font-size: $font-base;
}
.goods {
padding: 0 30rpx;
}
.scroll-con {
width: 750rpx;
flex-wrap: wrap;
.con {
width: 345rpx;
margin: 20rpx 0 0 20rpx;
background-color: #FFFFFF;
border-radius: 10rpx;
box-sizing: border-box;
display: inline-block;
font-size: $font-sm;
// line-height: 1.5em;
image {
width: 100%;
height: 320rpx;
border-radius: 8rpx 8rpx 0 0;
}
view{
padding: 0 20rpx;
&::after{
content: '';
display: block;
clear: right;
}
text {
display: inline-block;
color: #999;
}
text:nth-child(2) {
float: right;
text-align: right;
}
}
view:last-child{
margin-bottom: 20rpx;
}
.nowrap {
position: relative;
line-height: 1.4em;
max-height: 2.8em; //height是line-height的整数倍防止文字显示不全
overflow: hidden;
}
view:nth-child(2) {
font-size: 26rpx;
}
view:nth-child(3) {
margin-top: 10rpx;
font-weight: bold;
text:nth-child(1) {
color: #f56c6c;
}
text:nth-child(2) {
color: #d7d7d7;
text-decoration: line-through;
}
}
view:nth-child(4) {
margin-top: 10rpx;
}
}
}
</style>