Authored by yyq

地址弹窗交互

1 /** 1 /**
2 * 订单结算controller 2 * 订单结算controller
3 - * @author: xuqi<qi.xu@yoho.cn>  
4 - * @date: 2016/8/26 3 + * @author: yyq<yanqing.yang@yoho.cn>
  4 + * @date: 2016/12/21
5 */ 5 */
6 6
7 'use strict'; 7 'use strict';
@@ -22,7 +22,7 @@ router.post('/address/delete', address.delAddress); // 删除地址 @@ -22,7 +22,7 @@ router.post('/address/delete', address.delAddress); // 删除地址
22 router.post('/address/save', address.saveAddress); // 新增地址/更新地址 22 router.post('/address/save', address.saveAddress); // 新增地址/更新地址
23 router.post('/address/setdefault', address.setDefault); // 设置默认地址 23 router.post('/address/setdefault', address.setDefault); // 设置默认地址
24 24
25 -router.get('/orderensure', ensure.index); // 限购商品快捷结算页 25 +router.get('/ensure', ensure.index); // 限购商品快捷结算页
26 26
27 router.get('/easypay', easypay.index); // 限购商品快捷结算页 27 router.get('/easypay', easypay.index); // 限购商品快捷结算页
28 router.post('/easypay/compute', easypay.compute); // 价格重新计算 28 router.post('/easypay/compute', easypay.compute); // 价格重新计算
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 </div> 5 </div>
6 6
7 <div class="info-block-wrap"> 7 <div class="info-block-wrap">
8 - <p class="block-title">收货信息<span class="right">新增收货地址></span></p> 8 + <p class="block-title">收货信息<span id="new-address-btn" class="right">新增收货地址></span></p>
9 <div class="address-wrap"> 9 <div class="address-wrap">
10 <div class="addr-list clearfix"> 10 <div class="addr-list clearfix">
11 {{# deliveryAddress}} 11 {{# deliveryAddress}}
@@ -147,5 +147,7 @@ @@ -147,5 +147,7 @@
147 <button id="order-submit">提交订单</button> 147 <button id="order-submit">提交订单</button>
148 </div> 148 </div>
149 {{/ shoppingCartData}} 149 {{/ shoppingCartData}}
  150 +
  151 + {{> ensure-tpl}}
150 {{/ content}} 152 {{/ content}}
151 </div> 153 </div>
  1 +
  2 +
  3 +<script id="address-tpl" type="text/html">
  4 + <div class="title">\{{title}}</div>
  5 + <p class="prompt">电话为选填项,其他均为必填项</p>
  6 + <ul class="info-wrap">
  7 + <li>
  8 + <span class="left-rd"><i class="red">*</i>收货人:</span>
  9 + <input type="text" name="consignee" value="\{{name}}" placeholder="请输入您的姓名">
  10 + <span class="caveat-tip"></span>
  11 + </li>
  12 + <li>
  13 + <span class="left-rd"><i class="red">*</i>所在区域:</span>
  14 + <div class="area-box">
  15 + <select class="province">
  16 + <option value="0">请选择省</option>
  17 + </select>
  18 + <select class="city">
  19 + <option value="0">请选择市</option>
  20 + </select>
  21 + <select class="country">
  22 + <option value="0">请选择县</option>
  23 + </select>
  24 + </div>
  25 + <span>注:标“*”的为支持加急送的地区</span>
  26 + <span class="caveat-tip"></span>
  27 + </li>
  28 + <li>
  29 + <span class="left-rd"><i class="red">*</i>详细地址:</span>
  30 + <input type="text" name="address" value="\{{name}}" placeholder="街道名称或小区名称">
  31 + <span class="caveat-tip"></span>
  32 + </li>
  33 + <li>
  34 + <span class="left-rd"><i class="red">*</i>手机号码:</span>
  35 + <input type="text" name="mobile" value="\{{name}}" placeholder="请输入手机号码(重要必填)">
  36 + <span class="caveat-tip"></span>
  37 + </li>
  38 + <li>
  39 + <span class="left-rd">电话号码:</span>
  40 + <input type="text" name="tel" value="\{{name}}" placeholder="请输入电话号码(选填)">
  41 + <span class="caveat-tip"></span>
  42 + </li>
  43 + <li>
  44 + <span class="left-rd"></span>
  45 + <label class="radio-btn">设置为默认收货地址</label>
  46 +
  47 + </li>
  48 + </ul>
  49 +</script>

4.98 KB | W: | H:

5.48 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
@@ -11,6 +11,8 @@ var order = {}; @@ -11,6 +11,8 @@ var order = {};
11 var payWay, 11 var payWay,
12 deliveryWay; 12 deliveryWay;
13 13
  14 +require('./order-new/address');
  15 +
14 // 支付方式 16 // 支付方式
15 payWay = { 17 payWay = {
16 $payType: $('.pay-wrap .check-btn'), 18 $payType: $('.pay-wrap .check-btn'),
1 /** 1 /**
2 * 订单结算页 2 * 订单结算页
3 * @author: yyq<yanqing.yang@yoho.cn> 3 * @author: yyq<yanqing.yang@yoho.cn>
4 - * @date: 2016/11/30 4 + * @date: 2016/12/20
5 */ 5 */
6 6
7 -// var $ = require('yoho-jquery'); 7 +var $ = require('yoho-jquery');
  8 +var hbs = require('yoho-handlebars');
  9 +var dialog = require('../../common/dialog');
  10 +var Dialog = dialog.Dialog;
  11 +
  12 +// var Confirm = dialog.Confirm;
  13 +// var Alert = dialog.Alert;
  14 +
  15 +var addressTpl = hbs.compile($('#address-tpl').html());
  16 +
  17 +Dialog.prototype.packageInfo = function() {
  18 + var data = {};
  19 + var province = this.$el.find('.province').val(),
  20 + city = this.$el.find('.city').val(),
  21 + country = this.$el.find('.country').val();
  22 +
  23 + this.$el.find('input').each(function() {
  24 + var $this = $(this),
  25 + key = $this.attr('name');
  26 +
  27 + if (key) {
  28 + data[key] = $.trim($this.val());
  29 + }
  30 + });
  31 +
  32 + data.areacode = (province || '00') + '' + (city || '00') + (country || '00');
  33 +
  34 + if (this.$el.find('.radio-btn.on').length) {
  35 + data.setDefault = true;
  36 + }
  37 +
  38 + return data;
  39 +};
  40 +
  41 +function validateAddress(data) {
  42 + var regx = {
  43 + consignee: /^[\u4e00-\u9fa5]{2,5}$/,
  44 + areacode: /^[0-9]{6}$/,
  45 + mobile: /^\d{3}(\d{4}|\*{4})\d{4}$/,
  46 + tel: /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/
  47 + },
  48 + pass = true,
  49 + i;
  50 +
  51 + data = data || {};
  52 + for (i in data) {
  53 + if (data.hasOwnProperty(i) &&
  54 + regx[i] &&
  55 + !regx[i].test(data[i])) {
  56 + pass = false;
  57 + }
  58 + }
  59 +
  60 + return pass;
  61 +}
  62 +
  63 +function bindOperateEvent($el) {
  64 + var $province = $el.find('.province'),
  65 + $city = $el.find('.city'),
  66 + $country = $el.find('.country');
  67 +
  68 + $el.on('change', 'input[name="consignee"]', function() {
  69 + var $this = $(this);
  70 + var val = $.trim($this.val());
  71 +
  72 + if (!val) {
  73 + $this.siblings('.caveat-tip').text('收货人不能为空').show();
  74 + } else if (!validateAddress({consignee: val})) {
  75 + $this.siblings('.caveat-tip').text('收货人姓名至少2个中文,最多5个中文').show();
  76 + } else {
  77 + $this.siblings('.caveat-tip').empty().hide();
  78 + }
  79 + }).on('change', '.country', function() {
  80 + var code = '' + $province.val() + $city.val() + $country.val();
  81 +
  82 + if (!validateAddress({areacode: code})) {
  83 + $province.parent().siblings('.caveat-tip').show().text('请选择省市县').prev().hide();
  84 + } else {
  85 + $province.parent().siblings('.caveat-tip').empty().hide().prev().show();
  86 + }
  87 + }).on('change', 'input[name="address"]', function() {
  88 + var $this = $(this);
  89 + var val = $.trim($this.val());
  90 +
  91 + if (!val) {
  92 + $this.siblings('.caveat-tip').text('收货地址不能为空').show();
  93 + } else {
  94 + $this.siblings('.caveat-tip').empty().hide();
  95 + }
  96 + $country.trigger('change');
  97 + }).on('change', 'input[name="mobile"]', function() {
  98 + var $this = $(this);
  99 + var val = $.trim($this.val());
  100 +
  101 + if (!val) {
  102 + $this.siblings('.caveat-tip').text('手机号码不能为空').show();
  103 + } else if (!validateAddress({mobile: val})) {
  104 + $this.siblings('.caveat-tip').text('您输入的手机号码格式不正确').show();
  105 + } else {
  106 + $this.siblings('.caveat-tip').empty().hide();
  107 + }
  108 + }).on('change', 'input[name="tel"]', function() {
  109 + var $this = $(this);
  110 + var val = $.trim($this.val());
  111 +
  112 + if (val && !validateAddress({tel: val})) {
  113 + $this.siblings('.caveat-tip').text('您输入的电话格式不正确').show();
  114 + } else {
  115 + $this.siblings('.caveat-tip').empty().hide();
  116 + }
  117 + }).on('click', '.radio-btn', function() {
  118 + $(this).toggleClass('on');
  119 + });
  120 +}
  121 +
  122 +function newEditAddress(info) {
  123 + var addDia = new Dialog({
  124 + content: addressTpl({
  125 + title: '新增地址'
  126 + }),
  127 + className: 'ope-address-dialog',
  128 + btns: [{
  129 + id: 1,
  130 + name: '保存',
  131 + btnClass: ['black'],
  132 + cb: function() {
  133 + console.log(addDia.packageInfo());
  134 +
  135 + console.log(info);
  136 + // window.open(myCouponUrl);
  137 + }
  138 + }, {
  139 + id: 2,
  140 + name: '取消',
  141 + btnClass: ['btn-close']
  142 + }]
  143 + }).show();
  144 +
  145 + bindOperateEvent(addDia.$el);
  146 +}
  147 +
  148 +$('#new-address-btn').click(function() {
  149 + newEditAddress();
  150 +});
8 151
@@ -448,3 +448,130 @@ @@ -448,3 +448,130 @@
448 } 448 }
449 } 449 }
450 } 450 }
  451 +
  452 +.ope-address-dialog {
  453 + width: 610px;
  454 + height: 410px;
  455 + text-align: left;
  456 +
  457 + > .close {
  458 + display: none;
  459 + }
  460 +
  461 + > .content {
  462 + text-align: left;
  463 + }
  464 +
  465 + .title {
  466 + padding-bottom: 26px;
  467 + border-bottom: 1px solid #e8e8e8;
  468 + }
  469 +
  470 + .prompt {
  471 + line-height: 54px;
  472 + font-size: 12px;
  473 + color: #444;
  474 + }
  475 +
  476 + .info-wrap {
  477 + font-size: 12px;
  478 + color: #aaa;
  479 +
  480 + .radio-btn {
  481 + font-size: 14px;
  482 + color: #444;
  483 +
  484 + &:before {
  485 + content: '';
  486 + width: 15px;
  487 + height: 15px;
  488 + margin-right: 6px;
  489 + background-image: url(/cart/radio-off.png);
  490 + display: inline-block;
  491 + vertical-align: middle;
  492 + position: relative;
  493 + top: -1px;
  494 + cursor: pointer;
  495 + }
  496 +
  497 + &.on:before {
  498 + background-image: url(/cart/radio-on.png);
  499 + }
  500 + }
  501 +
  502 + li {
  503 + padding-bottom: 20px;
  504 +
  505 + input {
  506 + width: 180px;
  507 + border: 1px solid #e8e8e8;
  508 + padding: 5px;
  509 + margin-right: 10px;
  510 + }
  511 +
  512 + input[name="address"] {
  513 + width: 270px;
  514 + }
  515 + }
  516 +
  517 + .left-rd {
  518 + width: 92px;
  519 + font-size: 14px;
  520 + color: #444;
  521 + text-align: right;
  522 + display: inline-block;
  523 +
  524 + .red {
  525 + color: #ce0b24;
  526 + margin-right: 10px;
  527 + }
  528 + }
  529 +
  530 + .caveat-tip {
  531 + color: #ce0b24;
  532 + display: none;
  533 +
  534 + &:before {
  535 + content: '';
  536 + width: 16px;
  537 + height: 16px;
  538 + margin-right: 6px;
  539 + background: url('/cart/error-ico.png');
  540 + display: inline-block;
  541 + position: relative;
  542 + top: 4px;
  543 + }
  544 + }
  545 +
  546 + .area-box {
  547 + height: 26px;
  548 + display: inline-block;
  549 + border: 1px solid #e8e8e8;
  550 + background: #fff;
  551 + padding-right: 3px;
  552 + margin-right: 10px;
  553 +
  554 + > select {
  555 + width: 90px;
  556 + height: 26px;
  557 + border: 0;
  558 + background: none;
  559 + color: #aaa;
  560 + }
  561 + }
  562 + }
  563 +
  564 + .btns {
  565 + > .btn {
  566 + width: 128px;
  567 + height: 30px;
  568 + line-height: 32px;
  569 + }
  570 +
  571 + .black {
  572 + background: #000;
  573 + color: #fff;
  574 + margin-right: 18px;
  575 + }
  576 + }
  577 +}