Files
Smart-Farm/uniapp/uni-app/shop/pages/hot-goods.vue
2025-12-22 17:13:05 +08:00

150 lines
3.3 KiB
Vue

<template>
<view class="shop-hot-goods">
<fixed>
<view class="fill-base pt-big pb-big pl-md pr-md">
<search @input="toSearch" type="input" :padding="0" :radius="70" placeholder="搜索商品名称"></search>
</view>
</fixed>
<block v-for="(item,index) in list.data" :key="index">
<view @tap.stop="goDetail(index)"
class="goods-item flex-center mt-md ml-md mr-md pd-lg fill-base radius-16">
<image mode="aspectFill" lazy-load class="cover radius-16" :src="item.cover"></image>
<view class="flex-1 ml-lg">
<view class="flex-center">
<view class="flex-1">
<view class="f-title c-title text-bold mt-sm mb-sm ellipsis">{{item.goods_name}}
</view>
<view class="flex-y-baseline f-caption c-warning">¥<view class="f-lg-title">
{{item.show_price}}
</view>
</view>
<view class="f-caption c-caption text-delete">¥{{item.show_init_price}}</view>
</view>
<image lazy-load class="add-car-img" src="/static/image/shop/add-car.png">
</image>
</view>
</view>
</view>
</block>
<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
</load-more>
<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>
<view class="space-footer"></view>
</view>
</template>
<script>
import {
mapState,
mapActions,
mapMutations
} from "vuex"
export default {
components: {},
data() {
return {
options: {},
param: {
page: 1,
},
list: {
data: []
},
loading: true,
lockTap: false,
}
},
computed: mapState({
primaryColor: state => state.config.configInfo.primaryColor,
subColor: state => state.config.configInfo.subColor,
userInfo: state => state.user.userInfo,
}),
async onLoad(options) {
let {
type = 1
} = options
this.$util.showLoading()
this.options = options
await this.initIndex()
},
onPullDownRefresh() {
// #ifndef APP-PLUS
uni.showNavigationBarLoading()
// #endif
this.initRefresh()
uni.stopPullDownRefresh()
},
onReachBottom() {
if (this.list.current_page >= this.list.last_page || this.loading) return
this.param.page = this.param.page + 1
this.loading = true
this.getList()
},
methods: {
...mapActions(['getConfigInfo']),
...mapMutations(['updateUserItem']),
async initIndex() {
this.getList()
},
initRefresh() {
this.param.page = 1
this.initIndex()
},
toSearch(val) {
this.loading = true
this.param.page = 1
this.param.goods_name = val
this.getList()
},
async getList() {
let {
list: oldList,
param,
} = this
let newList = await this.$api.shop.hotGoodsList(param)
if (this.param.page == 1) {
this.list = newList
} else {
newList.data = oldList.data.concat(newList.data)
this.list = newList
}
this.loading = false
this.$util.hideAll()
},
async goDetail(index) {
let {
id
} = this.list.data[index]
let url = `/shop/pages/detail?id=${id}`
this.$util.goUrl({
url
})
}
}
}
</script>
<style lang="scss">
.shop-hot-goods {
.goods-item {
.cover {
width: 180rpx;
height: 170rpx;
}
.add-car-img {
width: 70rpx;
height: 70rpx;
}
.ellipsis {
max-width: 370rpx;
}
}
}
</style>