lists.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <link rel="stylesheet" href="ADMIN_CSS/order_list.css"/>
  4. {/block}
  5. {block name="main"}
  6. <div class="ns-screen layui-collapse">
  7. <div class="layui-colla-item">
  8. <h2 class="layui-colla-title">筛选</h2>
  9. <form class="layui-colla-content layui-form layui-show" lay-filter="order_list">
  10. <div class="layui-form-item">
  11. <div class="layui-inline">
  12. <label class="layui-form-label">搜索方式:</label>
  13. <div class="layui-input-inline">
  14. <select name="order_label" >
  15. {foreach $order_label_list as $k => $label_val}
  16. <option value="{$k}">{$label_val}</option>
  17. {/foreach}
  18. </select>
  19. </div>
  20. <div class="layui-input-inline">
  21. <input type="text" name="search" autocomplete="off" class="layui-input" />
  22. </div>
  23. </div>
  24. </div>
  25. <div class="layui-form-item">
  26. <div class="layui-inline">
  27. <label class="layui-form-label">下单时间:</label>
  28. <div class="layui-input-inline">
  29. <input type="text" class="layui-input" name="start_time" placeholder="开始时间" id="start_time" readonly>
  30. <i class="ns-calendar"></i>
  31. </div>
  32. <div class="layui-form-mid">-</div>
  33. <div class="layui-input-inline">
  34. <input type="text" class="layui-input" name="end_time" placeholder="结束时间" id="end_time" readonly>
  35. <i class="ns-calendar"></i>
  36. </div>
  37. <button class="layui-btn layui-btn-primary date-picker-btn" onclick="datePick(7, this);return false;">近7天</button>
  38. <button class="layui-btn layui-btn-primary date-picker-btn" onclick="datePick(30, this);return false;">近30天</button>
  39. </div>
  40. </div>
  41. <div class="layui-form-item">
  42. <div class="layui-inline">
  43. <label class="layui-form-label">订单类型:</label>
  44. <div class="layui-input-inline">
  45. <select name="order_type" lay-filter="order_type">
  46. {foreach $order_type_list as $order_type_k => $order_type_val}
  47. <option value="{$order_type_val.type}">{$order_type_val.name}</option>
  48. {/foreach}
  49. </select>
  50. </div>
  51. </div>
  52. <div class="layui-inline">
  53. <label class="layui-form-label">订单状态:</label>
  54. <div class="layui-input-inline">
  55. <select name="order_status" lay-filter="order_status">
  56. <option value="">全部</option>
  57. {foreach $order_status_list as $k => $status_val}
  58. <option value="{$status_val.status}">{$status_val.name}</option>
  59. {/foreach}
  60. </select>
  61. </div>
  62. </div>
  63. <div class="layui-inline">
  64. <label class="layui-form-label">营销类型:</label>
  65. <div class="layui-input-inline">
  66. <select name="promotion_type" lay-filter="promotion_type">
  67. <option value="">全部</option>
  68. {foreach $promotion_type as $promotion_type_k => $promotion_type_val}
  69. <option value="{$promotion_type_val.type}">{$promotion_type_val.name}</option>
  70. {/foreach}
  71. </select>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="layui-form-item">
  76. <div class="layui-inline">
  77. <label class="layui-form-label">付款方式:</label>
  78. <div class="layui-input-inline">
  79. <select name="pay_type" >
  80. <option value="">全部</option>
  81. {foreach pay_type_list as $pay_type_k => $pay_type_v}
  82. <option value="{$pay_type_k}">{$pay_type_v}</option>
  83. {/foreach}
  84. </select>
  85. </div>
  86. </div>
  87. <div class="layui-inline">
  88. <label class="layui-form-label">订单来源:</label>
  89. <div class="layui-input-inline">
  90. <select name="order_from">
  91. <option value="">全部</option>
  92. {volist name="order_from_list" id="order_from" key="order_from_key"}
  93. <option value="{$order_from_key}">{$order_from['name']}</option>
  94. {/volist}
  95. </select>
  96. </div>
  97. </div>
  98. </div>
  99. <div class="ns-form-row">
  100. <button class="layui-btn ns-bg-color" lay-submit id="btn_search"lay-filter="btn_search">筛选</button>
  101. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  102. <button class="layui-btn layui-btn-primary" lay-submit lay-filter="batch_export" >批量导出</button>
  103. <!--<button class="layui-btn layui-btn-primary">查看已生成报表</button>-->
  104. </div>
  105. <input type="hidden" name="status" val=""/>
  106. <input type="hidden" name="page" val=""/>
  107. </form>
  108. </div>
  109. </div>
  110. <div class="layui-tab ns-table-tab" lay-filter="order_tab">
  111. <ul class="layui-tab-title">
  112. <li class="layui-this" lay-id="">全部订单</li>
  113. </ul>
  114. <div class="layui-tab-content">
  115. <!-- 列表 -->
  116. <div id="order_list"></div>
  117. </div>
  118. </div>
  119. <div id="order_page"></div>
  120. <div id="order_operation"></div>
  121. {/block}
  122. {block name="script"}
  123. <script src="ADMIN_JS/order_list.js"></script>
  124. <script>
  125. var laypage,element, form, hash_url;
  126. var is_refresh = false;
  127. var order_type_status_json = {:json_encode($order_type_list)};
  128. /**
  129. *通过hash获取页数
  130. */
  131. function getHashPage(){
  132. var page = 1;
  133. var hash = location.hash;
  134. var hash_arr = hash.split("&");
  135. $.each(hash_arr,function(index, itemobj){
  136. var item_arr = itemobj.split("=");
  137. if(item_arr.length == 2){
  138. if(item_arr[0].indexOf("page") != "-1"){
  139. page = item_arr[1];
  140. }
  141. }
  142. })
  143. return page;
  144. }
  145. //从hash中获取数据
  146. function getHashData(){
  147. var hash = ns.urlReplace(location.hash);
  148. var data= [];
  149. var hash_arr = hash.split("&");
  150. var form_json = {
  151. "end_time" : "",
  152. "order_from" : "",
  153. "order_label" : $("select[name=order_label]").val(),
  154. "order_name" : "",
  155. "order_status" : "",
  156. "promotion_type" : "",
  157. "pay_type" : "",
  158. "search" : "",
  159. "start_time" : "",
  160. "order_type" : 'all',
  161. "page" : ""
  162. };
  163. if(hash_arr.length > 0){
  164. // page = hash_arr[0].replace('#!page=', '');
  165. $.each(hash_arr,function(index, itemobj){
  166. var item_arr = itemobj.split("=");
  167. if(item_arr.length == 2){
  168. $.each(form_json,function(key, form_val){
  169. if(item_arr[0].indexOf(key) != "-1"){
  170. form_json[key] = item_arr[1];
  171. }
  172. })
  173. }
  174. })
  175. }
  176. resetOrderStatus(form_json.order_type, 2);
  177. form.val("order_list", form_json);
  178. setOrderStatusTab(form_json.order_status);
  179. return form_json;
  180. }
  181. /**
  182. * 获取哈希值order_type
  183. */
  184. function getHashOrderType(){
  185. var hash = ns.urlReplace(location.hash);
  186. var hash_arr = hash.split("&");
  187. var order_type = "all";
  188. if(hash_arr.length > 0){
  189. // page = hash_arr[0].replace('#!page=', '');
  190. $.each(hash_arr,function(index, itemobj){
  191. var item_arr = itemobj.split("=");
  192. if(item_arr.length == 2){
  193. if(item_arr[0].indexOf("order_type") != "-1") {
  194. order_type = item_arr[1];
  195. }
  196. }
  197. })
  198. }
  199. return order_type;
  200. }
  201. layui.use(['laypage','laydate','form', 'element'], function(){
  202. form = layui.form;
  203. laypage = layui.laypage;
  204. element = layui.element;
  205. var laydate = layui.laydate;
  206. form.render();
  207. //渲染时间
  208. laydate.render({
  209. elem: '#start_time'
  210. ,type: 'datetime'
  211. ,change: function(value, date, endDate){
  212. $(".date-picker-btn").removeClass("selected");
  213. }
  214. });
  215. laydate.render({
  216. elem: '#end_time'
  217. ,type: 'datetime'
  218. ,change: function(value, date, endDate){
  219. $(".date-picker-btn").removeClass("selected");
  220. }
  221. });
  222. //监听筛选事件
  223. form.on('submit(btn_search)', function(data){
  224. is_refresh = true;
  225. data.field.page = 1;
  226. resetOrderStatus(data.field.order_type, 2);
  227. setHashOrderList(data.field);
  228. setOrderStatusTab(data.field.order_status);
  229. return false;
  230. });
  231. //批量导出
  232. form.on('submit(batch_export)', function(data){
  233. data.field.order_type = 1;
  234. location.href = ns.url("admin/order/exportOrderGoods",data.field);
  235. return false;
  236. });
  237. //订单类型
  238. form.on('select(order_type)', function(data){
  239. resetOrderStatus(data.value, 1);
  240. return false;
  241. });
  242. //监听Tab切换,以改变地址hash值
  243. element.on('tab(order_tab)', function(){
  244. var status = this.getAttribute('lay-id');
  245. form.val("order_list", {"order_status":status});
  246. var hash_data = getHashList();
  247. hash_data.order_status = status;
  248. hash_data.page = 1;
  249. setHashOrderList(hash_data);
  250. });
  251. getHashData();
  252. getOrderList();//筛选
  253. });
  254. function setOrderStatusTab(order_status){
  255. $(".layui-tab-title li").removeClass("layui-this");
  256. $(".layui-tab-title li").each(function(){
  257. var status = $(this).attr("lay-id");
  258. if(status == order_status){
  259. $(this).addClass("layui-this")
  260. }
  261. });
  262. }
  263. //重置状态tab 选项卡
  264. function resetOrderStatus(order_type, is_tab){
  265. var hash_order_type = getHashOrderType();
  266. if(hash_order_type != order_type || is_refresh == false){
  267. if(is_tab != 1 || is_refresh == false) {
  268. $(".layui-tab-title li").not(':first').remove();
  269. $(".layui-tab-title li").find(":first").addClass("layui-this");
  270. }
  271. if(is_tab != 2 || is_refresh == false){
  272. $("select[name=order_status] option").not(':first').remove();
  273. }
  274. var status_item = order_type_status_json[order_type]["status"];
  275. $.each(status_item,function(index, itemobj){
  276. if(is_tab != 1 || is_refresh == false) {
  277. $(".layui-tab-title").append('<li lay-id="' + index + '">' + itemobj + '</li>');
  278. }
  279. if(is_tab != 2 || is_refresh == false) {
  280. $("select[name=order_status]").append('<option value="' + index + '">' + itemobj + '</option>');
  281. }
  282. })
  283. form.render('select');
  284. }
  285. }
  286. //哈希值 订单数据
  287. function setHashOrderList(data){
  288. var hash = "";
  289. $.each(data,function(index, itemobj){
  290. if(itemobj != "" && itemobj != "all"){
  291. if(hash == ""){
  292. hash += "#!"+index +"="+itemobj;
  293. }else{
  294. hash += "&"+index +"="+itemobj;
  295. }
  296. }
  297. })
  298. // window.location.href = hash;
  299. hash_url = hash;
  300. location.hash = hash;
  301. getOrderList();
  302. }
  303. function getHashList(){
  304. var hash = ns.urlReplace(location.hash);
  305. var data= [];
  306. var hash_arr = hash.split("&");
  307. var form_json = {
  308. "end_time" : "",
  309. "order_from" : "",
  310. "order_label" : $("select[name=order_label]").val(),
  311. "order_name" : "",
  312. "order_status" : "",
  313. "promotion_type" : "",
  314. "pay_type" : "",
  315. "search" : "",
  316. "start_time" : "",
  317. "order_type" : 'all',
  318. "page" : ""
  319. };
  320. if(hash_arr.length > 0){
  321. // page = hash_arr[0].replace('#!page=', '');
  322. $.each(hash_arr,function(index, itemobj){
  323. var item_arr = itemobj.split("=");
  324. if(item_arr.length == 2){
  325. $.each(form_json,function(key, form_val){
  326. if(item_arr[0].indexOf(key) != "-1"){
  327. form_json[key] = item_arr[1];
  328. }
  329. })
  330. }
  331. })
  332. }
  333. return form_json;
  334. }
  335. var order = new Order();
  336. function getOrderList(){
  337. var url = ns.url("admin/order/lists", ns.urlReplace(location.hash.replace('#!', '')));
  338. $.ajax({
  339. type : 'get',
  340. dataType: 'json',
  341. url :url,
  342. success : function(res){
  343. if(res.code == 0){
  344. order.setData(res.data);
  345. $("#order_list").html(order.fetch());
  346. //执行一个laypage实例
  347. laypage.render({
  348. elem: 'order_page',
  349. count: res.data.count,
  350. curr: getHashPage(),
  351. layout: ['count', 'prev', 'page', 'next'],
  352. // hash: 'page',
  353. jump: function(obj, first){
  354. //首次不执行
  355. if(!first){
  356. var hash_data = getHashData();
  357. hash_data.page = obj.curr;
  358. setHashOrderList(hash_data);
  359. // $("#btn_search").click();//筛选
  360. }
  361. }
  362. });
  363. }else{
  364. layer.msg(res.message);
  365. }
  366. }
  367. });
  368. }
  369. /**
  370. * 七天时间
  371. */
  372. function datePick(date_num,event_obj){
  373. $(".date-picker-btn").removeClass("selected");
  374. $(event_obj).addClass('selected');
  375. // alert(new Date().format("yyyy-MM-dd hh:mm"));
  376. var now_date = new Date();
  377. Date.prototype.Format = function (fmt,date_num) { //author: meizz
  378. this.setDate(this.getDate()-date_num);
  379. var o = {
  380. "M+": this.getMonth() + 1, //月份
  381. "d+": this.getDate(), //日
  382. "H+": this.getHours(), //小时
  383. "m+": this.getMinutes(), //分
  384. "s+": this.getSeconds(), //秒
  385. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  386. "S": this.getMilliseconds() //毫秒
  387. };
  388. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  389. for (var k in o)
  390. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  391. return fmt;
  392. }
  393. // var now_time = new Date().Format("yyyy-MM-dd HH:mm:ss",0);//当前日期
  394. var now_time = new Date().Format("yyyy-MM-dd 23:59:59",0);//当前日期
  395. var before_time = new Date().Format("yyyy-MM-dd 00:00:00",date_num-1);//前几天日期
  396. $("input[name=start_time]").val(before_time,0);
  397. $("input[name=end_time]").val(now_time,date_num-1);
  398. }
  399. </script>
  400. {/block}