幼教产品B2B生态平台小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
7.0 KiB

11 months ago
<template>
11 months ago
<view class="page">
<view class="search-wrap">
<uni-search-bar class="search" radius="30" placeholder="请输入产品名称" v-model="keyword" clearButton="auto" cancelButton="none" @confirm="initList" @clear="clearKeyword" />
</view>
<ul class="tab">
<li :class="{active: curTab === ''}" @click="tabChange('')">全部</li>
10 months ago
<li :class="{active: curTab === 1}" @click="tabChange(1)">已上架({{ status1 }})</li>
11 months ago
<li :class="{active: curTab === 2}" @click="tabChange(2)">已下架({{ status2 }})</li>
<li :class="{active: curTab === 3}" @click="tabChange(3)">草稿({{ status3 }})</li>
<!-- <li :class="{active: curTab === 4}" @click="tabChange(4)">审核中({{ status4 }})</li> -->
<li class="disabled">审核中({{ status4 }})</li>
</ul>
<template v-if="list.length">
<view class="list">
<view class="item" v-for="item in list" @click="toDetail(item)">
<view class="metas">
<view class="time">{{ item.putawayTime }}</view>
<view :class="['status', {grounding: item.status === 1}]">{{ Goods.goodsStatus.find(e => e.id === item.status).name }}</view>
</view>
<view class="info">
<image class="pic" :src="item.pic"></image>
<view class="texts">
<view class="name">{{ item.prodName }}</view>
<view class="meta">
市场价{{ item.oriPrice || 0 }}
<text class="sell">售价{{ item.price || 0 }}</text>
</view>
<view class="meta">
库存{{ item.totalStocks || 0 }}&emsp;
<!-- 已售500 -->
</view>
<view class="btns">
<template v-if="item.status === 2 || item.status === 3">
<view class="btn del" @click.stop="del(item)">删除</view>
<view class="btn" @click.stop="toEdit(item)">编辑</view>
</template>
<view v-else-if="item.status === 1" class="btn off" @click.stop="changeStatus(item)">下架</view>
11 months ago
</view>
</view>
</view>
</view>
11 months ago
</view>
<uni-load-more :status="status" />
</template>
<empty v-else text="暂无商品"></empty>
<uni-icons class="plus" type="plus-filled" size="60" color="#007eff" @click="$util.to('../addGoods/addGoods')"></uni-icons>
11 months ago
</view>
</template>
<script>
import { page, batchDelete, prodStatus } from '@/apis/modules/goods.js'
11 months ago
import Goods from '@/config/goods.js'
11 months ago
export default {
data() {
return {
10 months ago
team: uni.getStorageSync('team'),
isTeam: uni.getStorageSync('team').isTeam == 1, // 队长
11 months ago
Goods,
11 months ago
curTab: '',
tabs: [],
reachBottom: 0, // 是否是上拉加载。0->否,1->是,-1->加载完所有数据
status: 'more', // 上拉加载状态 more|loading|noMore
searchTimer: null,
keyword: '',
list: [],
page: 1,
11 months ago
pageSize: 10,
11 months ago
total: 0,
status1: 0,
11 months ago
status2: 0,
status3: 0,
status4: 0,
11 months ago
}
},
watch: {
keyword () {
clearTimeout(this.searchTimer)
this.searchTimer = setTimeout(() => {
this.initList()
}, 500)
}
},
// 下拉刷新
onPullDownRefresh() {
this.initList()
setTimeout(() => {
uni.stopPullDownRefresh()
}, 1500)
},
// 上拉加载
onReachBottom() {
if (this.reachBottom >= 0) {
this.reachBottom = 1
this.status = 'loading'
this.getList()
}
},
onShow() {
11 months ago
this.status1 = 0
11 months ago
this.status2 = 0
this.status3 = 0
this.status4 = 0
11 months ago
this.initList()
},
methods: {
// 获取列表
getList() {
uni.showLoading({
title: '加载中'
})
page({
11 months ago
status: this.curTab,
current: this.page,
11 months ago
prodName: this.keyword,
10 months ago
shopId: this.team.isTeam ? this.team.teamId : this.team.parentId
11 months ago
}).then(({ page, productCount }) => {
// 各种状态的商品数量
const status1 = productCount.find(e => e.status === 1)
if (status1) this.status1 = status1.count
const status2 = productCount.find(e => e.status === 2)
if (status2) this.status2 = status2.count
const status3 = productCount.find(e => e.status === 3)
if (status3) this.status3 = status3.count
const status4 = productCount.find(e => e.status === 4)
if (status4) this.status4 = status4.count
11 months ago
uni.hideLoading()
// 未加载完所有数据,并且不是筛选,则拼接list,否则直接赋值
11 months ago
const list = page.records
11 months ago
list.forEach(e => {
if (e.pic) e.pic = e.pic.split(',')[0]
})
this.list = this.reachBottom > 0 ? [...this.list, ...list] : list
11 months ago
this.page++ // 每次获取了数据后page+1
11 months ago
const noMore = this.list.length === page.total // 是否加载完所有数据
this.total = page.total
11 months ago
this.status = noMore ? 'noMore' : 'more' // 加载完了则设置为noMore
this.reachBottom = noMore ? -1 : 0 // 加载完了则设置为-1
}).catch(e => {
uni.hideLoading()
})
},
initList() {
this.page = 1
this.reachBottom = 0
this.getList()
},
11 months ago
// keyword清除回调
clearKeyword() {
this.keyword = ''
this.initList()
},
11 months ago
// tab切换
tabChange(id) {
this.curTab = id
this.initList()
},
11 months ago
// 下架
async changeStatus(row, status) {
const that = this
uni.showModal({
title: '提示',
content: `确定要下架吗?`,
async success(res) {
if (res.confirm) {
await prodStatus(row.prodId, 2)
that.initList()
}
}
})
},
// 删除
del(row) {
const that = this
uni.showModal({
title: '提示',
content: '确定要删除吗?',
async success(res) {
if (res.confirm) {
await batchDelete([row.prodId])
that.$util.sucMsg('删除成功')
that.initList()
}
}
})
11 months ago
},
// 跳转详情
toDetail(item) {
11 months ago
this.$util.to(`../goodsDetail/goodsDetail?prodId=${item.prodId}`)
11 months ago
},
// 跳转编辑
toEdit(item) {
11 months ago
this.$util.to(`../addGoods/addGoods?prodId=${item.prodId}`)
11 months ago
},
}
}
</script>
<style scoped lang="scss">
.list {
margin-top: 20rpx;
11 months ago
padding: 20rpx;
.item {
11 months ago
padding: 20rpx;
margin-bottom: 20rpx;
// border-bottom: 1px solid #f1f1f1;
background-color: #fff;
}
.metas {
display: flex;
justify-content: space-between;
11 months ago
padding-bottom: 10rpx;
margin-bottom: 10rpx;
border-bottom: 1px dashed #eaeaea;
11 months ago
}
.time {
font-size: 24rpx;
color: #333;
}
.status {
font-size: 24rpx;
color: #333;
}
11 months ago
.grounding {
color: #1fc133;
}
11 months ago
.info {
display: flex;
align-items: center;
}
.pic {
11 months ago
width: 280rpx;
height: 180rpx;
11 months ago
margin-right: 20rpx;
11 months ago
border-radius: 8px;
}
.texts {
width: calc(100% - 300rpx);
11 months ago
}
.name {
font-size: 30rpx;
color: #333;
}
.meta {
display: flex;
margin: 10rpx 0;
11 months ago
font-size: 24rpx;
11 months ago
color: #999;
}
11 months ago
.sell {
margin-left: 20rpx;
color: #d60000;
}
11 months ago
.btns {
11 months ago
display: flex;
justify-content: flex-end;
margin-top: 20rpx;
11 months ago
}
.btn {
11 months ago
padding: 10rpx 50rpx;
11 months ago
margin-left: 20rpx;
font-size: 28rpx;
color: #fff;
background-color: $uni-primary;
11 months ago
border-radius: 20px;
11 months ago
&.del {
11 months ago
background-color: #ea9b4a;
11 months ago
}
&.off {
11 months ago
background-color: #de5151;
11 months ago
}
}
}
</style>