123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <template>
- <view class="container">
- <view class="search-box">
- <uni-search-bar ref="searchBar" radius="5" placeholder="搜索" :defaultText="goodName" clearButton="auto" cancelButton="none"
- bgColor="#ffffff" @confirm="search" class="search-bar" />
- </view>
- <k-scroll-view @onPullDown="handlePullDown" @onPullUp="handleLoadMore" class="goods-box">
- <view class="goods-row" v-for="item in goodsList" @click="goToGoodDetails(item)">
- <cover-image class="goods-img" :src="item.imgPath"></cover-image>
- <view class="goods-info">
- <view class="goods-name">{{item.productName}}</view>
- <view class="goods-details">{{item.details}}</view>
- <view class="goods-number">
- <text class="goods-icon">¥</text>
- <text class="goods-spec">{{item.bizPrice}}/{{item.spec}}</text>
- <text class="goods-sales">{{item.sellCount}}人付款</text>
- </view>
- </view>
- <view class="goods-cart">
- <view class="cart-button">
- <view class="iconfont icongouwuche"></view>
- </view>
- </view>
- </view>
- </k-scroll-view>
- </view>
- </template>
- <script>
- const NET = require('@/utils/request')
- const API = require('@/config/api')
- export default {
- data() {
- return {
- goodType: '',
- pageIndex: 1,
- isOver: false,
- goodName: '',
- goodsList: [],
- }
- },
- onLoad(options) {
- this.goodName = options.goodName ? options.goodName : ''
- this.goodType = options.goodType
- switch (this.goodType) {
- case 0:
- break;
- default:
- }
- uni.setNavigationBarTitle({
- title: this.goodType == 0 ? '商品列表' : (this.goodType == 1 ? '自助采摘' : (this.goodType == 2 ? '共享种植' : '拍卖'))
- });
- this.getGoodsList()
- },
- onReady(options) {
- if (this.goodName) {
- this.$refs.searchBar.show = true
- this.$refs.searchBar.showSync = true
- this.$refs.searchBar.searchVal = this.goodName
- }
- },
- methods: {
- // 搜索商品
- search(data) {
- this.goodName = data.value
- this.goodsList = []
- this.pageIndex = 1
- this.getGoodsList()
- },
- // 下拉刷新
- handlePullDown(stopLoad) {
- this.pageIndex = 1
- this.goodsList = []
- this.getGoodsList(stopLoad)
- stopLoad ? stopLoad() : '';
- },
- // 懒加载
- handleLoadMore(stopLoad) {
- if (!this.isOver) {
- this.pageIndex++
- this.getGoodsList()
- } else {
- stopLoad ? stopLoad({
- isEnd: true
- }) : '';
- }
- },
- // 获取商品
- getGoodsList(stopLoad) {
- NET.request(API.getGoodsBySort, {
- name: this.goodName,
- oneId: '',
- twoId: '',
- pageIndex: this.pageIndex,
- pageSize: 10,
- }, 'POST').then(res => {
- if (res.code == 0) {
- this.isOver = res.data.list.length != 10
- this.goodsList = this.goodsList.concat(res.data.list)
- } else {
- uni.showToast({
- title: "获取商品列表失败",
- icon: "none"
- })
- }
- }).catch(res => {})
- },
- // 跳转商品详情
- goToGoodDetails(item) {
- uni.navigateTo({
- url: '/pagesGood/goodDetails?goodId=' + item.productId
- });
- }
- },
- }
- </script>
- <style lang="less" scoped>
- page {
- width: 100%;
- height: 100%;
- }
- .container {
- width: 100%;
- height: 100%;
- background-color: #f7f7f7;
- .search-box {
- width: 100%;
- height: 58px;
- box-sizing: border-box;
- padding: 2px 12px 1px 12px;
- /deep/.uni-searchbar {
- background-color: #f7f7f7;
- }
- }
- .goods-box {
- width: 100%;
- height: calc(100% - 58px) !important;
- padding: 6px 0 0px 0;
- box-sizing: border-box;
- overflow-y: auto;
- .goods-row {
- width: calc(100% - 24px);
- height: 104px;
- padding: 11px 11px 11px 7px;
- box-sizing: border-box;
- margin: 4px 0 12px 12px;
- background: #FFFFFF;
- box-shadow: 0px 1px 5px 0px rgba(102, 102, 102, 0.43);
- border-radius: 15px;
- .goods-img {
- width: 84px;
- height: 84px;
- float: left;
- }
- .goods-info {
- width: calc(100% - 108px);
- height: 84px;
- float: left;
- .goods-name {
- height: 18px;
- font-size: 15px;
- font-family: PingFang SC;
- color: #333333;
- line-height: 18px;
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- }
- .goods-details {
- height: 28px;
- font-size: 12px;
- font-family: PingFang SC;
- color: #999999;
- line-height: 14px;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- word-wrap: break-word;
- margin: 4px 0 12px 0;
- }
- .goods-number {
- height: 16px;
- font-family: PingFang SC;
- line-height: 16px;
- .goods-icon {
- font-size: 12px;
- color: #52A63A;
- }
- .goods-spec {
- font-size: 15px;
- color: #52A63A;
- margin-right: 15px;
- }
- .goods-sales {
- font-size: 12px;
- color: #999999;
- }
- }
- }
- .goods-cart {
- width: 24px;
- height: 84px;
- float: left;
- .cart-button {
- width: 24px;
- height: 24px;
- margin-top: 30px;
- background-color: #52A63A;
- border-radius: 50%;
- text-align: center;
- .iconfont {
- color: #FFFFFF;
- font-size: 18px;
- line-height: 24px;
- }
- }
- }
- }
- }
- }
- </style>
|