admin.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. var scroller1 = null,roleLevel = null,docInfo = null, area=null;
  2. var userRole;
  3. var $docPhoto = $("#doc_photo"),//头像
  4. $name = $("#doc_name"),//名称
  5. $docType = $("#doc_type"),//类别
  6. $jobName = $("#doc_jobName"),
  7. $hospitalName = $("#hospitalName");//所属医院
  8. mui.plusReady(function() {
  9. plus.nativeUI.showWaiting();
  10. window.addEventListener("refreshData", function() {
  11. getJieZhiTime()
  12. });
  13. initQiehuanDom();//切换角色事件
  14. initData();
  15. getJieZhiTime();
  16. getAlalysisData();
  17. bindEvents();
  18. initScroll();
  19. });
  20. /*
  21. * 初始化处理各个数据
  22. */
  23. function initData(){
  24. userRole = JSON.parse(plus.storage.getItem("userRole"));
  25. area = userRole[0].code;
  26. roleLevel = area == '361100' ? 4 : area.length==6 ? 3 : 2;
  27. //保存默认的角色权限信息
  28. var selectedRole = JSON.stringify(userRole[0]);
  29. plus.storage.setItem("selectedRole", selectedRole);
  30. var docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  31. var deptName =docInfo.deptName;
  32. var jobName=docInfo.jobName;
  33. var docName = docInfo.name;//姓名
  34. var docSex = docInfo.sex;//性别
  35. var docPhoto = docInfo.photo; //图像
  36. var docHospitalName = docInfo.hospitalName; //医院
  37. //图片加载失败时使用默认图片
  38. document.getElementById("doc_photo").onerror = function(){
  39. this.src = setDocPhoto(docSex, 10);
  40. }
  41. $docPhoto.attr("src", getImgUrl(docPhoto));
  42. $name.html(docName)//名称
  43. if(jobName){
  44. $docType.html("("+jobName+")") //类别
  45. }
  46. $hospitalName.html(deptName);//userRole[0].name显示该医生拥有的管理员权限
  47. if(userRole.length > 1){
  48. $("#selectRole").show();
  49. var html = template("role_tmp", {list: userRole});
  50. $("#roleList").append(html);
  51. }
  52. $('#doc_type').css('max-width', ($('#doc-info').width() - $name.width() - 35) + 'px');
  53. if(!isMultiRole()){
  54. checkIdcard(docInfo.idcard);
  55. }
  56. $('#wrapper').height($(window).height());
  57. }
  58. /*
  59. * 加载数据截止时间
  60. */
  61. function getJieZhiTime(){
  62. sendPost("/statistics/time",null,function(res){
  63. },function(res){
  64. if(res.status=="200"){
  65. var date = (res.data && res.data.substring(11,16)) || "";
  66. $(".jiezhi-time").html(date);
  67. }
  68. });
  69. }
  70. /*
  71. * 获取统计数据
  72. */
  73. function getAlalysisData(){//level:等级(1 团队,2 科室,3 机构,4 区)此处传3
  74. sendGet("/statistics/getIndexTotal",{endDate:getDateFromNow(),area:srOrgCode,level:3},function(res){
  75. },function(res){
  76. if(res.status==200){
  77. var data = res.data;
  78. $("#zcjmAmount").html(data.reginNum);
  79. $("#jmzxlAmount").html(data.consultNum);
  80. $("#jmgzAmount").html(data.concernNum);
  81. $("#jkjyAmount").html(data.educateNum);
  82. $("#jkzdAmount").html(data.guideNum);
  83. }
  84. plus.nativeUI.closeWaiting();
  85. });
  86. }
  87. function initScroll() {
  88. //阻尼系数
  89. var deceleration = mui.os.ios?0.003:0.0009;
  90. mui('#wrapper').scroll({
  91. bounce: false,
  92. indicators: true, //是否显示滚动条
  93. deceleration:deceleration
  94. });
  95. mui("#wrapper .mui-scroll").pullToRefresh({
  96. down: {
  97. callback: function() {
  98. var self = this;
  99. setTimeout(function() {
  100. getJieZhiTime();
  101. self.endPullDownToRefresh();
  102. }, 1000);
  103. }
  104. }
  105. });
  106. //角色切换模块的下拉环境scroll初始
  107. mui("#roleWrapper").scroll({
  108. bounce: false,
  109. indicators: true,
  110. deceleration: deceleration
  111. })
  112. mui("#roleWrapper").pullRefresh();
  113. }
  114. function bindEvents(){
  115. mui('#wrapper').on('tap','.wrap', function(){
  116. var href=$(this).attr("data-href");
  117. var hrefId = $(this).attr("data-href-id");
  118. mui.openWindow({
  119. url:href,
  120. id:hrefId,
  121. extras:{
  122. type:$(this).attr("data-id")
  123. },
  124. })
  125. });
  126. mui('#wrapper').on('tap','.div-aitem', function(){
  127. var href=$(this).attr("data-href");
  128. var hrefId = $(this).attr("data-href-id");
  129. var activeId = $(this).attr("data-id");
  130. if(activeId=="5" && roleLevel==2){//两率分析
  131. href = "../../manager/html/lianglvfenxi-sheguan.html";
  132. hrefId = "lianglvfenxi-sheguan.html";
  133. }
  134. if(plus.os.name == "Android" && plus.device.vendor == "Meizu") {
  135. var wv = plus.webview.create( href, hrefId, {hardwareAccelerated:false}, {
  136. type:$(this).attr("data-id")
  137. } );
  138. wv.show("slide-in-right",250);
  139. } else {
  140. mui.openWindow({
  141. url:href,
  142. id:hrefId,
  143. extras:{
  144. type:$(this).attr("data-id")
  145. },
  146. })
  147. }
  148. });
  149. mui('#wrapper').on('tap','.fwfx-ul li',function(){
  150. var href=$(this).attr("data-href");
  151. var hrefId = $(this).attr("data-href-id");
  152. if(href){
  153. mui.openWindow({
  154. url:href,
  155. id:hrefId,
  156. extras:{
  157. type:$(this).attr("data-id")
  158. },
  159. })
  160. }
  161. });
  162. $("#roleList").on('tap', 'li', function(){
  163. var $this = $(this),
  164. index = $this.data('index'),
  165. name = $this.data('name'),
  166. code = $this.data('code');
  167. $("#hospitalName").text(name);
  168. area = code + '';
  169. roleLevel = area == '350200' ? 4 : area.length==6 ? 3 : 2;
  170. if(area.indexOf(350205)==0||area.indexOf(350200)==0) {
  171. $active.find('div').removeClass('new-hide')
  172. $active.find('p').removeClass('new-hide')
  173. }else{
  174. $active.find('div').addClass('new-hide')
  175. $active.find('p').addClass('new-hide')
  176. }
  177. getJieZhiTime();
  178. mui('#middlePopover').popover('hide');
  179. //保存默认的角色权限信息
  180. var selectedRole = JSON.stringify(userRole[index]);
  181. plus.storage.setItem("selectedRole", selectedRole);
  182. })
  183. $(".close-btn").on('tap', function(){
  184. mui('#middlePopover').popover('hide');
  185. });
  186. //医生体验
  187. $(".ysty").on("tap",function(){
  188. ysty();
  189. })
  190. $('#li-mingyi1').on("tap",function() {
  191. openWebview('../../mygl/html/mingyiguanli.html')
  192. });
  193. $('#unbind_device').on("tap",function(){
  194. openWebview('jiebangshebei.html');
  195. });
  196. $('#jianjiao-tuisong').on("tap",function(){
  197. <!--openWebview('jianjiaotuisong.html');-->
  198. openWebview("../../jkjy/html/article-store.html", {isAdmin: true});
  199. });
  200. $('#device-manage').on("tap",function(){
  201. openWebview("../../device/html/device-data.html");
  202. });
  203. $(".wjdc").on('tap', function(){
  204. //根据角色权限显示对应的列表信息
  205. // roleLevel: 级别(4:市 3:区 2:社区医院 1:团队)
  206. var userRole = JSON.parse(plus.storage.getItem("userRole"))[0];
  207. if(roleLevel == 4){
  208. openWebview('../../survey/html/survey_list.html');
  209. } else {
  210. mui.confirm("对不起,您无操作权限","提示",
  211. ["我知道了"], function(e){
  212. if(e.index==0) return false;
  213. });
  214. }
  215. });
  216. }
  217. /**
  218. * 数字3位加一个逗号
  219. * @param {Object} n
  220. */
  221. function format_number(n){
  222. var b=parseInt(n).toString();
  223. var len=b.length;
  224. if(len<=3){return b;}
  225. var r=len%3;
  226. return r>0?b.slice(0,r)+","+b.slice(r,len).match(/\d{3}/g).join(","):b.slice(r,len).match(/\d{3}/g).join(",");
  227. }
  228. /**
  229. * 获取多少天前的日期
  230. */
  231. function getDateBefore(days) {
  232. var now = new Date();
  233. var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
  234. var year = date.getFullYear();
  235. var month = date.getMonth() + 1;
  236. var day = date.getDate();
  237. var hour = date.getHours();
  238. var minute = date.getMinutes();
  239. var second = date.getSeconds();
  240. return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
  241. }
  242. function ysty(){
  243. //观察者模式下,不可以再次观察者查看
  244. var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
  245. if(userAgent.observer){
  246. mui.confirm("对不起,您无操作权限","提示",
  247. ["我知道了"], function(e){
  248. if(e.index==0) return false;
  249. });
  250. return;
  251. }
  252. var userRole = JSON.parse(plus.storage.getItem("selectedRole"));
  253. openWebview('../../observer/html/doctors.html', {code: userRole.code});
  254. }
  255. //获取当前时间
  256. function getDateFromNow(days) {
  257. if(!days) {
  258. return new Date().format("yyyy-MM-dd")
  259. }
  260. var now = new Date().getTime()
  261. var diff = 24 * 3600 * 1000 * days
  262. return new Date(now + diff).format("yyyy-MM-dd")
  263. }