excel.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. excel();
  26. }
  27. init = function () {
  28. var today = getFormatDate(false),
  29. // var today = '2018-10-10 00:00:00',
  30. now = getFormatDate(true),
  31. val = "",
  32. state = orderState;
  33. $("#startTime").val(today);
  34. $("#endTime").val(now);
  35. $("#startTime").next().show();
  36. $("#endTime").next().show();
  37. }
  38. //搜索-打印表格
  39. searchExcel = function () {
  40. $("#loading").css({"display": "block"});
  41. $("#warp").css({"display": "none"});
  42. var starttime = $("#startTime")[0].value,
  43. endtime = $("#endTime")[0].value;
  44. var parameter = urlEncode(["SelectExcel", starttime, endtime]);
  45. $.ajax({
  46. type: "post",
  47. url: "/new/php/index.php",
  48. data: {mode: parameter},
  49. dataType: "json",
  50. success: function (data) {
  51. if (data.length == 0 || data == -1) {
  52. $("#loading").css({"display": "none"});
  53. $("#warp").css({"display": "table-row-group"});
  54. $("#warp").html("");
  55. var th = '<th colspan="8" scope="col" class="text-c f-20" style="padding: 50px 0;">暂无数据</th>';
  56. $("#warp").html(th);
  57. return;
  58. }
  59. printExcel(data);
  60. }
  61. });
  62. }
  63. printExcel = function (data) {
  64. var warp = $("#warp"),
  65. tr,
  66. state = {1: "已付款,<p style='color:red'>等待发货</p>", 2: "已发货<p style='color:red'>等待收货</p>", 3: "已收货"},
  67. title = "'订单详情'";
  68. var ordernum,
  69. product_remarks,
  70. order_class, order_class_color, order_class_div,
  71. product_price,
  72. order_number,
  73. order_price,
  74. order_time,
  75. order_state,
  76. order_operation, order_operation_delivergoods, order_operation_buygood, order_operation_href, odrer_address;
  77. warp.html("");
  78. for (var i = 0; i < data.length; i++) {
  79. order_class_div = "";
  80. ordernum = '<td><label><input type="checkbox" value=' + data[i].OrderNum + ' >' + data[i].OrderNum + '</label></td>';
  81. product_remarks = '<td>' + data[i].ProductRemarks + '</td>';
  82. product_price = '<td>' + Math.ceil(data[i].ProductPrice) + '</td>';
  83. if (data[i].ProductInfoClassId == "") {
  84. order_class_color = data[i].ProductAttributeId.split(",")[1];
  85. order_class = '<td><div>' +
  86. order_class_color;
  87. order_number = '<td>' + data[i].ProductNumber + '</td>';
  88. order_price = '</td>' + '<td>' + data[i].Payment + '</td>';
  89. }
  90. else {
  91. data[i].ProductInfoClassId = JSON.parse(unescape(data[i].ProductInfoClassId));
  92. for (var j in data[i].ProductInfoClassId) {
  93. if (j == 0) {
  94. order_number = '<td>' + data[i].ProductInfoClassId[0].Number + '</td>';
  95. order_price = '<td>' + parseInt(data[i].ProductInfoClassId[0].Money) * parseInt(data[i].ProductInfoClassId[0].Number) + '</td>';
  96. }
  97. else {
  98. order_class_color = data[i].ProductInfoClassId[j].color;
  99. order_class_div += '<div>' +
  100. order_class_color +
  101. '</div>';
  102. order_class = '<td>' + order_class_div + '</td>';
  103. }
  104. }
  105. }
  106. order_time = '<td><p>' + data[i].OrderAddtime.split(" ")[0] + '</p><p>' + data[i].OrderAddtime.split(" ")[1] + '</p></td>';
  107. order_state = '<td class="state">' + state[data[i].OrderState] + '</td>';
  108. if (data[i].OrderState == 1) {
  109. order_operation_delivergoods = '<a class="btn btn-primary radius td-button" onclick="deliverGoods(\'' + data[i].OrderId + '\',this)">发货</a>';
  110. }
  111. else if (data[i].OrderState == 2) {
  112. order_operation_delivergoods = '<a class="btn btn-primary radius td-button" onclick="collectGoods(\'' + data[i].OrderId + '\',this)">确认买家已收货</a>';
  113. }
  114. else if (data[i].OrderState == 3) {
  115. order_operation_delivergoods = "";
  116. }
  117. if (data[i].BuyGoods == 0 || !data[i].BuyGoods) {
  118. order_operation_buygood = '<a class="btn btn-primary radius td-button" onclick="buygood(\'' + data[i].OrderId + '\',this)">采购</a>';
  119. }
  120. else {
  121. order_operation_buygood = '<a class="btn btn-primary radius td-button">已采购</a>';
  122. }
  123. order_operation_href = "'orderinfo.html?oid=" + data[i].OrderId + "&pid=" + data[i].ProductId + "'";
  124. order_operation = '<td>' + order_operation_delivergoods + order_operation_buygood +
  125. '<a class="btn btn-primary radius td-button" onclick="product_add(' + title + ',' + order_operation_href + ')">查看订单信息</a>' +
  126. '<a class="btn btn-primary radius td-button" onclick="deleteProduct(\'' + data[i].OrderId + '\',this)">删除</a>' +
  127. '</td>';
  128. // odrer_address = '<td>' + data[i].ProductIntroduce + '</td>';
  129. odrer_address = '<td><a href="' + data[i].ProductIntroduce + '">' + data[i].ProductIntroduce + '</a></td>';
  130. tr = $('<tr class="text-c">' + ordernum + product_remarks + order_class + product_price + order_number + order_price + order_time + order_state + '</tr>');
  131. warp.append(tr);
  132. }
  133. $("#loading").css({"display": "none"});
  134. $("#warp").css({"display": "table-row-group"});
  135. }
  136. excel = function () {
  137. $("#getValue").click(function () {
  138. var valArr = new Array;
  139. $("#warp :checkbox").each(function (i) {
  140. if (this.checked === true) {
  141. valArr.push($(this).val());
  142. }
  143. });
  144. var vals = valArr.join(',');
  145. var valsJ = JSON.stringify(vals);
  146. window.open("../php/excel.php?" + "vals=" + valsJ);
  147. // alert(vals);
  148. });
  149. }
  150. getJsonObjLength = function (jsonObj) {
  151. var Length = 0;
  152. for (var item in jsonObj) {
  153. Length++;
  154. }
  155. return Length;
  156. }
  157. urlEncode = function (arr) {
  158. var i; //循环初始化
  159. for (i = 0; i < arr.length; i++) {
  160. arr[i] = encodeURIComponent(encodeURIComponent(arr[i]));
  161. }
  162. return arr.join();
  163. }
  164. getFormatDate = function (flag) {
  165. var nowDate = new Date();
  166. var year = nowDate.getFullYear();
  167. var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
  168. var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
  169. var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
  170. var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
  171. var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
  172. var val;
  173. if (flag == true) {
  174. val = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  175. }
  176. else if (flag == false) {
  177. val = year + "-" + month + "-" + date + " 00:00:00";
  178. }
  179. else if (flag == -1) {
  180. val = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
  181. }
  182. return val;
  183. }
  184. hideSelectClose = function (el) {
  185. $(el).hide();
  186. $("#" + $(el).prev().attr("id")).val("");
  187. }
  188. toogle = function (cs) {
  189. var child = $(cs);
  190. for (var i = 0; i < child.length; i++) {
  191. if (child[i].style.display == "none") {
  192. child[i].style.display = "block";
  193. } else {
  194. child[i].style.display = "none";
  195. }
  196. }
  197. }