2024-12-27 15:03:48 +08:00
|
|
|
|
<script setup>
|
|
|
|
|
// 商品管理
|
|
|
|
|
import {
|
2025-01-16 20:18:22 +08:00
|
|
|
|
ref,
|
|
|
|
|
reactive,
|
2024-12-27 15:03:48 +08:00
|
|
|
|
} from 'vue'
|
|
|
|
|
import {
|
|
|
|
|
onLoad,
|
2025-02-07 11:24:41 +08:00
|
|
|
|
onReachBottom,
|
|
|
|
|
onPullDownRefresh
|
2024-12-27 15:03:48 +08:00
|
|
|
|
} from "@dcloudio/uni-app"
|
|
|
|
|
|
2025-01-16 20:18:22 +08:00
|
|
|
|
// 顶部导航
|
2024-12-27 15:03:48 +08:00
|
|
|
|
import apex from "@/components/header/apex.vue"
|
2025-01-16 20:18:22 +08:00
|
|
|
|
// api
|
|
|
|
|
import api from '@/api/index.js'
|
|
|
|
|
// 工具库
|
|
|
|
|
import util from '@/common/js/util.js'
|
|
|
|
|
// 产品列表
|
|
|
|
|
const product = reactive({
|
|
|
|
|
list: [],
|
|
|
|
|
pageNum: 1,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onLoad(() => {
|
|
|
|
|
// 获取列表
|
|
|
|
|
getList()
|
|
|
|
|
})
|
|
|
|
|
|
2025-02-07 11:24:41 +08:00
|
|
|
|
onReachBottom(() => {
|
|
|
|
|
// 获取更多商品
|
|
|
|
|
getMoreList()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onPullDownRefresh(() => {
|
|
|
|
|
// 重载商品列表
|
|
|
|
|
refeshList()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 重载商品列表
|
2025-01-16 20:18:22 +08:00
|
|
|
|
function refeshList() {
|
|
|
|
|
if (product.list.length >= product.total) return
|
|
|
|
|
product.pageNum++
|
|
|
|
|
getList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取更多商品
|
|
|
|
|
function getMoreList() {
|
|
|
|
|
if (product.list.length >= product.total) return
|
|
|
|
|
product.pageNum++
|
|
|
|
|
getList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 请求列表
|
|
|
|
|
function getList() {
|
|
|
|
|
//
|
|
|
|
|
api.shop.getProductionListByUserId({
|
|
|
|
|
data: {
|
|
|
|
|
pageSize: product.pageSize,
|
|
|
|
|
pageNum: product.pageNum,
|
|
|
|
|
}
|
|
|
|
|
}).then(rs => {
|
|
|
|
|
if (rs.code === 200) {
|
|
|
|
|
if (product.pageNum == 1) product.list.length = 0
|
|
|
|
|
product.list.push(...rs.rows)
|
|
|
|
|
product.total = rs.total
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
util.alert({
|
|
|
|
|
content: rs.msg,
|
|
|
|
|
showCancel: false,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 编辑
|
2025-02-07 11:24:41 +08:00
|
|
|
|
* @param {Object} item 商品对象
|
2025-01-16 20:18:22 +08:00
|
|
|
|
*/
|
|
|
|
|
function handleEdit(item) {
|
|
|
|
|
uni.navigateTo({
|
2025-02-07 11:24:41 +08:00
|
|
|
|
url: util.setUrl('/pages/release/commodity', {
|
2025-01-16 20:18:22 +08:00
|
|
|
|
id: item.id
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-02-04 20:44:28 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 跳转
|
2025-02-07 11:24:41 +08:00
|
|
|
|
* @param {String} url 路径
|
2025-02-04 20:44:28 +08:00
|
|
|
|
*/
|
|
|
|
|
function link(url) {
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-02-07 11:24:41 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除发布的商品
|
|
|
|
|
* @param {Object} item 商品对象
|
2025-02-08 18:25:43 +08:00
|
|
|
|
* @param {Object} index 操作的下标
|
2025-02-07 11:24:41 +08:00
|
|
|
|
*/
|
2025-02-08 18:25:43 +08:00
|
|
|
|
function handleRemove(item, index) {
|
2025-02-07 11:24:41 +08:00
|
|
|
|
util.alert({
|
|
|
|
|
content: '确定删除该商品吗?',
|
|
|
|
|
}).then(res => {
|
|
|
|
|
if (!res.confirm) return
|
|
|
|
|
// 删除商品
|
|
|
|
|
api.shop.removeProduct({
|
|
|
|
|
path: [item.id]
|
|
|
|
|
}).then(rs => {
|
|
|
|
|
if (rs.code === 200) {
|
2025-02-08 18:25:43 +08:00
|
|
|
|
product.list.splice(index, 1)
|
2025-02-07 11:24:41 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
util.alert({
|
|
|
|
|
content: rs.msg,
|
|
|
|
|
showCancel: false,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<view class="app">
|
|
|
|
|
<apex title="商品管理">
|
|
|
|
|
<template #right>
|
2025-02-04 20:44:28 +08:00
|
|
|
|
<view class="f24" @click="link('/pages/release/commodity')">添加</view>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</template>
|
|
|
|
|
</apex>
|
|
|
|
|
|
|
|
|
|
<view class="listBox oh">
|
2025-01-16 20:18:22 +08:00
|
|
|
|
<view class="item oh mtb20 mlr20 plr20 bfff br20" v-for="(item,index) in product.list" :key="index">
|
2024-12-27 15:03:48 +08:00
|
|
|
|
<!-- 商品信息 -->
|
|
|
|
|
<view class="product line df ptb20">
|
|
|
|
|
<view class="poster wh160">
|
2025-02-07 11:24:41 +08:00
|
|
|
|
<image class="wh160 br10" :src="item.sliderImage.split(',')[0]" mode="aspectFill" />
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view class="info df fdc jcsb f1 ml20">
|
2025-01-16 20:18:22 +08:00
|
|
|
|
<view class="name t2hd c333 f28">{{item.name}}</view>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
|
2025-01-16 20:18:22 +08:00
|
|
|
|
<view class="count fs0 c999 f24">销量:{{item.sales}}</view>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
|
|
|
|
|
<view class="other df aic">
|
|
|
|
|
<view class="price f1 cFF9B27">
|
|
|
|
|
<text class="f30">价格:</text>
|
|
|
|
|
<text class="f20">¥</text>
|
2025-01-16 20:18:22 +08:00
|
|
|
|
<text class="f30">{{item.price}}</text>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
2025-01-16 20:18:22 +08:00
|
|
|
|
<!-- <view class="f1 c999 f24">库存:×1</view> -->
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view class="menu ptb20 df jcr">
|
|
|
|
|
<!-- <view class="btn sm bar closeHollow plr30">上架</view> -->
|
2025-02-07 11:24:41 +08:00
|
|
|
|
<!-- <view class="btn sm bar closeHollow plr30">下架</view> -->
|
|
|
|
|
<!-- <view class="btn sm bar closeHollow plr30">改价</view> -->
|
2024-12-27 15:03:48 +08:00
|
|
|
|
<!-- 在没有进行中的订单才能删除 -->
|
2025-02-08 18:25:43 +08:00
|
|
|
|
<view class="btn sm bar closeHollow plr30" @click="handleRemove(item,index)">删除</view>
|
2025-01-16 20:18:22 +08:00
|
|
|
|
<view class="btn sm bar warmHollow plr30" @click="handleEdit(item)">编辑</view>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
2025-01-16 20:18:22 +08:00
|
|
|
|
<style lang="scss" scoped>
|
2024-12-27 15:03:48 +08:00
|
|
|
|
//
|
|
|
|
|
</style>
|