edit_user.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <style>
  4. .form-wrap {margin-top: 0;}
  5. .align-center {text-align: center!important;}
  6. .manage-store {display: none}
  7. .manage-store .store-group {width: 200px;margin: 0 auto}
  8. </style>
  9. {/block}
  10. {block name="main"}
  11. <div class="layui-form form-wrap">
  12. <div class="layui-form-item">
  13. <label class="layui-form-label">员工用户名:</label>
  14. <div class="layui-input-inline">
  15. <input name="username" value="{$edit_user_info.username}" type="text" disabled class="layui-input len-long" autocomplete="off">
  16. </div>
  17. </div>
  18. <div class="layui-form-item">
  19. <label class="layui-form-label">{if !$cashier_is_exit}<span class="required">*</span>{/if}员工角色:</label>
  20. <div class="layui-input-inline len-mid">
  21. <select name="group_id" {if !$cashier_is_exit}lay-verify="groupid"{/if}>
  22. <option value="">请选择角色</option>
  23. {foreach $group_list as $group_list_k => $group_list_v}
  24. <option value="{$group_list_v.group_id}" {if $edit_user_info.group_id==$group_list_v.group_id}selected{/if}>{$group_list_v.group_name} </option>
  25. {/foreach}
  26. </select>
  27. </div>
  28. </div>
  29. {if $store_is_exit}
  30. <div class="layui-form-item">
  31. <label class="layui-form-label">管理门店:</label>
  32. <div class="layui-input-block len-mid">
  33. <button class="layui-btn select-store">选择门店</button>
  34. </div>
  35. </div>
  36. <div class="layui-form-item manage-store" {notempty name="$edit_user_info.user_group_list"}style="display:block;"{/notempty}>
  37. <label class="layui-form-label"></label>
  38. <div class="layui-input-block" style="width: 600px">
  39. <table class="layui-table" lay-skin="nob">
  40. <colgroup>
  41. <col width="40%">
  42. <col width="40%">
  43. <col width="20%">
  44. </colgroup>
  45. <thead>
  46. <tr>
  47. <th>门店</th>
  48. <th class="align-center">门店角色</th>
  49. <th class="align-center">操作</th>
  50. </tr>
  51. </thead>
  52. <tbody>
  53. {foreach name="$edit_user_info.user_group_list" item="item"}
  54. <tr data-store="{$item.store_id}">
  55. <td>{$item.store_name}</td>
  56. <td>
  57. <div class="store-group">
  58. <select name="store_group" lay-verify="storegroupid">
  59. <option value="">请选择门店角色</option>
  60. {foreach name="store_user_group" item="vo"}
  61. <option value="{$vo.group_id}" {if $item.group_id eq $vo.group_id}selected{/if}>{$vo.group_name}</option>
  62. {/foreach}
  63. </select>
  64. </div>
  65. </td>
  66. <td class="align-center"><a href="javascript:;" class="del">删除</a></td>
  67. </tr>
  68. {/foreach}
  69. </tbody>
  70. </table>
  71. </div>
  72. </div>
  73. {elseif $cashier_is_exit}
  74. <div class="layui-form-item">
  75. <label class="layui-form-label">门店角色:</label>
  76. <div class="layui-input-block len-mid">
  77. <select name="store_group">
  78. <option value="">请选择门店角色</option>
  79. {foreach name="store_user_group" item="vo"}
  80. <option value="{$vo.group_id}" {if !empty($edit_user_info.user_group_list) && $edit_user_info.user_group_list[0].group_id eq $vo.group_id}selected{/if}>{$vo.group_name}</option>
  81. {/foreach}
  82. </select>
  83. </div>
  84. </div>
  85. <input type="hidden" name="default_store_id" value="{$default_store_id}">
  86. {/if}
  87. <div class="layui-form-item">
  88. <label class="layui-form-label">员工状态:</label>
  89. <div class="layui-input-inline">
  90. <input type="checkbox" name="status" value="1" lay-skin="switch" {if condition="$edit_user_info.status == 1"} checked {/if} />
  91. </div>
  92. </div>
  93. <div class="word-aux">关闭后,员工将被锁定,无法登录</div>
  94. <!-- 表单操作 -->
  95. <div class="form-row">
  96. <button class="layui-btn" lay-submit lay-filter="save">保存</button>
  97. <button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
  98. </div>
  99. <!-- 隐藏域 -->
  100. <input value="{$edit_user_info.uid}" type="hidden" class="user_id" name="uid" />
  101. </div>
  102. {if isset($store_user_group)}
  103. <script id="storeGroup" type="text/html">
  104. <select name="store_group" lay-verify="storegroupid" lay-filter="store_group">
  105. <option value="">请选择门店角色</option>
  106. {foreach name="store_user_group" item="vo"}
  107. <option value="{$vo.group_id}">{$vo.group_name}</option>
  108. {/foreach}
  109. </select>
  110. </script>
  111. {/if}
  112. {/block}
  113. {block name="script"}
  114. <script>
  115. var storeGroup = {};
  116. layui.use('form', function() {
  117. var form = layui.form,
  118. repeat_flag = false; //防重复标识
  119. form.render();
  120. form.on('submit(save)', function(data) {
  121. data.field.store = [];
  122. {if $store_is_exit}
  123. $('.manage-store tbody tr').each(function () {
  124. data.field.store.push({
  125. store_id: $(this).attr('data-store'),
  126. group_id: $(this).find('[name="store_group"]').val()
  127. });
  128. })
  129. {elseif $cashier_is_exit}
  130. if (data.field.store_group) {
  131. data.field.store.push({
  132. store_id: data.field.default_store_id,
  133. group_id: data.field.store_group
  134. });
  135. }
  136. {/if}
  137. {if $cashier_is_exit}
  138. if (!data.field.group_id && !data.field.store.length) {
  139. layer.msg('员工角色和门店角色至少需设置一项', {icon: 5});
  140. return;
  141. }
  142. {/if}
  143. data.field.store = JSON.stringify(data.field.store);
  144. if (repeat_flag) return;
  145. repeat_flag = true;
  146. $.ajax({
  147. dataType: 'JSON',
  148. type: 'POST',
  149. url: ns.url("shop/user/editUser"),
  150. data: data.field,
  151. success: function(res) {
  152. repeat_flag = false;
  153. if (res.code == 0) {
  154. layer.confirm('编辑成功', {
  155. title:'操作提示',
  156. btn: ['返回列表', '继续操作'],
  157. yes: function(){
  158. location.href = ns.url("shop/user/user")
  159. },
  160. btn2: function() {
  161. location.reload();
  162. }
  163. })
  164. }else{
  165. layer.msg(res.message);
  166. }
  167. }
  168. });
  169. });
  170. /**
  171. * 表单验证
  172. */
  173. form.verify({
  174. groupid: function(value) {
  175. if (value == 0) {
  176. return '请选择员工角色!';
  177. }
  178. },
  179. storegroupid: function (value) {
  180. if(!value) {
  181. return '请选择门店角色!';
  182. }
  183. }
  184. });
  185. form.on('select(store_group)', function (data) {
  186. var store_id = $(data.elem).parents('tr').attr('data-store');
  187. storeGroup['store_' + store_id] = data.value;
  188. })
  189. $('.manage-store tbody tr').each(function () {
  190. var store_id = $(this).attr('data-store'), group = $(this).find('[name="store_group"]').val();
  191. storeGroup['store_' + store_id] = group;
  192. })
  193. // 选择门店
  194. $('.select-store').click(function () {
  195. var storeId = [];
  196. $('.manage-store tbody tr').each(function () {
  197. storeId.push($(this).attr('data-store'));
  198. })
  199. storeSelect(function (store) {
  200. fetchStore(store);
  201. }, {store_id: storeId.toString()})
  202. })
  203. function fetchStore(store){
  204. if (store.length) {
  205. $('.manage-store').show();
  206. var h = '', group = $('#storeGroup').html();
  207. store.forEach(function (item) {
  208. h += `<tr data-store="`+ item.store_id +`">
  209. <td>`+ item.store_name +`</td>
  210. <td><div class="store-group">`+ group +`</div></td>
  211. <td class="align-center"><a href="javascript:;" class="del">删除</a></td>
  212. </tr>`;
  213. })
  214. $('.manage-store tbody').html(h);
  215. Object.keys(storeGroup).forEach(function (key) {
  216. let group = storeGroup[key], store_id = key.replace('store_', '');
  217. $('.manage-store tr[data-store="'+ store_id +'"] option[value="'+ group +'"]').prop('selected', true);
  218. })
  219. form.render();
  220. } else {
  221. $('.manage-store tbody').html('');
  222. $('.manage-store').hide();
  223. }
  224. }
  225. // 删除门店
  226. $('body').on('click', '.manage-store .del', function () {
  227. let store_id = $(this).parents('tr').attr('data-store')
  228. if (storeGroup['store_' + store_id]) delete storeGroup['store_' + store_id];
  229. $(this).parents('tr').remove();
  230. })
  231. });
  232. function back() {
  233. location.href = ns.url("shop/user/user");
  234. }
  235. </script>
  236. {/block}