123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- <template>
- <view class="container">
- <view class="search-box" v-if="goodsList.length">
- <uni-search-bar ref="searchBar" radius="5" placeholder="搜索" :defaultText="goodName" clearButton="auto" cancelButton="none"
- bgColor="#ffffff" @confirm="search" class="search-bar" />
- </view>
- <scroll-view class="goods-box" scroll-y="true" @scrolltolower="handleLoadMore()">
- <view class="goods-row" :style="{height: (item.productType == 2 ? '124px' : '104px')}" v-for="(item, index) in goodsList" :key="index" @click="goToGoodDetails(item)">
- <image class="goods-img" :src="item.imgPath" mode="aspectFill"></image>
- <view class="goods-info">
- <view class="goods-name">{{item.productName}}</view>
- <view class="goods-details" v-if="item.productType != 4">{{item.productDescribe}}</view>
- <view class="goods-area" v-if="item.productType == 4">面积:{{item.areaSize}}㎡ 时长:{{item.term}}天</view>
- <view class="goods-endTime" v-if="item.productType == 2">结束时间: {{item.auctionEndTime}}</view>
- <view class="goods-number">
- <text class="goods-icon">¥</text>
- <text class="goods-spec">{{item.bizPrice}}{{item.productType != 4 ? '/' + item.unit : ''}}</text>
- <text class="goods-original">原价:{{item.originalPrice}}</text>
- <!-- <text class="goods-sales" v-if="item.productType != 4">{{item.sellCount}}人付款</text> -->
- </view>
- </view>
- <view class="goods-cart">
- <view class="cart-button" v-if="goodType == 1 || goodType == 3 || goodType == 5" @click.stop="addCart(item)">
- <view class="iconfont icongouwuche"></view>
- </view>
- <view class="more-button" v-else>
- <view class="iconfont icongengduo"></view>
- </view>
- </view>
- </view>
- <view style="padding-top: 20px;background-color: transparent;" v-if="isOver">
- <u-divider color="#909399" border-color="#909399" bg-color="transparent">没有更多了</u-divider>
- </view>
- </scroll-view>
- <u-modal v-model="modalShow" content="是否将该商品添加至购物车" @confirm="submitAddCart()" :async-close="true"
- :show-cancel-button="true"></u-modal>
- <u-top-tips ref="uTips"></u-top-tips>
- </view>
- </template>
- <script>
- const NET = require('@/utils/request')
- const API = require('@/config/api')
- export default {
- data() {
- return {
- goodType: '',
- pageIndex: 1,
- isOver: false,
- goodName: '',
- goodsList: [],
- modalShow: false,
- goodItem: {},
- auctiontitle: {
- height: '35px',
- background:'#52A63A',
- color: '#FFFFFF',
- 'text-align': 'center',
- padding: '5px',
- }
- }
- },
- onLoad(options) {
- this.goodName = options.goodName ? options.goodName : ''
- this.goodType = options.goodType
- uni.setNavigationBarTitle({
- title: this.goodType == 1 ? '商品列表' : (this.goodType == 3 ? '自助采摘' : (this.goodType == 4 ? '共享种植' : this.goodType == 5 ? '今日特惠' : '拍卖'))
- });
- // this.getGoodsList()
- },
- onShow() {
- this.getGoodsList()
- },
- onReady() {
- if (this.goodName) {
- this.$refs.searchBar.show = true
- this.$refs.searchBar.showSync = true
- this.$refs.searchBar.searchVal = this.goodName
- }
- },
- onPullDownRefresh() {
- this.goodsList = []
- this.pageIndex = 1
- this.getGoodsList('refresh')
- },
- methods: {
- // 搜索商品
- search(data) {
- this.goodName = data.value
- this.goodsList = []
- this.pageIndex = 1
- this.getGoodsList()
- },
- // 懒加载
- handleLoadMore() {
- if (!this.isOver) {
- this.pageIndex++
- this.getGoodsList()
- }
- },
- // 获取商品
- getGoodsList(type) {
- if (this.goodType == 5) {
- NET.request(API.getPreferentialGoods+'/' + this.pageIndex+'/10', {
- name: this.goodName
- }, 'GET').then(res => {
- if (type == 'refresh') {
- uni.stopPullDownRefresh();
- } else {
- this.goodsList = []
- }
- this.isOver = res.data.list.length != 10
- this.goodsList = this.goodsList.concat(res.data.list)
- }).catch(error => {
- this.$refs.uTips.show({
- title: '获取今日特惠商品列表失败',
- type: 'warning',
- })
- })
- } else {
- NET.request(API.getGoodsByType, {
- name: this.goodName,
- productType: this.goodType,
- pageIndex: this.pageIndex,
- pageSize: 10,
- }, 'POST').then(res => {
- if (type == 'refresh') {
- uni.stopPullDownRefresh();
- } else {
- this.goodsList = []
- }
- this.isOver = res.data.list.length != 10
- this.goodsList = this.goodsList.concat(res.data.list)
- }).catch(error => {
- this.$refs.uTips.show({
- title: '获取商品列表失败',
- type: 'warning',
- })
- })
- }
- },
- // 添加购物车
- addCart(item) {
- this.goodItem = {
- productId: this.goodType == 5 ? item.productId : item.id,
- productName: item.productName,
- imgUrl: item.imgPath,
- bizPrice: item.bizPrice,
- originalPrice: item.originalPrice,
- productType: item.productType,
- tenantCode: item.tenantCode,
- buyNum: 1
- }
- this.modalShow = true
- },
- // 提交购物车
- submitAddCart() {
- NET.request(API.addCart, this.goodItem, 'POST').then(res => {
- this.$refs.uTips.show({
- title: '加入购物车成功',
- type: 'success',
- })
- this.modalShow = false
- }).catch(res => {
- this.modalShow = false
- this.$refs.uTips.show({
- title: '加入购物车失败',
- type: 'warning',
- })
- })
- },
- // 跳转商品详情
- goToGoodDetails(item) {
- if (this.goodType == 5) {
- item.id = item.productId
- }
- uni.navigateTo({
- url: '/pagesGood/goodDetails?goodId=' + item.id
- });
- }
- },
- }
- </script>
- <style>
- page {
- width: 100%;
- height: 100%;
- background-color: #f7f7f7;
- }
- </style>
- <style lang="less" scoped>
- page {
- width: 100%;
- height: 100%;
- }
- .container {
- width: 100%;
- height: 100%;
- background-color: #f7f7f7;
- .auction-main {
- // background: #52A63A;
- }
- .auction-title {
- height: 35px;
- background:#52A63A;
- color: #FFFFFF;
- text-align: center;
- padding: 5px;
- }
- .auction-explain {
- background:#52A63A;
- color: #FFFFFF;
- border-radius: 0 0 8px 8px;
- // text-align: center;
- padding: 10px;
- p {
- margin-bottom: 5px;
- text-indent:25px;
- }
- }
- .search-box {
- width: 100%;
- height: 58px;
- box-sizing: border-box;
- padding: 2px 3px 1px 3px;
- /deep/.uni-searchbar {
- background-color: #f7f7f7;
- }
- }
- .goods-box {
- width: 100%;
- height: calc(100% - 58px) !important;
- padding: 6px 0 10px 0;
- box-sizing: border-box;
- overflow-y: auto;
- .goods-row {
- width: calc(100% - 24px);
- height: 104px;
- float: left;
- 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;
- border-radius: 5px;
- }
- .goods-info {
- width: calc(100% - 108px);
- height: 84px;
- box-sizing: border-box;
- padding-left: 6px;
- float: left;
- .goods-name {
- width: calc(100% + 24px);
- 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 10px 0;
- margin-top: 4px
- }
- .goods-area {
- height: 28px;
- margin: 8px 0;
- line-height: 28px;
- font-size: 13px;
- font-family: PingFang SC;
- color: #666666;
- }
- .goods-endTime {
- margin-bottom: 10px;
- font-size: 12px;
- }
- .goods-number {
- height: 16px;
- font-family: PingFang SC;
- line-height: 16px;
- .goods-icon {
- font-size: 12px;
- color: #52A63A;
- }
- .goods-spec {
- font-size: 16px;
- color: #52A63A;
- margin-right: 5px;
- }
- .goods-original {
- font-size: 12px;
- color: #a67954;
- margin-right: 10px;
- text-decoration:line-through
- }
- .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;
- }
- }
- .more-button {
- width: 24px;
- height: 20px;
- margin-top: 64px;
- .iconfont {
- color: #999999;
- font-size: 32px;
- line-height: 20px;
- }
- }
- }
- }
- }
- }
- </style>
|