my-detail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. url: "/patient/bindCard",
  105. data: {},
  106. reqType: 'post'
  107. }]
  108. getReqPromises(reqParams).then(function(ress){
  109. querySuccess(ress[0]);
  110. //处理绑卡
  111. var res2 = ress[1];
  112. if(res2.data.bindStatus == '030007'){
  113. bindCardStatus = false;
  114. bindCardUrl = res2.data.sicardUrl;
  115. }else if(res2.data.bindStatus == '000000'){
  116. bindCardStatus = true;
  117. bindCardUrl = res2.data.sicardUrl;
  118. }else{
  119. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res2.msg}).show();
  120. }
  121. //判断是否可以在线支付
  122. if(canPayOnline){
  123. $("#elecard").show();
  124. $("#elecardStatus").text(bindCardStatus? "已绑定" : "未绑定");
  125. }else{
  126. $("#elecard").hide();
  127. }
  128. });
  129. }
  130. function queryFailed(res) {
  131. d.close();
  132. if (res && res.msg) {
  133. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  134. } else {
  135. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'初始化失败'}).show();
  136. }
  137. }
  138. function querySuccess(res) {
  139. d.close();
  140. if (res.status == 200) {
  141. setValue(res.data);
  142. if($("#ssc").val() != ""){
  143. $("#ssc").attr("readonly","readonly");
  144. }
  145. //取药码
  146. if(res.data.prescription == 1){
  147. $('#myMedicine').show()
  148. }else{
  149. $('#myMedicine').hide()
  150. }
  151. }
  152. }
  153. function bindEvents(){
  154. $("#backLogin").click(function (){
  155. dialog({
  156. content:'您确定继续退出登录吗?',
  157. ok: function (){
  158. d1.show()
  159. sendPost("patient/wxloginout",{},"JSON","POST",function(res){
  160. d1.close()
  161. if (res && res.msg) {
  162. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  163. } else {
  164. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'退出登录失败!'}).show();
  165. }
  166. },function(res){
  167. d1.close()
  168. if(res.status==200){
  169. clearAgent();
  170. window.localStorage.removeItem("isTiXingVideoFaSong");//清除咨询详情移动网络下,用户点击不再提醒后的处理,换账号登陆后,还可以重新提醒
  171. location.replace("../../home/html/zhmm-login.html?type=11&openid="+openid);
  172. }else{
  173. if (res && res.msg) {
  174. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  175. } else {
  176. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'退出登录失败!'}).show();
  177. }
  178. }
  179. })
  180. },
  181. cancel: function () {
  182. return;
  183. }
  184. }).showModal();
  185. });
  186. //绑定电子社保卡
  187. $('#elecard').on('tap',function(){
  188. if(!bindCardStatus){
  189. dialog({
  190. content: '当前未绑定电子社保卡,无法进行线上缴费,是否立即绑定',
  191. cancelValue: '不了,谢谢',
  192. cancel: function () {},
  193. okValue:'是',
  194. ok: function (){
  195. window.location.href = bindCardUrl;
  196. }
  197. }).showModal();
  198. }else {
  199. window.location.href = bindCardUrl;
  200. }
  201. });
  202. //电子健康卡点击事件
  203. $("#healthcard").on('tap', function(){
  204. window.location.href = "my-health-card.html"
  205. // d.show();
  206. // var url = "/patient/ehc/redirecturl";
  207. // sendPost(url, {}, 'json', 'post', queryFailed, function(res){
  208. // if(res.status == 200){
  209. // d.close();
  210. // window.location.href = res.data;
  211. // }else{
  212. // queryFailed(res);
  213. // }
  214. // })
  215. })
  216. }
  217. //初始化页面数据
  218. function setValue(data){
  219. var photo = data.photo;
  220. var name = data.name;
  221. var sex = data.sex;
  222. var mobile = data.mobile;
  223. var idcard = data.idcard;
  224. var ssc = data.ssc;
  225. var address = data.address;
  226. var medicareNumber = data.medicareNumber || "";
  227. var sign = Number(data.sign);
  228. var sexName = "女";
  229. if(sex == 1) {
  230. sexName = "男";
  231. }
  232. if(!photo){
  233. photo = "../../../images/p-default.png";
  234. }
  235. if(!name) name = "";
  236. if(!mobile) mobile = "";
  237. if(!idcard) idcard = "";
  238. if(!ssc) ssc = "";
  239. if(!address) address = "";
  240. document.getElementById("photo").src = getImgUrl(photo);
  241. document.getElementById("name").value = name;
  242. document.getElementById("sex").innerHTML = sexName;
  243. document.getElementById("mobile").innerHTML = mobile;
  244. document.getElementById("idcard").innerHTML = idcard;
  245. document.getElementById("medicareNumber").innerHTML = medicareNumber;
  246. document.getElementById("ssc").value = ssc;
  247. document.getElementById("address").innerHTML = address;
  248. $('#committee').text(data.countryName);
  249. }
  250. // 添加文件
  251. function appendFile(p) {
  252. document.getElementById("photo").src = p;
  253. $("#photo").attr("data-src",p);
  254. }
  255. //获取需要上传的图片
  256. function getImages() {
  257. var images = [];
  258. var imgSrc = $("#photo").attr("data-src");
  259. images.push(imgSrc);
  260. return images;
  261. }
  262. //剪切图片
  263. function clip_photo(){
  264. $("#content").addClass("c-hide");
  265. $("#clipPanel").removeClass("c-hide");
  266. var photo = document.getElementById('file_head');
  267. lrz(photo.files[0]).then(function (rst) {
  268. var url = rst.base64;
  269. new AlloyCrop({
  270. image_src: url,
  271. width: document.documentElement.clientWidth,
  272. height: document.documentElement.clientWidth,
  273. ok_text: "保存",
  274. cancel_text: "取消",
  275. ok: function (base64, canvas) {
  276. $("#content").removeClass("c-hide");
  277. var data=base64.split(',')[1];
  278. data=window.atob(data);
  279. var ia = new Uint8Array(data.length);
  280. for (var i = 0; i < data.length; i++) {
  281. ia[i] = data.charCodeAt(i);
  282. }
  283. var blob=new Blob([ia],{type:"image/png",endings:'transparent'});
  284. var fd=new FormData();
  285. fd.append('file',blob,'image.png');
  286. var new_url = URL.createObjectURL(blob);
  287. appendFile(new_url);
  288. $.ajax(server + 'upload/image', {
  289. data: fd,
  290. dataType: 'json',
  291. contentType: false,
  292. cache: false,
  293. processData: false,
  294. beforeSend: function(request) {
  295. request.setRequestHeader("userAgent", userAgent);
  296. },
  297. type: 'post',
  298. error: function(res) {
  299. if(res.status == 999 || res.status == 998 || res.status == 997){
  300. loginUrl(res.status);
  301. return;
  302. }
  303. clickCount = 0;
  304. },
  305. success: function(res) {
  306. if(res.status == 999 || res.status == 998 || res.status == 997){
  307. loginUrl(res.status);
  308. return;
  309. }
  310. var params = {};
  311. params.photo = res.urls;
  312. var patientUrl = res.urls;
  313. sendPost('patient/save', params, 'json', 'post', submitFailed, submitSuccess);
  314. clickCount = 0;
  315. }
  316. });
  317. },
  318. cancel: function () {
  319. $("#content").removeClass("c-hide");
  320. }
  321. });
  322. })
  323. .catch(function (err){
  324. // 处理失败会执行
  325. console.log(err);
  326. });
  327. }
  328. // 上传头像
  329. var serverId = "";
  330. function chooseImage(){
  331. wx.chooseImage({
  332. count: 1,
  333. success: function (res) {
  334. appendFile(res.localIds[0]);
  335. uploadImage();
  336. }
  337. });
  338. }
  339. //获取微信上传图片的媒体ID
  340. function uploadImage(){
  341. var images = getImages();
  342. if (images.length == 0) {
  343. return;
  344. }
  345. var i = 0, length = images.length;
  346. serverId = "";
  347. function upload() {
  348. wx.uploadImage({
  349. localId: images[i],
  350. success: function (res) {
  351. i++;
  352. if(serverId.length == 0){
  353. serverId = res.serverId;
  354. }
  355. else{
  356. serverId =serverId + "," + res.serverId;
  357. }
  358. if (i < length) {
  359. upload();
  360. }
  361. if(i == images.length){
  362. update_photo();
  363. }
  364. },
  365. fail: function (res) {
  366. alert(JSON.stringify(res));
  367. }
  368. });
  369. }
  370. upload();
  371. }
  372. //上传图片到服务器上
  373. function update_photo(){
  374. var params = {};
  375. params.mediaIds = serverId;
  376. sendPost('patient/save', params, 'json', 'post', submitFailed, submitSuccess);
  377. }
  378. //上传失败
  379. function submitFailed(res) {
  380. if (res && res.msg) {
  381. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  382. } else {
  383. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'上传失败'}).show();
  384. }
  385. }
  386. //上传成功
  387. function submitSuccess(res) {
  388. if (res.status == 200) {
  389. $("#content").removeClass("c-hide");
  390. $("#clipPanel").addClass("c-hide");
  391. } else {
  392. submitFailed(res);
  393. }
  394. }
  395. //查看图片
  396. function viewImg(dom) {
  397. var $img = $(dom);
  398. var thissrc = $img.attr("data-src");
  399. var mWid = $(window).width();
  400. var mHei = $(window).height();
  401. 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>';
  402. $("body").append(nHtml);
  403. $(".delimgpop").click(function() {
  404. $(this).remove()
  405. });
  406. };
  407. function myMedicine(){
  408. window.location.href = "../../prescription/html/my-medicine-code.html";
  409. }
  410. function myFeedback(){
  411. window.location.href = "../../yjfk/html/feedback.html";
  412. }
  413. function updatePwd(){
  414. var mobile = $('#mobile').html();
  415. window.location.href = "shezhimima.html?type=" + pagetype + "&openid=" + openid + "&mobile="+ mobile + "&1=1";
  416. }
  417. function updateAddress(){
  418. var address = $('#address').html();
  419. var paramAgent = "{\"type\":" + pagetype + ",\"openid\":\"" + openid + "\",\"address\":\"" + encodeURI(address) + "\"}";
  420. window.localStorage.setItem("paramAgent", paramAgent);
  421. window.location.href = "xiugaidizhi.html?type=" + pagetype + "&openid=" + openid + "&mobile="+ mobile + "&1=1";
  422. }
  423. function updateMobile(){
  424. var mobile = $.trim($('#mobile').html());
  425. if(mobile.length==0)
  426. window.location.href = "bangdingsj.html?type=" + pagetype + "&openid=" + openid + "&1=1";
  427. else
  428. window.location.href = "shenfenyz.html?type=" + pagetype + "&openid=" + openid + "&mobile="+ mobile + "&1=1";
  429. }