_transfer.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <script>
  2. $(document).ready(function () {
  3. //初始化数据
  4. $('#outTimet').datetimepicker({
  5. format: "Y-m-d", //格式化日期
  6. timepicker: false //关闭时间选项
  7. });
  8. <?php if (isset($pmData) && $pmData):?>
  9. //编辑页面数据初始化
  10. var D = "<?php echo date('Y-m-d', strtotime($pmData['outDate']));?>";
  11. $("#outTimet").val(D);
  12. var itemId = "<?php echo $itemId;?>";
  13. $('#itemId').val(itemId);
  14. var pmObj = $('.diy_select_list li[val=' + itemId + ']');
  15. var txt = pmObj.html();
  16. $('.pm_name_txt').text(txt);
  17. $('.item-num').text(pmObj.attr('invNo'));
  18. <?php else:?>
  19. //新增页面数据初始化
  20. var date = new Date;
  21. var year = date.getFullYear();
  22. var month = date.getMonth() + 1;
  23. var day = date.getDate(); //获取当前日(1-31)
  24. var maxD = year + '-' + month + '-' + day;
  25. $("#outTimet").attr("value", maxD);
  26. <?php endif;?>
  27. var transferType = 1;
  28. var itemsType = 2;
  29. var scrapNo = 0;
  30. var invNo = 0;
  31. $("input[name=transfer_type]").click(function(){
  32. transferType = $(this).val();
  33. if(transferType == 1){
  34. $('#type_num').html('不合格品数量');
  35. $(".item-num").text(scrapNo);
  36. }else{
  37. $('#type_num').html('合格品数量');
  38. $(".item-num").text(invNo);
  39. }
  40. });
  41. $("input[name=items_type]").click(function(){
  42. itemsType = $(this).val();
  43. $(".item-num").text(0);
  44. $("#itemId").val(0);
  45. scrapNo = 0;
  46. invNo = 0;
  47. $("input[name='transfer_num']").val(1)
  48. //提交数据
  49. $.ajax({
  50. type: 'POST',
  51. url: "<?php echo $this->createUrl('imsStore/ajaxGetItem');?>",
  52. data: {type:itemsType},
  53. async: false,
  54. dataType: 'json',
  55. success: function (result) {
  56. console.log(result);
  57. if (result.status == 1) {
  58. var liStr = '<li val="0" invNo="0">请选择</li>';
  59. var data = result.data;
  60. for(var i in data){
  61. liStr += '<li val="'+data[i].itemId+'" invNo="'+(data[i].invNo-data[i].scrapNo)+'" unit="'+data[i].unitName+'" scrapNo="'+data[i].scrapNo+'">'+data[i].itemName+'</li>'
  62. }
  63. $('.pm_name_txt').html('请选择')
  64. $('#item_list').html(liStr)
  65. $(".diy_select_list>li").click(function () {
  66. scrapNo = $(this).attr('scrapNo');
  67. invNo = $(this).attr('invNo');
  68. var unit = $(this).attr('unit');
  69. if(transferType == 1){
  70. $(".item-num").text(scrapNo);
  71. }else{
  72. $(".item-num").text(invNo);
  73. }
  74. $("#item-unit").text(unit);
  75. });
  76. } else {
  77. layer.msg(result.msg);
  78. }
  79. },
  80. error: function (jqXHR, textStatus, errorThrown) {
  81. /*错误信息处理*/
  82. flag = true;
  83. layer.msg('提交失败');
  84. }
  85. });
  86. });
  87. //显示库存
  88. $(".diy_select_list>li").click(function () {
  89. scrapNo = $(this).attr('scrapNo');
  90. invNo = $(this).attr('invNo');
  91. var unit = $(this).attr('unit');
  92. if(transferType == 1){
  93. $(".item-num").text(scrapNo);
  94. }else{
  95. $(".item-num").text(invNo);
  96. }
  97. $("#item-unit").text(unit);
  98. });
  99. //加减库存
  100. $(".reduce-out").click(function () {
  101. if($("#itemId").val() > 0){
  102. var obj = $("input[name='transfer_num']");
  103. var stock_nun = parseInt(obj.val());
  104. if(stock_nun > 1){
  105. obj.val(stock_nun - 1);
  106. }
  107. }else{
  108. showMsg('请选择品目名称!');
  109. return false;
  110. }
  111. });
  112. $(".add-out").click(function () {
  113. if($("#itemId").val() > 0){
  114. var obj = $("input[name='transfer_num']");
  115. var stock_nun = parseInt(obj.val());
  116. if(stock_nun < $(".item-num").text()){
  117. obj.val(stock_nun + 1);
  118. }
  119. }else{
  120. showMsg('请选择品目名称!');
  121. return false;
  122. }
  123. });
  124. //提交数据
  125. $(".label-primary-s").click(function () {
  126. var flag = true;
  127. if (flag){
  128. flag = false;
  129. //验证数据
  130. var outTitle = $.trim($("input[name='outTitle']").val());
  131. if (outTitle.length == 0) {
  132. showMsg('标题名称不能为空!');
  133. return false;
  134. } else if (outTitle.length > 49) {
  135. showMsg('标题名称不能超过50个字符!');
  136. return false;
  137. }
  138. var outDate = $.trim($("input[name='out_date']").val());
  139. if (!outDate) {
  140. showMsg('移库日期不正确!');
  141. return false;
  142. }
  143. if (!checkDate(outDate)) {
  144. showMsg('移库日期不正确!');
  145. return false;
  146. }
  147. var itemId = $("#itemId").val();
  148. if (itemId <= 0) {
  149. showMsg('请选择转移品目!');
  150. return false;
  151. }
  152. //判断出库数量
  153. var itemNum = parseInt($(".item-num").text());
  154. var outStockNum = $("input[name='transfer_num']").val();
  155. if(outStockNum > itemNum){
  156. showMsg('转移数大于库存数,不允许移库!');
  157. return false;
  158. }
  159. if(outStockNum <= 0){
  160. showMsg('转移数量数量必须大于0!');
  161. return false;
  162. }
  163. var noticeStr = '';
  164. if(transferType) noticeStr = '确认后,不合格品库存减少,合格品库存增加';
  165. else noticeStr = '确认后,合格品库存减少,不合格品库存增加';
  166. var data = {
  167. itemId: itemId,
  168. title: outTitle,
  169. transferType: transferType,
  170. outDate: outDate,
  171. outStockNum: outStockNum,
  172. itemsType: itemsType
  173. }
  174. layer.confirm('确认操作吗?</br>'+noticeStr, {
  175. btn: ['确定', '取消'], //按钮
  176. }, function () {
  177. $.ajax({
  178. type: 'POST',
  179. url: "<?php echo $this->createUrl('imsStore/ajaxAddTransfer');?>",
  180. data: data,
  181. async: false,
  182. dataType: 'json',
  183. success: function (result) {
  184. if (result.status == 1) {
  185. layer.alert("提交成功", {icon: 1,closeBtn:0}, function () {
  186. window.location.href = "<?php echo $this->createUrl('imsStore/transferlist');?>";
  187. })
  188. } else {
  189. flag = true;
  190. layer.msg(result.msg);
  191. }
  192. },
  193. error: function (jqXHR, textStatus, errorThrown) {
  194. /*错误信息处理*/
  195. flag = true;
  196. layer.msg('提交失败');
  197. }
  198. });
  199. });
  200. //提交数据
  201. }else{
  202. layer.msg("稍安勿躁,正在处理中...");
  203. }
  204. });
  205. //计算出库数目
  206. function outNum(has) {
  207. var getNum = $("input[name='stu_get_num']").val();
  208. var ever = parseInt(getNum);
  209. $('.rel-peapor-num').html(has);
  210. $('.out-num').html(ever * has);
  211. }
  212. function showMsg(msg) {
  213. layer.msg(msg);
  214. }
  215. function checkDate(date) {
  216. return (new Date(date).getDate() == date.substring(date.length - 2));
  217. }
  218. $(".label-primary-cancle").click(function () {
  219. history.go(-1);
  220. });
  221. });
  222. </script>