zhuanyijumin.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. allGroupMember=[],//所有组的成员
  19. allPatient,//所有成员的patint
  20. groupIdFornum;
  21. // 获取登录相关信息
  22. var getBaseInfo = function() {
  23. var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
  24. self = plus.webview.currentWebview();
  25. docCode = self.docCode;
  26. level = self.level;
  27. type = self.type;
  28. return {
  29. userAgent: userAgent,
  30. teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
  31. }
  32. },
  33. // 获取基础环境信息
  34. getBaseEnvPromise = function () {
  35. var env = {
  36. webview: plus&&plus.webview.currentWebview()
  37. };
  38. return Promise.resolve().then(function(res) {
  39. return env;
  40. });
  41. },
  42. // 初始化选择团队
  43. initTeams = function (){
  44. // lastTeamId = self.teamCode;
  45. //从消息列表过来的处理是没有团队code,能够分配健管师的只能是团队长 20171110 rl update
  46. if(self.teamCode){
  47. lastTeamId = self.teamCode;
  48. }else{
  49. var teams = baseInfo.teamInfo.data,
  50. len = teams.length;
  51. for(i=0; i<len; i++){
  52. if(baseInfo.userAgent.uid == teams[i].leaderCode){
  53. lastTeamId = teams[i].id;
  54. }
  55. }
  56. }
  57. $('#sortName').text($('#sortList').find('li').eq(typeId-1).find('a').text());//排列初始值
  58. $('.notice-tip').text('服务类型分组仅支持'+type+'2017年签约居民,如需为2016年签约居民进行操作,请使用健康情况、疾病类型、团队标签或所属居委会分组,或搜索居民单独'+type)
  59. },
  60. // 初始化画面患者分组列表
  61. initPatientGroupsList = function() {
  62. if(!lastTeamId){ return; }
  63. plus.nativeUI.showWaiting();
  64. var url = type == "分配" ? 'doctor/family_contract/findNoHealthSignFamilyHealthNum' : '/doctor/family_contract/getPatientLables' ;
  65. getReqPromise(url,{labelType: typeId, teamCode: lastTeamId,oldDoctorCode:docCode,level:level})
  66. .then(function(res) {
  67. if(res.status == 200) {
  68. console.log(res)
  69. allGroupMember = []
  70. allCount= 0;
  71. groupData = res.data.patients;//储存分组的数据
  72. if(groupData){
  73. _.map(groupData,function(item){
  74. allGroupData.push(item.label);
  75. allGroupCode.push(item.labelCode);
  76. if(item.ps.length>0){
  77. allGroupMember = allGroupMember.concat(item.ps);
  78. }
  79. })
  80. allGroupCode = _.uniq(allGroupCode);
  81. console.log(allGroupMember.length)
  82. allPatient = allGroupMember.map(function(v){ //将所有的重复的paitent取出来
  83. return v.patient
  84. }).filter(function(v,i,arr){
  85. return arr.indexOf(v) === i //过滤掉相同的paitent
  86. }).map(function(v){
  87. return {
  88. use:false,
  89. patient:v //增加use属性准备对象去重
  90. }
  91. })
  92. console.log(allPatient);
  93. var filterArr = [];
  94. allGroupMember.filter(function(value,index,arr){
  95. allPatient.map(function(v,i,arr){
  96. if(value.patient == v.patient && v.use ==false){ //
  97. if(value.photo && value.photo.indexOf('../') == -1){
  98. value.photo = getImgUrl(value.photo);
  99. }
  100. if(value.age <=0){
  101. value.age ='<1'
  102. }
  103. filterArr.push(value);
  104. allPatient[i].use =true;
  105. }
  106. })
  107. });
  108. allGroupMember = filterArr;
  109. allCount+=allGroupMember.length;
  110. // allCount = allGroupCode.length;
  111. }
  112. if(typeId = 3){
  113. var other = _.find(groupData, function(v) {
  114. return v.label == "其他疾病"
  115. });
  116. var arr = _.filter(groupData, function(v) {
  117. return v.label != "其他疾病"
  118. }) || [];
  119. other && arr.push(other);
  120. groupData = arr;
  121. }
  122. var html = template("groups_tmpl", {list: groupData});
  123. $('#groupList').empty().append(html);
  124. countHeight(groupData);
  125. changeGroupNum($('#groupList').find('li').eq(0));
  126. // mui('#scrol1').scroll({
  127. // bounce: false //是否启用回弹
  128. // }).scrollTo(0,0,100);
  129. mui('#scrol2').scroll({
  130. bounce: false //是否启用回弹
  131. }).scrollTo(0,0,100);
  132. plus.nativeUI.closeWaiting();
  133. }
  134. if(res.status == -1){
  135. plus.nativeUI.closeWaiting();
  136. mui.toast('数据获取失败');
  137. }
  138. }).catch(function(e){ console && console.error(e) });;
  139. },
  140. countHeight = function(data){
  141. var num = data.length;
  142. if(num>5){
  143. $('#sheet3_area').css('height','276px');
  144. }else{
  145. $('#sheet3_area').css('height',46*(num+1));
  146. }
  147. },
  148. changeGroupNum = function(obj){
  149. var groupNum,perGroup,
  150. groupId = obj.data('id');//储存组的位置
  151. groupIdFornum = groupId;
  152. $('#groupName').text(obj.find('a').text());
  153. //groupId=0为全部分组
  154. if(groupId>0){
  155. groupNum = groupData[groupId-1].ps.length;
  156. groupName = groupData[groupId-1].label;
  157. perGroup = groupData[groupId-1].ps;
  158. allGroupMember = allGroupMember.map(function(value){ //过滤掉其他组的 needHide=true
  159. var needHide =true;
  160. perGroup = perGroup.map(function(v){
  161. if(v.patient == value.patient){
  162. v.isCheck =value.isCheck
  163. needHide = false
  164. }
  165. return v
  166. })
  167. value.needHide =needHide;
  168. return value
  169. })
  170. }else{
  171. allGroupMember = allGroupMember.map(function(v){
  172. v.needHide = false;
  173. return v
  174. })
  175. groupNum = allCount;
  176. groupName = '';
  177. perGroup = allGroupMember;
  178. }
  179. refreshCount();
  180. var html = template("num_tmpl",{data:groupNum});
  181. $('#numList').empty().append(html);
  182. $('#peopleNum').text($('#numList').find('li').eq(0).find('a').text());
  183. var isAllCheck = (groupNum == sendCount);
  184. var html2 = template("members_tmpl",{data:{data:perGroup,allChecked:isAllCheck}});
  185. $('#memberList').empty().append(html2);
  186. mui('.mui-scroll-wrapper').scroll({
  187. deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006
  188. });
  189. },
  190. changePeopleNum = function(obj){
  191. $('#peopleNum').text(obj.find('a').text());
  192. var filterNumber = obj.data('num');
  193. if(groupIdFornum>0){
  194. perGroup = groupData[groupIdFornum-1].ps;
  195. perGroup = perGroup.map(function(v){
  196. allGroupMember.map(function(value){
  197. if(v.patient == value.patient){
  198. v.isCheck =value.isCheck;
  199. inAllGroup =true;
  200. v.needHide= value.needHide;
  201. }
  202. })
  203. return v
  204. })
  205. }else{
  206. perGroup = allGroupMember;
  207. }
  208. perGroup = perGroup.map(function(v,i,arr){
  209. if(i+1 >filterNumber){
  210. v.needHide = true
  211. }
  212. else{
  213. v.needHide = false
  214. }
  215. return v
  216. })
  217. allGroupMember = allGroupMember.map(function(value){
  218. perGroup.map(function(v,i,arr){
  219. if(v.patient == value.patient){
  220. value.needHide = v.needHide;
  221. }
  222. })
  223. return value
  224. })
  225. refreshCount();
  226. var isAllCheck = (filterNumber == sendCount);
  227. var html2 = template("members_tmpl",{data:{data:perGroup,allChecked:isAllCheck}});
  228. $('#memberList').empty().append(html2);
  229. mui('.mui-scroll-wrapper').scroll({
  230. deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006
  231. });
  232. if(sendCount>0){
  233. $('#sendBtn').addClass('active');//变色
  234. }else{
  235. $('#sendBtn').removeClass('active');
  236. }
  237. },
  238. refreshCount =function (){
  239. sendCount = allGroupMember.filter(function (v){
  240. return v.isCheck && !v.needHide
  241. }).length
  242. $sendCount.text(sendCount);//发送人数
  243. },
  244. // 绑定页面事件
  245. bindEvents = function () {
  246. $('#sortList').on('click','.j-choose-name',function(){
  247. var $this = $(this);
  248. $('#sortName').text($this.find('a').text());
  249. typeId = $this.data('type');
  250. mui('#sheet2').popover('toggle');
  251. initPatientGroupsList();
  252. $sendCount.text(0);
  253. sendCount=0;
  254. groupId = 0;
  255. allGroupData=[];//所有组的数据信息
  256. allGroupCode=[];
  257. })
  258. $('#groupList').on('click','.j-choose-name',function(){
  259. var $this = $(this);
  260. changeGroupNum($this);
  261. mui('#sheet3').popover('toggle');
  262. })
  263. $('#numList').on('click','.j-choose-name',function(){
  264. var $this = $(this);
  265. changePeopleNum($this);
  266. mui('#sheet4').popover('toggle');
  267. })
  268. $('#memberList').on('click','.memberClick',function(){
  269. var $this = $(this),
  270. memberObj = $('.memberClick');
  271. memberId = $this.data('id'),//储存组的位置
  272. value = $this.find('input').prop('checked'),
  273. patient =$this.data('code');
  274. if(memberId>0){
  275. allGroupMember = allGroupMember.map(function(v){
  276. if(v.patient == patient){
  277. if(value){
  278. v.isCheck =true
  279. }
  280. else{
  281. v.isCheck=null
  282. }
  283. }
  284. return v
  285. })
  286. } else{
  287. $("input[name='memberList']:checkbox").each(function() {
  288. $(this).prop("checked", value);
  289. });
  290. allGroupMember = allGroupMember.map(function(v){
  291. if(value){
  292. v.isCheck =true
  293. }
  294. else{
  295. v.isCheck=null
  296. }
  297. return v
  298. })
  299. }
  300. refreshCount();
  301. })
  302. $searchbarInput.on('click',function() {
  303. mui.openWindow({
  304. id: "zhuanyijumin_search",
  305. url: "zhuanyijumin_search.html",
  306. extras: {
  307. type:type,
  308. docCode:docCode,
  309. level:level,
  310. lastTeamId:lastTeamId,
  311. }
  312. });
  313. })
  314. $("#sendBtn").on('click',function(){
  315. if(sendCount<=0){
  316. mui.toast('请至少选一个居民!');
  317. return;
  318. }
  319. plus.nativeUI.showWaiting();
  320. //取居民code
  321. var pCode=[],
  322. patientArr=[];
  323. allGroupMember.map(function(v){
  324. if(v.isCheck && !v.needHide){
  325. pCode.push(v.patient)
  326. }
  327. })
  328. pCode = pCode.join(',');
  329. if(type == '转移'){
  330. sendPost("/doctor/consult/getConsultByPatientAndDoctor", {patientCode: pCode, doctor: docCode},null, function(res){
  331. var tem = {};
  332. console.log(res)
  333. if(res.length==0){
  334. to_next(pCode);
  335. } else if(res.length == sendCount){
  336. console.log(res)
  337. plus.nativeUI.closeWaiting();
  338. mui.confirm("对不起,您选择的居民均有尚未结束的健康咨询,无法继续转移。", "提示", ["我知道了"], function(e){})
  339. return;
  340. } else if(res.length <= 3 ){
  341. tem = getCanTrans(pCode, res);
  342. console.log(tem);
  343. plus.nativeUI.closeWaiting();
  344. mui.confirm("居民"+ tem.names + "尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){
  345. if(e.index == 0){
  346. to_next(tem.canPati);
  347. cancleSel(res);
  348. }
  349. })
  350. } else if(res.length < sendCount){
  351. tem = getCanTransByCode(pCode, res);
  352. plus.nativeUI.closeWaiting();
  353. mui.confirm("选中居民中有"+ res.length + "人,尚有未结束的健康咨询,本次只可转移其余居民,是否继续?", "提示", ["继续转移", "不了,谢谢"], function(e){
  354. if(e.index == 0){
  355. to_next(tem.canPati);
  356. cancleSel(res);
  357. }
  358. })
  359. }
  360. },'POST',300000)
  361. }else{
  362. to_next(pCode)
  363. return;
  364. }
  365. })
  366. function getCanTrans(pCode, notCodes){
  367. var canPati = [];
  368. var names = [];
  369. var allCode = pCode.split(',');
  370. $.each(allCode, function(i, v) {
  371. var has = false;
  372. $.each(notCodes, function(n, m) {
  373. if(v == m){
  374. has = true;
  375. var obj = _.find(allGroupMember, function(o){ return o.patient== m; });
  376. names.push(obj.name);
  377. }
  378. });
  379. if(!has){
  380. canPati.push(v);
  381. }
  382. });
  383. return {canPati: canPati.join(","), names: names.join(",")}
  384. }
  385. function getCanTransByCode(pCode, notCodes){
  386. var canPati = [];
  387. var allCode = pCode.split(',');
  388. $.each(allCode, function(i, v) {
  389. var has = false;
  390. $.each(notCodes, function(n, m) {
  391. if(v == m){
  392. has = true;
  393. }
  394. });
  395. if(!has){
  396. canPati.push(v);
  397. }
  398. });
  399. return {canPati: canPati.join(",")}
  400. }
  401. function cancleSel(notCodes){
  402. sendCount = sendCount*1 - (notCodes.length)*1
  403. }
  404. function to_next(pCode){
  405. mui.openWindow({
  406. id: "choose_doctor.html",
  407. url: "../../tuandui/html/choose_doctor.html",
  408. extras: {
  409. teamCode: lastTeamId,
  410. sendCount:sendCount,
  411. patients:pCode,
  412. level: level,
  413. docCode:docCode,
  414. type:type
  415. }
  416. })
  417. }
  418. };
  419. // 处理流程开始
  420. new Promise(function(resolve, reject) {
  421. mui.plusReady(function() {
  422. resolve(true);
  423. });
  424. }).then(function() {
  425. // 获取基础环境信息
  426. return getBaseEnvPromise().then(function(env) {
  427. baseEnv = env;
  428. }).then(function() {
  429. // 获取登录基本信息
  430. baseInfo = getBaseInfo();
  431. // 绑定页面事件
  432. bindEvents();
  433. initTeams();
  434. initPatientGroupsList();
  435. })
  436. }).catch(function(e) {
  437. plus.nativeUI.closeWaiting();
  438. console && console.error(e);
  439. })