common_wigsout.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /**
  2. * window onload
  3. * by lijg
  4. * 2018.11.07
  5. */
  6. window.onload = function(){
  7. // var yesterday = myGetDate(-1);
  8. var today = myGetDate(0);
  9. var monthAgo = myGetDate(-30);
  10. $(".start_date").val(monthAgo);
  11. $(".end_date").val(today);
  12. $(".top_start").html(monthAgo);
  13. $(".top_end").html(today);
  14. getOrdersInit();
  15. $(".code_input_in").focus();
  16. };
  17. /**
  18. * get any date
  19. * by lijg
  20. * 20181108
  21. */
  22. function myGetDate(whichDay){
  23. var myDate = new Date();
  24. myDate.setDate(myDate.getDate()+whichDay);
  25. var year = myDate.getFullYear();
  26. var month = (myDate.getMonth()+1<10)?'0'+(myDate.getMonth()+1):(myDate.getMonth()+1);
  27. var day = (myDate.getDate()<10)?('0'+myDate.getDate()):myDate.getDate();
  28. var today = year + '-' + month + '-' + day;
  29. return today;
  30. }
  31. /**
  32. * by lijg
  33. * 2018.11.07
  34. */
  35. $(document).ready(function(){
  36. var key = getUrlParam();
  37. // if(!key){
  38. // $('.options').hide();
  39. // }
  40. $(document).on("click", ".gtlt", function(){
  41. var shop = $(".shop").val();
  42. var status = $(".orders_status").val();
  43. var type = $(".type").val();
  44. var time_type = $(".time_type").val();
  45. var start = $(".start_date").val();
  46. var end = $(".end_date").val();
  47. var total_page = $(".total_page").data('ttpg');
  48. var wh = $(this).data('wh');
  49. var dir = wh.substr(0, 1);
  50. var now = wh.substr(1);
  51. let pnsn = localStorage.getItem('pnsn');
  52. if(dir == 'h'){
  53. now = (now-1)*10 + 1;
  54. }else if(dir == 't'){
  55. now = now*10 + 1;
  56. }
  57. if(now > 0 && now <= total_page){
  58. var params1 = now + '_' + shop + '_' + status + '_' + start + '_' + end + '_' + key + '_' + pnsn + '_' + type+ '_'+time_type;
  59. var params2 = shop + '_'+ status + '_' + start + '_' + end + '_' + wh + '_' + pnsn + '_' + type + '_'+time_type;
  60. myAjax('wigsOut_getOrders', params1);
  61. myAjax('wigsOut_pagination', params2);
  62. }else{
  63. return false;
  64. }
  65. });
  66. $(document).on("click", ".cancel_order", function(){
  67. var barcode = $(this).data('barcode');
  68. updateOrdersStatus(barcode, '4');
  69. });
  70. $(".status_btn").click(function(){
  71. getOrdersInit();
  72. var start = $(".start_date").val();
  73. var end = $(".end_date").val();
  74. $('.top_start').html(start);
  75. $('.top_end').html(end);
  76. });
  77. $(".code_input_in").change(function(){
  78. var code = $(this).val();
  79. updateOrdersStatus(code, '2');
  80. });
  81. $(".code_input_out").change(function(){
  82. var code = $(this).val();
  83. updateOrdersStatus(code, '3');
  84. });
  85. $(".code_input_dist").change(function(){
  86. var code = $(this).val();
  87. updateOrdersStatus(code, '6');
  88. });
  89. $('.search_code_btn').click(function(){
  90. var code = $('.search_code').val();
  91. if(code.length == 0){
  92. alert('请输入所查找编号!');
  93. return false;
  94. }
  95. var key = getUrlParam();
  96. $.ajax({
  97. type: 'get',
  98. url: 'application/main.php',
  99. data: 'c=wigsOut&m=searchOrders&code=' + code + '&key=' + key,
  100. success: function(rs){
  101. if(rs == '-1'){
  102. alert('查无此编号!');
  103. }else{
  104. $("#list").html(rs);
  105. }
  106. },
  107. });
  108. });
  109. $('.export_btn').click(function(){
  110. var shop = $("#shop").val();
  111. var status = $("#orders_status").val();
  112. var type = $('#type').val();
  113. var start_date = $(".start_date").val();
  114. var end_date = $(".end_date").val();
  115. var time_type= $(".time_type").val();
  116. if(!start_date || !end_date){
  117. alert("请选择查询日期");
  118. return false;
  119. }else if(start_date > end_date){
  120. alert("结束日期不得小于起始日期");
  121. return false;
  122. }
  123. window.location.href = 'application/main.php?c=wigsOut&m=exportExcel&shop='+shop+'&status='+status+'&startDate='+start_date+'&endDate='+end_date+'&type='+type+'&time_type='+time_type;
  124. });
  125. $('.export_yesterday_btn').click(function(){
  126. eyb();
  127. setTimeout(eyb, 2000);
  128. });
  129. function eyb(){
  130. window.location.href = 'application/main.php?c=wigsOut&m=exportExcel&shop='+0+'&status='+3+'&startDate='+myGetDate(-1)+'&endDate='+myGetDate(-1)+'&type='+0;
  131. }
  132. /**
  133. * change per page amount
  134. * by lijg 20190214
  135. */
  136. $('.pagination').on('change', '.pnsn', function(){
  137. let pnsn = $(this).val();
  138. localStorage.setItem('pnsn', pnsn);
  139. getOrdersInit();
  140. });
  141. $(document).on('click', '.update_memo', function(){
  142. var oid = $(this).data('id');
  143. var omemo = $(this).parent('.options').siblings('.memo').html();
  144. var memo = prompt("请填写备注:", omemo);
  145. if(memo != null && memo != ''){
  146. $.ajax({
  147. type: 'post',
  148. url: 'application/main.php',
  149. data: 'c=wigsOut&m=updateMemo&oid=' + oid + '&memo=' + memo,
  150. success: function(rs){
  151. if(rs == -1){
  152. alert('添加备注失败,请联系开发人员!');
  153. }else{
  154. window.location.reload();
  155. }
  156. },
  157. });
  158. }
  159. });
  160. $('.sync_data').click(function(){
  161. $('.sync_icon').show();
  162. $.ajax({
  163. type: 'get',
  164. url: 'application/main.php',
  165. data: 'c=wigsOut&m=syncData',
  166. dataType: 'json',
  167. success: function(rs){
  168. $('.sync_icon').hide();
  169. if(rs.code == 0){
  170. alert('无新数据!');
  171. }else if(rs.code != 1){
  172. alert('同步失败,请联系开发人员!');
  173. }else{
  174. alert('同步成功!');
  175. window.location.reload();
  176. }
  177. },
  178. });
  179. });
  180. $('#list').on('click', '.print_bc', function(){
  181. var order_barcode = $(this).parent().parent('.list_block').find('.order_barcode').html();
  182. var goods_info = $(this).parent().parent('.list_block').find('.goods_info').html();
  183. var print_time = $(this).parent().parent('.list_block').find('.order_id').data('printtime');
  184. var transport = $(this).parent().parent('.list_block').find('.order_id').data('transport');
  185. var oid = $(this).parent().parent('.list_block').find('.order_id').html();
  186. var LODOP;
  187. LODOP=getLodop();
  188. LODOP.PRINT_INIT("");
  189. if (LODOP.CVERSION) CLODOP.On_Return = function(TaskID, Value) {
  190. if(Value==1){
  191. $.ajax({
  192. type: 'post',
  193. url: 'application/main.php',
  194. data: 'c=wigsOut&m=updatePrint&oid=' + oid,
  195. success: function(rs){
  196. if(rs == -1){
  197. alert('系统错误,请联系开发人员!');
  198. }else{
  199. $('.barcode>.box').html('');
  200. $('.yp').html('').hide();
  201. $('.np').show();
  202. reloadNow();
  203. }
  204. },
  205. });
  206. }else{
  207. alert('系统错误,请联系开发人员!');
  208. }
  209. }
  210. LODOP.ADD_PRINT_BARCODE(3, 2, 400, 35, "128Auto", order_barcode);
  211. LODOP.SET_PRINT_STYLEA(0, "showBarText", 0)
  212. var str=order_barcode+'*'+goods_info + '*' + transport + '*' + print_time;
  213. if(str.length>=130){
  214. str1=str.slice(0,130);
  215. str2=str.slice(130);
  216. LODOP.ADD_PRINT_TEXT(47, "0mm",400,"45mm", str1);
  217. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  218. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  219. LODOP.NewPageA();
  220. LODOP.ADD_PRINT_TEXT(3, "0mm",400,"45mm", str2);
  221. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  222. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  223. }else{
  224. LODOP.ADD_PRINT_TEXT(47, "0mm",400,"45mm", str);
  225. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  226. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  227. }
  228. // LODOP.ADD_PRINT_BARCODE(3, 10, 32, 400, "128Auto", order_barcode);
  229. // LODOP.SET_PRINT_STYLEA(0, "showBarText", 0)
  230. // LODOP.SET_PRINT_STYLEA(0, "Angle", 90)
  231. // var str=order_barcode+'*'+goods_info + '*' + transport + '*' + print_time;
  232. // LODOP.ADD_PRINT_TEXT(450, 4, 500, 45, str);
  233. // LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
  234. // LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  235. // LODOP.SET_PRINT_STYLEA(0, "Angle", 90)
  236. // LODOP.SET_PRINT_PAGESIZE(3,450,70,"")//设置默认纸张
  237. LODOP.PRINT();
  238. });
  239. $('.print_all').click(function(){
  240. $.ajax({
  241. type: 'post',
  242. url: 'application/main.php',
  243. data: 'c=wigsOut&m=printAll',
  244. success: function(rs){
  245. if(rs == -1){
  246. alert('暂无可打印数据!');
  247. }else{
  248. var arr = JSON.parse(rs);
  249. var LODOP;
  250. LODOP=getLodop();
  251. LODOP.PRINT_INIT("");
  252. for(x in arr){
  253. LODOP.ADD_PRINT_BARCODE(3, 2, 400, 35, "128Auto", arr[x].barcode);
  254. LODOP.SET_PRINT_STYLEA(0, "showBarText", 0)
  255. str=arr[x].str;
  256. if(str.length>=130){
  257. str1=str.slice(0,130);
  258. str2=str.slice(130);
  259. LODOP.ADD_PRINT_TEXT(47, "0mm",400,"45mm", str1);
  260. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  261. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  262. LODOP.NewPageA();
  263. LODOP.ADD_PRINT_TEXT(3, "0mm",400,"45mm", str2);
  264. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  265. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  266. }else{
  267. LODOP.ADD_PRINT_TEXT(47, "0mm",400,"45mm", str);
  268. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  269. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  270. }
  271. // LODOP.SET_PRINT_PAGESIZE(3,450,70,"")//设置默认纸张
  272. // LODOP.PRINTA();
  273. LODOP.PRINT();
  274. sleep(2000);
  275. }
  276. $('.barcode>.box').html('');
  277. $('.yp').html('').hide();
  278. $('.np').show();
  279. reloadNow();
  280. }
  281. },
  282. });
  283. });
  284. });
  285. /**
  286. * reload current page
  287. * by lijg
  288. * 2019.10.15
  289. */
  290. function reloadNow(){
  291. var shop = $("#shop").val();
  292. var status = $("#orders_status").val();
  293. var start_date = $(".start_date").val();
  294. var end_date = $(".end_date").val();
  295. var type= $("#type").val();
  296. let pnsn = localStorage.getItem('pnsn');
  297. if(pnsn == null){
  298. pnsn = 15;
  299. localStorage.setItem('pnsn', 15);
  300. }
  301. var now = $('#pagination').data('now');
  302. if(!start_date || !end_date){
  303. alert("请选择查询日期");
  304. return false;
  305. }else if(start_date > end_date){
  306. alert("结束日期不得小于起始日期");
  307. return false;
  308. }
  309. var key = getUrlParam();
  310. var param1 = now + '_' + shop + '_' + status + '_' + start_date + '_' + end_date + '_' + key + '_' + pnsn + '_' + type + '_' + time_type;
  311. var param3 = start_date + '_' + end_date + '_' + time_type;
  312. myAjax('wigsOut_getOrders', param1);
  313. myAjax('wigsOut_getStatistics', param3);
  314. }
  315. /**
  316. * get orders
  317. * by lijg
  318. * 2018.11.07
  319. */
  320. function getOrdersInit(){
  321. var shop = $("#shop").val();
  322. var status = $("#orders_status").val();
  323. var start_date = $(".start_date").val();
  324. var end_date = $(".end_date").val();
  325. var type= $("#type").val();
  326. var time_type=$('.time_type').val();
  327. let pnsn = localStorage.getItem('pnsn');
  328. if(pnsn == null){
  329. pnsn = 15;
  330. localStorage.setItem('pnsn', 15);
  331. }
  332. if(!start_date || !end_date){
  333. alert("请选择查询日期");
  334. return false;
  335. }else if(start_date > end_date){
  336. alert("结束日期不得小于起始日期");
  337. return false;
  338. }
  339. var key = getUrlParam();
  340. var param1 = '1' + '_' + shop + '_' + status + '_' + start_date + '_' + end_date + '_' + key + '_' + pnsn + '_' + type+ '_' + time_type;
  341. var param2 = shop + '_' + status + '_' + start_date + '_' + end_date + '_h0' + '_' + pnsn + '_' + type + '_' + time_type;
  342. var param3 = start_date + '_' + end_date + '_' + time_type;
  343. myAjax('wigsOut_getOrders', param1);
  344. myAjax('wigsOut_pagination', param2);
  345. myAjax('wigsOut_getStatistics', param3);
  346. }
  347. /**
  348. * get orders from pagination
  349. * by lijg
  350. * 2018.11.07
  351. */
  352. function getOFP(param){
  353. var key = getUrlParam();
  354. let pnsn = localStorage.getItem('pnsn');
  355. param += '_' + key + '_' + pnsn;
  356. myAjax('wigsOut_getOrders', param);
  357. }
  358. /**
  359. * ajax upload excel for wigsOut
  360. * by lijg
  361. * 2018.11.07
  362. */
  363. function uploadWigsout(aim){
  364. var xmlHttp = getXmlHttpObjecf(xmlHttp == null);
  365. if(xmlHttp == null){
  366. alert("Please update your browser!");
  367. return false;
  368. }
  369. var excel = document.getElementById('excel').files['0'];
  370. if(excel == undefined){
  371. alert("请选择导入文件");
  372. return false;
  373. }else{
  374. var ext = excel.name.substr(excel.name.lastIndexOf('.')+1);
  375. if(ext != 'xlsx'){
  376. alert('请选择 *.xlsx 格式文件!');
  377. return false;
  378. }else{
  379. $(".btn").attr("disabled", true);
  380. $(".upload_icon").show();
  381. }
  382. }
  383. var cm = aim.split('_');
  384. var url = 'application/main.php';
  385. var form = new FormData();
  386. form.append('c', cm[0]);
  387. form.append('m', cm[1]);
  388. form.append('excel', excel);
  389. xmlHttp.onreadystatechange = function(){
  390. stateChanged(xmlHttp, aim);
  391. };
  392. xmlHttp.open('POST', url, true);
  393. xmlHttp.send(form);
  394. }
  395. /**
  396. * update orders
  397. * by lijg 20181108
  398. */
  399. function updateOrdersStatus(code, status){
  400. params = code + '_' + status;
  401. myAjax("wigsOut_updateOrder", params);
  402. }
  403. /**
  404. * get url param
  405. * by lijg 20181120
  406. */
  407. function getUrlParam(){
  408. var url = window.location.href;
  409. var p = url.split('?');
  410. if(p.length == 2){
  411. return p[1];
  412. }else{
  413. return null;
  414. }
  415. }