|
|
@@ -90,7 +90,7 @@
|
|
|
<el-button type="primary" size="mini" @click="addFn()">添加</el-button>
|
|
|
</template>
|
|
|
<template #slot-addNew-goods-btn>
|
|
|
- <el-button type="primary" size="mini" @click="addFn()">新增</el-button>
|
|
|
+ <el-button type="primary" size="mini" @click="replaceBtnFn(0)">新增</el-button>
|
|
|
</template>
|
|
|
|
|
|
</x-crud>
|
|
|
@@ -118,7 +118,13 @@
|
|
|
size="small"
|
|
|
></el-input>
|
|
|
</el-form-item>
|
|
|
-
|
|
|
+ <el-form-item label="拼音缩写" prop="py">
|
|
|
+ <el-input
|
|
|
+ v-model="replaceForm.py"
|
|
|
+ placeholder="拼音缩写"
|
|
|
+ size="small"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="别名" prop="alias">
|
|
|
<el-input
|
|
|
v-model="replaceForm.alias"
|
|
|
@@ -147,7 +153,25 @@
|
|
|
>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="大单位" prop="bigUnitId">
|
|
|
+ <el-select v-model="replaceForm.bigUnit" size="small" placeholder="请选择单位" @change="selBigUnitFn">
|
|
|
+ <el-option v-for="(item, index) in unitList" :key="index" :value="item.name" >{{ item.name }}</el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="小单位" prop="smallUnitId">
|
|
|
+ <el-select v-model="replaceForm.smallUnit" size="small" placeholder="请选择单位" @change="selSmallUnitFn">
|
|
|
+ <el-option v-for="(item, index) in unitList" :key="index" :value="item.name" >{{ item.name }}</el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
|
|
|
+ <el-form-item label="单位比" prop="ratio">
|
|
|
+ <el-input
|
|
|
+ v-model="replaceForm.ratio"
|
|
|
+ placeholder="1扎=20支,请输入20"
|
|
|
+ size="small"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="库存预警" prop="stockWarning">
|
|
|
<el-input
|
|
|
v-model="replaceForm.stockWarning"
|
|
|
@@ -230,6 +254,7 @@ export default {
|
|
|
addDialog: false,
|
|
|
replaceForm: {
|
|
|
name: '',
|
|
|
+ py: '',
|
|
|
alias: '',
|
|
|
classId: '',
|
|
|
className: '',
|
|
|
@@ -254,6 +279,18 @@ export default {
|
|
|
required: true,
|
|
|
message: '请选择分类',
|
|
|
},
|
|
|
+ bigUnitId: {
|
|
|
+ required: true,
|
|
|
+ message: '请选择大单位',
|
|
|
+ },
|
|
|
+ smallUnitId: {
|
|
|
+ required: true,
|
|
|
+ message: '请选择小单位',
|
|
|
+ },
|
|
|
+ ratio: {
|
|
|
+ required: true,
|
|
|
+ message: '比例不能为空',
|
|
|
+ },
|
|
|
stockWarning: {
|
|
|
required: true,
|
|
|
message: '最低库存不能为空',
|
|
|
@@ -271,7 +308,9 @@ export default {
|
|
|
message: '重量不能为空',
|
|
|
}
|
|
|
},
|
|
|
- itemClassList: []
|
|
|
+ itemClassList: [],
|
|
|
+ unitList: [],
|
|
|
+ currentItemId: 0
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -319,6 +358,14 @@ export default {
|
|
|
this.itemClassList = res.list;
|
|
|
});
|
|
|
},
|
|
|
+ getAllUnit() {
|
|
|
+ if (!this.$util.isEmpty(this.unitList)) {
|
|
|
+ return this.unitList;
|
|
|
+ }
|
|
|
+ this.$service.unit.getAllUnit().then((res) => {
|
|
|
+ this.unitList = res.list;
|
|
|
+ });
|
|
|
+ },
|
|
|
addFn () {
|
|
|
this.showItemModal = true
|
|
|
},
|
|
|
@@ -326,6 +373,14 @@ export default {
|
|
|
let index = this.itemClassList.findIndex((e) => e.name == val);
|
|
|
this.replaceForm.classId = this.itemClassList[index].id;
|
|
|
},
|
|
|
+ selBigUnitFn(val) {
|
|
|
+ let index = this.unitList.findIndex((e) => e.name == val);
|
|
|
+ this.replaceForm.bigUnitId = this.unitList[index].id;
|
|
|
+ },
|
|
|
+ selSmallUnitFn(val) {
|
|
|
+ let index = this.unitList.findIndex((e) => e.name == val);
|
|
|
+ this.replaceForm.smallUnitId = this.unitList[index].id;
|
|
|
+ },
|
|
|
resetForm() {
|
|
|
this.goodsData = {};
|
|
|
this.$refs['replaceForm'].resetFields();
|
|
|
@@ -336,16 +391,26 @@ export default {
|
|
|
if(this.replaceForm.cover.substr(0,4).toLowerCase() == "http"){
|
|
|
replaceForm.cover = this.replaceForm.shortCover;
|
|
|
}
|
|
|
- this.$refs.replaceForm.validate((valid) => {
|
|
|
- if(valid) {
|
|
|
- this.$service.product.update(replaceForm).then(res => {
|
|
|
- console.log('res1111', res)
|
|
|
- this.$message.success('操作成功!');
|
|
|
- this.addDialog = false
|
|
|
- this.app.refresh()
|
|
|
- }).catch(err => {})
|
|
|
- }
|
|
|
- })
|
|
|
+ this.$refs.replaceForm.validate((valid) => {
|
|
|
+ if(valid) {
|
|
|
+ if (this.currentItemId == 0) {
|
|
|
+ this.$service.product.addProduct(JSON.parse(JSON.stringify(this.replaceForm))).then(res => {
|
|
|
+ this.$message.success('操作成功!');
|
|
|
+ this.addDialog = false
|
|
|
+ this.app.refresh()
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ this.$service.product.update(replaceForm).then(res => {
|
|
|
+ console.log('res1111', res)
|
|
|
+ this.$message.success('操作成功!');
|
|
|
+ this.addDialog = false
|
|
|
+ this.app.refresh()
|
|
|
+ }).catch(err => {})
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
tabClick (tab, e) {
|
|
|
this.app.refresh({ classId: this.classId });
|
|
|
@@ -504,31 +569,83 @@ export default {
|
|
|
this.costWeight = false
|
|
|
},
|
|
|
replaceBtnFn(id) {
|
|
|
+ this.getAllClass()
|
|
|
+ this.getAllUnit()
|
|
|
this.addDialog = true
|
|
|
- this.getAllClass()
|
|
|
- this.$service.product.info({id}).then(res => {
|
|
|
- console.log(res)
|
|
|
- // this.replaceForm.name = res.name
|
|
|
- // this.replaceForm.alias = res.alias
|
|
|
- // this.replaceForm.classId = res.classId
|
|
|
- // this.replaceForm.className = res.classId
|
|
|
- // this.replaceForm.cover = res.cover
|
|
|
- // this.replaceForm.bigUnit = res.bigUnit
|
|
|
- // this.replaceForm.smallUnit = res.smallUnit
|
|
|
- // this.replaceForm.stockWarning = res.stockWarning
|
|
|
- // this.replaceForm.cost = res.cost
|
|
|
- // this.replaceForm.addPrice = res.addPrice
|
|
|
- // this.replaceForm.weight = res.weight
|
|
|
- let index = this.itemClassList.findIndex((e) => e.id == res.classId)
|
|
|
- this.replaceForm = res
|
|
|
- this.replaceForm.className = this.itemClassList[index].name
|
|
|
- console.log(this.replaceForm.cover)
|
|
|
- if(this.replaceForm.cover.indexOf('http') != -1 && this.replaceForm.cover.indexOf('/uploads') != -1) {
|
|
|
- let str = this.replaceForm.cover
|
|
|
- let str1 = str.substring(0, str.indexOf("/uploads"));
|
|
|
- this.replaceForm.cover = str.substring(str1.length+1, str.length);
|
|
|
- }
|
|
|
- })
|
|
|
+ this.currentItemId = id;
|
|
|
+
|
|
|
+ if(id==0){
|
|
|
+ this.replaceFormRules = {};
|
|
|
+ this.replaceForm = {
|
|
|
+ name: '',
|
|
|
+ py: '',
|
|
|
+ alias: '',
|
|
|
+ classId: '',
|
|
|
+ className: '',
|
|
|
+ cover: '',
|
|
|
+ bigUnit: '',
|
|
|
+ smallUnit: '',
|
|
|
+ stockWarning:'',
|
|
|
+ cost:'',
|
|
|
+ addPrice:'',
|
|
|
+ weight:'',
|
|
|
+ };
|
|
|
+ }else{
|
|
|
+ this.replaceFormRules = {
|
|
|
+ name: {
|
|
|
+ required: true,
|
|
|
+ message: '名称不能为空',
|
|
|
+ },
|
|
|
+ cover: {
|
|
|
+ required: true,
|
|
|
+ message: '图片不能为空',
|
|
|
+ },
|
|
|
+ classId: {
|
|
|
+ required: true,
|
|
|
+ message: '请选择分类',
|
|
|
+ },
|
|
|
+ bigUnitId: {
|
|
|
+ required: true,
|
|
|
+ message: '请选择大单位',
|
|
|
+ },
|
|
|
+ smallUnitId: {
|
|
|
+ required: true,
|
|
|
+ message: '请选择小单位',
|
|
|
+ },
|
|
|
+ ratio: {
|
|
|
+ required: true,
|
|
|
+ message: '比例不能为空',
|
|
|
+ },
|
|
|
+ stockWarning: {
|
|
|
+ required: true,
|
|
|
+ message: '最低库存不能为空',
|
|
|
+ },
|
|
|
+ cost: {
|
|
|
+ required: true,
|
|
|
+ message: '运费不能为空',
|
|
|
+ },
|
|
|
+ addPrice: {
|
|
|
+ required: true,
|
|
|
+ message: '加价不能为空',
|
|
|
+ },
|
|
|
+ weight: {
|
|
|
+ required: true,
|
|
|
+ message: '重量不能为空',
|
|
|
+ }
|
|
|
+ };
|
|
|
+ this.$service.product.info({id}).then(res => {
|
|
|
+ let index = this.itemClassList.findIndex((e) => e.id == res.classId)
|
|
|
+ this.replaceForm = res
|
|
|
+ this.replaceForm.className = this.itemClassList[index].name
|
|
|
+ console.log(this.replaceForm.cover)
|
|
|
+ if(this.replaceForm.cover.indexOf('http') != -1 && this.replaceForm.cover.indexOf('/uploads') != -1) {
|
|
|
+ let str = this.replaceForm.cover
|
|
|
+ let str1 = str.substring(0, str.indexOf("/uploads"));
|
|
|
+ this.replaceForm.cover = str.substring(str1.length+1, str.length);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
changeAllSort(e){
|
|
|
console.log(e,'1111');
|