123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789 |
- 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 = '<span class="mr30 c-f14">'+selectedAddr.name+'</span><span class="c-f14">'+selectedAddr.phone+'</span>',
- html2 = '<div>'+html+'</div><div class="c-f14">'+
- selectedAddr.province_name+ selectedAddr.city_name + selectedAddr.town_name +
- selectedAddr.adress+'</div>';
-
- //自取样式中填充
- $("#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<data.length; i++){
- var item = data[i];
- keys.push(item.code);
- values.push(item.name);
- addressObj[item.code] = {};
- addressObj[item.code]['fullAddress'] = item.cityName+item.townName+item.address;
- addressObj[item.code]['obj'] = item;
- }
-
- $("#serviceStation").mobiscroll({
- theme: 'ios',
- lang: 'zh',
- customWheels: true,
- wheels: [
- [{
- keys: keys,
- values: values
- }]
- ],
- onSelect: function(valueText, inst){
- var dd = eval("[" + valueText + "]"),
- k = dd[0].keys,
- v = dd[0].values;
- $('#serviceStation input').val(v);
- $('#serviceStation input').attr("data-value", k);
- $("#serviceAdress input").val(addressObj[k]['fullAddress']);
- expressAddressInfo = addressObj[k]['obj'];
- $("#serviceAdress").show();
- }
- });
- }
- //初始化快递地址选择下拉框数据
- function initExpressAddr(){
- picker = new mui.PopPicker({
- layer: 3,
- layerNames: ["省","市","区"]
- });
-
- //获取省份信息
- getDistrict(1, '', 0);
- bindPickerEvent();
- }
- //绑定picker的事件
- function bindPickerEvent(){
- $(picker.pickers[0].holder).on('change', function(event) {
- var eventData = event.originalEvent.detail || {},
- item = eventData.item;
-
- if(!item || !item.value) {
- return ;
- }
- //获取市信息
- getDistrict(2, item.value, 1);
- });
-
- $(picker.pickers[1].holder).on('change', function(event) {
- var eventData = event.originalEvent.detail || {},
- item = eventData.item;
- if(!item || !item.value) {
- return ;
- }
- getDistrict(3, item.value, 2);
- })
- }
- /**
- * 获得省市区数据
- * @param {number} type 1-省,2-市,3-区
- * @param {string} code 省市对应的code
- * @param {number} level 对应下拉框对应的列 0-省,1-市,2-区
- */
- function getDistrict(type, code, level){
- var url = 'common/district',
- params = {type: type, code: code};
- sendPost(url, params, 'json', 'post', queryFailed, function(res){
- if(res.status == 200){
- var data = _.map(res.list, function(o){
- return {
- value: o.code,
- text: o.name
- }
- });
- picker.pickers[level].setItems(data);
- }else{
- queryFailed(res);
- }
- });
- }
- //查询派送地址是否属于顺丰的派送范围
- function checkOrderService(address){
- var url = "/patient/sfexpress/sforderfilterservice",
- params = {
- d_address: $("#addressSelect .select-input").val()+address
- };
- sendPost(url, params, 'json', 'get', queryFailed, function(res){
- if(res.status == 200){
- //在配送范围内
- }else{
- //不在配送范围内
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '您填写的地址不在配送范围内,请填写其他地址'
- }).show();
- }
- });
- }
- //根据省,市信息获得邮费
- function getExpressPrice(province, city){
- var url = '/patient/sfexpress/getsfexpressprice',
- params = {
- d_province: province,
- d_city: city
- };
- sendPost(url, params, 'json', 'get', queryFailed, function(res){
- if(res.status == 200){
- $("#expressPrice").text(res.data.firstWeightPrice);
- }else{
- queryFailed(res);
- }
- });
- }
- //提交支付
- function submitToPay(){
- //首先判断是否绑定的电子社保卡
- checkBindStatus();
- // hard code 去支付页面
- // charge();
- }
- //判断是否有绑卡
- function checkBindStatus(){
- d.show();
- var url = "/patient/bindCard";
- sendPost(url, {}, 'json', 'post', queryFailed, function(res){
- d.close();
- if(res.data.bindStatus == '000000'){ //已绑卡
- //跳转去支付页面
- //先获取缴费金额信息,然后再组装支付信息
- charge();
- }else if(res.data.bindStatus == '030007'){//未绑卡
- //跳转去绑卡链接
- var bindUrl = res.data.sicardUrl;
- window.location.href = bindUrl;
- }
- });
- }
- function charge(){
- d.show();
- var url = '/patient/prescription/pay/recipeCharge',
- params = {
- orgCode: orgCode, //患者签约医院code
- prescriptionCode: code,
- type: type, //配送方式 1:自取 2:快递 3:健管师配送
- addressJson: JSON.stringify(expressAddressInfo), //配送信息
- totalAmount: Math.ceil(totalAmount * 100),
- deliveryTime: selectDate,
- returnUrl: '/wx/html/prescription/html/pay_return.html'
- };
-
- sendPost(url, params, 'json', 'post', queryFailed, function(res){
- if(res.status == 200){
- d.close();
- window.localStorage.setItem('expressType', $('#qyfsSelect input').attr("data-value"));
- window.location.href = res.data.payUrl; //跳转去支付页面
- //hard code 去支付回调页面
- // window.location.href = 'pay_return.html?outChargeNo='+res.data.outChargeNo+'&tradeStatus=0';
- }else{
- queryFailed(res);
- }
- });
- }
- //================================ 收货人地址管理页面方法 ==========================
- function getAddressList(){
- var url = "/patient/prescription/pay/getAddressList",
- params = {patient: patiCode};
- sendPost(url, params, 'json', 'post', queryFailed, function(res){
- if(res.status == 200){
- if(res.data.length == 0){
- $(".div-no-info").show();
- $("#addrUl").hide();
- }else{
- $(".div-no-info").hide();
- var list = _.map(res.data, function(o){
- o.jsonStr = JSON.stringify(o);
- return o;
- });
- var html = template('addr_tmp', {list: list});
- $("#addrUl").empty().append(html);
- $("#addrUl").show();
- }
- }else{
- queryFailed(res);
- }
- });
- }
- //保存地址
- function saveAddress(){
- d.show();
- var url = "/patient/prescription/pay/saveAddress",
- params = {addressJson: JSON.stringify(editAddrObj)};
- sendPost(url, params, 'json', 'post', queryFailed, function(res){
- if(res.status == 200){
- d.close();
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '保存成功'
- }).show();
- editAddrObj = null;
- // viewApi.back();
- window.history.back();
- }else{
- queryFailed(res);
- }
- });
- }
- //删除地址
- function delAddress(){
- d.show();
- var url = "/patient/prescription/pay/delAddress",
- params = {id: editAddrObj.id};
- sendPost(url, params, 'json', 'post', queryFailed, function(res){
- if(res.status == 200){
- d.close();
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '删除成功'
- }).show();
- editAddrObj = null;
- window.history.back();
- }else{
- queryFailed(res);
- }
- });
- }
- function bindEvents(){
- //时间控件
- var d = new Date(),
- end = new Date();
- end.setDate(d.getDate() + 5);
- $("input[data-type=date]").mobiscroll({
- preset: 'date',
- theme: 'ios',
- lang: 'zh',
- minDate: d,
- maxDate: end,
- onSelect: function(valueText, inst){
- $(this).val(valueText);
- selectDate = valueText;
- }
- });
-
- //选择地址下拉框
- $("#addressSelect").on('tap', function(){
- picker.show(function(selected){
- //选中后的回调页面
- console.log(selected);
- var text = selected[0].text+selected[1].text+selected[2].text;
- $("#addressSelect .select-input").val(text);
-
- editAddrObj = {
- provinceName: selected[0].text,
- province: selected[0].value,
- cityName: selected[1].text,
- city: selected[1].value,
- townName: selected[2].text,
- town: selected[2].value
- }
- });
- });
-
- $(".getAddr").on('tap', function(){
- viewApi.go('#addrList');
- pushHistory("addrList");
- });
-
- $(".add-btn").on('tap', function(){
- viewApi.go('#editPage');
- pushHistory("editPage");
- });
-
- //地址列表点击事件
- $("#addrUl").on('tap', 'li .c-list-info', function(){
- var jsonStr = $(this).parent().data("json");
- if(jsonStr){
- selectedAddr = jsonStr;
- // viewApi.back();
- window.history.back();
- }
- });
-
- $("#addrUl").on('tap', 'li .c-list-key', function(){
- var jsonStr = $(this).parent().data("json");
- if(jsonStr){
- editAddrObj = {
- id: jsonStr.id,
- provinceName: jsonStr.province_name,
- province: jsonStr.province,
- cityName: jsonStr.city_name,
- city: jsonStr.city,
- townName: jsonStr.town_name,
- town: jsonStr.town,
- name: jsonStr.name,
- phone: jsonStr.phone,
- adress: jsonStr.adress,
- defaultFlag: jsonStr.default_flag
- };
- viewApi.go("#editPage");
- pushHistory("editPage");
- }
- })
-
- $("#saveAddr").on('tap', function(){
- var district = $("#addressSelect input").val(),
- address = $("#address").val(),
- mobile = $(".mobile").val();
- if((district.length == 0) || (address.length == 0)){
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '请填写收药地址'
- }).show();
- return false;
- }
- if($("#receiver").val().trim().length == 0){
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '请填写收药人姓名'
- }).show();
- return false;
- }
- if(!isphone(mobile)){
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '请填写正确的手机号码'
- }).show();
- return false;
- }
- var defaultFlag = $("#defaultFlag").prop("checked");
-
- editAddrObj.patient = patiCode;
- editAddrObj.name = $("#receiver").val().trim();
- editAddrObj.phone = $(".mobile").val();
- editAddrObj.defaultFlag = defaultFlag? 1: 0;
- editAddrObj.adress = $("#address").val()
- saveAddress();
- });
-
- $("#delAddr").on('tap', function(){
- if(!editAddrObj.id){
- return false;
- }
- delAddress();
- });
-
- $("#submitBtn").on('tap', function(){
- if($(this).hasClass("disabled")){
- return false;
- }
- //判断是否选择了配送地址
- var $serviceStation = $('#serviceStation input');
-
- //判断是否填写了地址信息
- if(!selectedAddr){
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '请选择收药人信息'
- }).show();
- return false;
- }
- if(!onlyGetBySelf){
- if(!type){
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '请选择配送方式'
- }).show();
- return false;
- }
- if(type == 2){
- expressAddressInfo = {
- provinceName: selectedAddr.province_name,
- provinceCode: selectedAddr.province,
- cityName: selectedAddr.city_name,
- cityCode: selectedAddr.city,
- townName: selectedAddr.town_name,
- townCode: selectedAddr.town,
- address: selectedAddr.adress,
- phone: selectedAddr.phone,
- receiver: selectedAddr.name
- }
- checkOrderService(selectedAddr.adress);
- }else if(type == 3){
- if($serviceStation.val().length == 0){
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: '请选择配送服务站'
- }).show();
- return false;
- }
- expressAddressInfo.phone = selectedAddr.phone;
- }else{
- expressAddressInfo.phone = selectedAddr.phone;
- }
- }else{
- expressAddressInfo.phone = selectedAddr.phone;
- }
-
- //判断当前时间是否在11点前
- var now = new Date();
- if(now.getHours() >= 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);
- }
|