payment.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. var d = dialog({
  2. contentType: 'load',
  3. skin: 'bk-popup'
  4. });
  5. var request = GetRequest();
  6. var code = request.code; //从链接中获得处方code
  7. var $selectBar = $("#selectBar"),
  8. $zqBar = $("#zqBar"),
  9. $notice = $("#notice"),
  10. $initNotice = $("#initNotice"),
  11. $zqInputPanel = $('#zqInputPanel'),
  12. $jgpsInputPanel = $("#jgpsInputPanel"),
  13. $expressInputPanel = $("#expressInputPanel");
  14. var btnDisabled = true, //标记按钮是否是不可以使用
  15. expressAddressInfo = {}, //记录配送信息
  16. orgCode, //标记患者签约的机构code
  17. totalAmount = 0;
  18. var onlyGetBySelf = false, //只能自取
  19. canJGPS = false, //是否有服务站,有服务站可以选择健管师配送
  20. type,
  21. selectDate, //选择配送时间
  22. patiCode;
  23. var selectedAddr, //选中的收药人地址信息
  24. editAddrObj; //新增或者修改时选择的地址数据
  25. // changeAddr = false; // 记录是否修改地址了
  26. var picker; //地址下拉框变量
  27. mui.init();
  28. //初始化单页view
  29. var viewApi = mui('#app').view({
  30. defaultPage: '#main'
  31. });
  32. var view = viewApi.view;
  33. (function($) {
  34. //处理view的后退与webview后退
  35. var oldBack = $.back;
  36. $.back = function() {
  37. if (viewApi.canBack()) { //如果view可以后退,则执行view的后退
  38. viewApi.back();
  39. } else { //执行webview后退
  40. oldBack();
  41. }
  42. };
  43. //监听页面切换事件方案1,通过view元素监听所有页面切换事件,目前提供pageBeforeShow|pageShow|pageBeforeBack|pageBack四种事件(before事件为动画开始前触发)
  44. //第一个参数为事件名称,第二个参数为事件回调,其中e.detail.page为当前页面的html对象
  45. view.addEventListener('pageBeforeShow', function(e) {
  46. console.log(e.detail.page.id + ' beforeShow');
  47. if(e.detail.page.id == "addrList"){
  48. document.title = '选择收药人';
  49. //显示处方列表页面
  50. getAddressList();
  51. }else if(e.detail.page.id == "editPage"){
  52. document.title = '编辑收药信息';
  53. initExpressAddr();
  54. if(editAddrObj){
  55. fillEditData();
  56. }else{
  57. clearEditData();
  58. }
  59. }
  60. else if(e.detail.page.id == "main"){
  61. document.title = '续方订单支付';
  62. fillSelectedAddr();
  63. //计算运费
  64. getExpressPrice(selectedAddr.province_name, selectedAddr.city_name);
  65. }
  66. });
  67. //阻尼系数
  68. var deceleration = mui.os.ios?0.003:0.0009;
  69. $('.mui-scroll-wrapper').scroll({
  70. bounce: false,
  71. indicators: true, //是否显示滚动条
  72. deceleration:deceleration
  73. });
  74. $('.mui-scroll-wrapper').pullRefresh();
  75. })(mui);
  76. $(function(){
  77. getInfo();
  78. bindEvents();
  79. });
  80. function getInfo(){
  81. var url = "/patient/prescriptionInfo/getPrescriptionProcess",
  82. params = {code: code};
  83. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  84. if(res.status == 200){
  85. //填充居民信息
  86. var patientInfo = res.data.patient,
  87. patientInfoHtml = "";
  88. patientInfoHtml = template('patientInfo_tmp', patientInfo);
  89. $("#patientInfo").empty().append(patientInfoHtml);
  90. patiCode = patientInfo.code;
  91. getPatientDefAddr();
  92. //获取收药信息
  93. orgCode = res.data.signFamily.hospital;
  94. getExpressInfo();
  95. //填充订单信息内容
  96. var drugsList = _.map(res.data.prescriptionInfo, function(o){
  97. var sumPrice = 0;
  98. if(o.cost){
  99. var cost = parseFloat(o.cost) / 100;
  100. // o.cost = cost;
  101. sumPrice = cost;
  102. }
  103. totalAmount += sumPrice;
  104. o.sumPrice = sumPrice.toFixed(2);
  105. return o;
  106. });
  107. var drugsHtml = template('drug_tmp', {list: drugsList});
  108. $("#drgusList").empty().append(drugsHtml);
  109. //填充挂号费信息
  110. var fee = res.data.prescription.jwRegisterFee;
  111. if(!fee){
  112. fee = 0;
  113. }
  114. fee = parseFloat(fee);
  115. totalAmount += fee;
  116. $("#registerFee").html('¥'+fee.toFixed(2));
  117. $("#totalAmount").html('总金额:¥'+totalAmount.toFixed(2));
  118. //判断是否超时
  119. var status= res.data.prescription.status;
  120. if(status < 0){
  121. $("#submitBtn").addClass("disabled");
  122. $("#submitBtn").removeClass("bgc-47a8ef");
  123. $("#submitBtn").addClass("bgc-ccc");
  124. }
  125. }else{
  126. queryFailed(res);
  127. }
  128. });
  129. }
  130. //获得取药人默认地址
  131. function getPatientDefAddr(){
  132. var url = "/patient/prescription/pay/getDefAddress",
  133. params = {patient: patiCode};
  134. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  135. if(res.status == 200){
  136. if(res.data){
  137. selectedAddr = res.data;
  138. fillSelectedAddr();
  139. //计算运费
  140. getExpressPrice(selectedAddr.province_name, selectedAddr.city_name);
  141. }
  142. }else{
  143. queryFailed(res);
  144. }
  145. });
  146. }
  147. //填充选中的地址信息
  148. function fillSelectedAddr(){
  149. var html = '<span class="mr30 c-f14">'+selectedAddr.name+'</span><span class="c-f14">'+selectedAddr.phone+'</span>',
  150. html2 = '<div>'+html+'</div><div class="c-f14">'+
  151. selectedAddr.province_name+ selectedAddr.city_name + selectedAddr.town_name +
  152. selectedAddr.adress+'</div>';
  153. //自取样式中填充
  154. $("#zqInputPanel .getAddr").html(html);
  155. //快递配送填充
  156. $("#expressInputPanel .getAddr").html(html2);
  157. //健管师配送填充
  158. $("#jgpsInputPanel .getAddr").html(html);
  159. }
  160. //获得收药信息
  161. function getExpressInfo(){
  162. var url = '/patient/prescription/pay/dispatch',
  163. params = {
  164. prescriptionCode: code,
  165. orgCode: orgCode
  166. };
  167. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  168. if(res.status == 200){
  169. var types = res.data.types; //1-自取,2-快递配送,3-健管师配送,那种配送方式不能选时,即不返回该数据
  170. //判断是否只能自取
  171. if((types.length == 1) && (types.indexOf(1) > -1 )){
  172. onlyGetBySelf = true;
  173. type = 1;
  174. }
  175. //判断是否可以选择健管师配送
  176. if(types.indexOf(3) > -1){
  177. canJGPS = true;
  178. }
  179. expressAddressInfo = res.data.self;
  180. var selfInfo = res.data.self,
  181. zqAddress = selfInfo.cityName+selfInfo.townName+selfInfo.address;
  182. $("#zqAddress").text(zqAddress);
  183. if(onlyGetBySelf){
  184. $selectBar.hide();
  185. $zqBar.show();
  186. $notice.text('您的订单中存在有需冷藏保存的药品,为保证药品质量,该订单需要您到社区药房自取');
  187. $notice.show();
  188. $initNotice.hide();
  189. $zqInputPanel.show();
  190. $jgpsInputPanel.hide();
  191. $expressInputPanel.hide();
  192. }else{
  193. $selectBar.show();
  194. var initNotice;
  195. if(canJGPS){
  196. initQYSelectData(); //初始化取药方式下拉框
  197. initServiceStation(res.data.manager.codes); //初始化服务站下拉框
  198. initNotice = '您可选择到社区药房自取、快递派送上门或由健管师配送至您附近的卫生服务站,健管师配送暂时免费,快递配送所产生的快递费用需由您承担';
  199. }else{
  200. initQYSelectData(true);
  201. initNotice = '您可选择到社区药房自取或快递派送上门,快递配送所产生的快递费用需由您承担';
  202. }
  203. $initNotice.show();
  204. $initNotice.text(initNotice);
  205. $zqBar.hide();
  206. $notice.hide();
  207. $zqInputPanel.hide();
  208. $jgpsInputPanel.hide();
  209. $expressInputPanel.hide();
  210. }
  211. }else{
  212. queryFailed(res);
  213. }
  214. });
  215. }
  216. //初始化取药方式下拉框数据 noJGS - 判断是否没有健管师配送选项
  217. function initQYSelectData(noJGS){
  218. var keys = ['1', '2', '3'],
  219. values = ['自取', '快递派送', '健管师配送'];
  220. if(noJGS){
  221. keys.splice(2,1);
  222. values.splice(2,1);
  223. }
  224. $('#qyfsSelect').mobiscroll({
  225. theme: 'ios',
  226. lang: 'zh',
  227. customWheels: true,
  228. wheels: [
  229. [{
  230. keys: keys,
  231. values: values
  232. }]
  233. ],
  234. onSelect: function(valueText, inst){
  235. $initNotice.hide();
  236. var dd = eval("[" + valueText + "]"),
  237. k = dd[0].keys,
  238. v = dd[0].values;
  239. $('#qyfsSelect input').val(v);
  240. $('#qyfsSelect input').attr("data-value", k);
  241. type = k;
  242. if(k == 1){
  243. $zqInputPanel.show();
  244. $jgpsInputPanel.hide();
  245. $expressInputPanel.hide();
  246. } else if(k == 2){
  247. $zqInputPanel.hide();
  248. $jgpsInputPanel.hide();
  249. $expressInputPanel.show();
  250. $notice.show();
  251. $notice.text('配药完成后将使用顺丰速运派送到您的收药地址,您需支付快递费用');
  252. //初始化快递地址信息
  253. // initExpressAddr();
  254. } else {
  255. $zqInputPanel.hide();
  256. $jgpsInputPanel.show();
  257. $expressInputPanel.hide();
  258. $notice.show();
  259. $notice.text('健管师将把药送到您选择的服务站,您需要至服务站取药');
  260. }
  261. }
  262. });
  263. }
  264. //编辑地址时,数据填充
  265. function fillEditData(){
  266. $("#receiver").val(editAddrObj.name);
  267. $(".mobile").val(editAddrObj.phone);
  268. $("#addressSelect").find("input").val(editAddrObj.provinceName+editAddrObj.cityName+editAddrObj.townName);
  269. $("#address").val(editAddrObj.adress);
  270. $("#defaultFlag").prop("checked", (editAddrObj.defaultFlag == 1));
  271. }
  272. //清空表单数据
  273. function clearEditData(){
  274. $("#receiver").val('');
  275. $(".mobile").val('');
  276. $("#addressSelect").find("input").val('');
  277. $("#address").val('');
  278. $("#defaultFlag").prop("checked", false);
  279. }
  280. //初始化服务站信息下拉选择框
  281. function initServiceStation(data){
  282. var keys = [],
  283. values = [];
  284. var addressObj = {};
  285. for(i=0; i<data.length; i++){
  286. var item = data[i];
  287. keys.push(item.code);
  288. values.push(item.name);
  289. addressObj[item.code] = {};
  290. addressObj[item.code]['fullAddress'] = item.cityName+item.townName+item.address;
  291. addressObj[item.code]['obj'] = item;
  292. }
  293. $("#serviceStation").mobiscroll({
  294. theme: 'ios',
  295. lang: 'zh',
  296. customWheels: true,
  297. wheels: [
  298. [{
  299. keys: keys,
  300. values: values
  301. }]
  302. ],
  303. onSelect: function(valueText, inst){
  304. var dd = eval("[" + valueText + "]"),
  305. k = dd[0].keys,
  306. v = dd[0].values;
  307. $('#serviceStation input').val(v);
  308. $('#serviceStation input').attr("data-value", k);
  309. $("#serviceAdress input").val(addressObj[k]['fullAddress']);
  310. expressAddressInfo = addressObj[k]['obj'];
  311. $("#serviceAdress").show();
  312. }
  313. });
  314. }
  315. //初始化快递地址选择下拉框数据
  316. function initExpressAddr(){
  317. picker = new mui.PopPicker({
  318. layer: 3,
  319. layerNames: ["省","市","区"]
  320. });
  321. //获取省份信息
  322. getDistrict(1, '', 0);
  323. bindPickerEvent();
  324. }
  325. //绑定picker的事件
  326. function bindPickerEvent(){
  327. $(picker.pickers[0].holder).on('change', function(event) {
  328. var eventData = event.originalEvent.detail || {},
  329. item = eventData.item;
  330. if(!item || !item.value) {
  331. return ;
  332. }
  333. //获取市信息
  334. getDistrict(2, item.value, 1);
  335. });
  336. $(picker.pickers[1].holder).on('change', function(event) {
  337. var eventData = event.originalEvent.detail || {},
  338. item = eventData.item;
  339. if(!item || !item.value) {
  340. return ;
  341. }
  342. getDistrict(3, item.value, 2);
  343. })
  344. }
  345. /**
  346. * 获得省市区数据
  347. * @param {number} type 1-省,2-市,3-区
  348. * @param {string} code 省市对应的code
  349. * @param {number} level 对应下拉框对应的列 0-省,1-市,2-区
  350. */
  351. function getDistrict(type, code, level){
  352. var url = 'common/district',
  353. params = {type: type, code: code};
  354. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  355. if(res.status == 200){
  356. var data = _.map(res.list, function(o){
  357. return {
  358. value: o.code,
  359. text: o.name
  360. }
  361. });
  362. picker.pickers[level].setItems(data);
  363. }else{
  364. queryFailed(res);
  365. }
  366. });
  367. }
  368. //查询派送地址是否属于顺丰的派送范围
  369. function checkOrderService(address){
  370. var url = "/patient/sfexpress/sforderfilterservice",
  371. params = {
  372. d_address: $("#addressSelect .select-input").val()+address
  373. };
  374. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  375. if(res.status == 200){
  376. //在配送范围内
  377. }else{
  378. //不在配送范围内
  379. dialog({
  380. contentType: 'tipsbox',
  381. skin: 'bk-popup',
  382. content: '您填写的地址不在配送范围内,请填写其他地址'
  383. }).show();
  384. }
  385. });
  386. }
  387. //根据省,市信息获得邮费
  388. function getExpressPrice(province, city){
  389. var url = '/patient/sfexpress/getsfexpressprice',
  390. params = {
  391. d_province: province,
  392. d_city: city
  393. };
  394. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  395. if(res.status == 200){
  396. $("#expressPrice").text(res.data.firstWeightPrice);
  397. }else{
  398. queryFailed(res);
  399. }
  400. });
  401. }
  402. //提交支付
  403. function submitToPay(){
  404. //首先判断是否绑定的电子社保卡
  405. checkBindStatus();
  406. // hard code 去支付页面
  407. // charge();
  408. }
  409. //判断是否有绑卡
  410. function checkBindStatus(){
  411. d.show();
  412. var url = "/patient/bindCard";
  413. sendPost(url, {}, 'json', 'post', queryFailed, function(res){
  414. d.close();
  415. if(res.data.bindStatus == '000000'){ //已绑卡
  416. //跳转去支付页面
  417. //先获取缴费金额信息,然后再组装支付信息
  418. charge();
  419. }else if(res.data.bindStatus == '030007'){//未绑卡
  420. //跳转去绑卡链接
  421. var bindUrl = res.data.sicardUrl;
  422. window.location.href = bindUrl;
  423. }
  424. });
  425. }
  426. function charge(){
  427. d.show();
  428. var url = '/patient/prescription/pay/recipeCharge',
  429. params = {
  430. orgCode: orgCode, //患者签约医院code
  431. prescriptionCode: code,
  432. type: type, //配送方式 1:自取 2:快递 3:健管师配送
  433. addressJson: JSON.stringify(expressAddressInfo), //配送信息
  434. totalAmount: Math.ceil(totalAmount * 100),
  435. deliveryTime: selectDate,
  436. returnUrl: '/wx/html/prescription/html/pay_return.html'
  437. };
  438. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  439. if(res.status == 200){
  440. d.close();
  441. window.localStorage.setItem('expressType', $('#qyfsSelect input').attr("data-value"));
  442. window.location.href = res.data.payUrl; //跳转去支付页面
  443. //hard code 去支付回调页面
  444. // window.location.href = 'pay_return.html?outChargeNo='+res.data.outChargeNo+'&tradeStatus=0';
  445. }else{
  446. queryFailed(res);
  447. }
  448. });
  449. }
  450. //================================ 收货人地址管理页面方法 ==========================
  451. function getAddressList(){
  452. var url = "/patient/prescription/pay/getAddressList",
  453. params = {patient: patiCode};
  454. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  455. if(res.status == 200){
  456. if(res.data.length == 0){
  457. $(".div-no-info").show();
  458. $("#addrUl").hide();
  459. }else{
  460. $(".div-no-info").hide();
  461. var list = _.map(res.data, function(o){
  462. o.jsonStr = JSON.stringify(o);
  463. return o;
  464. });
  465. var html = template('addr_tmp', {list: list});
  466. $("#addrUl").empty().append(html);
  467. $("#addrUl").show();
  468. }
  469. }else{
  470. queryFailed(res);
  471. }
  472. });
  473. }
  474. //保存地址
  475. function saveAddress(){
  476. d.show();
  477. var url = "/patient/prescription/pay/saveAddress",
  478. params = {addressJson: JSON.stringify(editAddrObj)};
  479. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  480. if(res.status == 200){
  481. d.close();
  482. dialog({
  483. contentType: 'tipsbox',
  484. skin: 'bk-popup',
  485. content: '保存成功'
  486. }).show();
  487. editAddrObj = null;
  488. // viewApi.back();
  489. window.history.back();
  490. }else{
  491. queryFailed(res);
  492. }
  493. });
  494. }
  495. //删除地址
  496. function delAddress(){
  497. d.show();
  498. var url = "/patient/prescription/pay/delAddress",
  499. params = {id: editAddrObj.id};
  500. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  501. if(res.status == 200){
  502. d.close();
  503. dialog({
  504. contentType: 'tipsbox',
  505. skin: 'bk-popup',
  506. content: '删除成功'
  507. }).show();
  508. editAddrObj = null;
  509. window.history.back();
  510. }else{
  511. queryFailed(res);
  512. }
  513. });
  514. }
  515. function bindEvents(){
  516. //时间控件
  517. var d = new Date(),
  518. end = new Date();
  519. end.setDate(d.getDate() + 5);
  520. $("input[data-type=date]").mobiscroll({
  521. preset: 'date',
  522. theme: 'ios',
  523. lang: 'zh',
  524. minDate: d,
  525. maxDate: end,
  526. onSelect: function(valueText, inst){
  527. $(this).val(valueText);
  528. selectDate = valueText;
  529. }
  530. });
  531. //选择地址下拉框
  532. $("#addressSelect").on('tap', function(){
  533. picker.show(function(selected){
  534. //选中后的回调页面
  535. console.log(selected);
  536. var text = selected[0].text+selected[1].text+selected[2].text;
  537. $("#addressSelect .select-input").val(text);
  538. editAddrObj = {
  539. provinceName: selected[0].text,
  540. province: selected[0].value,
  541. cityName: selected[1].text,
  542. city: selected[1].value,
  543. townName: selected[2].text,
  544. town: selected[2].value
  545. }
  546. });
  547. });
  548. $(".getAddr").on('tap', function(){
  549. viewApi.go('#addrList');
  550. pushHistory("addrList");
  551. });
  552. $(".add-btn").on('tap', function(){
  553. viewApi.go('#editPage');
  554. pushHistory("editPage");
  555. });
  556. //地址列表点击事件
  557. $("#addrUl").on('tap', 'li .c-list-info', function(){
  558. var jsonStr = $(this).parent().data("json");
  559. if(jsonStr){
  560. selectedAddr = jsonStr;
  561. // viewApi.back();
  562. window.history.back();
  563. }
  564. });
  565. $("#addrUl").on('tap', 'li .c-list-key', function(){
  566. var jsonStr = $(this).parent().data("json");
  567. if(jsonStr){
  568. editAddrObj = {
  569. id: jsonStr.id,
  570. provinceName: jsonStr.province_name,
  571. province: jsonStr.province,
  572. cityName: jsonStr.city_name,
  573. city: jsonStr.city,
  574. townName: jsonStr.town_name,
  575. town: jsonStr.town,
  576. name: jsonStr.name,
  577. phone: jsonStr.phone,
  578. adress: jsonStr.adress,
  579. defaultFlag: jsonStr.default_flag
  580. };
  581. viewApi.go("#editPage");
  582. pushHistory("editPage");
  583. }
  584. })
  585. $("#saveAddr").on('tap', function(){
  586. var district = $("#addressSelect input").val(),
  587. address = $("#address").val(),
  588. mobile = $(".mobile").val();
  589. if((district.length == 0) || (address.length == 0)){
  590. dialog({
  591. contentType: 'tipsbox',
  592. skin: 'bk-popup',
  593. content: '请填写收药地址'
  594. }).show();
  595. return false;
  596. }
  597. if($("#receiver").val().trim().length == 0){
  598. dialog({
  599. contentType: 'tipsbox',
  600. skin: 'bk-popup',
  601. content: '请填写收药人姓名'
  602. }).show();
  603. return false;
  604. }
  605. if(!isphone(mobile)){
  606. dialog({
  607. contentType: 'tipsbox',
  608. skin: 'bk-popup',
  609. content: '请填写正确的手机号码'
  610. }).show();
  611. return false;
  612. }
  613. var defaultFlag = $("#defaultFlag").prop("checked");
  614. editAddrObj.patient = patiCode;
  615. editAddrObj.name = $("#receiver").val().trim();
  616. editAddrObj.phone = $(".mobile").val();
  617. editAddrObj.defaultFlag = defaultFlag? 1: 0;
  618. editAddrObj.adress = $("#address").val()
  619. saveAddress();
  620. });
  621. $("#delAddr").on('tap', function(){
  622. if(!editAddrObj.id){
  623. return false;
  624. }
  625. delAddress();
  626. });
  627. $("#submitBtn").on('tap', function(){
  628. if($(this).hasClass("disabled")){
  629. return false;
  630. }
  631. //判断是否选择了配送地址
  632. var $serviceStation = $('#serviceStation input');
  633. //判断是否填写了地址信息
  634. if(!selectedAddr){
  635. dialog({
  636. contentType: 'tipsbox',
  637. skin: 'bk-popup',
  638. content: '请选择收药人信息'
  639. }).show();
  640. return false;
  641. }
  642. if(!onlyGetBySelf){
  643. if(!type){
  644. dialog({
  645. contentType: 'tipsbox',
  646. skin: 'bk-popup',
  647. content: '请选择配送方式'
  648. }).show();
  649. return false;
  650. }
  651. if(type == 2){
  652. expressAddressInfo = {
  653. provinceName: selectedAddr.province_name,
  654. provinceCode: selectedAddr.province,
  655. cityName: selectedAddr.city_name,
  656. cityCode: selectedAddr.city,
  657. townName: selectedAddr.town_name,
  658. townCode: selectedAddr.town,
  659. address: selectedAddr.adress,
  660. phone: selectedAddr.phone,
  661. receiver: selectedAddr.name
  662. }
  663. checkOrderService(selectedAddr.adress);
  664. }else if(type == 3){
  665. if($serviceStation.val().length == 0){
  666. dialog({
  667. contentType: 'tipsbox',
  668. skin: 'bk-popup',
  669. content: '请选择配送服务站'
  670. }).show();
  671. return false;
  672. }
  673. expressAddressInfo.phone = selectedAddr.phone;
  674. }else{
  675. expressAddressInfo.phone = selectedAddr.phone;
  676. }
  677. }else{
  678. expressAddressInfo.phone = selectedAddr.phone;
  679. }
  680. //判断当前时间是否在11点前
  681. var now = new Date();
  682. if(now.getHours() >= 11){
  683. //判断选择时间是否是今天
  684. var text = type == 1 ? '取药' : '配送';
  685. var todayStr = now.Format('yyyy-MM-dd');
  686. if(todayStr == selectDate){
  687. dialog({
  688. contentType: 'tipsbox',
  689. skin: 'bk-popup',
  690. content: '当前不可选择当天'+text+',请重新选择'+text+'时间'
  691. }).show();
  692. return false;
  693. }
  694. }
  695. submitToPay();
  696. });
  697. //监听浏览器后退
  698. window.addEventListener("popstate", function(e) {
  699. var state = e.state;
  700. if(state){
  701. if(state.url == "#addrList"){
  702. viewApi.go("#addrList");
  703. }
  704. }else{
  705. viewApi.go("#main");
  706. }
  707. }, false);
  708. }
  709. function queryFailed(res){
  710. d.close();
  711. if(res && res.msg) {
  712. dialog({
  713. contentType: 'tipsbox',
  714. skin: 'bk-popup',
  715. content: res.msg
  716. }).show();
  717. } else {
  718. dialog({
  719. contentType: 'tipsbox',
  720. skin: 'bk-popup',
  721. content: '加载失败'
  722. }).show();
  723. }
  724. }
  725. //修改浏览器网页history信息
  726. function pushHistory(pageName) {
  727. if(!pageName){
  728. pageName = "";
  729. }
  730. var state = {
  731. title: "title",
  732. url: "#"+pageName
  733. };
  734. window.history.pushState(state, "title", "#"+pageName);
  735. }