123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- var d = dialog({
- contentType: 'load',
- skin: 'bk-popup'
- });
- var pagetype = 41;
- var request = GetRequest();
- var code = request.code; //从链接中获得处方code
- var toUser = request["toUser"];
- var toName = decodeURIComponent(request["toName"]);
- var openid = request["openid"];
- var represented = request["represented"];
- var userAgent = window.localStorage.getItem(agentName);
- var userInfo;
- $(function(){
- if(!userAgent) {
- localStorage.setItem("toUser",toUser);
- localStorage.setItem("prescriptionCode",code);
- window.location.href = "../../home/html/login.html?openid=" + openid+"&type="+pagetype;
- return false;
- }
- userInfo = JSON.parse(userAgent);
- initFamilyData();
- wxGetSign();
- });
- function initFamilyData () {
- //从微信模板消息进入
- if(represented && userAgent && toUser){
- if(toUser == represented){
- saveUserInfo(represented,userInfo.uid)
- }else if(toUser != represented && represented == userInfo.uid){
- //本人代理
- saveUserInfo(represented,newUaObj.uid)
- }else if(toUser != represented && toUser == userInfo.uid){
- //需要判定关系 200有授权 100家人 1无关系
- saveUserInfo(represented,userInfo.uid)
- }else{
- //重新登录
- relogin();
- }
- }else{
- //判断是否是本人的消息
- if(userInfo.uid != toUser){
- relogin();
- }else{
- getInfo();
- bindEvents();
- }
- }
- }
- //判断关系
- function hasFamilyRelation(a,b){
- return new Promise(function(resolve, reject) {
- var data={
- patient:a,
- familyMember:b
- }
- sendPost("patient/family/is_authorize", data, "json", "get", function(res){
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
- }, function(res){
- if(res.status == 200) {
- window.localStorage.setItem('nowPatientName',res.data.name);
- resolve(res)
- }else if(res.status == 100) {
- dialog({
- content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
- okValue:'切换账号',
- ok: function() {
- window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
- window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ request["openid"];
- },
- cancelValue: '我不看了',
- cancel: function () {
- wx.closeWindow();
- }
- }).showModal();
- }else{
- relogin();
- }
-
- })
- })
- }
- //重新登录操作
- function relogin(){
- dialog({
- content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
- okValue:'切换账号',
- ok: function() {
- window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
- window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ request["openid"];
- },
- cancelValue: '我不看了',
- cancel: function () {
- wx.closeWindow();
- }
- }).showModal();
- }
- //保存信息
- function saveUserInfo(a,b){
- Promise.all([hasFamilyRelation(a,b)]).then(function () {
- userInfo.represented = represented;
- window.localStorage.setItem(agentName,JSON.stringify(userInfo));
- getInfo();
- bindEvents();
- })
- }
- function getInfo(){
- var url = '/patient/prescription/prescriptionFollow',
- params = {prescriptionCode: code};
- sendPost(url, params,'json', 'get', queryFailed, function(res){
- if(res.status == 200){
- //如果是快递配送则没有取药码链接
- if(res.data.dispensaryDispensaryType == 2){
- $("#qyMa").hide();
- }else{
- if(res.data.prescriptionStatus < 60){
- //配药成功前,不显示取药码
- $("#qyMa").hide();
- }else{
- $("#qyMa").show();
- }
- }
- //居民端订单跟踪,针对取药方式为"居民自取"的订单,增加确认取药及延长收药功能
- if(res.data.dispensaryDispensaryType == 2 || res.data.dispensaryDispensaryType == 1){
- if(res.data.prescriptionStatus>=50 && res.data.prescriptionStatus<100){
- $('#handle-bar').css("display","-webkit-box");
- $('#waitqy').show();
- if(res.data.createTime){
- var nowDate = new Date();
- var confirmDate = new Date((res.data.payTime) + (res.data.extendCount+1)*(24*7*60*60*1000));
- var date3=confirmDate.getTime()-nowDate.getTime() //时间差的毫秒数
-
- if(date3>0){
- //计算出相差天数
- var days=Math.floor(date3/(24*3600*1000));
- //计算出小时数
- var leave1=date3%(24*3600*1000); //计算天数后剩余的毫秒数
- var hours=Math.floor(leave1/(3600*1000));
- if(days == 0 && hours == 0){
- $('#waitqy').hide();
- }else if(days == 0){
- $('#waitqy').show();
- $('#confirmDay').html(hours+'小时')
- }else if(hours == 0){
- $('#waitqy').show();
- $('#confirmDay').html(days+'天')
- }else{
- $('#waitqy').show();
- $('#confirmDay').html(days+'天'+hours+'小时')
- }
- }else{
- $('#waitqy').hide();
- }
- }
-
- }else{
- $('#handle-bar').hide();
- $('#waitqy').hide();
- }
- }
-
- //填充药品信息
- var drugList = res.data.prescriptionInfos,
- drugHtml = "";
- drugHtml = template("drug_tmp", {list: drugList});
- $("#drugsList").empty().append(drugHtml);
-
- if(res.data.prescriptionPay){
- //填充订单记录信息
- var orderInfo = {
- ordersn: res.data.prescriptionPay.code,
- dept: res.data.prescriptionHospital,
- status: res.data.prescriptionStatus
- },
- orderHtml = "";
- orderHtml = template("orderInfo_tmp", orderInfo);
- $("#orderInfo").empty().append(orderHtml);
- }
-
- if(res.data.dispensaryDispensaryType){
- //填充收药信息
- var recieveInfo = res.data.prescriptionExpressage;
- recieveInfo.dispensaryType = res.data.dispensaryDispensaryType;
- recieveInfo.dispensaryTypeName = res.data.dispensaryDispensaryTypeName;
- var recieveInfoHtml = template('recieveInfo_tmp', recieveInfo);
- $("#recieveInfo").empty().append(recieveInfoHtml);
- }
-
- if(res.data.prescriptionPay){
- //填充支付记录信息
- var paymentInfo = res.data.prescriptionPay,
- paymentHtml = template('paymentInfo_tmp', paymentInfo);
- $("#paymentInfo").empty().append(paymentHtml);
- }
-
-
- }else{
- queryFailed(res);
- }
- });
- }
- function delayMedicine(type){
- var url = '/patient/prescription/confirmReceipt'
- params = {
- prescriptionCode: code,
- type:type
- };
- sendPost(url, params, 'json', 'post', queryFailed, function(res){
- if(res.status == 200){
- getInfo();
- if(type==1){
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: res.msg
- }).show();
- }else{
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: res.msg
- }).show();
- }
- }else{
- queryFailed(res);
- }
- });
- }
- //获得订单跟踪数据
- function getOrderLogs(){
- var url = "/patient/prescriptionlog/orderFollow",
- params = {prescriptionCode: code};
- sendPost(url, params, 'json', 'get', queryFailed, function(res){
- if(res.status == 200){
- var html = template("orderLog_tmp", {list: res.data});
- $("#orderLogs").empty().append(html);
- $(".modal-content").show();
- }else{
- queryFailed(res);
- }
- });
- }
- function bindEvents(){
- //续方记录
- $("#xfRecord").on('click', function(){
- window.location.href = 're-prescription_info.html?code='+code+'&toUser='+userInfo.uid;
- });
-
- //取药码
- $("#qyMa").on('click', function(){
- window.location.href = 'code-detail.html?prescriptionCode='+code;
- });
-
- //快递记录
- $("#recieveInfo").on('click', '#expressInfo', function(res){
- var mailno = $(this).attr("data-code");
- window.location.href = "express_info.html?code="+code;
- });
-
- //订单状态
- $("#orderInfo").on('click', "#orderStatus", function(){
- $(".mask").show();
- //获取订单跟踪时间轴信息
- getOrderLogs();
- });
-
- //关闭按钮
- $("#closeBtn").on('click', function(){
- $(".mask").hide();
- $(".modal-content").hide();
- });
-
- //点击延长收药
- $('.delaysy').on('tap',function(){
- dialog({
- content: "<div style='font-weight:600'>确认延长收药时间?</div>确认后自动收药时间将延长一周,每笔订单只能延长一次哦",
- okValue:'确认',
- ok: function (){
- delayMedicine(2);
- },
- cancelValue: '取消',
- cancel: function () {
- // wx.closeWindow();
- }
- }).showModal();
- })
- //点击确认收药
- $('.confirmsy').on('tap',function(){
- dialog({
- content: "<div style='font-weight:600'>确认已收药?</div>确认后订单将自动完成哦",
- okValue:'确认',
- ok: function (){
- delayMedicine(1);
- },
- cancelValue: '取消',
- cancel: function () {
- // wx.closeWindow();
- }
- }).showModal();
- })
- }
- function queryFailed(res){
- d.close();
- if(res && res.msg) {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: res.msg
- }).show();
- } else {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '加载失败'
- }).show();
- }
- }
- template.helper("getStatusName", function(status){
- return getStatusName(status);
- });
- template.helper('getTypeName', function(type){
- switch(type){
- case 1:
- return "医保支付";
- break;
- default:
- return "";
- break;
- }
- });
- template.helper('formatMoney', function(money){
- var amount = money / 100;
- return amount.toFixed(2);
- })
- //获取微信信息,并配置微信api接口
- function wxGetSign(){
- var params = {};
- params.pageUrl = window.location.href;
- $.ajax(server + "weixin/getSign", {
- data: params,
- dataType: "json",
- type: "post",
- success: function(res){
- if (res.status == 200) {
- var t = res.data.timestamp;
- var noncestr = res.data.noncestr;
- var signature = res.data.signature;
- wx.config({
- //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
- appId: appId, // 必填,公众号的唯一标识
- timestamp: t, // 必填,生成签名的时间戳
- nonceStr: noncestr, // 必填,生成签名的随机串
- signature: signature,// 必填,签名,见附录1
- jsApiList: [
- 'closeWindow'
- ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
- }
- }
- });
- }
|