Skip to content

Commit

Permalink
添加商品库存批量编辑
Browse files Browse the repository at this point in the history
  • Loading branch information
zhh committed Jun 7, 2018
1 parent 61cf19f commit 98688dc
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/api/skuStock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import request from '@/utils/request'
export function fetchList(pid,params) {
return request({
url:'/sku/'+pid,
method:'get',
params:params
})
}

export function update(pid,data) {
return request({
url:'/sku/update/'+pid,
method:'post',
data:data
})
}
19 changes: 19 additions & 0 deletions src/views/pms/product/components/ProductAttrDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
style="margin-top: 20px"
@click="handleRefreshProductSkuList">刷新列表
</el-button>
<el-button
type="primary"
style="margin-top: 20px"
@click="handleSyncProductSkuPrice">同步价格
</el-button>
</el-form-item>
<el-form-item label="属性图片:" v-if="hasAttrPic">
<el-card shadow="never" class="cardBg">
Expand Down Expand Up @@ -403,6 +408,20 @@
this.refreshProductSkuList();
});
},
handleSyncProductSkuPrice(){
this.$confirm('将同步第一个sku的价格到所有sku,是否继续', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if(this.value.skuStockList!==null&&this.value.skuStockList.length>0){
let price=this.value.skuStockList[0].price;
for(let i=0;i<this.value.skuStockList.length;i++){
this.value.skuStockList[i].price=price;
}
}
});
},
refreshProductSkuList() {
this.value.skuStockList = [];
let skuList = this.value.skuStockList;
Expand Down
7 changes: 7 additions & 0 deletions src/views/pms/product/components/ProductDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@
showStatus: [true, false, false, false]
}
},
created(){
if(this.isEdit){
getProduct(this.$route.query.id).then(response=>{
this.productParam=response.data;
});
}
},
methods: {
hideAll() {
for (let i = 0; i < this.showStatus.length; i++) {
Expand Down
31 changes: 21 additions & 10 deletions src/views/pms/product/components/ProductInfoDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<el-input v-model="value.weight" style="width: 300px"></el-input>
<span style="margin-left: 20px">克</span>
</el-form-item>
<el-form-item label="排序">
<el-input v-model="value.sort"></el-input>
</el-form-item>
<el-form-item style="text-align: center">
<el-button type="primary" size="medium" @click="handleNext('productInfoForm')">下一步,填写商品促销</el-button>
</el-form-item>
Expand All @@ -75,6 +78,7 @@
},
data() {
return {
hasEditCreated:false,
//选中商品分类的值
selectProductCateValue: [],
productCateOptions: [],
Expand All @@ -93,13 +97,22 @@
};
},
created() {
if(this.isEdit){
this.handleEditCreated();
}
this.getProductCateList();
this.getBrandList();
},
computed:{
//商品的编号
productId(){
return this.value.id;
}
},
watch: {
productId:function(newValue){
if(!this.isEdit)return;
if(this.hasEditCreated)return;
if(newValue===undefined||newValue==null||newValue===0)return;
this.handleEditCreated();
},
selectProductCateValue: function (newValue) {
if (newValue != null && newValue.length === 2) {
this.value.productCategoryId = newValue[1];
Expand All @@ -111,13 +124,11 @@
methods: {
//处理编辑逻辑
handleEditCreated(){
getProduct(this.$route.query.id).then(response=>{
if(response.data.productCategoryId!=null){
this.selectProductCateValue.push(response.data.cateParentId);
this.selectProductCateValue.push(response.data.productCategoryId);
}
this.$emit('input',response.data);
});
if(this.value.productCategoryId!=null){
this.selectProductCateValue.push(this.value.cateParentId);
this.selectProductCateValue.push(this.value.productCategoryId);
}
this.hasEditCreated=true;
},
getProductCateList() {
fetchListWithChildren().then(response => {
Expand Down
2 changes: 1 addition & 1 deletion src/views/pms/product/components/ProductSaleDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</el-switch>
<span style="margin-left: 10px;margin-right: 10px">推荐</span>
<el-switch
v-model="value.recommendStatus"
v-model="value.recommandStatus"
:active-value="1"
:inactive-value="0">
</el-switch>
Expand Down
122 changes: 121 additions & 1 deletion src/views/pms/product/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
</el-table-column>
<el-table-column label="SKU库存" width="100" align="center">
<template slot-scope="scope">
<el-button type="primary" icon="el-icon-edit" circle></el-button>
<el-button type="primary" icon="el-icon-edit" @click="handleShowSkuEditDialog(scope.$index, scope.row)" circle></el-button>
</template>
</el-table-column>
<el-table-column label="销量" width="100" align="center">
Expand Down Expand Up @@ -211,6 +211,64 @@
:total="total">
</el-pagination>
</div>
<el-dialog
title="编辑货品信息"
:visible.sync="editSkuInfo.dialogVisible"
width="40%">
<span>商品货号:</span>
<span>{{editSkuInfo.productName}}</span>
<el-input placeholder="按sku编号搜索" v-model="editSkuInfo.keyword" size="small" style="width: 50%;margin-left: 20px">
<el-button slot="append" icon="el-icon-search" @click="handleSearchEditSku"></el-button>
</el-input>
<el-table style="width: 100%;margin-top: 20px"
:data="editSkuInfo.stockList"
border>
<el-table-column
label="SKU编号"
align="center">
<template slot-scope="scope">
<el-input v-model="scope.row.skuCode"></el-input>
</template>
</el-table-column>
<el-table-column
v-for="(item,index) in editSkuInfo.productAttr"
:label="item.name"
:key="item.id"
align="center">
<template slot-scope="scope">
{{getProductSkuSp(scope.row,index)}}
</template>
</el-table-column>
<el-table-column
label="销售价格"
width="80"
align="center">
<template slot-scope="scope">
<el-input v-model="scope.row.price"></el-input>
</template>
</el-table-column>
<el-table-column
label="商品库存"
width="80"
align="center">
<template slot-scope="scope">
<el-input v-model="scope.row.stock"></el-input>
</template>
</el-table-column>
<el-table-column
label="库存预警值"
width="100"
align="center">
<template slot-scope="scope">
<el-input v-model="scope.row.lowStock"></el-input>
</template>
</el-table-column>
</el-table>
<span slot="footer" class="dialog-footer">
<el-button @click="editSkuInfo.dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="handleEditSkuConfirm">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
Expand All @@ -221,6 +279,8 @@
updateRecommendStatus,
updatePublishStatus
} from '@/api/product'
import {fetchList as fetchSkuStockList,update as updateSkuStockList} from '@/api/skuStock'
import {fetchList as fetchProductAttrList} from '@/api/productAttr'
import {fetchList as fetchBrandList} from '@/api/brand'
import {fetchListWithChildren} from '@/api/productCate'
Expand All @@ -238,6 +298,15 @@
name: "productList",
data() {
return {
editSkuInfo:{
dialogVisible:false,
productId:null,
productName:'',
productAttributeCategoryId:null,
stockList:[],
productAttr:[],
keyword:null
},
operates: [
{
label: "商品上架",
Expand Down Expand Up @@ -322,6 +391,15 @@
}
},
methods: {
getProductSkuSp(row, index) {
if (index === 0) {
return row.sp1;
} else if (index === 1) {
return row.sp2;
} else {
return row.sp3;
}
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
Expand Down Expand Up @@ -354,6 +432,48 @@
}
});
},
handleShowSkuEditDialog(index,row){
this.editSkuInfo.dialogVisible=true;
this.editSkuInfo.productId=row.id;
this.editSkuInfo.productName=row.name;
this.editSkuInfo.productAttributeCategoryId = row.productAttributeCategoryId;
this.editSkuInfo.keyword=null;
fetchSkuStockList(row.id,{keyword:this.editSkuInfo.keyword}).then(response=>{
this.editSkuInfo.stockList=response.data;
});
fetchProductAttrList(row.productAttributeCategoryId,{type:0}).then(response=>{
this.editSkuInfo.productAttr=response.data.list;
});
},
handleSearchEditSku(){
fetchSkuStockList(this.editSkuInfo.productId,{keyword:this.editSkuInfo.keyword}).then(response=>{
this.editSkuInfo.stockList=response.data;
});
},
handleEditSkuConfirm(){
if(this.editSkuInfo.stockList==null||this.editSkuInfo.stockList.length<=0){
this.$message({
message: '暂无sku信息',
type: 'warning',
duration: 1000
});
return
}
this.$confirm('是否要进行修改', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(()=>{
updateSkuStockList(this.editSkuInfo.productId,this.editSkuInfo.stockList).then(response=>{
this.$message({
message: '修改成功',
type: 'success',
duration: 1000
});
this.editSkuInfo.dialogVisible=false;
});
});
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
Expand Down

0 comments on commit 98688dc

Please sign in to comment.