Commit bc42d6cb by zhangquan

分类联调

1 parent 6858f05d
import { http } from '@/main'
const url = 'rop-scrm-shopmall/router'
const addCategoryApi = params => {
params.method = 'scrm.api.shopmall.discover.category.insert.or.update'
return http({
url,
method: 'post',
data: params,
sign: true
})
}
const getCategoryListApi = params => {
if(params.categoryLevel == 2 && !params.parentCategoryId){
return new Promise((resolve, reject)=>{
reject()
})
}
console.log(params, '8888')
params.method = 'scrm.api.shopmall.discover.category.page'
return http({
url,
method: 'post',
data: params,
sign: true
})
}
const delCategoryApi = params => {
params.method = 'scrm.api.shopmall.discover.category.delete'
return http({
url,
method: 'post',
data: params,
sign: true
})
}
const batchAddCategoryApi = params => {
params.method = 'scrm.api.shopmall.discover.category.insert.batch'
return http({
url,
method: 'post',
data: params,
sign: true
})
}
export default {
addCategoryApi,
getCategoryListApi,
delCategoryApi,
batchAddCategoryApi
}
\ No newline at end of file \ No newline at end of file
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
<div class="global-title">新增二级分类</div> <div class="global-title">新增二级分类</div>
<glsx-combi-form :isInline="false" class="glsx-combi-form" ref="baseInfoRef" labelWidth="154px" defaultWidth="432px" :formObj.sync="formObj" :formData="formData" :formRules="myRule"> <glsx-combi-form :isInline="false" class="glsx-combi-form" ref="baseInfoRef" labelWidth="154px" defaultWidth="432px" :formObj.sync="formObj" :formData="formData" :formRules="myRule">
<div slot="mainCategorySlot"> <div slot="mainCategorySlot">
座椅 {{routeInfo.parentCategoryName}}
</div> </div>
<div slot="secondCategorySlot" class="category-slot"> <div slot="secondCategorySlot" class="category-slot">
<div class="category-item"> <div class="category-item" v-for="(item,index) in categoryList" :key="index">
<el-input maxLength="15" v-model="configName" class="input"></el-input> <el-input placeholder="请输入" maxLength="15" v-model="item.name" class="input"></el-input>
<i class="el-icon-delete del-icon"></i> <i v-if="categoryList.length>1" class="el-icon-delete del-icon" @click="delSecondCategory(index)"></i>
</div> </div>
<div class="add-btn" @click="addCondition('conditionList')"> <div v-if="!routeInfo.id" class="add-btn" @click="addCategory()">
<i class="el-icon-circle-plus-outline"></i> <i class="el-icon-circle-plus-outline"></i>
新增二级分类 新增二级分类
</div> </div>
...@@ -38,8 +38,23 @@ export default { ...@@ -38,8 +38,23 @@ export default {
videoCoverArr: [] videoCoverArr: []
}, },
myRule:{ myRule:{
mainCategory: [{ required: true, message: '请输入一级分类', trigger: 'change' }], mainCategory: [{ required: true,validator: (rule, value, callback) => {
secondCategory: [{ required: true, message: '请添加二级分类名称', trigger: 'change' }], if(!this.routeInfo.parentCategoryId) {
callback(new Error(`缺失一级分类ID`))
}else if(!this.routeInfo.categoryType){
callback(new Error(`缺失频道ID`))
}else{
callback()
}
}, trigger: 'change' }],
secondCategory: [{ required: true, validator: (rule, value, callback) => {
const _target = this.categoryList.find(item => !item.name)
if(_target) {
callback(new Error(`请输入二级分类`))
}else{
callback()
}
}, trigger: 'change' }],
}, },
formData:[ formData:[
{ {
...@@ -53,9 +68,68 @@ export default { ...@@ -53,9 +68,68 @@ export default {
addHtml: 'secondCategorySlot' addHtml: 'secondCategorySlot'
} }
], ],
categoryList: []
} }
}, },
created(){
const urlParam = this.$route.params
this.routeInfo = JSON.parse(decodeURIComponent(urlParam.id))
const { id, name } = this.routeInfo
this.categoryList = [{id: id || '', name: name || ''}]
},
methods:{ methods:{
addCategory(){
const _target = this.categoryList.find(item => !item.name)
if(_target) return this.$message.error('请输入二级分类')
this.categoryList.push({id: '', name: ''})
},
delSecondCategory(index){
this.categoryList.splice(index, 1)
},
handleSave(){
this.$refs.baseInfoRef.$refs.formRef.validate(valid => {
if(valid){
if(this.routeInfo.id){
this.editCategory()
}else{
this.batchAddCategory()
}
}
})
},
batchAddCategory(){
const { categoryType, parentCategoryId } = this.routeInfo
const params = {
categoryType,
parentCategoryId,
categoryNameList: this.categoryList.map(item => item.name)
}
this.$apis.category.batchAddCategoryApi(params).then(res => {
if(res) {
this.$message.success('操作成功')
this.handleCancel()
}
})
},
editCategory(){
const { categoryType, parentCategoryId, id } = this.routeInfo
const params = {
id,
categoryType,
parentCategoryId,
categoryLevel: 2,
categoryName: this.categoryList[0]?.name
}
this.$apis.category.addCategoryApi(params).then(res => {
if(res){
this.$message.success('编辑成功')
this.handleCancel()
}
})
},
handleCancel(){
this.$router.back()
},
} }
} }
</script> </script>
...@@ -67,6 +141,10 @@ export default { ...@@ -67,6 +141,10 @@ export default {
margin-bottom: 16px; margin-bottom: 16px;
.category-slot{ .category-slot{
.category-item{ .category-item{
margin-top: 10px;
&:first-child{
margin-top: 0;
}
.el-input{ .el-input{
width: 432px; width: 432px;
} }
......
<template> <template>
<div class="nav"> <div class="nav" ref="navCntrRef">
<div style="display: inline-block;"> <div style="display: inline-block;">
<div class="nav-item" :ref="'navRef'+index" v-for="(item,index) in rowList" :key="item.id" @click="selectNav(item)" :class="{'cur-nav':curNavId==item.id}">{{ item.name }}<i class="el-icon-close del-icon" @click.stop="delNav(item)"></i></div> <div class="nav-item" :ref="'navRef'+index" v-for="(item,index) in rowList" :key="item[defaultProps.id]" @click="selectNav(item)" :class="{'cur-nav':value==item[defaultProps.id]}">
{{ item[defaultProps.name] }}
<i class="el-icon-close del-icon" @click.stop="delNav(item)" @contextmenu.prevent="editNav(item)"></i>
</div>
</div> </div>
<div v-if="showInput" class="input-area"><el-input maxLength="15" ref="addInput" @blur="inputBlur" v-model="configName" class="input"></el-input></div> <div v-if="showInput" class="input-area"><el-input maxLength="15" ref="addInput" @blur="inputBlur" v-model="addValue" class="input"></el-input></div>
<div v-else class="nav-item add-icon" style="cursor: pointer;" @click="addNav"><i class="el-icon-plus border"></i></div> <div v-else class="nav-item add-icon" style="cursor: pointer;" @click="addNav"><i class="el-icon-plus border"></i></div>
<div v-if="colList && colList.length" class="nav-item pull-btn" style="cursor: pointer;"> <div v-if="colList && colList.length" class="nav-item pull-btn" style="cursor: pointer;">
<i class="el-icon-arrow-down border"></i> <i class="el-icon-arrow-down border"></i>
<div class="pull-down-wrap"> <div class="pull-down-wrap">
<div class="pull-down-item" @click="selectNav(item, 'sort')" :class="{'cur-nav':curNavId==item.id}" v-for="item in colList" :key="item.id">{{ item.name }}<i class="el-icon-close del-icon" @click.stop="delNav(item)"></i></div> <div class="pull-down-item" @click="selectNav(item, 'sort')" :class="{'cur-nav':value==item[defaultProps.id]}" v-for="item in colList" :key="item[defaultProps.id]">
{{ item[defaultProps.name] }}
<i class="el-icon-close del-icon" @click.stop="delNav(item)"></i>
</div>
</div> </div>
</div> </div>
</div> </div>
...@@ -16,33 +22,103 @@ ...@@ -16,33 +22,103 @@
<script> <script>
export default{ export default{
name: 'nav', name: 'nav',
model: {
prop: 'value', // 默认是value
event: 'changeValue', // 默认是input
},
props: {
value: {
type: String
},
tabList:{
type: Array,
default: () => {
return []
}
},
defaultProps: {
type: Object,
default: ()=>{
return {
id: 'id',
name: 'name'
}
}
}
},
data(){ data(){
return { return {
curNavId: '', curNavId: '',
rowList: [{ addValue: '',
id: 1, showInput: false,
name: '你好' rowList: [],
},{ colList: []
id: 2, }
name: '你好啥事' },
},{ watch:{
id: 3, tabList:{
name: '你好事实上' handler(val, oldVal) {
}] this.calcWidth()
},
deep: true
} }
}, },
mounted(){
window.addEventListener('resize', this.resizeDom);
},
beforeDestroy(){
window.removeEventListener('resize', this.resizeDom)
},
methods:{ methods:{
resizeDom(){
this.calcWidth()
},
calcWidth(){
this.rowList = this.tabList
let calculated = false
let mainW = this.$refs?.navCntrRef?.offsetWidth || 0
let curIdx = -1
this.$nextTick(()=>{
this.rowList.reduce((pre, cur,index) => {
let curW = this.$refs?.['navRef'+index]?.[0]?.offsetWidth
if((pre + curW) > mainW-500 && !calculated) {
curIdx = index
calculated = true
}
return pre + curW
},0);
console.log(curIdx)
this.colList = curIdx >-1 ? this.tabList.slice(curIdx) : []
this.rowList = curIdx >-1 ? this.tabList.slice(0, curIdx) : this.tabList
console.log(this.rowList)
})
},
selectNav(item){ selectNav(item){
this.curNavId = item.id this.$emit('changeValue', item[this.defaultProps.id])
},
editNav(item){
this.$emit('delete', item)
}, },
delNav(item){ delNav(item){
this.$emit('delete', item)
}, },
inputBlur(){ inputBlur(){
if(this.addValue) {
this.$emit('inputBlur', {value: this.addValue})
}else{
this.$message.error('请输入内容')
}
this.clearData()
},
clearData(){
this.showInput = false
this.addValue = ''
}, },
addNav(){ addNav(){
this.showInput = true
this.$nextTick(()=>{
this.$refs.addInput.focus()
})
} }
} }
} }
...@@ -116,7 +192,9 @@ export default{ ...@@ -116,7 +192,9 @@ export default{
border-radius: 4px; border-radius: 4px;
.pull-down-item{ .pull-down-item{
height: 36px; height: 36px;
line-height: 36px; display: flex;
justify-content: space-between;
align-items: center;
font-weight: 400; font-weight: 400;
padding: 0 15px; padding: 0 15px;
font-size: 14px; font-size: 14px;
...@@ -126,7 +204,7 @@ export default{ ...@@ -126,7 +204,7 @@ export default{
color: #666666; color: #666666;
background-color: #F8F8F8; background-color: #F8F8F8;
&:hover{ &:hover{
background-color: #f5f7fa; background-color: #f5f7fa;
} }
} }
.cur-nav{ .cur-nav{
......
<template> <template>
<div class="category-list-ctnr"> <div class="category-list-ctnr">
<GLTabs v-model="activeName" :tabPaneList="tabPaneList" @tab-click="handleClick"></GLTabs> <GLTabs class="tabs" v-model="activeName" :tabPaneList="tabPaneList" @tab-click="handleClick"></GLTabs>
<pullDownNav></pullDownNav> <pullDownNav @inputBlur="inputBlur" @delete="delCategory" v-model="curMainCategoryId" :tabList="mainCategoryList" :defaultProps="{id: 'id', name: 'categoryName'}"></pullDownNav>
<div class="main-wrap"> <div class="main-wrap">
<GLCombiForm ref="showSearch" :rowNumber="1" :formObj="tableSearchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm> <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="tableSearchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
<div class="operate-wrap"> <div class="operate-wrap">
<span class="table-title">二级分类列表</span> <span class="table-title">二级分类列表</span>
<el-button class="operate-btn" type="primary" size="small" @click="handleAdd">新增二级分类</el-button> <el-button class="operate-btn" type="primary" size="small" @click="editCategory">新增二级分类</el-button>
</div> </div>
<GLTable ref="categoryRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :beforeSearchFn="beforeSearchFn" :tableParams="tableParams" :pageConf="pageConf" @setTableFinishFun="setTableFinishFun"> <GLTable ref="categoryRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :beforeSearchFn="beforeSearchFn" :tableParams="tableParams" :pageConf="pageConf" @setTableFinishFun="setTableFinishFun">
<div slot="brandSlot"> <div slot="brandSlot">
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
}, },
data() { data() {
return { return {
activeName: '',
curMainCategoryId: '',
tabPaneList: [],
mainCategoryList: [],
brandList:['丰田','本田','一汽大众','奔驰','宝马','奥迪','比亚迪'], brandList:['丰田','本田','一汽大众','奔驰','宝马','奥迪','比亚迪'],
buttonList: [ buttonList: [
{ {
...@@ -50,7 +54,7 @@ ...@@ -50,7 +54,7 @@
fn: '编辑' fn: '编辑'
}, },
listeners: { listeners: {
click: row => this.addCategory(row.scope, 1) click: row => this.editCategory(row.scope)
} }
}, },
{ {
...@@ -61,7 +65,7 @@ ...@@ -61,7 +65,7 @@
fn: '删除' fn: '删除'
}, },
listeners: { listeners: {
click: row => this.updateStatus(row.scope.id, 1) click: row => this.delCategory(row.scope, 1)
} }
} }
], ],
...@@ -73,7 +77,7 @@ ...@@ -73,7 +77,7 @@
url: url, url: url,
searchFormData: [ searchFormData: [
{ {
label: '案例名称', label: '分类名称',
name: 'categoryName', name: 'categoryName',
type: 'input' type: 'input'
}, },
...@@ -93,47 +97,132 @@ ...@@ -93,47 +97,132 @@
} }
} }
], ],
getListApi: this.$apis.channel.getChannelListApi, getListApi: this.$apis.category.getCategoryListApi,
tableParams: { tableParams: {
listName: 'list', listName: 'list',
tableOption: true, tableOption: true,
tableColumns: [ tableColumns: [
{ {
label: '二级分类名称', label: '二级分类名称',
prop: 'channelName' prop: 'categoryName'
}, },
{ {
label: '创建日期', label: '创建日期',
prop: 'createdDate', prop: 'createdDate'
formatter: cellValue => {
return dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss')
}
}, },
{ {
label: '更新时间', label: '更新时间',
prop: 'createdDate', prop: 'updatedDate'
formatter: cellValue => {
return dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss')
}
}, },
{ {
label: '操作人', label: '操作人',
prop: 'channelName' prop: 'updatedBy'
}, },
] ]
}, },
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' } pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' }
} }
}, },
created() {}, created() {
this.getChannelList()
},
watch:{
curMainCategoryId:{
handler(){
this.handleSearch()
},
deep: true
},
activeName:{
handler(){
this.getMainCategory()
},
deep: true
},
},
mounted() {}, mounted() {},
methods: { methods: {
//获取频道名称
getChannelList() {
this.$apis.channel
.getChannelListApi({
pageSize: 100,
pageNum: 1
})
.then(res => {
if(res?.list?.length){
let tabPaneList = []
res.list.forEach(item => {
if(item.channelType == 5 || item.channelType == 5){
tabPaneList.push({label: item.channelName,name: item.channelType==5 ? 1 : 2 ,merchantChannelId: item.id})
}
})
this.tabPaneList = tabPaneList
this.activeName = tabPaneList[0].name
}
})
},
getMainCategory(){
const params = {
pageSize: 1000,
pageNum: 1,
categoryLevel: 1,
categoryType: this.activeName
}
this.$apis.category.getCategoryListApi(params).then(res => {
if(res?.list?.length){
this.mainCategoryList = res.list
this.curMainCategoryId = res.list[0].id
}else{
this.curMainCategoryId = ''
}
})
},
inputBlur(e){
this.addCategory(e.value)
},
delCategory(e, type){
this.$confirm(`删除后数据将无法恢复,是否确认删除${e.categoryName}?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
callback: action => {
if (action == 'confirm') {
this.$apis.category.delCategoryApi({id: e.id}).then(res => {
if(res){
this.$message.success('删除成功')
this.getMainCategory()
if(type) {
this.handleSearch()
}
}
})
}
}
})
},
addCategory(val){
const params = {
categoryType: this.activeName,
categoryLevel: 1,
categoryName: val
}
this.$apis.category.addCategoryApi(params).then(res => {
if(res){
this.$message.success('新增成功')
this.getMainCategory()
}
})
},
getParams() { getParams() {
var params = JSON.parse(JSON.stringify(this.tableSearchForm)) var params = JSON.parse(JSON.stringify(this.tableSearchForm))
if (this.tableSearchForm.createDate.length) { if (this.tableSearchForm.createDate.length) {
params.createdDateStrat = new Date(this.tableSearchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00' params.beginCreateTime = new Date(this.tableSearchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
params.createdDateEnd = new Date(this.tableSearchForm.createDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59' params.endCreateTime = new Date(this.tableSearchForm.createDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
} }
params.categoryType = 1
params.categoryLevel = 2
params.parentCategoryId = this.curMainCategoryId
return params return params
}, },
beforeSearchFn() { beforeSearchFn() {
...@@ -158,15 +247,21 @@ ...@@ -158,15 +247,21 @@
//接收到的数据为空 //接收到的数据为空
this.$refs.categoryRef.data.length ? (this.$refs.categoryRef.tableHeightValues = '') : this.$refs.categoryRef.setTableHeightFun() this.$refs.categoryRef.data.length ? (this.$refs.categoryRef.tableHeightValues = '') : this.$refs.categoryRef.setTableHeightFun()
}, },
addCategory(val) { editCategory(row={}) {
this.$router.push({ if(!this.activeName) return this.$message.error('暂无频道')
path: `/category/add?id=${val.id}&channelType=${val.channelType}&$title=频道设置` const target = this.mainCategoryList.find(item => item.id == this.curMainCategoryId)
}) if(!target) return this.$message.error('请选择一级分类')
}, const params = {
handleAdd(){ categoryType: this.activeName,
this.$router.push({ parentCategoryId: target.id,
path: `/case/add` parentCategoryName: target.categoryName
}) }
if(row.id) {
params.id = row.id
params.name = row.categoryName
}
const queryStr = encodeURIComponent(JSON.stringify(params))
this.$router.push({ path: `/category/add/`+queryStr,query: { $title: row.id ? '编辑二级分类' : '新增二级分类' }})
} }
} }
} }
...@@ -174,14 +269,17 @@ ...@@ -174,14 +269,17 @@
<style scoped lang="scss"> <style scoped lang="scss">
.category-list-ctnr{ .category-list-ctnr{
.main-wrap{ .tabs{
background-color: #fff; margin-bottom: 16px;
padding: 20px; }
} .main-wrap{
.more-brand{ background-color: #fff;
color: #5850FF; padding: 20px;
cursor: pointer; }
} .more-brand{
color: #5850FF;
cursor: pointer;
}
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!