|
@@ -1,47 +1,21 @@
|
|
|
<template>
|
|
|
<el-card class="form-container" shadow="never">
|
|
|
- <el-form ref="productCateFrom" :model="productCate" :rules="rules" label-width="150px">
|
|
|
- <el-form-item label="分类名称:" prop="name">
|
|
|
- <el-input v-model="productCate.name" />
|
|
|
+ <el-form ref="productCateFrom" :model="rolesForm" :rules="rules" label-width="150px">
|
|
|
+ <el-form-item label="角色名称:" prop="roleName">
|
|
|
+ <el-input v-model="rolesForm.roleName" maxlength="20" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="上级分类:">
|
|
|
- <el-select v-model="productCate.parentId" placeholder="请选择分类" @change="changeAttrProductCate">
|
|
|
- <el-option v-for="item in selectProductCateList" :key="item.id" :label="item.name" :value="item.id" />
|
|
|
- </el-select>
|
|
|
+ <el-form-item label="角色描述:" prop="roleDesc">
|
|
|
+ <el-input v-model="rolesForm.roleDesc" maxlength="20" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="数量单位:">
|
|
|
- <el-input v-model="productCate.productUnit" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="排序:">
|
|
|
- <el-input v-model="productCate.sort" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="是否显示:">
|
|
|
- <el-radio-group v-model="productCate.showStatus">
|
|
|
- <el-radio :label="1">是</el-radio>
|
|
|
- <el-radio :label="0">否</el-radio>
|
|
|
- </el-radio-group>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="是否显示在导航栏:">
|
|
|
- <el-radio-group v-model="productCate.navStatus">
|
|
|
- <el-radio :label="1">是</el-radio>
|
|
|
- <el-radio :label="0">否</el-radio>
|
|
|
- </el-radio-group>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="分类图标:">
|
|
|
- <!-- <single-upload v-model="productCate.icon" /> -->
|
|
|
- </el-form-item>
|
|
|
- <el-form-item v-for="(filterProductAttr, index) in filterProductAttrList" :key="filterProductAttr.key" :label="index | filterLabelFilter">
|
|
|
- <el-cascader v-model="filterProductAttr.value" clearable :options="filterAttrs" @change="changeFilterProductAttrFn" />
|
|
|
- <!-- <el-button style="margin-left: 20px" @click.prevent="removeFilterAttr(filterProductAttr)">删除</el-button> -->
|
|
|
- </el-form-item>
|
|
|
- <!-- <el-form-item>
|
|
|
- <el-button size="small" type="primary" @click="handleAddFilterAttr()">新增</el-button>
|
|
|
- </el-form-item> -->
|
|
|
- <el-form-item label="关键词:">
|
|
|
- <el-input v-model="productCate.keywords" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="分类描述:">
|
|
|
- <el-input v-model="productCate.description" type="textarea" :autosize="true" />
|
|
|
+ <el-form-item label="角色授权:">
|
|
|
+ <el-tree
|
|
|
+ ref="tree"
|
|
|
+ :data="treeData"
|
|
|
+ show-checkbox
|
|
|
+ node-key="id"
|
|
|
+ :props="defaultProps"
|
|
|
+ @node-click="handleNodeClick"
|
|
|
+ />
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
<el-button type="primary" @click="onSubmit('productCateFrom')">提交</el-button>
|
|
@@ -52,35 +26,20 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-// import { fetchList, createProductCate, updateProductCate, getProductCate } from '@/api/productCate'
|
|
|
-// import { fetchListWithAttr } from '@/api/productAttrCate'
|
|
|
-// import { getProductAttrInfo } from '@/api/productAttr'
|
|
|
-// import SingleUpload from '@/components/Upload/singleUpload'
|
|
|
+import { updateMenu, createMenu } from '@/api/role'
|
|
|
+import { sysMenuTree } from '@/api/menu'
|
|
|
+import { validAlphabets } from '@/utils/validate'
|
|
|
|
|
|
-const defaultProductCate = {
|
|
|
- description: '',
|
|
|
- icon: '',
|
|
|
- keywords: '',
|
|
|
- name: '',
|
|
|
- navStatus: 0,
|
|
|
- parentId: 0,
|
|
|
- productUnit: '',
|
|
|
- showStatus: 0,
|
|
|
- sort: 0,
|
|
|
- productAttributeIdList: []
|
|
|
+const defaultRole = {
|
|
|
+ roleDesc: '',
|
|
|
+ roleName: '',
|
|
|
+ menuIds: '',
|
|
|
+ id: 0
|
|
|
}
|
|
|
export default {
|
|
|
name: 'ProductCateDetail',
|
|
|
// components: { SingleUpload },
|
|
|
- filters: {
|
|
|
- filterLabelFilter(index) {
|
|
|
- if (index === 0) {
|
|
|
- return '筛选属性:'
|
|
|
- } else {
|
|
|
- return ''
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
+ filters: { },
|
|
|
props: {
|
|
|
isEdit: {
|
|
|
type: Boolean,
|
|
@@ -88,16 +47,31 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
+ const validateRoleName = (rule, value, callback) => {
|
|
|
+ if (!validAlphabets(value)) {
|
|
|
+ callback(new Error('请输入英文角色名称'))
|
|
|
+ } else {
|
|
|
+ callback()
|
|
|
+ }
|
|
|
+ }
|
|
|
return {
|
|
|
- productCate: Object.assign({}, defaultProductCate),
|
|
|
+ rolesForm: Object.assign({}, defaultRole),
|
|
|
selectProductCateList: [],
|
|
|
rules: {
|
|
|
- name: [
|
|
|
- { required: true, message: '请输入品牌名称', trigger: 'blur' },
|
|
|
- { min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur' }
|
|
|
+ roleName: [
|
|
|
+ { required: true, message: '请输入英文角色名称', trigger: 'blur', validator: validateRoleName },
|
|
|
+ { min: 2, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ roleDesc: [
|
|
|
+ { required: true, message: '请输入角色描述', trigger: 'blur' },
|
|
|
+ { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
|
|
|
]
|
|
|
},
|
|
|
- filterAttrs: [],
|
|
|
+ treeData: [],
|
|
|
+ defaultProps: {
|
|
|
+ children: 'subMenus',
|
|
|
+ label: 'title'
|
|
|
+ },
|
|
|
filterProductAttrList: [
|
|
|
{
|
|
|
value: []
|
|
@@ -123,68 +97,19 @@ export default {
|
|
|
// }
|
|
|
// })
|
|
|
} else {
|
|
|
- this.productCate = Object.assign({}, defaultProductCate)
|
|
|
+ this.rolesForm = Object.assign({}, defaultRole)
|
|
|
}
|
|
|
- this.getSelectProductCateList()
|
|
|
+ this.getSysMenuTree()
|
|
|
},
|
|
|
methods: {
|
|
|
- getSelectProductCateList() {
|
|
|
- // fetchList(0, { pageSize: 100, pageNum: 1 }).then(response => {
|
|
|
- // this.selectProductCateList = response.data.list
|
|
|
- // this.selectProductCateList.unshift({ id: 0, name: '无上级分类' })
|
|
|
- // this.selectProductCateList.forEach(el => {
|
|
|
- // // eslint-disable-next-line eqeqeq
|
|
|
- // if (el.id == this.productCate.parentId) {
|
|
|
- // this.changOptionName = el.name
|
|
|
- // }
|
|
|
- // })
|
|
|
- // console.log(this.changOptionName)
|
|
|
- // this.getProductAttrCateList()
|
|
|
- // })
|
|
|
- },
|
|
|
- getProductAttrCateList() {
|
|
|
- console.log(this.changOptionName)
|
|
|
- // const params = { productAttrCateId: null, parentName: this.changOptionName }
|
|
|
- // fetchListWithAttr(params).then(response => {
|
|
|
- // const list = response.data
|
|
|
- // for (let i = 0; i < list.length; i++) {
|
|
|
- // const productAttrCate = list[i]
|
|
|
- // const children = []
|
|
|
- // if (productAttrCate.productAttributeList != null && productAttrCate.productAttributeList.length > 0) {
|
|
|
- // for (let j = 0; j < productAttrCate.productAttributeList.length; j++) {
|
|
|
- // children.push({
|
|
|
- // label: productAttrCate.productAttributeList[j].name,
|
|
|
- // value: productAttrCate.productAttributeList[j].id
|
|
|
- // })
|
|
|
- // }
|
|
|
- // }
|
|
|
- // // this.filterAttrs.push({label: productAttrCate.name, value: productAttrCate.id, children: children});
|
|
|
- // this.filterAttrs.push({ label: productAttrCate.name, value: productAttrCate.id })
|
|
|
- // }
|
|
|
- // })
|
|
|
+ handleNodeClick(data, node) {
|
|
|
+ console.log(node)
|
|
|
+ debugger
|
|
|
},
|
|
|
- getProductAttributeIdList() {
|
|
|
- // 获取选中的筛选商品属性
|
|
|
- const productAttributeIdList = []
|
|
|
- for (let i = 0; i < this.filterProductAttrList.length; i++) {
|
|
|
- const item = this.filterProductAttrList[i]
|
|
|
- if (item.value !== null && item.value.length === 1) {
|
|
|
- productAttributeIdList.push(item.value[0])
|
|
|
- }
|
|
|
- }
|
|
|
- return productAttributeIdList
|
|
|
- },
|
|
|
- changeAttrProductCate(value) {
|
|
|
- this.selectProductCateList.forEach(el => {
|
|
|
- // eslint-disable-next-line eqeqeq
|
|
|
- if (value == el.id) {
|
|
|
- this.changOptionName = el.name
|
|
|
- }
|
|
|
+ getSysMenuTree() { // 属性菜单
|
|
|
+ sysMenuTree().then(response => {
|
|
|
+ this.treeData = response.data
|
|
|
})
|
|
|
- console.log(this.changOptionName)
|
|
|
- },
|
|
|
- changeFilterProductAttrFn(value) {
|
|
|
- console.log(value)
|
|
|
},
|
|
|
onSubmit(formName) {
|
|
|
this.$refs[formName].validate(valid => {
|
|
@@ -195,26 +120,26 @@ export default {
|
|
|
type: 'warning'
|
|
|
}).then(() => {
|
|
|
if (this.isEdit) {
|
|
|
- this.productCate.productAttributeIdList = this.getProductAttributeIdList()
|
|
|
- // updateProductCate(this.$route.query.id, this.productCate).then(response => {
|
|
|
- // this.$message({
|
|
|
- // message: '修改成功',
|
|
|
- // type: 'success',
|
|
|
- // duration: 1000
|
|
|
- // })
|
|
|
- // this.$router.back()
|
|
|
- // })
|
|
|
+ this.rolesForm.menuIds = this.getCheckedNodes()
|
|
|
+ updateMenu(this.$route.query.id, this.rolesForm).then(response => {
|
|
|
+ this.$message({
|
|
|
+ message: '修改成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ this.$router.back()
|
|
|
+ })
|
|
|
} else {
|
|
|
- this.productCate.productAttributeIdList = this.getProductAttributeIdList()
|
|
|
- // createProductCate(this.productCate).then(response => {
|
|
|
- // this.$refs[formName].resetFields()
|
|
|
- // this.resetForm(formName)
|
|
|
- // this.$message({
|
|
|
- // message: '提交成功',
|
|
|
- // type: 'success',
|
|
|
- // duration: 1000
|
|
|
- // })
|
|
|
- // })
|
|
|
+ this.rolesForm.menuIds = this.getCheckedNodes()
|
|
|
+ createMenu(this.rolesForm).then(response => {
|
|
|
+ this.$refs[formName].resetFields()
|
|
|
+ this.resetForm(formName)
|
|
|
+ this.$message({
|
|
|
+ message: '提交成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
@@ -227,15 +152,16 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ getCheckedNodes() { // 获取选中系统菜单Id
|
|
|
+ console.log(this.$refs.tree.getCheckedNodes())
|
|
|
+ const res = this.$refs.tree.getCheckedNodes()
|
|
|
+ const menuIds = res[0].id
|
|
|
+ console.log('menuIds', menuIds)
|
|
|
+ return menuIds
|
|
|
+ },
|
|
|
resetForm(formName) {
|
|
|
this.$refs[formName].resetFields()
|
|
|
- this.productCate = Object.assign({}, defaultProductCate)
|
|
|
- this.getSelectProductCateList()
|
|
|
- this.filterProductAttrList = [
|
|
|
- {
|
|
|
- value: []
|
|
|
- }
|
|
|
- ]
|
|
|
+ this.rolesForm = Object.assign({}, defaultRole)
|
|
|
},
|
|
|
removeFilterAttr(productAttributeId) {
|
|
|
if (this.filterProductAttrList.length === 1) {
|