tuisong_duixiang.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. var articleId;
  2. mui.init();
  3. mui.plusReady(function() {
  4. var self = plus.webview.currentWebview();
  5. articleId = self.articleId;
  6. init();
  7. bindEvents();
  8. });
  9. function init() {
  10. //labelType:( 1:服务类型(卫计委分组) 2:健康情况 3:疾病类型
  11. var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
  12. promise = getReqPromises([{ url: "/wlyygc/doctor/label/labels", data: { labelType: 2 }, reqType: "get" },
  13. { url: "/wlyygc/doctor/label/labels", data: { labelType: 3 }, reqType: "get" },
  14. { url: "/wlyygc/doctor/label/labels", data: { labelType: 1 }, reqType: "get" },
  15. { url: "/wlyygc/doctor/label/unitLabels", data: {currentRoleCode: selectedRole.code, currentRoleLevel: selectedRole.level }, reqType: "get"} //根据地区查找卫计委下属单位标签
  16. ])
  17. return promise.then(function(datas) {
  18. var data0 = datas[0],
  19. data1 = datas[1],
  20. data2 = datas[2];
  21. data3 = datas[3];
  22. initData(2, data0);
  23. initData(3, data1);
  24. initData(1, data2);
  25. initData(5, data3);
  26. plus.nativeUI.closeWaiting();
  27. });
  28. }
  29. function initData(type, res) {
  30. if(res.status == 10000) {
  31. if(res.result && res.result.length > 0) {
  32. appendLabel(type, res);
  33. }
  34. } else {
  35. queryFailed(res);
  36. }
  37. }
  38. function appendLabel(type, res) {
  39. if(type == 2) {
  40. //健康情况
  41. var jiankangList = _.filter(res.result, function(o) { return o.code != 0; });
  42. var healthTmp = template("option_tmp", { list: jiankangList, type: "checkbox", name: "health" });
  43. $("#health").append(healthTmp);
  44. }
  45. if(type == 3) {
  46. //疾病类型
  47. var sortList = _.sortBy(res.result, function(o) { return o.code });
  48. var diseaseTmp = template("option_tmp", { list: sortList, type: "checkbox", name: "disease" });
  49. $("#disease").append(diseaseTmp);
  50. }
  51. if(type == 1) {
  52. //服务类型
  53. var serviceTmp = template("option_tmp", { list: res.result, type: "checkbox", name: "service" });
  54. $("#service").append(serviceTmp);
  55. }
  56. if(type == 5) {
  57. //社区归属
  58. var communityTmp = template("option_tmp", { list: res.result, type: "checkbox", name: "community" });
  59. $("#community").append(communityTmp);
  60. }
  61. }
  62. function queryFailed(res) {
  63. if(res.msg) {
  64. mui.toast(res.msg);
  65. } else {
  66. mui.toast("标签加载失败!");
  67. }
  68. }
  69. function setYunChanFu(sex){
  70. if(sex=="1"){
  71. $("#service").children().each(function(){
  72. if($(this).find("label").text()=="孕产妇"){
  73. $(this).find("label").removeClass("active");
  74. $(this).find("label").css("color","#909090");
  75. $(this).find("input").attr("disabled","disabled");
  76. }
  77. })
  78. }else{
  79. $("#service").children().each(function(){
  80. if($(this).find("label").text()=="孕产妇"){
  81. $(this).find("label").removeAttr("style");
  82. $(this).find("input").removeAttr("disabled");
  83. }
  84. })
  85. }
  86. }
  87. function bindEvents() {
  88. $("body").on('change', 'input', function() {
  89. var $this = $(this),
  90. $label = $this.siblings('label');
  91. if(!this.checked) {
  92. $label.removeClass("active");
  93. //判断复选中非不限的选项是否都没有选中,如果都未选中,则将不限选中
  94. var type = $this.attr("type"),
  95. name = this.name;
  96. if(type == "checkbox") {
  97. var checkboxList = $("input[name=" + name + "]:checked"),
  98. len = checkboxList.length;
  99. if(len == 0) {
  100. var buxian = document.getElementById(name + "0");
  101. buxian.checked = true;
  102. $(buxian).siblings("label").addClass("active");
  103. }
  104. }
  105. } else {
  106. debugger
  107. $label.addClass("active");
  108. //不限选项与其他选型互斥
  109. var type = this.value,
  110. name = this.name;
  111. //性别选项都是互斥
  112. if(name == "sex") {
  113. $this.closest(".flag-div").siblings().find("label").removeClass("active");
  114. setYunChanFu($this.val())
  115. } else {
  116. if(type == 0) { //选择不限选项
  117. $this.closest(".flag-div").siblings().find("label").removeClass("active");
  118. var $inputlist = $("input[name=" + name + "]"),
  119. len = $inputlist.length;
  120. for(i = 1; i < len; i++) {
  121. $inputlist[i].checked = false;
  122. }
  123. } else {
  124. var buxian = document.getElementById(name + "0"),
  125. checked = buxian.checked;
  126. if(checked) {
  127. buxian.checked = false;
  128. $(buxian).siblings("label").removeClass("active");
  129. }
  130. }
  131. }
  132. }
  133. });
  134. $("#next_btn").on('click', function() {
  135. //获取选中的选项的值
  136. var $checked_list = $("input:checked"),
  137. len = $checked_list.length;
  138. var sex = "",
  139. disease = [],
  140. service = [],
  141. healthCondition = [],
  142. communityCondition = [],
  143. diseaseStr = "",
  144. serviceStr = "",
  145. healthConditionStr = "",
  146. communityConditionStr = "",
  147. sexText = "",
  148. diseaseText = [],
  149. serviceText = [],
  150. healthText = [],
  151. communityText = [],
  152. sexArr = [],
  153. diseaseArr = [],
  154. serviceArr = [],
  155. healthArr = [],
  156. communityArr = [];
  157. for(i = 0; i < len; i++) {
  158. var item = $checked_list[i],
  159. name = item.name,
  160. label = $(item).attr("data-label"),
  161. value = item.value ? parseInt(item.value) : item.value;
  162. if(name == "sex") {
  163. sex = value;
  164. sexText = label;
  165. var obj = {};
  166. obj.label = value;
  167. obj.labelName = label;
  168. sexArr.push(obj);
  169. }
  170. if(name == "disease") {
  171. disease.push(value);
  172. diseaseText.push(label);
  173. var obj = {};
  174. obj.label = value;
  175. obj.labelName = label;
  176. diseaseArr.push(obj);
  177. }
  178. if(name == "service") {
  179. service.push(value);
  180. serviceText.push(label);
  181. var obj = {};
  182. obj.label = value;
  183. obj.labelName = label;
  184. serviceArr.push(obj);
  185. }
  186. if(name == "health") {
  187. healthCondition.push(value);
  188. healthText.push(label);
  189. var obj = {};
  190. obj.label = value;
  191. obj.labelName = label;
  192. healthArr.push(obj);
  193. }
  194. if(name == "community") {
  195. communityCondition.push(value);
  196. communityText.push(label);
  197. var obj = {};
  198. obj.label = value;
  199. obj.labelName = label;
  200. communityArr.push(obj);
  201. }
  202. }
  203. diseaseStr = disease.join(",");
  204. serviceStr = service.join(",");
  205. healthConditionStr = healthCondition.join(",");
  206. communityConditionStr = communityCondition.join(",");
  207. plus.nativeUI.showWaiting("正在查询发送对象,所需时间较长,请稍候");
  208. //获得发送的人数
  209. var url = "/doctor/jkEdu/article/managePushArticleConfirm",
  210. params = {
  211. labelSexType: sex,
  212. labelDiseaseType: diseaseStr,
  213. labelHealthType: healthConditionStr,
  214. labelServeType: serviceStr,
  215. labelUnitType: communityConditionStr, //下属单位,多个用逗号分隔
  216. articleId: articleId
  217. };
  218. var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
  219. params.currentRoleCode = selectedRole.code;
  220. params.currentRoleLevel = selectedRole.level;
  221. sendGet(url, params, null, function(res) {
  222. if(res.status == 200) {
  223. var amount = res.amount;
  224. if(amount == 0) {
  225. dialog({
  226. content: "没有符合条件的居民,请重新选择",
  227. contentType: 'tipsbox',
  228. skin: 'popup',
  229. closeTime: 2000
  230. }).showModal();
  231. } else {
  232. dialog({
  233. content: "<div style='text-align:left;'><span style='font-weight:600;'>文章名称:</span>" + res.data.articleTitle + "</div><div style='text-align:left;'><span style='font-weight:600'>发送用户数:</span>" + res.data.num + "</div>",
  234. cancelValue: '我再看看',
  235. okValue: '立即发送',
  236. cancel: function() {
  237. return;
  238. },
  239. ok: function() {
  240. var params = {};
  241. //发送类型 1医生发送 2卫纪委发送(不填默认为2)
  242. // params.sendType = 2;
  243. //发送方名称(如:卫计委发送:集美区;医生发送:医生名称)
  244. // params.sendName = "集美区";
  245. params.labelUnitType = communityConditionStr;
  246. params.labelSexType = sex;
  247. params.labelServeType = serviceStr;
  248. params.labelDiseaseType = diseaseStr;
  249. params.labelHealthType = healthConditionStr;
  250. params.articleId = articleId;
  251. var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
  252. params.currentRoleCode = selectedRole.code;
  253. params.currentRoleLevel = selectedRole.level;
  254. sendPost("/doctor/jkEdu/article/manageSendArticleToPatients", params, function(res) {
  255. plus.nativeUI.closeWaiting();
  256. if(res.msg) {
  257. plus.nativeUI.toast(res.msg);
  258. } else {
  259. plus.nativeUI.toast("发送失败");
  260. }
  261. }, function(res) {
  262. plus.nativeUI.closeWaiting();
  263. if(res.status == 10000) {
  264. plus.nativeUI.toast("发送成功");
  265. // backArticle()
  266. } else {
  267. if(res.msg) {
  268. plus.nativeUI.toast(res.msg);
  269. } else {
  270. plus.nativeUI.toast("发送失败!");
  271. }
  272. }
  273. })
  274. }
  275. }).showModal();
  276. }
  277. } else {
  278. mui.toast(res.msg);
  279. }
  280. plus.nativeUI.closeWaiting();
  281. });
  282. });
  283. }
  284. function backArticle(){
  285. var view = plus.webview.getWebviewById("article-list");
  286. if(view){
  287. mui.fire(view,"refresh");
  288. }
  289. view=plus.webview.getWebviewById("article");
  290. if(view){
  291. mui.fire(view,"refresh");
  292. }
  293. mui.back();
  294. }