order_tracking.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. var d = dialog({
  2. contentType: 'load',
  3. skin: 'bk-popup'
  4. });
  5. var pagetype = 41;
  6. var request = GetRequest();
  7. var code = request.code; //从链接中获得处方code
  8. var toUser = request["toUser"];
  9. var toName = decodeURIComponent(request["toName"]);
  10. var openid = request["openid"];
  11. var represented = request["represented"];
  12. var userAgent = window.localStorage.getItem(agentName);
  13. var userInfo;
  14. $(function(){
  15. if(!userAgent) {
  16. localStorage.setItem("toUser",toUser);
  17. localStorage.setItem("prescriptionCode",code);
  18. window.location.href = "../../home/html/login.html?openid=" + openid+"&type="+pagetype;
  19. return false;
  20. }
  21. userInfo = JSON.parse(userAgent);
  22. initFamilyData();
  23. wxGetSign();
  24. });
  25. function initFamilyData () {
  26. //从微信模板消息进入
  27. if(represented && userAgent && toUser){
  28. if(toUser == represented){
  29. saveUserInfo(represented,userInfo.uid)
  30. }else if(toUser != represented && represented == userInfo.uid){
  31. //本人代理
  32. saveUserInfo(represented,newUaObj.uid)
  33. }else if(toUser != represented && toUser == userInfo.uid){
  34. //需要判定关系 200有授权 100家人 1无关系
  35. saveUserInfo(represented,userInfo.uid)
  36. }else{
  37. //重新登录
  38. relogin();
  39. }
  40. }else{
  41. //判断是否是本人的消息
  42. if(userInfo.uid != toUser){
  43. relogin();
  44. }else{
  45. getInfo();
  46. bindEvents();
  47. }
  48. }
  49. }
  50. //判断关系
  51. function hasFamilyRelation(a,b){
  52. return new Promise(function(resolve, reject) {
  53. var data={
  54. patient:a,
  55. familyMember:b
  56. }
  57. sendPost("patient/family/is_authorize", data, "json", "get", function(res){
  58. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
  59. }, function(res){
  60. if(res.status == 200) {
  61. window.localStorage.setItem('nowPatientName',res.data.name);
  62. resolve(res)
  63. }else if(res.status == 100) {
  64. dialog({
  65. content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
  66. okValue:'切换账号',
  67. ok: function() {
  68. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  69. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ request["openid"];
  70. },
  71. cancelValue: '我不看了',
  72. cancel: function () {
  73. wx.closeWindow();
  74. }
  75. }).showModal();
  76. }else{
  77. relogin();
  78. }
  79. })
  80. })
  81. }
  82. //重新登录操作
  83. function relogin(){
  84. dialog({
  85. content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
  86. okValue:'切换账号',
  87. ok: function() {
  88. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  89. window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ request["openid"];
  90. },
  91. cancelValue: '我不看了',
  92. cancel: function () {
  93. wx.closeWindow();
  94. }
  95. }).showModal();
  96. }
  97. //保存信息
  98. function saveUserInfo(a,b){
  99. Promise.all([hasFamilyRelation(a,b)]).then(function () {
  100. userInfo.represented = represented;
  101. window.localStorage.setItem(agentName,JSON.stringify(userInfo));
  102. getInfo();
  103. bindEvents();
  104. })
  105. }
  106. function getInfo(){
  107. var url = '/patient/prescription/prescriptionFollow',
  108. params = {prescriptionCode: code};
  109. sendPost(url, params,'json', 'get', queryFailed, function(res){
  110. if(res.status == 200){
  111. //如果是快递配送则没有取药码链接
  112. if(res.data.dispensaryDispensaryType == 2){
  113. $("#qyMa").hide();
  114. }else{
  115. if(res.data.prescriptionStatus < 60){
  116. //配药成功前,不显示取药码
  117. $("#qyMa").hide();
  118. }else{
  119. $("#qyMa").show();
  120. }
  121. }
  122. //居民端订单跟踪,针对取药方式为"居民自取"的订单,增加确认取药及延长收药功能
  123. if(res.data.dispensaryDispensaryType == 2 || res.data.dispensaryDispensaryType == 1){
  124. if(res.data.prescriptionStatus>=50 && res.data.prescriptionStatus<100){
  125. $('#handle-bar').css("display","-webkit-box");
  126. $('#waitqy').show();
  127. if(res.data.createTime){
  128. var nowDate = new Date();
  129. var confirmDate = new Date((res.data.payTime) + (res.data.extendCount+1)*(24*7*60*60*1000));
  130. var date3=confirmDate.getTime()-nowDate.getTime() //时间差的毫秒数
  131. if(date3>0){
  132. //计算出相差天数
  133. var days=Math.floor(date3/(24*3600*1000));
  134. //计算出小时数
  135. var leave1=date3%(24*3600*1000); //计算天数后剩余的毫秒数
  136. var hours=Math.floor(leave1/(3600*1000));
  137. if(days == 0 && hours == 0){
  138. $('#waitqy').hide();
  139. }else if(days == 0){
  140. $('#waitqy').show();
  141. $('#confirmDay').html(hours+'小时')
  142. }else if(hours == 0){
  143. $('#waitqy').show();
  144. $('#confirmDay').html(days+'天')
  145. }else{
  146. $('#waitqy').show();
  147. $('#confirmDay').html(days+'天'+hours+'小时')
  148. }
  149. }else{
  150. $('#waitqy').hide();
  151. }
  152. }
  153. }else{
  154. $('#handle-bar').hide();
  155. $('#waitqy').hide();
  156. }
  157. }
  158. //填充药品信息
  159. var drugList = res.data.prescriptionInfos,
  160. drugHtml = "";
  161. drugHtml = template("drug_tmp", {list: drugList});
  162. $("#drugsList").empty().append(drugHtml);
  163. if(res.data.prescriptionPay){
  164. //填充订单记录信息
  165. var orderInfo = {
  166. ordersn: res.data.prescriptionPay.code,
  167. dept: res.data.prescriptionHospital,
  168. status: res.data.prescriptionStatus
  169. },
  170. orderHtml = "";
  171. orderHtml = template("orderInfo_tmp", orderInfo);
  172. $("#orderInfo").empty().append(orderHtml);
  173. }
  174. if(res.data.dispensaryDispensaryType){
  175. //填充收药信息
  176. var recieveInfo = res.data.prescriptionExpressage;
  177. recieveInfo.dispensaryType = res.data.dispensaryDispensaryType;
  178. recieveInfo.dispensaryTypeName = res.data.dispensaryDispensaryTypeName;
  179. var recieveInfoHtml = template('recieveInfo_tmp', recieveInfo);
  180. $("#recieveInfo").empty().append(recieveInfoHtml);
  181. }
  182. if(res.data.prescriptionPay){
  183. //填充支付记录信息
  184. var paymentInfo = res.data.prescriptionPay,
  185. paymentHtml = template('paymentInfo_tmp', paymentInfo);
  186. $("#paymentInfo").empty().append(paymentHtml);
  187. }
  188. }else{
  189. queryFailed(res);
  190. }
  191. });
  192. }
  193. function delayMedicine(type){
  194. var url = '/patient/prescription/confirmReceipt'
  195. params = {
  196. prescriptionCode: code,
  197. type:type
  198. };
  199. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  200. if(res.status == 200){
  201. getInfo();
  202. if(type==1){
  203. dialog({
  204. contentType: 'tipsbox',
  205. skin: 'bk-popup',
  206. content: res.msg
  207. }).show();
  208. }else{
  209. dialog({
  210. contentType: 'tipsbox',
  211. skin: 'bk-popup',
  212. content: res.msg
  213. }).show();
  214. }
  215. }else{
  216. queryFailed(res);
  217. }
  218. });
  219. }
  220. //获得订单跟踪数据
  221. function getOrderLogs(){
  222. var url = "/patient/prescriptionlog/orderFollow",
  223. params = {prescriptionCode: code};
  224. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  225. if(res.status == 200){
  226. var html = template("orderLog_tmp", {list: res.data});
  227. $("#orderLogs").empty().append(html);
  228. $(".modal-content").show();
  229. }else{
  230. queryFailed(res);
  231. }
  232. });
  233. }
  234. function bindEvents(){
  235. //续方记录
  236. $("#xfRecord").on('click', function(){
  237. window.location.href = 're-prescription_info.html?code='+code+'&toUser='+userInfo.uid;
  238. });
  239. //取药码
  240. $("#qyMa").on('click', function(){
  241. window.location.href = 'code-detail.html?prescriptionCode='+code;
  242. });
  243. //快递记录
  244. $("#recieveInfo").on('click', '#expressInfo', function(res){
  245. var mailno = $(this).attr("data-code");
  246. window.location.href = "express_info.html?code="+code;
  247. });
  248. //订单状态
  249. $("#orderInfo").on('click', "#orderStatus", function(){
  250. $(".mask").show();
  251. //获取订单跟踪时间轴信息
  252. getOrderLogs();
  253. });
  254. //关闭按钮
  255. $("#closeBtn").on('click', function(){
  256. $(".mask").hide();
  257. $(".modal-content").hide();
  258. });
  259. //点击延长收药
  260. $('.delaysy').on('tap',function(){
  261. dialog({
  262. content: "<div style='font-weight:600'>确认延长收药时间?</div>确认后自动收药时间将延长一周,每笔订单只能延长一次哦",
  263. okValue:'确认',
  264. ok: function (){
  265. delayMedicine(2);
  266. },
  267. cancelValue: '取消',
  268. cancel: function () {
  269. // wx.closeWindow();
  270. }
  271. }).showModal();
  272. })
  273. //点击确认收药
  274. $('.confirmsy').on('tap',function(){
  275. dialog({
  276. content: "<div style='font-weight:600'>确认已收药?</div>确认后订单将自动完成哦",
  277. okValue:'确认',
  278. ok: function (){
  279. delayMedicine(1);
  280. },
  281. cancelValue: '取消',
  282. cancel: function () {
  283. // wx.closeWindow();
  284. }
  285. }).showModal();
  286. })
  287. }
  288. function queryFailed(res){
  289. d.close();
  290. if(res && res.msg) {
  291. dialog({
  292. contentType: 'tipsbox',
  293. skin: 'bk-popup',
  294. content: res.msg
  295. }).show();
  296. } else {
  297. dialog({
  298. contentType: 'tipsbox',
  299. skin: 'bk-popup',
  300. content: '加载失败'
  301. }).show();
  302. }
  303. }
  304. template.helper("getStatusName", function(status){
  305. return getStatusName(status);
  306. });
  307. template.helper('getTypeName', function(type){
  308. switch(type){
  309. case 1:
  310. return "医保支付";
  311. break;
  312. default:
  313. return "";
  314. break;
  315. }
  316. });
  317. template.helper('formatMoney', function(money){
  318. var amount = money / 100;
  319. return amount.toFixed(2);
  320. })
  321. //获取微信信息,并配置微信api接口
  322. function wxGetSign(){
  323. var params = {};
  324. params.pageUrl = window.location.href;
  325. $.ajax(server + "weixin/getSign", {
  326. data: params,
  327. dataType: "json",
  328. type: "post",
  329. success: function(res){
  330. if (res.status == 200) {
  331. var t = res.data.timestamp;
  332. var noncestr = res.data.noncestr;
  333. var signature = res.data.signature;
  334. wx.config({
  335. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  336. appId: appId, // 必填,公众号的唯一标识
  337. timestamp: t, // 必填,生成签名的时间戳
  338. nonceStr: noncestr, // 必填,生成签名的随机串
  339. signature: signature,// 必填,签名,见附录1
  340. jsApiList: [
  341. 'closeWindow'
  342. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  343. });
  344. }
  345. }
  346. });
  347. }