index.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. var test = true,
  2. orderState = "",
  3. webNotice = false,
  4. webNoticeId = "",
  5. oldOrderInfo = false,
  6. oldOrderInfo_malai = false;
  7. window.onload = function (ev) {
  8. init();
  9. //日历控件
  10. laydate.render({
  11. elem: '#startTime', //指定元素
  12. type: 'datetime',
  13. // value: getFormatDate(false),
  14. max: getFormatDate(true),
  15. done: function (value, date, endDate) {
  16. $("#startTime").next().show();
  17. }
  18. });
  19. //日历控件
  20. laydate.render({
  21. elem: '#endTime', //指定元素
  22. type: 'datetime',
  23. // value: getFormatDate(true),
  24. max: getFormatDate(true),
  25. done: function (value, date, endDate) {
  26. $("#endTime").next().show();
  27. }
  28. });
  29. }
  30. init = function () {
  31. var today = getFormatDate(false),
  32. // var today = '2018-10-10 00:00:00',
  33. now = getFormatDate(true),
  34. val = "",
  35. state = orderState;
  36. $("#startTime").val(today);
  37. $("#endTime").val(now);
  38. $("#startTime").next().show();
  39. $("#endTime").next().show();
  40. getProductInfo(today, now, val, state, 1, 10, true);
  41. pagenotify();
  42. }
  43. pagenotify = function () {
  44. notifyMe();
  45. orderWheelSearch();
  46. orderWheelSearchMaLai();
  47. }
  48. notifyMe = function () {
  49. // 先检查浏览器是否支持
  50. if (!("Notification" in window)) {
  51. // alert("本浏览器不支持网页通知提示,如需要网页提示,请使用chrome浏览器打开此网站。");
  52. }
  53. else {
  54. Notification.requestPermission(function (permission) {
  55. if (permission === "granted") {
  56. webNotice = true;
  57. }
  58. else if (Notification.permission === "denied") {
  59. // alert("请打开网页通知权限,或者质询技术人员协助打开。");
  60. }
  61. });
  62. }
  63. }
  64. orderWheelSearch = function () {
  65. setInterval(function () {
  66. var parameter = urlEncode(["OrderWheelSearch"]);
  67. $.ajax({
  68. type: "post",
  69. url: "/new/php/index.php",
  70. data: {mode: parameter},
  71. dataType: "json",
  72. success: function (data) {
  73. if (oldOrderInfo == false) {
  74. oldOrderInfo = data[0];
  75. }
  76. else {
  77. if (oldOrderInfo.OrderId == data[0].OrderId) {
  78. }
  79. else {
  80. oldOrderInfo = data[0];
  81. orderNoticeBody(oldOrderInfo);
  82. $("#audio")[0].play();
  83. }
  84. }
  85. console.log(oldOrderInfo);
  86. }
  87. });
  88. }, 5000);
  89. }
  90. orderWheelSearchMaLai = function () {
  91. setInterval(function () {
  92. var parameter = urlEncode(["OrderWheelSearch"]);
  93. $.ajax({
  94. type: "post",
  95. url: "/malai/php/index.php",
  96. data: {mode: parameter},
  97. dataType: "json",
  98. success: function (data) {
  99. if (oldOrderInfo_malai == false) {
  100. oldOrderInfo_malai = data[0];
  101. }
  102. else {
  103. if (oldOrderInfo_malai.OrderId == data[0].OrderId) {
  104. }
  105. else {
  106. oldOrderInfo_malai = data[0];
  107. orderNoticeBodyMaLai(3, oldOrderInfo_malai);
  108. $("#audio")[0].play();
  109. }
  110. }
  111. }
  112. });
  113. }, 5000);
  114. }
  115. orderNoticeBody = function (type, data) {
  116. var title, obj;
  117. if (type == 1) {
  118. title = "泰国来订单啦";
  119. }
  120. else if (type == 2) {
  121. title = "台湾来订单啦";
  122. }
  123. else if (type == 3) {
  124. title = "马来西亚来订单啦";
  125. }
  126. webNoticeId = data.OrderId + '<>' + data.ProductId;
  127. obj = {
  128. dir: "auto",
  129. body: "订单号:" + data.OrderNum + "\n" +
  130. "产品编号:" + data.ProductRemarks,
  131. // tag: webNoticeId,
  132. icon: JSON.parse(data.ProductInfoClassId)[1].img,
  133. renotify: false
  134. }
  135. var notification = new Notification(title, obj);
  136. notification.onclick = function (event, data) {
  137. event.preventDefault(); // prevent the browser from focusing the Notification's tab
  138. var oid = webNoticeId.split("<>")[0],
  139. pid = webNoticeId.split("<>")[1];
  140. window.open('https://kjdspro.com/new/admin/orderinfo.html?oid=' + oid + '&pid=' + pid, '_blank');
  141. }
  142. }
  143. orderNoticeBodyMaLai = function (type, data) {
  144. var title, obj;
  145. if (type == 1) {
  146. title = "泰国来订单啦";
  147. }
  148. else if (type == 2) {
  149. title = "台湾来订单啦";
  150. }
  151. else if (type == 3) {
  152. title = "马来西亚来订单啦";
  153. }
  154. webNoticeId = data.OrderId + '<>' + data.ProductId;
  155. obj = {
  156. dir: "auto",
  157. body: "订单号:" + data.OrderNum + "\n" +
  158. "产品编号:" + data.ProductRemarks,
  159. // tag: webNoticeId,
  160. icon: JSON.parse(data.ProductInfoClassId)[1].img,
  161. renotify: false
  162. }
  163. var notification = new Notification(title, obj);
  164. notification.onclick = function (event, data) {
  165. event.preventDefault(); // prevent the browser from focusing the Notification's tab
  166. var oid = webNoticeId.split("<>")[0],
  167. pid = webNoticeId.split("<>")[1];
  168. window.open('https://kjdspro.com/malai/admin/orderinfo.html?oid=' + oid + '&pid=' + pid, '_blank');
  169. }
  170. }
  171. getProductInfo = function (today, now, val, state, pageindex, pagesize, flag) {
  172. var parameter = urlEncode(["SelectOrderInfo", today, now, val, state, pageindex, pagesize]);
  173. $.ajax({
  174. type: "post",
  175. url: "/new/php/index.php",
  176. data: {mode: parameter},
  177. dataType: "json",
  178. success: function (data) {
  179. if (data.length == 0 || data == -1) {
  180. $("#loading").css({"display": "none"});
  181. $("#warp").css({"display": "table-row-group"});
  182. var th = '<th colspan="11" scope="col" class="text-c f-20" style="padding: 50px 0;">暂无数据</th>';
  183. $("#warp").html(th);
  184. $("#Page").html("");
  185. // $("#warp").append(th);
  186. return;
  187. }
  188. printProductInfo(data);
  189. if (!flag) {
  190. test = true;
  191. }
  192. if (test) {
  193. test = false;
  194. var totalSize = data[0].allcount,
  195. totalPage = Math.ceil(totalSize / pagesize);
  196. // $("#Page").whjPaging("setPage", {currPage: pageindex, totalPage: totalPage, totalSize: totalSize});
  197. $("#Page").html("");
  198. $("#Page").whjPaging({
  199. currPage: pageindex,
  200. totalSize: totalSize,//可选,总条数
  201. totalPage: totalPage,//可选,总页数
  202. isShowRefresh: false,//可选,是否展示刷新,默认true
  203. isShowPageSizeOpt: false,//可选,是否展示每页条数下拉框,默认true,如果设置显示,总条数必须设置
  204. // isResetPage:true,
  205. callBack: function (currPage) {
  206. $("#loading").css({display: "block"});
  207. $("#warp").css({display: "none"});
  208. getProductInfo(today, now, val, orderState, currPage, pagesize, true);
  209. // console.log('currPage:' + currPage + ' pageSize:' + pageSize);
  210. }
  211. });
  212. }
  213. console.log(data);
  214. }
  215. });
  216. }
  217. changeTab = function (state) {
  218. var starttime = $("#startTime").val(),
  219. endtime = $("#endTime").val(),
  220. val = $("#SearchPlaceBtn").val(),
  221. state = state;
  222. getProductInfo(starttime, endtime, val, state, 1, 10, false);
  223. // var li = $(el).parent().children();
  224. // li.removeClass("layui-this");
  225. // $(el).addClass("layui-this");
  226. // $("#loading").css({display: "table-row-group"});
  227. // $("#warp").css({display: "none"});
  228. // test = true;
  229. // getProductInfo(oid, pid, state, pageindex, pagesize);
  230. // $("#SearchPlaceBtn").val("");
  231. }
  232. printProductInfo = function (data) {
  233. // data = data[0];
  234. var warp = $("#warp"),
  235. tr,
  236. state = {1: "已付款,<p style='color:red'>等待发货</p>", 2: "已发货<p style='color:red'>等待收货</p>", 3: "已收货"},
  237. title = "'订单详情'";
  238. var ordernum,
  239. product_remarks,
  240. product_name,
  241. order_class, order_class_img, order_class_color, order_class_size, order_class_div,
  242. product_price,
  243. order_number,
  244. order_price,
  245. order_time,
  246. order_state,
  247. order_operation, order_operation_delivergoods, order_operation_buygood, order_operation_href, odrer_address;
  248. warp.html("");
  249. for (var i = 0; i < data.length; i++) {
  250. order_class_div = "";
  251. ordernum = '<td>' + data[i].OrderNum + '</td>';
  252. product_remarks = '<td>' + data[i].ProductRemarks + '</td>';
  253. product_name = '<td>' + data[i].ProductName + '</td>';
  254. product_price = '<td>' + Math.ceil(data[i].ProductPrice) + '</td>';
  255. if (data[i].ProductInfoClassId == "") {
  256. order_class_img = '<img src="' + data[i].ProductAttributeId.split(",")[0] + '" style="width: 80px;"/>';
  257. order_class_color = data[i].ProductAttributeId.split(",")[1];
  258. order_class_size = (data[i].ProductAttributeId.split(",")[2] && data[i].ProductAttributeId.split(",")[2] != "" && data[i].ProductAttributeId.split(",")[2] != "undefined") ? data[i].ProductAttributeId.split(",")[2] : "无";
  259. order_class = '<td style="text-align: initial;"><div>' +
  260. '<p>颜色:' + order_class_color + '</p>' +
  261. '<p>图片:' + order_class_img + '</p>' +
  262. '<p>尺寸:' + order_class_size + '</p></div></td>';
  263. order_number = '<td>' + data[i].ProductNumber + '</td>';
  264. order_price = '</td>' + '<td>' + data[i].Payment + '</td>';
  265. }
  266. else {
  267. data[i].ProductInfoClassId = JSON.parse(unescape(data[i].ProductInfoClassId));
  268. for (var j in data[i].ProductInfoClassId) {
  269. if (j == 0) {
  270. order_number = '<td>' + data[i].ProductInfoClassId[0].Number + '</td>';
  271. order_price = '<td>' + parseInt(data[i].ProductInfoClassId[0].Money) * parseInt(data[i].ProductInfoClassId[0].Number) + '</td>';
  272. }
  273. else {
  274. order_class_img = '<img src="' + data[i].ProductInfoClassId[j].img + '" style="width: 80px;"/>';
  275. order_class_color = data[i].ProductInfoClassId[j].color;
  276. order_class_size = data[i].ProductInfoClassId[j].size ? data[i].ProductInfoClassId[j].size : "无";
  277. order_class_div += '<div style="margin-bottom: 10px;border-bottom: 1px solid #cecece;">' +
  278. '<p>颜色:' + order_class_color + '</p>' +
  279. '<p>图片:' + order_class_img + '</p>' +
  280. '<p>尺寸:' + order_class_size + '</p>' +
  281. '</div>';
  282. order_class = '<td style="text-align: initial;">' + order_class_div + '</td>';
  283. }
  284. }
  285. }
  286. order_time = '<td><p>' + data[i].OrderAddtime.split(" ")[0] + '</p><p>' + data[i].OrderAddtime.split(" ")[1] + '</p></td>';
  287. order_state = '<td class="state">' + state[data[i].OrderState] + '</td>';
  288. if (data[i].OrderState == 1) {
  289. order_operation_delivergoods = '<a class="btn btn-primary radius td-button" onclick="deliverGoods(\'' + data[i].OrderId + '\',this)">发货</a>';
  290. }
  291. else if (data[i].OrderState == 2) {
  292. order_operation_delivergoods = '<a class="btn btn-primary radius td-button" onclick="collectGoods(\'' + data[i].OrderId + '\',this)">确认买家已收货</a>';
  293. }
  294. else if (data[i].OrderState == 3) {
  295. order_operation_delivergoods = "";
  296. }
  297. if (data[i].BuyGoods == 0 || !data[i].BuyGoods) {
  298. order_operation_buygood = '<a class="btn btn-primary radius td-button" onclick="buygood(\'' + data[i].OrderId + '\',this)">采购</a>';
  299. }
  300. else {
  301. order_operation_buygood = '<a class="btn btn-primary radius td-button">已采购</a>';
  302. }
  303. order_operation_href = "'orderinfo.html?oid=" + data[i].OrderId + "&pid=" + data[i].ProductId + "'";
  304. order_operation = '<td>' + order_operation_delivergoods + order_operation_buygood +
  305. '<a class="btn btn-primary radius td-button" onclick="product_add(' + title + ',' + order_operation_href + ')">查看订单信息</a>' +
  306. '<a class="btn btn-primary radius td-button" onclick="deleteProduct(\'' + data[i].OrderId + '\',this)">删除</a>' +
  307. '</td>';
  308. // odrer_address = '<td>' + data[i].ProductIntroduce + '</td>';
  309. odrer_address = '<td><a href="' + data[i].ProductIntroduce + '">' + data[i].ProductIntroduce + '</a></td>';
  310. tr = $('<tr class="text-c">' + ordernum + product_remarks + product_name + order_class + product_price + order_number + order_price + order_time + order_state + odrer_address + order_operation + '</tr>');
  311. warp.append(tr);
  312. }
  313. $("#loading").css({"display": "none"});
  314. $("#warp").css({"display": "table-row-group"});
  315. }
  316. //搜索
  317. searchProductInfo = function () {
  318. var starttime = $("#startTime").val(),
  319. endtime = $("#endTime").val(),
  320. val = $("#SearchPlaceBtn").val(),
  321. state = orderState;
  322. getProductInfo(starttime, endtime, val, state, 1, 10, false);
  323. // var _val = $("#SearchPlaceBtn").val().trim();
  324. // if (_val == "") {
  325. // layer.msg('请输入订单号、人名、地址、手机号其中一个', {icon: 1});
  326. // }
  327. // else {
  328. // $("#loading").css({display: "table-row-group"});
  329. // $("#warp").css({display: "none"});
  330. // test = true;
  331. // var parameter = urlEncode(["OrderInfoSearch", _val, 1, 10]);
  332. // $.ajax({
  333. // type: "post",
  334. // url: "/new/php/index.php",
  335. // data: {mode: parameter},
  336. // dataType: "json",
  337. // success: function (data) {
  338. // $("#Page").html("");
  339. // if (data.length == 0 || data == -1) {
  340. // $("#loading").css({"display": "none"});
  341. // $("#warp").css({"display": "table-row-group"});
  342. // var th = '<th colspan="10" scope="col" class="text-c f-20" style="padding: 50px 0;">暂无数据</th>';
  343. // $("#warp").html(th);
  344. // // $("#warp").append(th);
  345. // return;
  346. // }
  347. // printProductInfo(data);
  348. // console.log(data);
  349. // }
  350. // });
  351. // }
  352. }
  353. keySearchProductInfo = function () {
  354. if (event.keyCode == 13) {
  355. searchProductInfo();
  356. }
  357. }
  358. //发货
  359. deliverGoods = function (oid, e) {
  360. var el = e;
  361. layer.confirm('是否确定发货?', {
  362. btn: ['确定', '取消'] //按钮
  363. }, function () {
  364. $("#loading").css({"display": "block"});
  365. var parameter = urlEncode(["UpdateOrderState", oid, 2]);
  366. $.ajax({
  367. type: "post",
  368. url: "/new/php/index.php",
  369. data: {mode: parameter},
  370. dataType: "json",
  371. success: function (data) {
  372. if (data === 1) {
  373. layer.msg('发货成功', {icon: 1});
  374. // $(el).parents().children(".state").html("已发货");
  375. $("#loading").css({"display": "none"});
  376. $(el).remove();
  377. }
  378. }
  379. });
  380. })
  381. }
  382. //收货
  383. collectGoods = function (oid, e) {
  384. var el = e;
  385. layer.confirm('是否确定买家已经收货了?', {
  386. btn: ['确定', '取消'] //按钮
  387. }, function () {
  388. $("#loading").css({"display": "block"});
  389. var parameter = urlEncode(["UpdateOrderState", oid, 3]);
  390. $.ajax({
  391. type: "post",
  392. url: "/new/php/index.php",
  393. data: {mode: parameter},
  394. dataType: "json",
  395. success: function (data) {
  396. if (data === 1) {
  397. layer.msg('确认成功', {icon: 1});
  398. // $("#asd").parents().children(".state")[0].html("已完成");
  399. // $("#loading").css({"display": "none"});
  400. $(el).parent().parent('tr')[0].remove();
  401. $("#loading").css({"display": "none"});
  402. }
  403. }
  404. });
  405. })
  406. }
  407. //删除
  408. deleteProduct = function (oid, e) {
  409. var el = e;
  410. layer.confirm('是否删除订单?', {
  411. btn: ['确定', '取消'] //按钮
  412. }, function () {
  413. $("#loading").css({"display": "block"});
  414. var parameter = urlEncode(["DeleteOrderRecycleBin", oid, 1]);
  415. $.ajax({
  416. type: "post",
  417. url: "/new/php/index.php",
  418. data: {mode: parameter},
  419. dataType: "json",
  420. success: function (data) {
  421. if (data === 1) {
  422. layer.msg('删除成功', {icon: 1});
  423. $(el).parent().parent('tr')[0].remove();
  424. $("#loading").css({"display": "none"});
  425. }
  426. }
  427. });
  428. })
  429. }
  430. //是否采购
  431. buygood = function (oid, e) {
  432. var el = e;
  433. if ($(el).html() == "采购") {
  434. layer.confirm('是否确认采购?', {
  435. btn: ['确定', '取消'] //按钮
  436. }, function () {
  437. var parameter = urlEncode(["OrderBuyGoods", oid]);
  438. $.ajax({
  439. type: "post",
  440. url: "/new/php/index.php",
  441. data: {mode: parameter},
  442. dataType: "json",
  443. success: function (data) {
  444. if (data === 1) {
  445. $(el).html("已采购");
  446. }
  447. layer.msg('采购成功', {icon: 1});
  448. }
  449. });
  450. });
  451. }
  452. }
  453. orderWheelSearch = function () {
  454. setInterval(function () {
  455. var parameter = urlEncode(["OrderWheelSearch"]);
  456. $.ajax({
  457. type: "post",
  458. url: "/new/php/index.php",
  459. data: {mode: parameter},
  460. dataType: "json",
  461. success: function (data) {
  462. if (oldOrderInfo == false) {
  463. oldOrderInfo = data[0];
  464. }
  465. else {
  466. if (oldOrderInfo.OrderId == data[0].OrderId) {
  467. }
  468. else {
  469. oldOrderInfo = data[0];
  470. orderNoticeBody(1,oldOrderInfo);
  471. $("#audio")[0].play();
  472. }
  473. }
  474. console.log(oldOrderInfo);
  475. }
  476. });
  477. }, 5000);
  478. }
  479. getJsonObjLength = function (jsonObj) {
  480. var Length = 0;
  481. for (var item in jsonObj) {
  482. Length++;
  483. }
  484. return Length;
  485. }
  486. function product_add(title, url) {
  487. var index = layer.open({
  488. type: 2,
  489. title: title,
  490. content: url
  491. });
  492. layer.full(index);
  493. }
  494. urlEncode = function (arr) {
  495. var i; //循环初始化
  496. for (i = 0; i < arr.length; i++) {
  497. arr[i] = encodeURIComponent(encodeURIComponent(arr[i]));
  498. }
  499. return arr.join();
  500. }
  501. getFormatDate = function (flag) {
  502. var nowDate = new Date();
  503. var year = nowDate.getFullYear();
  504. var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
  505. var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
  506. var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
  507. var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
  508. var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
  509. var val;
  510. if (flag == true) {
  511. val = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  512. }
  513. else if (flag == false) {
  514. val = year + "-" + month + "-" + date + " 00:00:00";
  515. }
  516. else if (flag == -1) {
  517. val = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  518. }
  519. return val;
  520. }
  521. hideSelectClose = function (el) {
  522. $(el).hide();
  523. $("#" + $(el).prev().attr("id")).val("");
  524. }
  525. toogle = function (cs) {
  526. var child = $(cs);
  527. for (var i = 0; i < child.length; i++) {
  528. if (child[i].style.display == "none") {
  529. child[i].style.display = "block";
  530. } else {
  531. child[i].style.display = "none";
  532. }
  533. }
  534. }