application-msg-list.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. var loading = dialog({contentType:'load', skin:'bk-popup'}).show();
  2. var handing = dialog({contentType:'load', skin:'bk-popup', content: '正在处理中...'});
  3. var Request = GetRequest(),
  4. member = Request.member;
  5. var $listWrap = $('#listWrap');
  6. isRepresent(function(){
  7. initPage()
  8. })
  9. function getFamilyMesListPromise(code) {
  10. return new Promise(function(resolve, reject) {
  11. sendPost("patient/family/getFamilyMesList", {
  12. code: code
  13. } , "json", "POST",
  14. function failed (res) {
  15. loading.close();
  16. }, function(res) {
  17. resolve(res)
  18. });
  19. })
  20. }
  21. function addMemberByWxTempPromise(id,state) {
  22. handing.show();
  23. return new Promise(function(resolve, reject) {
  24. sendPost("patient/family/addMenberByWXTemp", {
  25. id: id,
  26. state: state
  27. } , "json", "POST",
  28. function failed (res) {
  29. handing.close();
  30. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  31. }, function(res) {
  32. handing.close();
  33. if(res.status == "200") {
  34. resolve(res)
  35. } else {
  36. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  37. }
  38. });
  39. })
  40. }
  41. function changeState(el,state) {
  42. var $el = $(el),
  43. $btns = $el.closest('.btn-menu'),
  44. $li = $el.closest('.c-list'),
  45. $agree = $li.find('.state-agree'),
  46. $reject = $li.find('.state-reject');
  47. $btns.hide();
  48. if(state == "1") {
  49. $agree.removeClass('c-hide');
  50. } else if((state == "2")){
  51. $reject.removeClass('c-hide');
  52. }
  53. }
  54. function bindEvents() {
  55. $listWrap.on('click','.btn-reject',function(){
  56. var self = this;
  57. var id = $(this).closest('.c-list').attr('data-id');
  58. addMemberByWxTempPromise(id,2)
  59. .then(function() {
  60. changeState(self,2)
  61. })
  62. }).on('click','.btn-agree',function(){
  63. var self = this;
  64. var id = $(this).closest('.c-list').attr('data-id');
  65. addMemberByWxTempPromise(id,1)
  66. .then(function() {
  67. changeState(self,1)
  68. })
  69. })
  70. }
  71. function initListPromise() {
  72. return getFamilyMesListPromise(member)
  73. .then(function(res) {
  74. loading.close();
  75. if(res.status == "200") {
  76. if(res.data.mes && res.data.mes.length) {
  77. var html = template('li_tmpl',{list: res.data.mes });
  78. $listWrap.html(html);
  79. } else {
  80. $('#no_result_wrap').show()
  81. }
  82. } else {
  83. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  84. }
  85. })
  86. }
  87. function initPage() {
  88. initListPromise()
  89. .then(function() {
  90. bindEvents();
  91. })
  92. .catch(function(e){
  93. loading.close();
  94. console && console.error(e);
  95. });
  96. }
  97. template.helper("setPhoto", function(p) {
  98. return getImgUrl(p);
  99. });