common_wigsout.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. }
  275. $('.barcode>.box').html('');
  276. $('.yp').html('').hide();
  277. $('.np').show();
  278. reloadNow();
  279. }
  280. },
  281. });
  282. });
  283. });
  284. /**
  285. * reload current page
  286. * by lijg
  287. * 2019.10.15
  288. */
  289. function reloadNow(){
  290. var shop = $("#shop").val();
  291. var status = $("#orders_status").val();
  292. var start_date = $(".start_date").val();
  293. var end_date = $(".end_date").val();
  294. var type= $("#type").val();
  295. let pnsn = localStorage.getItem('pnsn');
  296. if(pnsn == null){
  297. pnsn = 15;
  298. localStorage.setItem('pnsn', 15);
  299. }
  300. var now = $('#pagination').data('now');
  301. if(!start_date || !end_date){
  302. alert("请选择查询日期");
  303. return false;
  304. }else if(start_date > end_date){
  305. alert("结束日期不得小于起始日期");
  306. return false;
  307. }
  308. var key = getUrlParam();
  309. var param1 = now + '_' + shop + '_' + status + '_' + start_date + '_' + end_date + '_' + key + '_' + pnsn + '_' + type + '_' + time_type;
  310. var param3 = start_date + '_' + end_date + '_' + time_type;
  311. myAjax('wigsOut_getOrders', param1);
  312. myAjax('wigsOut_getStatistics', param3);
  313. }
  314. /**
  315. * get orders
  316. * by lijg
  317. * 2018.11.07
  318. */
  319. function getOrdersInit(){
  320. var shop = $("#shop").val();
  321. var status = $("#orders_status").val();
  322. var start_date = $(".start_date").val();
  323. var end_date = $(".end_date").val();
  324. var type= $("#type").val();
  325. var time_type=$('.time_type').val();
  326. let pnsn = localStorage.getItem('pnsn');
  327. if(pnsn == null){
  328. pnsn = 15;
  329. localStorage.setItem('pnsn', 15);
  330. }
  331. if(!start_date || !end_date){
  332. alert("请选择查询日期");
  333. return false;
  334. }else if(start_date > end_date){
  335. alert("结束日期不得小于起始日期");
  336. return false;
  337. }
  338. var key = getUrlParam();
  339. var param1 = '1' + '_' + shop + '_' + status + '_' + start_date + '_' + end_date + '_' + key + '_' + pnsn + '_' + type+ '_' + time_type;
  340. var param2 = shop + '_' + status + '_' + start_date + '_' + end_date + '_h0' + '_' + pnsn + '_' + type + '_' + time_type;
  341. var param3 = start_date + '_' + end_date + '_' + time_type;
  342. myAjax('wigsOut_getOrders', param1);
  343. myAjax('wigsOut_pagination', param2);
  344. myAjax('wigsOut_getStatistics', param3);
  345. }
  346. /**
  347. * get orders from pagination
  348. * by lijg
  349. * 2018.11.07
  350. */
  351. function getOFP(param){
  352. var key = getUrlParam();
  353. let pnsn = localStorage.getItem('pnsn');
  354. param += '_' + key + '_' + pnsn;
  355. myAjax('wigsOut_getOrders', param);
  356. }
  357. /**
  358. * ajax upload excel for wigsOut
  359. * by lijg
  360. * 2018.11.07
  361. */
  362. function uploadWigsout(aim){
  363. var xmlHttp = getXmlHttpObjecf(xmlHttp == null);
  364. if(xmlHttp == null){
  365. alert("Please update your browser!");
  366. return false;
  367. }
  368. var excel = document.getElementById('excel').files['0'];
  369. if(excel == undefined){
  370. alert("请选择导入文件");
  371. return false;
  372. }else{
  373. var ext = excel.name.substr(excel.name.lastIndexOf('.')+1);
  374. if(ext != 'xlsx'){
  375. alert('请选择 *.xlsx 格式文件!');
  376. return false;
  377. }else{
  378. $(".btn").attr("disabled", true);
  379. $(".upload_icon").show();
  380. }
  381. }
  382. var cm = aim.split('_');
  383. var url = 'application/main.php';
  384. var form = new FormData();
  385. form.append('c', cm[0]);
  386. form.append('m', cm[1]);
  387. form.append('excel', excel);
  388. xmlHttp.onreadystatechange = function(){
  389. stateChanged(xmlHttp, aim);
  390. };
  391. xmlHttp.open('POST', url, true);
  392. xmlHttp.send(form);
  393. }
  394. /**
  395. * update orders
  396. * by lijg 20181108
  397. */
  398. function updateOrdersStatus(code, status){
  399. params = code + '_' + status;
  400. myAjax("wigsOut_updateOrder", params);
  401. }
  402. /**
  403. * get url param
  404. * by lijg 20181120
  405. */
  406. function getUrlParam(){
  407. var url = window.location.href;
  408. var p = url.split('?');
  409. if(p.length == 2){
  410. return p[1];
  411. }else{
  412. return null;
  413. }
  414. }