prescription_records.js 18 KB

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