var articleId; mui.init(); mui.plusReady(function() { var self = plus.webview.currentWebview(); articleId = self.articleId; init(); bindEvents(); }); function init() { //labelType:( 1:服务类型(卫计委分组) 2:健康情况 3:疾病类型 var selectedRole = JSON.parse(plus.storage.getItem("selectedRole")); promise = getReqPromises([{ url: "/wlyygc/doctor/label/labels", data: { labelType: 2 }, reqType: "get" }, { url: "/wlyygc/doctor/label/labels", data: { labelType: 3 }, reqType: "get" }, { url: "/wlyygc/doctor/label/labels", data: { labelType: 1 }, reqType: "get" }, { url: "/wlyygc/doctor/label/unitLabels", data: {currentRoleCode: selectedRole.code, currentRoleLevel: selectedRole.level }, reqType: "get"} //根据地区查找卫计委下属单位标签 ]) return promise.then(function(datas) { var data0 = datas[0], data1 = datas[1], data2 = datas[2]; data3 = datas[3]; initData(2, data0); initData(3, data1); initData(1, data2); initData(5, data3); plus.nativeUI.closeWaiting(); }); } function initData(type, res) { if(res.status == 10000) { if(res.result && res.result.length > 0) { appendLabel(type, res); } } else { queryFailed(res); } } function appendLabel(type, res) { if(type == 2) { //健康情况 var jiankangList = _.filter(res.result, function(o) { return o.code != 0; }); var healthTmp = template("option_tmp", { list: jiankangList, type: "checkbox", name: "health" }); $("#health").append(healthTmp); } if(type == 3) { //疾病类型 var sortList = _.sortBy(res.result, function(o) { return o.code }); var diseaseTmp = template("option_tmp", { list: sortList, type: "checkbox", name: "disease" }); $("#disease").append(diseaseTmp); } if(type == 1) { //服务类型 var serviceTmp = template("option_tmp", { list: res.result, type: "checkbox", name: "service" }); $("#service").append(serviceTmp); } if(type == 5) { //社区归属 var communityTmp = template("option_tmp", { list: res.result, type: "checkbox", name: "community" }); $("#community").append(communityTmp); } } function queryFailed(res) { if(res.msg) { mui.toast(res.msg); } else { mui.toast("标签加载失败!"); } } function setYunChanFu(sex){ if(sex=="1"){ $("#service").children().each(function(){ if($(this).find("label").text()=="孕产妇"){ $(this).find("label").removeClass("active"); $(this).find("label").css("color","#909090"); $(this).find("input").attr("disabled","disabled"); } }) }else{ $("#service").children().each(function(){ if($(this).find("label").text()=="孕产妇"){ $(this).find("label").removeAttr("style"); $(this).find("input").removeAttr("disabled"); } }) } } function bindEvents() { $("body").on('change', 'input', function() { var $this = $(this), $label = $this.siblings('label'); if(!this.checked) { $label.removeClass("active"); //判断复选中非不限的选项是否都没有选中,如果都未选中,则将不限选中 var type = $this.attr("type"), name = this.name; if(type == "checkbox") { var checkboxList = $("input[name=" + name + "]:checked"), len = checkboxList.length; if(len == 0) { var buxian = document.getElementById(name + "0"); buxian.checked = true; $(buxian).siblings("label").addClass("active"); } } } else { debugger $label.addClass("active"); //不限选项与其他选型互斥 var type = this.value, name = this.name; //性别选项都是互斥 if(name == "sex") { $this.closest(".flag-div").siblings().find("label").removeClass("active"); setYunChanFu($this.val()) } else { if(type == 0) { //选择不限选项 $this.closest(".flag-div").siblings().find("label").removeClass("active"); var $inputlist = $("input[name=" + name + "]"), len = $inputlist.length; for(i = 1; i < len; i++) { $inputlist[i].checked = false; } } else { var buxian = document.getElementById(name + "0"), checked = buxian.checked; if(checked) { buxian.checked = false; $(buxian).siblings("label").removeClass("active"); } } } } }); $("#next_btn").on('click', function() { //获取选中的选项的值 var $checked_list = $("input:checked"), len = $checked_list.length; var sex = "", disease = [], service = [], healthCondition = [], communityCondition = [], diseaseStr = "", serviceStr = "", healthConditionStr = "", communityConditionStr = "", sexText = "", diseaseText = [], serviceText = [], healthText = [], communityText = [], sexArr = [], diseaseArr = [], serviceArr = [], healthArr = [], communityArr = []; for(i = 0; i < len; i++) { var item = $checked_list[i], name = item.name, label = $(item).attr("data-label"), value = item.value ? parseInt(item.value) : item.value; if(name == "sex") { sex = value; sexText = label; var obj = {}; obj.label = value; obj.labelName = label; sexArr.push(obj); } if(name == "disease") { disease.push(value); diseaseText.push(label); var obj = {}; obj.label = value; obj.labelName = label; diseaseArr.push(obj); } if(name == "service") { service.push(value); serviceText.push(label); var obj = {}; obj.label = value; obj.labelName = label; serviceArr.push(obj); } if(name == "health") { healthCondition.push(value); healthText.push(label); var obj = {}; obj.label = value; obj.labelName = label; healthArr.push(obj); } if(name == "community") { communityCondition.push(value); communityText.push(label); var obj = {}; obj.label = value; obj.labelName = label; communityArr.push(obj); } } diseaseStr = disease.join(","); serviceStr = service.join(","); healthConditionStr = healthCondition.join(","); communityConditionStr = communityCondition.join(","); plus.nativeUI.showWaiting("正在查询发送对象,所需时间较长,请稍候"); //获得发送的人数 var url = "/doctor/jkEdu/article/managePushArticleConfirm", params = { labelSexType: sex, labelDiseaseType: diseaseStr, labelHealthType: healthConditionStr, labelServeType: serviceStr, labelUnitType: communityConditionStr, //下属单位,多个用逗号分隔 articleId: articleId }; var selectedRole = JSON.parse(plus.storage.getItem("selectedRole")); params.currentRoleCode = selectedRole.code; params.currentRoleLevel = selectedRole.level; sendGet(url, params, null, function(res) { if(res.status == 200) { var amount = res.amount; if(amount == 0) { dialog({ content: "没有符合条件的居民,请重新选择", contentType: 'tipsbox', skin: 'popup', closeTime: 2000 }).showModal(); } else { dialog({ content: "
文章名称:" + res.data.articleTitle + "
发送用户数:" + res.data.num + "
", cancelValue: '我再看看', okValue: '立即发送', cancel: function() { return; }, ok: function() { var params = {}; //发送类型 1医生发送 2卫纪委发送(不填默认为2) // params.sendType = 2; //发送方名称(如:卫计委发送:集美区;医生发送:医生名称) // params.sendName = "集美区"; params.labelUnitType = communityConditionStr; params.labelSexType = sex; params.labelServeType = serviceStr; params.labelDiseaseType = diseaseStr; params.labelHealthType = healthConditionStr; params.articleId = articleId; var selectedRole = JSON.parse(plus.storage.getItem("selectedRole")); params.currentRoleCode = selectedRole.code; params.currentRoleLevel = selectedRole.level; sendPost("/doctor/jkEdu/article/manageSendArticleToPatients", params, function(res) { plus.nativeUI.closeWaiting(); if(res.msg) { plus.nativeUI.toast(res.msg); } else { plus.nativeUI.toast("发送失败"); } }, function(res) { plus.nativeUI.closeWaiting(); if(res.status == 10000) { plus.nativeUI.toast("发送成功"); // backArticle() } else { if(res.msg) { plus.nativeUI.toast(res.msg); } else { plus.nativeUI.toast("发送失败!"); } } }) } }).showModal(); } } else { mui.toast(res.msg); } plus.nativeUI.closeWaiting(); }); }); } function backArticle(){ var view = plus.webview.getWebviewById("article-list"); if(view){ mui.fire(view,"refresh"); } view=plus.webview.getWebviewById("article"); if(view){ mui.fire(view,"refresh"); } mui.back(); }