商品库存功能优化

This commit is contained in:
duan
2024-06-24 17:23:26 +08:00
parent e571869422
commit d51dd3382d
2 changed files with 125 additions and 19 deletions

View File

@@ -163,19 +163,26 @@ export function tbProductStockOperateOutAndOn(data) {
*/ */
export function stock(params) { export function stock(params) {
return request({ return request({
url: `/api/stock`, url: `/api/stock/v2`,
method: "get",
params
});
}
// 库存列表子集列表
export function stocks(params) {
return request({
url: `/api/stock/sku`,
method: "get", method: "get",
params params
}); });
} }
/** /**
* 导出数据 * 导出数据
* @returns * @returns
*/ */
export function stockdownload(data) { export function stockdownload(data) {
return request({ return request({
url: "/api/stock/download", url: "/api/stock/download/v2",
method: "post", method: "post",
data: { data: {
shopId: localStorage.getItem("shopId"), shopId: localStorage.getItem("shopId"),
@@ -194,7 +201,7 @@ export function stockdoImport(file) {
formData.append("file", file); formData.append("file", file);
formData.append("shopId", localStorage.getItem("shopId")); formData.append("shopId", localStorage.getItem("shopId"));
return request({ return request({
url: "/api/stock/doImport", url: "/api/stock/doImport/v2",
method: "post", method: "post",
data: formData, data: formData,
Headers: { Headers: {
@@ -217,3 +224,14 @@ export function stockStateChange(params) {
} }
}); });
} }
// 共享库存
export function stockStateChanges(params) {
return request({
url: `/api/stock/productStatus`,
method: "put",
data: {
shopId: localStorage.getItem("shopId"),
...params
}
});
}

View File

@@ -23,8 +23,9 @@
</div> </div>
</div> </div>
<div class="head-container"> <div class="head-container">
<el-table :data="tableData.list" v-loading="tableData.loading"> <el-table :data="tableData.list" v-loading="tableData.loading" row-key="id" lazy :load="load"
<el-table-column label="商品信息"> :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
<el-table-column label="商品信息" width="200px">
<template v-slot="scope"> <template v-slot="scope">
<div class="shop_info"> <div class="shop_info">
<el-image :src="scope.row.img" class="cover"> <el-image :src="scope.row.img" class="cover">
@@ -48,17 +49,30 @@
</el-table-column> </el-table-column>
<el-table-column label="库存" prop="number"> <el-table-column label="库存" prop="number">
<template v-slot="scope"> <template v-slot="scope">
{{ `${scope.row.number} ${scope.row.unitName}` }} {{ `${scope.row.stockNumber} ${scope.row.unitName}` }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="库存开关"> <el-table-column label="库存开关">
<template v-slot="scope"> <template v-slot="scope">
<el-switch v-model="scope.row.isStock" :active-value="1" :inactive-value="0" <el-switch v-model="scope.row.isStock" :active-value="1" :inactive-value="0"
v-if="scope.row.hasChildren || scope.row.hasChildren == false"
@change="showChange($event, scope.row)"></el-switch> @change="showChange($event, scope.row)"></el-switch>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" width="100"> <el-table-column label="共享库存">
<template v-slot="scope">
<el-switch v-model="scope.row.isDistribute" :active-value="1" :inactive-value="0"
v-if="scope.row.hasChildren || scope.row.hasChildren == false"
@change="showChanges($event, scope.row, 'proId', 'distribute')"></el-switch>
</template>
</el-table-column> <el-table-column label="售罄">
<template v-slot="scope">
<el-switch v-model="scope.row.isPauseSale" :active-value="1" :inactive-value="0"
@change="showChangess($event, scope.row)"></el-switch>
</template>
</el-table-column>
<el-table-column label="操作" width="220">
<template v-slot="scope"> <template v-slot="scope">
<el-button type="text" size="mini" <el-button type="text" size="mini"
@click="$refs.invoicingDetail.show(scope.row)">库存记录</el-button> @click="$refs.invoicingDetail.show(scope.row)">库存记录</el-button>
@@ -79,7 +93,7 @@
</template> </template>
<script> <script>
import { stock, stockdownload, stockdoImport, stockStateChange } from '@/api/invoicing' import { stock, stockdownload, stockdoImport, stockStateChange, stockStateChanges, stocks } from '@/api/invoicing'
import settings from '@/settings' import settings from '@/settings'
import invoicingDetail from './components/invoicingDetail' import invoicingDetail from './components/invoicingDetail'
import UploadExcel from '@/components/UploadExcel/' import UploadExcel from '@/components/UploadExcel/'
@@ -113,6 +127,31 @@ export default {
this.getTableData() this.getTableData()
}, },
methods: { methods: {
async load(tree, treeNode, resolve) {
const res = await stocks({
productId: tree.proId,
})
let arr = res.map(ele => ele)
console.log(res, '调试1')
console.log(arr, '调试2')
setTimeout(() => {
resolve(arr)
}, 1000);
// resolve([
// {
// id: 31,
// date: '2016-05-01',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1519 弄'
// }, {
// id: 32,
// date: '2016-05-01',
// name: '王小虎',
// address: '上海市普陀区金沙江路 1519 弄'
// }
// ])
},
async excelSuccessUpload(file) { async excelSuccessUpload(file) {
console.log(file); console.log(file);
try { try {
@@ -121,6 +160,7 @@ export default {
const res = await stockdoImport(file) const res = await stockdoImport(file)
this.uploadLoading = false this.uploadLoading = false
this.$notify.success('导入成功') this.$notify.success('导入成功')
this.tableData.list = []
this.getTableData() this.getTableData()
} catch (error) { } catch (error) {
this.dialogVisible = false this.dialogVisible = false
@@ -146,15 +186,45 @@ export default {
}, },
// 状态切换 // 状态切换
async showChange(e, row) { async showChange(e, row) {
try { await stockStateChanges({
await stockStateChange({ "updateKey": 'stock',
proId: row.proId, "updateValue": row.isStock,
isStock: row.isStock "targetId": row.proId,
shopId: localStorage.getItem('shopId')
})
},
// 共享库存
async showChanges(e, row, name, value) {
await stockStateChanges({
"updateKey": value,
"updateValue": row.isDistribute,
"targetId": row[name],
shopId: localStorage.getItem('shopId')
})
},
// 售罄
async showChangess(e, row) {
if (row.hasChildren || row.hasChildren == false) {
await stockStateChanges({
"updateKey": 'pauseSale',
"updateValue": row.isPauseSale,
"targetId": row.proId,
shopId: localStorage.getItem('shopId')
})
} else {
await stockStateChanges({
"updateKey": 'pauseSaleSku',
"updateValue": row.isPauseSale,
"targetId": row.skuId,
shopId: localStorage.getItem('shopId')
}) })
this.getTableData()
} catch (error) {
console.error(error);
} }
}, },
async getTableData() { async getTableData() {
this.tableData.loading = true this.tableData.loading = true
@@ -168,8 +238,18 @@ export default {
shopId: localStorage.getItem('shopId') shopId: localStorage.getItem('shopId')
}) })
this.tableData.loading = false this.tableData.loading = false
this.tableData.list = res.content
this.tableData.total = res.totalElements this.tableData.total = res.totalElements
// 多规格数据处理
res.content.forEach(element => {
if (element.type == '多规格' && element.isDistribute == 0) {
element.hasChildren = true
} else {
element.hasChildren = false
}
});
this.tableData.list = res.content
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
@@ -177,6 +257,7 @@ export default {
// 分页回调 // 分页回调
paginationChange(e) { paginationChange(e) {
this.tableData.page = e - 1 this.tableData.page = e - 1
this.tableData.list = []
this.getTableData() this.getTableData()
}, },
// 重置查询 // 重置查询
@@ -185,6 +266,7 @@ export default {
this.query.num = '' this.query.num = ''
this.query.isStock = '' this.query.isStock = ''
this.tableData.page = 0; this.tableData.page = 0;
this.tableData.list = []
this.getTableData() this.getTableData()
} }
} }
@@ -223,3 +305,9 @@ export default {
} }
} }
</style> </style>
<style>
.cell {
display: flex;
align-items: center;
}
</style>