123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- var d = dialog({
- contentType: 'load',
- skin: 'bk-popup'
- });
- var pagetype = 38;
- var pagesize = [15,15,15],
- page = [0,1,1], //3个tab对应的分页的页数
- loaded = [true, false, false], //3个tab对应的页面是否加载过,第一个tab默认加载过
- lastYear = ['2016', '2016', '2016']; // 记录数据最后的年份信息
- var userAgent = window.localStorage.getItem(agentName);
- var userInfo;
- $(function(){
- checkUserAgent();
- initScroller();
- });
- function initScroller(){
- //阻尼系数
- var deceleration = mui.os.ios?0.003:0.0009;
- mui('.mui-scroll-wrapper').scroll({
- bounce: false,
- indicators: true, //是否显示滚动条
- deceleration:deceleration
- });
- mui.ready(function() {
- //循环初始化所有下拉刷新,上拉加载。
- $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
- if(index == 0){
- mui(pullRefreshEl).pullRefresh({
- down: {
- callback: function() {
- var self = this;
- setTimeout(function() {
- d.showModal();
- var isrenewal = $("#checkbox").prop("checked");
- getPrescriptionList(index, true, isrenewal? 1 : 2);
- // getPrescriptionList(index, true);
- self.endPulldownToRefresh();
- }, 1000);
- }
- },
- up: {
- callback: function() {
- var self = this;
- setTimeout(function(){
- d.showModal();
- getPrescriptionList(index);
- self.endPullupToRefresh();
- }, 1000);
- }
- }
- });
- }else{
- mui(pullRefreshEl).pullRefresh({
- down: {
- callback: function() {
- var self = this;
- setTimeout(function() {
- getXFList(index, true);
- self.endPulldownToRefresh();
- }, 1000);
- }
- },
- up: {
- callback: function() {
- var self = this;
- setTimeout(function() {
- getXFList(index);
- self.endPullupToRefresh();
- }, 1000);
- }
- }
- });
- }
- });
- });
- }
- function queryInit(){
- userInfo = JSON.parse(userAgent);
- if(!canPrescription){
- $('#memberContainer').hide();
- $("#slider").hide();
- $("#building").show();
- }else{
- initFamilyData();
- checkPatientInfo();
- bindEvents();
- templatehelper();
- }
- wxGetSign();
- }
- //初始化家庭成员
- function initFamilyData(){
- appendFamilyMember($('#memberContainer'),function(){
- loaded = [false, false, false];
- page = [0,1,1];
- checkPatientInfo();
- //切换家人时,将‘只查看可续方记录’的checkbox设置为未选中
- // $("#checkbox").prop("checked", false);
- },function(){
- //判断有授权家人,修改样式
- $("#slider").css({
- 'top': '90px',
- 'height': 'calc(100% - 90px)'
- });
- });
- }
- //判断患者是否是慢病患者
- function checkPatientInfo(){
- d.showModal();
- var url = 'patient/baseinfo',
- params = {};
- sendPost(url, params, 'json', 'post', queryFailed, function(res){
- if(res.status == 200){
- var isChronicDisease = res.data.prescription; //慢病病人标记
- if(isChronicDisease){
- //显示3个tab
- mui('#slider').slider().gotoItem(0);
- $(".mui-slider-indicator .c-33").eq(1).show();
- $(".mui-slider-indicator .c-33").eq(2).show();
- mui('#slider').slider().setStopped(false);
- }else{
- //显示1个tab
- mui('#slider').slider().gotoItem(0);
- $(".mui-slider-indicator .c-33").eq(1).hide();
- $(".mui-slider-indicator .c-33").eq(2).hide();
- mui('#slider').slider().setStopped(true);
- }
- getPrescriptionList(0, true);
- }else{
- queryFailed(res);
- }
- });
- }
- /**
- * 获得处方记录
- * @param {number} index 对应tab的index
- * @param {boolean} isInit 是否是初始加载(用于初始加载和下拉刷新)
- * @param {boolean} isRenewal 是否只获取可续方的列表 1-是,2-无过滤
- */
- function getPrescriptionList(index, isInit, isRenewal){
- var tmpIndex = parseInt(index) + 1;
- if(isInit){
- page[index] = 0;
- if(tmpIndex == 1){
- //处方列表的获取可续方处方数据的特殊处理
- $("#recordList0").show();
- $("#item1 .straight-line").show();
- }
- mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().scrollTo(0, 0, 1000);
- }
- var url = "/patient/prescriptionInfo/getRecipeMasterList",
- params = {
- type: 1, //type: 1-查询处方,2-我的续方, 3-续方记录
- isRenewal: isRenewal ? isRenewal : 2, //1: 可续方, 2:无过滤
- startDate: '',
- endDate: '',
- // recipeNo: page[index],
- page: page[index],
- size: pagesize[index]
- };
- sendPost(url, params, 'json', 'GET', queryFailed, function(res){
- d.close();
- if(res.status == 200){
- loaded[index] = true;
- //暂时默认数据是按年份group了的 [{year: 2017, list:[]}]
- if(res.data.list.length > 0){
- $("#next").removeClass("disabled");
- var year = parseInt((new Date()).getFullYear());
- var obj = _.groupBy(res.data.list, function(o){
- for(y = year; y >= 2016; y--){
- if(o.createTime.substr(0,4) == y){
- lastYear[index] = y;
- return y;
- }
- }
- });
-
- for(y in obj){
- var list = obj[y];
- for(var i=0; i<list.length; i++){
- var item = list[i];
- var canXF = getXFStatus(item.prescriptionDt, item.createTime);
- var xfStatus = 0; //自定义按钮的状态, 1:申请续方,2:续方申请中
- if(canXF){
- item.canXFName = '续方';
- //reviewedState : 0 为审核中 1.已经处理完成/未申请
- if(item.reviewedState == 0){ //待支付之前的状态,前端实现‘续方审核中’
- //如果患者取消续方,则仍旧可以申请续方
- xfStatus = 2;
- }else{
- xfStatus = 1;
- }
- }
- item.canXF = canXF;
- item.xfStatus = xfStatus;
- // page[index] = item.code;
- }
- }
-
- var temp = 'record_tmp',
- isNewYear = 1;
- if((y == lastYear[index]) && !isInit){
- isNewYear = 0;
- }
- var html = template(temp, {list: obj, isNewYear: isNewYear});
- if(isInit){
- $("#item"+tmpIndex+" .mui-scroll-wrapper").show();
- $("#item"+tmpIndex+" .div-no-info").hide();
- $("#recordList"+index).empty().append(html);
- }else{
- $("#recordList"+index).append(html);
- }
- if(res.data.list.length < pagesize){
- mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
- }else{
- page[index] ++;
- }
- }else{
- if(isInit){
- //无数据
- if(isRenewal == 1){
- //获取可续方的处方列表
- $("#recordList0").empty().hide();
- $("#item1 .straight-line").hide();
- $("#item1 .div-no-info").show();
- }else{
- $("#next").hide();
- $("#item1 .mui-scroll-wrapper").hide();
- $("#item1 .div-no-info").show();
- }
- }else{
- $("#next").addClass("disabled");
- mui("#item1 .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
- }
- }
- }else{
- queryFailed(res);
- }
- });
- }
- //获取续方记录
- function getXFList(index, isInit){
- var tmpIndex = parseInt(index) + 1;
- if(isInit){
- page[index] = 1;
- }
- var url = "/patient/prescriptionInfo/getPrescriptionInfos",
- params = {
- type: parseInt(index) + 1, //type: 1-查询处方,2-我的续方, 3-续方记录
- isRenewal: 2,
- startDate: '',
- endDate: '',
- page: page[index],
- size: pagesize[index]
- };
- sendPost(url, params, 'json', 'GET', queryFailed, function(res){
- d.close();
- if(res.status == 200){
- loaded[index] = true;
- //暂时默认数据是按年份group了的 [{year: 2017, list:[]}]
- if(res.data.length > 0){
- var year = parseInt((new Date()).getFullYear());
- var obj = _.groupBy(res.data, function(o){
- for(y = year; y >= 2016; y--){
- if(o.createTime.substr(0,4) == y){
- return -y;
- }
- }
- });
- var temp = 'record'+index+'_tmp';
- var html = template(temp, {list: obj});
- if(isInit){
- $("#item"+tmpIndex+" .mui-scroll-wrapper").show();
- $("#item"+tmpIndex+" .div-no-info").hide();
- $("#recordList"+index).empty().append(html);
- }else{
- $("#recordList"+index).append(html);
- }
- if(res.data.length < pagesize){
- mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
- }else{
- page[index] ++;
- }
- }else{
- if(isInit){
- //无数据
- $("#item"+tmpIndex+" .mui-scroll-wrapper").hide();
- $("#item"+tmpIndex+" .div-no-info").show();
- }else{
- mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
- }
- }
- }else{
- queryFailed(res);
- }
- });
- }
- function getXFStatus(arr, date){
- var isXFDesease = true,
- statusName = '',
- canXF = false;
- if(arr){
- for(i=0; i<arr.length; i++){
- var item = arr[i];
- //HP0093 - 高血压 , HP0047 - 糖尿病
- if((item.healthProblem != 'HP0093') && (item.healthProblem != 'HP0047')){
- isXFDesease = false;
- break;
- }
- }
- if(isXFDesease){
- //判断时间是否是在6个月内的
- // var d = new Date(date),
- // now = new Date();
- // now.setMonth(now.getMonth() - 6);
-
- // if(d > now){ //6个月内的时间
- statusName = '续方';
- canXF = true;
- // }
- }
- }
- return canXF;
- }
- function queryFailed(res){
- d.close();
- if(res && res.msg) {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: res.msg
- }).show();
- } else {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '加载失败'
- }).show();
- }
- }
- function bindEvents(){
- document.querySelector('.mui-slider').addEventListener('slide', function(event) {
- var index = event.detail.slideNumber;
- console.log(index);
- if(!loaded[index]){ //tab未加载过,则加载数据
- d.showModal();
- if(index == 0){
- getPrescriptionList(index, true);
- }else{
- getXFList(index, true);
- }
- }
- });
-
- //只查看可续方记录按钮
- $("#checkbox").on('change', function(){
- d.showModal();
- if(this.checked){
- //获取可续方的记录
- getPrescriptionList(0, true, 1);
- }else{
- //获取全部记录
- getPrescriptionList(0, true);
- }
- });
-
- //'处方记录'tab内item的点击事件
- $("#recordList0").on('tap', '.prescription-item', function(){
- var code = $(this).attr('data-code');
- //跳转去处方详情页
- window.location.href = 'prescription_detail.html?code='+code;
- }).on('tap', '.btn', function(e){
- e.stopPropagation(); //防止事件冒泡
- var status = $(this).attr("data-status"),
- code = $(this).closest('.prescription-item').attr('data-code');
- //两种状态:1.申请续方 2.续方审核中
- if(status == 1){
- //跳转去’新增续方咨询‘页面
- var patient = $(this).closest('.prescription-item').attr('data-patient'),
- name = $(this).closest('.prescription-item').attr('data-pname');
- window.location.href = "../../yszx/html/add-prescription-consult.html?patient="+patient+'&name='+name+'&prescriptionCode='+code;
- }else{
- //跳转去’续方记录‘页面
- var prescriptionCode = $(this).attr("data-preCode");
- window.location.href = "re-prescription_info.html?code="+prescriptionCode+'&toUser='+userInfo.uid;
- }
- });
-
- //'我的续方'tab内item对应的点击事件
- $("#recordList1").on('tap', '.prescription-item', function(){
- var code = $(this).attr('data-code');
- //跳转去续方详情页面,只有审核通过的页面才有我的续方页面
- window.location.href = "re-prescription_detail.html?code="+code;
- }).on('tap', '.btn', function(e){
- e.stopPropagation();
- var code = $(this).closest('.prescription-item').attr("data-code");
- //订单跟踪按钮,跳转去订单跟踪页面
- window.location.href = "order_tracking.html?code="+code+'&toUser='+userInfo.uid;
- });
-
- //'续方管理'tab内item对应的点击事件
- $("#recordList2").on('tap', ' .prescription-item', function(){
- var code = $(this).attr('data-code');
- //跳转去续方记录页面
- window.location.href = "re-prescription_info.html?code="+code+'&toUser='+userInfo.uid;
- });
-
- //获取下一条处方数据
- $("#next").on('tap', function(){
- if($(this).hasClass("disabled")){
- return false;
- }
- d.showModal();
- getPrescriptionList(0);
- })
- }
- function templatehelper(){
- template.helper('getDateTime', function(str){
- if(str && str.length > 0){
- //str = 2017-07-31 11:09:53.0
- return str.substr(0, 19);
- }
- return '';
- });
- template.helper('getAbs', function(str) {
- console.log(str)
- return str.substr(1, 4);
- });
- template.helper('showStatus', function(status){
- return getStatusInfoAndImg(status).name;
- });
-
- template.helper('returnStatusImg', function(status){
- return getStatusInfoAndImg(status).img;
- });
-
- template.helper('getDate', function(str){
- if(str && str.length > 0){
- return str.substr(5, 6);
- }
- });
-
- template.helper('getXF', function(arr, date){
- var isXFDesease = false;
- if(arr){
- for(i=0; i<arr.length; i++){
- var item = arr[i];
- if(item.name == '高血压' || item.name == '糖尿病'){
- isXFDesease = true;
- }else{
- isXFDesease = false;
- }
- }
- if(isXFDesease){
- //判断时间是否是在6个月内的
- var d = new Date(date),
- now = new Date();
- now.setMonth(now.getMonth() - 6);
-
- if(d > now){ //6个月内的时间
- return '续方';
- }
- }
- }
- return '';
- });
- }
- //获取微信信息,并配置微信api接口
- function wxGetSign(){
- var params = {};
- params.pageUrl = window.location.href;
- $.ajax(server + "weixin/getSign", {
- data: params,
- dataType: "json",
- type: "post",
- success: function(res){
- if (res.status == 200) {
- var t = res.data.timestamp;
- var noncestr = res.data.noncestr;
- var signature = res.data.signature;
- wx.config({
- //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
- appId: appId, // 必填,公众号的唯一标识
- timestamp: t, // 必填,生成签名的时间戳
- nonceStr: noncestr, // 必填,生成签名的随机串
- signature: signature,// 必填,签名,见附录1
- jsApiList: [
- 'closeWindow'
- ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
- }
- }
- });
- }
|