1'use strict'; 2 3var nhOrder = { 4 init: function(){ 5 var self = this; 6 7 self.cart.init(); 8 self.sidebar.init(); 9 self.orderInfo.init(); 10 self.checkout.init(); 11 self.coupon.init(); 12 self.point.init(); 13 self.affiliate.init(); 14 self.shippingMethod.init(); 15 }, 16 cart: { 17 wrapElement: null, 18 init: function(){ 19 var self = this; 20 var checkChangeQuantity = false; 21 22 // events 23 $(document).on('click', '[nh-btn-action="add-cart"]:not(.disable)', function(e){ 24 e.preventDefault(); 25 $(this).tooltip('hide'); 26 var wrapElement = $(this).closest('[nh-product]'); 27 if(wrapElement == _UNDEFINED || wrapElement.length == 0){ 28 nhMain.showLog(nhMain.getLabel('khong_tim_thay_the_bao_ngoai_san_pham') + ' [nh-product]'); 29 return false; 30 }; 31 32 var productItemId = wrapElement.attr('nh-product-item-id'); 33 var btnAddCart = $(this); 34 var inputQuantity = wrapElement.find('input[nh-quantity-product="quantity"]'); 35 var quantity = inputQuantity.length > 0 ? nhMain.utilities.parseInt(inputQuantity.val()) : 1; 36 var redirect = btnAddCart.attr('nh-redirect'); 37 if(productItemId == _UNDEFINED || !productItemId > 0){ 38 nhMain.showAlert(_ERROR, nhMain.getLabel('khong_lay_duoc_thong_tin_san_pham')); 39 return false; 40 } 41 42 btnAddCart.addClass('effect-spin'); 43 self.addProductToCart(productItemId, quantity, function(){ 44 nhOrder.sidebar.reloadSidebarCart(function(){ 45 if(typeof(redirect) != _UNDEFINED && redirect.length > 0){ 46 window.location.href = redirect; 47 return false; 48 } 49 50 if(typeof(nhProduct) != _UNDEFINED && $(nhProduct.quickView.idModal).length > 0){ 51 $(nhProduct.quickView.idModal).modal('hide'); 52 } 53 nhOrder.sidebar.toggleSidebarCart(true); 54 }); 55 btnAddCart.removeClass('effect-spin'); 56 }); 57 }); 58 59 $(document).on('click', '[nh-quantity-product="subtract"], [nh-quantity-product="add"]', function(e) { 60 e.preventDefault(); 61 var wrapCartInfo = $('[nh-cart-info]'); 62 var itemElement = $(this).closest('[nh-cart-item]'); 63 if(itemElement.length == 0) return false; 64 65 var quantity = itemElement.find('input[nh-quantity-product="quantity"]').val(); 66 var old_quantity = itemElement.attr('nh-cart-item-quantity'); 67 68 var price = itemElement.find('[nh-cart-price]').attr('nh-cart-price'); 69 var totalItem = itemElement.find('[nh-cart-total-item]'); 70 var total = wrapCartInfo.find('[nh-cart-total]'); 71 72 if(quantity != old_quantity){ 73 checkChangeQuantity = true; 74 } 75 totalItem.text(nhMain.utilities.parseNumberToTextMoney(quantity * price)); 76 totalItem.attr('nh-cart-total-item', quantity * price); 77 78 var sumTotal = 0; 79 wrapCartInfo.find('[nh-cart-item]').each(function(index) { 80 sumTotal += Number($(this).find('[nh-cart-total-item]').attr('nh-cart-total-item')); 81 }); 82 total.text(nhMain.utilities.parseNumberToTextMoney(sumTotal)); 83 }); 84 85 $(document).on('click', '[nh-cart-action="checkout"]', function(e) { 86 e.preventDefault(); 87 if(typeof(checkChangeQuantity) != _UNDEFINED && Boolean(checkChangeQuantity)){ 88 var items = []; 89 $('[nh-cart-item]').each(function(index) { 90 var productItemId = $(this).attr('nh-cart-item'); 91 var quantity = $(this).find('input[nh-quantity-product="quantity"]').val(); 92 93 if(productItemId > 0 && quantity > 0){ 94 items.push({ 95 'product_item_id': productItemId, 96 'quantity': quantity 97 }); 98 } 99 }); 100 101 if($.isEmptyObject(items)){ 102 nhMain.showAlert(_ERROR, nhMain.getLabel('khong_lay_duoc_thong_tin_gio_hang')); 103 return false; 104 } 105 nhMain.showLoading.page(); 106 self.updateCart(items, function(){ 107 window.location.href = '/order/info'; 108 }); 109 } 110 window.location.href = '/order/info'; 111 }); 112 113 $(document).on('click', '[nh-update-item-cart]', function(e) { 114 e.preventDefault(); 115 116 var item = []; 117 var wrapElement = $(this).closest('[nh-cart-item]'); 118 var productItemId = wrapElement.attr('nh-cart-item'); 119 var quantity = wrapElement.find('input[nh-quantity-product="quantity"]').val(); 120 121 if(productItemId > 0 && quantity > 0){ 122 item = [{ 123 'product_item_id': productItemId, 124 'quantity': quantity 125 }] 126 } 127 128 if($.isEmptyObject(item)){ 129 nhMain.showAlert(_ERROR, nhMain.getLabel('khong_lay_duoc_thong_tin_gio_hang')); 130 return false; 131 } 132 133 self.updateCart(item, function(){ 134 nhMain.showAlert(_SUCCESS, nhMain.getLabel('cap_nhap_gio_hang_thanh_cong')); 135 var wrapCartInfo = $('[nh-cart-info]'); 136 if(wrapCartInfo.length > 0){ 137 location.reload(); 138 } 139 nhOrder.sidebar.reloadSidebarCart(); 140 }); 141 142 }); 143 144 $(document).on('click', '[nh-remove-item-cart]', function(e) { 145 e.preventDefault(); 146 147 var productItemId = $(this).attr('nh-remove-item-cart'); 148 if(productItemId > 0){ 149 nhMain.showAlert(_WARNING, nhMain.getLabel('ban_co_muon_xoa_san_pham_nay_khoi_gio_hang_khong'), function(){ 150 nhOrder.cart.removeProductInCart(productItemId, function(){ 151 nhMain.showAlert(_SUCCESS, nhMain.getLabel('cap_nhap_gio_hang_thanh_cong')); 152 var wrapCartInfo = $('[nh-cart-info]'); 153 if(wrapCartInfo.length > 0){ 154 location.reload(); 155 } 156 nhOrder.sidebar.reloadSidebarCart(); 157 });
158 }); 159 } 160 }); 161 162 $(document).on('click', '[nh-btn-action="select-option"]:not(.disable)', function(e){ 163 e.preventDefault(); 164 $(this).tooltip('hide'); 165 var wrapElement = $(this).closest('[nh-product]'); 166 if(wrapElement == _UNDEFINED || wrapElement.length == 0){ 167 nhMain.showLog(nhMain.getLabel('khong_tim_thay_the_bao_ngoai_san_pham') + ' [nh-product]'); 168 return false; 169 }; 170 171 wrapElement.find('.inner-image').addClass('effect-attribute-cart'); 172 if(typeof(nhProduct.selectAttribute) != _UNDEFINED){ 173 nhProduct.selectAttribute.activeOptionDefault(wrapElement); 174 } 175 setTimeout(function(){ 176 wrapElement.addClass('active-quick-shop'); 177 }, 500); 178 179 setTimeout(function(){ 180 wrapElement.find('.inner-image').removeClass('effect-attribute-cart'); 181 }, 900); 182 }); 183 184 $(document).on('click', '[nh-btn-action="close-quick-shop"]:not(.disable)', function(e) { 185 var wrapElement = $(this).closest('[nh-product]'); 186 if(wrapElement == _UNDEFINED || wrapElement.length == 0){ 187 nhMain.showLog(nhMain.getLabel('khong_tim_thay_the_bao_ngoai_san_pham') + ' [nh-product]'); 188 return false; 189 }; 190 wrapElement.removeClass('active-quick-shop'); 191 }); 192 }, 193 addProductToCart: function(productItemId = null, quantity = 1, callback = null){ 194 var self = this; 195 196 if (typeof(callback) != 'function') { 197 callback = function () {}; 198 } 199 200 if(!productItemId > 0 || !quantity > 0){ 201 nhMain.showLog(nhMain.getLabel('du_lieu_khong_hop_le')); 202 return false; 203 } 204 205 nhMain.callAjax({ 206 async: true, 207 url: '/cart/add-product', 208 data: { 209 product_item_id: productItemId, 210 quantity: quantity 211 }, 212 }).done(function(response) { 213 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 214 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 215 216 if (code == _ERROR){ 217 nhMain.showAlert(_ERROR, message); 218 } 219 220 if (code == _SUCCESS && typeof(nhOrder.sidebar) != _UNDEFINED) { 221 callback(response); 222 } 223 224 225 }); 226 }, 227 removeProductInCart: function(productItemId = null, callback = null){ 228 var self = this; 229 230 if (typeof(callback) != 'function') { 231 callback = function () {}; 232 } 233 234 nhMain.callAjax({ 235 async: true, 236 url: '/cart/remove-product', 237 data: { 238 product_item_id: productItemId 239 }, 240 }).done(function(response) { 241 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 242 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 243 if (code == _SUCCESS) { 244 callback(); 245 } else { 246 nhMain.showAlert(_ERROR, message); 247 } 248 }); 249 }, 250 updateCart: function(items = [], callback = null){ 251 var self = this; 252 253 if (typeof(callback) != 'function') { 254 callback = function () {}; 255 } 256 257 nhMain.callAjax({ 258 async: true, 259 url: '/cart/update', 260 data: { 261 items: items 262 } 263 }).done(function(response) { 264 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 265 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 266 if (code == _SUCCESS) { 267 callback(); 268 } else { 269 nhMain.showAlert(_ERROR, message); 270 } 271 }); 272 } 273 }, 274 sidebar: { 275 sidebarCartElement: null, 276 miniCartElement: null, 277 init: function(){ 278 var self = this; 279 280 // validate element exist 281 self.sidebarCartElement = $('[nh-mini-cart="sidebar"]'); 282 if(self.sidebarCartElement == null || self.sidebarCartElement == _UNDEFINED || self.sidebarCartElement.length == 0){ 283 return false 284 }; 285 286 self.miniCartElement = $('[nh-total-quantity-mini-cart]'); 287 288 // reload cart if exist product added 289 var cartInfo = typeof(nhMain.dataInit.cart) != _UNDEFINED && nhMain.dataInit.cart != null ? nhMain.dataInit.cart : {}; 290 if(!$.isEmptyObject(cartInfo)){ 291 nhOrder.sidebar.reloadSidebarCart(); 292 } 293 294 295 // events of mini-cart 296 $(document).on('click', '[nh-mini-cart="open"]', function(e) { 297 e.preventDefault(); 298 self.toggleSidebarCart(!self.sidebarCartElement.hasClass('open')); 299 }); 300 301 $(document).on('click', '[nh-mini-cart="close"]', function(e) { 302 e.preventDefault(); 303 self.toggleSidebarCart(false); 304 }); 305 306 $(document).on('click', '[nh-remove-item-mini-cart]', function(e) { 307 e.preventDefault(); 308 var productItemId = $(this).attr('nh-remove-item-mini-cart'); 309 if(productItemId > 0){ 310 nhMain.showAlert(_WARNING, nhMain.getLabel('ban_co_muon_xoa_san_pham_nay_khoi_gio_hang_khong'), function(){ 311 nhOrder.cart.removeProductInCart(productItemId, function(){ 312 self.reloadSidebarCart(); 313 });
314 }); 315 } 316 }); 317 318 $(document).on('click', 'body', function(e) { 319 if(($(e.target).is('[nh-mini-cart="close"]') || $(e.target).is('body.dark-overlay')) && self.sidebarCartElement.hasClass('open')){ 320 self.toggleSidebarCart(false); 321 } 322 }); 323 }, 324 toggleSidebarCart: function(open = true){ 325 var self = this; 326 327 self.sidebarCartElement.toggleClass('open', open); 328 $('body').toggleClass('dark-overlay', open); 329 }, 330 reloadSidebarCart: function(callback = null){ 331 var self = this; 332 if (typeof(callback) != 'function') { 333 callback = function () {}; 334 } 335 336 nhMain.showLoading.block(self.sidebarCartElement); 337 nhMain.callAjax({ 338 url: '/cart/reload-sidebar-cart', 339 dataType: 'html' 340 }).done(function(response) { 341 342 self.sidebarCartElement.find('.content-mini-cart').html(response); 343 var totalQuantityCart = nhMain.utilities.parseInt(self.sidebarCartElement.find('[nh-total-quantity-cart]').attr('nh-total-quantity-cart')); 344 if(self.miniCartElement.length > 0){ 345 self.miniCartElement.html(totalQuantityCart); 346 } 347 348 nhMain.showLoading.remove(); 349 callback(); 350 }); 351 } 352 }, 353 orderInfo: { 354 formElement: null, 355 updateAddressModal: null, 356 init: function(){ 357 var self = this; 358 self.formElement = $('#order-info'); 359 self.updateAddressModal = $('#update-address-modal'); 360 if(self.formElement.length == 0) return; 361 362 nhMain.location.init({ 363 idWrap: ['#order-info'] 364 }); 365 366 nhMain.validation.phoneVn(); 367 var validator = self.formElement.validate({ 368 ignore: ':hidden', 369 rules: { 370 full_name: { 371 required: true, 372 minlength: 6, 373 maxlength: 255 374 }, 375 phone: { 376 required: true, 377 minlength: 10, 378 maxlength: 11, 379 phoneVN: true 380 }, 381 email: { 382 required: true, 383 email: true, 384 minlength: 10, 385 maxlength: 255 386 }, 387 address: { 388 required: true, 389 }, 390 city_id: { 391 required: true, 392 }, 393 district_id: { 394 required: true, 395 }, 396 }, 397 messages: { 398 full_name: { 399 required: nhMain.getLabel('vui_long_nhap_thong_tin'), 400 minlength: nhMain.getLabel('thong_tin_nhap_qua_ngan'), 401 maxlength: nhMain.getLabel('thong_tin_nhap_qua_dai') 402 }, 403 phone: { 404 required: nhMain.getLabel('vui_long_nhap_thong_tin'), 405 minlength: nhMain.getLabel('so_dien_thoai_khong_hop_le'), 406 maxlength: nhMain.getLabel('so_dien_thoai_khong_hop_le') 407 }, 408 email: { 409 required: nhMain.getLabel('vui_long_nhap_thong_tin'), 410 email: nhMain.getLabel('email_chua_dung_dinh_dang'), 411 minlength: nhMain.getLabel('thong_tin_nhap_qua_ngan'), 412 maxlength: nhMain.getLabel('thong_tin_nhap_qua_dai') 413 }, 414 address: { 415 required: nhMain.getLabel('vui_long_nhap_thong_tin'), 416 }, 417 city_id: { 418 required: nhMain.getLabel('vui_long_chon_thong_tin'), 419 }, 420 district_id: { 421 required: nhMain.getLabel('vui_long_chon_thong_tin'), 422 } 423 }, 424 errorPlacement: function(error, element) { 425 426 if(element.hasClass('selectpicker')){ 427 var formGroup = element.closest('.form-group'); 428 formGroup.append(error.addClass('invalid-feedback')); 429 }else{ 430 element.after(error.addClass('invalid-feedback')); 431 } 432 }, 433 invalidHandler: function(event, validator) { 434 validator.errorList[0].element.focus(); 435 }, 436 }); 437 438 $(document).on('click', '[nh-btn-action="create-order"]', function(e) { 439 e.preventDefault(); 440 441 if (validator.form()) { 442 nhMain.showLoading.page(); 443 444 var formData = self.formElement.serialize(); 445 nhMain.callAjax({ 446 url: '/order/create', 447 data: formData 448 }).done(function(response) { 449 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 450 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 451 var status = typeof(response.status) != _UNDEFINED ? response.status : null; 452 var data = typeof(response.data) != _UNDEFINED ? response.data : {}; 453 var orderCode = nhMain.utilities.notEmpty(data.code) ? data.code : ''; 454 455 var total = nhMain.utilities.notEmpty(data.total) ? nhMain.utilities.parseFloat(data.total) : 0; 456 var paid = nhMain.utilities.notEmpty(data.paid) ? nhMain.utilities.parseFloat(data.paid) : 0; 457 var debt = nhMain.utilities.notEmpty(data.debt) ? nhMain.utilities.parseFloat(data.debt) : 0; 458 459 if(code == _ERROR && status == 511){ 460 nhMain.showAlert(_ERROR, message); 461 setTimeout(function(){ 462 window.location.href = '/order/error'; 463 }, 2000); 464 465 return false; 466 } 467 468 nhMain.showLoading.remove(); 469 470 if(code == _ERROR && status != 511){ 471 nhMain.showAlert(_ERROR, message); 472 return false; 473 } 474 475 if(total == paid && debt == 0){ 476 window.location.href = '/order/success?code=' + orderCode; 477 }else{ 478 window.location.href = '/order/checkout?code=' + orderCode; 479 } 480 });
481 } 482 }); 483 484 $(document).on('click', '[nh-address="list"]', function(e){ 485 self.updateAddressModal.modal('show'); 486 $('[nh-form="member-address"]').find('input[name="callback"]').val('contact'); 487 }); 488 489 490 $(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) { 491 e.preventDefault(); 492 var ref = $(this).attr('href').replace('#', ''); 493 var tabContent = $('.tab-content'); 494 tabContent.find('.tab-pane').removeClass('active'); 495 tabContent.find('.tab-pane').removeClass('show'); 496 tabContent.find('.tab-pane').hide(); 497 tabContent.find('#' + ref).show(); 498 tabContent.find('#' + ref).addClass('active'); 499 tabContent.find('#' + ref).addClass('show'); 500 }); 501 502 $(document).on('click', '[nh-table="choose-row"] tbody tr', function(e){ 503 var addressId = $(this).attr('data-address-id'); 504 if(!nhMain.utilities.notEmpty(addressId)) return false; 505 506 self.chooseAddress(addressId, function(data){ 507 self.updateAddressModal.modal('hide'); 508 }); 509 }); 510 511 $(document).on('click', '[nh-order-login]', function(e){ 512 var loginModal = $('#login-modal'); 513 if(loginModal.length > 0){ 514 loginModal.modal('show'); 515 loginModal.find('input[name="redirect"]').val(window.location.href); 516 }else{ 517 window.location.href = '/member/login'; 518 } 519 }); 520 521 $(document).on('change', '#city_id', function(e) { 522 var shippingMethodId = $('[nh-shipping-method]').attr('nh-shipping-method'); 523 var cityId = $('#order-info').find('select[name="city_id"]').val(); 524 525 nhOrder.shippingMethod.loadListShippingMethod(cityId, shippingMethodId); 526 }); 527 }, 528 chooseAddress: function(address_id = null, callback = null){ 529 var self = this; 530 531 if (typeof(callback) != 'function') { 532 callback = function () {}; 533 } 534 535 if(!nhMain.utilities.notEmpty(address_id)) return false; 536 nhMain.callAjax({ 537 url: '/order/choose-address', 538 data:{ 539 address_id: address_id 540 } 541 }).done(function(response) { 542 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 543 544 var status = typeof(response.status) != _UNDEFINED ? response.status : null; 545 var data = typeof(response.data) != _UNDEFINED ? response.data : {}; 546 var orderCode = typeof(data.code) != _UNDEFINED ? data.code : null; 547 548 if(code == _ERROR && status == 511){ 549 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 550 nhMain.showAlert(_ERROR, message); 551 setTimeout(function(){ 552 window.location.href = '/order/error'; 553 }, 2000); 554 555 return false; 556 } 557 558 if(code == _ERROR && status != 511){ 559 nhMain.showAlert(_ERROR, message); 560 return false; 561 } 562 563 if (code == _SUCCESS) { 564 self.reload(); 565 callback(data); 566 } 567 }); 568 }, 569 reload: function(viewReload = null, wrapElement = null){ 570 var self = this; 571 572 if(wrapElement == null || wrapElement.length == 0) { 573 wrapElement = $('[nh-order-info]'); 574 } 575 576 var formData = self.formElement.serialize(); 577 if(viewReload != null && viewReload.length > 0){ 578 var firstChar = formData.length > 0 ? '&' : ''; 579 formData += firstChar + 'view_reload=' + viewReload; 580 } 581 582 583 nhMain.showLoading.page(); 584 nhMain.callAjax({ 585 url: '/order/info', 586 dataType: _HTML, 587 data: formData 588 }).done(function(response) { 589 wrapElement.html(response); 590 nhMain.showLoading.remove(); 591 592 $(document).find('.selectpicker').selectpicker('refresh'); 593 nhMain.input.inputMask.init($(document).find('.number-input'), 'number'); 594 }); 595 } 596 }, 597 checkout: { 598 init: function(){ 599 var formElement = $('#form-checkout'); 600 601 $(document).on('click', '[nh-btn-action="checkout"]', function(e) { 602 e.preventDefault(); 603 604 var paymentGateway = $('[nh-gateway-item].active').attr('nh-gateway-item'); 605 if(typeof(paymentGateway) == _UNDEFINED || paymentGateway.length == 0){ 606 nhMain.showAlert(_ERROR, nhMain.getLabel('khong_lay_duoc_ma_phuong_thuc_thanh_toan')); 607 return false; 608 } 609 610 formElement.find('input[name="payment_gateway"]').val(paymentGateway); 611 612 var formData = formElement.serialize(); 613 nhMain.showLoading.page(); 614 nhMain.callAjax({ 615 url: '/order/checkout/process', 616 data: formData 617 }).done(function(response) { 618 nhMain.showLoading.remove(); 619 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 620 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 621 var data = typeof(response.data) != _UNDEFINED ? response.data : {}; 622 var orderCode = typeof(data.code) != _UNDEFINED ? data.code : null; 623 var urlCheckout = typeof(data.url) != _UNDEFINED ? data.url : null; 624 625 if(code != _SUCCESS || orderCode == null || orderCode.length == 0){ 626 nhMain.showAlert(_ERROR, message); 627 return false; 628 } 629 630 if(urlCheckout != null && urlCheckout.length > 0){ 631 window.location.href = urlCheckout; 632 }else{ 633 window.location.href = '/order/success?code=' + orderCode; 634 } 635 636 }); 637 }); 638 } 639 }, 640 affiliate:{ 641 inputAffiliate: null, 642 init: function(){ 643 var self = this; 644 645 self.inputAffiliate = $('input#affiliate-code'); 646 if(self.inputAffiliate.length == 0) return; 647 648 $(document).on('click', '[nh-btn-action="apply-affiliate"]', function(e) { 649 if($('input#affiliate-code').val().length == 0){ 650 nhMain.showAlert(_ERROR, nhMain.getLabel('vui_long_nhap_ma_gioi_thieu')); 651 return false; 652 } 653 654 var affiliateCode = $('input#affiliate-code').val(); 655 656 self.applyAffiliate(affiliateCode, function(e){
657 nhOrder.orderInfo.reload('element_order_info_right', $('#order-info-right')); 658 }); 659 }); 660 661 $(document).on('click', '[nh-btn-action="delete-affiliate"]', function(e) { 662 self.deleteAffiliate(function(e){ 663 nhOrder.orderInfo.reload('element_order_info_right', $('#order-info-right'));; 664 }) 665 }); 666 }, 667 applyAffiliate: function(affiliateCode = null, callback = null){ 668 var self = this; 669 670 if (typeof(callback) != 'function') { 671 callback = function () {}; 672 } 673 674 nhMain.showLoading.page(); 675 nhMain.callAjax({ 676 url: '/affiliate/apply', 677 data:{ 678 affiliate_code: affiliateCode 679 } 680 }).done(function(response) { 681 nhMain.showLoading.remove(); 682 683 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 684 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 685 686 if(code == _ERROR){ 687 nhMain.showAlert(_ERROR, message); 688 return false; 689 } 690 691 if (code == _SUCCESS) { 692 nhMain.showAlert(_SUCCESS, message); 693 callback(); 694 } 695 }); 696 }, 697 deleteAffiliate: function(callback = null){ 698 var self = this; 699 700 if (typeof(callback) != 'function') { 701 callback = function () {}; 702 } 703 704 nhMain.showLoading.page(); 705 nhMain.callAjax({ 706 url: '/affiliate/delete', 707 }).done(function(response) { 708 nhMain.showLoading.remove(); 709 710 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 711 712 var status = typeof(response.status) != _UNDEFINED ? response.status : null; 713 var data = typeof(response.data) != _UNDEFINED ? response.data : {}; 714 715 if(code == _ERROR){ 716 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 717 nhMain.showAlert(_ERROR, message); 718 return false; 719 } 720 721 if (code == _SUCCESS) { 722 callback(); 723 } 724 }); 725 } 726 }, 727 coupon:{ 728 init: function(){ 729 var self = this; 730 731 self.orderCoupon.init(); 732 self.listCoupon.init(); 733 }, 734 orderCoupon:{ 735 inputCoupon: null, 736 coupon: null, 737 init: function(){ 738 var self = this; 739 740 self.inputCoupon = $('input#order-coupon-code'); 741 if(self.inputCoupon.length == 0) return; 742 743 self.event(); 744 }, 745 event: function(){ 746 var self = this; 747 748 $(document).on('click', '[nh-btn-action="apply-coupon"]', function(e) { 749 if($('input#order-coupon-code').val().length == 0){ 750 nhMain.showAlert(_ERROR, nhMain.getLabel('vui_long_nhap_ma_coupon')); 751 return false; 752 } 753 754 var couponCode = $('input#order-coupon-code').val(); 755 756 self.checkCoupon(couponCode, function(e){ 757 nhOrder.orderInfo.reload('element_order_info_right', $('#order-info-right')); 758 }); 759 }); 760 761 $(document).on('click', '[nh-btn-action="delete-coupon"]', function(e) { 762 self.deleteCoupon(function(e){ 763 nhOrder.orderInfo.reload('element_order_info_right', $('#order-info-right'));; 764 }) 765 }); 766 767 $(document).on('click', '[nh-btn-action="list-coupon"]', function(e){ 768 if(!nhOrder.coupon.listCoupon.modal.length > 0) return; 769 nhOrder.coupon.listCoupon.modal.modal('show'); 770 771 }); 772 }, 773 checkCoupon: function(couponCode = null, callback = null){ 774 var self = this; 775 776 if (typeof(callback) != 'function') { 777 callback = function () {}; 778 } 779 780 nhMain.showLoading.page(); 781 nhMain.callAjax({ 782 url: '/promotion/check-coupon', 783 data:{ 784 coupon: couponCode 785 } 786 }).done(function(response) { 787 nhMain.showLoading.remove(); 788 789 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 790 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 791 var status = typeof(response.status) != _UNDEFINED ? response.status : null; 792 var data = typeof(response.data) != _UNDEFINED ? response.data : {}; 793 794 if(code == _ERROR){ 795 nhMain.showAlert(_ERROR, message); 796 return false; 797 } 798 799 if (code == _SUCCESS) { 800 if($.isEmptyObject(data)) { 801 nhMain.showAlert(_ERROR, message); 802 return false; 803 } 804 805 // nhMain.showAlert(_SUCCESS, message, null, {timer: 1000}); 806 callback(data); 807 } 808 }); 809 }, 810 deleteCoupon: function(callback = null){ 811 var self = this; 812 813 if (typeof(callback) != 'function') { 814 callback = function () {}; 815 } 816 817 nhMain.showLoading.page(); 818 nhMain.callAjax({ 819 url: '/promotion/delete-coupon', 820 }).done(function(response) { 821 nhMain.showLoading.remove(); 822 823 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 824 var status = typeof(response.status) != _UNDEFINED ? response.status : null; 825 var data = typeof(response.data) != _UNDEFINED ? response.data : {}; 826 827 if(code == _ERROR){ 828 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 829 nhMain.showAlert(_ERROR, message); 830 return false; 831 } 832 833 if (code == _SUCCESS) { 834 callback(data); 835 } 836 }); 837 } 838 }, 839 listCoupon: { 840 modal: $('#list-coupon-modal'), 841 wrapElement: $('[nh-promotion]'), 842 init: function() { 843 var self = this; 844 if(self.wrapElement.length == 0) return; 845 846 self.event(); 847 }, 848 event: function(){ 849 var self = this; 850 851 $(document).on('click', '[nh-btn-action="select-coupon"]', function(e){
852 var code = $(this).attr('nh-coupon-code'); 853 854 // copy phieu giam gia 855 // var input_tmp = $('<input value="' + code + '">'); 856 // self.wrapElement.append(input_tmp); 857 // input_tmp.select(); 858 // document.execCommand('copy'); 859 // input_tmp.remove(); 860 861 // nhMain.showAlert(_SUCCESS, nhMain.getLabel('da_copy_ma_giam_gia')); 862 863 if(nhOrder.coupon.orderCoupon.inputCoupon.length > 0) { 864 nhOrder.coupon.orderCoupon.checkCoupon(code, function(e){ 865 self.modal.modal('hide'); 866 nhOrder.orderInfo.reload('element_order_info_right', $('#order-info-right')); 867 }); 868 } 869 }); 870 } 871 } 872 }, 873 point:{ 874 init: function(){ 875 var self = this; 876 877 $(document).on('click', '[nh-btn-action="apply-point-promotion"]', function(e){ 878 if($('#point-promotion').length == 0) return false; 879 880 var pointPromotion = $('#point-promotion').val().replace(',', ''); 881 if(pointPromotion.length == 0){ 882 nhMain.showAlert(_ERROR, nhMain.getLabel('vui_long_nhap_diem')); 883 return false; 884 } 885 886 self.applyPoint(pointPromotion, _PROMOTION, function(e){ 887 nhOrder.orderInfo.reload(); 888 }); 889 }); 890 891 $(document).on('click', '[nh-btn-action="apply-point-promotion-all"]', function(e){ 892 if($('#point-promotion').length == 0) return false; 893 894 var pointMax = $('#point-promotion').attr('nh-point-max'); 895 if(pointMax.length == 0){ 896 nhMain.showAlert(_ERROR, nhMain.getLabel('khong_lay_duoc_thong_tin_so_diem')); 897 return false; 898 } 899 900 self.applyPoint(pointMax, _PROMOTION, function(e){ 901 nhOrder.orderInfo.reload(); 902 }); 903 }); 904 905 $(document).on('click', '[nh-btn-action="apply-wallet"]', function(e){ 906 if($('#wallet').length == 0) return false; 907 908 var pointWallet = $('#wallet').val().replace(',', ''); 909 if(pointWallet.length == 0){ 910 nhMain.showAlert(_ERROR, nhMain.getLabel('vui_long_nhap_diem')); 911 return false; 912 } 913 914 self.applyPoint(pointWallet, _WALLET, function(e){ 915 nhOrder.orderInfo.reload(); 916 }); 917 }); 918 919 $(document).on('click', '[nh-btn-action="apply-wallet-all"]', function(e){ 920 if($('#wallet').length == 0) return false; 921 922 var pointMax = $('#wallet').attr('nh-point-max'); 923 if(pointMax.length == 0){ 924 nhMain.showAlert(_ERROR, nhMain.getLabel('khong_lay_duoc_thong_tin_so_diem')); 925 return false; 926 } 927 928 self.applyPoint(pointMax, _WALLET, function(e){ 929 nhOrder.orderInfo.reload(); 930 }); 931 }); 932 933 $(document).on('keyup keypess keydown', '#point-promotion', function(e) { 934 var pointToMoney = $(this).attr('nh-point-money'); 935 var pointMax = $(this).attr('nh-point-max'); 936 var point = $(this).val().replace(',', ''); 937 938 if(parseInt(pointMax) < parseInt(point)) { 939 point = pointMax; 940 $(this).val(pointMax); 941 } 942 943 var wrapElement = $(this).closest('.input-group'); 944 945 var labelPointToMoney = wrapElement.find('.point-to-money'); 946 947 labelPointToMoney.text(nhMain.utilities.parseNumberToTextMoney(pointToMoney * point)); 948 }); 949 950 $(document).on('keyup keypess keydown', '#wallet', function(e) { 951 var pointToMoney = $(this).attr('nh-point-money'); 952 var pointMax = $(this).attr('nh-point-max'); 953 var point = $(this).val().replace(',', ''); 954 955 if(parseInt(pointMax) < parseInt(point)) { 956 point = pointMax; 957 $(this).val(pointMax); 958 } 959 960 var wrapElement = $(this).closest('.input-group'); 961 962 var labelPointToMoney = wrapElement.find('.point-to-money'); 963 964 labelPointToMoney.text(nhMain.utilities.parseNumberToTextMoney(pointToMoney * point)); 965 }); 966 967 $(document).on('click', '[nh-btn-action="delete-wallet"]', function(e) { 968 self.deletePoint(_WALLET, function(e){ 969 nhOrder.orderInfo.reload(); 970 }) 971 }); 972 973 $(document).on('click', '[nh-btn-action="delete-point-promotion"]', function(e) { 974 self.deletePoint(_PROMOTION, function(e){ 975 nhOrder.orderInfo.reload(); 976 }) 977 }); 978 }, 979 applyPoint: function(point = null, type = null, callback = null) { 980 var self = this; 981 982 if (typeof(callback) != 'function') { 983 callback = function () {}; 984 } 985 986 nhMain.showLoading.page(); 987 nhMain.callAjax({ 988 url: '/customer/point/apply-order', 989 data:{ 990 type: type, 991 point: point 992 } 993 }).done(function(response) { 994 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 995 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 996 var status = typeof(response.status) != _UNDEFINED ? response.status : null; 997 var data = typeof(response.data) != _UNDEFINED ? response.data : {}; 998 999 nhMain.showLoading.remove(); 1000 if(code == _ERROR){ 1001 nhMain.showAlert(_ERROR, message); 1002 return false; 1003 } 1004 1005 if (code == _SUCCESS) { 1006 if($.isEmptyObject(data)) { 1007 nhMain.showAlert(_ERROR, message); 1008 return false; 1009 } 1010 callback(data); 1011 } 1012 }); 1013 }, 1014 deletePoint: function(type = null, callback = null){ 1015 var self = this; 1016 1017 if (typeof(callback) != 'function') { 1018 callback = function () {}; 1019 } 1020 nhMain.showLoading.page(); 1021 nhMain.callAjax({ 1022 url: '/customer/point/clear-in-order', 1023 data: { 1024 type: type 1025 } 1026 }).done(function(response) { 1027 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 1028 1029 var status = typeof(response.status) != _UNDEFINED ? response.status : null; 1030 var data = typeof(response.data) != _UNDEFINED ? response.data : {}; 1031 nhMain.showLoading.remove(); 1032 if(code == _ERROR){ 1033 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 1034 nhMain.showAlert(_ERROR, message); 1035 return false; 1036 } 1037 1038 if (code == _SUCCESS) { 1039 callback(data); 1040 } 1041 }); 1042 } 1043 }, 1044 shippingMethod: { 1045 wrapElement: $('[nh-wrap="shipping-method"]'), 1046 init: function(){ 1047 var self = this; 1048 if(self.wrapElement.length == 0) return; 1049 1050 self.event(); 1051 }, 1052 event: function(){ 1053 var self = this; 1054 1055 $(document).on('change', '[nh-shipping-method]', function(e) { 1056 var shippingMethodId = $(this).attr('nh-shipping-method'); 1057 var cityId = $('#order-info').find('select[name="city_id"]').val(); 1058 1059 self.loadListShippingMethod(cityId, shippingMethodId); 1060 }); 1061 1062 $(document).on('change', 'form#order-info select[name="city_id"]', function(e) { 1063 nhOrder.orderInfo.reload('element_order_info_right', $('#order-info-right'));; 1064 }); 1065 }, 1066 loadListShippingMethod: function (city_id = null, shipping_method_id = null) { 1067 nhMain.showLoading.page(); 1068 nhMain.callAjax({ 1069 url: '/order/shipping-method/select', 1070 data: { 1071 shipping_method_id: typeof(shipping_method_id) != _UNDEFINED ? shipping_method_id : null, 1072 city_id: typeof(city_id) != _UNDEFINED ? city_id : null, 1073 } 1074 }).done(function(response) { 1075 var code = typeof(response.code) != _UNDEFINED ? response.code : _ERROR; 1076 var message = typeof(response.message) != _UNDEFINED ? response.message : ''; 1077 var data = typeof(response.data) != _UNDEFINED ? response.data : {}; 1078 1079 if(code != _SUCCESS){ 1080 nhMain.showLoading.remove(); 1081 nhMain.showAlert(_ERROR, message); 1082 return false; 1083 }else{ 1084 nhOrder.orderInfo.reload('element_order_info_right', $('#order-info-right'));; 1085 } 1086 }); 1087 } 1088 } 1089} 1090 1091nhOrder.init();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.