index.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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(1, 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: "/malai/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><a href="' + data[i].ProductIntroduce + '">' + data[i].ProductIntroduce + '</a></td>';
  309. 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>');
  310. warp.append(tr);
  311. }
  312. $("#loading").css({"display": "none"});
  313. $("#warp").css({"display": "table-row-group"});
  314. }
  315. //搜索
  316. searchProductInfo = function () {
  317. var starttime = $("#startTime").val(),
  318. endtime = $("#endTime").val(),
  319. val = $("#SearchPlaceBtn").val(),
  320. state = orderState;
  321. getProductInfo(starttime, endtime, val, state, 1, 10, false);
  322. // var _val = $("#SearchPlaceBtn").val().trim();
  323. // if (_val == "") {
  324. // layer.msg('请输入订单号、人名、地址、手机号其中一个', {icon: 1});
  325. // }
  326. // else {
  327. // $("#loading").css({display: "table-row-group"});
  328. // $("#warp").css({display: "none"});
  329. // test = true;
  330. // var parameter = urlEncode(["OrderInfoSearch", _val, 1, 10]);
  331. // $.ajax({
  332. // type: "post",
  333. // url: "/new/php/index.php",
  334. // data: {mode: parameter},
  335. // dataType: "json",
  336. // success: function (data) {
  337. // $("#Page").html("");
  338. // if (data.length == 0 || data == -1) {
  339. // $("#loading").css({"display": "none"});
  340. // $("#warp").css({"display": "table-row-group"});
  341. // var th = '<th colspan="10" scope="col" class="text-c f-20" style="padding: 50px 0;">暂无数据</th>';
  342. // $("#warp").html(th);
  343. // // $("#warp").append(th);
  344. // return;
  345. // }
  346. // printProductInfo(data);
  347. // console.log(data);
  348. // }
  349. // });
  350. // }
  351. }
  352. keySearchProductInfo = function () {
  353. if (event.keyCode == 13) {
  354. searchProductInfo();
  355. }
  356. }
  357. //发货
  358. deliverGoods = function (oid, e) {
  359. var el = e;
  360. layer.confirm('是否确定发货?', {
  361. btn: ['确定', '取消'] //按钮
  362. }, function () {
  363. $("#loading").css({"display": "block"});
  364. var parameter = urlEncode(["UpdateOrderState", oid, 2]);
  365. $.ajax({
  366. type: "post",
  367. url: "/malai/php/index.php",
  368. data: {mode: parameter},
  369. dataType: "json",
  370. success: function (data) {
  371. if (data === 1) {
  372. layer.msg('发货成功', {icon: 1});
  373. // $(el).parents().children(".state").html("已发货");
  374. $("#loading").css({"display": "none"});
  375. $(el).remove();
  376. }
  377. }
  378. });
  379. })
  380. }
  381. //收货
  382. collectGoods = function (oid, e) {
  383. var el = e;
  384. layer.confirm('是否确定买家已经收货了?', {
  385. btn: ['确定', '取消'] //按钮
  386. }, function () {
  387. $("#loading").css({"display": "block"});
  388. var parameter = urlEncode(["UpdateOrderState", oid, 3]);
  389. $.ajax({
  390. type: "post",
  391. url: "/malai/php/index.php",
  392. data: {mode: parameter},
  393. dataType: "json",
  394. success: function (data) {
  395. if (data === 1) {
  396. layer.msg('确认成功', {icon: 1});
  397. // $("#asd").parents().children(".state")[0].html("已完成");
  398. // $("#loading").css({"display": "none"});
  399. $(el).parent().parent('tr')[0].remove();
  400. $("#loading").css({"display": "none"});
  401. }
  402. }
  403. });
  404. })
  405. }
  406. //删除
  407. deleteProduct = function (oid, e) {
  408. var el = e;
  409. layer.confirm('是否删除订单?', {
  410. btn: ['确定', '取消'] //按钮
  411. }, function () {
  412. $("#loading").css({"display": "block"});
  413. var parameter = urlEncode(["DeleteOrderRecycleBin", oid, 1]);
  414. $.ajax({
  415. type: "post",
  416. url: "/malai/php/index.php",
  417. data: {mode: parameter},
  418. dataType: "json",
  419. success: function (data) {
  420. if (data === 1) {
  421. layer.msg('删除成功', {icon: 1});
  422. $(el).parent().parent('tr')[0].remove();
  423. $("#loading").css({"display": "none"});
  424. }
  425. }
  426. });
  427. })
  428. }
  429. //是否采购
  430. buygood = function (oid, e) {
  431. var el = e;
  432. if ($(el).html() == "采购") {
  433. layer.confirm('是否确认采购?', {
  434. btn: ['确定', '取消'] //按钮
  435. }, function () {
  436. var parameter = urlEncode(["OrderBuyGoods", oid]);
  437. $.ajax({
  438. type: "post",
  439. url: "/malai/php/index.php",
  440. data: {mode: parameter},
  441. dataType: "json",
  442. success: function (data) {
  443. if (data === 1) {
  444. $(el).html("已采购");
  445. }
  446. layer.msg('采购成功', {icon: 1});
  447. }
  448. });
  449. });
  450. }
  451. }
  452. getJsonObjLength = function (jsonObj) {
  453. var Length = 0;
  454. for (var item in jsonObj) {
  455. Length++;
  456. }
  457. return Length;
  458. }
  459. function product_add(title, url) {
  460. var index = layer.open({
  461. type: 2,
  462. title: title,
  463. content: url
  464. });
  465. layer.full(index);
  466. }
  467. urlEncode = function (arr) {
  468. var i; //循环初始化
  469. for (i = 0; i < arr.length; i++) {
  470. arr[i] = encodeURIComponent(encodeURIComponent(arr[i]));
  471. }
  472. return arr.join();
  473. }
  474. getFormatDate = function (flag) {
  475. var nowDate = new Date();
  476. var year = nowDate.getFullYear();
  477. var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
  478. var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
  479. var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
  480. var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
  481. var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
  482. var val;
  483. if (flag == true) {
  484. val = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  485. }
  486. else if (flag == false) {
  487. val = year + "-" + month + "-" + date + " 00:00:00";
  488. }
  489. else if (flag == -1) {
  490. val = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  491. }
  492. return val;
  493. }
  494. hideSelectClose = function (el) {
  495. $(el).hide();
  496. $("#" + $(el).prev().attr("id")).val("");
  497. }
  498. toogle = function (cs) {
  499. var child = $(cs);
  500. for (var i = 0; i < child.length; i++) {
  501. if (child[i].style.display == "none") {
  502. child[i].style.display = "block";
  503. } else {
  504. child[i].style.display = "none";
  505. }
  506. }
  507. }