set_store.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
  6. <meta name="author" content="siweiyong 2602812659@qq.com"/>
  7. <title>设置配送商</title>
  8. <link rel="stylesheet" href="../script/lib/miniui/themes/default/miniui.css">
  9. <link rel="stylesheet" href="../script/lib/layui/css/layui.css" />
  10. <link rel="stylesheet" href="../script/lib/cashier/common.css">
  11. <link rel="stylesheet" href="../script/lib/layui/admin/modules/plugin/formselects/formselects.css" media="all" />
  12. <script src="../script/lib/jquery/jquery.min.js"></script>
  13. <script src="../script/lib/miniui/miniui.js"></script>
  14. <script src="../script/lib/layui/layui.js"></script>
  15. <script><{Dever::script()}></script>
  16. <script src="../script/dever/core.js"></script>
  17. </head>
  18. <body style="background: #F6F7F9;">
  19. <div class="main">
  20. <form class="layui-form" lay-filter="form">
  21. <div class="layui-row">
  22. <div class="main_left layui-col-xs12 layui-col-md3">
  23. <div class="layui-row">
  24. <div class="top">
  25. <i class="layui-icon layui-icon-app"></i>仓库列表
  26. </div>
  27. <div class="left_main">
  28. <input id="key" class="mini-textbox" onenter="onKeyEnter" value="请输入配送商名称" onclick="setVal('key')"/>
  29. <a class="mini-button" onclick="search()">查询</a>
  30. <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="addGoods()">一键添加</button>
  31. <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="delGoods()">一键删除</button>
  32. <ul id="tree1" class="mini-tree" url="<{$url}>" showTreeIcon="true" textField="name" idField="id" expandOnLoad="true" onNodeClick="onNodeClick">
  33. </ul>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="main_right layui-col-xs12 layui-col-md9">
  38. <div class="layui-row">
  39. <div class="top">
  40. <label>切换<{$name}>:</label>
  41. <div class="layui-input-inline">
  42. <div><select xm-select="sid" xm-select-skin="normal" xm-select-search="<{$search}>" xm-select-search-type="dl" xm-select-radio="" class="update_value form-control layui-input layui-select" name="sid" id="sid" ></select></div>
  43. </div>
  44. <div class="layui-input-inline">
  45. <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="setShop()">确认切换</button>
  46. </div>
  47. </div>
  48. <div class="goods_list" style="height:645px;">
  49. <table class="layui-table">
  50. <thead>
  51. <tr>
  52. <th lay-data="{field:'id'}">配送商ID</th>
  53. <th lay-data="{field:'id'}">配送商编码</th>
  54. <th lay-data="{field:'name'}">配送商名称</th>
  55. <th lay-data="{field:'name'}">配送商类型</th>
  56. <th lay-data="{field:'operation'}">操作</th>
  57. </tr>
  58. </thead>
  59. <tbody id="goods">
  60. </tbody>
  61. </table>
  62. </div>
  63. <div class="total ft16">
  64. 合计:【<span> 分配仓库总数:<i class="totalNum">0</i> </span>】 注意:不分配仓库,则门店可以使用所有与经销商绑定的配送商下的仓库
  65. </div>
  66. <div class="towbtn">
  67. <input type="button" id="settlement" value="确认分配">
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </form>
  74. </div>
  75. <script>
  76. var form;
  77. layui.config(
  78. {
  79. base: '../script/lib/layui/admin/' //静态资源所在路径
  80. ,version: true
  81. }).extend(
  82. {
  83. index: 'lib/index', //主入口模块
  84. formSelects: 'plugin/formselects/formselects'
  85. }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
  86. {
  87. var table = layui.table;
  88. form = layui.form;
  89. var formSelects = layui.formSelects;
  90. });
  91. $(function()
  92. {
  93. $("#settlement").click(function(){
  94. var url = '<{$submit}>';
  95. var id = '<{$id}>';
  96. var role = '<{$role}>';
  97. var table = '<{$table}>';
  98. layui.layer.confirm('确定进行此项设置吗?', function() {
  99. var goods_string = JSON.stringify(goods);
  100. var data = {};
  101. data = {id:id, role:role,table:table, value:goods_string};
  102. $.post(url, data, function(t) {
  103. t = JSON.parse(t);
  104. if (t.status == 1) {
  105. layui.layer.alert('设置成功', function(index){
  106. if (t.data == 'refer') {
  107. history.back();
  108. } else {
  109. location.href = t.data;
  110. }
  111. layer.close(index);
  112. });
  113. } else {
  114. layui.layer.alert(t.msg);
  115. }
  116. });
  117. });
  118. })
  119. })
  120. var goods = {};
  121. var del_goods = {};
  122. mini.parse();
  123. var tree = mini.get("tree1");
  124. for (var i in tree.data) {
  125. if (typeof(tree.data[i].children) == 'object') {
  126. if (tree.data[i].children.length > 0) {
  127. for (var j in tree.data[i].children) {
  128. if(tree.data[i].children[j].select == 1) {
  129. setGoods(tree.data[i].children[j]);
  130. }
  131. }
  132. } else if(tree.data[i].select == 1) {
  133. setGoods(tree.data[i]);
  134. }
  135. }
  136. }
  137. function search()
  138. {
  139. var key = mini.get("key").getValue();
  140. if (key == "") {
  141. tree.clearFilter();
  142. } else {
  143. key = key.toLowerCase();
  144. tree.filter(function (node) {
  145. var name = node.name ? node.name.toLowerCase() : "";
  146. if (name.indexOf(key) != -1) {
  147. return true;
  148. }
  149. });
  150. }
  151. }
  152. function onKeyEnter(e)
  153. {
  154. search();
  155. }
  156. function onNodeClick()
  157. {
  158. var tree=mini.get("tree1");
  159. node=tree.getSelectedNode();
  160. if(node.end) {
  161. setGoods(node);
  162. }
  163. }
  164. function setGoods(node)
  165. {
  166. if (node.id) {
  167. var key = node.id;
  168. if (!goods[key]) {
  169. goods[key] = node;
  170. create(node);
  171. setTotal();
  172. } else {
  173. add(key);
  174. }
  175. }
  176. }
  177. function unsetGoods(node)
  178. {
  179. if (node.id) {
  180. if (goods[node.id]) {
  181. delete goods[node.id];
  182. get(node.id).remove();
  183. }
  184. }
  185. }
  186. function get(key)
  187. {
  188. return $('#goods_' + key);
  189. }
  190. function create(node)
  191. {
  192. if (!get(node.id).length) {
  193. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  194. addtr += '<td class="goods_id">'+node.id+'</td>';
  195. addtr += '<td class="goods_id">'+node.code+'</td>';
  196. addtr += '<td class="goods_name">'+node.name+'</td>';
  197. addtr += '<td class="goods_name">'+node.type_name+'</td>';
  198. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  199. addtr += '</tr>';
  200. $("#goods").append(addtr);
  201. }
  202. }
  203. function add(id)
  204. {
  205. goods[id].num += 1;
  206. get(id).find('.goods_num').val(goods[id].num);
  207. setTotal();
  208. }
  209. function dec(id)
  210. {
  211. goods[id].num -= 1;
  212. if (goods[id].num < 1) {
  213. goods[id].num = 0;
  214. }
  215. get(id).find('.goods_num').val(goods[id].num);
  216. setTotal();
  217. }
  218. function del(id)
  219. {
  220. if (confirm('确定删除吗?')) {
  221. delete goods[id];
  222. get(id).remove();
  223. setTotal();
  224. }
  225. }
  226. // 一键添加
  227. function addGoods()
  228. {
  229. var key = mini.get("key").getValue();
  230. if (key == '请输入配送商名称') {
  231. key = '';
  232. }
  233. if (key) {
  234. key = key.toLowerCase();
  235. }
  236. for (var i in tree.data) {
  237. if (typeof(tree.data[i].children) == 'object') {
  238. if (tree.data[i].children.length > 0) {
  239. for (var j in tree.data[i].children) {
  240. if (key) {
  241. var name = tree.data[i].children[j].name;
  242. if (name.indexOf(key) != -1) {
  243. setGoods(tree.data[i].children[j]);
  244. }
  245. } else {
  246. setGoods(tree.data[i].children[j]);
  247. }
  248. }
  249. } else {
  250. if (key) {
  251. var name = tree.data[i].name;
  252. if (name.indexOf(key) != -1) {
  253. setGoods(tree.data[i]);
  254. }
  255. } else {
  256. setGoods(tree.data[i]);
  257. }
  258. }
  259. }
  260. }
  261. }
  262. // 一键删除
  263. function delGoods()
  264. {
  265. if (confirm('确定删除吗?')) {
  266. var key = mini.get("key").getValue();
  267. if (key == '请输入配送商名称') {
  268. key = '';
  269. }
  270. if (key) {
  271. key = key.toLowerCase();
  272. }
  273. for (var i in tree.data) {
  274. if (typeof(tree.data[i].children) == 'object') {
  275. if (tree.data[i].children.length > 0) {
  276. for (var j in tree.data[i].children) {
  277. if (key) {
  278. var name = tree.data[i].children[j].name;
  279. if (name.indexOf(key) != -1) {
  280. unsetGoods(tree.data[i].children[j]);
  281. }
  282. } else {
  283. unsetGoods(tree.data[i].children[j]);
  284. }
  285. }
  286. } else {
  287. if (key) {
  288. var name = tree.data[i].name;
  289. if (name.indexOf(key) != -1) {
  290. unsetGoods(tree.data[i]);
  291. }
  292. } else {
  293. unsetGoods(tree.data[i]);
  294. }
  295. }
  296. }
  297. }
  298. setTotal();
  299. }
  300. }
  301. function setTotal()
  302. {
  303. var num = 0;
  304. for (var i in goods) {
  305. num += 1;
  306. }
  307. $(".totalNum").html(num);
  308. }
  309. function setShop()
  310. {
  311. var sid = $('.xm-select-parent[fs_id="sid"] span[fsw="xm-select"]').attr('value');
  312. if (!sid) {
  313. layui.layer.alert('请选择<{$name}>');
  314. return;
  315. }
  316. layui.layer.confirm('确定切换<{$name}>吗?', function() {
  317. location.href = '<{$host}>&id=' + sid;
  318. });
  319. }
  320. </script>
  321. </body>
  322. </html>