wangfukang 2 weeks ago
parent
commit
57c411f1c6
  1. 111
      components/tab-bar/myCenter.vue
  2. 367
      components/tab-bar/postList.vue

111
components/tab-bar/myCenter.vue

@ -346,7 +346,7 @@
desc: '待处理订单', desc: '待处理订单',
icon: this.getMyCenterImage('identityShop'), icon: this.getMyCenterImage('identityShop'),
count: this.shopCounts, count: this.shopCounts,
action: this.hasShop ? 'merchantCenter' : 'merchant' action: 'merchantCenter'
}, { }, {
type: 'delivery', type: 'delivery',
title: '兼职主页', title: '兼职主页',
@ -566,6 +566,64 @@
} }
return typeof list == 'object' ? [list] : [] return typeof list == 'object' ? [list] : []
}, },
setCurrentShop(item) {
uni.setStorageSync('shopId', item.id)
uni.setStorageSync('shopName', item.shopName)
uni.setStorageSync('shopIcon', item.shopIcon)
uni.setStorageSync('shopScore', item.shopScore)
uni.setStorageSync('shopMerchantType', item.merchantType)
uni.setStorageSync('shopTakeaway', item.shopTakeaway)
uni.setStorageSync('attrId', item.attrId)
},
openMerchantCenterWithShops(shops) {
const area = this.getArea()
let shopItem = []
for (let aa = 0; aa < shops.length; aa++) {
if (!area.id || shops[aa].regionId == area.id) {
shopItem.push(shops[aa])
}
}
this.schoolShop = shopItem
if (this.schoolShop.length > 1) {
this.$refs.shopPopup.open()
return
} else if (this.schoolShop.length == 1) {
this.setCurrentShop(this.schoolShop[0])
uni.navigateTo({
url: '/package2/shop/merchantCenter'
})
return
}
uni.showModal({
title: '提示',
content: '您还没有注册成为商家,要去注册吗?',
cancelText: '暂时不了',
confirmText: '去注册',
success: function(res) {
if (res.confirm) {
uni.navigateTo({
url: '/package2/shop/merchantRegister'
})
}
}
})
},
getShopInfoByUserid() {
return this.tui.request("/app/shop/getShopInfoByUserid", "GET", {
userId: uni.getStorageSync('id')
}, false, true).then((res) => {
if (res.code == 200) {
const shops = this.normalizeShopList(res.result)
uni.setStorageSync('schoolShop', shops)
this.openMerchantCenterWithShops(shops)
} else {
this.tui.toast(res.message)
}
uni.hideLoading()
}).catch(() => {
uni.hideLoading()
})
},
showComingSoon(title) { showComingSoon(title) {
this.tui.toast(title + '即将开放') this.tui.toast(title + '即将开放')
}, },
@ -636,13 +694,7 @@
}) })
}, },
clickShop(item) { clickShop(item) {
uni.setStorageSync('shopId', item.id) this.setCurrentShop(item)
uni.setStorageSync('shopName', item.shopName)
uni.setStorageSync('shopIcon', item.shopIcon)
uni.setStorageSync('shopScore', item.shopScore)
uni.setStorageSync('shopMerchantType', item.merchantType)
uni.setStorageSync('shopTakeaway', item.shopTakeaway)
uni.setStorageSync('attrId', item.attrId)
this.$refs.shopPopup.close() this.$refs.shopPopup.close()
uni.navigateTo({ uni.navigateTo({
url: '/package2/shop/merchantCenter' url: '/package2/shop/merchantCenter'
@ -687,45 +739,8 @@
if (e == 'addgoods') { if (e == 'addgoods') {
url = '/package2/myCenter/addGoods' url = '/package2/myCenter/addGoods'
} else if (e == 'merchantCenter') { } else if (e == 'merchantCenter') {
this.schoolShop = this.normalizeShopList(this.schoolShop.length ? this.schoolShop : uni.getStorageSync('schoolShop')) this.getShopInfoByUserid()
if (this.schoolShop && this.schoolShop.length) { return
let shopItem = []
const area = this.getArea()
for (let aa = 0; aa < this.schoolShop.length; aa++) {
if (!area.id || this.schoolShop[aa].regionId == area.id) {
shopItem.push(this.schoolShop[aa])
}
}
this.schoolShop = shopItem
if (this.schoolShop.length > 1) {
this.$refs.shopPopup.open()
return
} else if (this.schoolShop.length == 1) {
uni.setStorageSync('shopId', this.schoolShop[0].id)
uni.setStorageSync('attrId', this.schoolShop[0].attrId)
uni.setStorageSync('shopName', this.schoolShop[0].shopName)
uni.setStorageSync('shopIcon', this.schoolShop[0].shopIcon)
uni.setStorageSync('shopMerchantType', this.schoolShop[0].merchantType)
uni.setStorageSync('shopScore', this.schoolShop[0].shopScore)
uni.setStorageSync('shopTakeaway', this.schoolShop[0].shopTakeaway)
url = '/package2/shop/merchantCenter'
}
} else {
uni.showModal({
title: '提示',
content: '您还没有注册成为商家,要去注册吗?',
cancelText: '暂时不了',
confirmText: '去注册',
success: function(res) {
if (res.confirm) {
uni.navigateTo({
url: '/package2/shop/merchantRegister'
})
}
}
})
return
}
} else if (e == 'dingdan') { } else if (e == 'dingdan') {
url = '/package1/order/orderList' url = '/package1/order/orderList'
} else if (e == 'groupPending') { } else if (e == 'groupPending') {
@ -763,7 +778,7 @@
this.showComingSoon('星球券') this.showComingSoon('星球券')
return return
} else if (e == 'fishRelease') { } else if (e == 'fishRelease') {
url = '/package1/tabbar/release' url = '/package1/tabbar/fishRelease'
} else if (e == 'myPost') { } else if (e == 'myPost') {
url = '/package2/myCenter/myPost' url = '/package2/myCenter/myPost'
} else if (e == 'idleTrad') { } else if (e == 'idleTrad') {

367
components/tab-bar/postList.vue

@ -29,9 +29,10 @@
scroll-y scroll-y
:style="{ paddingTop: headerHeight + 'px' }" :style="{ paddingTop: headerHeight + 'px' }"
:show-scrollbar="false" :show-scrollbar="false"
@scrolltolower="loadMore"
> >
<view class="scroll-content"> <view class="scroll-content">
<view class="hero-card"> <!-- <view class="hero-card">
<image class="hero-image" :src="getPostListImage('hero')" mode="aspectFill"></image> <image class="hero-image" :src="getPostListImage('hero')" mode="aspectFill"></image>
<view class="hero-copy"> <view class="hero-copy">
<view class="hero-title">幸运盲盒</view> <view class="hero-title">幸运盲盒</view>
@ -48,14 +49,20 @@
<view class="hero-dot"></view> <view class="hero-dot"></view>
<view class="hero-dot"></view> <view class="hero-dot"></view>
</view> </view>
-->
<view class="shortcut-list"> <view class="shortcut-list">
<view class="shortcut-item" v-for="(item,index) in shortcutList" :key="index" @tap="selectShortcut(item)"> <view
class="shortcut-item"
:class="{ 'shortcut-item--publish': item.action == 'publishSell' }"
v-for="(item,index) in shortcutList"
:key="index"
@tap="selectShortcut(item)"
>
<view class="shortcut-icon"> <view class="shortcut-icon">
<image class="shortcut-icon-image" :src="getPostListImage(item.imageKey)" mode="aspectFit"></image> <image class="shortcut-icon-image" :src="getPostListImage(item.imageKey)" mode="aspectFit"></image>
</view> </view>
<view class="shortcut-name">{{item.name}}</view> <view class="shortcut-name">{{item.name}}</view>
<view class="shortcut-desc">{{item.desc}}</view> <view class="shortcut-desc">{{item.action == 'publishSell' ? '点我发布' : item.desc}}</view>
</view> </view>
</view> </view>
@ -90,7 +97,7 @@
:data-goods-id="item.id" :data-goods-id="item.id"
@load="onImageLoad" @load="onImageLoad"
></image> ></image>
<view class="distance-tag">距离{{item.distance}}</view> <view class="distance-tag">{{item.regionName}}</view>
</view> </view>
<view class="goods-info"> <view class="goods-info">
<view class="goods-title">{{item.text}}</view> <view class="goods-title">{{item.text}}</view>
@ -103,7 +110,7 @@
</view> </view>
<view class="seller-row"> <view class="seller-row">
<image class="seller-avatar" :src="item.icon" mode="aspectFill"></image> <image class="seller-avatar" :src="item.icon" mode="aspectFill"></image>
<text class="seller-name">{{item.shopName}}</text> <text class="seller-name">半径卖家</text>
<view class="want-count" @tap.stop="toggleLike(item)"> <view class="want-count" @tap.stop="toggleLike(item)">
<uni-icons <uni-icons
:type="item.liked ? 'heart-filled' : 'heart'" :type="item.liked ? 'heart-filled' : 'heart'"
@ -130,6 +137,13 @@
</template> </template>
<script> <script>
import {
listFishCategories,
pageFishGoods,
pageFishWants,
toggleFishLike
} from '@/common/fishMarketApi.js'
const POST_LIST_IMAGE_CACHE_KEY = 'post_list_image_cache_v1' const POST_LIST_IMAGE_CACHE_KEY = 'post_list_image_cache_v1'
const POST_LIST_IMAGE_CACHE_TTL = 30 * 24 * 60 * 60 * 1000 const POST_LIST_IMAGE_CACHE_TTL = 30 * 24 * 60 * 60 * 1000
const POST_LIST_IMAGE_CACHE_LIMIT = 12 const POST_LIST_IMAGE_CACHE_LIMIT = 12
@ -151,88 +165,50 @@
keyword: '', keyword: '',
categoryIndex: 0, categoryIndex: 0,
shortcutList: [{ shortcutList: [{
name: '0元专区',
desc: '免费送好物',
category: '推荐',
imageKey: 'free'
}, {
name: '求购广场', name: '求购广场',
desc: '找你想要的', desc: '大家想要的',
category: '求购', category: '求购',
imageKey: 'wanted' imageKey: 'wanted',
}, { action: 'category'
name: '极速卖',
desc: '快速出手',
category: '推荐',
imageKey: 'quickSell'
}, { }, {
name: '拼团购', name: '拼团购',
desc: '拼着更便宜', desc: '暂未开放',
category: '拼团购', category: '拼团购',
imageKey: 'groupBuy' imageKey: 'groupBuy',
action: 'disabled'
}, { }, {
name: '毕业清仓', name: '发布',
desc: '好物低价', desc: '极速买卖',
category: '生活', category: '推荐',
imageKey: 'graduation' imageKey: 'quickSell',
}], action: 'publishSell'
categories: ['推荐', '附近', '数码', '书籍', '生活', '美妆', '服饰'], },{
goodsList: [{ name: '我的消息',
id: 1, desc: '买卖沟通',
pic: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/9362dfb66c0f426789584cabb3977ccc.png', category: '推荐',
text: 'LG 27寸显示屏 带底座', imageKey: 'free',
price: 100, action: 'sessions'
originalPrice: 699,
xiangyao: 32,
distance: '200m',
icon: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/801c569079da4540990c1cc634186fdd.png',
shopName: '小熊数码',
tags: ['轻微使用', '可小刀'],
category: '数码',
liked: false
}, {
id: 2,
pic: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/bc6b887514a5469a938cdd0001e841c2.png',
text: '宿舍护眼台灯 学习专用',
price: 38,
originalPrice: 89,
xiangyao: 21,
distance: '300m',
icon: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/801c569079da4540990c1cc634186fdd.png',
shopName: '桃桃乌龙',
tags: ['轻微使用', '可小刀'],
category: '生活',
liked: false
}, {
id: 3,
pic: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/90a37f3f8a204d7eaa8ea2d3293e1086.png',
text: '考研资料打包出 笔记齐全',
price: 15,
originalPrice: 39,
xiangyao: 18,
distance: '400m',
icon: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/801c569079da4540990c1cc634186fdd.png',
shopName: '晴天小卖部',
tags: ['九成新', '可小刀'],
category: '书籍',
liked: false
}, { }, {
id: 4, name: '我的',
pic: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/9362dfb66c0f426789584cabb3977ccc.png', desc: '个人中心',
text: '便携蓝牙音箱 音质清晰', category: '我的',
price: 45, imageKey: 'graduation',
originalPrice: 129, action: 'mine'
xiangyao: 12, }],
distance: '150m', baseCategories: ['推荐', '附近', '最新', '求购'],
icon: 'https://jewel-shop.oss-cn-beijing.aliyuncs.com/801c569079da4540990c1cc634186fdd.png', categoryList: [],
shopName: '可乐不加冰', goodsList: [],
tags: ['全新', '可小刀'], pageNum: 1,
category: '数码', pageSize: 10,
liked: false totalPages: 1,
}] loading: false,
sortType: 'hot'
} }
}, },
computed: { computed: {
categories() {
return this.baseCategories.concat(this.categoryList.map(item => item.name))
},
statusBarTop() { statusBarTop() {
return Number(this.menuButtonInfo.top) || 24 return Number(this.menuButtonInfo.top) || 24
}, },
@ -241,13 +217,7 @@
return this.statusBarTop + uni.upx2px(158) return this.statusBarTop + uni.upx2px(158)
}, },
filteredGoods() { filteredGoods() {
const keyword = this.keyword.toLowerCase() return this.goodsList
const category = this.categories[this.categoryIndex]
return this.goodsList.filter(item => {
const matchesCategory = category == '推荐' || category == '附近' || item.category == category
const text = [item.text, item.shopName, item.category].concat(item.tags || []).join(' ').toLowerCase()
return matchesCategory && (!keyword || text.indexOf(keyword) > -1)
})
}, },
waterfallColumns() { waterfallColumns() {
const columns = [[], []] const columns = [[], []]
@ -404,28 +374,66 @@
bottom: (systemInfo.statusBarHeight || 24) + 32 bottom: (systemInfo.statusBarHeight || 24) + 32
} }
} }
this.loadCategories()
this.reloadGoods()
}, },
handleSearch() { handleSearch() {
uni.hideKeyboard() uni.hideKeyboard()
this.reloadGoods()
}, },
changeCategory(index) { changeCategory(index) {
this.categoryIndex = index this.categoryIndex = index
this.reloadGoods()
}, },
selectShortcut(item) { selectShortcut(item) {
if (!item) return
if (item.action == 'disabled') {
uni.showToast({
title: item.name + '暂未开放',
icon: 'none'
})
return
}
if (item.action == 'publishSell') {
this.goPublish('sell')
return
}
if (item.action == 'publishWant') {
this.goPublish('want')
return
}
if (item.action == 'mine') {
this.goMyFish()
return
}
if (item.action == 'sessions') {
this.goFishSessions()
return
}
const index = this.categories.indexOf(item.category) const index = this.categories.indexOf(item.category)
if (index > -1) { if (index > -1) {
this.categoryIndex = index this.categoryIndex = index
if (item.keyword) {
this.keyword = item.keyword
} else if (item.action != 'filter') {
this.keyword = ''
}
this.reloadGoods()
} else { } else {
uni.showToast({ this.keyword = item.keyword || item.name
title: item.name + '即将开放', this.categoryIndex = 0
icon: 'none' this.reloadGoods()
})
} }
}, },
showFilterTip() { showFilterTip() {
uni.showToast({ const sorts = ['推荐优先', '最新发布', '价格从低到高', '价格从高到低']
title: '筛选功能即将开放', uni.showActionSheet({
icon: 'none' itemList: sorts,
success: (res) => {
const map = ['hot', 'latest', 'priceAsc', 'priceDesc']
this.sortType = map[res.tapIndex] || 'hot'
this.reloadGoods()
}
}) })
}, },
openBlindBox() { openBlindBox() {
@ -434,6 +442,97 @@
icon: 'none' icon: 'none'
}) })
}, },
loadCategories() {
const area = this.getArea()
listFishCategories(area.id || '').then(list => {
this.categoryList = Array.isArray(list) ? list : []
}).catch(() => {})
},
reloadGoods() {
this.pageNum = 1
this.totalPages = 1
this.goodsList = []
this.loadGoods()
},
loadMore() {
if (this.loading || this.pageNum >= this.totalPages) return
this.pageNum += 1
this.loadGoods()
},
loadGoods() {
if (this.loading) return
this.loading = true
const category = this.categories[this.categoryIndex]
const categoryItem = this.categoryList.find(item => item.name == category)
const area = this.getArea()
const sortType = this.sortType || (category == '附近' ? 'school' : (category == '最新' ? 'latest' : 'hot'))
const query = {
pageNum: this.pageNum,
pageSize: this.pageSize,
keyword: this.keyword,
regionId: area.id || '',
sortType,
categoryId: categoryItem ? categoryItem.id : '',
status: 1,
auditStatus: 1,
offShelf: 0
}
const request = category == '求购' ? pageFishWants(query) : pageFishGoods(query)
request.then(page => {
const records = this.normalizeRecords(page && (page.records || page.content), category == '求购')
this.totalPages = Number(page && (page.pages || page.totalPages)) || 1
this.goodsList = this.pageNum == 1 ? records : this.goodsList.concat(records)
}).finally(() => {
this.loading = false
})
},
normalizeRecords(records, isWant) {
const area = this.getArea()
const fallbackRegionName = area.title || area.name || uni.getStorageSync('schoolName') || '本校'
return (Array.isArray(records) ? records : []).map(item => {
const images = this.parseJsonList(item.images)
const tags = this.parseJsonList(item.tags)
return {
raw: item,
id: item.id,
pic: item.coverImage || images[0] || '',
text: item.title || '',
price: isWant ? (item.expectedPrice || 0) : (item.price || 0),
originalPrice: item.originPrice,
xiangyao: item.likeCount || 0,
distance: item.distance || '本校',
icon: item.userAvatar || '/static/images/img/songshu.png',
shopName: item.userName || '校园同学',
regionName: item.regionName || item.schoolName || item.areaName || fallbackRegionName,
tags: tags.length ? tags : (item.negotiable == 1 ? ['可小刀'] : []),
category: item.categoryName || '',
liked: !!item.liked,
type: isWant ? 'want' : 'goods'
}
})
},
parseJsonList(value) {
if (!value) return []
if (Array.isArray(value)) return value
try {
const parsed = JSON.parse(value)
return Array.isArray(parsed) ? parsed : []
} catch (e) {
return []
}
},
getArea() {
const area = uni.getStorageSync('area')
if (!area) return {}
if (typeof area === 'string') {
try {
return JSON.parse(area)
} catch (e) {
return {}
}
}
return area
},
getImageHeight(item) { getImageHeight(item) {
return Number(item.imageHeight) || 280 return Number(item.imageHeight) || 280
}, },
@ -451,12 +550,40 @@
} }
}, },
toggleLike(item) { toggleLike(item) {
item.liked = !item.liked if (!item || item.type == 'want') return
item.xiangyao += item.liked ? 1 : -1 if (!item.id) {
uni.showToast({ title: '商品ID不能为空', icon: 'none' })
return
}
toggleFishLike({ goodsId: item.id, likeType: 'goods' }).then(res => {
if (!res) return
item.liked = !!res.liked
item.xiangyao = Number(res.count) || 0
})
},
goDetail(item) {
if (!item) return
if (item.type == 'want') {
this.goPublish('sell')
return
}
uni.navigateTo({
url: '/package2/IdleTrad/detail?id=' + item.id
})
}, },
goDetail() { goPublish(type) {
uni.navigateTo({ uni.navigateTo({
url: '/package2/IdleTrad/detail' url: '/package1/tabbar/fishRelease?type=' + (type || 'sell')
})
},
goMyFish() {
uni.navigateTo({
url: '/package2/myCenter/myPost'
})
},
goFishSessions() {
uni.navigateTo({
url: '/package2/IdleTrad/sessionList'
}) })
} }
} }
@ -684,15 +811,41 @@
.shortcut-item { .shortcut-item {
width: 19%; width: 19%;
position: relative;
text-align: center; text-align: center;
} }
.shortcut-item--publish {
margin-top: -8rpx;
}
.shortcut-item--publish::before {
content: '';
position: absolute;
left: 50%;
top: -6rpx;
width: 104rpx;
height: 104rpx;
border-radius: 30rpx;
background: linear-gradient(180deg, #fff7df 0%, #fff 100%);
box-shadow: 0 10rpx 24rpx rgba(255, 156, 24, 0.24);
transform: translateX(-50%);
}
.shortcut-icon { .shortcut-icon {
width: 84rpx; width: 84rpx;
height: 84rpx; height: 84rpx;
margin: 0 auto 10rpx; margin: 0 auto 10rpx;
} }
.shortcut-item--publish .shortcut-icon {
position: relative;
z-index: 1;
width: 98rpx;
height: 98rpx;
margin-bottom: 2rpx;
}
.shortcut-icon-image { .shortcut-icon-image {
width: 100%; width: 100%;
height: 100%; height: 100%;
@ -706,6 +859,14 @@
white-space: nowrap; white-space: nowrap;
} }
.shortcut-item--publish .shortcut-name {
position: relative;
z-index: 1;
color: #ff8a00;
font-size: 25rpx;
font-weight: 900;
}
.shortcut-desc { .shortcut-desc {
margin-top: 5rpx; margin-top: 5rpx;
color: #939c98; color: #939c98;
@ -713,6 +874,15 @@
white-space: nowrap; white-space: nowrap;
} }
.shortcut-item--publish .shortcut-desc {
position: relative;
z-index: 1;
margin-top: 1rpx;
color: #ff9b1a;
font-size: 18rpx;
font-weight: 800;
}
.category-row { .category-row {
height: 80rpx; height: 80rpx;
display: flex; display: flex;
@ -810,8 +980,8 @@
.distance-tag { .distance-tag {
position: absolute; position: absolute;
top: 14rpx; top: 1rpx;
left: 14rpx; left: 1rpx;
height: 36rpx; height: 36rpx;
padding: 0 12rpx; padding: 0 12rpx;
border-radius: 18rpx; border-radius: 18rpx;
@ -944,4 +1114,5 @@
height: calc(190rpx + constant(safe-area-inset-bottom)); height: calc(190rpx + constant(safe-area-inset-bottom));
height: calc(190rpx + env(safe-area-inset-bottom)); height: calc(190rpx + env(safe-area-inset-bottom));
} }
</style> </style>

Loading…
Cancel
Save