set_supplier.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. layui.layer.confirm('确定进行此项设置吗?', function() {
  98. var goods_string = JSON.stringify(goods);
  99. var data = {};
  100. data = {id:id, role:role, value:goods_string};
  101. $.post(url, data, function(t) {
  102. t = JSON.parse(t);
  103. if (t.status == 1) {
  104. layui.layer.alert('设置成功', function(index){
  105. if (t.data == 'refer') {
  106. history.back();
  107. } else {
  108. location.href = t.data;
  109. }
  110. layer.close(index);
  111. });
  112. } else {
  113. layui.layer.alert(t.msg);
  114. }
  115. });
  116. });
  117. })
  118. })
  119. var goods = {};
  120. var del_goods = {};
  121. mini.parse();
  122. var tree = mini.get("tree1");
  123. for (var i in tree.data) {
  124. if (typeof(tree.data[i].children) == 'object') {
  125. if (tree.data[i].children.length > 0) {
  126. for (var j in tree.data[i].children) {
  127. if(tree.data[i].children[j].select == 1) {
  128. setGoods(tree.data[i].children[j]);
  129. }
  130. }
  131. } else if(tree.data[i].select == 1) {
  132. setGoods(tree.data[i]);
  133. }
  134. }
  135. }
  136. function search()
  137. {
  138. var key = mini.get("key").getValue();
  139. if (key == "") {
  140. tree.clearFilter();
  141. } else {
  142. key = key.toLowerCase();
  143. tree.filter(function (node) {
  144. var name = node.name ? node.name.toLowerCase() : "";
  145. if (name.indexOf(key) != -1) {
  146. return true;
  147. }
  148. });
  149. }
  150. }
  151. function onKeyEnter(e)
  152. {
  153. search();
  154. }
  155. function onNodeClick()
  156. {
  157. var tree=mini.get("tree1");
  158. node=tree.getSelectedNode();
  159. if(node.end) {
  160. setGoods(node);
  161. }
  162. }
  163. function setGoods(node)
  164. {
  165. if (node.id) {
  166. var key = node.id;
  167. if (!goods[key]) {
  168. goods[key] = node;
  169. create(node);
  170. setTotal();
  171. } else {
  172. add(key);
  173. }
  174. }
  175. }
  176. function unsetGoods(node)
  177. {
  178. if (node.id) {
  179. if (goods[node.id]) {
  180. delete goods[node.id];
  181. get(node.id).remove();
  182. }
  183. }
  184. }
  185. function get(key)
  186. {
  187. return $('#goods_' + key);
  188. }
  189. function create(node)
  190. {
  191. if (!get(node.id).length) {
  192. var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
  193. addtr += '<td class="goods_id">'+node.id+'</td>';
  194. addtr += '<td class="goods_id">'+node.code+'</td>';
  195. addtr += '<td class="goods_name">'+node.name+'</td>';
  196. addtr += '<td class="goods_name">'+node.type_name+'</td>';
  197. addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
  198. addtr += '</tr>';
  199. $("#goods").append(addtr);
  200. }
  201. }
  202. function add(id)
  203. {
  204. goods[id].num += 1;
  205. get(id).find('.goods_num').val(goods[id].num);
  206. setTotal();
  207. }
  208. function dec(id)
  209. {
  210. goods[id].num -= 1;
  211. if (goods[id].num < 1) {
  212. goods[id].num = 0;
  213. }
  214. get(id).find('.goods_num').val(goods[id].num);
  215. setTotal();
  216. }
  217. function del(id)
  218. {
  219. if (confirm('确定删除吗?')) {
  220. delete goods[id];
  221. get(id).remove();
  222. setTotal();
  223. }
  224. }
  225. // 一键添加
  226. function addGoods()
  227. {
  228. var key = mini.get("key").getValue();
  229. if (key == '请输入供应商名称') {
  230. key = '';
  231. }
  232. if (key) {
  233. key = key.toLowerCase();
  234. }
  235. for (var i in tree.data) {
  236. if (typeof(tree.data[i].children) == 'object') {
  237. if (tree.data[i].children.length > 0) {
  238. for (var j in tree.data[i].children) {
  239. if (key) {
  240. var name = tree.data[i].children[j].name;
  241. if (name.indexOf(key) != -1) {
  242. setGoods(tree.data[i].children[j]);
  243. }
  244. } else {
  245. setGoods(tree.data[i].children[j]);
  246. }
  247. }
  248. } else {
  249. if (key) {
  250. var name = tree.data[i].name;
  251. if (name.indexOf(key) != -1) {
  252. setGoods(tree.data[i]);
  253. }
  254. } else {
  255. setGoods(tree.data[i]);
  256. }
  257. }
  258. }
  259. }
  260. }
  261. // 一键删除
  262. function delGoods()
  263. {
  264. if (confirm('确定删除吗?')) {
  265. var key = mini.get("key").getValue();
  266. if (key == '请输入供应商名称') {
  267. key = '';
  268. }
  269. if (key) {
  270. key = key.toLowerCase();
  271. }
  272. for (var i in tree.data) {
  273. if (typeof(tree.data[i].children) == 'object') {
  274. if (tree.data[i].children.length > 0) {
  275. for (var j in tree.data[i].children) {
  276. if (key) {
  277. var name = tree.data[i].children[j].name;
  278. if (name.indexOf(key) != -1) {
  279. unsetGoods(tree.data[i].children[j]);
  280. }
  281. } else {
  282. unsetGoods(tree.data[i].children[j]);
  283. }
  284. }
  285. } else {
  286. if (key) {
  287. var name = tree.data[i].name;
  288. if (name.indexOf(key) != -1) {
  289. unsetGoods(tree.data[i]);
  290. }
  291. } else {
  292. unsetGoods(tree.data[i]);
  293. }
  294. }
  295. }
  296. }
  297. setTotal();
  298. }
  299. }
  300. function setTotal()
  301. {
  302. var num = 0;
  303. for (var i in goods) {
  304. num += 1;
  305. }
  306. $(".totalNum").html(num);
  307. }
  308. function setShop()
  309. {
  310. var sid = $('.xm-select-parent[fs_id="sid"] span[fsw="xm-select"]').attr('value');
  311. if (!sid) {
  312. layui.layer.alert('请选择<{$name}>');
  313. return;
  314. }
  315. layui.layer.confirm('确定切换<{$name}>吗?', function() {
  316. location.href = '<{$host}>&id=' + sid;
  317. });
  318. }
  319. </script>
  320. </body>
  321. </html>