_delivery.php 19 KB

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