manyidu.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var dd = dialog({contentType:'load', skin:'bk-popup', content:'发送中...'});
  3. var Request = new Object();
  4. Request = GetRequest();
  5. var userAgent = window.localStorage.getItem(agentName);
  6. var toUser = Request["toUser"];
  7. var toName = decodeURIComponent(Request["toName"]);
  8. var openid = Request["openid"];
  9. var represented = Request["represented"];
  10. var consult = Request["consult"];
  11. var pagetype = 0;
  12. $(function() {
  13. if(!userAgent) {
  14. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  15. window.location.href = server + "wx/html/home/html/login.html?type=" + pagetype + "&openid=" + openid;
  16. return false;
  17. }
  18. var newUaObj = JSON.parse(window.localStorage.getItem(agentName))
  19. //判断关系
  20. function hasFamilyRelation(a,b){
  21. return new Promise(function(resolve, reject) {
  22. var data={
  23. patient:a,
  24. familyMember:b
  25. }
  26. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  27. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  28. }, function(res){
  29. if(res.status == 200) {
  30. window.localStorage.setItem('nowPatientName',res.data.name);
  31. resolve(res)
  32. }else if(res.status == 100) {
  33. dialog({
  34. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  35. okValue:'切换账号',
  36. ok: function() {
  37. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  38. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  39. },
  40. cancelValue: '我不看了',
  41. cancel: function () {
  42. wx.closeWindow();
  43. }
  44. }).showModal();
  45. }else{
  46. relogin();
  47. }
  48. })
  49. })
  50. }
  51. //重新登录操作
  52. function relogin(){
  53. dialog({
  54. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  55. okValue:'切换账号',
  56. ok: function() {
  57. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  58. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
  59. },
  60. cancelValue: '我不看了',
  61. cancel: function () {
  62. wx.closeWindow();
  63. }
  64. }).showModal();
  65. }
  66. //保存信息
  67. function saveUserInfo(a,b){
  68. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  69. newUaObj.represented = represented;
  70. window.localStorage.setItem(agentName,JSON.stringify(newUaObj));
  71. })
  72. }
  73. function initFamilyData () {
  74. //从微信模板消息进入
  75. if(represented && userAgent && toUser){
  76. if(toUser == represented){
  77. saveUserInfo(represented,newUaObj.uid)
  78. }else if(toUser != represented && represented == newUaObj.uid){
  79. //本人代理
  80. saveUserInfo(represented,newUaObj.uid)
  81. }else if(toUser != represented && toUser == newUaObj.uid){
  82. //需要判定关系 200有授权 100家人 1无关系
  83. saveUserInfo(represented,newUaObj.uid)
  84. }else{
  85. //重新登录
  86. relogin();
  87. }
  88. }
  89. }
  90. initFamilyData();
  91. var doctorPar,//参与咨询医生信息
  92. $starListGroup = $('#manValueList'),
  93. reqUrl = '',
  94. evaluateKind = 1,//实名类型
  95. finish = 1;//提交后标志
  96. //参与者
  97. var data = {};
  98. data.consult = consult;
  99. data.page = 1;
  100. data.pagesize = 1;
  101. sendPost('patient/consult/loglist', data, 'json', 'GET', function(){
  102. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'请求数据失败'}).show();
  103. }, function(res){
  104. if (res.status == 200) {
  105. res = res.list;
  106. var arr = [];//储存参与咨询的医生
  107. for(var k in res.users){
  108. if(res.users[k].is_patient == 0){
  109. arr.push(res.users[k])
  110. }
  111. }
  112. doctorPar=arr;
  113. nextWork();
  114. }else{
  115. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'加载数据失败'}).show();
  116. }
  117. })
  118. function nextWork(){
  119. if(doctorPar){
  120. for(var k in doctorPar){
  121. if(doctorPar[k].level == 1){
  122. doctorPar[k].levelName = '专科医生'
  123. }
  124. if(doctorPar[k].level == 2){
  125. doctorPar[k].levelName = '全科医生'
  126. }
  127. if(doctorPar[k].level == 3){
  128. doctorPar[k].levelName = '健康管理师'
  129. }
  130. }
  131. }
  132. queryOldData();
  133. bindEvents();
  134. }
  135. function bindEvents(){
  136. //文本框
  137. $starListGroup.on('keyup',"textarea",function(){
  138. var $this = $(this);
  139. var count = $this.val().length;
  140. $this.parent('.text-input').find('.text_count').text(count);
  141. });
  142. //匿名
  143. $('.j-niming').on('click',function(){
  144. if(finish == 1){
  145. var $this = $(this).parent();
  146. if($this.hasClass('active')){
  147. $this.removeClass('active');
  148. evaluateKind = 1;
  149. }else{
  150. $this.addClass('active');
  151. evaluateKind = 2;
  152. }
  153. }
  154. })
  155. //贴标签展开和关闭
  156. $starListGroup.on('click','.small-title',function(){
  157. if(finish == 1){
  158. var $this = $(this);
  159. if($this.hasClass('active')){
  160. $this.removeClass('active');
  161. $this.siblings('.j-tag-detail').animate({height:'hide'},300)
  162. }else{
  163. $this.addClass('active');
  164. $this.siblings('.j-tag-detail').animate({height:'show'},300)
  165. }
  166. }
  167. })
  168. //点击显示星星
  169. $starListGroup.on('click','.star-lists .one-star',function(){
  170. var $this = $(this);
  171. var $parent = $this.parent();
  172. if(finish == 1){
  173. $parent.find('.one-star').removeClass('active')
  174. for(var i=0;i<=$this.index();i++){
  175. $parent.find('.one-star').eq(i).addClass('active');
  176. }
  177. }
  178. })
  179. //贴上功能
  180. $starListGroup.on('click','.j-submit',function(){
  181. if(finish == 1){
  182. var $this = $(this);
  183. var $input = $this.siblings('.input').find('input');
  184. var val = $input.val().trim();
  185. if($this.parent().siblings('ul.tag-list').find('li.active').length > 3){
  186. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'最多只能选择4个标签'}).show();
  187. }else{
  188. if(val){
  189. if(val.length>8){
  190. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'自定义标签最多8个字'}).show();
  191. $input.blur();
  192. return;
  193. }else{
  194. var html = '<li class="active">'+val+'</li>';
  195. $this.parent().siblings('ul.tag-list').append(html);
  196. $input.val('');
  197. $input.blur();
  198. }
  199. }
  200. }
  201. }
  202. })
  203. //点击标签选取
  204. $starListGroup.on('click','ul.tag-list li',function(){
  205. if(finish == 1){
  206. var $this = $(this);
  207. if($this.hasClass('active')){
  208. $this.removeClass('active');
  209. }else{
  210. if($this.closest('ul.tag-list').find('li.active').length > 3){
  211. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'最多只能选择4个标签'}).show();
  212. }else{
  213. $this.addClass('active');
  214. }
  215. }
  216. }
  217. })
  218. $('#commit').click(function(){
  219. var data = {},
  220. label = [],
  221. evaluate = [],
  222. evaluateScore = [],
  223. $one = $starListGroup.find('.j-section');
  224. for(var i=0;i< $one.length;i++){
  225. var $ul = $one.eq(i).find('.star-lists').find('ul.list li.active').length;//该医生是否评价完整
  226. var remarkValue = $one.eq(i).find('.text-input textarea').val().trim();
  227. if($ul >0){
  228. for(var j=0;j<3;j++){
  229. var val = $one.eq(i).find('.star-lists').eq(j).find('ul.list li.active').length;
  230. if(!val){
  231. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'请完善医生评分'}).show();
  232. return ;
  233. }
  234. if(val <= 3){
  235. var isNimimg = $('.ni-select').hasClass('active');
  236. if(isNimimg){
  237. dialog({
  238. content:'为了帮助医生及时发现服务中存在的问题并作出改正,当您给出三星及以下评价时,需要实名评价哦~',
  239. okValue:'确定',
  240. ok: function() {
  241. // wx.closeWindow();
  242. }
  243. }).showModal();
  244. return ;
  245. }
  246. }
  247. if(val <= 4){
  248. if(!remarkValue){
  249. dialog({
  250. content:'为帮助医生及时发现服务存在的问题,当您给出四星及以下评价时,需要说明对医生服务的意见哦~',
  251. okValue:'确定',
  252. ok: function() {
  253. // wx.closeWindow();
  254. }
  255. }).showModal();
  256. return ;
  257. }
  258. }
  259. }
  260. }else{
  261. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'请完善医生评分'}).show();
  262. return ;
  263. }
  264. }
  265. dd.showModal();
  266. for(var i=0;i< $one.length;i++){
  267. for(var j=0;j<3;j++){
  268. var obj = {};
  269. obj['doctor'] = $one.eq(i).find('.down-sec').data('code');
  270. obj['score'] = $one.eq(i).find('.star-lists').eq(j).find('ul.list li.active').length*20;
  271. obj['type'] = evaluateKind;
  272. obj['evaluateType'] = j+1;//匿名评价类型
  273. evaluate.push(obj);
  274. }
  275. var that = $one.eq(i).find('.j-nosel .tag-list li.active');
  276. if(that.length >0){
  277. for(var z=0;z<that.length;z++){
  278. var obj = {};
  279. obj['doctor'] = $one.eq(i).find('.down-sec').data('code');
  280. obj['content'] = that.eq(z).text().trim();
  281. label.push(obj);
  282. }
  283. }
  284. var $text = $one.eq(i).find('.text-input textarea');
  285. var obj = {};
  286. obj['doctor'] = $one.eq(i).find('.down-sec').data('code');
  287. obj['remark'] = $text.val().trim();
  288. evaluateScore.push(obj);
  289. }
  290. data['consult'] = consult;
  291. data['label'] = label;
  292. data['evaluateScore'] = evaluateScore;
  293. data['evaluate'] = evaluate;
  294. var params = {evaluate:JSON.stringify(data)};
  295. sendPost(reqUrl, params, 'json', 'post', submitFailed, submitSuccess);
  296. })
  297. }
  298. //点击修改按钮
  299. $('#revise').on('click',function(){
  300. revising()
  301. reqUrl = 'patient/consult/evaluate/update';
  302. })
  303. //点击修改评价的样式
  304. function revising(){
  305. $('#again_header').show();
  306. $('#yes_header').hide();
  307. $('#no_header').hide();
  308. $('#commit').show();//按钮
  309. $('#revise').hide();
  310. finish = 1;
  311. showTag2();
  312. showTextarea2();
  313. $('body').scrollTop(0);
  314. }
  315. //点击修改显示标签
  316. function showTag2(){
  317. var $one = $starListGroup.find('.j-section');
  318. for(var i=0;i<$one.length;i++){
  319. var $ul = $one.eq(i).find('.j-hassel .tag-list');
  320. var $li = $ul.find('li.active');
  321. var num = $li.length;
  322. var $ul2 = $one.eq(i).find('.j-nosel .tag-list');
  323. var $li2 = $ul2.find('li');
  324. if(num>0){
  325. for(var j=0;j<num;j++){
  326. var yes = 0;
  327. var name = $li.eq(j).text();
  328. for(var z=0;z<$li2.length;z++){
  329. if($li2.eq(z).text() == name){
  330. $li2.eq(z).addClass('active');
  331. yes = 1;
  332. }
  333. }
  334. if(yes == 0){
  335. var html = '<li class="active">'+name+'</li>';
  336. $ul2.append(html);
  337. }
  338. }
  339. }
  340. }
  341. $('.j-nosel').show();
  342. $('.j-hassel').hide();
  343. }
  344. //点击修改显示文本
  345. function showTextarea2(){
  346. var $one = $starListGroup.find('.j-section');
  347. for(var i=0;i<$one.length;i++){
  348. var $ul = $one.eq(i).find('.text-input textarea'),
  349. $ul2 = $one.eq(i).find('.show-word'),
  350. $val = $ul2.html();
  351. if($val){
  352. $ul.val($val);
  353. $ul.parent('.text-input').find('.text_count').text($ul.val().length);
  354. }
  355. }
  356. $('.text-input').show();
  357. $('.show-word').hide();
  358. }
  359. //正要评价的样式
  360. function evaluating(){
  361. finish = 1;
  362. $('#show_text').show();
  363. $('#no_header').show();
  364. }
  365. //已经评价过的样式
  366. function evaluated(){
  367. finish = 0;
  368. $('#show_text').show();
  369. $('#yes_header').show();
  370. $('.j-nosel').hide();
  371. $('.text-input').hide();
  372. $('.show-word').show();
  373. hasName();
  374. $('#revise').show();
  375. $('#commit').hide();
  376. $('.small-title').removeClass('active');
  377. $('.j-tag-detail').hide();
  378. }
  379. //提交评价后的样式
  380. function committed(){
  381. finish = 0;
  382. localStorage.setItem("evaluate",1);
  383. $('#commit').hide();//按钮
  384. $('#revise').show();
  385. $('#yes_header').show();
  386. $('#again_header').hide();
  387. $('#no_header').hide();
  388. $('.small-title').removeClass('active');
  389. $('.j-tag-detail').hide();
  390. showTag();
  391. showTextarea();
  392. $('body').scrollTop(0);
  393. }
  394. //实匿名样式切换
  395. function hasName(){
  396. if(evaluateKind == 2){
  397. $('.ni-select').addClass('active');
  398. }else{
  399. $('.ni-select').removeClass('active');
  400. }
  401. }
  402. function submitFailed(res) {
  403. dd.close();
  404. if (res && res.msg) {
  405. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  406. } else {
  407. dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content:'提交失败'}).show();
  408. }
  409. }
  410. function submitSuccess(res) {
  411. dd.close();
  412. if(res.status==200){
  413. dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content:'提交成功'}).show();
  414. committed();
  415. }else{
  416. if (res && res.msg) {
  417. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  418. }
  419. }
  420. }
  421. //提交后显示标签
  422. function showTag(){
  423. var $one = $starListGroup.find('.j-section');
  424. for(var i=0;i<$one.length;i++){
  425. var $ul = $one.eq(i).find('.j-nosel .tag-list');
  426. var $li = $ul.find('li.active');
  427. var num = $li.length;
  428. var $ul2 = $one.eq(i).find('.j-hassel .tag-list');
  429. if(num>0){
  430. var html='';
  431. for(var j=0;j<num;j++){
  432. html +='<li class="active">'+$li.eq(j).text()+'</li>'
  433. }
  434. $ul2.html(html);
  435. $one.eq(i).find('.j-hassel').show();
  436. }
  437. }
  438. $('.j-nosel').hide();
  439. }
  440. //提交后显示文本
  441. function showTextarea(){
  442. var $one = $starListGroup.find('.j-section');
  443. for(var i=0;i<$one.length;i++){
  444. var $ul = $one.eq(i).find('.text-input'),
  445. $val = $ul.find('textarea').val().trim(),
  446. $ul2 = $one.eq(i).find('.show-word');
  447. if($val){
  448. $ul2.html($val);
  449. $one.eq(i).find('.show-word').show();
  450. }
  451. }
  452. $('.text-input').hide();
  453. }
  454. //请求数据看是否评价
  455. function queryOldData(){
  456. var params= {};
  457. params.consult = consult;
  458. sendPost('patient/consult/evaluate/list', params, 'json', 'get', queryFailed, querySuccess);
  459. function queryFailed(res) {
  460. if (res && res.msg) {
  461. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  462. } else {
  463. dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content:'请求数据失败'}).show();
  464. }
  465. }
  466. function querySuccess(res) {
  467. if(res.status==200){
  468. //显示内容
  469. var html = template("star_list_temp", {data: doctorPar});
  470. $starListGroup.append(html);
  471. var list = res.data['evaluate'];
  472. var labelTag = res.data['label'];
  473. var content = res.data['evaluateScore'];
  474. if(list && list.length>0){
  475. for(var i=0;i<$('.j-section').length;i++){
  476. for(var j=0;j<list.length;j++){
  477. if($('.down-sec').eq(i).data('code') == list[j].doctor){
  478. //1专业能力,2服务态度,3回复速度
  479. if(list[j].evaluateType == 1){
  480. //临时判断实匿名
  481. evaluateKind = list[j].type;
  482. var num = Math.floor(list[j].score/20);
  483. for(var q=0;q<num;q++){
  484. $('.j-section').eq(i).find('.star-lists').eq(0).find('.one-star').eq(q).addClass('active');
  485. }
  486. }
  487. if(list[j].evaluateType == 2){
  488. var num = Math.floor(list[j].score/20);
  489. for(var q=0;q<num;q++){
  490. $('.j-section').eq(i).find('.star-lists').eq(1).find('.one-star').eq(q).addClass('active');
  491. }
  492. }
  493. if(list[j].evaluateType == 3){
  494. var num = Math.floor(list[j].score/20);
  495. for(var q=0;q<num;q++){
  496. $('.j-section').eq(i).find('.star-lists').eq(2).find('.one-star').eq(q).addClass('active');
  497. }
  498. }
  499. }
  500. }
  501. //显示标签
  502. if(labelTag && labelTag.length>0){
  503. var that = $('.j-hassel').eq(i).find('.tag-list');
  504. for(var z=0;z<labelTag.length;z++){
  505. if($('.down-sec').eq(i).data('code') == labelTag[z].doctor){
  506. var html = '<li class="active">'+labelTag[z].content+'</li>';
  507. that.append(html);
  508. }
  509. }
  510. $('.j-section').eq(i).find('.j-hassel').show();
  511. }
  512. //显示意见内容
  513. if(content && content.length>0){
  514. var that = $('.j-section').eq(i).find('.show-word');
  515. for(var z=0;z<content.length;z++){
  516. if($('.down-sec').eq(i).data('code') == content[z].doctor){
  517. that.html(content[z].remark);
  518. }
  519. }
  520. }
  521. }
  522. evaluated();
  523. reqUrl = 'patient/consult/evaluate/update';
  524. }else{//未评价
  525. evaluating();
  526. reqUrl = 'patient/consult/evaluate/save';
  527. }
  528. }else{
  529. queryFailed(res);
  530. }
  531. }
  532. }
  533. })
  534. template.helper('getPhoto', function(str){
  535. return getImgUrl(str);
  536. })