From a447a4f4e85fc8aff5632de92026fe7caa03335e Mon Sep 17 00:00:00 2001
From: er <913652501@qq.com>
Date: Fri, 03 Apr 2020 09:43:48 +0800
Subject: [PATCH] 数据需求  添加 导出功能

---
 kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/dataNeed.html |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/dataNeed.html b/kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/dataNeed.html
index 253df8c..91ddc4a 100644
--- a/kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/dataNeed.html
+++ b/kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/dataNeed.html
@@ -135,13 +135,63 @@
             var key = $('#app-edit-search').val();
             var needBegintime = $('#test1').val();
             var needEndtime = $('#test2').val();
+            if (needBegintime != null && needEndtime != null) {
+                var flag=compareDate(needBegintime, needEndtime);
+                if(!flag){
+                    layer.msg('结束时间不得小于开始时间');
+                    return;
+                }
+            }
+            
             table.reload('app-table', { where: { doctorName: key,needBegintime:needBegintime, needEndtime:needEndtime} });
+        });
+        //比较日期大小
+        function compareDate(logintime, logouttime) {
+            var arys1 = new Array();
+            var arys2 = new Array();
+            if (logintime != null && logouttime != null) {
+                arys1 = logintime.split('-');
+                var logindate = new Date(arys1[0], parseInt(arys1[1] - 1), arys1[2]);
+                arys2 = logouttime.split('-');
+                var logoutdate = new Date(arys2[0], parseInt(arys2[1] - 1), arys2[2]);
+                if (logindate > logoutdate) {
+                    return false;
+                } else {
+                    return true;
+                }
+            }
+        }
+         // 导出
+         $('#app-btn-export').click(function () {
+            var url = config.base_server + 'api-opration/dataneed/export';
+            var xhr = new XMLHttpRequest();
+            xhr.open('POST', url, true);
+            xhr.responseType = "blob";
+            xhr.setRequestHeader("client_type", "DESKTOP_WEB");
+            xhr.setRequestHeader("Authorization", "Bearer " + config.getToken().access_token);
+            xhr.onload = function() {
+                if (this.status == 200) {
+                    var fileName = "user.xlsx";
+                    var blob = this.response;
+                    var a = document.createElement('a');
+                    a.innerHTML = fileName;
+                    // 指定生成的文件名
+                    a.download = fileName;
+                    a.href = URL.createObjectURL(blob);
+                    document.body.appendChild(a);
+                    var evt = document.createEvent("MouseEvents");
+                    evt.initEvent("click", false, false);
+                    a.dispatchEvent(evt);
+                    document.body.removeChild(a);
+                }
+            }
+            xhr.send();
         });
 
         // 添加按钮点击事件
-        $('#app-btn-add').click(function () {
-            showEditModel();
-        });
+        // $('#app-btn-add').click(function () {
+        //     showEditModel();
+        // });
 
         // // 显示编辑弹窗
         // var showEditModel = function (data) {

--
Gitblit v1.8.0