平板端快衣店
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.
 
 
 
 
 

458 lines
12 KiB

<template>
<view class="u-wrap">
<!-- <view class="top">
<u-button type="primary" :plain="true" @tap="inputDialogToggle('add')">添加分类</u-button>
</view>
<view class="top">
<ul>
<li v-for="(item, index) in indexList" :key="index">
<view class="name">
{{item.categoryName}}
<view class="rightBox">
<u-icon size="20" name="plus" color="#5fd9ee" @tap="inputDialogToggle('attrAdd',item.id) "></u-icon>
<u-icon size="24" name="edit-pen" color="#5fd9ee" @tap="inputDialogToggle('edit', item) "></u-icon>
<u-icon size="24" name="trash" color="#f56c6c" @tap="delItem(item, 'del')"></u-icon>
</view>
</view>
<view class="attr">
<view class="content" v-for="items in item.attrName" :key="items.id">
<view class="attrName">
{{items.attributeName }}
<u-icon size="16" name="plus" color="#999" @tap="inputDialogToggle('attrValAdd', items.id) "></u-icon>
<u-icon size="20" name="edit-pen" color="#999" @tap="inputDialogToggle('attrEdit', items, item) "></u-icon>
<u-icon size="20" name="trash" color="#999" @tap="delItem(items, 'attrDel')"></u-icon>
</view>
<view class="attrs">
<u-tag :text="itemTag.value" size="mini" closable @close="delItem(itemTag, 'attrNameDel')" class="utag" v-for="(itemTag, index1) in items.attributeValue" :key="index1"></u-tag>
</view>
</view>
</view>
</li>
</ul>
</view> -->
<view>
<button size="default" type="default" @tap="inputDialogToggle('add')" hover-class="is-hover">添加分类</button>
</view>
<view class="card-list">
<ul>
<li v-for="(item, index) in indexList" :key="index">
<view class="name">{{item.categoryName}}</view>
<button class="bj-btn" @tap="inputDialogToggle('edit', item)">编辑</button>
<uni-icons type="forward" size="25"></uni-icons>
</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:'输入分类名'
// type: 'center',
}
},
computed: {
},
onLoad() {
this.getGategoryList()
},
methods: {
getGategoryList() {
this.tui.request("/app/productCategory/list", "get", {
// shopId: 1,
}, false, true).then((res) => {
console.log(res, 'res');
if (res.code == 200) {
this.indexList = res.result;
this.indexList.forEach((item, index) => {
this.tui.request("/app/productAttribute/selectByCategoryId", "get", {
categoryId: item.id
}, false, true).then((res1) => {
if (res1.code == 200) {
item.attrName = res1.result;
if(item.attrName.length > 0 ) {
item.attrName.forEach((items) => {
this.tui.request("/app/productAttributeValue/selectByAttributeId", "get", {
id: items.id
}, false, true).then((res2) => {
if (res2.code == 200) {
items.attributeValue = res2.result;
}
}).catch((res) => {})
})
}
}
}).catch((res) => {})
})
setTimeout(() => {
this.showList = this.indexList;
},1000)
} else {}
}).catch((res) => {})
},
// 获取属性名
getProductAttribute() {
this.indexList.forEach((item, index) => {
this.tui.request("/app/productAttribute/selectByCategoryId", "get", {
categoryId: item.id
}, 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.indexList
}
}).catch((res) => {})
})
}
}
}).catch((res) => {})
})
},
// 获取属性值
getProductAttributeValue(index) {
console.log(index,this.indexList, this.indexList[index].attrName);
this.indexList[index].attrName.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;
}
}).catch((res) => {})
})
this.showList = JSON.parse(JSON.stringify( this.indexList))
console.log(this.showList,'shoeList', index);
},
inputDialogToggle( type, item, parent ) {
this.typeModel = type;
if(type == 'edit') {
this.inputVal = item.categoryName ;
this.editItem = item;
this.$refs.delDialog.open()
}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 = '输入属性值'
}
this.$refs.inputDialog.open()
} else if ( type == 'attrEdit') {
this.inputVal = item.attributeName ;
this.editItem = item;
}
},
dialogInputConfirm(e) {
switch (this.typeModel) {
case 'add':
this.tui.request("/app/productCategory/save", "post", {
categoryName: e
}, false, true).then((res) => {
console.log(res, '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) => {
console.log(res, '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) => {
console.log(res, '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) => {
console.log(res, '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) => {
console.log(res, '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;
.top {
line-height: 70rpx;
margin: 20rpx 0;
padding: 0 20rpx;
background-color: #fff;
.u-collapse-content {
.icon {
display: flex;
float: right;
.u-icon {
flex: 1;
}
}
}
.name {
font-size: 14px;
.rightBox {
display: flex;
float: right;
}
}
.attr {
line-height: 28px;
margin-left: 20rpx;
.attrName {
color: #767a82;
font-size: 12px;
display: flex;
box-sizing: border-box;
width: 100%;
margin-top: 20rpx;
}
.attrs {
margin-left: 20rpx;
.u-tag-wrapper {
width: 20%;
}
}
}
}
}
button{
color:#ffffff;
background:#5fd9ee;
width: 90%;
margin-top:20upx;
}
.card-list{
width: 95%;
border-radius: 10upx;
background: #fff;
height: auto;
margin: 20upx auto;
}
.card-list ul{
}
.card-list li{
width: 95%;
height: 100rpx;
line-height: 100rpx;
padding-left: 20rpx;
font-size: 37rpx;
border-bottom: 0.5px solid #eee;
margin: 0 auto;
}
.bj-btn{
width: 95rpx;
height: 60rpx;
font-size: 26rpx;
background: red;
margin: 0;
margin: 20rpx;
float: left;
padding: 0;
line-height: 60rpx;
}
.name{
width: 70%;
float: left;
}
.data-v-5ff5d986{
}
</style>