zhuanyijumin.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. var baseInfo = null,// 基本信息(包括userAgent)
  2. baseEnv = null, // 基础环境信息(包括当前webview)
  3. self,
  4. $searchbarInput = $('.icon-sousuo-btn'),// 搜索输入框
  5. $sendCount = $("#sendCount");//发送数量
  6. var lastTeamId,
  7. typeId = 1, //记录排列的值
  8. sendCount = 0, //记录发送的数量
  9. groupId = 0,//记录分组的值
  10. groupName = '',//记录分组的名字
  11. groupData = '',//记录分组的所有数据
  12. type,//转移或分配
  13. docCode,//医生code
  14. level,//2全科 3健管
  15. allCount,//所有人数
  16. allGroupData=[],//所有组的数据信息
  17. allGroupCode=[];//所有组的数据code
  18. // 获取登录相关信息
  19. var getBaseInfo = function() {
  20. var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
  21. self = plus.webview.currentWebview();
  22. docCode = self.docCode;
  23. level = self.level;
  24. type = self.type;
  25. return {
  26. userAgent: userAgent,
  27. teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
  28. }
  29. },
  30. // 获取基础环境信息
  31. getBaseEnvPromise = function () {
  32. var env = {
  33. webview: plus&&plus.webview.currentWebview()
  34. };
  35. return Promise.resolve().then(function(res) {
  36. return env;
  37. });
  38. },
  39. // 初始化选择团队
  40. initTeams = function (){
  41. // lastTeamId = self.teamCode;
  42. //从消息列表过来的处理是没有团队code,能够分配健管师的只能是团队长 20171110 rl update
  43. if(self.teamCode){
  44. lastTeamId = self.teamCode;
  45. }else{
  46. var teams = baseInfo.teamInfo.data,
  47. len = teams.length;
  48. for(i=0; i<len; i++){
  49. if(baseInfo.userAgent.uid == teams[i].leaderCode){
  50. lastTeamId = teams[i].id;
  51. }
  52. }
  53. }
  54. $('#sortName').text($('#sortList').find('li').eq(typeId-1).find('a').text());//排列初始值
  55. $('.notice-tip').text('服务类型分组仅支持'+type+'2017年签约居民,如需为2016年签约居民进行操作,请使用健康情况、疾病类型、团队标签或所属居委会分组,或搜索居民单独'+type)
  56. },
  57. // 初始化画面患者分组列表
  58. initPatientGroupsList = function() {
  59. if(!lastTeamId){ return; }
  60. plus.nativeUI.showWaiting();
  61. var url = type == "分配" ? 'doctor/family_contract/findNoHealthSignFamilyHealthNum' : '/doctor/family_contract/getPatientLables' ;
  62. getReqPromise(url,{labelType: typeId, teamCode: lastTeamId,oldDoctorCode:docCode,level:level})
  63. .then(function(res) {
  64. if(res.status == 200) {
  65. groupData = res.data.patients;//储存分组的数据
  66. if(groupData){
  67. _.map(groupData,function(item){
  68. $.each(item.codes, function(i, v) {
  69. allGroupData.push(v);
  70. allGroupCode.push(v.code);
  71. })
  72. })
  73. allGroupCode = _.uniq(allGroupCode);
  74. allCount = allGroupCode.length;
  75. }
  76. if(typeId = 3){
  77. var other = _.find(groupData, function(v) {
  78. return v.label == "其他疾病"
  79. });
  80. var arr = _.filter(groupData, function(v) {
  81. return v.label != "其他疾病"
  82. }) || [];
  83. other && arr.push(other);
  84. groupData = arr;
  85. }
  86. var html = template("groups_tmpl", {list: groupData});
  87. $('#groupList').empty().append(html);
  88. countHeight(groupData);
  89. changeGroupNum($('#groupList').find('li').eq(0));
  90. mui('.mui-scroll-wrapper').scroll({
  91. bounce: false //是否启用回弹
  92. }).scrollTo(0,0,100);
  93. plus.nativeUI.closeWaiting();
  94. }
  95. if(res.status == -1){
  96. plus.nativeUI.closeWaiting();
  97. mui.toast('数据获取失败');
  98. }
  99. }).catch(function(e){ console && console.error(e) });;
  100. },
  101. countHeight = function(data){
  102. var num = data.length;
  103. if(num>5){
  104. $('#sheet3_area').css('height','276px');
  105. }else{
  106. $('#sheet3_area').css('height',46*(num+1));
  107. }
  108. },
  109. changeGroupNum = function(obj){
  110. var groupNum;
  111. groupId = obj.data('id');//储存组的位置
  112. $('#groupName').text(obj.find('a').text());
  113. //groupId=0为全部分组
  114. if(groupId>0){
  115. groupNum = groupData[groupId-1].number;
  116. groupName = groupData[groupId-1].label;
  117. }else{
  118. groupNum = allCount;
  119. groupName = '';
  120. }
  121. var html = template("num_tmpl",{data:groupNum});
  122. $('#numList').empty().append(html);
  123. changePeopleNum($('#numList').find('li').eq(0));//取人数初始值
  124. },
  125. changePeopleNum = function(obj){
  126. $('#peopleNum').text(obj.find('a').text());
  127. sendCount = obj.data('num');
  128. $sendCount.text(sendCount);//发送人数
  129. if(sendCount>0){
  130. $('#sendBtn').addClass('active');//变色
  131. }else{
  132. $('#sendBtn').removeClass('active');
  133. }
  134. },
  135. // 绑定页面事件
  136. bindEvents = function () {
  137. $('#sortList').on('click','.j-choose-name',function(){
  138. var $this = $(this);
  139. $('#sortName').text($this.find('a').text());
  140. typeId = $this.data('type');
  141. mui('#sheet2').popover('toggle');
  142. initPatientGroupsList();
  143. $sendCount.text(0);
  144. sendCount=0;
  145. groupId = 0;
  146. allGroupData=[];//所有组的数据信息
  147. allGroupCode=[];
  148. })
  149. $('#groupList').on('click','.j-choose-name',function(){
  150. var $this = $(this);
  151. changeGroupNum($this);
  152. mui('#sheet3').popover('toggle');
  153. })
  154. $('#numList').on('click','.j-choose-name',function(){
  155. var $this = $(this);
  156. changePeopleNum($this);
  157. mui('#sheet4').popover('toggle');
  158. })
  159. $searchbarInput.on('click',function() {
  160. mui.openWindow({
  161. id: "zhuanyijumin_search",
  162. url: "zhuanyijumin_search.html",
  163. extras: {
  164. type:type,
  165. docCode:docCode,
  166. level:level,
  167. lastTeamId:lastTeamId,
  168. }
  169. });
  170. })
  171. $("#sendBtn").on('click',function(){
  172. if(sendCount<=0){
  173. mui.toast('请至少选一个居民!');
  174. return;
  175. }
  176. plus.nativeUI.showWaiting();
  177. //取居民code
  178. var pCode=[],
  179. patientArr=[];
  180. if(groupId>0){//不是全部分组
  181. for(var i=0;i<sendCount;i++){
  182. pCode.push(groupData[groupId-1].codes[i].code)
  183. }
  184. }else{//全部分组
  185. for(var i=0;i<sendCount;i++){
  186. pCode.push(allGroupCode[i])
  187. }
  188. }
  189. pCode = pCode.join(',');
  190. if(type == '转移'){
  191. sendPost("/doctor/consult/getConsultByPatientAndDoctor", {patientCode: pCode, doctor: docCode}, null, function(res){
  192. var tem = {};
  193. if(res.length==0){
  194. to_next(pCode);
  195. } else if(res.length == sendCount){
  196. plus.nativeUI.closeWaiting();
  197. mui.confirm("对不起,您选择的居民均有尚未结束的健康咨询,无法继续转移。", "提示", ["我知道了"], function(e){})
  198. return;
  199. } else if(res.length <= 3 ){
  200. tem = getCanTrans(allGroupCode, res);
  201. plus.nativeUI.closeWaiting();
  202. mui.confirm("居民"+ tem.names + "尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){
  203. if(e.index == 0){
  204. to_next(tem.canPati);
  205. cancleSel(res);
  206. }
  207. })
  208. } else if(res.length < sendCount){
  209. tem = getCanTransByCode(allGroupCode, res);
  210. plus.nativeUI.closeWaiting();
  211. mui.confirm("选中居民中有"+ res.length + "人,尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){
  212. if(e.index == 0){
  213. to_next(tem.canPati);
  214. cancleSel(res);
  215. }
  216. })
  217. }
  218. })
  219. }else{
  220. to_next(pCode)
  221. return;
  222. }
  223. })
  224. function getCanTrans(allGroupCode, notCodes){
  225. var canPati = [];
  226. var names = [];
  227. $.each(allGroupCode, function(i, v) {
  228. var has = false;
  229. $.each(notCodes, function(n, m) {
  230. if(v == m){
  231. has = true;
  232. var obj = _.find(allGroupData, function(o){ return o.code== m; });
  233. names.push(obj.name);
  234. }
  235. });
  236. if(!has){
  237. canPati.push(v);
  238. }
  239. });
  240. return {canPati: canPati.join(","), names: names.join(",")}
  241. }
  242. function getCanTransByCode(allGroupCode, notCodes){
  243. var canPati = [];
  244. $.each(allGroupCode, function(i, v) {
  245. var has = false;
  246. $.each(notCodes, function(n, m) {
  247. if(v == m){
  248. has = true;
  249. }
  250. });
  251. if(!has){
  252. canPati.push(v);
  253. }
  254. });
  255. return {canPati: canPati.join(",")}
  256. }
  257. function cancleSel(notCodes){
  258. sendCount = sendCount*1 - (notCodes.length)*1
  259. }
  260. function to_next(pCode){
  261. mui.openWindow({
  262. id: "choose_doctor.html",
  263. url: "../../tuandui/html/choose_doctor.html",
  264. extras: {
  265. teamCode: lastTeamId,
  266. sendCount:sendCount,
  267. patients:pCode,
  268. level: level,
  269. docCode:docCode,
  270. type:type
  271. }
  272. })
  273. }
  274. };
  275. // 处理流程开始
  276. new Promise(function(resolve, reject) {
  277. mui.plusReady(function() {
  278. resolve(true);
  279. });
  280. }).then(function() {
  281. // 获取基础环境信息
  282. return getBaseEnvPromise().then(function(env) {
  283. baseEnv = env;
  284. }).then(function() {
  285. // 获取登录基本信息
  286. baseInfo = getBaseInfo();
  287. // 绑定页面事件
  288. bindEvents();
  289. initTeams();
  290. initPatientGroupsList();
  291. })
  292. }).catch(function(e) {
  293. plus.nativeUI.closeWaiting();
  294. console && console.error(e);
  295. })