tuisong_duixiang.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 bindEvents() {
  70. $("body").on('change', 'input', function() {
  71. var $this = $(this),
  72. $label = $this.siblings('label');
  73. if(!this.checked) {
  74. $label.removeClass("active");
  75. //判断复选中非不限的选项是否都没有选中,如果都未选中,则将不限选中
  76. var type = $this.attr("type"),
  77. name = this.name;
  78. if(type == "checkbox") {
  79. var checkboxList = $("input[name=" + name + "]:checked"),
  80. len = checkboxList.length;
  81. if(len == 0) {
  82. var buxian = document.getElementById(name + "0");
  83. buxian.checked = true;
  84. $(buxian).siblings("label").addClass("active");
  85. }
  86. }
  87. } else {
  88. $label.addClass("active");
  89. //不限选项与其他选型互斥
  90. var type = this.value,
  91. name = this.name;
  92. //性别选项都是互斥
  93. if(name == "sex") {
  94. $this.closest(".flag-div").siblings().find("label").removeClass("active");
  95. } else {
  96. if(type == 0) { //选择不限选项
  97. $this.closest(".flag-div").siblings().find("label").removeClass("active");
  98. var $inputlist = $("input[name=" + name + "]"),
  99. len = $inputlist.length;
  100. for(i = 1; i < len; i++) {
  101. $inputlist[i].checked = false;
  102. }
  103. } else {
  104. var buxian = document.getElementById(name + "0"),
  105. checked = buxian.checked;
  106. if(checked) {
  107. buxian.checked = false;
  108. $(buxian).siblings("label").removeClass("active");
  109. }
  110. }
  111. }
  112. }
  113. });
  114. $("#next_btn").on('click', function() {
  115. //获取选中的选项的值
  116. var $checked_list = $("input:checked"),
  117. len = $checked_list.length;
  118. var sex = "",
  119. disease = [],
  120. service = [],
  121. healthCondition = [],
  122. communityCondition = [],
  123. diseaseStr = "",
  124. serviceStr = "",
  125. healthConditionStr = "",
  126. communityConditionStr = "",
  127. sexText = "",
  128. diseaseText = [],
  129. serviceText = [],
  130. healthText = [],
  131. communityText = [],
  132. sexArr = [],
  133. diseaseArr = [],
  134. serviceArr = [],
  135. healthArr = [],
  136. communityArr = [];
  137. for(i = 0; i < len; i++) {
  138. var item = $checked_list[i],
  139. name = item.name,
  140. label = $(item).attr("data-label"),
  141. value = item.value ? parseInt(item.value) : item.value;
  142. if(name == "sex") {
  143. sex = value;
  144. sexText = label;
  145. var obj = {};
  146. obj.label = value;
  147. obj.labelName = label;
  148. sexArr.push(obj);
  149. }
  150. if(name == "disease") {
  151. disease.push(value);
  152. diseaseText.push(label);
  153. var obj = {};
  154. obj.label = value;
  155. obj.labelName = label;
  156. diseaseArr.push(obj);
  157. }
  158. if(name == "service") {
  159. service.push(value);
  160. serviceText.push(label);
  161. var obj = {};
  162. obj.label = value;
  163. obj.labelName = label;
  164. serviceArr.push(obj);
  165. }
  166. if(name == "health") {
  167. healthCondition.push(value);
  168. healthText.push(label);
  169. var obj = {};
  170. obj.label = value;
  171. obj.labelName = label;
  172. healthArr.push(obj);
  173. }
  174. if(name == "community") {
  175. communityCondition.push(value);
  176. communityText.push(label);
  177. var obj = {};
  178. obj.label = value;
  179. obj.labelName = label;
  180. communityArr.push(obj);
  181. }
  182. }
  183. diseaseStr = disease.join(",");
  184. serviceStr = service.join(",");
  185. healthConditionStr = healthCondition.join(",");
  186. communityConditionStr = communityCondition.join(",");
  187. plus.nativeUI.showWaiting("正在查询发送对象,所需时间较长,请稍候");
  188. //获得发送的人数
  189. var url = "/doctor/jkEdu/article/managePushArticleConfirm",
  190. params = {
  191. labelSexType: sex,
  192. labelDiseaseType: diseaseStr,
  193. labelHealthType: healthConditionStr,
  194. labelServeType: serviceStr,
  195. labelUnitType: communityConditionStr, //下属单位,多个用逗号分隔
  196. articleId: articleId,
  197. };
  198. var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
  199. params.currentRoleCode = selectedRole.code;
  200. params.currentRoleLevel = selectedRole.level;
  201. sendGet(url, params, null, function(res) {
  202. if(res.status == 200) {
  203. var amount = res.amount;
  204. if(amount == 0) {
  205. dialog({
  206. content: "没有符合条件的居民,请重新选择",
  207. contentType: 'tipsbox',
  208. skin: 'popup',
  209. closeTime: 2000
  210. }).showModal();
  211. } else {
  212. dialog({
  213. 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>",
  214. cancelValue: '我再看看',
  215. okValue: '立即发送',
  216. cancel: function() {
  217. return;
  218. },
  219. ok: function() {
  220. var params = {};
  221. //发送类型 1医生发送 2卫纪委发送(不填默认为2)
  222. // params.sendType = 2;
  223. //发送方名称(如:卫计委发送:集美区;医生发送:医生名称)
  224. // params.sendName = "集美区";
  225. params.labelUnitType = communityConditionStr;
  226. params.labelSexType = sex;
  227. params.labelServeType = serviceStr;
  228. params.labelDiseaseType = diseaseStr;
  229. params.labelHealthType = healthConditionStr;
  230. params.articleId = articleId;
  231. var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
  232. params.currentRoleCode = selectedRole.code;
  233. params.currentRoleLevel = selectedRole.level;
  234. sendPost("/doctor/jkEdu/article/manageSendArticleToPatients", params, function(res) {
  235. plus.nativeUI.closeWaiting();
  236. if(res.msg) {
  237. plus.nativeUI.toast(res.msg);
  238. } else {
  239. plus.nativeUI.toast("发送失败");
  240. }
  241. }, function(res) {
  242. plus.nativeUI.closeWaiting();
  243. if(res.status == 10000) {
  244. plus.nativeUI.toast("发送成功");
  245. } else {
  246. if(res.msg) {
  247. plus.nativeUI.toast(res.msg);
  248. } else {
  249. plus.nativeUI.toast("发送失败!");
  250. }
  251. }
  252. })
  253. }
  254. }).showModal();
  255. }
  256. } else {
  257. mui.toast(res.msg);
  258. }
  259. plus.nativeUI.closeWaiting();
  260. });
  261. });
  262. }