123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- 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
- }, null, null);
- $(function(){
- // 判断是否登录
- checkUserAgent();
-
- getTemplateHelper();
- 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() {
- $('#msgContainer').on('tap',function() {
- var userAgent = JSON.parse(window.localStorage.getItem(agentName));
- window.location.href = "application-msg-list.html?member="+userAgent.uid;
- });
- // 点击咨询详情
- $("#ul_family").on("tap", "li.member-li", function () {
- var $this = $(this),
- objStr = $this.attr("data-json");
-
- // 缓存信息
- window.localStorage.removeItem("familyMemberInfo");
- window.localStorage.setItem("familyMemberInfo", objStr);
-
- // 跳转详情
- window.location.href = "family-detail.html";
- });
-
- //免疫关联
- $("#ul_family").on("tap", "li.childSick", function (){
- var $this = $(this)
- location.href="../../fybj/html/mianyijihua.html"
- })
-
- //绑定居民
- $("#ul_family").on("tap", "li.add-member", function(){
- window.location.href = "add-step1.html";
- return false;
- });
-
- $('#ul_family').on('tap','.cancel-btn',function(e) {
- e.stopPropagation();
- 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(e) {
- e.stopPropagation();
- var obj = $(this).data("json");
- retryApplication(obj.name, obj.code, obj.mobile, obj.familyRelation, obj.photo);
-
- }).on('tap','.immunememberConnec',function(e){
- e.stopPropagation();
- location.href="../../fybj/html/mianyijihua.html"
- });
- }
- /**
- * 界面数据初始化
- */
- function queryInit() {
- d.showModal();
- 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 =$("#ul_family"),
- list = _.map(res.data.normalmembers, function(o){
- o.relation = getRelationName(o.familyRelation);
- o.signText = getSignText(o.signType);
- return o;
- })
- var html = template("member-tmp", {
- list: list,
- immunemembers: res.data.immunemembers
- });
-
- $list.append(html);
- d.close();
- scroller1.myScroll.refresh();
- $(".pullUp").hide();
- $(".pullDown").hide();
- } else {
- //非200则为失败
- queryListFailed(res);
- }
- mui('.mui-switch')['switch']();
- $('.mui-switch').on('tap',function(e) {
- e.stopPropagation();
- });
- $('.mui-switch').on('toggle',function(e) {
- e.stopPropagation();
- 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)
- })
- }
- function getTemplateHelper(){
- template.helper("getPhoto", function(p){
- if(p){
- return getImgUrl(p);
- }else{
- return "../../../images/p-female.png";
- }
- });
-
- template.helper("getJsonStr", function(obj){
- if(obj){
- return JSON.stringify(obj);
- }else{
- return "";
- }
- });
-
- template.helper("getSignTypeText", function(signType){
- return getSignText(signType);
- });
-
- template.helper("getRelationName", function(type){
- return getRelationName(type);
- })
- }
- function getSignText(signType){
- var signText = "";
- if (signType == 1) {
- signText = "三师共管";
- } else if (signType == 2) {
- signText = "家庭医生";
- } else if (signType == 3) {
- signText = "三师共管、家庭医生";
- }
- return signText;
- }
- function getRelationName(type){
- var relation = "";
- switch(type){
- case 0:
- relation = "其他";
- break;
- case 1:
- relation = "父亲";
- break;
- case 2:
- relation = "母亲";
- break;
- case 3:
- relation = "老公";
- break;
- case 4:
- relation = "老婆";
- break;
- case 5:
- relation = "儿子";
- break;
- case 6:
- relation = "女儿";
- break;
- default:
- relation = "未知";
- break;
- }
- return relation;
- }
|