var d = dialog({contentType:'load', skin:'bk-popup'}); var id = 0; var pagetype = 22; var scroller1 = new IScrollPullUpDown('wrapper',{ probeType:2, bounceTime: 250, bounceEasing: 'quadratic', mouseWheel:false, scrollbars:true, click:true, fadeScrollbars:true, interactiveScrollbars:false }, pullDownAction, null); $(function(){ // 判断是否登录 checkUserAgent(); $('#msgContainer').on('tap',function() { var userAgent = JSON.parse(window.localStorage.getItem(agentName)); window.location.href = "application-msg-list.html?member="+userAgent.uid; }); // 点击咨询详情 $("body").on("tap", ".n-list.tap-enable", function () { if ($(this).is(".list-last")) { window.location.href = "add-step1.html"; } else { // 缓存信息 var index = $(this).parents("li").index(); var name = $(this).data("name"); var imgUrl = $(this).find("img").attr("src"); var code = $(this).data("code"); var mobile = $(this).data("mobile"); var idcard = $(this).data("idcard"); var address = $(this).data("address"); var sign = $(this).data("sign"); var relation, relationIndex = "relation" + index; relation = $(this).data("relation"); window.localStorage.removeItem(relationIndex); window.localStorage.setItem(relationIndex, relation); window.localStorage.removeItem("index"); window.localStorage.setItem("index", index); window.localStorage.removeItem("name"); window.localStorage.setItem("name", name); window.localStorage.removeItem("imgUrl"); window.localStorage.setItem("imgUrl", imgUrl); window.localStorage.removeItem("code"); window.localStorage.setItem("code", code); window.localStorage.removeItem("mobile"); window.localStorage.setItem("mobile", mobile); window.localStorage.removeItem("idcard"); window.localStorage.setItem("idcard", idcard); window.localStorage.removeItem("address"); window.localStorage.setItem("address", address); window.localStorage.removeItem("sign"); window.localStorage.setItem("sign", sign); // 跳转详情 window.location.href = "family-detail.html"; } }); //免疫关联 $("body").on("tap", ".n-list.childSick", function (){ var $this = $(this) location.href="../../fybj/html/mianyijihua.html" }) bindEvents(); }); //下拉刷新 function pullDownAction(theScrollerTemp) { $(".pullDown").show(); setTimeout(function () { $("#ul_family").html(""); queryInit(); }, 1000); } //上拉加载数据 function pullUpAction(theScrollerTemp) { $(".pullUp").show(); setTimeout(function () { queryInit(); }, 1000); } // 禁止拖动 document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); function bindEvents() { $('#wrapper').on('tap','.cancel-btn',function() { var id = $(this).attr('data-id'); dialog({ content: '确定撤销添加此家人的申请吗?', ok: function() { cancelApplicationPromise(id) .then(function(res) { if(res.status=="200") { dialog({contentType:'tipsbox', skin:'bk-popup' , content:"撤销成功"}).show(); $("#ul_family").html(""); queryInit(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg||"撤销失败"}).show(); } },function() { dialog({contentType:'tipsbox', skin:'bk-popup' , content:"撤销失败"}).show(); }).catch(function(e) { console && console.error(e) }) }, cancel: function() { return; } }).showModal(); }).on('tap','.retry-btn',function() { var code = $(this).attr('data-code'); var mobile = $(this).attr('data-mobile'); var name = $(this).attr('data-name'); var relation = $(this).attr('data-relation'); var photo = $(this).attr('data-photo'); retryApplication(name,code,mobile,relation,photo); }).on('tap','.immunememberConnec',function(){ location.href="../../fybj/html/mianyijihua.html" }); } /** * 界面数据初始化 */ function queryInit() { d.show(); var data = {}; sendPostNoCache("patient/family/members", data, "json", "get", queryListFailed, queryAppoListSuccesss); var userAgent = JSON.parse(window.localStorage.getItem(agentName)); getFamilyMesListPromise(userAgent.uid) .then(function(res) { if(res.status == "200") { if(res.data.mes && res.data.mes.length) { var unhandledMsgs = _.filter(res.data.mes,function(v) { return v.state == '0' }); if(unhandledMsgs.length) { $('#msgNum').text('('+unhandledMsgs.length+')') } } } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } }); } function queryListFailed(res) { d.close(); if (res && res.msg) { var d1 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}); } else { var d2 = dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}); } } function queryAppoListSuccesss(res) { if (res.status == 200) { var $list = document.querySelector("#ul_family"); if (res.data && res.data.normalmembers.length > 0) { var list = res.data.normalmembers; window.localStorage.removeItem("userfamily"); window.localStorage.setItem("userfamily", JSON.stringify(res.data)); for (var i = 0; i < list.length; i++) { var $li = document.createElement("li"); var code = list[i].code; var name = list[i].name; var mobile = list[i].mobile; var idcard = list[i].idcard; var address = list[i].address; var familyRelation = list[i].familyRelation; var photo = getImgUrl(list[i].photo); var signType=list[i].signType; var isAuthorize = list[i].isAuthorize; var state = list[i].state; // 状态(0 :未处理;1:已同意;2:已拒绝;3:已撤销) var id = list[i].id; // 手机不存在默认显示未绑定手机 if(mobile == undefined || mobile == null || mobile == ""){ mobile = "未绑定手机"; } // 地址不存在或者为空显示空 if(address == undefined || address == null || address == ""){ address = ""; } // 头像为空设置默认头像 if(photo == undefined || photo == null || photo == ""){ photo = "../../../images/p-default.png"; } // 家庭关系 var relation = ""; if (familyRelation == 0) { relation = "其他"; } else if (familyRelation == 1) { relation = "父亲"; } else if (familyRelation == 2) { relation = "母亲"; } else if (familyRelation == 3) { relation = "老公"; } else if (familyRelation == 4) { relation = "老婆"; } else if (familyRelation == 5) { relation = "儿子"; } else if (familyRelation == 6) { relation = "女儿"; } else if (familyRelation == 7) { relation = "未知"; }; // 签约类型 var signTmpl = ""; var signText = ""; if (signType == 0) { signTmpl = '

未签约

'; signText = "未签约"; } else { if (signType == 1) { signText = "三师共管"; } else if (signType == 2) { signText = "家庭医生"; } else if (signType == 3) { signText = "三师共管、家庭医生"; } signTmpl = '

签约类型:' + signText + '

' } var childContent = ""; if(state == "1") { childContent = '
'+ '
'+ '
'+ '
'+ ''+ '
'+ '
'+ '
'+ '

' + name + '(' + relation + ')

'+ signTmpl + '
'+ '
'+ '
'+ '
  • '+ '
    '+ '

    授权设置

    '+ '

    是否允许该家人处理您全部健康服务

    '+ '
    '+ '
    '+ '
    ' '
  • '+ '' ; } else if(state == "0") { childContent = '
    '+ '
    '+ '
    '+ '
    '+ ''+ '
    '+ '
    '+ '
    '+ '

    ' + name + '(' + relation + ')

    '+ '

    待对方确认关联

    ' + '
    '+ '
    '+ '
    '+ '
    '+ '
    '+ '
    重新添加
    '+ '
     撤销 
    '+ '
    '+ '
    ' ; } else if(state == "2") { childContent = '
    '+ '
    '+ '
    '+ '
    '+ ''+ '
    '+ '
    '+ '
    '+ '

    ' + name + '(免疫关联)

    '+'

    未签约

    ' '
    '+ '
    '+ '
    '; } $li.innerHTML = childContent; $list.appendChild($li); } if( res.data.immunemembers && res.data.immunemembers.length > 0){ var listImmunemembers = res.data.immunemembers; for(var j = 0; j < listImmunemembers.length; j++){ var $li = document.createElement("li"); var immunememberName = listImmunemembers[j].name; var immunememberPhoto = getImgUrl(listImmunemembers[j].photo); // 头像为空设置默认头像 if(immunememberPhoto == undefined || immunememberPhoto == null || immunememberPhoto == ""){ immunememberPhoto = "../../../images/p-default.png"; } childContent = '
    '+ '
    '+ '
    '+ '
    '+ ''+ '
    '+ '
    '+ '
    '+ '

    ' + immunememberName + '(免疫关联)

    ' // +'

    未签约

    ' '
    '+ '
    '+ '
    '; $li.innerHTML = childContent; $list.appendChild($li); } } var $liLast = document.createElement("li"); lastContent = '
    '+ ''+ '

    添加家人

    '+ '
    '; $liLast.innerHTML = lastContent; $list.appendChild($liLast); } else { var $li = document.createElement("li"); var content = '
    '+ ''+ '

    添加家人

    '+ '
    '; $li.innerHTML = content; $list.appendChild($li); } d.close(); scroller1.myScroll.refresh(); $(".pullUp").hide(); $(".pullDown").hide(); } else { //非200则为失败 queryListFailed(res); } mui('.mui-switch')['switch'](); $('.mui-switch').on('toggle',function(e) { var event = e.originalEvent; d.show() var isAuthorize = event.detail.isActive?1:0; var msg = isAuthorize?'授权':'取消授权'; sendPost("patient/family/member_authorize", { familyMember: $(this).data('code'), isAuthorize: isAuthorize }, "json", "post", function() { d.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg+'失败'}).show(); }, function(){ d.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:(msg+'成功')}).show(); }); }) } function getFamilyMesListPromise(code) { return new Promise(function(resolve, reject) { sendPost("patient/family/getFamilyMesList", { code: code } , "json", "POST", function failed (res) { d.close(); }, function(res) { resolve(res) }); }) } function cancelApplicationPromise(id) { d.show(); return new Promise(function(resolve, reject) { sendPost("patient/family/member_revoke", { id: id } , "json", "POST", function failed (res) { d.close(); reject(res); }, function(res) { d.close(); resolve(res) }); }) } function checkMemberPromise(code) { return new Promise(function(resolve, reject) { sendPost("patient/family/check_member", { memberCode: code }, "json", "get", commitFailed, function(res) { resolve(res) }); }) } // 提交失败 function commitFailed (res) { d.close(); if (res && res.msg) { var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } else { var d2 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show(); } } function sendWXTempPromise(data) { return new Promise(function(resolve, reject) { sendPost("patient/family/sendWXTemp", data , "json", "POST", commitFailed, function(res) { resolve(res) }); }) } function retryApplication(name,code,mobile,relation,photo) { d.show(); window.localStorage.removeItem("familyCode"); window.localStorage.setItem("familyCode", code); window.localStorage.removeItem("familyName"); window.localStorage.setItem("familyName", name); window.localStorage.removeItem("familyImgUrl"); window.localStorage.setItem("familyImgUrl", photo); window.localStorage.removeItem("familyRelation"); window.localStorage.setItem("familyRelation", relation); checkMemberPromise(code) .then(function(res) { d.close(); if(res.status == "200") { var state = res.data.state; if(state == "0") { // 未绑定微信和手机 window.location.href = 'add-step3.html'; } else if(state == "1") { // 仅绑定微信 sendWXTempPromise({ member: code, relation: relation, reAdd: "1" // 重新申请 }) .then(function(res) { if(res.status=="200") { dialog({contentType:'tipsbox', skin:'bk-popup' , content:"已发送添加申请"}).show(); } else { if(res.msg){ dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); }else dialog({contentType:'tipsbox', skin:'bk-popup' , content:"发送失败"}).show(); } }) } else if(state == "2") { // 仅绑定手机 window.localStorage.removeItem("familyMobile"); window.localStorage.setItem("familyMobile", mobile); window.location.href = 'add-step2.html'; } else if(state== "3") { // 手机和微信都绑定 window.localStorage.removeItem("familyMobile"); window.localStorage.setItem("familyMobile", mobile); window.location.href = 'add-step2-pre.html?reAdd=1'; } } else { d.close(); dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show() } }) .catch(function(e) { d.close(); console && console.error(e) }) }