var d = dialog({ contentType: 'load', skin: 'bk-popup' }); var request = GetRequest(); var code = request.code; //从链接中获得处方code var $selectBar = $("#selectBar"), $zqBar = $("#zqBar"), $notice = $("#notice"), $initNotice = $("#initNotice"), $zqInputPanel = $('#zqInputPanel'), $jgpsInputPanel = $("#jgpsInputPanel"), $expressInputPanel = $("#expressInputPanel"); var btnDisabled = true, //标记按钮是否是不可以使用 expressAddressInfo = {}, //记录配送信息 orgCode, //标记患者签约的机构code totalAmount = 0; var onlyGetBySelf = false, //只能自取 canJGPS = false, //是否有服务站,有服务站可以选择健管师配送 type, selectDate, //选择配送时间 patiCode; var selectedAddr, //选中的收药人地址信息 editAddrObj; //新增或者修改时选择的地址数据 // changeAddr = false; // 记录是否修改地址了 var picker; //地址下拉框变量 mui.init(); //初始化单页view var viewApi = mui('#app').view({ defaultPage: '#main' }); var view = viewApi.view; (function($) { //处理view的后退与webview后退 var oldBack = $.back; $.back = function() { if (viewApi.canBack()) { //如果view可以后退,则执行view的后退 viewApi.back(); } else { //执行webview后退 oldBack(); } }; //监听页面切换事件方案1,通过view元素监听所有页面切换事件,目前提供pageBeforeShow|pageShow|pageBeforeBack|pageBack四种事件(before事件为动画开始前触发) //第一个参数为事件名称,第二个参数为事件回调,其中e.detail.page为当前页面的html对象 view.addEventListener('pageBeforeShow', function(e) { console.log(e.detail.page.id + ' beforeShow'); if(e.detail.page.id == "addrList"){ document.title = '选择收药人'; //显示处方列表页面 getAddressList(); }else if(e.detail.page.id == "editPage"){ document.title = '编辑收药信息'; initExpressAddr(); if(editAddrObj){ fillEditData(); }else{ clearEditData(); } } else if(e.detail.page.id == "main"){ document.title = '续方订单支付'; fillSelectedAddr(); //计算运费 getExpressPrice(selectedAddr.province_name, selectedAddr.city_name); } }); //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; $('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); $('.mui-scroll-wrapper').pullRefresh(); })(mui); $(function(){ getInfo(); bindEvents(); }); function getInfo(){ var url = "/patient/prescriptionInfo/getPrescriptionProcess", params = {code: code}; sendPost(url, params, 'json', 'get', queryFailed, function(res){ if(res.status == 200){ //填充居民信息 var patientInfo = res.data.patient, patientInfoHtml = ""; patientInfoHtml = template('patientInfo_tmp', patientInfo); $("#patientInfo").empty().append(patientInfoHtml); patiCode = patientInfo.code; getPatientDefAddr(); //获取收药信息 orgCode = res.data.signFamily.hospital; getExpressInfo(); //填充订单信息内容 var drugsList = _.map(res.data.prescriptionInfo, function(o){ var sumPrice = 0; if(o.cost){ var cost = parseFloat(o.cost) / 100; // o.cost = cost; sumPrice = cost; } totalAmount += sumPrice; o.sumPrice = sumPrice.toFixed(2); return o; }); var drugsHtml = template('drug_tmp', {list: drugsList}); $("#drgusList").empty().append(drugsHtml); //填充挂号费信息 var fee = res.data.prescription.jwRegisterFee; if(!fee){ fee = 0; } fee = parseFloat(fee); totalAmount += fee; $("#registerFee").html('¥'+fee.toFixed(2)); $("#totalAmount").html('总金额:¥'+totalAmount.toFixed(2)); //判断是否超时 var status= res.data.prescription.status; if(status < 0){ $("#submitBtn").addClass("disabled"); $("#submitBtn").removeClass("bgc-47a8ef"); $("#submitBtn").addClass("bgc-ccc"); } }else{ queryFailed(res); } }); } //获得取药人默认地址 function getPatientDefAddr(){ var url = "/patient/prescription/pay/getDefAddress", params = {patient: patiCode}; sendPost(url, params, 'json', 'post', queryFailed, function(res){ if(res.status == 200){ if(res.data){ selectedAddr = res.data; fillSelectedAddr(); //计算运费 getExpressPrice(selectedAddr.province_name, selectedAddr.city_name); } }else{ queryFailed(res); } }); } //填充选中的地址信息 function fillSelectedAddr(){ var html = ''+selectedAddr.name+''+selectedAddr.phone+'', html2 = '
'+html+'
'+ selectedAddr.province_name+ selectedAddr.city_name + selectedAddr.town_name + selectedAddr.adress+'
'; //自取样式中填充 $("#zqInputPanel .getAddr").html(html); //快递配送填充 $("#expressInputPanel .getAddr").html(html2); //健管师配送填充 $("#jgpsInputPanel .getAddr").html(html); } //获得收药信息 function getExpressInfo(){ var url = '/patient/prescription/pay/dispatch', params = { prescriptionCode: code, orgCode: orgCode }; sendPost(url, params, 'json', 'post', queryFailed, function(res){ if(res.status == 200){ var types = res.data.types; //1-自取,2-快递配送,3-健管师配送,那种配送方式不能选时,即不返回该数据 //判断是否只能自取 if((types.length == 1) && (types.indexOf(1) > -1 )){ onlyGetBySelf = true; type = 1; } //判断是否可以选择健管师配送 if(types.indexOf(3) > -1){ canJGPS = true; } expressAddressInfo = res.data.self; var selfInfo = res.data.self, zqAddress = selfInfo.cityName+selfInfo.townName+selfInfo.address; $("#zqAddress").text(zqAddress); if(onlyGetBySelf){ $selectBar.hide(); $zqBar.show(); $notice.text('您的订单中存在有需冷藏保存的药品,为保证药品质量,该订单需要您到社区药房自取'); $notice.show(); $initNotice.hide(); $zqInputPanel.show(); $jgpsInputPanel.hide(); $expressInputPanel.hide(); }else{ $selectBar.show(); var initNotice; if(canJGPS){ initQYSelectData(); //初始化取药方式下拉框 initServiceStation(res.data.manager.codes); //初始化服务站下拉框 initNotice = '您可选择到社区药房自取、快递派送上门或由健管师配送至您附近的卫生服务站,健管师配送暂时免费,快递配送所产生的快递费用需由您承担'; }else{ initQYSelectData(true); initNotice = '您可选择到社区药房自取或快递派送上门,快递配送所产生的快递费用需由您承担'; } $initNotice.show(); $initNotice.text(initNotice); $zqBar.hide(); $notice.hide(); $zqInputPanel.hide(); $jgpsInputPanel.hide(); $expressInputPanel.hide(); } }else{ queryFailed(res); } }); } //初始化取药方式下拉框数据 noJGS - 判断是否没有健管师配送选项 function initQYSelectData(noJGS){ var keys = ['1', '2', '3'], values = ['自取', '快递派送', '健管师配送']; if(noJGS){ keys.splice(2,1); values.splice(2,1); } $('#qyfsSelect').mobiscroll({ theme: 'ios', lang: 'zh', customWheels: true, wheels: [ [{ keys: keys, values: values }] ], onSelect: function(valueText, inst){ $initNotice.hide(); var dd = eval("[" + valueText + "]"), k = dd[0].keys, v = dd[0].values; $('#qyfsSelect input').val(v); $('#qyfsSelect input').attr("data-value", k); type = k; if(k == 1){ $zqInputPanel.show(); $jgpsInputPanel.hide(); $expressInputPanel.hide(); } else if(k == 2){ $zqInputPanel.hide(); $jgpsInputPanel.hide(); $expressInputPanel.show(); $notice.show(); $notice.text('配药完成后将使用顺丰速运派送到您的收药地址,您需支付快递费用'); //初始化快递地址信息 // initExpressAddr(); } else { $zqInputPanel.hide(); $jgpsInputPanel.show(); $expressInputPanel.hide(); $notice.show(); $notice.text('健管师将把药送到您选择的服务站,您需要至服务站取药'); } } }); } //编辑地址时,数据填充 function fillEditData(){ $("#receiver").val(editAddrObj.name); $(".mobile").val(editAddrObj.phone); $("#addressSelect").find("input").val(editAddrObj.provinceName+editAddrObj.cityName+editAddrObj.townName); $("#address").val(editAddrObj.adress); $("#defaultFlag").prop("checked", (editAddrObj.defaultFlag == 1)); } //清空表单数据 function clearEditData(){ $("#receiver").val(''); $(".mobile").val(''); $("#addressSelect").find("input").val(''); $("#address").val(''); $("#defaultFlag").prop("checked", false); } //初始化服务站信息下拉选择框 function initServiceStation(data){ var keys = [], values = []; var addressObj = {}; for(i=0; i= 11){ //判断选择时间是否是今天 var text = type == 1 ? '取药' : '配送'; var todayStr = now.Format('yyyy-MM-dd'); if(todayStr == selectDate){ dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: '当前不可选择当天'+text+',请重新选择'+text+'时间' }).show(); return false; } } submitToPay(); }); //监听浏览器后退 window.addEventListener("popstate", function(e) { var state = e.state; if(state){ if(state.url == "#addrList"){ viewApi.go("#addrList"); } }else{ viewApi.go("#main"); } }, false); } 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(); } } //修改浏览器网页history信息 function pushHistory(pageName) { if(!pageName){ pageName = ""; } var state = { title: "title", url: "#"+pageName }; window.history.pushState(state, "title", "#"+pageName); }