250 lines
7.4 KiB
HTML
250 lines
7.4 KiB
HTML
{extend name="base"/}
|
|
{block name="resources"}
|
|
<style>
|
|
.form-wrap {margin-top: 0;}
|
|
.align-center {text-align: center!important;}
|
|
.manage-store {display: none}
|
|
.manage-store .store-group {width: 200px;margin: 0 auto}
|
|
</style>
|
|
{/block}
|
|
{block name="main"}
|
|
<div class="layui-form form-wrap">
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label"><span class="required">*</span>用户名:</label>
|
|
<div class="layui-input-block">
|
|
<input name="username" type="text" lay-verify="required" placeholder="请输入员工用户名" autocomplete="off" readonly onfocus="this.removeAttribute('readonly');" onblur="this.setAttribute('readonly',true);" class="layui-input len-long">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label"><span class="required">*</span>密码:</label>
|
|
<div class="layui-input-block">
|
|
<input name="password" type="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input len-long" readonly onfocus="this.removeAttribute('readonly');" onblur="this.setAttribute('readonly',true);">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label"><span class="required">*</span>再次输入密码:</label>
|
|
<div class="layui-input-block">
|
|
<input name="repassword" type="password" lay-verify="required|repassword" placeholder="请输入密码" autocomplete="off" class="layui-input len-long" readonly onfocus="this.removeAttribute('readonly');" onblur="this.setAttribute('readonly',true);">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">{if !$cashier_is_exit}<span class="required">*</span>{/if}员工角色:</label>
|
|
<div class="layui-input-block len-mid">
|
|
<select name="group_id" {if !$cashier_is_exit}lay-verify="groupid"{/if}>
|
|
<option value="">选择角色</option>
|
|
{foreach $group_list as $group_list_k => $group_list_v}
|
|
<option value="{$group_list_v.group_id}">{$group_list_v.group_name}</option>
|
|
{/foreach}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
{if $store_is_exit}
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">管理门店:</label>
|
|
<div class="layui-input-block len-mid">
|
|
<button class="layui-btn select-store">选择门店</button>
|
|
</div>
|
|
</div>
|
|
<div class="layui-form-item manage-store">
|
|
<label class="layui-form-label"></label>
|
|
<div class="layui-input-block" style="width: 600px">
|
|
<table class="layui-table" lay-skin="nob">
|
|
<colgroup>
|
|
<col width="40%">
|
|
<col width="40%">
|
|
<col width="20%">
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th>门店</th>
|
|
<th class="align-center">门店角色</th>
|
|
<th class="align-center">操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
{elseif $cashier_is_exit}
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">门店角色:</label>
|
|
<div class="layui-input-block len-mid">
|
|
<select name="store_group">
|
|
<option value="">请选择门店角色</option>
|
|
{foreach name="store_user_group" item="vo"}
|
|
<option value="{$vo.group_id}">{$vo.group_name}</option>
|
|
{/foreach}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<input type="hidden" name="default_store_id" value="{$default_store_id}">
|
|
{/if}
|
|
|
|
<div class="form-row">
|
|
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
|
|
<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
|
|
</div>
|
|
</div>
|
|
|
|
{if isset($store_user_group)}
|
|
<script id="storeGroup" type="text/html">
|
|
<select name="store_group" lay-verify="storegroupid" lay-filter="store_group">
|
|
<option value="">请选择门店角色</option>
|
|
{foreach name="store_user_group" item="vo"}
|
|
<option value="{$vo.group_id}">{$vo.group_name}</option>
|
|
{/foreach}
|
|
</select>
|
|
</script>
|
|
{/if}
|
|
|
|
{/block}
|
|
{block name="script"}
|
|
<script>
|
|
var storeGroup = {};
|
|
layui.use('form', function() {
|
|
var form = layui.form,
|
|
repeat_flag = false;//防重复标识
|
|
form.render();
|
|
|
|
/**
|
|
* 监听提交
|
|
*/
|
|
form.on('submit(save)', function(data) {
|
|
data.field.store = [];
|
|
{if $store_is_exit}
|
|
$('.manage-store tbody tr').each(function () {
|
|
data.field.store.push({
|
|
store_id: $(this).attr('data-store'),
|
|
group_id: $(this).find('[name="store_group"]').val()
|
|
});
|
|
})
|
|
{elseif $cashier_is_exit}
|
|
if (data.field.store_group) {
|
|
data.field.store.push({
|
|
store_id: data.field.default_store_id,
|
|
group_id: data.field.store_group
|
|
});
|
|
}
|
|
{/if}
|
|
{if $cashier_is_exit}
|
|
if (!data.field.group_id && !data.field.store.length) {
|
|
layer.msg('员工角色和门店角色至少需设置一项', {icon: 5});
|
|
return;
|
|
}
|
|
{/if}
|
|
data.field.store = JSON.stringify(data.field.store);
|
|
|
|
if (repeat_flag) return;
|
|
repeat_flag = true;
|
|
|
|
$.ajax({
|
|
dataType: 'JSON',
|
|
type: 'POST',
|
|
url: ns.url("shop/user/addUser"),
|
|
data: data.field,
|
|
success: function(res){
|
|
repeat_flag = false;
|
|
if (res.code == 0) {
|
|
layer.confirm('添加员工已成功', {
|
|
title:'操作提示',
|
|
btn: ['返回列表', '继续添加'],
|
|
closeBtn: 0,
|
|
yes: function(){
|
|
location.href = ns.url("shop/user/user")
|
|
},
|
|
btn2: function() {
|
|
location.href = ns.url("shop/user/addUser")
|
|
}
|
|
})
|
|
}else{
|
|
layer.msg(res.message);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 表单验证
|
|
*/
|
|
form.verify({
|
|
repassword: function (value) {
|
|
if (value.length == 0) {
|
|
return '请输入密码!';
|
|
}
|
|
var pw = $("input[name='password']").val();
|
|
if(value != pw){
|
|
return '两次密码输入不一致!';
|
|
}
|
|
},
|
|
groupid: function (value) {
|
|
if(value == 0) {
|
|
return '请选择角色!';
|
|
}
|
|
},
|
|
storegroupid: function (value) {
|
|
if(!value) {
|
|
return '请选择门店角色!';
|
|
}
|
|
},
|
|
});
|
|
|
|
form.on('select(store_group)', function (data) {
|
|
var store_id = $(data.elem).parents('tr').attr('data-store');
|
|
storeGroup['store_' + store_id] = data.value;
|
|
})
|
|
|
|
// 选择门店
|
|
$('.select-store').click(function () {
|
|
var storeId = [];
|
|
$('.manage-store tbody tr').each(function () {
|
|
storeId.push($(this).attr('data-store'));
|
|
})
|
|
storeSelect(function (store) {
|
|
fetchStore(store);
|
|
}, {store_id: storeId.toString()})
|
|
})
|
|
|
|
function fetchStore(store){
|
|
if (store.length) {
|
|
$('.manage-store').show();
|
|
var h = '', group = $('#storeGroup').html();
|
|
store.forEach(function (item) {
|
|
h += `<tr data-store="`+ item.store_id +`">
|
|
<td>`+ item.store_name +`</td>
|
|
<td><div class="store-group">`+ group +`</div></td>
|
|
<td class="align-center"><a href="javascript:;" class="del">删除</a></td>
|
|
</tr>`;
|
|
})
|
|
$('.manage-store tbody').html(h);
|
|
|
|
Object.keys(storeGroup).forEach(function (key) {
|
|
let group = storeGroup[key], store_id = key.replace('store_', '');
|
|
$('.manage-store tr[data-store="'+ store_id +'"] option[value="'+ group +'"]').prop('selected', true);
|
|
})
|
|
form.render();
|
|
} else {
|
|
$('.manage-store tbody').html('');
|
|
$('.manage-store').hide();
|
|
}
|
|
}
|
|
|
|
// 删除门店
|
|
$('body').on('click', '.manage-store .del', function () {
|
|
let store_id = $(this).parents('tr').attr('data-store')
|
|
if (storeGroup['store_' + store_id]) delete storeGroup['store_' + store_id];
|
|
$(this).parents('tr').remove();
|
|
})
|
|
});
|
|
|
|
function back() {
|
|
location.href = ns.url("shop/user/user");
|
|
}
|
|
</script>
|
|
{/block}
|