Commit 7c03bf2d by cwq0219

商户管理

1 parent 14d48b28
...@@ -73,11 +73,13 @@ ...@@ -73,11 +73,13 @@
.hide { .hide {
display: none; display: none;
} }
.option-btns{
.option-btns {
height: 38px; height: 38px;
} }
.wrap-add-signal{
.wrap-add-signal {
margin-top: 11px; margin-top: 11px;
background-color: #1989FA; background-color: #1989FA;
color: #fff; color: #fff;
...@@ -286,7 +288,20 @@ ...@@ -286,7 +288,20 @@
</div> </div>
<!-- 权限树 --> <!-- 权限树 -->
<div id="authorityTree"> <div id="authorityTree">
树-- <!-- 树-- -->
<div class="layui-form-item">
<label class="layui-form-label required">角色权限:</label>
<div class="layui-input-block" id="accountType">
<!-- <input lay-filter="switch" type="checkbox" name="merchantId" value="1" title="引流渠道商" />
<input lay-filter="switch" type="checkbox" name="merchantId" value="2" title="服务商/合作商" /> -->
</div>
</div>
<div class="layui-tab" lay-filter="roleAuth">
<ul class="layui-tab-title"></ul>
<div class="layui-tab-content"></div>
</div>
<button id="confirm" class="layui-btn">确定</button>
<button class="layui-btn" data-type="handleCancel">取消</button>
</div> </div>
</div> </div>
</main> </main>
...@@ -294,19 +309,22 @@ ...@@ -294,19 +309,22 @@
<script src="https://www.layuicdn.com/layui/layui.js"></script> <script src="https://www.layuicdn.com/layui/layui.js"></script>
<script src="/js/load.js"></script> <script src="/js/load.js"></script>
<script> <script>
layui.use(['gtree', 'request', 'helper', 'layer', 'laydate'], function () { layui.use(['gtree', 'request', 'helper', 'layer', 'laydate', 'element', 'xmSelect', 'laytpl'], function () {
var tree = layui.gtree var tree = layui.gtree
var request = layui.request var request = layui.request
var form = layui.form var form = layui.form
var laydate = layui.laydate var laydate = layui.laydate
var $ = layui.$ var $ = layui.$
var helper = layui.helper var helper = layui.helper
var element = layui.element
var editData = {} var editData = {}
var treeObj = null var treeObj = null
var all_nodes = [] var all_nodes = []
// 1-创建新商户;2-创建子商户;3-修改 // 1-创建新商户;2-创建子商户;3-修改
var editLevel = 1 var editLevel = 1
var id = null // 1-基本信息;2-权限树
var step = 1
var merchantId = null
var merchantForm = { var merchantForm = {
channelId: '', channelId: '',
...@@ -374,6 +392,12 @@ ...@@ -374,6 +392,12 @@
helper.store.set('merchantMapObj', merchantForm) helper.store.set('merchantMapObj', merchantForm)
form.on('submit(handleSubmit)', function (data) { form.on('submit(handleSubmit)', function (data) {
//---------------
baseIsShow(false)
treeIsShow(true)
// getMenuList()
findMenuFunTreeByMerId()
//-------------------
console.log(editLevel) console.log(editLevel)
// console.log(data.field) // console.log(data.field)
var formData = data.field var formData = data.field
...@@ -444,7 +468,7 @@ ...@@ -444,7 +468,7 @@
} else if (editLevel == 2) { } else if (editLevel == 2) {
params.method = 'cn.com.glsx.merchants.merchant.saveMerchant' params.method = 'cn.com.glsx.merchants.merchant.saveMerchant'
} else if (editLevel == 3) { } else if (editLevel == 3) {
params.id = id params.id = merchantId
params.method = 'cn.com.glsx.merchants.merchant.updateMerchant' params.method = 'cn.com.glsx.merchants.merchant.updateMerchant'
} }
// 保存状态 1.草稿 2.发布 3.注销 4.过期 // 保存状态 1.草稿 2.发布 3.注销 4.过期
...@@ -457,10 +481,15 @@ ...@@ -457,10 +481,15 @@
console.log(params) console.log(params)
request(params, function (res) { request(params, function (res) {
console.log(res) console.log(res)
// authorityTree
if (editLevel == 3) {
layer.msg('操作成功', { layer.msg('操作成功', {
icon: 1 icon: 1
}) })
// go('merchant', 'index') go('merchant', 'index')
} else {
}
}) })
return false return false
}) })
...@@ -595,9 +624,33 @@ ...@@ -595,9 +624,33 @@
reader.onload() reader.onload()
}) })
function baseIsShow(isShow) {
if (isShow) {
$('#basicForm').show()
} else {
$('#basicForm').hide()
}
}
function treeIsShow(isShow) {
if (isShow) {
$('#authorityTree').show()
} else {
$('#authorityTree').hide()
}
}
function init() { function init() {
editLevel = qs('editLevel') editLevel = qs('editLevel')
id = qs('id') merchantId = qs('id')
step = qs('step')
if (step == 1) {
treeIsShow(false)
} else {
baseIsShow(false)
// getMenuList()
// findMenuFunTreeByMerId()
}
if (editLevel == 3) { if (editLevel == 3) {
// merchantName = qs('merchantName') // merchantName = qs('merchantName')
getMerchantInfo() getMerchantInfo()
...@@ -605,6 +658,7 @@ ...@@ -605,6 +658,7 @@
getBusiScope() getBusiScope()
getCarBrandTree() getCarBrandTree()
getAccountType() getAccountType()
findMenuFunTreeByMerId()
} }
getChannel() getChannel()
getAccountLevel() getAccountLevel()
...@@ -645,7 +699,7 @@ ...@@ -645,7 +699,7 @@
function getMerchantInfo() { function getMerchantInfo() {
request({ request({
method: 'cn.com.glsx.merchants.merchant.findMerchantDetail', method: 'cn.com.glsx.merchants.merchant.findMerchantDetail',
id: id id: merchantId
}, function (res) { }, function (res) {
console.log(res.data) console.log(res.data)
form.val('merchantForm', res.data) form.val('merchantForm', res.data)
...@@ -655,6 +709,8 @@ ...@@ -655,6 +709,8 @@
getAccountType() getAccountType()
recoveryBusiScopeCus() recoveryBusiScopeCus()
recoveryFile() recoveryFile()
getById()
// findMenuFunTreeByMerId()
}) })
} }
...@@ -815,7 +871,373 @@ ...@@ -815,7 +871,373 @@
}) })
}) })
} }
// 树--
// function getMenuList() {
// request({
// method: 'cn.com.glsx.merchants.merchant.findPermissionsByMerId',
// id: merchantId
// }, function(res) {
// console.log(res.data)
// menuList = res.data
// })
// }
// 树
// console.log(merchantId)
// if (merchantId) {
// getById()
// } else {
// findMenuFunTreeByMerId()
// }
// start
var laytpl = layui.laytpl
var xmSelect = layui.xmSelect
// var tree = layui.gtree
// var helper = layui.helper
var check_arr = []
var requestList = []
var templateData = {}
var selectEl = {}
var treeData = {}
var menuFunTreeData = [] // 商户的菜单权限树数据
var active = {
/**
* 第一级tab添加
* item: {name: 选项卡名称, value: 选项卡值}
* roleAuth: 选项卡过滤器的名称 lay-filter绑定的名字
* content: 一个放置模板的视图容器,用于呈现渲染结果 带有id的div
* id:选项卡标题的lay-id属性值
* 需要引入laytpl 模块
* rolesAuth:模板的id
* view 放置模板的视图容器的dom
* templateData:用于渲染模板的数据
* productList:复选下拉框的list,修改过的数据{name: '', value: ''}
* products:对应的菜单下的产品list,包含了对应的权限树,原始数据,需作为参数传入treeTabAdd中,在实例化tree时传入的数据使用
*/
tabAdd: function (item) {
// 渠道的id,一层选项卡的id
var id = item.value
// roleAuth 一层选项卡过滤器的名称
element.tabAdd('roleAuth', {
title: item.title,
// 放置模板视图的上一级div
content: '<div id="role' + id + '"></div>',
// 选项卡标题的lay-id属性值
id: id
})
var getTpl = rolesAuth.innerHTML, // 模板内容
view = document.getElementById('role' + id)
templateData.id = id // 渲染模版的数据
laytpl(getTpl).render(templateData, function (html) {
view.innerHTML = html
})
var productList = []
var products = []
$.each(menuFunTreeData, function (index, item) {
if (item.accounttypeId == id) {
products = item.products
$.each(item.products, function (idx, i) {
productList.push({
name: i.productName,
value: i.productId
})
})
}
})
selectEl[id] = xmSelect.render({
el: '#select' + id,
data: productList,
on: function (data) {
//arr: 当前多选已选中的数据
var arr = data.arr
//change, 此次选择变化的数据,数组
var change = data.change
//isAdd, 此次操作是新增还是删除
var isAdd = data.isAdd
var filterName = 'treeTab' + id
if (isAdd) {
active.treeTabAdd(change[0], id, products)
} else {
var productId = 'tab_' + id + '_' + change[0].value
active.tabDelete(filterName, productId)
}
if (arr.length != 0) {
var productId = 'tab_' + id + '_' + arr[0].value
active.tabChange(filterName, productId)
}
}
})
// console.log(selectEl[id])
},
// tab删除
tabDelete: function (name, id) {
element.tabDelete(name, id)
},
// tab Change
tabChange: function (name, id) {
element.tabChange(name, id)
},
/**
* 第二级选项卡
* treeTabAdd 产品的权限添加
* item: {name: 选项卡名称, value: 选项卡值}
* id 第一级选项卡的item.value
* filterName: 过滤器的名称 lay-filter绑定的值
* treeData:渲染模板的数据,和用来存放对应树实例的对象,
* products:产品list数组
* defaultList:编辑时传入,默认勾选中的数组。(举例:[1,2,3])
*/
treeTabAdd: function (item, id, products, defaultList) {
// console.log(defaultList)
var productId = 'tab_' + id + '_' + item.value
var filterName = 'treeTab' + id // 过滤器的名称 lay-filter
element.tabAdd(filterName, {
title: item.name,
content: '<div id="treeTab' + productId + '"></div>', // 放置模板视图的div
id: productId
})
var getTreeTpl = treeAuth.innerHTML, // 获取的模板的id的内容
treeView = document.getElementById('treeTab' + productId) // 放置模板视图的div
treeData[id] = treeData[id] || {}
treeData[id][item.value] = treeData[id][item.value] || {}
treeData[id][item.value].id = productId // 渲染模版的数据
treeData[id][item.value].productId = item.value
laytpl(getTreeTpl).render(treeData[id][item.value], function (html) {
treeView.innerHTML = html
})
var treeListData = []
$.each(products, function (index, i) {
if (item.value == i.productId) {
treeListData = i.merchantProTreeResponses
}
})
var treedom = 'tree_' + productId
// console.log(merchantId)
if (!merchantId) {
treeData[id][item.value].treeObj = tree.create(treedom, treeListData)
treeData[id][item.value].treeObj.checkAllNodes(true)
} else {
treeData[id][item.value].treeObj = tree.create(treedom, treeListData, {
checkedList: defaultList
})
}
}
}
function getTree() {
var arr = []
if (merchantForm.accountType) {
var labelList = merchantForm.accountTypeNames.split(',')
var valList = merchantForm.accountType.split(',')
$.each(valList, function (index, item) {
var obj = {
title: labelList[index],
value: valList[index]
}
arr.push(obj)
active.tabAdd(obj)
})
if (arr.length != 0) {
active.tabChange('roleAuth', arr[0].value)
}
}
}
// 复选框的change事件
// form.on('checkbox(switch)', function (data) {
// var arr = []
// if (data.elem.checked) {
// var obj = {
// title: data.elem.title,
// value: data.elem.value
// }
// arr.push({
// accounttypeId: data.elem.value
// })
// active.tabAdd(obj)
// } else {
// for (var i in arr) {
// var id = arr[i].accounttypeId
// if (arr[i].accounttypeId == data.elem.value) {
// active.tabDelete('roleAuth', id)
// arr.splice(i, 1)
// }
// }
// }
// if (arr.length != 0) {
// active.tabChange('roleAuth', arr[0].accounttypeId)
// }
// })
// end
function toInt(str) {
var arr = str.split(',')
$.each(arr, function(index, item) {
arr[index] = parseInt(item)
})
return arr
}
// 查询商户的菜单权限树
function findMenuFunTreeByMerId() {
console.log(merchantForm.merchantAccountLevel)
var accountType = toInt(merchantForm.accountType)
var params = {
// method: 'cn.com.glsx.merchants.merchant.findMenuFunTreeByMerId',
method: 'org.ore.api.accountType.getProductTreeList',
idList: accountType,
merchantId: merchantId,
accountLevel: merchantForm.merchantAccountLevel
}
request(params, function (res) {
if (res.code == '0') {
// callback(res.data)
menuFunTreeData = res.data
console.log(menuFunTreeData)
var accountType = $('#accountType')
$.each(menuFunTreeData, function (index, item) {
// console.log(item)
var str = $('<input lay-filter="switch" type="checkbox" name="accounttypeId" value="' + item
.accounttypeId + '" title="' + item.accounttypeName + '" />')
accountType.append(str)
if (merchantId) {
console.log(check_arr, 'check_arr')
// 角色权限的check
for (var i = 0; i < check_arr.length; i++) {
if (check_arr[i].accounttypeId == item.accounttypeId) {
var productData = check_arr[i]
str.attr("checked", true)
var obj = {
title: item.accounttypeName,
value: item.accounttypeId
}
active.tabAdd(obj)
var selectArr = []
var menuData = []
for (var j = 0; j < productData.products.length; j++) {
menuData = productData.products[j]
selectArr.push(menuData.productId)
active.treeTabAdd({
name: menuData.productName,
value: menuData.productId
}, item.accounttypeId, item.products, menuData.idList)
}
// // 产品的回显
console.log(selectEl[item.accounttypeId], '\\\\\\\\\\\\\\\\\\')
selectEl[item.accounttypeId].setValue(selectArr)
var filterName = 'treeTab' + item.accounttypeId
var productId = 'tab_' + item.accounttypeId + '_' + item.products[0].productId
active.tabChange(filterName, productId)
// 树的回显
}
break
}
if (check_arr.length != 0) {
active.tabChange('roleAuth', check_arr[0].accounttypeId)
}
}
})
form.render('checkbox')
getTree()
}
})
}
// 根据id获取角色详情
function getById() {
var params = {
method: 'cn.com.glsx.merchants.merchant.findPermissionsByMerId',
// method: 'org.ore.api.role.getById',
id: merchantId
}
request(params, function (res) {
if (res.code == '0') {
console.log(res.data, '详情')
var accounttypeId = ''
if (res.data) {
check_arr = res.data
}
console.log(check_arr, 'jklj')
findMenuFunTreeByMerId()
form.val('roleForm', {
roleName: res.data.roleName,
roleDescription: res.data.roleDescription
})
}
})
}
// 获取角色权限数据requestList
function getAuthList() {
for (var key in treeData) {
var accountObj = treeData[key]
var productList = []
for (var i in accountObj) {
var productObj = accountObj[i]
var menuIdList = []
var functionIdList = []
var functionIdLists = []
var nodes = productObj.treeObj.getCheckedNodes(true)
$.each(nodes, function (index, item) {
if (item.logo == 'function') {
functionIdLists.push(item)
} else {
menuIdList.push(item.id)
}
})
$.each(functionIdLists, function (idx, m) {
// m.parentId
var findIdx = -1
$.each(functionIdList, function (idn, n) {
if (n.id == m.parentId) {
findIdx = idn
}
})
if (findIdx != -1) {
functionIdList[findIdx].functionValue += ';' + m.id + ':' + m.label
} else {
functionIdList.push({
id: m.parentId,
menuId: m.superParentId,
functionValue: m.id + ':' + m.label
})
}
}) })
productList.push({
productId: productObj.productId,
functionIdList: functionIdList,
menuIdList: menuIdList
})
}
requestList.push({
accountTypeId: key,
productList: productList
})
}
console.log(requestList)
}
$('#confirm').on('click', function () {
// console.log(treeData)
getAuthList()
return false
})
})
</script>
<script type="text/html" id="rolesAuth">
<div id="select{{d.id}}"></div>
<div class="layui-tab layui-tab-brief" lay-filter="treeTab{{d.id}}">
<ul class="layui-tab-title">
</ul>
<div class="layui-tab-content">
</div>
</div>
</script>
<script type="text/html" id="treeAuth">
<!-- <button class="layui-btn" data-type="d.id" id="checkedAll">全选</button>
<button class="layui-btn" id="cancelCheckedAll">取消全选</button> -->
<ul id="tree_{{d.id}}" class="ztree wrapper-tree"></ul>
</script> </script>
</body> </body>
......
...@@ -111,7 +111,10 @@ ...@@ -111,7 +111,10 @@
<script type="text/html" id="merchantBtns"> <script type="text/html" id="merchantBtns">
<a class="layui-btn-xs" lay-event="handleDetail">查看</a> <a class="layui-btn-xs" lay-event="handleDetail">查看</a>
{{# if((d.btn.edit)){ }} {{# if((d.btn.edit)){ }}
<a class="layui-btn-xs" lay-event="handleEdit">修改</a> <a class="layui-btn-xs" lay-event="handleEdit">修改基本信息</a>
{{# } }}
{{# if((d.btn.edit)){ }}
<a class="layui-btn-xs" lay-event="handleAuthority">修改权限</a>
{{# } }} {{# } }}
{{# if((d.btn.createSubMerchant)){ }} {{# if((d.btn.createSubMerchant)){ }}
<a class="layui-btn-xs" lay-event="handleAddMerchant">创建子商户/门店</a> <a class="layui-btn-xs" lay-event="handleAddMerchant">创建子商户/门店</a>
...@@ -219,11 +222,21 @@ ...@@ -219,11 +222,21 @@
break break
// 修改 // 修改
case 'handleEdit': case 'handleEdit':
// 1-创建新商户;2-创建子商户;3-修改 // editLevel - 1-创建新商户;2-创建子商户;3-修改
// step - 1-基本信息;2-权限树
go('merchant', 'edit', { go('merchant', 'edit', {
editLevel: 3, editLevel: 3,
id: row.id id: row.id,
// merchantName: row.merchantName step: 1
})
break
case 'handleAuthority':
// editLevel - 1-创建新商户;2-创建子商户;3-修改
// step - 1-基本信息;2-权限树
go('merchant', 'edit', {
editLevel: 3,
id: row.id,
step: 2
}) })
break break
// 创建子商户/门店 // 创建子商户/门店
...@@ -236,7 +249,9 @@ ...@@ -236,7 +249,9 @@
break break
// 创建员工 // 创建员工
case 'handleAddStaff': case 'handleAddStaff':
go('employee', 'add') go('employee', 'add', {
merchantId: row.id
})
break break
// 修改账户有效期 // 修改账户有效期
case 'handleVaildPeriod': case 'handleVaildPeriod':
...@@ -440,7 +455,8 @@ ...@@ -440,7 +455,8 @@
function init() { function init() {
// 运营系统 // 运营系统
if (!isDxternal) { // if (!isDxternal) {
if (isDxternal) {
getChannel() getChannel()
getAccountLevel() getAccountLevel()
getAccountType() getAccountType()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!