yshop1.7发布,后台升級eladmin2.4(前端,后台权限,代码生成器等重构),修复商品分类等一些问题
This commit is contained in:
@ -1,89 +1,96 @@
|
||||
<template>
|
||||
<el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="title" width="900px">
|
||||
<el-form ref="form" :model="form" :inline="true" :rules="rules" label-width="80px" v-show="hidden == false">
|
||||
<el-form-item label="规则名称" >
|
||||
<el-form v-show="hidden == false" ref="form" :model="form" :inline="true" :rules="rules" label-width="80px">
|
||||
<el-form-item label="规则名称">
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="10"><el-button type="primary" @click="hiddenBool" >添加新规则</el-button></el-col>
|
||||
<el-col :span="10"><el-button type="primary" @click="hiddenBool">添加新规则</el-button></el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px" v-show="hidden == true">
|
||||
<el-form-item label="规则名称" >
|
||||
<el-form v-show="hidden == true" ref="form" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="规则名称">
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="5" style="position: relative;margin-right: 6px"
|
||||
v-for="(item, index) in items"
|
||||
:key="index">
|
||||
<el-col
|
||||
v-for="(item, index) in items"
|
||||
:key="index"
|
||||
:span="5"
|
||||
style="position: relative;margin-right: 6px"
|
||||
>
|
||||
<el-input v-model="item.value" style="width: 150px;" placeholder="设置名称" />
|
||||
<el-button type="text" style="position: absolute;top:-6px;right:17px;margin-top:1px;border: none;font-size: 14px;font-weight:bold;line-height: 1.8" @click="handleRemove(index)" icon="el-icon-close" v-show="item.attrHidden == true" />
|
||||
<el-button type="text" style="position: absolute;top:-6px;right:17px;margin-top:1px;border: none;font-size: 14px;font-weight:bold;line-height: 1.8" @click="attrHiddenBool(item)" icon="el-icon-check" v-show="item.attrHidden == false" />
|
||||
<el-button v-show="item.attrHidden == true" type="text" style="position: absolute;top:-6px;right:17px;margin-top:1px;border: none;font-size: 14px;font-weight:bold;line-height: 1.8" icon="el-icon-close" @click="handleRemove(index)" />
|
||||
<el-button v-show="item.attrHidden == false" type="text" style="position: absolute;top:-6px;right:17px;margin-top:1px;border: none;font-size: 14px;font-weight:bold;line-height: 1.8" icon="el-icon-check" @click="attrHiddenBool(item)" />
|
||||
</el-col>
|
||||
<el-col :span="5"><el-button type="primary" @click="handleAdd" >添加新规则</el-button></el-col>
|
||||
<el-col :span="5"><el-button type="primary" @click="handleAdd">添加新规则</el-button></el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
<el-form-item v-show="item.attrHidden == true"
|
||||
v-for="(item, index) in items"
|
||||
:key="index"
|
||||
:label="''+item.value+':'" >
|
||||
<el-form-item
|
||||
v-for="(item, index) in items"
|
||||
v-show="item.attrHidden == true"
|
||||
:key="index"
|
||||
:label="''+item.value+':'"
|
||||
>
|
||||
<el-row :gutter="13">
|
||||
<el-col :span="3"
|
||||
v-for="(attr,k) in item.detail"
|
||||
:key="attr"
|
||||
:name="attr">
|
||||
<el-tag @on-close="attrRemove(item,k)" closable>{{ attr }}</el-tag>
|
||||
<el-col
|
||||
v-for="(attr,k) in item.detail"
|
||||
:key="attr"
|
||||
:span="3"
|
||||
:name="attr"
|
||||
>
|
||||
<el-tag closable @on-close="attrRemove(item,k)">{{ attr }}</el-tag>
|
||||
</el-col>
|
||||
<el-col :span="5">
|
||||
<el-input v-model="item.detailValue" style="width: 150px;" placeholder="设置属性" />
|
||||
</el-col>
|
||||
<el-col :span="5">
|
||||
<el-button type="primary" @click="attrAdd(item)" >添加</el-button>
|
||||
<el-button type="primary" @click="attrAdd(item)">添加</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
<el-form-item v-show="hidden == true" >
|
||||
<el-form-item v-show="hidden == true">
|
||||
<el-row :gutter="24">
|
||||
<el-col :span="24"><el-button :loading="loading" type="primary" @click="addGoods(true)">生成</el-button></el-col>
|
||||
<el-col :span="24"><el-button :loading="loading" type="primary" @click="addGoods(true)">生成</el-button></el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
|
||||
<template v-if="items[0].value!='' && items[0].detail.length>0 && attrs.length">
|
||||
<template v-for="(attr,index) in attrs">
|
||||
<el-form-item>
|
||||
<el-row :gutter="24">
|
||||
<el-row :gutter="24">
|
||||
<template v-for="(item,index) in attr.detail">
|
||||
<el-col :span="3" style="margin-right: 2px">
|
||||
{{index}}:{{item}}
|
||||
{{ index }}:{{ item }}
|
||||
</el-col>
|
||||
</template>
|
||||
<el-col :span="4">
|
||||
<span :class="attr.check ? 'check':''">金额:</span>
|
||||
<el-input placeholder="金额" v-model="attr.price" style="width: 60%" :number="true" />
|
||||
</el-col>
|
||||
<el-input v-model="attr.price" placeholder="金额" style="width: 60%" :number="true" />
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<span :class="attr.check ? 'check':''">库存:</span>
|
||||
<el-input placeholder="库存" v-model="attr.sales" style="width: 60%" :number="true" />
|
||||
</el-col>
|
||||
<el-input v-model="attr.sales" placeholder="库存" style="width: 60%" :number="true" />
|
||||
</el-col>
|
||||
<el-col :span="5">
|
||||
<span :class="attr.check ? 'check':''">成本价:</span>
|
||||
<el-input placeholder="成本价" v-model="attr.cost" style="width: 60%" :number="true" />
|
||||
</el-col>
|
||||
<el-col :span="3" style="margin-right: 2px">
|
||||
<el-input v-model="attr.cost" placeholder="成本价" style="width: 60%" :number="true" />
|
||||
</el-col>
|
||||
<el-col :span="3" style="margin-right: 2px">
|
||||
<div class="demo-upload">
|
||||
<!--<img :src="attr.pic">-->
|
||||
<pic-upload-two v-model="attr.pic" />
|
||||
</div>
|
||||
</el-col>
|
||||
</el-col>
|
||||
<el-col :span="2" style="margin-right: 3px">
|
||||
<el-button type="primary" @click="removeGoods(index)" >删除</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-button type="primary" @click="removeGoods(index)">删除</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
</template>
|
||||
<el-form-item>
|
||||
<el-row :gutter="24">
|
||||
<el-col :span="2" >
|
||||
<el-col :span="2">
|
||||
<el-button type="primary" :loading="loading" @click="submit">提交</el-button>
|
||||
</el-col>
|
||||
<el-col :span="2" >
|
||||
<el-col :span="2">
|
||||
<el-button type="error" @click="clear">清空所有属性</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@ -96,7 +103,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getCates } from '@/api/yxStoreCategory'
|
||||
import { getCates } from '@/api/yxStoreCategory'
|
||||
import { add, edit, isFormatAttr, setAttr, clearAttr, getAttr } from '@/api/yxStoreProduct'
|
||||
import editor from '../../components/Editor'
|
||||
import picUploadTwo from '@/components/pic-upload-two'
|
||||
@ -114,7 +121,7 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
loading: false, dialog: false, cates: [], title: "规则属性",
|
||||
loading: false, dialog: false, cates: [], title: '规则属性',
|
||||
form: {
|
||||
id: '',
|
||||
merId: '',
|
||||
@ -157,37 +164,44 @@ export default {
|
||||
},
|
||||
items: [{
|
||||
value: '',
|
||||
detailValue:'',
|
||||
attrHidden:false,
|
||||
detail:[]
|
||||
detailValue: '',
|
||||
attrHidden: false,
|
||||
detail: []
|
||||
}],
|
||||
attrs: [],
|
||||
hidden:false,
|
||||
attrHidden:false,
|
||||
submiting :false,
|
||||
hidden: false,
|
||||
attrHidden: false,
|
||||
submiting: false
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// console.log('items'+this.items)
|
||||
// console.log('attrs'+this.attrs)
|
||||
// if(this.items && this.attrs) this.hidden = true;
|
||||
|
||||
// window.changeIMG = (index,pic)=>{
|
||||
// _vm.setAttrPic(index,pic);
|
||||
// };
|
||||
},
|
||||
methods: {
|
||||
getAttrs(id) {
|
||||
getAttr(id).then(res=>{
|
||||
console.log('res'+res)
|
||||
//this.items = JSON.parse(res.attr)
|
||||
if(res){
|
||||
getAttr(id).then(res => {
|
||||
console.log('res' + res)
|
||||
// this.items = JSON.parse(res.attr)
|
||||
if (res) {
|
||||
this.hidden = true
|
||||
this.items = res.attr
|
||||
this.attrs = res.value
|
||||
}else{
|
||||
} else {
|
||||
this.hidden = false
|
||||
this.items = [{
|
||||
value: '',
|
||||
detailValue:'',
|
||||
attrHidden:false,
|
||||
detail:[]
|
||||
detailValue: '',
|
||||
attrHidden: false,
|
||||
detail: []
|
||||
}]
|
||||
this.attrs = []
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
},
|
||||
cancel() {
|
||||
@ -271,112 +285,109 @@ export default {
|
||||
soureLink: ''
|
||||
}
|
||||
},
|
||||
setAttrPic(index,pic){
|
||||
this.$set(this.attrs[index],'pic',pic);
|
||||
setAttrPic(index, pic) {
|
||||
this.$set(this.attrs[index], 'pic', pic)
|
||||
},
|
||||
attrHiddenBool(item){
|
||||
if(item.value == ''){
|
||||
Message({message: '请填写规则名称',type: 'error'})
|
||||
}else{
|
||||
item.attrHidden = true;
|
||||
attrHiddenBool(item) {
|
||||
if (item.value == '') {
|
||||
Message({ message: '请填写规则名称', type: 'error' })
|
||||
} else {
|
||||
item.attrHidden = true
|
||||
}
|
||||
},
|
||||
hiddenBool(){
|
||||
this.hidden = true;
|
||||
hiddenBool() {
|
||||
this.hidden = true
|
||||
},
|
||||
handleAdd () {
|
||||
if(!this.checkAttr())return ;
|
||||
handleAdd() {
|
||||
if (!this.checkAttr()) return
|
||||
this.items.push({
|
||||
value: '',
|
||||
detailValue:'',
|
||||
attrHidden:false,
|
||||
detail:[]
|
||||
});
|
||||
detailValue: '',
|
||||
attrHidden: false,
|
||||
detail: []
|
||||
})
|
||||
},
|
||||
checkAttr(){
|
||||
var bool = true;
|
||||
this.items.map(function(item){
|
||||
if(!bool) return;
|
||||
if(!item.value){
|
||||
Message({message: '请填写规则名称',type: 'error'})
|
||||
bool = false;
|
||||
}else if(!item.detail.length){
|
||||
Message({message: '请设置规则属性',type: 'error'})
|
||||
bool = false;
|
||||
checkAttr() {
|
||||
var bool = true
|
||||
this.items.map(function(item) {
|
||||
if (!bool) return
|
||||
if (!item.value) {
|
||||
Message({ message: '请填写规则名称', type: 'error' })
|
||||
bool = false
|
||||
} else if (!item.detail.length) {
|
||||
Message({ message: '请设置规则属性', type: 'error' })
|
||||
bool = false
|
||||
}
|
||||
});
|
||||
return bool;
|
||||
})
|
||||
return bool
|
||||
},
|
||||
attrAdd (item) {
|
||||
if(!item.detailValue) return false;
|
||||
item.detail.push(item.detailValue);
|
||||
item.detailValue = '';
|
||||
attrAdd(item) {
|
||||
if (!item.detailValue) return false
|
||||
item.detail.push(item.detailValue)
|
||||
item.detailValue = ''
|
||||
},
|
||||
handleRemove (index) {
|
||||
if(this.items.length > 1)
|
||||
this.items.splice(index,1);
|
||||
else
|
||||
Message({message: '请设置至少一个规则',type: 'error'})
|
||||
handleRemove(index) {
|
||||
if (this.items.length > 1) { this.items.splice(index, 1) } else { Message({ message: '请设置至少一个规则', type: 'error' }) }
|
||||
},
|
||||
attrRemove(item,k){
|
||||
if(1==item.detail.length){
|
||||
Message({message: '请设置至少一个属性',type: 'error'})
|
||||
return false;
|
||||
attrRemove(item, k) {
|
||||
if (item.detail.length == 1) {
|
||||
Message({ message: '请设置至少一个属性', type: 'error' })
|
||||
return false
|
||||
}
|
||||
item.detail.splice(k,1);
|
||||
item.detail.splice(k, 1)
|
||||
},
|
||||
removeGoods(index){
|
||||
this.attrs.splice(index,1);
|
||||
removeGoods(index) {
|
||||
this.attrs.splice(index, 1)
|
||||
},
|
||||
checkGoods(){
|
||||
var bool = true;
|
||||
this.attrs.map(function(attr){
|
||||
if(!bool) return ;
|
||||
if(!Object.keys(attr.detail).length){
|
||||
Message({message: '请选择至少一个属性',type: 'error'})
|
||||
bool = false;
|
||||
}else if(attr.price != parseFloat(attr.price) || attr.price < 0){
|
||||
Message({message: '请输入正确的商品价格',type: 'error'})
|
||||
bool = false;
|
||||
}else if(attr.sales != parseInt(attr.sales) || attr.sales < 0){
|
||||
Message({message: '请输入正确的商品库存',type: 'error'})
|
||||
bool = false;
|
||||
checkGoods() {
|
||||
var bool = true
|
||||
this.attrs.map(function(attr) {
|
||||
if (!bool) return
|
||||
if (!Object.keys(attr.detail).length) {
|
||||
Message({ message: '请选择至少一个属性', type: 'error' })
|
||||
bool = false
|
||||
} else if (attr.price != parseFloat(attr.price) || attr.price < 0) {
|
||||
Message({ message: '请输入正确的商品价格', type: 'error' })
|
||||
bool = false
|
||||
} else if (attr.sales != parseInt(attr.sales) || attr.sales < 0) {
|
||||
Message({ message: '请输入正确的商品库存', type: 'error' })
|
||||
bool = false
|
||||
}
|
||||
});
|
||||
return bool;
|
||||
})
|
||||
return bool
|
||||
},
|
||||
addGoods(type){
|
||||
if(this.attrs.length){
|
||||
if(!this.checkGoods())return ;
|
||||
addGoods(type) {
|
||||
if (this.attrs.length) {
|
||||
if (!this.checkGoods()) return
|
||||
}
|
||||
var that = this;
|
||||
isFormatAttr(this.form.id,{items:this.items,attrs:this.attrs}).then(res => {
|
||||
var that = this
|
||||
isFormatAttr(this.form.id, { items: this.items, attrs: this.attrs }).then(res => {
|
||||
this.attrs = res
|
||||
}).catch(err => {
|
||||
this.loading = false
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
},
|
||||
submit(){
|
||||
var that = this;
|
||||
that.submiting = true;
|
||||
if(!this.checkAttr() || !this.checkGoods()) return ;
|
||||
for(let attr in that.attrs){
|
||||
that.attrs[attr].check = false;
|
||||
submit() {
|
||||
var that = this
|
||||
that.submiting = true
|
||||
if (!this.checkAttr() || !this.checkGoods()) return
|
||||
for (const attr in that.attrs) {
|
||||
that.attrs[attr].check = false
|
||||
}
|
||||
|
||||
//console.log({items:this.items,attrs:this.attrs})
|
||||
// console.log({items:this.items,attrs:this.attrs})
|
||||
this.loading = false
|
||||
setAttr(this.form.id,{items:this.items,attrs:this.attrs}).then(res => {
|
||||
setAttr(this.form.id, { items: this.items, attrs: this.attrs }).then(res => {
|
||||
this.attrs = res
|
||||
Message({message: '操作成功',type: 'success'})
|
||||
Message({ message: '操作成功', type: 'success' })
|
||||
}).catch(err => {
|
||||
this.loading = false
|
||||
console.log(err.response.data.message)
|
||||
})
|
||||
this.dialog = false
|
||||
},
|
||||
clear(){
|
||||
clear() {
|
||||
this.$confirm(`确定要清空属性数据'}]操作?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
@ -384,22 +395,13 @@ export default {
|
||||
})
|
||||
.then(() => {
|
||||
clearAttr(this.form.id).then(({ data }) => {
|
||||
Message({message: '操作成功',type: 'success'})
|
||||
//this.dialog = false
|
||||
Message({ message: '操作成功', type: 'success' })
|
||||
// this.dialog = false
|
||||
this.getAttrs(this.form.id)
|
||||
})
|
||||
})
|
||||
.catch(() => { })
|
||||
}
|
||||
},
|
||||
mounted (){
|
||||
//console.log('items'+this.items)
|
||||
//console.log('attrs'+this.attrs)
|
||||
//if(this.items && this.attrs) this.hidden = true;
|
||||
|
||||
// window.changeIMG = (index,pic)=>{
|
||||
// _vm.setAttrPic(index,pic);
|
||||
// };
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -424,7 +426,6 @@ export default {
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
.demo-upload-cover{
|
||||
display: block;
|
||||
position: absolute;
|
||||
|
||||
Reference in New Issue
Block a user