select-committee.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //选择居委会 jwcode基卫的code 有直接提交功能
  2. //<div id="committee"></div>
  3. var ddd = dialog({contentType:'load', skin:'bk-popup',content:'数据提交中'});
  4. function selectCommittee(){
  5. var content = '<div id="sheet" class="mui-popover mui-popover-bottom mui-popover-action">\
  6. <div id="sheet_committee" style="height:314px;background-color: #fff;position: relative;">\
  7. <div class="md-title">所属居委会</div>\
  8. <div class="md-bttn-true">确定</div>\
  9. <div class="md-bttn-false">取消</div>\
  10. <ul class="md-tag" id="showTitle"></ul>\
  11. <div id="district" class="mui-scroll-wrapper md-wrapper">\
  12. <div class="mui-scroll" style="width:100%!important">\
  13. <ul class="mui-table-view"></ul>\
  14. </div>\
  15. </div>\
  16. <div id="town" class="mui-scroll-wrapper md-wrapper c-hide">\
  17. <div class="mui-scroll" style="width:100%!important">\
  18. <ul class="mui-table-view"></ul>\
  19. </div>\
  20. </div>\
  21. <div id="village" class="mui-scroll-wrapper md-wrapper c-hide">\
  22. <div class="mui-scroll" style="width:100%!important">\
  23. <ul class="mui-table-view"></ul>\
  24. </div>\
  25. </div>\
  26. </div>\
  27. </div>';
  28. $('body').append(content)
  29. nextWork()
  30. function nextWork(){
  31. var $tit = $('#showTitle'),
  32. $sel0 = '<li class="active">请选择</li>',
  33. $sel1='',
  34. $sel2='',
  35. $list = $('.md-wrapper'),
  36. $true = $('.md-bttn-true'),
  37. $false = $('.md-bttn-false');
  38. var countryCode,
  39. jwcode,
  40. countryName;
  41. $('#selectType').click(function(){
  42. mui('#sheet').popover('show');
  43. if(!$tit.text().trim()){
  44. $tit.html($sel0);
  45. var data={};
  46. sendPost('patient/sign/getTownList', data, 'json', 'get', queryAddrFailed ,function(res){
  47. if(res.status == 200){
  48. var list="";
  49. $.map(res.data,function(item,index){
  50. list +='<li data-code='+item.code+'>'+item.name+'</li>';
  51. })
  52. $('#district').find('ul').empty().append(list);
  53. }else{
  54. queryAddrFailed(res);
  55. }
  56. })
  57. }
  58. $true.hide();
  59. $false.show();
  60. })
  61. //请求数据
  62. function queryAddrFailed(res) {
  63. if (res && res.msg) {
  64. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  65. } else {
  66. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据加载失败'}).show();
  67. }
  68. }
  69. mui('#village').scroll({
  70. bounce: false //是否启用回弹
  71. }).scrollTo(0,0,100);
  72. mui('#district').scroll({
  73. bounce: false //是否启用回弹
  74. })
  75. mui('#town').scroll({
  76. bounce: false //是否启用回弹
  77. }).scrollTo(0,0,100);
  78. //区
  79. $('#district').on('click','li',function(){
  80. var $this = $(this);
  81. changeList($('#town'),$this);
  82. $true.hide();
  83. $false.show();
  84. $sel1 = '<li>'+$this.text()+'</li>';
  85. $tit.html($sel1+$sel0);
  86. var data={
  87. town:$this.data('code')
  88. };
  89. sendPost('patient/sign/getStreetListByTown', data, 'json', 'get', queryAddrFailed ,function(res){
  90. if(res.status == 200){
  91. var list="";
  92. $.map(res.data,function(item,index){
  93. list +='<li data-code='+item.code+'>'+item.name+'</li>';
  94. })
  95. $('#town').find('ul').empty().append(list);
  96. }else{
  97. queryAddrFailed(res);
  98. }
  99. })
  100. })
  101. //街道
  102. $('#town').on('click','li',function(){
  103. var $this = $(this);
  104. changeList($('#village'),$this);
  105. $true.hide();
  106. $false.show();
  107. $sel2 = '<li>'+$this.text()+'</li>';
  108. $tit.html($sel1+$sel2+$sel0);
  109. var data={
  110. street:$this.data('code')
  111. };
  112. sendPost('patient/sign/getCountryListByStreet', data, 'json', 'get', queryAddrFailed ,function(res){
  113. if(res.status == 200){
  114. var list="";
  115. if(res.data.length>0){
  116. $.map(res.data,function(item,index){
  117. list +='<li data-jwcode='+item.jwCode+' data-code='+item.code+'>'+item.name+'</li>';
  118. })
  119. }else{
  120. }
  121. $('#village').find('ul').empty().append(list);
  122. }else{
  123. queryAddrFailed(res);
  124. }
  125. })
  126. })
  127. //居委会
  128. $('#village').on('click','li',function(){
  129. var $this = $(this);
  130. changeList($('#village'),$this);
  131. countryCode = $this.attr('data-code');
  132. jwcode = $this.attr('data-jwcode');
  133. countryName = $this.text();
  134. $true.show();
  135. $false.hide();
  136. })
  137. $tit.on('click','li',function(){
  138. var $this = $(this);
  139. if(! $this.hasClass('active')){
  140. $this.addClass('active').siblings().removeClass('active');
  141. $list.hide();
  142. $list.eq($this.index()).show();
  143. }
  144. })
  145. //取消
  146. $false.click(function(){
  147. mui('#sheet').popover('hide');
  148. })
  149. //确定
  150. $true.click(function(){
  151. mui('#sheet').popover('hide');
  152. ddd.show();
  153. var data={
  154. countryCode:countryCode
  155. };
  156. sendPost('patient/sign/updatePatientCountry', data, 'json', 'get',function(){
  157. ddd.close();
  158. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败'}).show();
  159. },function(res){
  160. if(res.status == 200){
  161. ddd.close();
  162. $('#committee').text(countryName);
  163. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存成功'}).show();
  164. }else{
  165. ddd.close();
  166. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败'}).show();
  167. }
  168. })
  169. })
  170. function changeList($next,$li){
  171. $li.addClass('active').siblings().removeClass('active');
  172. $list.hide();
  173. $next.show();
  174. }
  175. }
  176. }
  177. //清空选择
  178. function clearCommittee(){
  179. $('#showTitle').text('');
  180. $('.md-wrapper').hide();
  181. $('#district').show();
  182. }