select_goal.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. var self, param;
  2. var goalArr = [],
  3. patientArr = [],
  4. description = "",
  5. subNum = 0,
  6. judgeClear = false,
  7. $resultList = $("#device_goal");
  8. // 初始化画面-积分数据
  9. var goalList = function() {
  10. plus.nativeUI.showWaiting();
  11. var obj = {type: "NORMAL", status: 1},
  12. params = {
  13. taskRule: JSON.stringify(obj),
  14. page: 1,
  15. size: 100
  16. }
  17. sendPost("/doctor/healthBank/selectTaskRule", params, queryFails, function(res) {
  18. if(res.status == 200) {
  19. plus.nativeUI.closeWaiting();
  20. var list = res.data.detailModelList;
  21. var html = template("result_tmpl", {list: list});
  22. // 渲染数据
  23. if(!list || list.length == 0) {
  24. $("#no_result_wrap").show()
  25. } else {
  26. $resultList.empty().append(html);
  27. }
  28. } else {
  29. plus.nativeUI.closeWaiting();
  30. queryFails(res);
  31. }
  32. }, 'post')
  33. },
  34. //查询失败回调
  35. queryFails = function(res) {
  36. if(res) {
  37. mui.toast(res.msg)
  38. } else {
  39. mui.toast("加载失败!")
  40. }
  41. },
  42. load = function() {
  43. if(self.patient) {
  44. $("#sure").show();
  45. patientArr.push(self.patient)
  46. } else {
  47. $("#next").show();
  48. }
  49. },
  50. // 移除勾选
  51. spliceArr = function(goalId) {
  52. for(var i = 0, len = goalArr.length; i < len; i++) {
  53. if(goalArr[i] == goalId) {
  54. goalArr.splice(i, 1)
  55. return
  56. }
  57. }
  58. },
  59. // 提交数据
  60. submitData = function() {
  61. plus.nativeUI.showWaiting();
  62. var obj = {
  63. patientIds: patientArr,
  64. ruleId: goalArr[0],
  65. description: description
  66. },
  67. params = {
  68. object: JSON.stringify(obj)
  69. }
  70. sendPost("/doctor/healthBank/doctorAddInteger", params, queryFails, function(res) {
  71. if(res.status == 200) {
  72. plus.nativeUI.closeWaiting();
  73. if(res.data.status == -1) {
  74. mui.toast(res.data.message || "网络错误,请求失败!")
  75. return false;
  76. }
  77. mui.toast("操作成功!")
  78. setTimeout(function() {
  79. var vm = plus.webview.getWebviewById("pati_detail")
  80. mui.fire(vm,"reLoad")
  81. var mv = plus.webview.getWebviewById("health-bank")
  82. mui.fire(mv,"reLoad")
  83. mui.back()
  84. }, 200)
  85. } else {
  86. plus.nativeUI.closeWaiting();
  87. queryFails(res);
  88. }
  89. }, 'POST')
  90. },
  91. setDialog = function() {
  92. var judgeText = judgeClear ? "清零" : "-10分"
  93. dialog({
  94. content: '<p style="font-size:16px;">你将给予居民' + judgeText + ',请简要说明原因。</p><textarea id="reason" placeholder="请简要说明原因(必填)"></textarea>',
  95. okValue: '确认',
  96. cancelValue: '取消打分',
  97. cancel: function () {
  98. return;
  99. },
  100. ok: function() {
  101. description = $("#reason").val();
  102. if(!description || description.length <= 0) {
  103. mui.toast("扣分描述为必填项!");
  104. return false;
  105. }
  106. submitData()
  107. }
  108. }).showModal();
  109. },
  110. // 绑定页面事件
  111. bindEvents = function () {
  112. $("#con_tit div").on("tap", function() {
  113. var $this = $(this),
  114. index = $this.index();
  115. if($this.hasClass("active")){
  116. return false;
  117. }
  118. $this.siblings().removeClass("active");
  119. $this.addClass("active");
  120. mui('.mui-slider').slider().gotoItem(parseInt(index));
  121. })
  122. $("#device_goal").on("tap", ".sel-label", function() {
  123. goalArr = [];
  124. subNum = 0;
  125. var goalId = $(this).parent().attr("data-id"),
  126. jsonTradeDirection = $(this).parent().attr("data-tradeDirection"),
  127. jsonIntegrate = $(this).parent().attr("data-integrate");
  128. if(jsonIntegrate == 0) {
  129. judgeClear = true;
  130. } else {
  131. judgeClear = false;
  132. }
  133. if(jsonTradeDirection < 0) {
  134. subNum++;
  135. }
  136. if($(this).hasClass("active")) {
  137. $(this).removeClass("active");
  138. } else {
  139. $("#device_goal .sel-label").removeClass("active");
  140. $(this).addClass("active");
  141. goalArr.push(goalId);
  142. }
  143. })
  144. //滚动切换
  145. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  146. $("#con_tit div").removeClass("active")
  147. if (event.detail.slideNumber === 0) {
  148. $("#con_tit div").eq(0).addClass("active");
  149. } else if (event.detail.slideNumber === 1) {
  150. $("#con_tit div").eq(1).addClass("active");
  151. } else if (event.detail.slideNumber === 2) {
  152. $("#con_tit div").eq(2).addClass("active");
  153. } else if (event.detail.slideNumber === 3) {
  154. $("#con_tit div").eq(3).addClass("active");
  155. }
  156. });
  157. // 下一步
  158. $("#next").on("tap", function() {
  159. if(goalArr.length == 0) {
  160. mui.toast("请选择任务栏!");
  161. return false;
  162. }
  163. openWebview("health-award.html",{
  164. subNum: subNum,
  165. goalArr: goalArr,
  166. judgeClear: judgeClear
  167. });
  168. });
  169. $("#sure").on("tap", function() {
  170. if(goalArr.length == 0) {
  171. mui.toast("请先选择积分任务!")
  172. return false;
  173. }
  174. if(subNum > 0) {
  175. setDialog();
  176. } else {
  177. // 提交数据
  178. submitData();
  179. }
  180. })
  181. };
  182. // 页面业务处理流程开始
  183. mui.plusReady(function() {
  184. //获取当前页面
  185. self = plus.webview.currentWebview();
  186. load();
  187. //绑定事件
  188. bindEvents();
  189. //数据渲染
  190. goalList()
  191. })