_stock.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <script>
  2. $(document).ready(function () {
  3. $('#stocktakingDate').datetimepicker({
  4. format: "Y-m-d", //格式化日期
  5. timepicker: false //关闭时间选项
  6. });
  7. <?php if (isset($_GET['stockId'])):?>
  8. var itemId = "<?php echo $detail['itemId'];?>";
  9. $('#itemId').val(itemId);
  10. var obj = $('.select-itemId li[val=' + itemId + ']');
  11. var txt = obj.html();
  12. $('.select-itemId .diy_select_txt').html(txt);
  13. setItem(obj);
  14. getKuisun();
  15. <?php endif;?>
  16. //品目类别
  17. $('input[name="itemType"]').change(function () {
  18. var itemType = $(this).val();
  19. if(itemType!=0){
  20. $('#fixCode td').html('');
  21. $('#fixCode').fadeOut();
  22. }
  23. //初始化
  24. $('#itemId').val(0);
  25. $('.diy_select_txt').html('请选择品目名称');
  26. $('.item_desc').empty();
  27. $('#stockNo').val('');
  28. $('.get-status').empty();
  29. $('#imgPreview').empty();
  30. $.ajax({
  31. url: "<?php echo Yii::app()->createUrl('imsStore/getItem')?>",
  32. type: "post",
  33. data: {'itemType':itemType},
  34. dataType: 'json',
  35. success: function (res) {
  36. if(res.status){
  37. var html='';
  38. html+='<li val="0">请选择品目名称</li>';
  39. for (var i=0;i<res.data.length;i++){
  40. var ii = res.data[i];
  41. html+= '<li val="'+ii.itemId+'" ' +
  42. 'itemSpec="'+ii.itemSpec+'" ' +
  43. 'unitName="'+ii.unitName+'" ' +
  44. 'unitId="'+ii.unitId+'" ' +
  45. 'invNo="'+ii.invNo+'" ' +
  46. 'itemCode="'+ii.itemCode+'" ' +
  47. 'itemName="'+ii.itemName+'">' +
  48. ii.itemName
  49. '</li>';
  50. }
  51. $('.select-itemId ul').html(html);
  52. }else{
  53. layer.msg("暂无品目");
  54. var html='<li val="0">请选择品目名称</li>';
  55. $('.select-itemId ul').html(html);
  56. return false;
  57. }
  58. }
  59. })
  60. });
  61. //筛选品目
  62. $('body').on('click','.select-itemId li',function () {
  63. var currVal = $(this).attr('val');
  64. if (currVal> 0) {
  65. setItem($(this));
  66. }else{
  67. $('#fixCode td').empty();
  68. $('.item_desc').empty();
  69. }
  70. });
  71. //盈亏计算
  72. $('body').on('input','#stockNo' ,function () {
  73. getKuisun();
  74. });
  75. // 添加图片
  76. $("#fileImg").on("change", function () {
  77. //限制图片数量
  78. var imgObj = $('#imgPreview img');
  79. if(imgObj.length>=3){
  80. layer.msg("最多可上传三张图片");
  81. return false;
  82. }
  83. var formData = new FormData();
  84. formData.append('uploadFile', document.getElementById('fileImg').files[0]);
  85. if(document.getElementById('fileImg').files[0]==undefined){
  86. return false;
  87. }
  88. var basic = "<?php echo $basic;?>";
  89. $.ajax({
  90. url: "<?php echo $uploadUrl;?>",
  91. type: "post",
  92. data: formData,
  93. processData: false,
  94. contentType: false,
  95. beforeSend: function (req) {
  96. req.setRequestHeader("Authorization", basic);
  97. },
  98. success: function (data) {
  99. console.log(data);
  100. if (data.errCode == '00') {
  101. var html = "<img src='" + data.data.url + "'>";
  102. $('#imgPreview').append(html);
  103. $('#uploadImg').val('');
  104. } else {
  105. layer.msg(data.errMsg);
  106. }
  107. }
  108. });
  109. });
  110. $("body").on("click", "#imgPreview img", function () {
  111. var obj = $(this);
  112. var imgUrl = $(this).attr('src');
  113. layer.confirm('您确定删除此图片吗?', {
  114. btn: ['确定', '取消'] //按钮
  115. }, function () {
  116. obj.remove();
  117. layer.closeAll();
  118. });
  119. })
  120. //提交
  121. $("#savebutton").click(function () {
  122. var flag = true;
  123. if (flag){
  124. flag = false;
  125. var stockTitle = $.trim($("input[name='stockTitle']").val());
  126. var stocktakingDate = $("input[name='stocktakingDate']").val();
  127. var itemId = $("input[name='itemId']").val();
  128. var stockNo = $.trim($("input[name='stockNo']").val());
  129. var itemType = $('input[name="itemType"]:checked');
  130. var remark = $('#remark').val();
  131. if (stockTitle == '') {
  132. layer.msg('标题名称不能为空!');
  133. return false;
  134. } else if (stockTitle.length > 49) {
  135. showMsg('标题名称不能超过50个字符!');
  136. return false;
  137. }
  138. if (!stocktakingDate) {
  139. layer.msg('时间不能为空!');
  140. return false;
  141. }
  142. if(itemType.length<=0){
  143. layer.msg('请选择品目类型!');
  144. return false;
  145. }
  146. if (itemId<=0) {
  147. layer.msg('请选择盘点品目!');
  148. return false;
  149. }
  150. if ($.trim(stockNo)=='') {
  151. layer.msg('盘点数量不能为空!');
  152. return false;
  153. }
  154. var imgArr = [];
  155. $('#imgPreview img').each(function () {
  156. imgArr.push($(this).attr('src'));
  157. });
  158. if (imgArr.length < 1) {
  159. layer.msg('请上传图片!');
  160. return false;
  161. }
  162. //固定资产
  163. var fixedCodesArr = [];
  164. var inFixedCodesArr = [];
  165. if (itemType.val()==0){
  166. var fixedObj = $('input[name="fixedCodes"]:checked');
  167. fixedObj.each(function () {
  168. fixedCodesArr.push($(this).val());
  169. });
  170. var infixedObj = $('input[name="fixedCodes"]');
  171. infixedObj.each(function () {
  172. inFixedCodesArr.push($(this).val());
  173. });
  174. }
  175. <?php if (isset($_GET['stockId']) && $_GET['stockId'] != ''):?>
  176. var data = {
  177. stockTitle: stockTitle,
  178. stocktakingDate: stocktakingDate,
  179. itemId: itemId,
  180. itemCode: $('input[name="itemCode"]').val(),
  181. itemName: $('input[name="itemName"]').val(),
  182. itemSpec: $('input[name="itemSpec"]').val(),
  183. unitId: $('input[name="unitId"]').val(),
  184. stockNo: parseInt($('#stockNo').val()),
  185. imgArr: imgArr,
  186. theoreticalNo: parseInt($("#invNo").val()),
  187. stockId: "<?php echo $_GET['stockId'];?>",
  188. itemType: itemType.val(),
  189. fixedCodes:fixedCodesArr,
  190. invFixedCodes:inFixedCodesArr,
  191. remark:remark
  192. };
  193. <?php else:?>
  194. var data = {
  195. stockTitle: stockTitle,
  196. stocktakingDate: stocktakingDate,
  197. itemId: itemId,
  198. itemCode: $('input[name="itemCode"]').val(),
  199. itemName: $('input[name="itemName"]').val(),
  200. itemSpec: $('input[name="itemSpec"]').val(),
  201. unitId: $('input[name="unitId"]').val(),
  202. stockNo: parseInt($('#stockNo').val()),
  203. imgArr: imgArr,
  204. theoreticalNo: parseInt($("#invNo").val()),
  205. itemType: itemType.val(),
  206. fixedCodes:fixedCodesArr,
  207. invFixedCodes:inFixedCodesArr,
  208. remark:remark
  209. };
  210. <?php endif;?>
  211. $.ajax({
  212. type: 'POST',
  213. url: "<?php echo $this->createUrl('imsStore/ajaxStockAdd');?>",
  214. data: data,
  215. async: false,
  216. dataType: 'json',
  217. success: function (result) {
  218. console.log(result);
  219. if (result.status == 1) {
  220. layer.alert(result.msg, {icon: 1,closeBtn:0}, function () {
  221. window.location.href = "<?php echo $this->createUrl('imsStore/stock');?>";
  222. })
  223. } else {
  224. flag = true;
  225. layer.alert(result.msg,{icon:2});
  226. }
  227. },
  228. error: function (jqXHR, textStatus, errorThrown) {
  229. /*错误信息处理*/
  230. flag = true;
  231. layer.msg('提交失败');
  232. }
  233. });
  234. } else {
  235. layer.msg("稍安勿躁,正在处理中...");
  236. }
  237. });
  238. function setItem(obj){
  239. var html = '规格:' + obj.attr('itemSpec') + '; 单位:' + obj.attr('unitName') + '; 理论数量:' + obj.attr('invNo');
  240. $(".item_desc").html(html);
  241. $("#invNo").val(obj.attr('invNo'));
  242. $('input[name="itemSpec"]').val(obj.attr('itemSpec'));
  243. $('input[name="itemName"]').val(obj.attr('itemName'));
  244. $('input[name="itemCode"]').val(obj.attr('itemCode'));
  245. $('input[name="unitId"]').val(obj.attr('unitId'));
  246. //固定资产编号
  247. var hasFixed = [];
  248. <?php if (isset($_GET['stockId']) && $_GET['stockId'] != '' && isset($detail['fixedCodes'])):?>
  249. var hasFixeds = "<?php echo implode(',',$detail['fixedCodes'])?>";
  250. var hasFixed = hasFixeds.split(',');
  251. <?php endif;?>
  252. console.log(hasFixed);
  253. var itemId = $("#itemId").val();
  254. var itemType = $('input[name="itemType"]:checked').val();
  255. if (itemType==0){
  256. $.ajax({
  257. type: 'post',
  258. url: "<?php echo Yii::app()->createUrl('imsStore/getFixCode');?>",
  259. data: {'itemId':obj.attr("val")},
  260. dataType: 'json',
  261. success: function (res) {
  262. console.log(res);
  263. var html = '';
  264. for (var i=0;i<res.data.length;i++){
  265. var fixedCodes = res.data[i];
  266. if($.inArray(fixedCodes,hasFixed)<0){
  267. html+='<lable style="margin-right: 10px;display:inline-block;"><input name="fixedCodes" type="checkbox" value="'+fixedCodes+'"> '+fixedCodes+'</lable>';
  268. }else{
  269. html+='<lable style="margin-right: 10px;display:inline-block;"><input name="fixedCodes" checked type="checkbox" value="'+fixedCodes+'"> '+fixedCodes+'</lable>';
  270. }
  271. }
  272. $('#fixCode').fadeIn();
  273. $('#fixCode td').html(html);
  274. }
  275. });
  276. }
  277. }
  278. function getKuisun() {
  279. var num = parseInt($('#stockNo').val());
  280. var procurementUnit = parseInt($("#invNo").val());
  281. if (num == procurementUnit) {
  282. var html = ' <em class="same">平</em>';
  283. $(".sale-num").html(html);
  284. }
  285. if (num < procurementUnit) {
  286. var html = '<em class="less">亏</em>盈亏数:<span class="red">' + (num - procurementUnit) + '</span>';
  287. $(".sale-num").html(html);
  288. }
  289. if (num > procurementUnit) {
  290. var html = ' <em class="more">盈</em>盈亏数:<span class="red">' + (num - procurementUnit) + '</span>';
  291. $(".sale-num").html(html);
  292. }
  293. }
  294. });
  295. </script>