商品库存功能优化

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) {
return request({
url: `/api/stock`,
url: `/api/stock/v2`,
method: "get",
params
});
}
// 库存列表子集列表
export function stocks(params) {
return request({
url: `/api/stock/sku`,
method: "get",
params
});
}
/**
* 导出数据
* @returns
*/
export function stockdownload(data) {
return request({
url: "/api/stock/download",
url: "/api/stock/download/v2",
method: "post",
data: {
shopId: localStorage.getItem("shopId"),
@ -194,7 +201,7 @@ export function stockdoImport(file) {
formData.append("file", file);
formData.append("shopId", localStorage.getItem("shopId"));
return request({
url: "/api/stock/doImport",
url: "/api/stock/doImport/v2",
method: "post",
data: formData,
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 class="head-container">
<el-table :data="tableData.list" v-loading="tableData.loading">
<el-table-column label="商品信息">
<el-table :data="tableData.list" v-loading="tableData.loading" row-key="id" lazy :load="load"
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
<el-table-column label="商品信息" width="200px">
<template v-slot="scope">
<div class="shop_info">
<el-image :src="scope.row.img" class="cover">
@ -43,22 +44,35 @@
</el-table-column>
<el-table-column label="规格" prop="number">
<template v-slot="scope">
{{scope.row.specSnap }}
{{ scope.row.specSnap }}
</template>
</el-table-column>
<el-table-column label="库存" prop="number">
<template v-slot="scope">
{{ `${scope.row.number} ${scope.row.unitName}` }}
{{ `${scope.row.stockNumber} ${scope.row.unitName}` }}
</template>
</el-table-column>
<el-table-column label="库存开关">
<template v-slot="scope">
<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>
</template>
</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">
<el-button type="text" size="mini"
@click="$refs.invoicingDetail.show(scope.row)">库存记录</el-button>
@ -79,7 +93,7 @@
</template>
<script>
import { stock, stockdownload, stockdoImport, stockStateChange } from '@/api/invoicing'
import { stock, stockdownload, stockdoImport, stockStateChange, stockStateChanges, stocks } from '@/api/invoicing'
import settings from '@/settings'
import invoicingDetail from './components/invoicingDetail'
import UploadExcel from '@/components/UploadExcel/'
@ -113,6 +127,31 @@ export default {
this.getTableData()
},
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) {
console.log(file);
try {
@ -121,6 +160,7 @@ export default {
const res = await stockdoImport(file)
this.uploadLoading = false
this.$notify.success('导入成功')
this.tableData.list = []
this.getTableData()
} catch (error) {
this.dialogVisible = false
@ -146,15 +186,45 @@ export default {
},
//
async showChange(e, row) {
try {
await stockStateChange({
proId: row.proId,
isStock: row.isStock
await stockStateChanges({
"updateKey": 'stock',
"updateValue": 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() {
this.tableData.loading = true
@ -168,8 +238,18 @@ export default {
shopId: localStorage.getItem('shopId')
})
this.tableData.loading = false
this.tableData.list = res.content
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) {
console.log(error);
}
@ -177,6 +257,7 @@ export default {
//
paginationChange(e) {
this.tableData.page = e - 1
this.tableData.list = []
this.getTableData()
},
//
@ -185,6 +266,7 @@ export default {
this.query.num = ''
this.query.isStock = ''
this.tableData.page = 0;
this.tableData.list = []
this.getTableData()
}
}
@ -222,4 +304,10 @@ export default {
gap: 10px;
}
}
</style>
<style>
.cell {
display: flex;
align-items: center;
}
</style>