select-committee.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //选择居委会 jwcode为基卫
  2. //调用语句
  3. //<input id="committee" data-jwcode="" data-code="" value="" type="text" readonly="readonly" placeholder="请选择您的所属居委会"/>
  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><div class="md-bttn-true">确定</div><div class="md-bttn-false">取消</div>\
  8. <ul class="md-tag" id="showTitle"></ul>\
  9. <div id="district" class="mui-scroll-wrapper md-wrapper">\
  10. <div class="mui-scroll" style="width:100%!important"><ul class="mui-table-view"></ul></div>\
  11. </div>\
  12. <div id="town" class="mui-scroll-wrapper md-wrapper c-hide">\
  13. <div class="mui-scroll" style="width:100%!important"><ul class="mui-table-view"></ul></div>\
  14. </div>\
  15. <div id="village" class="mui-scroll-wrapper md-wrapper c-hide">\
  16. <div class="mui-scroll" style="width:100%!important"><ul class="mui-table-view"></ul></div>\
  17. </div>\
  18. </div> \
  19. </div>';
  20. $('body').append(content)
  21. nextWork()
  22. function nextWork(){
  23. var $tit = $('#showTitle'),
  24. $sel0 = '<li class="active">请选择</li>',
  25. $sel1='',
  26. $sel2='',
  27. $list = $('.md-wrapper'),
  28. $true = $('.md-bttn-true'),
  29. $false = $('.md-bttn-false');
  30. var countryCode,
  31. jwcountryCode,
  32. countryName;
  33. $('#selectType').click(function(){
  34. mui('#sheet').popover('show');
  35. if(!$tit.text().trim()){
  36. $tit.html($sel0);
  37. var data={};
  38. sendPost('doctor/sign/getTownList', data, queryAddrFailed ,function(res){
  39. if(res.status == 200){
  40. var list="";
  41. $.map(res.data,function(item,index){
  42. list +='<li data-code='+item.code+'>'+item.name+'</li>';
  43. })
  44. $('#district').find('ul').empty().append(list);
  45. }else{
  46. queryAddrFailed(res);
  47. }
  48. })
  49. }
  50. $true.hide();
  51. $false.show();
  52. })
  53. //请求数据
  54. function queryAddrFailed(res) {
  55. if (res && res.msg) {
  56. mui.toast(res.msg);
  57. } else {
  58. mui.toast('数据加载失败');
  59. }
  60. }
  61. mui('#village').scroll({
  62. bounce: false //是否启用回弹
  63. }).scrollTo(0,0,100);
  64. mui('#district').scroll({
  65. bounce: false //是否启用回弹
  66. })
  67. mui('#town').scroll({
  68. bounce: false //是否启用回弹
  69. }).scrollTo(0,0,100);
  70. //区
  71. $('#district').on('click','li',function(){
  72. var $this = $(this);
  73. changeList($('#town'),$this);
  74. $true.hide();
  75. $false.show();
  76. $sel1 = '<li>'+$this.text()+'</li>';
  77. $tit.html($sel1+$sel0);
  78. var data={
  79. town:$this.data('code')
  80. };
  81. sendPost('doctor/sign/getStreetListByTown', data, queryAddrFailed ,function(res){
  82. if(res.status == 200){
  83. var list="";
  84. $.map(res.data,function(item,index){
  85. list +='<li data-code='+item.code+'>'+item.name+'</li>';
  86. })
  87. $('#town').find('ul').empty().append(list);
  88. }else{
  89. queryAddrFailed(res);
  90. }
  91. })
  92. })
  93. //街道
  94. $('#town').on('click','li',function(){
  95. var $this = $(this);
  96. changeList($('#village'),$this);
  97. $true.hide();
  98. $false.show();
  99. $sel2 = '<li>'+$this.text()+'</li>';
  100. $tit.html($sel1+$sel2+$sel0);
  101. var data={
  102. street:$this.data('code')
  103. };
  104. sendPost('doctor/sign/getCountryListByStreet', data,queryAddrFailed ,function(res){
  105. if(res.status == 200){
  106. var list="";
  107. if(res.data.length>0){
  108. $.map(res.data,function(item,index){
  109. list +='<li data-jwcode="'+item.jwCode+'" data-code="'+item.code+'">'+item.name+'</li>';
  110. })
  111. }else{
  112. }
  113. $('#village').find('ul').empty().append(list);
  114. }else{
  115. queryAddrFailed(res);
  116. }
  117. })
  118. })
  119. //居委会
  120. $('#village').on('click','li',function(){
  121. var $this = $(this);
  122. changeList($('#village'),$this);
  123. jwcountryCode = $this.attr('data-jwcode');
  124. countryCode = $this.attr('data-code');
  125. countryName = $this.text();
  126. $true.show();
  127. $false.hide();
  128. })
  129. $tit.on('click','li',function(){
  130. var $this = $(this);
  131. if(! $this.hasClass('active')){
  132. $this.addClass('active').siblings().removeClass('active');
  133. $list.hide();
  134. $list.eq($this.index()).show();
  135. }
  136. })
  137. //取消
  138. $false.click(function(){
  139. mui('#sheet').popover('hide');
  140. })
  141. //确定
  142. $true.click(function(){
  143. mui('#sheet').popover('hide');
  144. $('#committee').val(countryName);
  145. $('#committee').attr('data-jwcode',jwcountryCode);
  146. $('#committee').attr('data-code',countryCode);
  147. })
  148. function changeList($next,$li){
  149. $li.addClass('active').siblings().removeClass('active');
  150. $list.hide();
  151. $next.show();
  152. }
  153. }
  154. }