Commit 1ea2864a by cwq0219

商户管理

1 parent b1670f61
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
<div class="edit-box"> <div class="edit-box">
<!-- 基本信息 --> <!-- 基本信息 -->
<div id="basicForm"> <div id="basicForm">
<form class="layui-form" lay-filter="merchantForm" lay-verify="merchantVerify"> <form class="layui-form" lay-filter="merchantForm">
<div class="layui-form-item edit-title" style="position: relative;"> <div class="layui-form-item edit-title" style="position: relative;">
<div class="layui-input-inline">企业基本信息</div> <div class="layui-input-inline">企业基本信息</div>
<div class="layui-input-inline" style="position: absolute; right: 0; top: 5px; font-size: normal;"> <div class="layui-input-inline" style="position: absolute; right: 0; top: 5px; font-size: normal;">
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
</select> </select>
</div> </div>
<div class="layui-input-inline" style="width: 220px;"> <div class="layui-input-inline" style="width: 220px;">
<input class="layui-input" maxlength="50" name="merchantOrgcode" placeholder="请输入组织机构号码"> <input class="layui-input" maxlength="50" lay-verify="merchantOrgcode" name="merchantOrgcode" placeholder="请输入组织机构号码">
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
...@@ -164,7 +164,7 @@ ...@@ -164,7 +164,7 @@
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">驻点联系人:</label> <label class="layui-form-label">驻店联系人:</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input class="layui-input" name="residentContact" maxlength="15" placeholder="请输入驻点联系人"> <input class="layui-input" name="residentContact" maxlength="15" placeholder="请输入驻点联系人">
</div> </div>
...@@ -172,7 +172,8 @@ ...@@ -172,7 +172,8 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">驻店电话:</label> <label class="layui-form-label">驻店电话:</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input class="layui-input" name="residentPhone" maxlength="11" placeholder="请输入驻点电话"> <input class="layui-input" name="residentPhone" maxlength="11" placeholder="请输入驻点电话"
lay-verify="residentPhone">
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
...@@ -326,1046 +327,1048 @@ ...@@ -326,1046 +327,1048 @@
</div> </div>
<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 src="/js/validator.js"></script>
<script> <script>
layui.use(['gtree', 'request', 'helper', 'layer', 'laydate', 'element', 'xmSelect', 'laytpl'], function () { layui.use(['gtree', 'request', 'helper', 'layer', 'laydate', 'element', 'xmSelect', 'laytpl', 'validator'],
var tree = layui.gtree function () {
var request = layui.request var tree = layui.gtree
var form = layui.form var request = layui.request
var laydate = layui.laydate var form = layui.form
var $ = layui.$ var laydate = layui.laydate
var helper = layui.helper var $ = layui.$
var element = layui.element var validator = layui.validator
var editData = {} var helper = layui.helper
var treeObj = null var element = layui.element
var all_nodes = [] var editData = {}
// 1-创建新商户;2-创建子商户;3-修改 var treeObj = null
var editLevel = 1 var all_nodes = []
// 1-基本信息;2-权限树 // 1-创建新商户;2-创建子商户;3-修改
var step = 1 var editLevel = 1
var merchantId = null // 1-基本信息;2-权限树
var parentMerchantId = null var step = 1
// 是否工厂 var merchantId = null
var isFactory = true var parentMerchantId = null
var parentInfo = {} // 是否工厂
var isFactory = true
var parentInfo = {}
var merchantForm = { var merchantForm = {
channelId: '', channelId: '',
merchantName: '', merchantName: '',
merchantAbbreviation: '', merchantAbbreviation: '',
merchantType: '', merchantType: '',
merchantOrgcode: '', merchantOrgcode: '',
merchantLegalPerson: '', merchantLegalPerson: '',
merchantLegalPersonPhone: '', merchantLegalPersonPhone: '',
isloginName: 0, isloginName: 0,
residentContact: '', residentContact: '',
residentPhone: '', residentPhone: '',
bussinessBegintime: '', bussinessBegintime: '',
bussinessEndtime: '', bussinessEndtime: '',
lat: '', lat: '',
lng: '', lng: '',
merchantAddress: '', merchantAddress: '',
businessScope: '', businessScope: '',
merchantFiles: [] merchantFiles: []
}
var baseData = {
channelList: [],
carBrandTreeList: [],
accountLevelList: [],
validPeriodList: [],
busiScopeList: [],
accountTypeList: []
}
var startDate = laydate.render({
elem: '#startDate', //指定元素
type: 'time',
format: 'HH:mm:ss',
done: function (value, date) { //监听日期被切换
if (value != "") {
date.month = date.month - 1
endDate.config.min = date
} else {
endDate.config.min = startDate.config.min
}
lay('#startDate').html(value)
} }
})
var endDate = laydate.render({
elem: '#endDate', //指定元素
type: 'time',
format: 'HH:mm:ss',
done: function (value, date) { //监听日期被切换
if (value != "") {
date.month = date.month - 1
startDate.config.max = date
} else {
startDate.config.max = endDate.config.max
}
lay('#endDate').html(value)
}
})
init() var baseData = {
channelList: [],
// helper.store.set('merchantMapObj', { carBrandTreeList: [],
// lat: '116.397428', accountLevelList: [],
// lng: '39.90923', validPeriodList: [],
// merchantAddress: '深圳' busiScopeList: [],
// }) accountTypeList: []
// helper.store.set('merchantMapObj', merchantForm)
// 校验
// form.vertify({
// merchantVerify: []
// })
form.on('submit(handleFirstSubmit)', function (data) {
// console.log(editLevel)
// console.log(data.field)
var formData = data.field
var params = {
isloginName: 0
}
var fieldToFormNameList = ['channelId', 'merchantName', 'merchantAbbreviation', 'merchantType',
'merchantOrgcode',
'merchantLegalPerson', 'merchantLegalPersonPhone', 'residentContact', 'residentPhone',
'merchantLoginAccount', 'merchantLoginPassword',
'merchantAccountLevel', 'effectiveTime'
]
if (formData.isloginName == 'on') {
params.isloginName = 1
}
if (formData.bussinessBegintime) {
merchantForm.bussinessBegintime = formData.bussinessBegintime
params.bussinessBegintime = formData.bussinessBegintime
} }
if (formData.bussinessEndtime) {
merchantForm.bussinessEndtime = formData.bussinessEndtime var startDate = laydate.render({
params.bussinessEndtime = formData.bussinessEndtime elem: '#startDate', //指定元素
} type: 'time',
if (merchantForm.lat) { format: 'HH:mm:ss',
params.lat = merchantForm.lat done: function (value, date) { //监听日期被切换
params.lng = merchantForm.lng if (value != "") {
params.merchantAddress = merchantForm.merchantAddress date.month = date.month - 1
} endDate.config.min = date
$.each(fieldToFormNameList, function (index, item) { } else {
if (formData[item]) { endDate.config.min = startDate.config.min
merchantForm[item] = formData[item]
params[item] = formData[item]
}
})
var checkClassNameList = [{
attr: 'businessScope',
toString: ','
}, {
attr: 'accounttypeId',
toString: ','
}]
$.each(checkClassNameList, function (index, item) {
var checkedArr = []
$('input[class=' + item.attr + ']:checked').each(function () {
checkedArr.push($(this).val())
})
if (checkedArr.length) {
if (item.toString) {
merchantForm[item.attr] = checkedArr.join(item.toString)
params[item.attr] = checkedArr.join(item.toString)
} }
lay('#startDate').html(value)
} }
}) })
var elList = $('.business-scope-cust') var endDate = laydate.render({
var tempList = [] elem: '#endDate', //指定元素
$.each(elList, function (index, item) { type: 'time',
tempList.push(item.value) format: 'HH:mm:ss',
}) done: function (value, date) { //监听日期被切换
merchantForm.businessScopeCustomize = tempList.join(',') if (value != "") {
params.businessScopeCustomize = tempList.join(',') date.month = date.month - 1
merchantForm.merchantBrand = treeObj.getCheckedNodes(true) startDate.config.max = date
params.merchantBrand = findId(merchantForm.merchantBrand).join(',')
if (merchantForm.merchantFiles.length) {
params.merchantFiles = JSON.stringify(merchantForm.merchantFiles)
}
if (editLevel == 1) {
params.method = 'cn.com.glsx.merchants.merchant.saveMerchant'
} else if (editLevel == 2) {
if (!isFactory) {
params.parentId = parentInfo.parentId
}
params.method = 'cn.com.glsx.merchants.merchant.saveMerchant'
} else if (editLevel == 3) {
params.id = merchantId
if (!isFactory) {
params.parentId = parentInfo.parentId
}
params.method = 'cn.com.glsx.merchants.merchant.updateMerchant'
}
// 保存状态 1.草稿 2.发布 3.注销 4.过期
if (merchantForm.status) {
params.status = merchantForm.status
} else {
params.status = 1
}
console.log(editLevel)
console.log(params)
layer.msg('操作成功', {
icon: 1
})
// merchantId = 58
// merchantForm.merchantAccountLevel = parseInt(merchantForm.merchantAccountLevel)
// getMerchantApi(merchantId, function (res) {
// form.val('merchantForm', res.data)
// merchantForm = res.data
// baseIsShow(false)
// treeIsShow(true)
// getById()
// })
request(params, function (res) {
console.log(res)
// authorityTree
if (res.code == '0') {
if (editLevel == 3) {
layer.msg('操作成功', {
icon: 1
})
go('merchant', 'index')
} else { } else {
merchantId = res.data startDate.config.max = endDate.config.max
merchantForm.merchantAccountLevel = parseInt(merchantForm.merchantAccountLevel)
getMerchantApi(merchantId, function (respone) {
form.val('merchantForm', respone.data)
merchantForm = respone.data
baseIsShow(false)
treeIsShow(true)
getById()
})
} }
lay('#endDate').html(value)
} }
}) })
return false
})
function findId(nodeList) { init()
var idList = []
$.each(nodeList, function (index, item) {
idList.push(item.id)
})
return idList
}
// 按钮事件绑定 // helper.store.set('merchantMapObj', {
var btnHandle = { // lat: '116.397428',
// 选择地址 // lng: '39.90923',
handleSelectAddr: function () { // merchantAddress: '深圳'
helper.store.set('merchantMapObj', merchantForm) // })
layer.open({ // helper.store.set('merchantMapObj', merchantForm)
type: 2,
title: '选择地址',
area: ['900px', '600px'],
btn: ['确定', '取消'],
content: 'map.html',
success: function (layero, index) {
//向layer页面传值,传值主要代码
// var body = layer.getChildFrame('body', index)
// console.log(body)
//得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
// var iframeWin = window[layero.find('iframe')[0]['name']]
// console.log(iframeWin)
//将弹窗页面中属性名id="merchantAddress"的标签赋值 // console.log(validator.PHONEREG)
// body.find("[id='merchantAddress']").val('fhdskfls') // 校验
}, form.verify({
yes: function (index, layero) { // merchantOrgcode: function(value) {
// console.log(window["layui-layer-iframe" + index])
// var res = window["layui-layer-iframe" + index].callbackdata() // },
// console.log(res) residentPhone: function(value) {
var body = layer.getChildFrame('body', index) if(!validator.checkPhoneNumber(value)) {
body.find('#mapBtn').click() return '请填入正确的驻店电话'
var res = helper.store.get('merchantMapObj')
// console.log(res)
merchantForm.lat = res.lat
merchantForm.lng = res.lng
merchantForm.merchantAddress = res.merchantAddress
setInput('#addrEl', merchantForm.merchantAddress)
layer.close(index)
},
end: function () {
helper.store.remove('merchantMapObj')
} }
}) }
}, })
// 添加范围
handleAddScope(txt) {
var parent = $('#custom-scope')
var subParent = $('<div class="layui-form-item"><label class="layui-form-label"></label></div>')
var child1 = $(
'<div class="layui-input-inline"></div>'
)
var inputEl = $(
'<input class="layui-input business-scope-cust" maxlength="15" placeholder="请自定义营业范围,建议不超过10个">')
var child2 = $(
'<div class="layui-input-inline"></div>'
)
var addBtn = $( form.on('submit(handleFirstSubmit)', function (data) {
'<button type="button" class="layui-btn btn-no-border"><i class="layui-icon layui-icon-add-circle"></i></button>' // console.log(editLevel)
) // console.log(data.field)
var deleteBtn = $( var formData = data.field
'<button type="button" class="layui-btn btn-no-border"><i class="layui-icon layui-icon-reduce-circle"></i></button>' var params = {
) isloginName: 0
if (txt) { }
inputEl.val(txt) var fieldToFormNameList = ['channelId', 'merchantName', 'merchantAbbreviation', 'merchantType',
'merchantOrgcode',
'merchantLegalPerson', 'merchantLegalPersonPhone', 'residentContact', 'residentPhone',
'merchantLoginAccount', 'merchantLoginPassword',
'merchantAccountLevel', 'effectiveTime'
]
if (formData.isloginName == 'on') {
params.isloginName = 1
}
if (formData.bussinessBegintime) {
merchantForm.bussinessBegintime = formData.bussinessBegintime
params.bussinessBegintime = formData.bussinessBegintime
}
if (formData.bussinessEndtime) {
merchantForm.bussinessEndtime = formData.bussinessEndtime
params.bussinessEndtime = formData.bussinessEndtime
}
if (merchantForm.lat) {
params.lat = merchantForm.lat
params.lng = merchantForm.lng
params.merchantAddress = merchantForm.merchantAddress
}
$.each(fieldToFormNameList, function (index, item) {
if (formData[item]) {
merchantForm[item] = formData[item]
params[item] = formData[item]
}
})
var checkClassNameList = [{
attr: 'businessScope',
toString: ','
}, {
attr: 'accounttypeId',
toString: ','
}]
$.each(checkClassNameList, function (index, item) {
var checkedArr = []
$('input[class=' + item.attr + ']:checked').each(function () {
checkedArr.push($(this).val())
})
if (checkedArr.length) {
if (item.toString) {
merchantForm[item.attr] = checkedArr.join(item.toString)
params[item.attr] = checkedArr.join(item.toString)
}
}
})
var elList = $('.business-scope-cust')
var tempList = []
$.each(elList, function (index, item) {
tempList.push(item.value)
})
merchantForm.businessScopeCustomize = tempList.join(',')
params.businessScopeCustomize = tempList.join(',')
merchantForm.merchantBrand = treeObj.getCheckedNodes(true)
params.merchantBrand = findId(merchantForm.merchantBrand).join(',')
if (merchantForm.merchantFiles.length) {
params.merchantFiles = JSON.stringify(merchantForm.merchantFiles)
} }
addBtn.bind('click', function (e) { if (editLevel == 1) {
btnHandle.handleAddScope() params.method = 'cn.com.glsx.merchants.merchant.saveMerchant'
} else if (editLevel == 2) {
if (!isFactory) {
params.parentId = parentInfo.parentId
}
params.method = 'cn.com.glsx.merchants.merchant.saveMerchant'
} else if (editLevel == 3) {
params.id = merchantId
if (!isFactory) {
params.parentId = parentInfo.parentId
}
params.method = 'cn.com.glsx.merchants.merchant.updateMerchant'
}
// 保存状态 1.草稿 2.发布 3.注销 4.过期
if (merchantForm.status) {
params.status = merchantForm.status
} else {
params.status = 1
}
console.log(editLevel)
console.log(params)
layer.msg('操作成功', {
icon: 1
}) })
deleteBtn.bind('click', function (e) { request(params, function (res) {
var el = $(this).parent().parent() console.log(res)
el.remove() // authorityTree
if (res.code == '0') {
if (editLevel == 3) {
layer.msg('操作成功', {
icon: 1
})
go('merchant', 'index')
} else {
merchantId = res.data
merchantForm.merchantAccountLevel = parseInt(merchantForm.merchantAccountLevel)
getMerchantApi(merchantId, function (respone) {
form.val('merchantForm', respone.data)
merchantForm = respone.data
baseIsShow(false)
treeIsShow(true)
getById()
})
}
}
}) })
child1.append(inputEl)
child2.append(addBtn)
child2.append(deleteBtn)
subParent.append(child1)
subParent.append(child2)
parent.append(subParent)
},
handleCancel() {
go('merchant', 'index')
return false return false
} })
}
$('.layui-btn').on('click', function () { function findId(nodeList) {
var type = $(this).data('type') var idList = []
if (btnHandle[type]) { $.each(nodeList, function (index, item) {
btnHandle[type]() idList.push(item.id)
})
return idList
} }
})
$('.upload').on('change', function (e) { // 按钮事件绑定
// console.log(e) var btnHandle = {
var idx = $(this).data('idx') // 选择地址
var imgEl = $('#img' + idx) handleSelectAddr: function () {
var el = $('#upload' + idx) helper.store.set('merchantMapObj', merchantForm)
var addEl = $('.img-add' + idx) layer.open({
var reader = new FileReader() type: 2,
var fileInfo = el[0].files[0] title: '选择地址',
// console.log(el) area: ['900px', '600px'],
reader.readAsDataURL(fileInfo) btn: ['确定', '取消'],
reader.onload = function (e) { content: 'map.html',
if (e) { success: function (layero, index) {
const imgFile = e.target.result //向layer页面传值,传值主要代码
const base64 = fileInfo.name.split('.')[1] + '@' + imgFile.split(',')[1] // var body = layer.getChildFrame('body', index)
request({ // console.log(body)
method: 'glsx.accounts.biz.common.pictureUpload', //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
file: base64 // var iframeWin = window[layero.find('iframe')[0]['name']]
}, function (result) { // console.log(iframeWin)
merchantForm.merchantFiles[idx] = {
fileUrl: result.data, //将弹窗页面中属性名id="merchantAddress"的标签赋值
fileName: '' // body.find("[id='merchantAddress']").val('fhdskfls')
},
yes: function (index, layero) {
// console.log(window["layui-layer-iframe" + index])
// var res = window["layui-layer-iframe" + index].callbackdata()
// console.log(res)
var body = layer.getChildFrame('body', index)
body.find('#mapBtn').click()
var res = helper.store.get('merchantMapObj')
// console.log(res)
merchantForm.lat = res.lat
merchantForm.lng = res.lng
merchantForm.merchantAddress = res.merchantAddress
setInput('#addrEl', merchantForm.merchantAddress)
layer.close(index)
},
end: function () {
helper.store.remove('merchantMapObj')
} }
imgEl.attr('src', result.data) })
imgEl.removeClass('hide') },
imgEl.addClass('show') // 添加范围
addEl.removeClass('show') handleAddScope(txt) {
addEl.addClass('hide') var parent = $('#custom-scope')
}, {}, ['file'], true) var subParent = $('<div class="layui-form-item"><label class="layui-form-label"></label></div>')
var child1 = $(
'<div class="layui-input-inline"></div>'
)
var inputEl = $(
'<input class="layui-input business-scope-cust" maxlength="15" placeholder="请自定义营业范围,建议不超过10个">')
var child2 = $(
'<div class="layui-input-inline"></div>'
)
var addBtn = $(
'<button type="button" class="layui-btn btn-no-border"><i class="layui-icon layui-icon-add-circle"></i></button>'
)
var deleteBtn = $(
'<button type="button" class="layui-btn btn-no-border"><i class="layui-icon layui-icon-reduce-circle"></i></button>'
)
if (txt) {
inputEl.val(txt)
}
addBtn.bind('click', function (e) {
btnHandle.handleAddScope()
})
deleteBtn.bind('click', function (e) {
var el = $(this).parent().parent()
el.remove()
})
child1.append(inputEl)
child2.append(addBtn)
child2.append(deleteBtn)
subParent.append(child1)
subParent.append(child2)
parent.append(subParent)
},
handleCancel() {
go('merchant', 'index')
return false
} }
} }
reader.onload()
})
function baseIsShow(isShow) { $('.layui-btn').on('click', function () {
if (isShow) { var type = $(this).data('type')
$('#basicForm').show() if (btnHandle[type]) {
} else { btnHandle[type]()
$('#basicForm').hide() }
})
$('.upload').on('change', function (e) {
// console.log(e)
var idx = $(this).data('idx')
var imgEl = $('#img' + idx)
var el = $('#upload' + idx)
var addEl = $('.img-add' + idx)
var reader = new FileReader()
var fileInfo = el[0].files[0]
// console.log(el)
reader.readAsDataURL(fileInfo)
reader.onload = function (e) {
if (e) {
const imgFile = e.target.result
const base64 = fileInfo.name.split('.')[1] + '@' + imgFile.split(',')[1]
request({
method: 'glsx.accounts.biz.common.pictureUpload',
file: base64
}, function (result) {
merchantForm.merchantFiles[idx] = {
fileUrl: result.data,
fileName: ''
}
imgEl.attr('src', result.data)
imgEl.removeClass('hide')
imgEl.addClass('show')
addEl.removeClass('show')
addEl.addClass('hide')
}, {}, ['file'], true)
}
}
reader.onload()
})
function baseIsShow(isShow) {
if (isShow) {
$('#basicForm').show()
} else {
$('#basicForm').hide()
}
} }
}
function treeIsShow(isShow) { function treeIsShow(isShow) {
if (isShow) { if (isShow) {
$('#authorityTree').show() $('#authorityTree').show()
} else { } else {
$('#authorityTree').hide() $('#authorityTree').hide()
}
} }
}
function init() { function init() {
editLevel = qs('editLevel') editLevel = qs('editLevel')
isFactory = (qs('isFactory') == 'true') isFactory = (qs('isFactory') == 'true')
step = qs('step') step = qs('step')
if (step == 1) { if (step == 1) {
treeIsShow(false) treeIsShow(false)
} else { } else {
baseIsShow(false) baseIsShow(false)
} }
// 创建商户 // 创建商户
if (editLevel == 1) { if (editLevel == 1) {
$('#accountLevelEl').attr('disabled', true)
getBusiScope()
getCarBrandTree()
getAccountLevel()
getAccountType()
} else {
merchantId = qs('id')
$('#preStep').remove()
if (editLevel == 3) {
$('#firstBtn').text('确定')
$('#accountLevelEl').attr('disabled', true) $('#accountLevelEl').attr('disabled', true)
} else {
getBusiScope() getBusiScope()
getCarBrandTree() getCarBrandTree()
getAccountLevel()
getAccountType() getAccountType()
} else {
merchantId = qs('id')
$('#preStep').remove()
if (editLevel == 3) {
$('#firstBtn').text('确定')
$('#accountLevelEl').attr('disabled', true)
} else {
getBusiScope()
getCarBrandTree()
getAccountType()
}
if (isFactory) {
getAccountLevel()
getMerchantInfo()
} else {
// 创建/编辑子商户
parentMerchantId = qs('parentId')
// $('#validPeriodEl').attr('disabled', true)
$('#channelEl').attr('disabled', true)
getParentInfo()
}
} }
if (isFactory) { if (isFactory) {
getAccountLevel() $('#subMerchantEl').hide()
getMerchantInfo()
} else {
// 创建/编辑子商户
parentMerchantId = qs('parentId')
// $('#validPeriodEl').attr('disabled', true)
$('#channelEl').attr('disabled', true)
getParentInfo()
} }
}
if (isFactory) { getChannel()
$('#subMerchantEl').hide() getPeriod()
} }
getChannel() function bindEvent() {
getPeriod() $('#brand').on('input', helper.debounce(function () {
} var txt = $(this).val()
if (!txt) {
treeObj.showNodes(all_nodes)
} else {
var show_nodes = treeObj.getNodesByParamFuzzy('label', txt)
treeObj.hideNodes(all_nodes)
treeObj.showNodes(show_nodes)
}
}, 500))
}
function bindEvent() { function setCheckbox(checkedStr, attr) {
$('#brand').on('input', helper.debounce(function () { if (!checkedStr || !checkedStr.length) {
var txt = $(this).val() return false
if (!txt) { }
treeObj.showNodes(all_nodes) var list = []
if (layui._isArray(checkedStr)) {
list = checkedStr
} else { } else {
var show_nodes = treeObj.getNodesByParamFuzzy('label', txt) list = checkedStr.split(',')
treeObj.hideNodes(all_nodes)
treeObj.showNodes(show_nodes)
} }
}, 500)) // console.log(list)
} $.each(list, function (index, item) {
$('input[class=' + attr + ']').attr("checked", true)
function setCheckbox(checkedStr, attr) { })
if (!checkedStr || !checkedStr.length) {
return false
}
var list = []
if (layui._isArray(checkedStr)) {
list = checkedStr
} else {
list = checkedStr.split(',')
} }
// console.log(list)
$.each(list, function (index, item) {
$('input[class=' + attr + ']').attr("checked", true)
})
}
function getMerchantApi(id, fn) { function getMerchantApi(id, fn) {
request({ request({
method: 'cn.com.glsx.merchants.merchant.findMerchantDetail', method: 'cn.com.glsx.merchants.merchant.findMerchantDetail',
id: id id: id
}, function (res) { }, function (res) {
fn && fn(res) fn && fn(res)
}) })
} }
// 子商户 - 获取父商户信息 // 子商户 - 获取父商户信息
function getParentInfo() { function getParentInfo() {
// console.log(parentMerchantId) // console.log(parentMerchantId)
getMerchantApi(parentMerchantId, function (res) { getMerchantApi(parentMerchantId, function (res) {
// console.log(res.data) // console.log(res.data)
var data = res.data var data = res.data
parentInfo = { parentInfo = {
parentId: data.id, parentId: data.id,
parentName: data.merchantName, parentName: data.merchantName,
parentAccountTypeName: data.accountTypeNames, parentAccountTypeName: data.accountTypeNames,
parentAccountType: data.merchantType, parentAccountType: data.merchantType,
channelId: data.channelId, channelId: data.channelId,
effectiveTime: data.effectiveTime effectiveTime: data.effectiveTime
} }
form.val('merchantForm', parentInfo) form.val('merchantForm', parentInfo)
if (editLevel == 3) { if (editLevel == 3) {
getMerchantInfo() getMerchantInfo()
$('#accountLevelEl').attr('disabled', true) $('#accountLevelEl').attr('disabled', true)
} }
getAccountLevel() getAccountLevel()
}) })
} }
// 获取商户信息 // 获取商户信息
function getMerchantInfo() { function getMerchantInfo() {
getMerchantApi(merchantId, function (res) { getMerchantApi(merchantId, function (res) {
form.val('merchantForm', res.data) form.val('merchantForm', res.data)
merchantForm = res.data merchantForm = res.data
if (merchantForm.status != 1) { if (merchantForm.status != 1) {
$('#draft').remove() $('#draft').remove()
} }
console.log(merchantForm) console.log(merchantForm)
getBusiScope() getBusiScope()
getCarBrandTree() getCarBrandTree()
getAccountType() getAccountType()
recoveryBusiScopeCus() recoveryBusiScopeCus()
recoveryFile() recoveryFile()
// if (merchantForm.status == 1) { // if (merchantForm.status == 1) {
// findMenuFunTreeByMerId() // findMenuFunTreeByMerId()
// } else { // } else {
getById() getById()
// } // }
}) })
} }
// 渠道 // 渠道
function getChannel() { function getChannel() {
getDictData('channel', function (res) { getDictData('channel', function (res) {
baseData.channelList = res.data baseData.channelList = res.data
setSelectOption('#channelEl', 'channelList', 'dictValue', 'dictLabel') setSelectOption('#channelEl', 'channelList', 'dictValue', 'dictLabel')
}) })
} }
// 品牌 // 品牌
function getCarBrandTree() { function getCarBrandTree() {
request({ request({
method: 'cn.com.glsx.merchants.merchantCommon.getCarbrandTree' method: 'cn.com.glsx.merchants.merchantCommon.getCarbrandTree'
}, function (res) { }, function (res) {
baseData.carBrandTreeList = res.data baseData.carBrandTreeList = res.data
var checkedList = [] var checkedList = []
if (editLevel == 3 && merchantForm.merchantBrand) { if (editLevel == 3 && merchantForm.merchantBrand) {
checkedList = merchantForm.merchantBrand.split(',') checkedList = merchantForm.merchantBrand.split(',')
$.each(checkedList, function (index, item) { $.each(checkedList, function (index, item) {
checkedList[index] = parseInt(item) checkedList[index] = parseInt(item)
})
}
treeObj = tree.create('carBrandTree', res.data, {
checkedList: checkedList
}) })
} all_nodes = treeObj.getNodes()
treeObj = tree.create('carBrandTree', res.data, { bindEvent()
checkedList: checkedList
}) })
all_nodes = treeObj.getNodes() }
bindEvent() // 获取字典数据
}) function getDictData(dictType, fn) {
} request({
// 获取字典数据 method: 'cn.com.glsx.merchants.menu.findAllDictData',
function getDictData(dictType, fn) { dictType: dictType
request({ }, function (res) {
method: 'cn.com.glsx.merchants.menu.findAllDictData', fn && fn(res)
dictType: dictType })
}, function (res) { }
fn && fn(res)
})
}
// 设置option
function setSelectOption(elName, listName, optionId, optionLabel) {
var el = $(elName)
$.each(baseData[listName], function (index, item) {
el.append(new Option(item[optionLabel], item[optionId]))
})
form.render('select')
}
// 设置input值
function setInput(elName, value) {
$(elName).val(value)
}
// 账户等级 // 设置option
function getAccountLevel() { function setSelectOption(elName, listName, optionId, optionLabel) {
getDictData('account_level', function (res) { var el = $(elName)
baseData.accountLevelList = res.data $.each(baseData[listName], function (index, item) {
console.log(baseData.accountLevelList) el.append(new Option(item[optionLabel], item[optionId]))
if (!isFactory) { })
var tempList = [] form.render('select')
$.each(baseData.accountLevelList, function (index, item) { }
if (item.dictValue > parentInfo.parentAccountType) {
tempList.push(baseData.accountLevelList[index])
}
})
baseData.accountLevelList = tempList
}
setSelectOption('#accountLevelEl', 'accountLevelList', 'dictValue', 'dictLabel')
})
}
// 有效期 // 设置input值
function getPeriod() { function setInput(elName, value) {
getDictData('account_validity_period', function (res) { $(elName).val(value)
baseData.validPeriodList = res.data }
setSelectOption('#validPeriodEl', 'validPeriodList', 'dictValue', 'dictLabel')
})
}
// 营业范围 // 账户等级
function getBusiScope() { function getAccountLevel() {
getDictData('business_scope', function (res) { getDictData('account_level', function (res) {
baseData.busiScopeList = res.data baseData.accountLevelList = res.data
var checkedList = [] // console.log(baseData.accountLevelList)
if (editLevel == 3 && merchantForm.businessScope) { if (!isFactory) {
checkedList = merchantForm.businessScope.split(',') var tempList = []
} $.each(baseData.accountLevelList, function (index, item) {
var el = $('#busiScopeEl') if (item.dictValue > parentInfo.parentAccountType) {
$.each(baseData.busiScopeList, function (index, item) { tempList.push(baseData.accountLevelList[index])
var optionEl = $('<input type="checkbox" class="businessScope" name="businessScope[' + item
.dictValue + ']" title=' +
item.dictLabel + ' value="' + item.dictValue + '" lay-skin="primary">')
// 修改-回显
if (editLevel == 3) {
for (var i = 0; i <= checkedList.length; i++) {
if (checkedList[i] == item.dictValue) {
optionEl.attr("checked", true)
break
} }
} })
baseData.accountLevelList = tempList
} }
el.append(optionEl) setSelectOption('#accountLevelEl', 'accountLevelList', 'dictValue', 'dictLabel')
form.render('checkbox')
}) })
}) }
}
// 恢复自定义营业范围 // 有效期
function recoveryBusiScopeCus() { function getPeriod() {
// console.log(merchantForm.businessScopeCustomize) getDictData('account_validity_period', function (res) {
if (merchantForm.businessScopeCustomize) { baseData.validPeriodList = res.data
var scopeCusList = merchantForm.businessScopeCustomize.split(',') setSelectOption('#validPeriodEl', 'validPeriodList', 'dictValue', 'dictLabel')
$.each(scopeCusList, function (index, item) {
if (index != 0) {
btnHandle.handleAddScope(item)
} else {
$('#scopeCus').val(item)
}
}) })
} }
}
// 恢复图片 // 营业范围
function recoveryFile() { function getBusiScope() {
// console.log(merchantForm.merchantFileResponses) getDictData('business_scope', function (res) {
merchantForm.merchantFiles = [] baseData.busiScopeList = res.data
$.each(merchantForm.merchantFileResponses, function (index, item) { var checkedList = []
var imgEl = $('#img' + index) if (editLevel == 3 && merchantForm.businessScope) {
var el = $('#upload' + index) checkedList = merchantForm.businessScope.split(',')
var addEl = $('.img-add' + index) }
merchantForm.merchantFiles[index] = { var el = $('#busiScopeEl')
fileUrl: item.fileUrl, $.each(baseData.busiScopeList, function (index, item) {
fileName: item.fileName var optionEl = $('<input type="checkbox" class="businessScope" name="businessScope[' + item
} .dictValue + ']" title=' +
imgEl.attr('src', item.fileUrl) item.dictLabel + ' value="' + item.dictValue + '" lay-skin="primary">')
imgEl.removeClass('hide') // 修改-回显
imgEl.addClass('show') if (editLevel == 3) {
addEl.removeClass('show') for (var i = 0; i <= checkedList.length; i++) {
addEl.addClass('hide') if (checkedList[i] == item.dictValue) {
}) optionEl.attr("checked", true)
} break
}
// 账户类型
function getAccountType() {
getDictData('account_type', function (res) {
// console.log(res.data)
baseData.accountTypeList = res.data
var checkedList = []
if (editLevel == 3 && merchantForm.accountType) {
checkedList = merchantForm.accountType.split(',')
}
var el = $('#accountTypeEl')
$.each(baseData.accountTypeList, function (index, item) {
var optionEl = $('<input type="checkbox" class="accounttypeId" name="accountType[' + item
.dictValue + ']" title=' +
item.dictLabel + ' value="' + item.dictValue + '">')
// 修改-回显
if (editLevel == 3) {
for (var i = 0; i <= checkedList.length; i++) {
if (checkedList[i] == item.dictValue) {
optionEl.attr("checked", true)
break
} }
} }
} el.append(optionEl)
el.append(optionEl) form.render('checkbox')
form.render('checkbox') })
}) })
}) }
}
// 数 - start // 恢复自定义营业范围
var laytpl = layui.laytpl function recoveryBusiScopeCus() {
var xmSelect = layui.xmSelect // console.log(merchantForm.businessScopeCustomize)
var check_arr = [] if (merchantForm.businessScopeCustomize) {
var requestList = [] var scopeCusList = merchantForm.businessScopeCustomize.split(',')
var templateData = {} $.each(scopeCusList, function (index, item) {
var selectEl = {} if (index != 0) {
var treeData = {} btnHandle.handleAddScope(item)
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) {
// console.log(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 =
'<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>'
// var getTpl = tpl//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 { } else {
var productId = 'tab_' + id + '_' + change[0].value $('#scopeCus').val(item)
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
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
}) })
} }
} }
}
// 复选框的change事件 // 恢复图片
// form.on('checkbox(switch)', function (data) { function recoveryFile() {
// var arr = [] // console.log(merchantForm.merchantFileResponses)
// if (data.elem.checked) { merchantForm.merchantFiles = []
// var obj = { $.each(merchantForm.merchantFileResponses, function (index, item) {
// title: data.elem.title, var imgEl = $('#img' + index)
// value: data.elem.value var el = $('#upload' + index)
// } var addEl = $('.img-add' + index)
// arr.push({ merchantForm.merchantFiles[index] = {
// accounttypeId: data.elem.value fileUrl: item.fileUrl,
// }) fileName: item.fileName
// active.tabAdd(obj) }
// } else { imgEl.attr('src', item.fileUrl)
// for (var i in arr) { imgEl.removeClass('hide')
// var id = arr[i].accounttypeId imgEl.addClass('show')
// if (arr[i].accounttypeId == data.elem.value) { addEl.removeClass('show')
// active.tabDelete('roleAuth', id) addEl.addClass('hide')
// 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() { function getAccountType() {
console.log(merchantForm, '查询商户菜单权限树') getDictData('account_type', function (res) {
console.log(parentMerchantId, 'parentMerchantId') // console.log(res.data)
var params = {} baseData.accountTypeList = res.data
if (parentMerchantId) { var checkedList = []
params = { if (editLevel == 3 && merchantForm.accountType) {
method: 'cn.com.glsx.merchants.merchant.findMenuFunTreeByMerId', checkedList = merchantForm.accountType.split(',')
id: merchantId, }
parentId: parentMerchantId, var el = $('#accountTypeEl')
accountLevel: merchantForm.merchantAccountLevel $.each(baseData.accountTypeList, function (index, item) {
} var optionEl = $('<input type="checkbox" class="accounttypeId" name="accountType[' + item
} else { .dictValue + ']" title=' +
params = { item.dictLabel + ' value="' + item.dictValue + '">')
method: 'cn.com.glsx.merchants.merchant.accountTypeSearchRequest', // 修改-回显
// method: 'org.ore.api.accountType.getProductTreeList', if (editLevel == 3) {
ids: merchantForm.accountType, for (var i = 0; i <= checkedList.length; i++) {
merchantId: merchantId, if (checkedList[i] == item.dictValue) {
accountLevel: merchantForm.merchantAccountLevel optionEl.attr("checked", true)
} break
}
}
}
el.append(optionEl)
form.render('checkbox')
})
})
} }
console.log(params.method)
request(params, function (res) { // 数 - start
if (res.code == '0') { var laytpl = layui.laytpl
// callback(res.data) var xmSelect = layui.xmSelect
menuFunTreeData = res.data var check_arr = []
// console.log(menuFunTreeData) var requestList = []
var accountType = $('#accountType') 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) {
// console.log(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 =
'<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>'
// var getTpl = tpl//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) { $.each(menuFunTreeData, function (index, item) {
// console.log(item) if (item.accounttypeId == id) {
var str = $('<input lay-filter="switch" type="checkbox" name="accounttypeId" value="' + item products = item.products
.accounttypeId + '" title="' + item.accounttypeName + '" />') $.each(item.products, function (idx, i) {
accountType.append(str) productList.push({
// console.log(check_arr, '0000000000') name: i.productName,
if (merchantId) { value: i.productId
// 角色权限的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) selectEl[id] = xmSelect.render({
var obj = { el: '#select' + id,
title: item.accounttypeName, data: productList,
value: item.accounttypeId on: function (data) {
} //arr: 当前多选已选中的数据
active.tabAdd(obj) var arr = data.arr
var selectArr = [] //change, 此次选择变化的数据,数组
var menuData = [] var change = data.change
for (var j = 0; j < productData.products.length; j++) { //isAdd, 此次操作是新增还是删除
menuData = productData.products[j] var isAdd = data.isAdd
selectArr.push(menuData.productId) var filterName = 'treeTab' + id
var idList = menuData.menuIds.concat(menuData.functionIds) if (isAdd) {
active.treeTabAdd({ active.treeTabAdd(change[0], id, products)
name: menuData.productName, } else {
value: menuData.productId var productId = 'tab_' + id + '_' + change[0].value
}, item.accounttypeId, item.products, idList) active.tabDelete(filterName, productId)
}
// // 产品的回显
selectEl[item.accounttypeId].setValue(selectArr)
var filterName = 'treeTab' + item.accounttypeId
var productId = 'tab_' + item.accounttypeId + '_' + item.products[0].productId
active.tabChange(filterName, productId)
// 树的回显
}
} }
if (check_arr.length != 0) { if (arr.length != 0) {
active.tabChange('roleAuth', check_arr[0].accounttypeId) var productId = 'tab_' + id + '_' + arr[0].value
active.tabChange(filterName, productId)
} }
} }
}) })
form.render('checkbox') 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
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
})
}
} }
})
}
// 根据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') { // 复选框的change事件
// console.log(res.data, '角色详情') // form.on('checkbox(switch)', function (data) {
var accounttypeId = '' // var arr = []
if (res.data) { // if (data.elem.checked) {
check_arr = res.data // 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, '查询商户菜单权限树')
// console.log(parentMerchantId, 'parentMerchantId')
var params = {}
if (parentMerchantId) {
params = {
method: 'cn.com.glsx.merchants.merchant.findMenuFunTreeByMerId',
id: merchantId,
parentId: parentMerchantId,
accountLevel: merchantForm.merchantAccountLevel
}
} else {
params = {
method: 'cn.com.glsx.merchants.merchant.accountTypeSearchRequest',
// method: 'org.ore.api.accountType.getProductTreeList',
ids: merchantForm.accountType,
merchantId: merchantId,
accountLevel: merchantForm.merchantAccountLevel
} }
console.log(check_arr, '角色详情check_arr')
findMenuFunTreeByMerId()
form.val('roleForm', {
roleName: res.data.roleName,
roleDescription: res.data.roleDescription
})
} }
}) // console.log(params.method)
} 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)
// console.log(check_arr, '0000000000')
if (merchantId) {
// 角色权限的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)
var idList = menuData.menuIds.concat(menuData.functionIds)
active.treeTabAdd({
name: menuData.productName,
value: menuData.productId
}, item.accounttypeId, item.products, idList)
}
// // 产品的回显
selectEl[item.accounttypeId].setValue(selectArr)
var filterName = 'treeTab' + item.accounttypeId
var productId = 'tab_' + item.accounttypeId + '_' + item.products[0].productId
active.tabChange(filterName, productId)
// 树的回显
}
}
if (check_arr.length != 0) {
active.tabChange('roleAuth', check_arr[0].accounttypeId)
}
// 获取角色权限数据requestList }
function getAuthList() { })
requestList = [] form.render('checkbox')
for (var key in treeData) { }
var accountObj = treeData[key] })
var productList = [] }
for (var i in accountObj) {
var productObj = accountObj[i] // 根据id获取角色详情
var menuIds = [] function getById() {
var functionIds = [] var params = {
var functionIdLists = [] method: 'cn.com.glsx.merchants.merchant.findPermissionsByMerId',
var nodes = productObj.treeObj.getCheckedNodes(true) // method: 'org.ore.api.role.getById',
$.each(nodes, function (index, item) { id: merchantId
if (item.logo == 'function') { }
functionIdLists.push(item) request(params, function (res) {
} else { if (res.code == '0') {
menuIds.push(item.id) // console.log(res.data, '角色详情')
var accounttypeId = ''
if (res.data) {
check_arr = res.data
} }
}) // console.log(check_arr, '角色详情check_arr')
$.each(functionIdLists, function (idx, m) { findMenuFunTreeByMerId()
// m.parentId form.val('roleForm', {
var findIdx = -1 roleName: res.data.roleName,
$.each(functionIds, function (idn, n) { roleDescription: res.data.roleDescription
if (n.mendId == m.parentId) { })
findIdx = idn }
})
}
// 获取角色权限数据requestList
function getAuthList() {
requestList = []
for (var key in treeData) {
var accountObj = treeData[key]
var productList = []
for (var i in accountObj) {
var productObj = accountObj[i]
var menuIds = []
var functionIds = []
var functionIdLists = []
var nodes = productObj.treeObj.getCheckedNodes(true)
$.each(nodes, function (index, item) {
if (item.logo == 'function') {
functionIdLists.push(item)
} else {
menuIds.push(item.id)
} }
}) })
if (findIdx != -1) { $.each(functionIdLists, function (idx, m) {
functionIds[findIdx].functionValue += ';' + m.id + ':' + m.label // m.parentId
} else { var findIdx = -1
functionIds.push({ $.each(functionIds, function (idn, n) {
functionId: m.parentId, if (n.mendId == m.parentId) {
mendId: m.superParentId, findIdx = idn
functionValue: m.id + ':' + m.label }
}) })
} if (findIdx != -1) {
}) functionIds[findIdx].functionValue += ';' + m.id + ':' + m.label
productList.push({ } else {
productId: productObj.productId, functionIds.push({
functionIds: functionIds, functionId: m.parentId,
menuIds: menuIds mendId: m.superParentId,
functionValue: m.id + ':' + m.label
})
}
})
productList.push({
productId: productObj.productId,
functionIds: functionIds,
menuIds: menuIds
})
}
requestList.push({
accountTypeId: key,
products: productList
}) })
} }
requestList.push({ // console.log(requestList)
accountTypeId: key,
products: productList
})
} }
// console.log(requestList)
}
$('#draft').on('click', function () { $('#draft').on('click', function () {
getAuthList() getAuthList()
console.log(requestList) console.log(requestList)
var params = { var params = {
merchantId: merchantId, merchantId: merchantId,
accountTypes: JSON.stringify(requestList), accountTypes: JSON.stringify(requestList),
method: 'cn.com.glsx.merchants.merchant.updatePermissions', method: 'cn.com.glsx.merchants.merchant.updatePermissions',
status: merchantForm.status status: merchantForm.status
}
request(params, function (res) {
console.log(res.data)
if (res.code == '0') {
layer.msg('操作成功', {
icon: 1
})
go('merchant', 'index')
} }
request(params, function (res) {
console.log(res.data)
if (res.code == '0') {
layer.msg('操作成功', {
icon: 1
})
go('merchant', 'index')
}
})
return false
}) })
return false
})
$('#preStep').on('click', function () { $('#preStep').on('click', function () {
step = 1 step = 1
init() init()
}) })
$('#confirm').on('click', function () { $('#confirm').on('click', function () {
// console.log(treeData) // console.log(treeData)
getAuthList() getAuthList()
console.log(merchantForm) console.log(merchantForm)
console.log(requestList) console.log(requestList)
// 草稿 // 草稿
var params = { var params = {
merchantId: merchantId, merchantId: merchantId,
accountTypes: JSON.stringify(requestList) accountTypes: JSON.stringify(requestList)
}
params.method = 'cn.com.glsx.merchants.merchant.updatePermissions'
if (merchantForm.status == 1) {
params.status = 2
} else {
params.status = merchantForm.status
}
request(params, function (res) {
console.log(res.data)
if (res.code == '0') {
layer.msg('操作成功', {
icon: 1
})
go('merchant', 'index')
} }
params.method = 'cn.com.glsx.merchants.merchant.updatePermissions'
if (merchantForm.status == 1) {
params.status = 2
} else {
params.status = merchantForm.status
}
request(params, function (res) {
console.log(res.data)
if (res.code == '0') {
layer.msg('操作成功', {
icon: 1
})
go('merchant', 'index')
}
})
return false
}) })
return false
}) })
})
</script> </script>
<script type="text/html" id="rolesAuth"> <script type="text/html" id="rolesAuth">
<div id="select{{d.id}}"></div> <div id="select{{d.id}}"></div>
......
layui.define(['store'], function (exports) {
var validator = {
/* 手机号码格式校验正则 */
PHONEREG: /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/,
/* 同时包含字母和数字 */
ISNUMANDLETTERS: /^[a-zA-Z0-9]+$/,
/* 特殊字符正则 */
SPECIALLETTER: new RegExp("[`~!@#$^&*=|{}':;',\\[\\]<>?~!@#¥……&*——|{}【】‘;:”“'。,、? ]"),
/* 邮箱地址格式正则 */
// EMAILREG:/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/,
EMAILREG: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
/* 判断是否为中文 */
ISCHINESE: /^[\u0391-\uFFE5]+$/,
/* 判断是否为英文字母 */
ISENGLISH: /^[a-zA-Z]+$/,
/* 是否包含空格 */
ISHAVENULL: /^[^\s]*$/,
/* 保留两位小数 */
TWODECIMAL: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
/* 判断是否为正整数 */
ISDECIMAL: /^[0-9]*$/,
/**
* 账号管理-手机号码校验
*/
checkPhoneNumber: function (str) {
return validator.PHONEREG.test(str)
},
// 判断是否含有数字或字母
checkNumOrLetters: function (str) {
return validator.ISNUMANDLETTERS.test(str)
},
// 身份证验证
// checkIdCard: function (code) {
// var city = {
// 11: '北京',
// 12: '天津',
// 13: '河北',
// 14: '山西',
// 15: '内蒙古',
// 21: '辽宁',
// 22: '吉林',
// 23: '黑龙江',
// 31: '上海',
// 32: '江苏',
// 33: '浙江',
// 34: '安徽',
// 35: '福建',
// 36: '江西',
// 37: '山东',
// 41: '河南',
// 42: '湖北',
// 43: '湖南',
// 44: '广东',
// 45: '广西',
// 46: '海南',
// 50: '重庆',
// 51: '四川',
// 52: '贵州',
// 53: '云南',
// 54: '西藏',
// 61: '陕西',
// 62: '甘肃',
// 63: '青海',
// 64: '宁夏',
// 65: '新疆',
// 71: '台湾',
// 81: '香港',
// 82: '澳门',
// 91: '国外 '
// }
// // var tip = ''
// var pass = true
// // 身份证位数为15或18位
// // if (![15, 18].includes(code.length)) {
// if ((code.length != 15) || (code.length != 18)) {
// pass = false
// } else if (!code || (code.length === 18 && !/^\d{6}(18|19|20)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code))) {
// // tip = '身份证号格式错误'
// pass = false
// } else if (code.length === 15 && !/^\d{6}\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}$/i.test(code)) {
// pass = false
// } else if (!city[code.substr(0, 2)]) {
// // tip = '地址编码错误'
// pass = false
// } else {
// // 18位身份证需要验证最后一位校验位
// if (code.length === 18) {
// code = code.split('')
// // ∑(ai×Wi)(mod 11)
// // 加权因子
// var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
// // 校验位
// var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
// var sum = 0
// var ai = 0
// var wi = 0
// for (var i = 0; i < 17; i++) {
// ai = code[i]
// wi = factor[i]
// sum += ai * wi
// }
// // var last = parity[sum % 11]
// if (parity[sum % 11] != code[17]) {
// // tip = '校验位错误'
// pass = false
// }
// }
// }
// // if (!pass) alert(tip)
// return pass
// }
}
exports('validator', validator)
})
\ 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!