分类删除 ; spu添加页 sku组删除按钮及功能

This commit is contained in:
szdot 2023-11-05 06:54:40 +08:00
parent c498272ab6
commit dca6e7f798
5 changed files with 107 additions and 24 deletions

View File

@ -73,9 +73,14 @@ export default {
}, },
watch: { watch: {
categoryList (val) { categoryList (val) {
if (this.defaultPath !== '') { if (this.defaultPath !== '') { //
this.form.path = this.defaultPath this.form.path = 'none'
} }
val.forEach(element => { //
if (element.path === this.defaultPath) {
this.form.path = this.defaultPath
}
})
this.updatePath() this.updatePath()
}, },
shop_id () { // selection selection"" "" shop_id () { // selection selection"" ""
@ -91,9 +96,14 @@ export default {
}, },
created () { created () {
if (this.categoryList.length > 0) { if (this.categoryList.length > 0) {
if (this.defaultPath !== '') { if (this.defaultPath !== '') { //
this.form.path = this.defaultPath this.form.path = 'none'
} }
this.categoryList.forEach(element => { //
if (element.path === this.defaultPath) {
this.form.path = this.defaultPath
}
})
this.updatePath() this.updatePath()
} }
}, },

View File

@ -1,6 +1,6 @@
<template> <template>
<el-transfer class="m-t-20" :titles="['SKU列表', tit]" :filter-method="filterMethod" filterable <el-transfer :titles="['SKU列表', tit]" :filter-method="filterMethod" filterable filter-placeholder="输入编号或名称搜索"
filter-placeholder="输入编号或名称搜索" v-model="value" :data="skuListArr"> v-model="value" :data="skuListArr">
</el-transfer> </el-transfer>
</template> </template>
<script> <script>

View File

@ -602,6 +602,24 @@ const store = new Vuex.Store({
} }
return res return res
}, },
/**
* @description: 删除账号
* @param {*} 多选id组
*/
// eslint-disable-next-line camelcase
async fetchDelCategory ({ dispatch }, form) {
const params = new URLSearchParams()
params.append('delIdArr', form.delIdArr)
params.append('shop_id', form.shop_id)
api.post('delCategory', params, 'Admin').then(res => {
if (res.data.status === 1) {
Message.success(res.data.msg)
dispatch('fetchCategoryList')// 刷新分类列表
} else {
Message.error(res.data.msg)
}
})
},
/** /**
* @description: 获取商品spu列表 * @description: 获取商品spu列表
* @return {*} 列表 * @return {*} 列表
@ -680,8 +698,8 @@ const store = new Vuex.Store({
params.append('spu_number', form.spu_number) params.append('spu_number', form.spu_number)
params.append('sort', form.sort) params.append('sort', form.sort)
params.append('hot', form.hot) params.append('hot', form.hot)
params.append('pro_tag', form.pro_tag) params.append('pro_tag', JSON.stringify(form.pro_tag))
params.append('bind_sku', form.bind_sku) params.append('bind_sku', JSON.stringify(form.bind_sku))
params.append('upFile', form.upFile) params.append('upFile', form.upFile)
if (form.recommend) { if (form.recommend) {
params.append('recommend', '1') params.append('recommend', '1')
@ -716,8 +734,8 @@ const store = new Vuex.Store({
params.append('spu_number', form.spu_number) params.append('spu_number', form.spu_number)
params.append('sort', form.sort) params.append('sort', form.sort)
params.append('hot', form.hot) params.append('hot', form.hot)
params.append('pro_tag', form.pro_tag) params.append('pro_tag', JSON.stringify(form.pro_tag))
params.append('bind_sku', form.bind_sku) params.append('bind_sku', JSON.stringify(form.bind_sku))
params.append('oldFile', form.oldFile) params.append('oldFile', form.oldFile)
params.append('upFile', form.upFile) params.append('upFile', form.upFile)
if (form.recommend) { if (form.recommend) {

View File

@ -32,7 +32,7 @@
<el-button type="text" @click.stop="" @click="openWin(`${data.name} : 编辑`, data)"> <el-button type="text" @click.stop="" @click="openWin(`${data.name} : 编辑`, data)">
编辑 编辑
</el-button> </el-button>
<el-button type="text" @click.stop=""> <el-button type="text" @click.stop="" @click="delCategory(data.id)">
删除 删除
</el-button> </el-button>
</span> </span>
@ -122,6 +122,8 @@ export default {
oldFile: '', oldFile: '',
desc: '' desc: ''
}, },
isStartDel: false,
delIdArr: [],
categoryListData: [], // categoryListData: [], //
winIsShow: false, // winIsShow: false, //
winTitle: ''// winTitle: ''//
@ -229,6 +231,40 @@ export default {
if (res.data.status === 1) { if (res.data.status === 1) {
this.winIsShow = false this.winIsShow = false
} }
},
/**
* @description: 删除分类 及其 子分类
*/
delCategory (id) {
this.$confirm('删除分类及其子分类, 并且旗下的所有商品会被归为"未分类", 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.delIdArr = []// ID
this.findCategoryChildren(this.categoryListData, id)// IDIDdelIdArr
const data = { delIdArr: this.delIdArr, shop_id: this.form.shop_id }
this.$store.dispatch('fetchDelCategory', data)//
}).catch(() => {
this.$message.info('已取消删除')
})
},
// id idid pushthis.delIdArr
findCategoryChildren (data, id) {
//
data.forEach(item => {
// IDID
if (item.id === id) {
this.isStartDel = true
}
if (this.isStartDel) {
this.delIdArr.push(item.id)
}
this.findCategoryChildren(item.children, id)
if (item.id === id) {
this.isStartDel = false
}
})
} }
}, },
watch: { watch: {
@ -240,6 +276,7 @@ export default {
}, },
categoryList () { categoryList () {
this.categoryListData = this.buildTree(this.categoryList) this.categoryListData = this.buildTree(this.categoryList)
console.log(this.categoryListData)
} }
}, },
created () { created () {

View File

@ -42,9 +42,11 @@
@close="handleCloseTag(tag)"> @close="handleCloseTag(tag)">
{{ tag }} {{ tag }}
</el-tag> </el-tag>
<el-input class="input-new-tag" v-if="inputTagVisible" v-model="inputTagValue" ref="saveTagInput" <span class="" v-if="inputTagVisible">
@keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm"> <el-input class="input-new-tag" v-model="inputTagValue" ref="saveTagInput">
</el-input> </el-input>
<el-button type="primary" @click="handleInputConfirm" icon="el-icon-plus">添加</el-button>
</span>
<el-button v-else @click="showTagInput" icon="el-icon-plus">点击添加</el-button> <el-button v-else @click="showTagInput" icon="el-icon-plus">点击添加</el-button>
</el-form-item> </el-form-item>
<!-- 商品图片 --> <!-- 商品图片 -->
@ -64,12 +66,16 @@
</el-form-item> </el-form-item>
<!-- sku组 穿梭框 --> <!-- sku组 穿梭框 -->
<el-form-item label="SKU组"> <el-form-item label="SKU组">
<el-input class="input-new-tag" v-if="inputSkuVisible" v-model="inputSkuValue" ref="saveSkuInput" <span class="" v-if="inputSkuVisible">
@keyup.enter.native="addSkuTransfer" @blur="addSkuTransfer"> <el-input class="input-new-tag" v-model="inputSkuValue" ref="saveSkuInput">
</el-input> </el-input>
<el-button type="primary" @click="addSkuTransfer" icon="el-icon-plus">添加</el-button>
</span>
<el-button v-else @click="showSkuInput" icon="el-icon-plus">添加规格</el-button> <el-button v-else @click="showSkuInput" icon="el-icon-plus">添加规格</el-button>
<SkuTransfer v-for="(t, index) in form.bind_sku" :key="index" :tit="t.tit" :val="t.value" <div class="m-t-10 relative-container" v-for="(t, index) in form.bind_sku" :key="index">
@input="handleTransferInput(index, $event)" /> <SkuTransfer :tit="t.tit" :val="t.value" @input="handleTransferInput(index, $event)" />
<el-button type="danger" icon="el-icon-delete" class="absolute-center-button" @click="delBind_skuArr" />
</div>
</el-form-item> </el-form-item>
<!-- 表单提交 --> <!-- 表单提交 -->
<el-form-item v-if="pageState == 'add' ? true : false"> <el-form-item v-if="pageState == 'add' ? true : false">
@ -158,6 +164,9 @@ export default {
handleTransferInput (index, val) { // input value handleTransferInput (index, val) { // input value
this.form.bind_sku[index].value = val this.form.bind_sku[index].value = val
}, },
delBind_skuArr (index) {
this.form.bind_sku.splice(index, 1)
},
// //
handleCloseTag (tag) { // handleCloseTag (tag) { //
this.form.pro_tag.splice(this.form.pro_tag.indexOf(tag), 1) this.form.pro_tag.splice(this.form.pro_tag.indexOf(tag), 1)
@ -242,8 +251,6 @@ export default {
* @description: 创建新商品spu * @description: 创建新商品spu
*/ */
async addSpu () { async addSpu () {
this.form.pro_tag = JSON.stringify(this.form.pro_tag)
this.form.bind_sku = JSON.stringify(this.form.bind_sku)
const res = await this.$store.dispatch('fetchAddSpu', this.form) const res = await this.$store.dispatch('fetchAddSpu', this.form)
if (res.data.status === 1) { if (res.data.status === 1) {
this.$router.push('/spu/index') this.$router.push('/spu/index')
@ -254,8 +261,6 @@ export default {
*/ */
async saveSpu () { async saveSpu () {
this.form.id = this.spuId this.form.id = this.spuId
this.form.pro_tag = JSON.stringify(this.form.pro_tag)
this.form.bind_sku = JSON.stringify(this.form.bind_sku)
const res = await this.$store.dispatch('fetchSaveSpu', this.form) const res = await this.$store.dispatch('fetchSaveSpu', this.form)
if (res.data.status === 1) { if (res.data.status === 1) {
this.$router.push('/spu/index') this.$router.push('/spu/index')
@ -292,11 +297,24 @@ export default {
} }
.input-new-tag { .input-new-tag {
margin-right: 10px;
width: 20%; width: 20%;
margin-left: 10px;
vertical-align: bottom; vertical-align: bottom;
} }
.relative-container {
position: relative;
width: 585px;
}
.absolute-center-button {
position: absolute;
left: 50%;
transform: translateX(-50%);
margin-top: -130px;
/* 根据按钮高度调整上边距,使按钮垂直居中 */
}
.avatar-uploader .el-upload { .avatar-uploader .el-upload {
border: 1px dashed #d9d9d9; border: 1px dashed #d9d9d9;
border-radius: 6px; border-radius: 6px;