order-address-modify.page.js 1.83 KB
require('common.css');
require('home/order-address-modify.page.css');

const $ = require('yoho-jquery');
const Vue = require('vue');
const tip = require('plugin/tip');

require('common');

let $areaForm = $('#areaForm');
let $btnSure = $('#btnSure');
let $province = $('input[name=province]');
let $provinceCode = $('input[name=provinceCode]');
let $area = $('#area');

let vueAddressAct = require('home/address/address-act.vue');

let addressVact = new Vue({
    el: '#vAddressAct',
    components: {
        vueAddressAct: vueAddressAct
    }
});

/**
 * 弹出地址选择框
 */
$area.on('click', function() {
    if ($provinceCode.val() && $province.val()) {
        addressVact.$children[0].supportChangeProvince = false;
        addressVact.$children[0].switchAddress($provinceCode.val(), $province.val());
    }

    addressVact.$children[0].show = true;
});

/**
 * 提交表单
 */
$btnSure.on('click', function() {
    let username = $areaForm.find('input[name=username]').val();

    username = username.replace(/(^\s+)|(\s+$)/g, '');

    if (username && username.length > 20) {
        tip.show('收货人姓名最多支持20个字');
        return false;
    }

    if (username && /([^u4e00-\u9fa5])([^\p{P}])/gi.test(username)) {
        tip.show('收货人姓名不支持特殊符号');
        return false;
    }

    $.post('/home/orders/changeAddress', $areaForm.serialize(), function(result) {
        if (result && result.code === 200) {
            if (result.data && result.data.is_modified === 'Y') {
                tip.show(result.data.tips);
            }
            location.href = document.referrer;
        } else {
            tip.show((result && result.message) || '系统错误,请重试!');
        }
    });
});

/**
 * 动态更改页面高度
 */
$(function() {
    $('.address-modify').css('height', $(window).height());
});