mianyijihua.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var pagetype = 46;
  3. var Request = GetRequest();
  4. var $body = $('.my-main');
  5. var route = Request['route'];//来源路径
  6. var code;
  7. //定义弹窗
  8. function toast(msg){
  9. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:msg}).show()
  10. }
  11. //请求失败
  12. function queryFailed(){
  13. d.close()
  14. toast('请求失败')
  15. }
  16. $(function(){
  17. checkUserAgent();
  18. //从后台那边获取签名等信息
  19. var params = {};
  20. params.pageUrl = window.location.href;
  21. $.ajax(server + "weixin/getSign", {
  22. data: params,
  23. dataType: "json",
  24. type: "post",
  25. success: function(res){
  26. if (res.status == 200) {
  27. var t = res.data.timestamp;
  28. var noncestr = res.data.noncestr;
  29. var signature = res.data.signature;
  30. wx.config({
  31. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  32. appId: appId, // 必填,公众号的唯一标识
  33. timestamp: t, // 必填,生成签名的时间戳
  34. nonceStr: noncestr, // 必填,生成签名的随机串
  35. signature: signature,// 必填,签名,见附录1
  36. jsApiList: [
  37. 'closeWindow'
  38. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  39. })
  40. }
  41. }
  42. })
  43. getImmuneMembers();
  44. newBind();
  45. })
  46. function getImmuneMembers(){
  47. var data = {};
  48. sendPost("patient/family/members", data, "json", "get", queryListFailed, queryAppoListSuccesss);
  49. }
  50. function queryAppoListSuccesss(res){
  51. if (res.status == 200) {
  52. code = "";
  53. if(res.data.immunemembers.length==0){
  54. location.replace("ertongbangding.html");
  55. }else{
  56. showMember(res);
  57. }
  58. }else{
  59. //非200则为失败
  60. queryListFailed(res);
  61. }
  62. }
  63. function queryListFailed(res) {
  64. if (res && res.msg) {
  65. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  66. } else {
  67. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载家庭成员失败'}).show();
  68. }
  69. }
  70. function showMember(res){
  71. var html='',
  72. data=res.data.immunemembers;
  73. for(var i=0;i<data.length;i++){
  74. //"relation": 1//---1父亲 2母亲 3老公 4老婆 5儿子 6女儿 7其他
  75. if(data[i].relation==5){
  76. data[i].familyRelationName = '儿子'
  77. }else if(data[i].relation==6){
  78. data[i].familyRelationName = '女儿'
  79. }else{
  80. data[i].familyRelationName = '其他'
  81. }
  82. html = html + '<div class="mui-control-item" data-code="'+data[i].code+'" data-name="'+data[i].name+'" style="display: inline-block;margin-right: 15px;-webkit-user-select: none;vertical-align: middle;text-align: center;">\
  83. <img style="width: 40px;height: 40px;border-radius: 50%;overflow: hidden;border:solid 1px #dcdcdc;" src="../images/youer_moren_img.png"/>\
  84. <div class="name" style="font-size: 12px;color: #333;line-height: 20px;">'+data[i].name+'('+data[i].familyRelationName+')</div></div>'
  85. }
  86. html = html + '<div id="xinzeng_btn" style="display: inline-block;margin-right: 15px;-webkit-user-select: none;vertical-align: middle;text-align: center;">\
  87. <img style="width: 40px;height: 40px;border-radius: 50%;overflow: hidden;border:solid 1px #dcdcdc;" src="../images/xinzengguanlian_btn.png"/>\
  88. <div class="name" style="font-size: 12px;color: #333;line-height: 20px;">新增关联</div></div>'
  89. html = '<div class="mui-scroll-wrapper family-member" style="position: absolute;z-index: 999;top: 0;bottom: 0;left: 0;overflow: hidden;width: 100%;height: 90px;background-color:#f3f3f3;padding-left: 15px;padding-top: 7px;border-bottom:solid 1px #dcdcdc;box-sizing: border-box;">\
  90. <div class="mui-scroll" style="position: absolute;width: auto;z-index: 99;white-space: nowrap;-webkit-transform: translateZ(0);transform: translateZ(0);">'+html+'</div></div>';
  91. $('#memberContainer').append(html);
  92. setTimeout(function(){
  93. addEvent();
  94. },200)
  95. initData();
  96. }
  97. function active(one){
  98. one.find('img').css({width: '55px',height: '55px'});
  99. one.find('.name').css({'font-size': '14px','line-height':'23px'});
  100. }
  101. function addEvent(){
  102. mui('.family-member').scroll({
  103. scrollY: false, //是否竖向滚动
  104. scrollX: true, //是否横向滚动
  105. });
  106. $('#memberContainer').on('tap','.mui-control-item',function(){
  107. var $this = $(this),
  108. $code = $this.data('code');
  109. code = $code;
  110. $('.mui-control-item').find('img').css({width: '40px',height: '40px'});
  111. $('.mui-control-item').find('.name').css({'font-size': '12px','line-height':'20px'});
  112. active($this);
  113. initData();
  114. })
  115. }
  116. function initData(){
  117. d.show();
  118. var params = {};
  119. if(code == ""){
  120. var $ul = $('#memberContainer').find('.mui-control-item');
  121. code = $ul.eq(0).data('code')
  122. if(code){
  123. active($ul.eq(0));
  124. }
  125. }
  126. if(code){
  127. $('.my-section').css('top','90px');
  128. // $(".my-section").show();
  129. // $('.div-no-info').css('padding-top','150px');
  130. // $(".div-no-info").hide();
  131. params.code = code;
  132. getImmChildInfo(params);
  133. }else{
  134. $('.my-section').css('top','0px');
  135. d.close();
  136. // $(".my-section").hide();
  137. // $(".div-no-info").show();
  138. }
  139. }
  140. //根据新生儿编码获取新生儿基础信息
  141. function getImmChildInfo(params){
  142. d.close();
  143. sendPost('/patient/family/getImmChildInfo',params,'json','get', queryFailed,function(res){
  144. if(res.status == 200){
  145. var html = template('patient_tmpl', res.data)
  146. $('#patientInfo').html(html)
  147. if(res.data.sex==2){
  148. // nextWork()
  149. bindEvent()
  150. }else{
  151. d.close()
  152. dialog({
  153. content: '<div><div class="c-f16 c-333 c-t-left mb10">当前未关联在免疫计划内居民,是否添加条形码关联?</div></div>',
  154. okValue: '是',
  155. ok: function() {
  156. location.href="ertongbangding.html"
  157. },
  158. cancelValue: '否',
  159. cancel: function () {
  160. wx.closeWindow();
  161. }
  162. }).showModal()
  163. }
  164. }else{
  165. d.close()
  166. toast('获取信息失败')
  167. }
  168. })
  169. }
  170. function bindEvent(){
  171. //头部展示
  172. showActive(route)
  173. mui('.my-nav').scroll({
  174. scrollY: false, //是否竖向滚动
  175. scrollX: true, //是否横向滚动
  176. })
  177. //切换类型
  178. $('.j-change').on('tap',function(){
  179. var $this = $(this)
  180. if(!$this.hasClass('active')){
  181. $this.addClass('active').siblings().removeClass('active')
  182. }
  183. })
  184. //跳转疫苗详情
  185. $('.my-line').on('tap',function(){
  186. location.href="yimiaoxiangqing.html"
  187. })
  188. }
  189. function newBind(){
  190. //新增关联
  191. $('body').on('tap','#xinzeng_btn',function(){
  192. location.href="ertongbangding.html"
  193. })
  194. $('body').on('tap','.idClick',function(){
  195. var $this = $(this);
  196. var $editbarcode = $this.attr('data-code');
  197. location.href="edit-idcard-ssc.html?barcode="+$editbarcode;
  198. })
  199. $('body').on('tap','.sscClick',function(){
  200. var $this = $(this);
  201. var $editbarcode = $this.attr('data-code');
  202. location.href="edit-idcard-ssc.html?barcode="+$editbarcode;
  203. })
  204. }
  205. //优先展示
  206. function showActive(route){
  207. var $list = $('.j-change');
  208. if(route){
  209. for(var i=0;i<$list.length;i++){
  210. if($list.eq(i).attr('data-id') == route){
  211. $list.eq(i).addClass('active')
  212. return
  213. }
  214. }
  215. }else{
  216. $list.eq(0).addClass('active')
  217. }
  218. }
  219. template.helper("setPhoto", function(p) {
  220. return getImgUrl(p);
  221. });
  222. template.helper("setAge", function(p) {
  223. // 获得今天的时间
  224. var date = new Date();
  225. // alert(birthday);
  226. var startDate = new Date(p);
  227. var newDate = date.getTime() - startDate.getTime();
  228. // 向下取整 例如 10岁 20天 会计算成 10岁
  229. // 如果要向上取整 计算成11岁,把floor替换成 ceil
  230. var age = Math.ceil(newDate / 1000 / 60 / 60 / 24 /365);
  231. if (isNaN(age)){
  232. age = "";
  233. }
  234. return age;
  235. });