production_edit.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>生产计划新建</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  9. <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  10. <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
  11. <style type="text/css">
  12. .table-overlay .layui-table-view,
  13. .table-overlay .layui-table-header,
  14. .table-overlay .layui-table-box,
  15. .table-overlay .layui-table-body{overflow: visible;}
  16. .table-overlay .layui-table-cell{height: auto; overflow: visible;}
  17. </style>
  18. </head>
  19. <body>
  20. <div class="layui-fluid">
  21. <div class="layui-card">
  22. <div class="layui-card-body" pad15>
  23. <div class="layui-row layui-col-space15">
  24. <div class="layui-col-md12">
  25. <form class="layui-form" action="" lay-filter="component-form-element">
  26. <div class="layui-row layui-col-space10">
  27. <div class="layui-col-sm6">
  28. <label class="layui-form-label"><font color='red' size="4">*</font>名称:</label>
  29. <div class="layui-input-block">
  30. <input type="text" name="name" lay-verify="required" autocomplete="off" id="name" class="layui-input">
  31. </div>
  32. </div>
  33. </div>
  34. <div class="layui-row layui-col-space10">
  35. <div class="layui-col-sm10">
  36. <label class="layui-form-label">备注:</label>
  37. <div class="layui-input-block">
  38. <input type="text" name="notes" autocomplete="off" id="notes" class="layui-input">
  39. </div>
  40. </div>
  41. </div>
  42. <fieldset class="layui-elem-field layui-field-title">
  43. <legend>产品明细&nbsp;&nbsp;<button type="button" id="goods-btn-add" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button></legend>
  44. </fieldset>
  45. <div class="table-overlay">
  46. <table id="goods_data_table" lay-filter="goods_data_table" class="layui-hide"></table>
  47. </div>
  48. <button class="layui-btn" id="submit_btn" lay-submit lay-filter="component-form-element" style="display: none"></button>
  49. </form>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. <script src="../../layuiadmin/layui/layui.js"></script>
  56. <script>
  57. var _Quality_request = []
  58. ,_Department = []
  59. ,_Product_user = [];
  60. layui.config({
  61. base: '../../../layuiadmin/' //静态资源所在路径
  62. }).extend({
  63. index: 'lib/index', //主入口模块
  64. utils:'utils'
  65. }).use(['index','utils', 'form', 'table','laydate'], function() {
  66. var $ = layui.$;
  67. var admin = layui.admin;
  68. var form = layui.form;
  69. var table = layui.table;
  70. var utils = layui.utils;
  71. var laydate = layui.laydate;
  72. var options_isload = false;
  73. var other_isload = false;
  74. var data_isload = false;
  75. var id = layui.view.getParameterByName('id');
  76. admin.req({
  77. url: '/foundation/search_options/?type=4',
  78. done: function (res) {
  79. _Quality_request = res.data;
  80. options_isload = true;
  81. load_list()
  82. }
  83. });
  84. admin.req({
  85. url: '/plan/plan/options/',
  86. done: function(res){
  87. var department = res.data.departments;
  88. var product_user = res.data.users;
  89. _Department = department;
  90. _Product_user = product_user;
  91. other_isload = true;
  92. load_list()
  93. }
  94. });
  95. var load_list = function(){
  96. if (!(options_isload && other_isload)){
  97. return;
  98. }
  99. if (data_isload) {
  100. return;
  101. }
  102. data_isload = true;
  103. if (id) {
  104. admin.req({
  105. url: '/plan/production/detail/?id=' + id,
  106. done: function (res) {
  107. var production_items = res.data.production;
  108. var goods_items = res.data.goods_items;
  109. for (var p in production_items) {
  110. $('#name').val(production_items[p].name);
  111. $('#notes').val(production_items[p].notes);
  112. }
  113. var goodsData = table.cache[goods_data_table];
  114. for (var i in goods_items) {
  115. var newRow = {
  116. id: goods_items[i].goods_id,
  117. name: goods_items[i].name,
  118. model: goods_items[i].model,
  119. unit: goods_items[i].unit,
  120. quality_request: goods_items[i].quality_request_id,
  121. count: goods_items[i].count,
  122. product_user: goods_items[i].product_user_id,
  123. p_department: goods_items[i].p_department_id,
  124. product_time: goods_items[i].product_time,
  125. notes: goods_items[i].notes
  126. };
  127. goodsData.push(newRow);
  128. }
  129. goods_tableIns.reload({
  130. data: goodsData
  131. })
  132. }
  133. })
  134. };
  135. var sale_id = layui.view.getParameterByName('sale_id');
  136. if (sale_id) {
  137. admin.req({
  138. url: '/plan/sale/detail/?id=' + sale_id,
  139. done: function (res) {
  140. var goods_items = res.data.goods_items;
  141. var goodsData = table.cache[goods_data_table];
  142. for (var i in goods_items) {
  143. var newRow = {
  144. id: goods_items[i].goods_id,
  145. name: goods_items[i].name,
  146. model: goods_items[i].model,
  147. unit: goods_items[i].unit,
  148. quality_request: goods_items[i].quality_request,
  149. count: goods_items[i].require_product_count,
  150. product_user: '',
  151. p_department: '',
  152. product_time: '',
  153. notes: ''
  154. };
  155. goodsData.push(newRow);
  156. }
  157. goods_tableIns.reload({
  158. data: goodsData
  159. })
  160. }
  161. })
  162. }
  163. };
  164. var goods_data_table = "goods_data_table";
  165. var goods_tableIns = table.render({
  166. elem: '#goods_data_table',
  167. id: goods_data_table,
  168. data: [],
  169. page: false,
  170. limit: 1000,
  171. loading: true,
  172. even: true, //不开启隔行背景
  173. cols: [[
  174. {title: '序号', type: 'numbers'},
  175. {field: 'name', title: '产品名称', width: 150},
  176. {field: 'model', title: '产品代码', width: 150},
  177. {field: 'unit', title: '单位', width: 120},
  178. {field: 'quality_request', title: '质量要求', width: 150, templet: function (d) {
  179. var options = utils.renderSelectOptions(_Quality_request, {
  180. valueField: "id",
  181. textField: "name",
  182. selectedValue: d.quality_request
  183. });
  184. return '<select id="quality_request'+d.id+'" lay-filter="type_select"><option value="">请选择</option>' + options + '</select>';
  185. }
  186. },
  187. {field: 'count', title: '数量', width: 100, templet: function (d){
  188. return '<input id="count'+d.id+'" type="text" value="'+d.count+'" lay-verify="required|numberGtZ" autocomplete="off" class="layui-input">';
  189. }},
  190. {field: 'p_department', title: '生产车间', width: 150,templet: function (d) {
  191. var options = utils.renderSelectOptions(_Department, {
  192. valueField: "id",
  193. textField: "name",
  194. selectedValue: d.p_department
  195. });
  196. return '<select id="p_department'+d.id+'" lay-filter="type_select"><option value="">请选择车间</option>' + options + '</select>';
  197. }
  198. },
  199. {field: 'product_time', title: '生产时间', width: 180,event:'chooseDate',templet:function(d){
  200. return '<input id="product_time'+d.id+'" type="text" lay-verify="datetime" autocomplete="off" class="layui-input" value="'+d.product_time+'">';
  201. }},
  202. {field: 'product_user', title: '负责人', width: 150,templet: function (d) {
  203. var options = utils.renderSelectOptions(_Product_user, {
  204. valueField: "id",
  205. textField: "name",
  206. selectedValue: d.product_user
  207. });
  208. return '<select id="product_user'+d.id+'" lay-filter="type_select"><option value="">请选择人员</option>' + options + '</select>';
  209. }
  210. },
  211. {field: 'notes', title: '备注', minWidth: 150, templet: function (d){
  212. return '<input id="notes'+ d.id +'" type="text" autocomplete="off" value="'+d.notes+'" class="layui-input" autocomplete="off">';
  213. }},
  214. {
  215. field: 'id', title: '操作', minWidth:120,templet: function (d) {
  216. return '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
  217. }
  218. }
  219. ]]
  220. ,done: function (res, curr, count) {
  221. }
  222. });
  223. //监听工具条
  224. table.on('tool(goods_data_table)', function (obj) {
  225. var data = obj.data;
  226. var event = obj.event;
  227. switch (event) {
  228. case "chooseDate":
  229. laydate.render({
  230. elem: '#product_time'+data.id,
  231. trigger:"click",
  232. type:'datetime',
  233. show:true,
  234. closeStop:'#product_time'+data.id
  235. });
  236. break;
  237. case "del":
  238. obj.del();
  239. layer.msg('删除成功', {icon: 6});
  240. break;
  241. }
  242. });
  243. var getgoodsData = function () {
  244. var rows = table.cache[goods_data_table];
  245. var data = [];
  246. for (var n in rows) {
  247. if (rows[n] == false) {
  248. continue;
  249. }
  250. var notes = $('#notes'+rows[n].id).val();
  251. var quality_request = $('#quality_request'+rows[n].id).val();
  252. var count = $('#count'+rows[n].id).val();
  253. var p_department = $('#p_department'+rows[n].id).val();
  254. var product_user = $('#product_user'+rows[n].id).val();
  255. var product_time = $('#product_time'+rows[n].id).val();
  256. var item = {
  257. id: rows[n].id,
  258. name: rows[n].name,
  259. model: rows[n].model,
  260. unit: rows[n].unit,
  261. quality_request:quality_request,
  262. count:count,
  263. p_department:p_department,
  264. product_user:product_user,
  265. product_time:product_time,
  266. notes:notes
  267. };
  268. data.push(item);
  269. }
  270. return data;
  271. };
  272. form.on('submit(component-form-element)', function (data) {
  273. var items = getgoodsData();
  274. if (items.length == 0) {
  275. layer.msg('请添加产品!', {icon: 5});
  276. return false;
  277. }
  278. admin.req({
  279. url: '/plan/production/save/?id=' + id
  280. , data: {production: JSON.stringify(data.field), items: JSON.stringify(items)}
  281. , type: 'post'
  282. , done: function (res) {
  283. parent.layui.onSubmitChild(res.data);
  284. }
  285. });
  286. return false;
  287. });
  288. $('#goods-btn-add').on('click', function () {
  289. layer.open({
  290. type: 2,
  291. title: '添加成品',
  292. area: ['90%', '98%'],
  293. btn: ['确定', '取消'],
  294. yes: function (index, dom) {
  295. layui.onSubmitChild = function (data) {
  296. var oldData = getgoodsData();
  297. if (data.length > 0) {
  298. layer.msg('添加成功!', {icon: 6});
  299. } else {
  300. layer.msg('请先选择记录!');
  301. }
  302. for (var i in data) {
  303. var is_exit = false;
  304. for (var m in oldData) {
  305. if (oldData[m].id == data[i].id) {
  306. is_exit = true;
  307. break;
  308. }
  309. }
  310. if (is_exit) {
  311. continue;
  312. }
  313. var newRow = {
  314. id: data[i].id,
  315. name: data[i].name,
  316. model: data[i].model,
  317. unit: data[i].unit,
  318. quality_request: '',
  319. count: '',
  320. product_user: '',
  321. p_department: '',
  322. product_time: '',
  323. notes: ''
  324. };
  325. oldData.push(newRow);
  326. }
  327. goods_tableIns.reload({
  328. data: oldData
  329. });
  330. };
  331. layui.submitChild();
  332. },
  333. btn2: function (index, layero) {
  334. layer.close(index);//关闭当前按钮
  335. },
  336. content: '../goods/search_goods_item.html'
  337. });
  338. });
  339. parent.layui.submitChild = function () {
  340. $("#submit_btn").click();
  341. };
  342. })
  343. </script>
  344. </body>
  345. </html>