my-detail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var d1 = dialog({contentType:'load', skin:'bk-popup',content:'退出中..'});
  3. var pagetype = 11;
  4. var openid =null;
  5. var userAgent = window.localStorage.getItem(agentName);
  6. var firstUid = window.localStorage.getItem("firstUid");
  7. if(firstUid == null || firstUid == undefined){
  8. document.getElementById("divChangeLogin").style.display='none';
  9. }
  10. var bindCardUrl = "",
  11. bindCardStatus;
  12. if(userAgent){
  13. var jsonstr = $.parseJSON(userAgent);
  14. openid = jsonstr.openid;
  15. }
  16. $(function() {
  17. checkUserAgent();
  18. });
  19. appendFamilyMember($('#memberContainer'),function(){
  20. queryInit();
  21. clearCommittee()
  22. var jsonstr = $.parseJSON(window.localStorage.getItem(agentName));
  23. if(jsonstr.uid == jsonstr.represented){
  24. $('#divChangeLogin').show()
  25. //判断是否可以在线支付
  26. if(canPayOnline){
  27. $("#elecard").show();
  28. }else{
  29. $("#elecard").hide();
  30. }
  31. }else{
  32. $('#divChangeLogin').hide()
  33. $("#elecard").hide();
  34. }
  35. },function(){
  36. //判断有授权家人,修改样式
  37. if($('#memberContainer').is(':hidden')){
  38. $('#content').css('padding-top','0px');
  39. }else{
  40. $('#content').css('padding-top','90px');
  41. }
  42. });
  43. function queryInit(){
  44. d.show();
  45. isRepresent(function() {
  46. //查询用户信息
  47. query();
  48. getWeixinSign();
  49. bindEvents();
  50. //选择居委会
  51. selectCommittee()
  52. })
  53. }
  54. //获得微信sdk信息
  55. function getWeixinSign(){
  56. var params1 = {};
  57. params1.pageUrl = server + "wx/html/grzx/html/my-detail.html&state=STATE";
  58. $.ajax(server + "weixin/getSign", {
  59. data: params1,
  60. dataType: "json",
  61. type: "post",
  62. success: function(res){
  63. if (res.status == 200) {
  64. var t = res.data.timestamp;
  65. var noncestr = res.data.noncestr;
  66. var signature = res.data.signature;
  67. wx.config({
  68. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  69. appId: appId, // 必填,公众号的唯一标识
  70. timestamp: t, // 必填,生成签名的时间戳
  71. nonceStr: noncestr, // 必填,生成签名的随机串
  72. signature: signature,// 必填,签名,见附录1
  73. jsApiList: [
  74. 'chooseImage',
  75. 'uploadImage'
  76. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  77. });
  78. }
  79. }
  80. });
  81. }
  82. //跳转到三师信息
  83. function changeSanshi(){
  84. window.location.href = "../../qygl/html/signing-doctors.html";
  85. }
  86. //跳转到家庭签约信息
  87. function changeJtqy(signedStatus){
  88. if(signedStatus) {
  89. window.location.href = "../../ssgg/html/doctor-homepage-new.html"
  90. } else {
  91. window.location.href = "../../qygl/html/signing-doctors.html"
  92. }
  93. }
  94. //查询列表
  95. function query() {
  96. // var data={};
  97. // sendPost('patient/baseinfo', data, 'json', 'post', queryFailed, querySuccess);
  98. //初始查询患者基本信息,然后调用接口判断该患者是否已绑定电子社保卡
  99. var reqParams = [{
  100. url: "patient/baseinfo",
  101. data: {},
  102. reqType: 'post'
  103. }]
  104. getReqPromises(reqParams).then(function(ress){
  105. querySuccess(ress[0]);
  106. //处理绑卡
  107. // var res2 = ress[1];
  108. // if(res2.data.bindStatus == '030007'){
  109. // bindCardStatus = false;
  110. // bindCardUrl = res2.data.sicardUrl;
  111. // }else if(res2.data.bindStatus == '000000'){
  112. // bindCardStatus = true;
  113. // bindCardUrl = res2.data.sicardUrl;
  114. // }else{
  115. // dialog({contentType:'tipsbox', skin:'bk-popup' , content:res2.msg}).show();
  116. // }
  117. // //判断是否可以在线支付
  118. // if(canPayOnline){
  119. // $("#elecard").show();
  120. // $("#elecardStatus").text(bindCardStatus? "已绑定" : "未绑定");
  121. // }else{
  122. // $("#elecard").hide();
  123. // }
  124. });
  125. }
  126. function queryFailed(res) {
  127. d.close();
  128. if (res && res.msg) {
  129. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  130. } else {
  131. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'初始化失败'}).show();
  132. }
  133. }
  134. function querySuccess(res) {
  135. d.close();
  136. if (res.status == 200) {
  137. setValue(res.data);
  138. // if($("#ssc").val() != ""){
  139. // $("#ssc").attr("readonly","readonly");
  140. // }
  141. //取药码
  142. if(res.data.prescription == 1){
  143. $('#myMedicine').show()
  144. }else{
  145. $('#myMedicine').hide()
  146. }
  147. }
  148. }
  149. function bindEvents(){
  150. $("#backLogin").click(function (){
  151. dialog({
  152. content:'您确定继续退出登录吗?',
  153. ok: function (){
  154. d1.show()
  155. sendPost("patient/wxloginout",{},"JSON","POST",function(res){
  156. d1.close()
  157. if (res && res.msg) {
  158. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  159. } else {
  160. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'退出登录失败!'}).show();
  161. }
  162. },function(res){
  163. d1.close()
  164. if(res.status==200){
  165. clearAgent();
  166. window.localStorage.removeItem("isTiXingVideoFaSong");//清除咨询详情移动网络下,用户点击不再提醒后的处理,换账号登陆后,还可以重新提醒
  167. location.replace("../../home/html/login.html?type=11&openid="+openid+"&loginType=password");
  168. }else{
  169. if (res && res.msg) {
  170. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  171. } else {
  172. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'退出登录失败!'}).show();
  173. }
  174. }
  175. })
  176. },
  177. cancel: function () {
  178. return;
  179. }
  180. }).showModal();
  181. });
  182. //绑定电子社保卡
  183. $('#elecard').on('tap',function(){
  184. if(!bindCardStatus){
  185. dialog({
  186. content: '当前未绑定电子社保卡,无法进行线上缴费,是否立即绑定',
  187. cancelValue: '不了,谢谢',
  188. cancel: function () {},
  189. okValue:'是',
  190. ok: function (){
  191. window.location.href = bindCardUrl;
  192. }
  193. }).showModal();
  194. }else {
  195. window.location.href = bindCardUrl;
  196. }
  197. });
  198. //电子健康卡点击事件
  199. $("#healthcard").on('tap', function(){
  200. window.location.href = "my-health-card.html"
  201. // d.show();
  202. // var url = "/patient/ehc/redirecturl";
  203. // sendPost(url, {}, 'json', 'post', queryFailed, function(res){
  204. // if(res.status == 200){
  205. // d.close();
  206. // window.location.href = res.data;
  207. // }else{
  208. // queryFailed(res);
  209. // }
  210. // })
  211. })
  212. }
  213. //初始化页面数据
  214. function setValue(data){
  215. var photo = data.photo;
  216. var name = data.name;
  217. var sex = data.sex;
  218. var mobile = data.mobile;
  219. var idcard = data.idcard;
  220. var ssc = data.ssc;
  221. var address = data.address;
  222. var sign = Number(data.sign);
  223. var sexName = "女";
  224. if(sex == 1) {
  225. sexName = "男";
  226. }
  227. if(!photo){
  228. photo = "../../../images/p-default.png";
  229. }
  230. if(!name) name = "";
  231. if(!mobile) mobile = "";
  232. if(!idcard) idcard = "";
  233. if(!ssc) ssc = "";
  234. if(!address) address = "";
  235. document.getElementById("photo").src = getImgUrl(photo);
  236. document.getElementById("name").value = name;
  237. document.getElementById("sex").innerHTML = sexName;
  238. document.getElementById("mobile").innerHTML = mobile;
  239. document.getElementById("idcard").innerHTML = idcard;
  240. document.getElementById("ssc").innerHTML = ssc;
  241. document.getElementById("address").innerHTML = address;
  242. $('#committee').text(data.countryName);
  243. }
  244. // 添加文件
  245. function appendFile(p) {
  246. document.getElementById("photo").src = p;
  247. $("#photo").attr("data-src",p);
  248. }
  249. //获取需要上传的图片
  250. function getImages() {
  251. var images = [];
  252. var imgSrc = $("#photo").attr("data-src");
  253. images.push(imgSrc);
  254. return images;
  255. }
  256. //剪切图片
  257. function clip_photo(){
  258. $("#content").addClass("c-hide");
  259. $("#clipPanel").removeClass("c-hide");
  260. var photo = document.getElementById('file_head');
  261. lrz(photo.files[0]).then(function (rst) {
  262. var url = rst.base64;
  263. new AlloyCrop({
  264. image_src: url,
  265. width: document.documentElement.clientWidth,
  266. height: document.documentElement.clientWidth,
  267. ok_text: "保存",
  268. cancel_text: "取消",
  269. ok: function (base64, canvas) {
  270. $("#content").removeClass("c-hide");
  271. var data=base64.split(',')[1];
  272. data=window.atob(data);
  273. var ia = new Uint8Array(data.length);
  274. for (var i = 0; i < data.length; i++) {
  275. ia[i] = data.charCodeAt(i);
  276. }
  277. var blob=new Blob([ia],{type:"image/png",endings:'transparent'});
  278. var fd=new FormData();
  279. fd.append('file',blob,'image.png');
  280. var new_url = URL.createObjectURL(blob);
  281. appendFile(new_url);
  282. $.ajax(server + 'upload/image', {
  283. data: fd,
  284. dataType: 'json',
  285. contentType: false,
  286. cache: false,
  287. processData: false,
  288. beforeSend: function(request) {
  289. request.setRequestHeader("userAgent", userAgent);
  290. },
  291. type: 'post',
  292. error: function(res) {
  293. if(res.status == 999 || res.status == 998 || res.status == 997){
  294. loginUrl(res.status);
  295. return;
  296. }
  297. clickCount = 0;
  298. },
  299. success: function(res) {
  300. if(res.status == 999 || res.status == 998 || res.status == 997){
  301. loginUrl(res.status);
  302. return;
  303. }
  304. var params = {};
  305. params.photo = res.urls;
  306. var patientUrl = res.urls;
  307. sendPost('patient/save', params, 'json', 'post', submitFailed, submitSuccess);
  308. clickCount = 0;
  309. }
  310. });
  311. },
  312. cancel: function () {
  313. $("#content").removeClass("c-hide");
  314. }
  315. });
  316. })
  317. .catch(function (err){
  318. // 处理失败会执行
  319. console.log(err);
  320. });
  321. }
  322. // 上传头像
  323. var serverId = "";
  324. function chooseImage(){
  325. wx.chooseImage({
  326. count: 1,
  327. success: function (res) {
  328. appendFile(res.localIds[0]);
  329. uploadImage();
  330. }
  331. });
  332. }
  333. //获取微信上传图片的媒体ID
  334. function uploadImage(){
  335. var images = getImages();
  336. if (images.length == 0) {
  337. return;
  338. }
  339. var i = 0, length = images.length;
  340. serverId = "";
  341. function upload() {
  342. wx.uploadImage({
  343. localId: images[i],
  344. success: function (res) {
  345. i++;
  346. if(serverId.length == 0){
  347. serverId = res.serverId;
  348. }
  349. else{
  350. serverId =serverId + "," + res.serverId;
  351. }
  352. if (i < length) {
  353. upload();
  354. }
  355. if(i == images.length){
  356. update_photo();
  357. }
  358. },
  359. fail: function (res) {
  360. alert(JSON.stringify(res));
  361. }
  362. });
  363. }
  364. upload();
  365. }
  366. //上传图片到服务器上
  367. function update_photo(){
  368. var params = {};
  369. params.mediaIds = serverId;
  370. sendPost('patient/save', params, 'json', 'post', submitFailed, submitSuccess);
  371. }
  372. //上传失败
  373. function submitFailed(res) {
  374. if (res && res.msg) {
  375. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  376. } else {
  377. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'上传失败'}).show();
  378. }
  379. }
  380. //上传成功
  381. function submitSuccess(res) {
  382. if (res.status == 200) {
  383. $("#content").removeClass("c-hide");
  384. $("#clipPanel").addClass("c-hide");
  385. } else {
  386. submitFailed(res);
  387. }
  388. }
  389. //查看图片
  390. function viewImg(dom) {
  391. var $img = $(dom);
  392. var thissrc = $img.attr("data-src");
  393. var mWid = $(window).width();
  394. var mHei = $(window).height();
  395. var nHtml = '<div class="delimgpop"><div class="del-img-box"><div class="del-img-con"><img class="del-pop-img" src="' + thissrc + '" style="max-width:' + mWid + 'px; max-height:' + mHei + 'px;"></div></div></div>';
  396. $("body").append(nHtml);
  397. $(".delimgpop").click(function() {
  398. $(this).remove()
  399. });
  400. };
  401. function myMedicine(){
  402. window.location.href = "../../prescription/html/my-medicine-code.html";
  403. }
  404. function myFeedback(){
  405. window.location.href = "../../yjfk/html/feedback.html";
  406. }
  407. function updatePwd(){
  408. var mobile = $('#mobile').html();
  409. window.location.href = "shezhimima.html?type=" + pagetype + "&openid=" + openid + "&mobile="+ mobile + "&1=1";
  410. }
  411. function updateAddress(){
  412. var address = $('#address').html();
  413. var paramAgent = "{\"type\":" + pagetype + ",\"openid\":\"" + openid + "\",\"address\":\"" + encodeURI(address) + "\"}";
  414. window.localStorage.setItem("paramAgent", paramAgent);
  415. window.location.href = "xiugaidizhi.html?type=" + pagetype + "&openid=" + openid + "&mobile="+ mobile + "&1=1";
  416. }
  417. function updateMobile(){
  418. var mobile = $.trim($('#mobile').html());
  419. if(mobile.length==0)
  420. window.location.href = "bangdingsj.html?type=" + pagetype + "&openid=" + openid + "&1=1";
  421. else
  422. window.location.href = "shenfenyz.html?type=" + pagetype + "&openid=" + openid + "&mobile="+ mobile + "&1=1";
  423. }
  424. function updateSSC(){
  425. var ssc = $.trim($('#ssc').html());
  426. window.location.href = "update-ssc.html?type=" + pagetype + "&openid=" + openid + "&ssc="+ ssc + "&1=1";
  427. }