prescription_records.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. var d = dialog({
  2. contentType: 'load',
  3. skin: 'bk-popup'
  4. });
  5. var pagetype = 38;
  6. var pagesize = [15,15,15],
  7. page = [0,1,1], //3个tab对应的分页的页数
  8. loaded = [true, false, false], //3个tab对应的页面是否加载过,第一个tab默认加载过
  9. lastYear = ['2016', '2016', '2016'], // 记录数据最后的年份信息
  10. isOverdue = false; //是否过期
  11. var userAgent = window.localStorage.getItem(agentName);
  12. var userInfo;
  13. $(function(){
  14. checkUserAgent();
  15. initScroller();
  16. });
  17. function initScroller(){
  18. //阻尼系数
  19. var deceleration = mui.os.ios?0.003:0.0009;
  20. mui('.mui-scroll-wrapper').scroll({
  21. bounce: false,
  22. indicators: true, //是否显示滚动条
  23. deceleration:deceleration
  24. });
  25. mui.ready(function() {
  26. //循环初始化所有下拉刷新,上拉加载。
  27. $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
  28. if(index == 0){
  29. mui(pullRefreshEl).pullRefresh({
  30. down: {
  31. callback: function() {
  32. var self = this;
  33. setTimeout(function() {
  34. d.showModal();
  35. var isrenewal = $("#checkbox").prop("checked");
  36. getPrescriptionList(index, true, isrenewal? 1 : 2);
  37. // getPrescriptionList(index, true);
  38. self.endPulldownToRefresh();
  39. }, 1000);
  40. }
  41. },
  42. up: {
  43. callback: function() {
  44. var self = this;
  45. setTimeout(function(){
  46. d.showModal();
  47. getPrescriptionList(index);
  48. self.endPullupToRefresh();
  49. }, 1000);
  50. }
  51. }
  52. });
  53. }else{
  54. mui(pullRefreshEl).pullRefresh({
  55. down: {
  56. callback: function() {
  57. var self = this;
  58. setTimeout(function() {
  59. getXFList(index, true);
  60. self.endPulldownToRefresh();
  61. }, 1000);
  62. }
  63. },
  64. up: {
  65. callback: function() {
  66. var self = this;
  67. setTimeout(function() {
  68. getXFList(index);
  69. self.endPullupToRefresh();
  70. }, 1000);
  71. }
  72. }
  73. });
  74. }
  75. });
  76. });
  77. }
  78. function queryInit(){
  79. userInfo = JSON.parse(userAgent);
  80. if(!canPrescription){
  81. $('#memberContainer').hide();
  82. $("#slider").hide();
  83. $("#building").show();
  84. }else{
  85. initFamilyData();
  86. checkPatientInfo();
  87. bindEvents();
  88. templatehelper();
  89. }
  90. wxGetSign();
  91. }
  92. //初始化家庭成员
  93. function initFamilyData(){
  94. appendFamilyMember($('#memberContainer'),function(){
  95. loaded = [false, false, false];
  96. page = [0,1,1];
  97. checkPatientInfo();
  98. //切换家人时,将‘只查看可续方记录’的checkbox设置为未选中
  99. // $("#checkbox").prop("checked", false);
  100. },function(){
  101. //判断有授权家人,修改样式
  102. $("#slider").css({
  103. 'top': '90px',
  104. 'height': 'calc(100% - 90px)'
  105. });
  106. });
  107. }
  108. //判断患者是否是慢病患者
  109. function checkPatientInfo(){
  110. d.showModal();
  111. var url = 'patient/baseinfo',
  112. params = {};
  113. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  114. if(res.status == 200){
  115. var isChronicDisease = res.data.prescription; //慢病病人标记
  116. if(isChronicDisease){
  117. //显示3个tab
  118. mui('#slider').slider().gotoItem(0);
  119. $(".mui-slider-indicator .c-33").eq(1).show();
  120. $(".mui-slider-indicator .c-33").eq(2).show();
  121. mui('#slider').slider().setStopped(false);
  122. //删除混存中存储的不可续方的标识
  123. var canPrescription = window.localStorage.getItem("cannotPrescription");
  124. if(canPrescription){
  125. window.localStorage.removeItem("cannotPrescription");
  126. }
  127. }else{
  128. //两种情况:1-非慢病病人, 2-过期的慢病病人
  129. checkOverduePrescription();
  130. }
  131. getPrescriptionList(0, true);
  132. }else{
  133. queryFailed(res);
  134. }
  135. });
  136. }
  137. //判断是否有慢病续方记录
  138. function checkOverduePrescription(){
  139. var url = "/patient/prescriptionInfo/checkPatientWithPrescription";
  140. sendPost(url, {}, 'JSON', 'get', queryFailed, function(res){
  141. if(res.status == 200){
  142. if(res.data){
  143. isOverdue = true;
  144. mui('#slider').slider().gotoItem(0);
  145. $(".mui-slider-indicator .c-33").eq(1).show();
  146. $(".mui-slider-indicator .c-33").eq(2).show();
  147. mui('#slider').slider().setStopped(false);
  148. //设置缓存存储可以查看处方,但是不能新增续方的标识
  149. window.localStorage.setItem("cannotPrescription", 1);
  150. }else{
  151. //显示1个tab
  152. mui('#slider').slider().gotoItem(0);
  153. $(".mui-slider-indicator .c-33").eq(1).hide();
  154. $(".mui-slider-indicator .c-33").eq(2).hide();
  155. mui('#slider').slider().setStopped(true);
  156. }
  157. }else{
  158. queryFailed(res);
  159. }
  160. })
  161. }
  162. /**
  163. * 获得处方记录
  164. * @param {number} index 对应tab的index
  165. * @param {boolean} isInit 是否是初始加载(用于初始加载和下拉刷新)
  166. * @param {boolean} isRenewal 是否只获取可续方的列表 1-是,2-无过滤
  167. */
  168. function getPrescriptionList(index, isInit, isRenewal){
  169. var tmpIndex = parseInt(index) + 1;
  170. if(isInit){
  171. page[index] = 0;
  172. if(tmpIndex == 1){
  173. //处方列表的获取可续方处方数据的特殊处理
  174. $("#recordList0").show();
  175. $("#item1 .straight-line").show();
  176. }
  177. mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().scrollTo(0, 0, 1000);
  178. }
  179. var url = "/patient/prescriptionInfo/getRecipeMasterList",
  180. params = {
  181. type: 1, //type: 1-查询处方,2-我的续方, 3-续方记录
  182. isRenewal: isRenewal ? isRenewal : 2, //1: 可续方, 2:无过滤
  183. startDate: '',
  184. endDate: '',
  185. // recipeNo: page[index],
  186. page: page[index],
  187. size: pagesize[index]
  188. };
  189. sendPost(url, params, 'json', 'GET', queryFailed, function(res){
  190. d.close();
  191. if(res.status == 200){
  192. loaded[index] = true;
  193. //暂时默认数据是按年份group了的 [{year: 2017, list:[]}]
  194. if(res.data.list.length > 0){
  195. $("#next").removeClass("disabled");
  196. var year = parseInt((new Date()).getFullYear());
  197. var obj = _.groupBy(res.data.list, function(o){
  198. for(y = year; y >= 2016; y--){
  199. if(o.createTime.substr(0,4) == y){
  200. lastYear[index] = y;
  201. return y;
  202. }
  203. }
  204. });
  205. for(y in obj){
  206. var list = obj[y];
  207. for(var i=0; i<list.length; i++){
  208. var item = list[i];
  209. var canXF = getXFStatus(item.prescriptionDt, item.createTime);
  210. var xfStatus = 0; //自定义按钮的状态, 1:申请续方,2:续方申请中
  211. if(canXF){
  212. item.canXFName = '续方';
  213. //reviewedState : 0 为审核中 1.已经处理完成/未申请
  214. if(item.reviewedState == 0){ //待支付之前的状态,前端实现‘续方审核中’
  215. //如果患者取消续方,则仍旧可以申请续方
  216. xfStatus = 2;
  217. }else{
  218. xfStatus = 1;
  219. }
  220. }
  221. item.canXF = canXF;
  222. item.xfStatus = xfStatus;
  223. // page[index] = item.code;
  224. }
  225. }
  226. var temp = 'record_tmp',
  227. isNewYear = 1;
  228. if((y == lastYear[index]) && !isInit){
  229. isNewYear = 0;
  230. }
  231. var html = template(temp, {list: obj, isNewYear: isNewYear});
  232. if(isInit){
  233. $("#item"+tmpIndex+" .mui-scroll-wrapper").show();
  234. $("#item"+tmpIndex+" .div-no-info").hide();
  235. $("#recordList"+index).empty().append(html);
  236. }else{
  237. $("#recordList"+index).append(html);
  238. }
  239. if(res.data.list.length < pagesize){
  240. mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  241. }else{
  242. page[index] ++;
  243. }
  244. }else{
  245. if(isInit){
  246. //无数据
  247. if(isRenewal == 1){
  248. //获取可续方的处方列表
  249. $("#recordList0").empty().hide();
  250. $("#item1 .straight-line").hide();
  251. $("#item1 .div-no-info").show();
  252. }else{
  253. $("#next").hide();
  254. $("#item1 .mui-scroll-wrapper").hide();
  255. $("#item1 .div-no-info").show();
  256. }
  257. }else{
  258. $("#next").addClass("disabled");
  259. mui("#item1 .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  260. }
  261. }
  262. }else{
  263. queryFailed(res);
  264. }
  265. });
  266. }
  267. //获取续方记录
  268. function getXFList(index, isInit){
  269. var tmpIndex = parseInt(index) + 1;
  270. if(isInit){
  271. page[index] = 1;
  272. }
  273. var url = "/patient/prescriptionInfo/getPrescriptionInfos",
  274. params = {
  275. type: parseInt(index) + 1, //type: 1-查询处方,2-我的续方, 3-续方记录
  276. isRenewal: 2,
  277. startDate: '',
  278. endDate: '',
  279. page: page[index],
  280. size: pagesize[index]
  281. };
  282. sendPost(url, params, 'json', 'GET', queryFailed, function(res){
  283. d.close();
  284. if(res.status == 200){
  285. loaded[index] = true;
  286. //暂时默认数据是按年份group了的 [{year: 2017, list:[]}]
  287. if(res.data.length > 0){
  288. var year = parseInt((new Date()).getFullYear());
  289. var obj = _.groupBy(res.data, function(o){
  290. for(y = year; y >= 2016; y--){
  291. if(o.createTime.substr(0,4) == y){
  292. return -y;
  293. }
  294. }
  295. });
  296. var temp = 'record'+index+'_tmp';
  297. var html = template(temp, {list: obj});
  298. if(isInit){
  299. $("#item"+tmpIndex+" .mui-scroll-wrapper").show();
  300. $("#item"+tmpIndex+" .div-no-info").hide();
  301. $("#recordList"+index).empty().append(html);
  302. }else{
  303. $("#recordList"+index).append(html);
  304. }
  305. if(res.data.length < pagesize){
  306. mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  307. }else{
  308. page[index] ++;
  309. }
  310. }else{
  311. if(isInit){
  312. //无数据
  313. $("#item"+tmpIndex+" .mui-scroll-wrapper").hide();
  314. $("#item"+tmpIndex+" .div-no-info").show();
  315. }else{
  316. mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  317. }
  318. }
  319. }else{
  320. queryFailed(res);
  321. }
  322. });
  323. }
  324. function getXFStatus(arr, date){
  325. var isXFDesease = true,
  326. statusName = '',
  327. canXF = false;
  328. if(arr){
  329. for(i=0; i<arr.length; i++){
  330. var item = arr[i];
  331. //HP0093 - 高血压 , HP0047 - 糖尿病
  332. if((item.healthProblem != 'HP0093') && (item.healthProblem != 'HP0047')){
  333. isXFDesease = false;
  334. break;
  335. }
  336. }
  337. if(isXFDesease){
  338. //判断时间是否是在6个月内的
  339. // var d = new Date(date),
  340. // now = new Date();
  341. // now.setMonth(now.getMonth() - 6);
  342. // if(d > now){ //6个月内的时间
  343. statusName = '续方';
  344. canXF = true;
  345. // }
  346. }
  347. }
  348. return canXF;
  349. }
  350. function queryFailed(res){
  351. d.close();
  352. if(res && res.msg) {
  353. dialog({
  354. contentType: 'tipsbox',
  355. skin: 'bk-popup',
  356. content: res.msg
  357. }).show();
  358. } else {
  359. dialog({
  360. contentType: 'tipsbox',
  361. skin: 'bk-popup',
  362. content: '加载失败'
  363. }).show();
  364. }
  365. }
  366. function bindEvents(){
  367. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  368. var index = event.detail.slideNumber;
  369. console.log(index);
  370. if(!loaded[index]){ //tab未加载过,则加载数据
  371. d.showModal();
  372. if(index == 0){
  373. getPrescriptionList(index, true);
  374. }else{
  375. getXFList(index, true);
  376. }
  377. }
  378. });
  379. //只查看可续方记录按钮
  380. $("#checkbox").on('change', function(){
  381. d.showModal();
  382. if(this.checked){
  383. //获取可续方的记录
  384. getPrescriptionList(0, true, 1);
  385. }else{
  386. //获取全部记录
  387. getPrescriptionList(0, true);
  388. }
  389. });
  390. //'处方记录'tab内item的点击事件
  391. $("#recordList0").on('tap', '.prescription-item', function(){
  392. var code = $(this).attr('data-code');
  393. //跳转去处方详情页
  394. window.location.href = 'prescription_detail.html?code='+code;
  395. }).on('tap', '.btn', function(e){
  396. e.stopPropagation(); //防止事件冒泡
  397. var status = $(this).attr("data-status"),
  398. code = $(this).closest('.prescription-item').attr('data-code');
  399. //两种状态:1.申请续方 2.续方审核中
  400. if(status == 1){
  401. //跳转去’新增续方咨询‘页面
  402. if(isOverdue){
  403. dialog({
  404. contentType: 'tipsbox',
  405. skin: 'bk-popup',
  406. content: '您好,你的签约已过期,不能申请新的续方。'
  407. }).show();
  408. }else{
  409. var patient = $(this).closest('.prescription-item').attr('data-patient'),
  410. name = $(this).closest('.prescription-item').attr('data-pname');
  411. window.location.href = "../../yszx/html/add-prescription-consult.html?patient="+patient+'&name='+name+'&prescriptionCode='+code;
  412. }
  413. }else{
  414. //跳转去’续方记录‘页面
  415. var prescriptionCode = $(this).attr("data-preCode");
  416. window.location.href = "re-prescription_info.html?code="+prescriptionCode+'&toUser='+userInfo.uid;
  417. }
  418. });
  419. //'我的续方'tab内item对应的点击事件
  420. $("#recordList1").on('tap', '.prescription-item', function(){
  421. var code = $(this).attr('data-code');
  422. //跳转去续方详情页面,只有审核通过的页面才有我的续方页面
  423. window.location.href = "re-prescription_detail.html?code="+code;
  424. }).on('tap', '.btn', function(e){
  425. e.stopPropagation();
  426. var code = $(this).closest('.prescription-item').attr("data-code");
  427. //订单跟踪按钮,跳转去订单跟踪页面
  428. window.location.href = "order_tracking.html?code="+code+'&toUser='+userInfo.uid;
  429. });
  430. //'续方管理'tab内item对应的点击事件
  431. $("#recordList2").on('tap', ' .prescription-item', function(){
  432. var code = $(this).attr('data-code');
  433. //跳转去续方记录页面
  434. window.location.href = "re-prescription_info.html?code="+code+'&toUser='+userInfo.uid;
  435. });
  436. //获取下一条处方数据
  437. $("#next").on('tap', function(){
  438. if($(this).hasClass("disabled")){
  439. return false;
  440. }
  441. d.showModal();
  442. getPrescriptionList(0);
  443. })
  444. }
  445. function templatehelper(){
  446. template.helper('getDateTime', function(str){
  447. if(str && str.length > 0){
  448. //str = 2017-07-31 11:09:53.0
  449. return str.substr(0, 19);
  450. }
  451. return '';
  452. });
  453. template.helper('getAbs', function(str) {
  454. return str.substr(1, 4);
  455. });
  456. template.helper('showStatus', function(status){
  457. return getStatusInfoAndImg(status).name;
  458. });
  459. template.helper('returnStatusImg', function(status){
  460. return getStatusInfoAndImg(status).img;
  461. });
  462. template.helper('getDate', function(str){
  463. if(str && str.length > 0){
  464. return str.substr(5, 6);
  465. }
  466. });
  467. template.helper('getXF', function(arr, date){
  468. var isXFDesease = false;
  469. if(arr){
  470. for(i=0; i<arr.length; i++){
  471. var item = arr[i];
  472. if(item.name == '高血压' || item.name == '糖尿病'){
  473. isXFDesease = true;
  474. }else{
  475. isXFDesease = false;
  476. }
  477. }
  478. if(isXFDesease){
  479. //判断时间是否是在6个月内的
  480. var d = new Date(date),
  481. now = new Date();
  482. now.setMonth(now.getMonth() - 6);
  483. if(d > now){ //6个月内的时间
  484. return '续方';
  485. }
  486. }
  487. }
  488. return '';
  489. });
  490. }
  491. //获取微信信息,并配置微信api接口
  492. function wxGetSign(){
  493. var params = {};
  494. params.pageUrl = window.location.href;
  495. $.ajax(server + "weixin/getSign", {
  496. data: params,
  497. dataType: "json",
  498. type: "post",
  499. success: function(res){
  500. if (res.status == 200) {
  501. var t = res.data.timestamp;
  502. var noncestr = res.data.noncestr;
  503. var signature = res.data.signature;
  504. wx.config({
  505. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  506. appId: appId, // 必填,公众号的唯一标识
  507. timestamp: t, // 必填,生成签名的时间戳
  508. nonceStr: noncestr, // 必填,生成签名的随机串
  509. signature: signature,// 必填,签名,见附录1
  510. jsApiList: [
  511. 'closeWindow'
  512. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  513. });
  514. }
  515. }
  516. });
  517. }