common_wigsout.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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_yesterday_btn').click(function(){
  133. eyb();
  134. setTimeout(eyb, 2000);
  135. });
  136. function eyb(){
  137. window.location.href = 'application/main.php?c=wigsOut&m=exportExcel&shop='+0+'&status='+3+'&startDate='+myGetDate(-1)+'&endDate='+myGetDate(-1)+'&type='+0;
  138. }
  139. /**
  140. * change per page amount
  141. * by lijg 20190214
  142. */
  143. $('.pagination').on('change', '.pnsn', function(){
  144. let pnsn = $(this).val();
  145. localStorage.setItem('pnsn', pnsn);
  146. getOrdersInit();
  147. });
  148. $(document).on('click', '.update_memo', function(){
  149. var oid = $(this).data('id');
  150. var omemo = $(this).parent('.options').siblings('.memo').html();
  151. var memo = prompt("请填写备注:", omemo);
  152. if(memo != null && memo != ''){
  153. $.ajax({
  154. type: 'post',
  155. url: 'application/main.php',
  156. data: 'c=wigsOut&m=updateMemo&oid=' + oid + '&memo=' + memo,
  157. success: function(rs){
  158. if(rs == -1){
  159. alert('添加备注失败,请联系开发人员!');
  160. }else{
  161. window.location.reload();
  162. }
  163. },
  164. });
  165. }
  166. });
  167. $('.sync_data').click(function(){
  168. $('.sync_icon').show();
  169. $.ajax({
  170. type: 'get',
  171. url: 'application/main.php',
  172. data: 'c=wigsOut&m=syncData',
  173. dataType: 'json',
  174. success: function(rs){
  175. $('.sync_icon').hide();
  176. if(rs.code == 0){
  177. alert('无新数据!');
  178. }else if(rs.code != 1){
  179. alert('同步失败,请联系开发人员!');
  180. }else{
  181. alert('同步成功!');
  182. window.location.reload();
  183. }
  184. },
  185. });
  186. });
  187. $('#list').on('click', '.print_bc', function(){
  188. var order_barcode = $(this).parent().parent('.list_block').find('.order_barcode').html();
  189. var goods_info = $(this).parent().parent('.list_block').find('.goods_info').html();
  190. var print_time = $(this).parent().parent('.list_block').find('.order_id').data('printtime');
  191. var transport = $(this).parent().parent('.list_block').find('.order_id').data('transport');
  192. var oid = $(this).parent().parent('.list_block').find('.order_id').html();
  193. var LODOP;
  194. LODOP=getLodop();
  195. LODOP.PRINT_INIT("");
  196. if (LODOP.CVERSION) CLODOP.On_Return = function(TaskID, Value) {
  197. if(Value==1){
  198. $.ajax({
  199. type: 'post',
  200. url: 'application/main.php',
  201. data: 'c=wigsOut&m=updatePrint&oid=' + oid,
  202. success: function(rs){
  203. if(rs == -1){
  204. alert('系统错误,请联系开发人员!');
  205. }else{
  206. $('.barcode>.box').html('');
  207. $('.yp').html('').hide();
  208. $('.np').show();
  209. reloadNow();
  210. }
  211. },
  212. });
  213. }else{
  214. alert('系统错误,请联系开发人员!');
  215. }
  216. }
  217. LODOP.ADD_PRINT_BARCODE(3, 2, 400, 35, "128Auto", order_barcode);
  218. LODOP.SET_PRINT_STYLEA(0, "showBarText", 0)
  219. var str=order_barcode+'*'+goods_info + '*' + transport + '*' + print_time;
  220. if(str.length>=130){
  221. str1=str.slice(0,130);
  222. str2=str.slice(130);
  223. LODOP.ADD_PRINT_TEXT(47, "0mm",400,"45mm", str1);
  224. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  225. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  226. LODOP.NewPageA();
  227. LODOP.ADD_PRINT_TEXT(3, "0mm",400,"45mm", str2);
  228. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  229. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  230. }else{
  231. LODOP.ADD_PRINT_TEXT(47, "0mm",400,"45mm", str);
  232. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  233. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  234. }
  235. // LODOP.ADD_PRINT_BARCODE(3, 10, 32, 400, "128Auto", order_barcode);
  236. // LODOP.SET_PRINT_STYLEA(0, "showBarText", 0)
  237. // LODOP.SET_PRINT_STYLEA(0, "Angle", 90)
  238. // var str=order_barcode+'*'+goods_info + '*' + transport + '*' + print_time;
  239. // LODOP.ADD_PRINT_TEXT(450, 4, 500, 45, str);
  240. // LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
  241. // LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  242. // LODOP.SET_PRINT_STYLEA(0, "Angle", 90)
  243. // LODOP.SET_PRINT_PAGESIZE(3,450,70,"")//设置默认纸张
  244. LODOP.PRINT();
  245. });
  246. $('.print_all').click(function(){
  247. $.ajax({
  248. type: 'post',
  249. url: 'application/main.php',
  250. data: 'c=wigsOut&m=printAll',
  251. success: function(rs){
  252. if(rs == -1){
  253. alert('暂无可打印数据!');
  254. }else{
  255. var arr = JSON.parse(rs);
  256. var LODOP;
  257. LODOP=getLodop();
  258. LODOP.PRINT_INIT("");
  259. for(x in arr){
  260. LODOP.ADD_PRINT_BARCODE(3, 2, 400, 35, "128Auto", arr[x].barcode);
  261. LODOP.SET_PRINT_STYLEA(0, "showBarText", 0)
  262. str=arr[x].str;
  263. if(str.length>=130){
  264. str1=str.slice(0,130);
  265. str2=str.slice(130);
  266. LODOP.ADD_PRINT_TEXT(47, "0mm",400,"45mm", str1);
  267. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  268. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  269. LODOP.NewPageA();
  270. LODOP.ADD_PRINT_TEXT(3, "0mm",400,"45mm", str2);
  271. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  272. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  273. }else{
  274. LODOP.ADD_PRINT_TEXT(47, "0mm",400,"45mm", str);
  275. LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
  276. LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
  277. }
  278. // LODOP.SET_PRINT_PAGESIZE(3,450,70,"")//设置默认纸张
  279. // LODOP.PRINTA();
  280. LODOP.PRINT();
  281. }
  282. $('.barcode>.box').html('');
  283. $('.yp').html('').hide();
  284. $('.np').show();
  285. reloadNow();
  286. }
  287. },
  288. });
  289. });
  290. });
  291. /**
  292. * reload current page
  293. * by lijg
  294. * 2019.10.15
  295. */
  296. function reloadNow(){
  297. var shop = $("#shop").val();
  298. var status = $("#orders_status").val();
  299. var start_date = $(".start_date").val();
  300. var end_date = $(".end_date").val();
  301. var type= $("#type").val();
  302. let pnsn = localStorage.getItem('pnsn');
  303. if(pnsn == null){
  304. pnsn = 15;
  305. localStorage.setItem('pnsn', 15);
  306. }
  307. var now = $('#pagination').data('now');
  308. if(!start_date || !end_date){
  309. alert("请选择查询日期");
  310. return false;
  311. }else if(start_date > end_date){
  312. alert("结束日期不得小于起始日期");
  313. return false;
  314. }
  315. var key = getUrlParam();
  316. var param1 = now + '_' + shop + '_' + status + '_' + start_date + '_' + end_date + '_' + key + '_' + pnsn + '_' + type + '_' + time_type;
  317. var param3 = start_date + '_' + end_date + '_' + time_type;
  318. myAjax('wigsOut_getOrders', param1);
  319. myAjax('wigsOut_getStatistics', param3);
  320. }
  321. /**
  322. * get orders
  323. * by lijg
  324. * 2018.11.07
  325. */
  326. function getOrdersInit(){
  327. var shop = $("#shop").val();
  328. var status = $("#orders_status").val();
  329. var start_date = $(".start_date").val();
  330. var end_date = $(".end_date").val();
  331. var type= $("#type").val();
  332. var time_type=$('.time_type').val();
  333. let pnsn = localStorage.getItem('pnsn');
  334. if(pnsn == null){
  335. pnsn = 15;
  336. localStorage.setItem('pnsn', 15);
  337. }
  338. if(!start_date || !end_date){
  339. alert("请选择查询日期");
  340. return false;
  341. }else if(start_date > end_date){
  342. alert("结束日期不得小于起始日期");
  343. return false;
  344. }
  345. var key = getUrlParam();
  346. var param1 = '1' + '_' + shop + '_' + status + '_' + start_date + '_' + end_date + '_' + key + '_' + pnsn + '_' + type+ '_' + time_type;
  347. var param2 = shop + '_' + status + '_' + start_date + '_' + end_date + '_h0' + '_' + pnsn + '_' + type + '_' + time_type;
  348. var param3 = start_date + '_' + end_date + '_' + time_type;
  349. myAjax('wigsOut_getOrders', param1);
  350. myAjax('wigsOut_pagination', param2);
  351. myAjax('wigsOut_getStatistics', param3);
  352. }
  353. /**
  354. * get orders from pagination
  355. * by lijg
  356. * 2018.11.07
  357. */
  358. function getOFP(param){
  359. var key = getUrlParam();
  360. let pnsn = localStorage.getItem('pnsn');
  361. param += '_' + key + '_' + pnsn;
  362. myAjax('wigsOut_getOrders', param);
  363. }
  364. /**
  365. * ajax upload excel for wigsOut
  366. * by lijg
  367. * 2018.11.07
  368. */
  369. function uploadWigsout(aim){
  370. var xmlHttp = getXmlHttpObjecf(xmlHttp == null);
  371. if(xmlHttp == null){
  372. alert("Please update your browser!");
  373. return false;
  374. }
  375. var excel = document.getElementById('excel').files['0'];
  376. if(excel == undefined){
  377. alert("请选择导入文件");
  378. return false;
  379. }else{
  380. var ext = excel.name.substr(excel.name.lastIndexOf('.')+1);
  381. if(ext != 'xlsx'){
  382. alert('请选择 *.xlsx 格式文件!');
  383. return false;
  384. }else{
  385. $(".btn").attr("disabled", true);
  386. $(".upload_icon").show();
  387. }
  388. }
  389. var cm = aim.split('_');
  390. var url = 'application/main.php';
  391. var form = new FormData();
  392. form.append('c', cm[0]);
  393. form.append('m', cm[1]);
  394. form.append('excel', excel);
  395. xmlHttp.onreadystatechange = function(){
  396. stateChanged(xmlHttp, aim);
  397. };
  398. xmlHttp.open('POST', url, true);
  399. xmlHttp.send(form);
  400. }
  401. /**
  402. * update orders
  403. * by lijg 20181108
  404. */
  405. function updateOrdersStatus(code, status){
  406. params = code + '_' + status;
  407. myAjax("wigsOut_updateOrder", params);
  408. }
  409. /**
  410. * get url param
  411. * by lijg 20181120
  412. */
  413. function getUrlParam(){
  414. var url = window.location.href;
  415. var p = url.split('?');
  416. if(p.length == 2){
  417. return p[1];
  418. }else{
  419. return null;
  420. }
  421. }