You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
416 lines
10 KiB
416 lines
10 KiB
<template>
|
|
<view class="u-wrap">
|
|
<view>
|
|
<button size="default" type="default" @tap="inputDialogToggle('attrAdd',categoryId)" hover-class="is-hover">添加分类</button>
|
|
</view>
|
|
<view class="card-list">
|
|
<ul>
|
|
<li v-for="items in attrList" :key="items.id">
|
|
<view class="title-fur">
|
|
<view class="name">{{items.attributeName}}</view>
|
|
<view class="rightBox">
|
|
<u-icon size="20" name="plus" color="#5fd9ee" @tap="inputDialogToggle('attrValAdd', items.id) "></u-icon>
|
|
<u-icon size="24" name="edit-pen" color="#5fd9ee" @tap="inputDialogToggle('attrEdit', items, item) "></u-icon>
|
|
<u-icon size="24" name="trash" color="#f56c6c" @tap="delItem(items, 'attrDel')"></u-icon>
|
|
</view>
|
|
</view>
|
|
<view class="content-fur">
|
|
<view class="content-low" v-for="item in items.attributeValue" :key="item.id" @tap="delItem(item, 'attrNameDel')">{{item.value}}</view>
|
|
</view>
|
|
</li>
|
|
</ul>
|
|
</view>
|
|
<u-modal :show="show" :title="'删除'" :content="'是否确认删除此分类?'" showCancelButton="true" @cancel="show = false"
|
|
@confirm="delItemModal"></u-modal>
|
|
<uni-popup ref="inputDialog" type="dialog">
|
|
<uni-popup-dialog ref="inputClose" mode="input" :title="dialogTit" :value="inputVal" placeholder="请输入名称"
|
|
@confirm="dialogInputConfirm" @close="dialogClose">
|
|
</uni-popup-dialog>
|
|
</uni-popup>
|
|
<uni-popup ref="delDialog" type="dialog">
|
|
<uni-popup-dialog ref="inputClose" mode="input" :title="dialogTit" :value="inputVal" placeholder="请输入名称"
|
|
cancelText="删除" @confirm="dialogInputConfirm" @close="dialogDel">
|
|
</uni-popup-dialog>
|
|
</uni-popup>
|
|
</view>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
// indexList: [],
|
|
show: false,
|
|
inputVal: '',
|
|
typeModel: '',
|
|
editItem: {},
|
|
delItems: {},
|
|
isOpenId: '',
|
|
attrList: [],
|
|
openIndex: '',
|
|
delType: '',
|
|
showList: {},
|
|
dialogTit: '输入分类名',
|
|
categoryId:'',
|
|
// type: 'center',
|
|
}
|
|
},
|
|
computed: {
|
|
|
|
},
|
|
onLoad(options) {
|
|
this.categoryId = options.id
|
|
this.getGategoryList(options.id)
|
|
},
|
|
methods: {
|
|
//初始化获取子分类列表
|
|
getGategoryList() {
|
|
this.tui.request("/app/productAttribute/selectByCategoryId", "POST", {
|
|
categoryId: this.categoryId
|
|
}, false, true).then((res1) => {
|
|
if (res1.code == 200) {
|
|
this.attrList = res1.result;
|
|
if (res1.result.length > 0) {
|
|
this.attrList.forEach((items) => {
|
|
|
|
this.tui.request(
|
|
"/app/productAttributeValue/selectByAttributeId",
|
|
"get", {
|
|
id: items.id
|
|
}, false, true).then((res2) => {
|
|
if (res2.code == 200) {
|
|
items.attributeValue = res2.result;
|
|
//
|
|
}else{
|
|
this.tui.toast(res.message)
|
|
}
|
|
|
|
}).catch((res) => {})
|
|
})
|
|
}
|
|
setTimeout(() => {
|
|
this.showList = this.attrList;
|
|
},1000)
|
|
}else{
|
|
this.tui.toast(res.message)
|
|
}
|
|
}).catch((res) => {})
|
|
},
|
|
// 获取属性名
|
|
getProductAttribute() {
|
|
this.attrList.forEach((item, index) => {
|
|
this.tui.request("/app/productAttribute/selectByCategoryId", "get", {
|
|
categoryId: this.categoryId
|
|
}, false, true).then((res) => {
|
|
if (res.code == 200) {
|
|
item.attrName = res.result;
|
|
if (item.attrName.length > 0) {
|
|
item.attrName.forEach((items) => {
|
|
this.tui.request(
|
|
"/app/productAttributeValue/selectByAttributeId",
|
|
"get", {
|
|
id: items.id
|
|
}, false, true).then((res) => {
|
|
if (res.code == 200) {
|
|
items.attributeValue = res.result;
|
|
this.showList = this.attrList
|
|
}else{
|
|
this.tui.toast(res.message)
|
|
}
|
|
}).catch((res) => {})
|
|
})
|
|
}
|
|
}else{
|
|
this.tui.toast(res.message)
|
|
}
|
|
}).catch((res) => {})
|
|
})
|
|
},
|
|
// 获取属性值
|
|
getProductAttributeValue(index) {
|
|
|
|
this.attrList.forEach((item) => {
|
|
this.tui.request("/app/productAttributeValue/selectByAttributeId", "get", {
|
|
id: item.id
|
|
}, false, true).then((res) => {
|
|
if (res.code == 200) {
|
|
item.attributeValue = res.result;
|
|
// item.attributeValue = res.result;
|
|
}else{
|
|
this.tui.toast(res.message)
|
|
}
|
|
}).catch((res) => {})
|
|
})
|
|
this.showList = JSON.parse(JSON.stringify(this.attrList))
|
|
|
|
},
|
|
inputDialogToggle(type, item, parent) {
|
|
this.typeModel = type;
|
|
if(type == 'edit') {
|
|
this.inputVal = item.categoryName ;
|
|
this.editItem = item;
|
|
}else if ( type == 'add' || type == 'attrAdd' || type == 'attrValAdd') {
|
|
this.inputVal = '';
|
|
this.isOpenId = item;
|
|
if(type == 'add') {
|
|
this.dialogTit = '输入分类名'
|
|
} else if(type == 'attrAdd') {
|
|
this.dialogTit = '输入属性名'
|
|
} else if(type == 'attrValAdd') {
|
|
this.dialogTit = '输入属性值'
|
|
}
|
|
} else if ( type == 'attrEdit') {
|
|
this.inputVal = item.attributeName ;
|
|
this.editItem = item;
|
|
}
|
|
this.$refs.inputDialog.open()
|
|
},
|
|
dialogInputConfirm(e) {
|
|
switch (this.typeModel) {
|
|
case 'add':
|
|
this.tui.request("/app/productCategory/save", "post", {
|
|
categoryName: e
|
|
}, false, true).then((res) => {
|
|
|
|
if (res.code == 200) {
|
|
this.getGategoryList()
|
|
uni.showToast({
|
|
title:"添加成功",
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title:"添加失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
|
|
}).catch((res) => {})
|
|
break;
|
|
case 'edit':
|
|
this.tui.request("/app/productCategory/edit", "post", {
|
|
categoryName: e,
|
|
id: this.editItem.id
|
|
}, false, true).then((res) => {
|
|
if (res.code == 200) {
|
|
this.getGategoryList()
|
|
uni.showToast({
|
|
title:"修改成功",
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title:"修改失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}).catch((res) => {})
|
|
break;
|
|
case 'attrAdd':
|
|
this.tui.request("/app/productAttribute/save", "post", {
|
|
attributeName: e,
|
|
categoryId: this.isOpenId
|
|
}, false, true).then((res) => {
|
|
if (res.code == 200) {
|
|
this.getGategoryList()
|
|
uni.showToast({
|
|
title:"添加成功",
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title:"添加失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}).catch((res) => {})
|
|
break;
|
|
case 'attrValAdd':
|
|
this.tui.request("/app/productAttributeValue/save", "post", {
|
|
value: e,
|
|
attributeId: this.isOpenId
|
|
}, false, true).then((res) => {
|
|
if (res.code == 200) {
|
|
this.getGategoryList()
|
|
uni.showToast({
|
|
title:"添加成功",
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title:"添加失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}).catch((res) => {})
|
|
break;
|
|
case 'attrEdit':
|
|
this.tui.request("/app/productAttribute/edit", "post", {
|
|
attributeName: e,
|
|
categoryId: this.editItem.categoryId,
|
|
id: this.editItem.id
|
|
}, false, true).then((res) => {
|
|
|
|
if (res.code == 200) {
|
|
this.getGategoryList()
|
|
uni.showToast({
|
|
title:"修改成功",
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title:"修改失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}).catch((res) => {})
|
|
break;
|
|
default:
|
|
}
|
|
this.$refs.inputClose.val=''
|
|
},
|
|
dialogClose() {
|
|
this.inputVal = '';
|
|
this.$refs.inputClose.val = ''
|
|
},
|
|
dialogDel() {
|
|
this.delItem(this.editItem, 'del')
|
|
},
|
|
delItemModal() {
|
|
this.show = false;
|
|
if (this.delType == 'del') {
|
|
this.tui.request("/app/productCategory/delById", "post", {
|
|
id: this.delItems.id,
|
|
}, false, true).then((res) => {
|
|
|
|
if (res.code == 200) {
|
|
this.getGategoryList()
|
|
uni.showToast({
|
|
title: "删除成功",
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title: "删除失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}).catch((res) => {})
|
|
} else if (this.delType == 'attrDel') {
|
|
this.tui.request("/app/productAttribute/delById", "post", {
|
|
categoryId: this.delItems.categoryId,
|
|
attributeName: this.delItems.attributeName,
|
|
id: this.delItems.id,
|
|
}, false, true).then((res) => {
|
|
|
|
if (res.code == 200) {
|
|
this.getGategoryList()
|
|
uni.showToast({
|
|
title: "删除成功",
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title: "删除失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}).catch((res) => {})
|
|
} else if (this.delType == 'attrNameDel') {
|
|
this.tui.request("/app/productAttributeValue/delById", "post", {
|
|
attributeId: this.delItems.attributeId,
|
|
value: this.delItems.value,
|
|
id: this.delItems.id,
|
|
}, false, true).then((res) => {
|
|
|
|
if (res.code == 200) {
|
|
this.getGategoryList()
|
|
uni.showToast({
|
|
title: "删除成功",
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title: "删除失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}).catch((res) => {})
|
|
}
|
|
},
|
|
delItem(item, type) {
|
|
this.delType = type;
|
|
this.delItems = item;
|
|
this.show = true;
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.u-wrap {
|
|
height: calc(100vh);
|
|
/* #ifdef H5 */
|
|
height: calc(100vh - var(--window-top));
|
|
/* #endif */
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
button {
|
|
color: #ffffff;
|
|
background: #5fd9ee;
|
|
width: 90%;
|
|
margin-top: 20upx;
|
|
}
|
|
|
|
.card-list {
|
|
width: 95%;
|
|
border-radius: 10upx;
|
|
background: #fff;
|
|
height: auto;
|
|
margin: 20upx auto;
|
|
|
|
}
|
|
|
|
.title-fur {
|
|
width: 95%;
|
|
height: 70rpx;
|
|
margin: 0 auto;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
|
|
.name {
|
|
font-size: 30rpx;
|
|
width: 50%;
|
|
float: left;
|
|
height: 70rpx;
|
|
line-height: 70rpx;
|
|
}
|
|
|
|
.rightBox {
|
|
display: flex;
|
|
float: right;
|
|
}
|
|
|
|
.content-fur {
|
|
padding-bottom: 25rpx;
|
|
}
|
|
|
|
.content-low {
|
|
width: auto;
|
|
border: 1px solid #eee;
|
|
display: inline-block;
|
|
min-width: 90rpx;
|
|
padding: 5rpx;
|
|
font-size: 35rpx;
|
|
text-align: center;
|
|
color: #777;
|
|
margin: 20rpx 0 0 20rpx;
|
|
}
|
|
|
|
.content-low:hover {
|
|
background: #eee;
|
|
}
|
|
</style>
|