set_supplier.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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:'name'}">优先级</th>
  57. <th lay-data="{field:'operation'}">操作</th>
  58. </tr>
  59. </thead>
  60. <tbody id="goods">
  61. </tbody>
  62. </table>
  63. </div>
  64. <div class="total ft16">
  65. 合计:【<span> 分配供应商总数:<i class="totalNum">0</i> </span>】
  66. </div>
  67. <div class="towbtn">
  68. <input type="button" id="settlement" value="确认分配">
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </form>
  75. </div>
  76. <script>
  77. var form;
  78. layui.config(
  79. {
  80. base: '../script/lib/layui/admin/' //静态资源所在路径
  81. ,version: true
  82. }).extend(
  83. {
  84. index: 'lib/index', //主入口模块
  85. formSelects: 'plugin/formselects/formselects'
  86. }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
  87. {
  88. var table = layui.table;
  89. form = layui.form;
  90. var formSelects = layui.formSelects;
  91. });
  92. $(function()
  93. {
  94. $("#settlement").click(function(){
  95. var url = '<{$submit}>';
  96. var id = '<{$id}>';
  97. var role = '<{$role}>';
  98. layui.layer.confirm('确定进行此项设置吗?', function() {
  99. var goods_string = JSON.stringify(goods);
  100. var data = {};
  101. data = {id:id, role:role, 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. $("#goods").on("keyup", ".goods_num", function() {
  120. var num = parseFloat($(this).val());
  121. if (num < 0) {
  122. num = 1;
  123. $(this).val(1);
  124. }
  125. var id = $(this).parent().attr('value');
  126. goods[id].reorder = num;
  127. setTotal();
  128. });
  129. })
  130. var goods = {};
  131. var del_goods = {};
  132. mini.parse();
  133. var tree = mini.get("tree1");
  134. for (var i in tree.data) {
  135. if (typeof(tree.data[i].children) == 'object') {
  136. if (tree.data[i].children.length > 0) {
  137. for (var j in tree.data[i].children) {
  138. if(tree.data[i].children[j].select == 1) {
  139. setGoods(tree.data[i].children[j]);
  140. }
  141. }
  142. } else if(tree.data[i].select == 1) {
  143. setGoods(tree.data[i]);
  144. }
  145. }
  146. }
  147. function search()
  148. {
  149. var key = mini.get("key").getValue();
  150. if (key == "") {
  151. tree.clearFilter();
  152. } else {
  153. key = key.toLowerCase();
  154. tree.filter(function (node) {
  155. var name = node.name ? node.name.toLowerCase() : "";
  156. if (name.indexOf(key) != -1) {
  157. return true;
  158. }
  159. });
  160. }
  161. }
  162. function onKeyEnter(e)
  163. {
  164. search();
  165. }
  166. function onNodeClick()
  167. {
  168. var tree=mini.get("tree1");
  169. node=tree.getSelectedNode();
  170. if(node.end) {
  171. setGoods(node);
  172. }
  173. }
  174. function setGoods(node)
  175. {
  176. if (node.id) {
  177. var key = node.id;
  178. if (!goods[key]) {
  179. goods[key] = node;
  180. goods[key].reorder = goods[key].reorder ? parseFloat(goods[key].reorder) : 1;
  181. create(node);
  182. setTotal();
  183. } else {
  184. add(key);
  185. }
  186. }
  187. }
  188. function unsetGoods(node)
  189. {
  190. if (node.id) {
  191. if (goods[node.id]) {
  192. delete goods[node.id];
  193. get(node.id).remove();
  194. }
  195. }
  196. }
  197. function get(key)
  198. {
  199. return $('#goods_' + key);
  200. }
  201. function create(node)
  202. {
  203. if (!get(node.id).length) {
  204. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  205. addtr += '<td class="goods_id">'+node.id+'</td>';
  206. addtr += '<td class="goods_id">'+node.code+'</td>';
  207. addtr += '<td class="goods_name">'+node.name+'</td>';
  208. addtr += '<td class="goods_name">'+node.type_name+'</td>';
  209. addtr += '<td><div class="jiajian" value='+node.id+'><span class="jian" onclick="dec(\''+node.id+'\')">-</span><input type="text" value="'+node.reorder+'" class="goods_num"><span class="jia" onclick="add(\''+node.id+'\')">+</span></div></td>';
  210. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  211. addtr += '</tr>';
  212. $("#goods").append(addtr);
  213. }
  214. }
  215. function add(id)
  216. {
  217. goods[id].reorder += 1;
  218. get(id).find('.goods_num').val(goods[id].reorder);
  219. setTotal();
  220. }
  221. function dec(id)
  222. {
  223. goods[id].reorder -= 1;
  224. if (goods[id].reorder < 1) {
  225. goods[id].reorder = 0;
  226. }
  227. get(id).find('.goods_num').val(goods[id].reorder);
  228. setTotal();
  229. }
  230. function del(id)
  231. {
  232. if (confirm('确定删除吗?')) {
  233. delete goods[id];
  234. get(id).remove();
  235. setTotal();
  236. }
  237. }
  238. // 一键添加
  239. function addGoods()
  240. {
  241. var key = mini.get("key").getValue();
  242. if (key == '请输入供应商名称') {
  243. key = '';
  244. }
  245. if (key) {
  246. key = key.toLowerCase();
  247. }
  248. for (var i in tree.data) {
  249. if (typeof(tree.data[i].children) == 'object') {
  250. if (tree.data[i].children.length > 0) {
  251. for (var j in tree.data[i].children) {
  252. if (key) {
  253. var name = tree.data[i].children[j].name;
  254. if (name.indexOf(key) != -1) {
  255. setGoods(tree.data[i].children[j]);
  256. }
  257. } else {
  258. setGoods(tree.data[i].children[j]);
  259. }
  260. }
  261. } else {
  262. if (key) {
  263. var name = tree.data[i].name;
  264. if (name.indexOf(key) != -1) {
  265. setGoods(tree.data[i]);
  266. }
  267. } else {
  268. setGoods(tree.data[i]);
  269. }
  270. }
  271. }
  272. }
  273. }
  274. // 一键删除
  275. function delGoods()
  276. {
  277. if (confirm('确定删除吗?')) {
  278. var key = mini.get("key").getValue();
  279. if (key == '请输入供应商名称') {
  280. key = '';
  281. }
  282. if (key) {
  283. key = key.toLowerCase();
  284. }
  285. for (var i in tree.data) {
  286. if (typeof(tree.data[i].children) == 'object') {
  287. if (tree.data[i].children.length > 0) {
  288. for (var j in tree.data[i].children) {
  289. if (key) {
  290. var name = tree.data[i].children[j].name;
  291. if (name.indexOf(key) != -1) {
  292. unsetGoods(tree.data[i].children[j]);
  293. }
  294. } else {
  295. unsetGoods(tree.data[i].children[j]);
  296. }
  297. }
  298. } else {
  299. if (key) {
  300. var name = tree.data[i].name;
  301. if (name.indexOf(key) != -1) {
  302. unsetGoods(tree.data[i]);
  303. }
  304. } else {
  305. unsetGoods(tree.data[i]);
  306. }
  307. }
  308. }
  309. }
  310. setTotal();
  311. }
  312. }
  313. function setTotal()
  314. {
  315. var num = 0;
  316. for (var i in goods) {
  317. num += 1;
  318. }
  319. $(".totalNum").html(num);
  320. }
  321. function setShop()
  322. {
  323. var sid = $('.xm-select-parent[fs_id="sid"] span[fsw="xm-select"]').attr('value');
  324. if (!sid) {
  325. layui.layer.alert('请选择<{$name}>');
  326. return;
  327. }
  328. layui.layer.confirm('确定切换<{$name}>吗?', function() {
  329. location.href = '<{$host}>&id=' + sid;
  330. });
  331. }
  332. </script>
  333. </body>
  334. </html>