my-detail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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/zhmm-login.html?type=11&openid="+openid);
  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 medicareNumber = data.medicareNumber || "";
  223. var sign = Number(data.sign);
  224. var sexName = "女";
  225. if(sex == 1) {
  226. sexName = "男";
  227. }
  228. if(!photo){
  229. photo = "../../../images/p-default.png";
  230. }
  231. if(!name) name = "";
  232. if(!mobile) mobile = "";
  233. if(!idcard) idcard = "";
  234. if(!ssc) ssc = "";
  235. if(!address) address = "";
  236. document.getElementById("photo").src = getImgUrl(photo);
  237. document.getElementById("name").value = name;
  238. document.getElementById("sex").innerHTML = sexName;
  239. document.getElementById("mobile").innerHTML = mobile;
  240. document.getElementById("idcard").innerHTML = idcard;
  241. document.getElementById("medicareNumber").innerHTML = medicareNumber;
  242. document.getElementById("ssc").value = ssc;
  243. document.getElementById("address").innerHTML = address;
  244. $('#committee').text(data.countryName);
  245. }
  246. // 添加文件
  247. function appendFile(p) {
  248. document.getElementById("photo").src = p;
  249. $("#photo").attr("data-src",p);
  250. }
  251. //获取需要上传的图片
  252. function getImages() {
  253. var images = [];
  254. var imgSrc = $("#photo").attr("data-src");
  255. images.push(imgSrc);
  256. return images;
  257. }
  258. //剪切图片
  259. function clip_photo(){
  260. $("#content").addClass("c-hide");
  261. $("#clipPanel").removeClass("c-hide");
  262. var photo = document.getElementById('file_head');
  263. lrz(photo.files[0]).then(function (rst) {
  264. var url = rst.base64;
  265. new AlloyCrop({
  266. image_src: url,
  267. width: document.documentElement.clientWidth,
  268. height: document.documentElement.clientWidth,
  269. ok_text: "保存",
  270. cancel_text: "取消",
  271. ok: function (base64, canvas) {
  272. $("#content").removeClass("c-hide");
  273. var data=base64.split(',')[1];
  274. data=window.atob(data);
  275. var ia = new Uint8Array(data.length);
  276. for (var i = 0; i < data.length; i++) {
  277. ia[i] = data.charCodeAt(i);
  278. }
  279. var blob=new Blob([ia],{type:"image/png",endings:'transparent'});
  280. var fd=new FormData();
  281. fd.append('file',blob,'image.png');
  282. var new_url = URL.createObjectURL(blob);
  283. appendFile(new_url);
  284. $.ajax(server + 'upload/image', {
  285. data: fd,
  286. dataType: 'json',
  287. contentType: false,
  288. cache: false,
  289. processData: false,
  290. beforeSend: function(request) {
  291. request.setRequestHeader("userAgent", userAgent);
  292. },
  293. type: 'post',
  294. error: function(res) {
  295. if(res.status == 999 || res.status == 998 || res.status == 997){
  296. loginUrl(res.status);
  297. return;
  298. }
  299. clickCount = 0;
  300. },
  301. success: function(res) {
  302. if(res.status == 999 || res.status == 998 || res.status == 997){
  303. loginUrl(res.status);
  304. return;
  305. }
  306. var params = {};
  307. params.photo = res.urls;
  308. var patientUrl = res.urls;
  309. sendPost('patient/save', params, 'json', 'post', submitFailed, submitSuccess);
  310. clickCount = 0;
  311. }
  312. });
  313. },
  314. cancel: function () {
  315. $("#content").removeClass("c-hide");
  316. }
  317. });
  318. })
  319. .catch(function (err){
  320. // 处理失败会执行
  321. console.log(err);
  322. });
  323. }
  324. // 上传头像
  325. var serverId = "";
  326. function chooseImage(){
  327. wx.chooseImage({
  328. count: 1,
  329. success: function (res) {
  330. appendFile(res.localIds[0]);
  331. uploadImage();
  332. }
  333. });
  334. }
  335. //获取微信上传图片的媒体ID
  336. function uploadImage(){
  337. var images = getImages();
  338. if (images.length == 0) {
  339. return;
  340. }
  341. var i = 0, length = images.length;
  342. serverId = "";
  343. function upload() {
  344. wx.uploadImage({
  345. localId: images[i],
  346. success: function (res) {
  347. i++;
  348. if(serverId.length == 0){
  349. serverId = res.serverId;
  350. }
  351. else{
  352. serverId =serverId + "," + res.serverId;
  353. }
  354. if (i < length) {
  355. upload();
  356. }
  357. if(i == images.length){
  358. update_photo();
  359. }
  360. },
  361. fail: function (res) {
  362. alert(JSON.stringify(res));
  363. }
  364. });
  365. }
  366. upload();
  367. }
  368. //上传图片到服务器上
  369. function update_photo(){
  370. var params = {};
  371. params.mediaIds = serverId;
  372. sendPost('patient/save', params, 'json', 'post', submitFailed, submitSuccess);
  373. }
  374. //上传失败
  375. function submitFailed(res) {
  376. if (res && res.msg) {
  377. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  378. } else {
  379. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'上传失败'}).show();
  380. }
  381. }
  382. //上传成功
  383. function submitSuccess(res) {
  384. if (res.status == 200) {
  385. $("#content").removeClass("c-hide");
  386. $("#clipPanel").addClass("c-hide");
  387. } else {
  388. submitFailed(res);
  389. }
  390. }
  391. //查看图片
  392. function viewImg(dom) {
  393. var $img = $(dom);
  394. var thissrc = $img.attr("data-src");
  395. var mWid = $(window).width();
  396. var mHei = $(window).height();
  397. 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>';
  398. $("body").append(nHtml);
  399. $(".delimgpop").click(function() {
  400. $(this).remove()
  401. });
  402. };
  403. function myMedicine(){
  404. window.location.href = "../../prescription/html/my-medicine-code.html";
  405. }
  406. function myFeedback(){
  407. window.location.href = "../../yjfk/html/feedback.html";
  408. }
  409. function updatePwd(){
  410. var mobile = $('#mobile').html();
  411. window.location.href = "shezhimima.html?type=" + pagetype + "&openid=" + openid + "&mobile="+ mobile + "&1=1";
  412. }
  413. function updateAddress(){
  414. var address = $('#address').html();
  415. var paramAgent = "{\"type\":" + pagetype + ",\"openid\":\"" + openid + "\",\"address\":\"" + encodeURI(address) + "\"}";
  416. window.localStorage.setItem("paramAgent", paramAgent);
  417. window.location.href = "xiugaidizhi.html?type=" + pagetype + "&openid=" + openid + "&mobile="+ mobile + "&1=1";
  418. }
  419. function updateMobile(){
  420. var mobile = $.trim($('#mobile').html());
  421. if(mobile.length==0)
  422. window.location.href = "bangdingsj.html?type=" + pagetype + "&openid=" + openid + "&1=1";
  423. else
  424. window.location.href = "shenfenyz.html?type=" + pagetype + "&openid=" + openid + "&mobile="+ mobile + "&1=1";
  425. }