_deliveryOut.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <script>
  2. $(document).ready(function () {
  3. //初始化数据
  4. // $('#outTimet').datetimepicker({
  5. // format: "Y-m-d", //格式化日期
  6. // timepicker: false //关闭时间选项
  7. // });
  8. <?php if ($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 txt = $('.select-itemId li[val=' + itemId + ']').html();
  15. $('.select-itemId .diy_select_txt').html(txt);
  16. var b = $('.rel-peapor-num').html();
  17. outNum(b);
  18. var goodsName = "<?php echo $pmData['goodsName'];?>";
  19. $('#goodsName').text(goodsName);
  20. var orderNo = "<?php echo $pmData['orderNo'];?>";
  21. $('.relate-goods').text(orderNo);
  22. <?php else:?>
  23. //新增页面数据初始化
  24. var date = new Date;
  25. var year = date.getFullYear();
  26. var month = date.getMonth() + 1;
  27. var day = date.getDate(); //获取当前日(1-31)
  28. if(month<10) month = '0'+month;
  29. if(day<10) day = '0'+day;
  30. var maxD = year + '-' + month + '-' + day;
  31. $("#outTimet").attr("value", maxD);
  32. <?php endif;?>
  33. // $(".grade>span").on("click", function() {
  34. $("body").delegate(".grade>span", "click", function () {
  35. $(this).parent().children(".student-list").toggle();
  36. return false;
  37. });
  38. // $(".student-list").on("click", "span", function() {
  39. $("body").delegate(".student-list>.class-li>span", "click", function () {
  40. $(this).parent().toggleClass("active");
  41. $(this).parent().children(".student-name_box").toggle();
  42. return false;
  43. });
  44. // 单选按钮
  45. $('body').on('change', "input[name='studentName']", function () {
  46. getsStudentSelected();
  47. });
  48. // 全选按钮
  49. // $(".btn-select_all").on("click", function() {
  50. $("body").delegate(".btn-select_all", "click", function () {
  51. var obj = $(this).parent().find("input");
  52. if($(this).hasClass('isSelected')){
  53. obj.each(function () {
  54. $(this).prop("checked", false);
  55. })
  56. $(this).removeClass("isSelected");
  57. }else{
  58. obj.each(function () {
  59. if(!$(this).is(":disabled")){
  60. $(this).prop("checked", true);
  61. }
  62. })
  63. $(this).addClass("isSelected");
  64. }
  65. getsStudentSelected();
  66. return false;
  67. });
  68. //关联正式订单
  69. $(".relate-goods").on("click", function () {
  70. var doType = $(this).attr('doType');
  71. relationOrderAction(1,doType);
  72. layer.open({
  73. type: 1,
  74. title: '选择订单',
  75. btn: ['确定'],
  76. area: ['810px', '420px'], //宽高
  77. btnAlign: 'c',
  78. content: $('.layer-relate'),
  79. yes: function (index, layero) {
  80. $('#active-submit-stu').empty();
  81. $('.student-list_box ul').empty();
  82. //提交
  83. var obj = $("input[name='relation_order_select']:checked");
  84. var orderNo = obj.next('input').val();
  85. var goodsName = obj.next('input').next('input').val();
  86. var orderId = obj.val();
  87. if (typeof(orderId) != undefined) {
  88. $(".relate-goods").text(orderNo);
  89. $(".relate-goods").attr('orderId', orderId);
  90. $("#goodsName").text(goodsName);
  91. $("#itemName").text($('#order_item_name').val());
  92. } else {
  93. showMsg(orderId);
  94. }
  95. layer.closeAll();
  96. }
  97. });
  98. return false;
  99. });
  100. //出库数目计算
  101. $("input[name='stu_get_num']").on("input", function () {
  102. var a = $('.rel-peapor-num').html();
  103. outNum(parseInt(a));
  104. });
  105. // 添加图片
  106. $("#uploadImg").on("change", function () {
  107. //限制图片数量
  108. var imgObj = $('#imgPreview img');
  109. if(imgObj.length>=3){
  110. layer.msg("最多可上传三张图片");
  111. return false;
  112. }
  113. var formData = new FormData();
  114. formData.append('uploadFile', document.getElementById('uploadImg').files[0]);
  115. if(document.getElementById('uploadImg').files[0]==undefined){
  116. return false;
  117. }
  118. var basic = "<?php echo $basic;?>";
  119. $.ajax({
  120. url: "<?php echo $uploadUrl;?>",
  121. type: "post",
  122. data: formData,
  123. processData: false,
  124. contentType: false,
  125. beforeSend: function (req) {
  126. req.setRequestHeader("Authorization", basic);
  127. },
  128. success: function (data) {
  129. console.log(data);
  130. if (data.errCode == '00') {
  131. var html = "<img src='" + data.data.url + "'>";
  132. $('#imgPreview').append(html);
  133. $('#uploadImg').val('');
  134. } else {
  135. layer.msg(data.errMsg);
  136. }
  137. }
  138. });
  139. });
  140. $("body").on("click", "#imgPreview img", function () {
  141. var obj = $(this);
  142. var imgUrl = $(this).attr('src');
  143. layer.confirm('您确定删除此图片吗?', {
  144. btn: ['确定', '取消'] //按钮
  145. }, function () {
  146. obj.remove();
  147. layer.closeAll();
  148. });
  149. })
  150. //-----------------------编辑名单-common---------------------------
  151. $(".edit-btn").on("click", function () {
  152. var orderId = $(".relate-goods").attr('orderId');
  153. var inId = "<?php echo isset($_GET['inId'])?$_GET['inId']:0; ?>"
  154. if (typeof(orderId) == undefined || orderId.length <= 0 || orderId == 0) {
  155. layer.msg("请选择关联财务订单!");
  156. return false;
  157. }
  158. //获取学生列表
  159. var isGetStu = false;
  160. var addNotic = '';
  161. if($('.student-list_box li').length<=0){
  162. $.ajax({
  163. type: 'POST',
  164. url: "<?php echo $this->createUrl('imsStore/ajaxAddOutputStu');?>",
  165. data: {orderId: orderId,inId:inId},
  166. async: false,
  167. dataType: 'json',
  168. success: function (result) {
  169. if (result.status == 1) {
  170. $('.student-list_box').html(result.data);
  171. addNotic = result.notice;
  172. isGetStu = true;
  173. } else {
  174. layer.msg('学生列表获取失败!');
  175. }
  176. },
  177. error: function (jqXHR, textStatus, errorThrown) {
  178. layer.msg('学生列表获取失败!');
  179. }
  180. });
  181. }else{
  182. isGetStu = true;
  183. }
  184. //初始化选择的学生
  185. getsStudentSelected();
  186. if (isGetStu == false) {
  187. return false;
  188. }
  189. layer.open({
  190. type: 1,
  191. title: '编辑名单 &nbsp;&nbsp;&nbsp;'+addNotic,
  192. btn: ['保存'],
  193. area: ['800px', '420px'], //宽高
  194. btnAlign: 'c',
  195. content: $('.layer-edit'),
  196. yes: function (index, layero) {
  197. //选择的学生
  198. var stuSeled = $(".student-selected>li");
  199. if (stuSeled.length <= 0) {
  200. showMsg('请选择学生!');
  201. } else {
  202. //把选择的学生信息添加到主页面
  203. var trStr = '';
  204. for (var i = 0; i < stuSeled.length; i++) {
  205. var stuName = $(stuSeled[i]).children('.stu_name').text();
  206. var stuClass = $(stuSeled[i]).children('.stu_class').text();
  207. var stuInfo = $(stuSeled[i]).children('i');
  208. var stuId = $(stuInfo).attr('value');
  209. // var className = $(stuInfo).attr('className');
  210. trStr += '<tr stuId="' + stuId + '">\n' +
  211. ' <th>' + (i+1) + '</th>\n' +
  212. ' <th>' + stuName + '</th>\n' +
  213. ' <th>' + stuClass + '</th>\n' +
  214. ' </tr>';
  215. }
  216. outNum(stuSeled.length);
  217. $("#active-submit-stu").html(trStr);
  218. layer.closeAll();
  219. }
  220. }
  221. });
  222. return false;
  223. });
  224. //删除学生
  225. $(".student-selected").on("click", ".btn-delete", function () {
  226. $(this).parent().remove();
  227. var studentValue = $(this).attr('value');
  228. $("input[value='" + studentValue + "']").prop("checked", false);
  229. var selectedData = $("input[name='studentName']:checked"); //获取所以选中学生
  230. $('#studentSelectedLength').text(selectedData.length);
  231. return false;
  232. });
  233. //分页
  234. $("body").on("click", ".pagination li", function () {
  235. var pageNo = $(this).attr('pageNo');
  236. var doType = $('.relate-goods').attr('doType');
  237. if(pageNo>0){
  238. relationOrderAction(pageNo,doType);
  239. }
  240. });
  241. //提交数据
  242. $(".sale-submit").click(function () {
  243. var flag = true;
  244. if (flag){
  245. flag = false;
  246. var orderId = $(".relate-goods").attr('orderId');
  247. if (orderId <= 0 || !orderId) {
  248. showMsg('请选择关联财务订单!');
  249. return false;
  250. }
  251. var outDate = $.trim($("input[name='out_date']").val());
  252. if (!outDate) {
  253. showMsg('退库日期不正确!');
  254. return false;
  255. }
  256. if (!checkDate(outDate)) {
  257. showMsg('退库日期不正确!');
  258. return false;
  259. }
  260. //选择的学生
  261. var stuSeled = $("#active-submit-stu>tr");
  262. var stuSeledArr = []; //已选学生id数组
  263. if (stuSeled.length <= 0) {
  264. showMsg('请添加学生!');
  265. return false;
  266. } else {
  267. $.each(stuSeled, function (index, value) {
  268. stuSeledArr.push($(value).attr('stuId'));
  269. });
  270. }
  271. <?php if (isset($_GET['inId']) && $_GET['inId'] != ''):?>
  272. //更新
  273. var inId = "<?php echo $_GET['inId'];?>";
  274. var data = {
  275. orderId: orderId,
  276. outDate: outDate,
  277. stuSeledArr: stuSeledArr,
  278. inId: inId
  279. }
  280. <?php else:?>
  281. var data = {
  282. orderId: orderId,
  283. outDate: outDate,
  284. stuSeledArr: stuSeledArr
  285. }
  286. <?php endif;?>
  287. //提交数据
  288. $.ajax({
  289. type: 'POST',
  290. url: "<?php echo $this->createUrl('imsStore/ajaxDeliveryOutAdd');?>",
  291. data: data,
  292. async: false,
  293. dataType: 'json',
  294. success: function (result) {
  295. console.log(result);
  296. if (result.status == 1) {
  297. layer.alert("提交成功", {icon: 1,closeBtn:0}, function () {
  298. window.location.href = "<?php echo $this->createUrl('imsStore/useOut/useOutType/cancle');?>";
  299. })
  300. } else {
  301. flag = true;
  302. layer.msg(result.error);
  303. }
  304. },
  305. error: function (jqXHR, textStatus, errorThrown) {
  306. /*错误信息处理*/
  307. flag = true;
  308. layer.msg('提交失败');
  309. }
  310. });
  311. }else{
  312. layer.msg("稍安勿躁,正在处理中...");
  313. }
  314. });
  315. //关联正式订单方法
  316. function relationOrderAction(page,doType) {
  317. if(doType=='add'){
  318. var orderId = 0;
  319. }else{
  320. var orderId = $('#oldOrderId').val();
  321. }
  322. $.ajax({
  323. type: 'POST',
  324. url: "<?php echo $this->createUrl('imsStore/ajaxOutputOrder');?>",
  325. data: {page: page,doType:doType,orderId:orderId},
  326. async: false,
  327. dataType: 'json',
  328. success: function (res) {
  329. console.log(res);
  330. if (res.status) {
  331. var html = '';
  332. for (var i = 0; i < res.data.list.length; i++) {
  333. var item = res.data.list[i];
  334. html += '<tr>';
  335. html += '<td><label class="checkbox-inline">';
  336. html += '<input type="radio" value="' + item['orderId'] + '" name="relation_order_select">';
  337. html += '<input type="hidden" value="' + item['orderNo'] + '" name="relation_orderNo_select">';
  338. html += '<input type="hidden" value="' + item['goodsName'] + '" name="relation_goodsName_select">';
  339. html += '<input type="hidden" value="' + item['itemName'] + '" id="order_item_name">';
  340. html += '</label></td>';
  341. html += '<td>' + item['orderNo'] + '</td>';
  342. html += '<td>' + item['goodsName'] + '</td>';
  343. html += '<td>' + item['goodsPackageName'] + '</td>';
  344. html += '<td>' + item['createTime'] + '</td>';
  345. html += '<td>' + item['quantity'] + '</td>';
  346. html += '<td>' + item['studentNo'] + '</td>';
  347. html += '</tr>';
  348. }
  349. console.log(page);
  350. setPage(res.data);
  351. } else {
  352. html += '<td>暂无数据</td>';
  353. }
  354. $('.order-table tbody').html(html);
  355. }
  356. });
  357. }
  358. //选择学生
  359. function getsStudentSelected() {
  360. var selectedData = $("input[name='studentName']:checked"); //获取所以选中学生
  361. var selectedDataList = [];
  362. var studentName, studentClass = '';
  363. for (var i = 0; i < selectedData.length; i++) {
  364. studentName = $(selectedData[i]).parent().text();
  365. studentClass = $(selectedData[i]).parents('li').children('span.classTitle').text();
  366. selectedDataList.push('<li><span class="stu_name">' + studentName + '</span>--<span class="stu_class">' + studentClass + '</span><i class="btn-delete" value="' + selectedData[i].value + '" gradeName="' + $(selectedData[i]).attr('gradeName') + '" className="' + $(selectedData[i]).attr('className') + '">X</i></li>');
  367. }
  368. $('.student-selected').html(selectedDataList);
  369. $('#studentSelectedLength').text(selectedData.length);
  370. };
  371. //计算出库数目
  372. function outNum(has) {
  373. var getNum = $("input[name='stu_get_num']").val();
  374. var ever = parseInt(getNum);
  375. $('.rel-peapor-num').html(has);
  376. $('.out-num').html(ever * has);
  377. }
  378. function showMsg(msg) {
  379. layer.msg(msg);
  380. }
  381. //获取字符长度
  382. function getCharLength(str) {
  383. return str.replace(/[\u0391-\uFFE5]/g, "a").length;
  384. }
  385. function checkDate(date) {
  386. return (new Date(date).getDate() == date.substring(date.length - 2));
  387. }
  388. function setPage(data) {
  389. var pageHtml = '';
  390. if(data['pages']>1){
  391. pageHtml+= '<li>';
  392. pageHtml+= '<span style="border: none;background: #ffffff;color: #666666;">';
  393. pageHtml+= '共'+data['total']+'条记录,共'+ data['pages']+'页';
  394. pageHtml+= '</span></li>';
  395. //上一页
  396. if(data['isFirstPage']){
  397. pageHtml+= "<li class='disabled' pageNo=0><a href='#'>上一页</a></li>";
  398. }else{
  399. pageHtml+= "<li class='' pageNo='"+data.prePage+"'><a href='#'>上一页</a></li>";
  400. }
  401. for (var i = 1; i <= data['lastPage']; i++) {
  402. if (i == data['pageNum']) {
  403. pageHtml+= "<li class='active' pageNo='"+i+"'><a href='#'>"+i+"</a></li>";
  404. } else {
  405. pageHtml+= "<li class='' pageNo='"+i+"'><a href='#' pageNo='"+i+"'>"+i+"</a></li>";
  406. }
  407. }
  408. //下一页
  409. if(data['isLastPage']){
  410. pageHtml+= "<li class='disabled' pageNo=0><a href='#'>下一页</a></li>";
  411. }else{
  412. pageHtml+= "<li class='' pageNo='"+data.nextPage+"'><a href='#'>下一页</a></li>";
  413. }
  414. }
  415. $('.pagination').html(pageHtml);
  416. }
  417. })
  418. </script>