Blame view

public/js/home/order-address-modify.page.js 2.07 KB
陈峰 authored
1
import Vue from 'vue';
陈峰 authored
2 3
require('scss/common.scss');
require('scss/home/order-address-modify.page.scss');
lijing authored
4
郭成尧 authored
5
const $ = require('yoho-jquery');
陈峰 authored
6 7
const tip = require('js/plugin/tip');
const stringHandle = require('js/common/helpers/stringHandle');
郭成尧 authored
8
陈峰 authored
9
require('js/common');
郭成尧 authored
10
郭成尧 authored
11 12 13 14 15
let $areaForm = $('#areaForm');
let $btnSure = $('#btnSure');
let $province = $('input[name=province]');
let $provinceCode = $('input[name=provinceCode]');
let $area = $('#area');
Targaryen authored
16
let $usernameInput = $areaForm.find('input[name=username]');
陈峰 authored
17 18

import vueAddressAct from 'vues/home/address/address-act.vue';
郭成尧 authored
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

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;
});
郭成尧 authored
38
Targaryen authored
39
$usernameInput.bind('input propertychange', function() {
郭成尧 authored
40
    if (stringHandle.chinese2($usernameInput.val()) > 20) {
Targaryen authored
41
        tip.show('收货人姓名最多支持20个字');
郭成尧 authored
42
        $usernameInput.val($usernameInput.val() && stringHandle.sub_chinese2($usernameInput.val(), 20));
Targaryen authored
43 44 45
    }
});
郭成尧 authored
46 47 48 49
/**
 * 提交表单
 */
$btnSure.on('click', function() {
Targaryen authored
50
    let username = $usernameInput.val().replace(/(^\s+)|(\s+$)/g, '');
51
郭成尧 authored
52
    if (username && !/^[\u4E00-\u9FA5A-Za-z0-9*]+$/gi.test(username)) {
53 54 55 56
        tip.show('收货人姓名不支持特殊符号');
        return false;
    }
郭成尧 authored
57 58
    $.post('/home/orders/changeAddress', $areaForm.serialize(), function(result) {
        if (result && result.code === 200) {
郭成尧 authored
59 60 61
            if (result.data && result.data.is_modified === 'Y') {
                tip.show(result.data.tips);
            }
郭成尧 authored
62
            location.href = document.referrer;
郭成尧 authored
63
        } else {
郭成尧 authored
64
            tip.show((result && result.message) || '系统错误,请重试!');
郭成尧 authored
65 66
        }
    });
郭成尧 authored
67
});
郭成尧 authored
68 69 70 71 72 73 74

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