_useDetail.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. //显示库存
  28. $(".diy_select_list>li").click(function () {
  29. var invNo = $(this).attr('invNo');
  30. var unitName = $(this).attr('unitName');
  31. var typeId = $(this).attr('typeId');
  32. $(".item-num").text(invNo);
  33. $(".unit-name").text(unitName);
  34. $("#typeId").val(typeId);
  35. $('.selected_item').html('');
  36. });
  37. //加减库存
  38. $(".reduce-out").click(function () {
  39. if($("#itemId").val() > 0){
  40. var obj = $("input[name='out_stock_num']");
  41. var stock_nun = parseInt(obj.val());
  42. if(stock_nun > 1){
  43. obj.val(stock_nun - 1);
  44. }
  45. }else{
  46. showMsg('请选择品目名称!');
  47. return false;
  48. }
  49. });
  50. $(".add-out").click(function () {
  51. if($("#itemId").val() > 0){
  52. var obj = $("input[name='out_stock_num']");
  53. var stock_nun = parseInt(obj.val());
  54. if(stock_nun < $(".item-num").text()){
  55. obj.val(stock_nun + 1);
  56. }
  57. }else{
  58. showMsg('请选择品目名称!');
  59. return false;
  60. }
  61. });
  62. //提交数据
  63. $(".bth-s").click(function () {
  64. var flag = true;
  65. if (flag){
  66. flag = false;
  67. //验证数据
  68. var outTitle = $.trim($("input[name='outTitle']").val());
  69. if (outTitle.length == 0) {
  70. showMsg('标题名称不能为空!');
  71. return false;
  72. } else if (outTitle.length > 49) {
  73. showMsg('标题名称不能超过50个字符!');
  74. return false;
  75. }
  76. var relationPmId = $("#itemId").val();
  77. if (relationPmId <= 0 || !relationPmId) {
  78. showMsg('请选择出库品名!');
  79. return false;
  80. }
  81. var outDate = $.trim($("input[name='out_date']").val());
  82. if (!outDate) {
  83. showMsg('出库日期不正确!');
  84. return false;
  85. }
  86. if (!checkDate(outDate)) {
  87. showMsg('出库日期不正确!');
  88. return false;
  89. }
  90. //领用说明
  91. var useExplain = $(".use-explain").val();
  92. var itemId = $("#itemId").val();
  93. if (itemId <= 0) {
  94. showMsg('请选择品目名称!');
  95. return false;
  96. }
  97. //判断出库数量
  98. var itemNum = parseInt($(".item-num").text());
  99. var outStockNum = $("input[name='out_stock_num']").val();
  100. if(outStockNum > itemNum){
  101. showMsg('出库数量不能大于库存!');
  102. return false;
  103. }
  104. if(itemNum <= 0){
  105. showMsg('出库数量必须大于0!');
  106. return false;
  107. }
  108. var itemType = $("input[name='itemType']:checked").val();
  109. if (itemType <= 0 || !itemType) {
  110. showMsg('请选择品目类型!');
  111. return false;
  112. }
  113. var fcId=0;
  114. if(itemType==3){
  115. fcId=$.trim($("#fcId").val());
  116. }
  117. var orderId=$('.orderId').html();
  118. var outId = "<?php echo isset($_GET['outId'])?$_GET['outId']:0;?>";
  119. var data = {
  120. itemId: relationPmId,
  121. useExplain: useExplain,
  122. outTitle: outTitle,
  123. outDate: outDate,
  124. outStockNum: outStockNum,
  125. outId: outId,
  126. itemType:itemType,
  127. orderId:orderId,
  128. fcId:fcId
  129. }
  130. //提交数据
  131. $.ajax({
  132. type: 'POST',
  133. url: "<?php echo $this->createUrl('imsStore/ajaxUseAdd');?>",
  134. data: data,
  135. async: false,
  136. dataType: 'json',
  137. success: function (result) {
  138. console.log(result);
  139. if (result.status == 1) {
  140. layer.alert("提交成功", {icon: 1,closeBtn:0}, function () {
  141. window.location.href = "<?php echo $this->createUrl('imsStore/useOut');?>";
  142. })
  143. } else {
  144. flag = true;
  145. layer.msg(result.msg);
  146. }
  147. },
  148. error: function (jqXHR, textStatus, errorThrown) {
  149. /*错误信息处理*/
  150. flag = true;
  151. layer.msg('提交失败');
  152. }
  153. });
  154. }else{
  155. layer.msg("稍安勿躁,正在处理中...");
  156. }
  157. });
  158. //计算出库数目
  159. function outNum(has) {
  160. var getNum = $("input[name='stu_get_num']").val();
  161. var ever = parseInt(getNum);
  162. $('.rel-peapor-num').html(has);
  163. $('.out-num').html(ever * has);
  164. }
  165. function showMsg(msg) {
  166. layer.msg(msg);
  167. }
  168. function checkDate(date) {
  169. return (new Date(date).getDate() == date.substring(date.length - 2));
  170. }
  171. $(".label-primary-cancle").click(function () {
  172. history.go(-1);
  173. });
  174. //品目类型切花
  175. $("input[name='itemType']").click(function () {
  176. var itemType =$(this).val();
  177. if(itemType){
  178. var outId = "<?php echo isset($_GET['outId'])?$_GET['outId']:0;?>";
  179. window.location.href = "<?php echo $this->createUrl('imsStore/useAddEdit/outId');?>/"+outId+"/itemType/"+itemType;
  180. }
  181. })
  182. });
  183. </script>