Authored by xuqi

address dialogs for order

@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <div class="form-group"> 5 <div class="form-group">
6 <label class="label-name">&nbsp;&nbsp;收货人:</label> 6 <label class="label-name">&nbsp;&nbsp;收货人:</label>
7 <input id="address_id" type="hidden" value=""> 7 <input id="address_id" type="hidden" value="">
8 - <input id="consignee" class="input width-190" type="text" placeholder="请输入您的姓名" maxlength="10"> 8 + <input id="consignee" class="input" type="text" placeholder="请输入您的姓名" maxlength="10">
9 <span class="blue error-tips">{{> icon/error-round}}收件人不能为空</span> 9 <span class="blue error-tips">{{> icon/error-round}}收件人不能为空</span>
10 </div> 10 </div>
11 <div class="form-group"> 11 <div class="form-group">
@@ -15,17 +15,17 @@ @@ -15,17 +15,17 @@
15 </div> 15 </div>
16 <div class="form-group"> 16 <div class="form-group">
17 <label class="label-name">详细地址:</label> 17 <label class="label-name">详细地址:</label>
18 - <input id="addressDetail" class="input width-275" type="text" placeholder="街道名称或小区名称" maxlength="60"> 18 + <input id="addressDetail" class="input address-detail" type="text" placeholder="街道名称或小区名称" maxlength="60">
19 <span class="blue error-tips">{{> icon/error-round}}详细地址不能为空</span> 19 <span class="blue error-tips">{{> icon/error-round}}详细地址不能为空</span>
20 </div> 20 </div>
21 <div class="form-group"> 21 <div class="form-group">
22 <label class="label-name">手机号码:</label> 22 <label class="label-name">手机号码:</label>
23 - <input id="mobile" class="input width-190" type="text" placeholder="请输入手机号码(重要必填)" maxlength="11"> 23 + <input id="mobile" class="input" type="text" placeholder="请输入手机号码(重要必填)" maxlength="11">
24 <span class="blue error-tips">{{> icon/error-round}}手机号码不能为空</span> 24 <span class="blue error-tips">{{> icon/error-round}}手机号码不能为空</span>
25 </div> 25 </div>
26 <div class="form-group"> 26 <div class="form-group">
27 <label class="label-name">电话号码:</label> 27 <label class="label-name">电话号码:</label>
28 - <input id="phone" class="input width-190" type="text" placeholder="请输入电话号码(选填)"> 28 + <input id="phone" class="input" type="text" placeholder="请输入电话号码(选填)">
29 </div> 29 </div>
30 <div class="form-group "> 30 <div class="form-group ">
31 <label class="label-name"></label> 31 <label class="label-name"></label>
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 <div class="address-info order-block"> 4 <div class="address-info order-block">
5 <p class="title"> 5 <p class="title">
6 收货信息 6 收货信息
7 - <span id="new-address" class="right new-address"> 7 + <span class="right new-address">
8 新增收货地址 8 新增收货地址
9 <i class="iconfont">&#xe61f;</i> 9 <i class="iconfont">&#xe61f;</i>
10 </span> 10 </span>
@@ -260,6 +260,17 @@ @@ -260,6 +260,17 @@
260 </div> 260 </div>
261 </div> 261 </div>
262 </script> 262 </script>
  263 +
  264 + <script id="address-dialog-tpl" type="text/html">
  265 + <p class="dialog-title">
  266 + \{{#if updateAddress}}
  267 + 修改地址
  268 + \{{^}}
  269 + 新增地址
  270 + \{{/if}}
  271 + </p>
  272 + {{> write-address}}
  273 + </script>
263 </div> 274 </div>
264 {{/ content}} 275 {{/ content}}
265 </div> 276 </div>
  1 +<form id="address-form" name="address-form">
  2 + <div class="address-page">
  3 + <span class="tip">
  4 + <em class="blue">
  5 + \{{#if updateAddress}}
  6 + 修改地址
  7 + \{{^}}
  8 + 新增地址
  9 + \{{/if}}
  10 + </em>
  11 + 电话为选填项,其他均为必填项
  12 + </span>
  13 + <div class="add-address-detail" data-id="\{{id}}">
  14 + <div class="form-group">
  15 + <label class="label-name">
  16 + <em class="required-mark">*</em>
  17 + 收货人:
  18 + </label>
  19 + <input class="input address-name" type="text" placeholder="请输入您的姓名" maxlength="10" value="\{{name}}">
  20 + <span class="blue error-tips hide">
  21 + {{> icon/error-round}}
  22 + <em></em>
  23 + </span>
  24 + </div>
  25 + <div class="form-group">
  26 + <label class="label-name">
  27 + <em class="required-mark">*</em>
  28 + 所在区域:
  29 + </label>
  30 + <div id="address" class="clearfix"></div>
  31 + <span class="blue error-tips hide">
  32 + {{> icon/error-round}}
  33 + 所在区域不能为空
  34 + </span>
  35 + </div>
  36 + <div class="form-group">
  37 + <label class="label-name">
  38 + <em class="required-mark">*</em>
  39 + 详细地址:
  40 + </label>
  41 + <input class="input address-detail" type="text" placeholder="街道名称或小区名称" maxlength="60" value="\{{detail}}">
  42 + <span class="blue error-tips hide">
  43 + {{> icon/error-round}}
  44 + <em></em>
  45 + </span>
  46 + </div>
  47 + <div class="form-group">
  48 + <label class="label-name">
  49 + <em class="required-mark">*</em>
  50 + 手机号码:
  51 + </label>
  52 + <input class="input address-mobile" type="text" placeholder="请输入手机号码(重要必填)" maxlength="11" value="\{{mobile}}">
  53 + <span class="blue error-tips hide">
  54 + {{> icon/error-round}}
  55 + <em></em>
  56 + </span>
  57 + </div>
  58 + <div class="form-group">
  59 + <label class="label-name">电话号码:</label>
  60 + <input class="input address-phone" type="text" placeholder="请输入电话号码(选填)" value="\{{phone}}">
  61 + <span class="blue error-tips hide">
  62 + {{> icon/error-round}}
  63 + <em></em>
  64 + </span>
  65 + </div>
  66 + <div class="form-group ">
  67 + <label class="label-name"></label>
  68 + <div class="default-address-radio default-address">
  69 + \{{#if checked}}
  70 + <span class="iconfont radio checked">&#xe603;</span>
  71 + \{{^}}
  72 + <span class="iconfont radio">&#xe604;</span>
  73 + \{{/if}}
  74 + <label>设置为默认收货地址</label>
  75 + </div>
  76 + </div>
  77 + \{{#unless dialogAddress}}
  78 + <div class="form-group">
  79 + <span class="btn operation" id="save-address">保存</span>
  80 + </div>
  81 + \{{/unless}}
  82 + </div>
  83 + </div>
  84 +</form>
@@ -22,6 +22,7 @@ var tpl = @@ -22,6 +22,7 @@ var tpl =
22 '<div class="content">' + 22 '<div class="content">' +
23 '{{{content}}}' + 23 '{{{content}}}' +
24 '</div>' + 24 '</div>' +
  25 + '{{#if btns}}' +
25 '<div class="btns">' + 26 '<div class="btns">' +
26 '{{# btns}}' + 27 '{{# btns}}' +
27 '<span {{#if id}}id="dialog-{{id}}"{{/if}} class="btn{{#each btnClass}} {{.}}{{/each}}">' + 28 '<span {{#if id}}id="dialog-{{id}}"{{/if}} class="btn{{#each btnClass}} {{.}}{{/each}}">' +
@@ -29,6 +30,7 @@ var tpl = @@ -29,6 +30,7 @@ var tpl =
29 '</span>' + 30 '</span>' +
30 '{{/ btns}}' + 31 '{{/ btns}}' +
31 '</div>' + 32 '</div>' +
  33 + '{{/if}}' +
32 '</div>'; 34 '</div>';
33 35
34 var tplFn = Handlebars.compile(tpl); 36 var tplFn = Handlebars.compile(tpl);
@@ -48,7 +50,7 @@ function createMask() { @@ -48,7 +50,7 @@ function createMask() {
48 function createDialog(data) { 50 function createDialog(data) {
49 $('body').append(tplFn(data)); 51 $('body').append(tplFn(data));
50 52
51 - return $('.yoho-dialog'); 53 + return $('.yoho-dialog').last();
52 } 54 }
53 55
54 function Dialog(options) { 56 function Dialog(options) {
@@ -144,7 +146,7 @@ function Confirm(opt) { @@ -144,7 +146,7 @@ function Confirm(opt) {
144 146
145 var option = { 147 var option = {
146 content: opt.content, 148 content: opt.content,
147 - className: 'confirm-dialog', 149 + className: 'confirm-dialog' + (opt.className ? ' ' + opt.className : ''),
148 btns: [ 150 btns: [
149 { 151 {
150 id: 'confirm-sure', 152 id: 'confirm-sure',
@@ -6,7 +6,12 @@ @@ -6,7 +6,12 @@
6 6
7 var $ = require('yoho-jquery'), 7 var $ = require('yoho-jquery'),
8 lazyLoad = require('yoho-jquery-lazyload'), 8 lazyLoad = require('yoho-jquery-lazyload'),
9 - Dialog = require('../plugins/dialog').Dialog; 9 + Hbs = require('yoho-handlebars'),
  10 + cascadingAddress = require('../plugins/cascading-address'),
  11 + popup = require('../plugins/dialog');
  12 +
  13 +var Dialog = popup.Dialog,
  14 + Confirm = popup.Confirm;
10 15
11 var minusPlus = { 16 var minusPlus = {
12 minus: '&#xe630;', 17 minus: '&#xe630;',
@@ -33,12 +38,160 @@ var $invoiceTitleInput, @@ -33,12 +38,160 @@ var $invoiceTitleInput,
33 $invoiceEntity, 38 $invoiceEntity,
34 invoiceDialog; 39 invoiceDialog;
35 40
  41 +var addressTpl = Hbs.compile($('#address-dialog-tpl').html());
  42 +
36 require('../plugins/check'); 43 require('../plugins/check');
37 44
38 lazyLoad($('img.lazy')); 45 lazyLoad($('img.lazy'));
39 46
40 -// 地址切换 47 +// 显示全部地址
  48 +$('.address-all').click(function() {
  49 + $(this).siblings('.address-list').removeClass('shrink').end().remove();
  50 +});
  51 +
  52 +// address dialog 数据验证
  53 +function validateAddress($el) {
  54 + var field = {
  55 + name: [
  56 + {
  57 + noEmpty: true,
  58 + err: '收货人不能为空'
  59 + },
  60 + {
  61 + regx: /[\u4e00-\u9fa5a-zA-Z\d]{2,12}/,
  62 + err: '请输入2-12个汉字、英文或数字'
  63 + }
  64 + ],
  65 + detail: [
  66 + {
  67 + noEmpty: true,
  68 + err: '详细地址不能为空'
  69 + },
  70 + {
  71 + regx: /[\u4e00-\u9fa5a-zA-Z\d#-()]+/,
  72 + err: '只能包含数字、字母、汉字、#、-、()及其组合'
  73 + }
  74 + ],
  75 + mobile: [
  76 + {
  77 + noEmpty: true,
  78 + err: '手机号码不能为空'
  79 + },
  80 + {
  81 + regx: /\d+/,
  82 + err: '手机号码格式不正确'
  83 + }
  84 + ],
  85 + phone: [
  86 + {
  87 + regx: /[\d-]+/,
  88 + err: '只能包含数字、-组合',
  89 + skipWhenEmpty: true
  90 + }
  91 + ]
  92 + };
  93 +
  94 + var key,
  95 + $cur,
  96 + cur,
  97 + vaKey,
  98 + vaRegx;
  99 +
  100 + var pass = true;
  101 +
  102 + for (key in field) {
  103 + if (field.hasOwnProperty(key)) {
  104 + $cur = $el.find('.address-' + key);
  105 + cur = $cur.val();
  106 +
  107 + // 按顺序去验证对应filed的值
  108 + for (vaKey = 0; vaKey < field[key].length; vaKey++) {
  109 + vaRegx = field[key][vaKey];
  110 +
  111 + // 非空验证、非空下正则验证、其他正则验证
  112 + if ((vaRegx.noEmpty && cur === '') || (vaRegx.regx &&
  113 + (vaRegx.skipWhenEmpty ? !(cur === '' || vaRegx.regx.test(cur)) : !vaRegx.regx.test(cur))
  114 + )) {
  115 + pass = false;
  116 + $cur.siblings('.error-tips').find('em').text(vaRegx.err).end().removeClass('hide');
  117 + break;
  118 + }
  119 + }
  120 + }
  121 + }
  122 +
  123 + return pass;
  124 +}
  125 +
  126 +// 地址弹窗Factory
  127 +function addressDialogFactory(opt) {
  128 + var tplData = $.extend({
  129 + dialogAddress: true,
  130 + checked: true
  131 + }, opt);
  132 +
  133 + var address = new Dialog({
  134 + closeIcon: false,
  135 + className: 'address',
  136 + content: addressTpl(tplData),
  137 + btns: [
  138 + {
  139 + id: 'save-address',
  140 + btnClass: ['save-address'],
  141 + name: '保存',
  142 + cb: function() {
  143 +
  144 + // 验证输入
  145 + if (validateAddress(address.$el)) {
  146 + address.close();
  147 + }
  148 + }
  149 + },
  150 + {
  151 + id: 'cancel-address',
  152 + btnClass: ['cancel-address', 'white'],
  153 + name: '取消',
  154 + cb: function() {
  155 + address.close();
  156 + }
  157 + }
  158 + ]
  159 + });
  160 +
  161 + return address;
  162 +}
  163 +
  164 +// 初始化弹窗内容
  165 +function initAddressContent($el) {
  166 +
  167 + // 初始化地址组件
  168 + cascadingAddress({
  169 + el: '#address',
  170 + url: 'http://localhost:3000/areas/0',
  171 + resource: 'areas'
  172 + });
  173 +
  174 + $el.find('.default-address-radio').check({
  175 + type: 'radio',
  176 + onChange: function(el, checked) {
  177 + console.log(checked);
  178 + }
  179 + });
  180 +}
  181 +
  182 +// 新增地址
  183 +$('.new-address').click(function() {
  184 + var address = addressDialogFactory();
  185 +
  186 + initAddressContent(address.$el);
  187 +
  188 + address.show();
  189 +});
  190 +
  191 +
41 $('.address-list').on('click', '.address', function() { 192 $('.address-list').on('click', '.address', function() {
  193 +
  194 + // 地址切换
42 var $this = $(this); 195 var $this = $(this);
43 196
44 if ($this.hasClass('focus')) { 197 if ($this.hasClass('focus')) {
@@ -47,16 +200,48 @@ $('.address-list').on('click', '.address', function() { @@ -47,16 +200,48 @@ $('.address-list').on('click', '.address', function() {
47 200
48 $this.addClass('focus'); 201 $this.addClass('focus');
49 $this.siblings('.focus').removeClass('focus'); 202 $this.siblings('.focus').removeClass('focus');
50 -}); 203 +}).on('click', '.modify', function(e) {
51 204
52 -// 显示全部地址  
53 -$('.address-all').click(function() {  
54 - $(this).siblings('.address-list').removeClass('shrink').end().remove(); 205 +
  206 + // 修改地址
  207 + var $this = $(this).closest('.address');
  208 + var address = addressDialogFactory({
  209 + updateAddress: true,
  210 + name: '徐祁',
  211 + detail: '嘉陵江东街18号',
  212 + mobile: '15895869035',
  213 + id: $this.data('id')
  214 + });
  215 +
  216 + initAddressContent(address.$el);
  217 +
  218 + address.show();
  219 +
  220 + e.stopPropagation();
  221 +}).on('click', '.delete', function(e) {
  222 +
  223 + // 删除地址
  224 + // var $this = $(this).closest('.address');
  225 + // var id = $this.data('id');
  226 +
  227 + new Confirm({
  228 + className: 'address-confirm-dialog',
  229 + content: '<p class="main">删除地址</p><p class="sub">您确定要删除该收货地址吗?</p>',
  230 + cb: function() {
  231 +
  232 + // 确认删除,do something
  233 + }
  234 + }).show();
  235 +
  236 + e.stopPropagation();
  237 +}).on('click', '.set-default', function(e) {
  238 +
  239 + // 设置为默认地址
  240 +
  241 + e.stopPropagation();
55 }); 242 });
56 243
57 -/**  
58 - * 发票弹窗Factory  
59 - */ 244 +// 发票弹窗Factory
60 function invoiceDialogFactory() { 245 function invoiceDialogFactory() {
61 var invoice = new Dialog({ 246 var invoice = new Dialog({
62 className: 'invoice', 247 className: 'invoice',
@@ -10,6 +10,10 @@ @@ -10,6 +10,10 @@
10 font-size: 14px; 10 font-size: 14px;
11 } 11 }
12 12
  13 + .required-mark {
  14 + color: #f00;
  15 + }
  16 +
13 .add-address-detail { 17 .add-address-detail {
14 padding: 15px 0 0; 18 padding: 15px 0 0;
15 19
@@ -17,28 +21,28 @@ @@ -17,28 +21,28 @@
17 clear: both; 21 clear: both;
18 margin-bottom: 20px; 22 margin-bottom: 20px;
19 23
  24 + .input {
  25 + width: 190px;
  26 + }
  27 +
20 .default-address, 28 .default-address,
21 #address, 29 #address,
22 .btn { 30 .btn {
  31 + margin-left: 94px;
  32 + }
23 33
24 - margin-left: 83px; 34 + .default-address {
  35 + font-size: 14px;
25 } 36 }
26 37
27 .label-name { 38 .label-name {
  39 + width: 84px;
28 font-size: 14px; 40 font-size: 14px;
29 - text-align: left;  
30 float: left; 41 float: left;
31 line-height: 26px; 42 line-height: 26px;
  43 + margin-right: 10px;
32 } 44 }
33 45
34 - .width-190 {  
35 - width: 190px;  
36 - margin-left: 20px;  
37 - }  
38 - .width-275 {  
39 - width: 275px;  
40 - margin-left: 20px;  
41 - }  
42 .iconfont { 46 .iconfont {
43 font-size: 14px; 47 font-size: 14px;
44 } 48 }
@@ -61,6 +65,10 @@ @@ -61,6 +65,10 @@
61 } 65 }
62 66
63 } 67 }
  68 +
  69 + .address-detail.input {
  70 + width: 270px;
  71 + }
64 } 72 }
65 } 73 }
66 74
@@ -412,14 +412,43 @@ @@ -412,14 +412,43 @@
412 } 412 }
413 } 413 }
414 414
  415 +.yoho-dialog.address,
415 .yoho-dialog.invoice { 416 .yoho-dialog.invoice {
416 - width: 702px;  
417 background: #fff; 417 background: #fff;
418 418
419 .content { 419 .content {
420 text-align: left; 420 text-align: left;
421 } 421 }
422 422
  423 + .btns .btn {
  424 + width: 140px;
  425 + height: 40px;
  426 + line-height: 40px;
  427 +
  428 + &.white {
  429 + border-color: #000;
  430 + color: #000;
  431 + }
  432 + }
  433 +}
  434 +
  435 +.yoho-dialog.address {
  436 + width: 664px;
  437 + padding: 0 40px 10px;
  438 +
  439 + .label-name {
  440 + text-align: right;
  441 + }
  442 +
  443 + .dialog-title {
  444 + margin: 25px 0;
  445 + font-size: 18px;
  446 + }
  447 +}
  448 +
  449 +.yoho-dialog.invoice {
  450 + width: 702px;
  451 +
423 /* 纸质发票不显示提示和收票人手机 */ 452 /* 纸质发票不显示提示和收票人手机 */
424 .tip, 453 .tip,
425 .phone-row { 454 .phone-row {
@@ -502,15 +531,20 @@ @@ -502,15 +531,20 @@
502 width: 520px; 531 width: 520px;
503 } 532 }
504 } 533 }
  534 +}
505 535
506 - .btns .btn {  
507 - width: 140px;  
508 - height: 40px;  
509 - line-height: 40px; 536 +.address-confirm-dialog {
  537 + .content {
  538 + padding-top: 0 !important;
510 539
511 - &.white {  
512 - border-color: #000;  
513 - color: #000; 540 + p {
  541 + position: static !important;
  542 + }
  543 +
  544 + p.main {
  545 + line-height: 100px;
  546 + font-weight: bold;
  547 + font-size: 28px;
514 } 548 }
515 } 549 }
516 } 550 }