index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. var test = true,
  2. orderState = "";
  3. window.onload = function (ev) {
  4. init();
  5. //日历控件
  6. laydate.render({
  7. elem: '#startTime', //指定元素
  8. type: 'datetime',
  9. // value: getFormatDate(false),
  10. max: getFormatDate(true),
  11. done: function (value, date, endDate) {
  12. $("#startTime").next().show();
  13. }
  14. });
  15. //日历控件
  16. laydate.render({
  17. elem: '#endTime', //指定元素
  18. type: 'datetime',
  19. // value: getFormatDate(true),
  20. max: getFormatDate(true),
  21. done: function (value, date, endDate) {
  22. $("#endTime").next().show();
  23. }
  24. });
  25. }
  26. init = function () {
  27. var today = getFormatDate(false),
  28. // var today = '2018-10-10 00:00:00',
  29. now = getFormatDate(true),
  30. val = "",
  31. state = orderState;
  32. $("#startTime").val(today);
  33. $("#endTime").val(now);
  34. $("#startTime").next().show();
  35. $("#endTime").next().show();
  36. getProductInfo(today, now, val, state, 1, 10, true);
  37. }
  38. getProductInfo = function (today, now, val, state, pageindex, pagesize, flag) {
  39. var parameter = urlEncode(["SelectOrderInfo", today, now, val, state, pageindex, pagesize]);
  40. $.ajax({
  41. type: "post",
  42. url: "/taiwan/php/index.php",
  43. data: {mode: parameter},
  44. dataType: "json",
  45. success: function (data) {
  46. if (data.length == 0 || data == -1) {
  47. $("#loading").css({"display": "none"});
  48. $("#warp").css({"display": "table-row-group"});
  49. var th = '<th colspan="11" scope="col" class="text-c f-20" style="padding: 50px 0;">暂无数据</th>';
  50. $("#warp").html(th);
  51. $("#Page").html("");
  52. // $("#warp").append(th);
  53. return;
  54. }
  55. printProductInfo(data);
  56. if (!flag) {
  57. test = true;
  58. }
  59. if (test) {
  60. test = false;
  61. var totalSize = data[0].allcount,
  62. totalPage = Math.ceil(totalSize / pagesize);
  63. // $("#Page").whjPaging("setPage", {currPage: pageindex, totalPage: totalPage, totalSize: totalSize});
  64. $("#Page").html("");
  65. $("#Page").whjPaging({
  66. currPage: pageindex,
  67. totalSize: totalSize,//可选,总条数
  68. totalPage: totalPage,//可选,总页数
  69. isShowRefresh: false,//可选,是否展示刷新,默认true
  70. isShowPageSizeOpt: false,//可选,是否展示每页条数下拉框,默认true,如果设置显示,总条数必须设置
  71. // isResetPage:true,
  72. callBack: function (currPage) {
  73. $("#loading").css({display: "block"});
  74. $("#warp").css({display: "none"});
  75. getProductInfo(today, now, val, orderState, currPage, pagesize, true);
  76. // console.log('currPage:' + currPage + ' pageSize:' + pageSize);
  77. }
  78. });
  79. }
  80. console.log(data);
  81. }
  82. });
  83. }
  84. changeTab = function (state) {
  85. var starttime = $("#startTime").val(),
  86. endtime = $("#endTime").val(),
  87. val = $("#SearchPlaceBtn").val(),
  88. state = state;
  89. getProductInfo(starttime, endtime, val, state, 1, 10, false);
  90. // var li = $(el).parent().children();
  91. // li.removeClass("layui-this");
  92. // $(el).addClass("layui-this");
  93. // $("#loading").css({display: "table-row-group"});
  94. // $("#warp").css({display: "none"});
  95. // test = true;
  96. // getProductInfo(oid, pid, state, pageindex, pagesize);
  97. // $("#SearchPlaceBtn").val("");
  98. }
  99. printProductInfo = function (data) {
  100. // data = data[0];
  101. var warp = $("#warp"),
  102. tr,
  103. state = {1: "已付款,<p style='color:red'>等待发货</p>", 2: "已发货<p style='color:red'>等待收货</p>", 3: "已收货"},
  104. title = "'订单详情'";
  105. var ordernum,
  106. product_remarks,
  107. product_name,
  108. order_class, order_class_img, order_class_color, order_class_size, order_class_div,
  109. product_price,
  110. order_number,
  111. order_price,
  112. order_time,
  113. order_state,
  114. order_operation, order_operation_delivergoods, order_operation_buygood, order_operation_href, odrer_address;
  115. warp.html("");
  116. for (var i = 0; i < data.length; i++) {
  117. order_class_div = "";
  118. ordernum = '<td>' + data[i].OrderNum + '</td>';
  119. product_remarks = '<td>' + data[i].ProductRemarks + '</td>';
  120. product_name = '<td>' + data[i].ProductName + '</td>';
  121. product_price = '<td>' + Math.ceil(data[i].ProductPrice) + '</td>';
  122. if (data[i].ProductInfoClassId == "") {
  123. order_class_img = '<img src="' + data[i].ProductAttributeId.split(",")[0] + '" style="width: 80px;"/>';
  124. order_class_color = data[i].ProductAttributeId.split(",")[1];
  125. order_class_size = (data[i].ProductAttributeId.split(",")[2] && data[i].ProductAttributeId.split(",")[2] != "" && data[i].ProductAttributeId.split(",")[2] != "undefined") ? data[i].ProductAttributeId.split(",")[2] : "无";
  126. order_class = '<td style="text-align: initial;"><div>' +
  127. '<p>颜色:' + order_class_color + '</p>' +
  128. '<p>图片:' + order_class_img + '</p>' +
  129. '<p>尺寸:' + order_class_size + '</p></div></td>';
  130. order_number = '<td>' + data[i].ProductNumber + '</td>';
  131. order_price = '</td>' + '<td>' + data[i].Payment + '</td>';
  132. }
  133. else {
  134. data[i].ProductInfoClassId = JSON.parse(unescape(data[i].ProductInfoClassId));
  135. for (var j in data[i].ProductInfoClassId) {
  136. if (j == 0) {
  137. order_number = '<td>' + data[i].ProductInfoClassId[0].Number + '</td>';
  138. order_price = '<td>' + parseInt(data[i].ProductInfoClassId[0].Money) * parseInt(data[i].ProductInfoClassId[0].Number) + '</td>';
  139. }
  140. else {
  141. order_class_img = '<img src="' + data[i].ProductInfoClassId[j].img + '" style="width: 80px;"/>';
  142. order_class_color = data[i].ProductInfoClassId[j].color;
  143. order_class_size = data[i].ProductInfoClassId[j].size ? data[i].ProductInfoClassId[j].size : "无";
  144. order_class_div += '<div style="margin-bottom: 10px;border-bottom: 1px solid #cecece;">' +
  145. '<p>颜色:' + order_class_color + '</p>' +
  146. '<p>图片:' + order_class_img + '</p>' +
  147. '<p>尺寸:' + order_class_size + '</p>' +
  148. '</div>';
  149. order_class = '<td style="text-align: initial;">' + order_class_div + '</td>';
  150. }
  151. }
  152. }
  153. order_time = '<td><p>' + data[i].OrderAddtime.split(" ")[0] + '</p><p>' + data[i].OrderAddtime.split(" ")[1] + '</p></td>';
  154. order_state = '<td class="state">' + state[data[i].OrderState] + '</td>';
  155. if (data[i].OrderState == 1) {
  156. order_operation_delivergoods = '<a class="btn btn-primary radius td-button" onclick="deliverGoods(\'' + data[i].OrderId + '\',this)">发货</a>';
  157. }
  158. else if (data[i].OrderState == 2) {
  159. order_operation_delivergoods = '<a class="btn btn-primary radius td-button" onclick="collectGoods(\'' + data[i].OrderId + '\',this)">确认买家已收货</a>';
  160. }
  161. else if (data[i].OrderState == 3) {
  162. order_operation_delivergoods = "";
  163. }
  164. if (data[i].BuyGoods == 0 || !data[i].BuyGoods) {
  165. order_operation_buygood = '<a class="btn btn-primary radius td-button" onclick="buygood(\'' + data[i].OrderId + '\',this)">采购</a>';
  166. }
  167. else {
  168. order_operation_buygood = '<a class="btn btn-primary radius td-button">已采购</a>';
  169. }
  170. order_operation_href = "'orderinfo.html?oid=" + data[i].OrderId + "&pid=" + data[i].ProductId + "'";
  171. order_operation = '<td>' + order_operation_delivergoods + order_operation_buygood +
  172. '<a class="btn btn-primary radius td-button" onclick="product_add(' + title + ',' + order_operation_href + ')">查看订单信息</a>' +
  173. '<a class="btn btn-primary radius td-button" onclick="deleteProduct(\'' + data[i].OrderId + '\',this)">删除</a>' +
  174. '</td>';
  175. //odrer_address = '<td>' + data[i].ProductIntroduce + '</td>';
  176. odrer_address = '<td><a href="' + data[i].ProductIntroduce + '">' + data[i].ProductIntroduce + '</a></td>';
  177. 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>');
  178. warp.append(tr);
  179. }
  180. $("#loading").css({"display": "none"});
  181. $("#warp").css({"display": "table-row-group"});
  182. }
  183. //搜索
  184. searchProductInfo = function () {
  185. var starttime = $("#startTime").val(),
  186. endtime = $("#endTime").val(),
  187. val = $("#SearchPlaceBtn").val(),
  188. state = orderState;
  189. getProductInfo(starttime, endtime, val, state, 1, 10, false);
  190. // var _val = $("#SearchPlaceBtn").val().trim();
  191. // if (_val == "") {
  192. // layer.msg('请输入订单号、人名、地址、手机号其中一个', {icon: 1});
  193. // }
  194. // else {
  195. // $("#loading").css({display: "table-row-group"});
  196. // $("#warp").css({display: "none"});
  197. // test = true;
  198. // var parameter = urlEncode(["OrderInfoSearch", _val, 1, 10]);
  199. // $.ajax({
  200. // type: "post",
  201. // url: "/new/php/index.php",
  202. // data: {mode: parameter},
  203. // dataType: "json",
  204. // success: function (data) {
  205. // $("#Page").html("");
  206. // if (data.length == 0 || data == -1) {
  207. // $("#loading").css({"display": "none"});
  208. // $("#warp").css({"display": "table-row-group"});
  209. // var th = '<th colspan="10" scope="col" class="text-c f-20" style="padding: 50px 0;">暂无数据</th>';
  210. // $("#warp").html(th);
  211. // // $("#warp").append(th);
  212. // return;
  213. // }
  214. // printProductInfo(data);
  215. // console.log(data);
  216. // }
  217. // });
  218. // }
  219. }
  220. keySearchProductInfo = function () {
  221. if (event.keyCode == 13) {
  222. searchProductInfo();
  223. }
  224. }
  225. //发货
  226. deliverGoods = function (oid, e) {
  227. var el = e;
  228. layer.confirm('是否确定发货?', {
  229. btn: ['确定', '取消'] //按钮
  230. }, function () {
  231. $("#loading").css({"display": "block"});
  232. var parameter = urlEncode(["UpdateOrderState", oid, 2]);
  233. $.ajax({
  234. type: "post",
  235. url: "/taiwan/php/index.php",
  236. data: {mode: parameter},
  237. dataType: "json",
  238. success: function (data) {
  239. if (data === 1) {
  240. layer.msg('发货成功', {icon: 1});
  241. // $(el).parents().children(".state").html("已发货");
  242. $("#loading").css({"display": "none"});
  243. $(el).remove();
  244. }
  245. }
  246. });
  247. })
  248. }
  249. //收货
  250. collectGoods = function (oid, e) {
  251. var el = e;
  252. layer.confirm('是否确定买家已经收货了?', {
  253. btn: ['确定', '取消'] //按钮
  254. }, function () {
  255. $("#loading").css({"display": "block"});
  256. var parameter = urlEncode(["UpdateOrderState", oid, 3]);
  257. $.ajax({
  258. type: "post",
  259. url: "/taiwan/php/index.php",
  260. data: {mode: parameter},
  261. dataType: "json",
  262. success: function (data) {
  263. if (data === 1) {
  264. layer.msg('确认成功', {icon: 1});
  265. // $("#asd").parents().children(".state")[0].html("已完成");
  266. // $("#loading").css({"display": "none"});
  267. $(el).parent().parent('tr')[0].remove();
  268. $("#loading").css({"display": "none"});
  269. }
  270. }
  271. });
  272. })
  273. }
  274. //删除
  275. deleteProduct = function (oid, e) {
  276. var el = e;
  277. layer.confirm('是否删除订单?', {
  278. btn: ['确定', '取消'] //按钮
  279. }, function () {
  280. $("#loading").css({"display": "block"});
  281. var parameter = urlEncode(["DeleteOrderRecycleBin", oid, 1]);
  282. $.ajax({
  283. type: "post",
  284. url: "/taiwan/php/index.php",
  285. data: {mode: parameter},
  286. dataType: "json",
  287. success: function (data) {
  288. if (data === 1) {
  289. layer.msg('删除成功', {icon: 1});
  290. $(el).parent().parent('tr')[0].remove();
  291. $("#loading").css({"display": "none"});
  292. }
  293. }
  294. });
  295. })
  296. }
  297. //是否采购
  298. buygood = function (oid, e) {
  299. var el = e;
  300. if ($(el).html() == "采购") {
  301. layer.confirm('是否确认采购?', {
  302. btn: ['确定', '取消'] //按钮
  303. }, function () {
  304. var parameter = urlEncode(["OrderBuyGoods", oid]);
  305. $.ajax({
  306. type: "post",
  307. url: "/taiwan/php/index.php",
  308. data: {mode: parameter},
  309. dataType: "json",
  310. success: function (data) {
  311. if (data === 1) {
  312. $(el).html("已采购");
  313. }
  314. layer.msg('采购成功', {icon: 1});
  315. }
  316. });
  317. });
  318. }
  319. }
  320. getJsonObjLength = function (jsonObj) {
  321. var Length = 0;
  322. for (var item in jsonObj) {
  323. Length++;
  324. }
  325. return Length;
  326. }
  327. function product_add(title, url) {
  328. var index = layer.open({
  329. type: 2,
  330. title: title,
  331. content: url
  332. });
  333. layer.full(index);
  334. }
  335. urlEncode = function (arr) {
  336. var i; //循环初始化
  337. for (i = 0; i < arr.length; i++) {
  338. arr[i] = encodeURIComponent(encodeURIComponent(arr[i]));
  339. }
  340. return arr.join();
  341. }
  342. getFormatDate = function (flag) {
  343. var nowDate = new Date();
  344. var year = nowDate.getFullYear();
  345. var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
  346. var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
  347. var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
  348. var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
  349. var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
  350. var val;
  351. if (flag == true) {
  352. val = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  353. }
  354. else if (flag == false) {
  355. val = year + "-" + month + "-" + date + " 00:00:00";
  356. }
  357. else if (flag == -1) {
  358. val = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  359. }
  360. return val;
  361. }
  362. hideSelectClose = function (el) {
  363. $(el).hide();
  364. $("#" + $(el).prev().attr("id")).val("");
  365. }
  366. toogle = function (cs) {
  367. var child = $(cs);
  368. for (var i = 0; i < child.length; i++) {
  369. if (child[i].style.display == "none") {
  370. child[i].style.display = "block";
  371. } else {
  372. child[i].style.display = "none";
  373. }
  374. }
  375. }