Authored by yyq

Merge branch 'feature/homeInvoice' into release/6.1

@@ -109,20 +109,68 @@ function validateInvoice($el, info) { @@ -109,20 +109,68 @@ function validateInvoice($el, info) {
109 return pass; 109 return pass;
110 } 110 }
111 111
112 -function supplyInvoice(info) { 112 +function viewInvoice(code) {
  113 + if (!code) {
  114 + return;
  115 + }
  116 +
  117 + $.ajax({
  118 + url: '/home/invoice/detail',
  119 + type: 'GET',
  120 + data: {orderCode: code}
  121 + }).done(function(res) {
  122 + if (res.code !== 200) {
  123 + return;
  124 + }
  125 +
  126 + new Dialog({
  127 + className: 'invoice-me-page invoice-detail-dialog',
  128 + content: detailTpl(res.data)
  129 + }).show();
  130 + });
  131 +}
  132 +
  133 +function supplyInvoice(info, cb) {
113 $.ajax({ 134 $.ajax({
114 url: '/home/invoice/supply', 135 url: '/home/invoice/supply',
115 type: 'POST', 136 type: 'POST',
116 data: info 137 data: info
117 }).done(function(res) { 138 }).done(function(res) {
  139 + var _dg, _btn;
  140 +
  141 + cb && cb(res); // eslint-disable-line
  142 +
118 if (res.code === 200) { 143 if (res.code === 200) {
119 - history.go(0); 144 + if (res.data.issueType === 2) {
  145 + _btn = {
  146 + name: '查看发票',
  147 + cb: function() {
  148 + viewInvoice(res.data.order_code);
  149 + }
  150 + };
  151 + } else {
  152 + _btn = {name: '我知道了'};
  153 + }
  154 +
  155 + _dg = new Dialog({
  156 + className: 'invoice-me-page supply-success-dialog',
  157 + content: '<h2>提交成功</h2><p>您的服务申请已提交,您可以在我的发票中下载电子发票</p>',
  158 + btns: [{
  159 + id: 'close-dg',
  160 + name: _btn.name,
  161 + btnClass: ['close-dg'],
  162 + cb: function() {
  163 + _dg.close();
  164 + _btn.cb && _btn.cb();
  165 + }
  166 + }]
  167 + }).show();
120 } 168 }
121 }); 169 });
122 } 170 }
123 171
124 $('#me-invoice-orders').on('click', '.supply-invoice', function() { 172 $('#me-invoice-orders').on('click', '.supply-invoice', function() {
125 - var code = $(this).data('id'); 173 + var $this = $(this);
126 var dg = new Dialog({ 174 var dg = new Dialog({
127 className: 'invoice-me-page invoice-supply-dialog', 175 className: 'invoice-me-page invoice-supply-dialog',
128 content: invoiceTpl, 176 content: invoiceTpl,
@@ -133,10 +181,24 @@ $('#me-invoice-orders').on('click', '.supply-invoice', function() { @@ -133,10 +181,24 @@ $('#me-invoice-orders').on('click', '.supply-invoice', function() {
133 cb: function() { 181 cb: function() {
134 var info = packInvoiceInfo(dg.$el); 182 var info = packInvoiceInfo(dg.$el);
135 183
136 - if (validateInvoice(dg.$el, info)) {  
137 - info.orderCode = code;  
138 - supplyInvoice(info); 184 + if (!validateInvoice(dg.$el, info)) {
  185 + return;
139 } 186 }
  187 +
  188 + info.orderCode = $(this).data('id');
  189 + supplyInvoice(info, function(data) {
  190 + if (data.code !== 200) {
  191 + return;
  192 + }
  193 +
  194 + dg.close();
  195 +
  196 + if (+data.issueType === 2) {
  197 + $this.removeClass('supply-invoice').addClass('view-invoice').text('查看发票');
  198 + } else {
  199 + $this.removeClass('supply-invoice').addClass('on-invoice').text('开票中');
  200 + }
  201 + });
140 } 202 }
141 }, { 203 }, {
142 id: 'cancel-apply', 204 id: 'cancel-apply',
@@ -151,20 +213,5 @@ $('#me-invoice-orders').on('click', '.supply-invoice', function() { @@ -151,20 +213,5 @@ $('#me-invoice-orders').on('click', '.supply-invoice', function() {
151 // 事件绑定 213 // 事件绑定
152 bindSupplyDialogEvent(dg.$el); 214 bindSupplyDialogEvent(dg.$el);
153 }).on('click', '.view-invoice', function() { 215 }).on('click', '.view-invoice', function() {
154 - var code = $(this).data('id');  
155 -  
156 - $.ajax({  
157 - url: '/home/invoice/detail',  
158 - type: 'GET',  
159 - data: {orderCode: code}  
160 - }).done(function(res) {  
161 - if (res.code !== 200) {  
162 - return;  
163 - }  
164 -  
165 - new Dialog({  
166 - className: 'invoice-me-page invoice-detail-dialog',  
167 - content: detailTpl(res.data)  
168 - }).show();  
169 - }); 216 + viewInvoice($(this).data('id'));
170 }); 217 });
@@ -241,4 +241,21 @@ @@ -241,4 +241,21 @@
241 } 241 }
242 } 242 }
243 } 243 }
  244 +
  245 + &.supply-success-dialog {
  246 + background-color: #fff;
  247 + font-size: 14px;
  248 +
  249 + .content {
  250 + width: 300px;
  251 + padding: 0 30px 40px;
  252 + line-height: 2;
  253 + color: #444;
  254 +
  255 + h2 {
  256 + font-size: 18px;
  257 + margin-bottom: 26px;
  258 + }
  259 + }
  260 + }
244 } 261 }