goods_deliver_edit.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. <link rel="stylesheet" type="text/css" href="../../layuiadmin/style/formSelects-v4.css"/>
  12. <style type="text/css">
  13. .table-overlay .layui-table-view,
  14. .table-overlay .layui-table-header,
  15. .table-overlay .layui-table-box,
  16. .table-overlay .layui-table-body{overflow: visible;}
  17. .table-overlay .layui-table-cell{height: auto; overflow: visible;}
  18. #department_employee_selecter dl{max-height: 250px;}
  19. </style>
  20. </head>
  21. <body>
  22. <div class="layui-fluid">
  23. <div class="layui-card">
  24. <div class="layui-card-body" pad15>
  25. <div class="layui-row layui-col-space15">
  26. <div class="layui-col-md12">
  27. <form class="layui-form" action="" lay-filter="component-form-element">
  28. <div class="layui-row layui-col-space10">
  29. <div class="layui-col-sm6">
  30. <label class="layui-form-label"><font color='red' size="4">*</font>仓别:</label>
  31. <div class="layui-input-block">
  32. <select id="id_warehouse" name="warehouse" lay-filter="onWarehouseChange"
  33. lay-verify="required">
  34. <option value=""></option>
  35. </select>
  36. </div>
  37. </div>
  38. <div class="layui-col-sm6">
  39. <label class="layui-form-label"><font color='red' size="4">*</font>经办人:</label>
  40. <div class="layui-input-block" id="department_employee_selecter">
  41. <select name="agent_user" xm-select="selectDepartment" xm-select-radio lay-verify="required">
  42. </select>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="layui-row layui-col-space10">
  47. <div class="layui-col-md6">
  48. <label class="layui-form-label">客户:</label>
  49. <div class="layui-input-block">
  50. <div>
  51. <div class="layui-col-xs8">
  52. <input id='id_customer' name="customer_text" type="text" autocomplete="off" class="layui-input"/>
  53. </div>
  54. <div class="layui-col-xs4">
  55. <button id="btn_add_customer" class="layui-btn layui-btn-warm" type="button" data-permission="customer.add_customer"><i class="layui-icon layui-icon-add-circle"></i>新建</button>
  56. </div>
  57. <div style="clear: both;"></div>
  58. </div>
  59. <div style="line-height: 37px;">
  60. <label id="customer_name" style="margin-left: 10px;">姓名</label>
  61. <label id="mobile" style="margin-left: 10px;">电话</label>
  62. </div>
  63. <div style="clear: both;"></div>
  64. </div>
  65. </div>
  66. <div class="layui-col-md6">
  67. <label class="layui-form-label">销售单:</label>
  68. <div class="layui-input-block">
  69. <div>
  70. <input id='id_sale_order' name="sale_order_no" type="text" autocomplete="off" class="layui-input"/>
  71. </div>
  72. <div class="layui-col-xs12 layui-col-sm7" style="line-height: 37px;">
  73. <label id="no" style="margin-left: 10px;">单号</label>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. <div class="layui-row layui-col-space10">
  79. <div class="layui-col-xs12 layui-col-sm12">
  80. <label class="layui-form-label">备注:</label>
  81. <div class="layui-input-block">
  82. <input id="notes" type="text" name="notes" autocomplete="off" class="layui-input">
  83. </div>
  84. </div>
  85. </div>
  86. <fieldset class="layui-elem-field layui-field-title">
  87. <legend>成品明细<button type="button" id="goods-btn-add" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button></legend>
  88. </fieldset>
  89. <div class="layui-row layui-col-space10">
  90. <div id="goodsDataTable" class="table-overlay">
  91. <table id="goods_layTable" lay-filter="goods_layTable" class="layui-hide"></table>
  92. </div>
  93. </div>
  94. <button class="layui-btn" id="goods-deliver-submit" lay-submit lay-filter="component-form-element" style="display: none">确定</button>
  95. </form>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <script src="../../layuiadmin/layui/layui.js"></script>
  102. <script>
  103. layui.link('../../../layuiadmin/style/autocomplete.css');
  104. layui.config({
  105. base: '../../../layuiadmin/' //静态资源所在路径
  106. }).extend({
  107. index: 'lib/index', //主入口模块
  108. utils: 'utils',
  109. formSelects: 'formSelects-v4'
  110. }).use(['index', 'form', 'table', 'utils', 'laydate', 'autocomplete','formSelects'], function() {
  111. var $ = layui.$;
  112. var admin = layui.admin;
  113. var utils = layui.utils;
  114. var autocomplete = layui.autocomplete;
  115. var form = layui.form;
  116. var table = layui.table;
  117. var formSelects = layui.formSelects;
  118. var id = layui.view.getParameterByName('id');
  119. var order_id = layui.view.getParameterByName('order_id');
  120. var _customer_id = '';
  121. var _sale_order_id = '';
  122. var warehouse_isload = false;
  123. var other_isload = false;
  124. var data_isload = false;
  125. autocomplete.render({
  126. elem:$('#id_customer'),
  127. url:'/customer/customer/select/',
  128. template_val:'{{d.name}}-{{d.mobile}}',
  129. template_txt:'{{d.name}} <span class=\'layui-badge layui-bg-gray\'>{{d.mobile}}</span>',
  130. onselect: function (resp) {
  131. fillCustomerData(resp);
  132. }
  133. });
  134. autocomplete.render({
  135. elem:$('#id_sale_order'),
  136. url:'/order/sale_order/select/',
  137. template_val:'{{d.no}}',
  138. template_txt:'{{d.no}}',
  139. onselect: function (resp) {
  140. resp.customer_id = resp.customer;
  141. resp.name = resp.customer_name;
  142. resp.mobile = resp.customer_tel;
  143. fillSaleOrderData(resp);
  144. }
  145. });
  146. function fillSaleOrderData(data) {
  147. fillCustomerData(data);
  148. _customer_id = data.customer_id;
  149. $('#no').html('单号:' + data.no);
  150. $('#id_sale_order').val(data.no);
  151. _sale_order_id = data.id;
  152. loadSaleData(data.id);
  153. }
  154. function fillCustomerData(data){
  155. $('#customer_name').html('姓名:' + data.name);
  156. $('#mobile').html('电话:' + data.mobile);
  157. $('#id_customer').val(data.name + '-' + data.mobile);
  158. _customer_id = data.id;
  159. }
  160. admin.req({
  161. url: '/warehouse/select/?type=2',
  162. done: function(res){
  163. var data = res.data;
  164. var warehouse_node = $('#id_warehouse');
  165. for (var i in data) {
  166. var pid = data[i].id;
  167. var value = data[i].value;
  168. warehouse_node.append("<option value='"+pid+"'>"+value+"</option>");
  169. }
  170. form.render();
  171. warehouse_isload = true;
  172. loadData();// 赋值完成后调用传值
  173. }
  174. });
  175. formSelects.render('selectDepartment',{
  176. template:function(id, item) {
  177. if (item.value.split('_')[0] == 'employee') {
  178. return "<span style='color:red;'>"+item.name+"</span>";
  179. }
  180. return item.name;
  181. }
  182. });
  183. formSelects.value('selectDepartment', []);
  184. admin.req({
  185. url: '/account/employee/tree/'
  186. ,done: function(res){
  187. formSelects.data('selectDepartment', 'local', {
  188. arr: res.data,
  189. tree: {
  190. //在点击节点的时候, 如果没有子级数据, 会触发此事件
  191. nextClick: function(id, item, callback){
  192. return false;
  193. },
  194. }
  195. });
  196. other_isload = true;
  197. loadData();
  198. }
  199. });
  200. var loadData = function () {
  201. if (!(warehouse_isload && other_isload)) { // 要等下拉框渲染完成后才能赋值
  202. return;
  203. }
  204. if (data_isload) {
  205. return;
  206. }
  207. data_isload = true;
  208. if(id){
  209. loadeidtData()
  210. }
  211. if(order_id) {
  212. var data = JSON.parse(JSON.stringify(parent.layui.table.editdata));
  213. data.customer_id = data.customer;
  214. data.name = data.customer_name;
  215. data.mobile = data.customer_tel;
  216. fillSaleOrderData(data);
  217. }
  218. };
  219. var loadSaleData = function (sale_id) {
  220. var warehouse = $('#id_warehouse').val();
  221. admin.req({
  222. url: '/order/sale_order/detail/?id=' + sale_id + '&warehouse_id=' + warehouse,
  223. done: function (res) {
  224. var items_data = res.data.items_data;
  225. var roldData = [];
  226. var k=0;
  227. if (roldData.length > 0){
  228. k = roldData[roldData.length-1].num;
  229. }
  230. for (var n in items_data) {
  231. var item_data = items_data[n];
  232. k = k + 1;
  233. if (!warehouse) {
  234. item_data.record_data = ''
  235. }
  236. var newRow = {
  237. id: item_data.product_id,
  238. product_base: item_data.product_id,
  239. name: item_data.name,
  240. model: item_data.model,
  241. price: item_data.price,
  242. total_cost: '',
  243. count: item_data.count,
  244. unit: item_data.unit,
  245. notes: '',
  246. record_data: item_data.record_data,
  247. entry_no: '',
  248. num: k
  249. };
  250. roldData.push(newRow);
  251. }
  252. goods_tableIns.reload({
  253. data: roldData
  254. });
  255. updateCost();
  256. }
  257. });
  258. };
  259. var loadeidtData = function () {
  260. var agent_user = '';
  261. if (id) {
  262. var data = JSON.parse(JSON.stringify(parent.layui.table.editdata));
  263. agent_user = data.agent_user;
  264. form.val("component-form-element", data);
  265. admin.req({
  266. url: '/order/deliver/detail/?id=' + id,
  267. done: function (res) {
  268. var main_data = res.data.main_data;
  269. var items_data = res.data.items_data;
  270. var roldData = table.cache[goods_layTable];
  271. if (main_data.customer_id){
  272. var customer_data = {
  273. 'name':main_data.customer_name,
  274. 'id':main_data.customer_id,
  275. 'mobile':main_data.customer_tel
  276. };
  277. fillCustomerData(customer_data);
  278. }
  279. if(data.sale_order_no){
  280. $('#id_sale_order').val(data.sale_order_no);
  281. $('#no').html('单号:' + data.sale_order_no);
  282. }
  283. var k=0;
  284. if (roldData.length > 0){
  285. k = roldData[roldData.length-1].num;
  286. }
  287. _sale_order_id = res.data.main_data.sale_order_id;
  288. for (var i in items_data) {
  289. k = k + 1;
  290. var newRow = {
  291. id: items_data[i].id,
  292. product_base: items_data[i].product_base,
  293. name: items_data[i].name,
  294. model: items_data[i].model,
  295. price: items_data[i].price,
  296. total_cost: items_data[i].total_cost,
  297. count: items_data[i].count,
  298. unit: items_data[i].unit,
  299. notes: items_data[i].notes,
  300. record_data: items_data[i].record_data,
  301. entry_no: items_data[i].entry_no,
  302. num: k
  303. };
  304. roldData.push(newRow);
  305. }
  306. goods_tableIns.reload({
  307. data: roldData
  308. });
  309. updateCost();
  310. }
  311. })
  312. }
  313. if (agent_user) {
  314. agent_user = 'employee_'+agent_user;
  315. }
  316. formSelects.value('selectDepartment', [agent_user]);
  317. };
  318. var goods_tbWidth = $("#goodsDataTable").width();
  319. var goods_layTable = "goods_layTable";
  320. var goods_tableIns = table.render({
  321. elem: '#goods_layTable',
  322. id: goods_layTable,
  323. data: [],
  324. width: goods_tbWidth,
  325. page: false,
  326. limit: 1000,
  327. loading: true,
  328. even: true, //不开启隔行背景
  329. cols: [[
  330. {title: '序号', type: 'numbers'},
  331. {field: 'name', title: '名称', width: 100},
  332. {field: 'model', title: '代码', width: 100},
  333. {field: 'unit', title: '单位', width: 120},
  334. {field: 'count', title: '数量', width: 100, templet: function (d) {
  335. return '<input id="count' + d.num + '" value="' + d.count + '" type="text" onchange="onCountChange('+ d.id +','+ d.num +')" lay-verify="required|numberGtZ" autocomplete="off" class="layui-input">';
  336. }},
  337. {field: 'price', title: '单价', width: 100, templet: function (d) {
  338. return '<input id="price' + d.num + '" value="' + d.price + '" type="text" lay-verify="required|numberGeZ" autocomplete="off" class="layui-input">';
  339. }},
  340. {field: 'total_cost', title: '成本合计', width: 100, templet: function (d) {
  341. return '<span id="total_cost' + d.num + '">'+ d.total_cost +'</span>';
  342. }},
  343. {field: 'notes', title: '备注', width: 200, templet: function (d) {
  344. return '<input id="notes' + d.num + '" value="' + d.notes + '" type="text" autocomplete="off" class="layui-input">';
  345. }},
  346. {field: 'entry_no', title: '入库单号', width: 200,templet: function (d) {
  347. var options = utils.renderSelectOptions(d.record_data, {
  348. valueField: "stock_id",
  349. textField: "no",
  350. selectedValue: d.entry_no
  351. });
  352. return '<select id="no'+d.num+'" lay-filter="entryno" lay-verify="required"><option value="">请选择入库单</option>' + options + '</select>';
  353. }
  354. },
  355. {field: 'surplus_count', title: '库存数量', width: 100, templet: function (d) {
  356. return '<span id="surplus_count' + d.num + '"></span>';
  357. }},
  358. {field: 'entry_price', title: '成本价', width: 100, templet: function (d) {
  359. return '<span id="entry_price' + d.num + '"></span>';
  360. }},
  361. {field: 'entry_notes', title: '入库单备注', width: 100, templet: function (d) {
  362. return '<span id="entry_notes' + d.num + '"></span>';
  363. }},
  364. {
  365. field: 'id', title: '操作', minWidth: 120, templet: function (d) {
  366. return '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" lay-id="' + d.num + '"><i class="layui-icon layui-icon-delete"></i>删除</a>';
  367. }
  368. }
  369. ]],
  370. done: function (res, curr, count) {
  371. //viewObj.tbData = res.data;
  372. }
  373. });
  374. table.on('tool(goods_layTable)', function (obj) {
  375. var data = obj.data;
  376. var event = obj.event;
  377. switch (event) {
  378. case "del":
  379. obj.del();
  380. layer.msg('删除成功', {icon: 6});
  381. break;
  382. }
  383. });
  384. form.on('select(entryno)', function (data) {
  385. var num = data.elem.id;
  386. num = num.match(/\d+/g)[0];
  387. var stock_id = data.value;
  388. updateTotalCost(num, stock_id);
  389. updateEntry(num, stock_id)
  390. });
  391. function updateEntry(num, stock_id){
  392. if(!stock_id || !num || isNaN(num) || isNaN(stock_id) ){
  393. $('#entry_notes' + num).html('');
  394. $('#surplus_count' + num).html('');
  395. $('#entry_price' + num).html('');
  396. return;
  397. }
  398. var items = getgoodsData();
  399. for (var n in items){
  400. if (items[n].num == num){
  401. var record_data = items[n].record_data;
  402. for (var i in record_data){
  403. if(record_data[i].stock_id == stock_id){
  404. $('#entry_notes' + num).html(record_data[i].notes);
  405. $('#surplus_count' + num).html(record_data[i].surplus_count);
  406. $('#entry_price' + num).html(record_data[i].entry_price);
  407. break;
  408. }
  409. }
  410. break;
  411. }
  412. }
  413. }
  414. function updateTotalCost(num, stock_id){
  415. if(!stock_id || !num || isNaN(num) || isNaN(stock_id) ){
  416. $("#total_cost" + num).html('');
  417. return;
  418. }
  419. var items = getgoodsData();
  420. for (var n in items){
  421. if (items[n].num == num){
  422. num = items[n].num;
  423. var count = items[n].count;
  424. if(!count || isNaN(count)){
  425. return;
  426. }
  427. var record_data = items[n].record_data;
  428. for (var i in record_data){
  429. if(record_data[i].stock_id == stock_id){
  430. var total_cost = record_data[i].entry_price * count;
  431. $('#total_cost' + num).html(total_cost.toFixed(4));
  432. break;
  433. }
  434. }
  435. break;
  436. }
  437. }
  438. }
  439. var getgoodsData = function () {
  440. var rows = table.cache[goods_layTable];
  441. var data = [];
  442. for (var n in rows) {
  443. if (rows[n] == false) {
  444. continue;
  445. }
  446. var count = $('#count'+rows[n].num).val();
  447. var price = $('#price'+rows[n].num).val();
  448. var notes = $('#notes'+rows[n].num).val();
  449. var warehouse_stockrecord = $('#no'+rows[n].num).val();
  450. var total_cost = $('#total_cost'+rows[n].num).html();
  451. var item = {
  452. product_base: rows[n].product_base,
  453. id: rows[n].id,
  454. name: rows[n].name,
  455. model: rows[n].model,
  456. unit: rows[n].unit,
  457. count: count,
  458. price: price,
  459. notes: notes,
  460. num: rows[n].num,
  461. entry_no:warehouse_stockrecord,
  462. record_data: rows[n].record_data,
  463. warehouse_stockrecord: warehouse_stockrecord,
  464. total_cost: total_cost
  465. };
  466. data.push(item);
  467. }
  468. return data;
  469. };
  470. $('#btn_add_customer').on('click', function(){
  471. layer.open({
  472. type: 2,
  473. title: '添加客户',
  474. shadeClose: false,
  475. area: ['95%', '95%'],
  476. btn: ['保存', '取消'],
  477. yes: function(index, dom){
  478. layui.onSubmitChild = function (data) {
  479. layer.close(index);
  480. fillCustomerData(data)
  481. };
  482. layui.submitChild();
  483. },
  484. btn2: function(index, layero){
  485. layer.close(index);//关闭当前按钮
  486. },
  487. content:'../customer/customer_edit.html?add=true'
  488. });
  489. });
  490. form.on('submit(component-form-element)', function (data) {
  491. var items = getgoodsData();
  492. if (items.length == 0) {
  493. layer.msg('请添加成品!', {icon: 5});
  494. return false;
  495. }
  496. var agent_user = formSelects.value('selectDepartment', 'val')[0];
  497. if (agent_user.split('_')[0] == 'employee') {
  498. agent_user = agent_user.split('_')[1];
  499. } else {
  500. layer.msg('经办人只能选择红色的人员项!', {icon: 5});
  501. return false;
  502. }
  503. data.field.agent_user = agent_user;
  504. if (order_id){
  505. data.field.sale_order = order_id;
  506. }
  507. data.field.customer = _customer_id;
  508. data.field.sale_order = _sale_order_id;
  509. admin.req({
  510. url: '/order/deliver/save/?id=' + id
  511. , data: {main: JSON.stringify(data.field), item: JSON.stringify(items)}
  512. , type: 'post'
  513. , done: function (res) {
  514. parent.layui.onSubmitChild(res.data);
  515. }
  516. });
  517. return false;
  518. });
  519. $('#goods-btn-add').on('click', function () {
  520. warehouse = $('#id_warehouse').val();
  521. layer.open({
  522. type: 2,
  523. title: '添加成品',
  524. area: ['90%', '98%'],
  525. btn: ['确定', '取消'],
  526. yes: function (index, dom) {
  527. layui.onSubmitChild = function (data) {
  528. if(data.length > 0) {
  529. layer.msg('添加成功!', {icon: 6});
  530. } else {
  531. layer.msg('请先选择记录!');
  532. }
  533. // layer.close(index);
  534. var oldData = getgoodsData();
  535. var k=0;
  536. if (oldData.length > 0){
  537. k = oldData[oldData.length-1].num;
  538. }
  539. for (var i in data) {
  540. k = k + 1;
  541. var newRow = {
  542. id: data[i].product_id,
  543. product_base:data[i].product_id,
  544. name: data[i].name,
  545. model: data[i].model,
  546. unit: data[i].unit,
  547. record_data: data[i].record_data,
  548. num: k,
  549. count:'',
  550. price:'',
  551. total_cost:'',
  552. notes:''
  553. };
  554. oldData.push(newRow);
  555. }
  556. goods_tableIns.reload({
  557. data: oldData
  558. });
  559. updateCost();
  560. };
  561. layui.submitChild();
  562. },
  563. btn2: function (index, layero) {
  564. layer.close(index);//关闭当前按钮
  565. },
  566. content: '../goods/search_goods_item.html?warehouse=' + warehouse
  567. });
  568. });
  569. form.on('select(onWarehouseChange)',function(){
  570. updateCost();
  571. updateEnryno();
  572. });
  573. function updateEnryno(){
  574. var warehouse = $("#id_warehouse").val();
  575. var data = getgoodsData();
  576. var products = [];
  577. for(var i in data) {
  578. data[i].record_data = [];
  579. }
  580. goods_tableIns.reload({data: data});
  581. if (data.length == 0){
  582. return;
  583. }
  584. for(var i in data){
  585. $('#total_cost' + data[i].num).html('');
  586. var product_id = data[i].id;
  587. var num = data[i].num;
  588. var item = {
  589. product_id: product_id,
  590. index: num
  591. };
  592. products.push(item);
  593. }
  594. if(!warehouse){
  595. return;
  596. }
  597. admin.req({
  598. url: '/warehouse/select/stocks/?warehouse=' + warehouse
  599. , data: {products:JSON.stringify(products)}
  600. , type: 'post'
  601. ,done: function(res){
  602. var result_data = res.data;
  603. var table_data = getgoodsData();
  604. for (var i in table_data) {
  605. var record_data = [];
  606. for (var m in result_data){
  607. if (table_data[i].num == result_data[m].index && table_data[i].product_base == result_data[m].product_id) {
  608. record_data = result_data[m].items;
  609. table_data[i].record_data = record_data;
  610. break;
  611. }
  612. }
  613. }
  614. goods_tableIns.reload({
  615. data: table_data
  616. });
  617. }
  618. });
  619. }
  620. function updateCost() {
  621. var data = getgoodsData();
  622. if (data.length == 0){
  623. return;
  624. }
  625. for(var i in data){
  626. var num = data[i].num;
  627. var stock_id = data[i].warehouse_stockrecord;
  628. updateTotalCost(num, stock_id);
  629. updateEntry(num, stock_id)
  630. }
  631. }
  632. parent.layui.submitChild = function () {
  633. $("#goods-deliver-submit").click();
  634. };
  635. });
  636. function onCountChange(id, num){
  637. var $ = layui.$;
  638. var warehouse = $("#id_warehouse").val();
  639. var stock_id = $("#no" + num).val();
  640. var count = $("#count" + num).val();
  641. count = parseFloat(count);
  642. if(!warehouse){
  643. $("#total_cost" + num).html('');
  644. return;
  645. }
  646. if(!stock_id || !num || isNaN(num) || isNaN(stock_id) ){
  647. $("#total_cost" + num).html('');
  648. return;
  649. }
  650. if(!count || isNaN(count)){
  651. $("#total_cost" + num).html('');
  652. return;
  653. }
  654. var admin = layui.admin;
  655. admin.req({
  656. url: '/warehouse/select/stock/?warehouse=' + warehouse + '&product=' + id
  657. ,done: function(res){
  658. var result_data = res.data;
  659. for (var i in result_data) {
  660. if (result_data[i].stock_id == stock_id){
  661. var total_cost = count * result_data[i].entry_price;
  662. $('#total_cost' + num).html(total_cost.toFixed(4))
  663. }
  664. }
  665. }
  666. })
  667. }
  668. </script>
  669. </body>
  670. </html>