_allocationJs.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <script>
  2. var partHtml='<?php echo $part_list;?>';
  3. $(document).ready(function () {
  4. $('.some_class').datetimepicker({
  5. format: "Y-m-d", //格式化日期
  6. timepicker: false //关闭时间选项
  7. });
  8. $('.create-allocation').click(function(){
  9. $.ajax({
  10. url:'<?php echo $this->createUrl('imsStore/inventory')?>',
  11. type:'POST',
  12. dataType:'json',
  13. data:{'page':1},
  14. success:function(res){
  15. if(res.status==1){
  16. //填充数据
  17. var html='';
  18. var list=res.data.list;
  19. $('.prev').removeClass('hide');
  20. $('.next').removeClass('hide');
  21. for(var i=0;i<list.length;i++){
  22. html+='<tr>';
  23. html+='<td><input type="checkbox" name="select_item" value="'+list[i]['itemId']+'"><input type="hidden" class="unitName" name="unitName" value="'+list[i]['unitName']+'">';
  24. html+='<input type="hidden" class="invNo" name="invNo" value="'+list[i]['invNo']+'">';
  25. html+='</td>';
  26. html+='<td>'+list[i]['itemId']+'</td>';
  27. html+='<td class="itemName">'+list[i]['itemName']+'</td>';
  28. html+='<td class="itemType">'+list[i]['typeName']+'</td>';
  29. html+='<td>'+list[i]['invNo']+'</td>';
  30. html+='</tr>';
  31. }
  32. $('.item_list').html(html);
  33. $('.last_page').html(res.data['total_page']);
  34. $('.now_page').html(res.data['now_page']);
  35. if(res.data['now_page']==1){
  36. $('.prev').addClass('hide');
  37. }
  38. if(res.data['now_page']==res.data['total_page']){
  39. $('.next').addClass('hide');
  40. }
  41. layer.open({
  42. type: 1,
  43. title: '添加品目-低值易耗品',
  44. btn: ['确定','取消'],
  45. area: ['620px', '420px'], //宽高
  46. btnAlign: 'c',
  47. content: $('.layer-edit'),
  48. yes: function (index, layero) {
  49. $('input[name=select_item]').each(function(){
  50. if($(this).is(':Checked')){
  51. var vhtml='<tr id="'+$(this).val()+'" class="allocateDetail">';
  52. vhtml+='<td>'+$(this).closest('tr').find('.itemName').html()+'</td>';
  53. vhtml+='<td>'+$(this).closest('tr').find('.itemType').html()+'</td>';
  54. vhtml+='<td><input type="text" class="num" name="num" value="1"></td>';
  55. vhtml+='<td>'+$(this).closest('tr').find('.invNo').val()+'</td>';
  56. vhtml+='<td>'+$(this).closest('tr').find('.unitName').val()+'</td>';
  57. vhtml+='<td><a href="#" class="removePM">移除</a></td>';
  58. vhtml+='</tr>';
  59. $('#P_list').append(vhtml);
  60. }
  61. })
  62. layer.closeAll();
  63. }
  64. });
  65. }
  66. }
  67. });
  68. });
  69. //提交申请
  70. $('#savebutton').click(function(){
  71. var receiveDate=$('input[name=receiveDate]').val();
  72. var receiveUser=$('input[name=receiveUser]').val();
  73. var telephone=$('input[name=telephone]').val();
  74. var address=$('input[name=address]').val();
  75. var remark=$('#remark').val();
  76. var warehouse=$('.warehouse').val();
  77. var receiveStorage = $(".receiveStorage").val();
  78. var operateType = "<?php echo $operateType ?>";
  79. if(operateType == 'edit'){
  80. var atCode=$('input[name=atCode]').val();
  81. var atId=$('input[name=atId]').val();
  82. }
  83. var allocateDetail=[]; //品目
  84. $('.allocateDetail').each(function(){
  85. if($(this).find('.num').val()<1){
  86. layer.msg('申请的品目数量不正确');
  87. return false;
  88. }
  89. str=$(this).attr('id')+'///'+$(this).find('input[name=num]').val();
  90. allocateDetail.push(str);
  91. });
  92. var partDetail=[];//零件
  93. $('.add_part').each(function(){
  94. // if($(this).find('.num').val()<1){
  95. // layer.msg('申请的零件数量不正确');
  96. // return false;
  97. // }
  98. applyNo=$(this).find('input[name=num]').val();
  99. fpTypeId=$(this).find('.part_list').val();
  100. itemId=$(this).find('.device_list').val();
  101. str=applyNo+'///'+fpTypeId+'///'+itemId;
  102. partDetail.push(str);
  103. });
  104. if(warehouse <= 0){
  105. layer.msg('请选择申请发货仓库');
  106. return false;
  107. }
  108. if(receiveStorage ==''){
  109. layer.msg('请选择接收仓库');
  110. return false;
  111. }
  112. if(allocateDetail.length==0 && partDetail.length==0){
  113. layer.msg('请添加品目或者零件类型');
  114. return false;
  115. }
  116. if(receiveDate==''){
  117. layer.msg('请选择接收日期');
  118. return false;
  119. }
  120. if(receiveUser==''){
  121. layer.msg('请输入接收人');
  122. return false;
  123. }
  124. if(telephone==''){
  125. layer.msg('请输入接收人联系方式 ');
  126. return false;
  127. }
  128. if(address==''){
  129. layer.msg('请输入接收地址');
  130. return false;
  131. }
  132. var imgArr = [];
  133. $('#imgPreview img').each(function () {
  134. imgArr.push($(this).attr('src'));
  135. });
  136. if (imgArr.length <= 0) {
  137. layer.msg('请上传发货凭证');
  138. return false;
  139. }
  140. var data={
  141. 'warehouse':warehouse,
  142. 'allocateDetail':allocateDetail,
  143. 'receiveDate':receiveDate,
  144. 'receiveUser':receiveUser,
  145. 'telephone':telephone,
  146. 'address':address,
  147. 'img' : imgArr,
  148. 'remark' : remark,
  149. 'receiveStorage':receiveStorage,
  150. 'partDetail':partDetail
  151. };
  152. console.log(data);
  153. var url = '<?php echo $this->createUrl('imsStore/applysubmit')?>';
  154. if(operateType == 'edit'){
  155. data.atCode = atCode;
  156. data.atId = atId;
  157. url = '<?php echo $this->createUrl('imsStore/applyedit')?>';
  158. }
  159. $.ajax({
  160. url:url,
  161. type:'POST',
  162. dataType:'json',
  163. data:data,
  164. success:function(res){
  165. if(res.status==1){
  166. window.location.href='<?php echo $this->createUrl('imsStore/allocation')?>';
  167. }else{
  168. if(res.msg!=undefined){
  169. layer.msg(res.msg);
  170. }else{
  171. layer.msg('提交失败');
  172. }
  173. }
  174. }
  175. });
  176. });
  177. $('#P_list').on('click','.removePM',function(){
  178. $(this).closest('tr').remove();
  179. })
  180. $('.search_pm').click(function(){
  181. var pm_name=$('input[name=pm_name]').val();
  182. var ptype=$('.pm_type').val();
  183. var warehouse=$('.warehouse').val();
  184. loadPM(pm_name,ptype,1,warehouse);
  185. });
  186. $('.prev').click(function(){
  187. var now_page=parseInt($('.now_page').html());
  188. if(now_page<=1){
  189. return false;
  190. }
  191. var pm_name=$('input[name=pm_name]').val();
  192. var ptype=$('.pm_type').val();
  193. var warehouse=$('.warehouse').val();
  194. loadPM(pm_name,ptype,(now_page-1),warehouse);
  195. });
  196. $('.next').click(function(){
  197. var now_page=parseInt($('.now_page').html());
  198. var last_page=parseInt($('.last_page').html());
  199. if(now_page>=last_page){
  200. return false;
  201. }
  202. var pm_name=$('input[name=pm_name]').val();
  203. var ptype=$('.pm_type').val();
  204. var warehouse=$('.warehouse').val();
  205. loadPM(pm_name,ptype,(now_page+1),warehouse);
  206. });
  207. function loadPM(name,ptype,page,warehouse){
  208. $.ajax({
  209. url:'<?php echo $this->createUrl('imsStore/inventory')?>',
  210. type:'POST',
  211. dataType:'json',
  212. data:{'page':page,'name':name,'type':ptype,'warehouse':warehouse},
  213. success:function(res){
  214. if(res.status==1){
  215. //填充数据
  216. var html='';
  217. var list=res.data.list;
  218. $('.prev').removeClass('hide');
  219. $('.next').removeClass('hide');
  220. for(var i=0;i<list.length;i++){
  221. html+='<tr>';
  222. html+='<td><input type="checkbox" name="select_item" value="'+list[i]['itemId']+'"><input type="hidden" class="unitName" name="unitName" value="'+list[i]['unitName']+'">';
  223. html+='<input type="hidden" class="invNo" name="invNo" value="'+list[i]['invNo']+'">';
  224. html+='</td>';
  225. html+='<td>'+list[i]['itemId']+'</td>';
  226. html+='<td class="itemName">'+list[i]['itemName']+'</td>';
  227. html+='<td class="itemType">'+list[i]['typeName']+'</td>';
  228. html+='<td>'+list[i]['invNo']+'</td>';
  229. html+='</tr>';
  230. }
  231. $('.item_list').html(html);
  232. $('.last_page').html(res.data['total_page']);
  233. $('.now_page').html(res.data['now_page']);
  234. if(res.data['now_page']==1){
  235. $('.prev').addClass('hide');
  236. }
  237. if(res.data['now_page']==res.data['total_page']){
  238. $('.next').addClass('hide');
  239. }
  240. }
  241. }
  242. });
  243. }
  244. $(document)
  245. .on('change','.num',function(){
  246. $(this).val($(this).val().replace(/[^\d+|\.]/g,"1"));
  247. var num=parseInt($(this).val());
  248. console.log(num);
  249. if(num<1 ){
  250. $(this).val(1);
  251. }
  252. })
  253. // 添加图片
  254. $("#uploadImg").on("change", function () {
  255. //限制图片数量
  256. var imgObj = $('#imgPreview img');
  257. var formData = new FormData();
  258. formData.append('uploadFile', document.getElementById('uploadImg').files[0]);
  259. if(document.getElementById('uploadImg').files[0]==undefined){
  260. return false;
  261. }
  262. var basic = "<?php echo $basic;?>";
  263. $.ajax({
  264. url: "<?php echo $uploadUrl;?>",
  265. type: "post",
  266. data: formData,
  267. processData: false,
  268. contentType: false,
  269. beforeSend: function (req) {
  270. req.setRequestHeader("Authorization", basic);
  271. },
  272. success: function (data) {
  273. console.log(data);
  274. if (data.errCode == '00') {
  275. var html = "<img src='" + data.data.url + "'>";
  276. $('#imgPreview').append(html);
  277. $('#uploadImg').val('');
  278. } else {
  279. layer.msg(data.errMsg);
  280. }
  281. }
  282. });
  283. });
  284. $("body").on("click", "#imgPreview img", function () {
  285. var obj = $(this);
  286. var imgUrl = $(this).attr('src');
  287. layer.confirm('您确定删除此图片吗?', {
  288. btn: ['确定', '取消'] //按钮
  289. }, function () {
  290. obj.remove();
  291. layer.closeAll();
  292. });
  293. })
  294. $('.warehouse').change(function(){
  295. utype=$('.warehouse option:selected').attr('utype');
  296. console.log(utype);
  297. if(utype==0){
  298. $('.create-part').attr('disabled',false)
  299. }else{
  300. $('.create-part').attr('disabled',true)
  301. }
  302. $('.add_part').remove();
  303. $('.allocateDetail').remove();
  304. });
  305. $('.receiveStorage').change(function(){
  306. username=$('.receiveStorage option:selected').attr('username');
  307. mobile=$('.receiveStorage option:selected').attr('mobile');
  308. place=$('.receiveStorage option:selected').attr('place');
  309. $('input[name=receiveUser]').val(username);
  310. $('input[name=telephone]').val(mobile);
  311. $('input[name=address]').val(place);
  312. });
  313. //添加零件,设备编号
  314. $('.receiveStorage').change(function(){
  315. $('.add_part').remove();
  316. });
  317. var partTrOrder=0;
  318. $('.create-part').click(function(){
  319. // storageId=$('.receiveStorage').val();
  320. // if(storageId=='0'){
  321. // layer.msg('请选择接收仓库');
  322. // return false;
  323. // }
  324. html='<tr class="add_part">';
  325. html+='<td>'+partHtml+'</td>';
  326. html+='<td ><select class=" device_list part_'+partTrOrder+'"><option value="0">选择</option></select></td>';
  327. html+='<td></td>';
  328. html+='<td></td>';
  329. html+='<td><input type="text" class="num" name="num" value="1"></td>';
  330. html+='<td><a class="remove_part">移除</a></td>';
  331. html+='</tr>';
  332. //console.log(html);
  333. $('#part_list').append(html);
  334. });
  335. $('#part_list')
  336. .on('change','.part_list',function(){
  337. storageId=$('.receiveStorage').val();
  338. partType=$(this).val();
  339. if(partType==0){
  340. return false;
  341. }
  342. if(storageId=='0'){
  343. layer.msg('请选择接收仓库');
  344. return false;
  345. }
  346. obj=$(this);
  347. selectHtml='';
  348. selectHtml+='<option value="0">选择</option>';
  349. obj.closest('tr').find('.device_list').html(selectHtml);
  350. $.ajax({
  351. url: "<?php echo $this->createUrl('imsStore/getDeviceByPart')?>",
  352. type: "post",
  353. data: {storageId: storageId,partType:partType},
  354. dataType: 'json',
  355. success: function (res) {
  356. if(res.status==1){
  357. list=res.data;
  358. if(list.length>0){
  359. if(res.data.length>0){
  360. var list=res.data;
  361. for(var i=0;i<list.length;i++){
  362. selectHtml+='<option value="'+list[i]['fcId']+'" itemName="'+list[i]['itemName']+'" itemSpec="'+list[i]['itemSpec']+'" >'+list[i]['fixedCode']+'</option>';
  363. }
  364. }
  365. obj.closest('tr').find('.device_list').html(selectHtml);
  366. }else{
  367. layer.msg('没有对应零件类型的设备');
  368. }
  369. }
  370. }
  371. })
  372. })
  373. .on('change','.device_list',function(){
  374. //console.log($(this).val());
  375. fixedId=$(this).val();
  376. obj=$(this);
  377. if(fixedId!=0) {
  378. itemName=$(this).find('option:selected').attr('itemName');
  379. itemSpec=$(this).find('option:selected').attr('itemSpec');
  380. obj.closest('tr').find('td').eq(2).html(itemName);
  381. obj.closest('tr').find('td').eq(3).html(itemSpec);
  382. }
  383. })
  384. .on('click','.remove_part',function(){
  385. $(this).closest('tr').remove()
  386. })
  387. })
  388. </script>