common_wigsout.js 13 KB

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