Blame view

public/js/home/address-modify.page.js 2.1 KB
郭成尧 authored
1 2 3 4 5 6
/**
 * 订单 地址修改
 * @author: liangxiaosong
 * @date: 2016/5/11
 */
lijing authored
7
let $ = require('yoho-jquery'),
8
    tip = require('plugin/tip');
郭成尧 authored
9
lijing authored
10
let $confimMod = $('.confim-modify-mask'),
郭成尧 authored
11 12
    $modifyAdd = $('.modifyAdd'),
    orderCode = $modifyAdd.data('orderCode'),
13 14
    $pageWrap = $('.page-wrap'),
    $footer = $('#yoho-footer'),
zhangxiaoru authored
15 16
    $addAddress = $('.add-address'),
    $addressItem = $('.address-item'),
郭成尧 authored
17 18
    selectId;
19
require('common');
郭成尧 authored
20
21 22 23 24 25
$pageWrap.first().css('min-height', function() {
    return $(window).height() - $('#yoho-header').height() - $footer.height();
});
window.rePosFooter();
郭成尧 authored
26 27 28 29
$('.address-item').on('touchend', function() {
    selectId = $(this).data('addressId');

    if ($modifyAdd.data('rel') === true) {
30
        $confimMod.find('.modify-content').text('关联订单的收货地址将会一起修改且不可修改第二次,请确认是否修改?');
郭成尧 authored
31 32
        $confimMod.fadeIn();
    } else {
33
        $confimMod.find('.modify-content').text('收货地址仅且只能修改一次,请确认是否修改?');
郭成尧 authored
34 35 36 37
        $confimMod.fadeIn();
    }
});
郭成尧 authored
38
$confimMod.on('touchend', '.cancel', function() {
郭成尧 authored
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    selectId = null;
    $confimMod.fadeOut();
    return false;
}).on('touchend', '.confim', function() {
    $.ajax({
        method: 'GET',
        url: '/home/chooseAddress',
        data: {
            addressId: selectId,
            orderCode: orderCode
        }
    }).then(function(res) {
        if ($.type(res) !== 'object') {
            res = {};
        }
        if (res.code !== 200) {
            $confimMod.fadeOut();
            tip.show(res.message || '网络出了点问题~');
        } else {
            window.location.href = '/home/orderdetail?order_code=' + orderCode;
        }
    }).fail(function() {
        tip.show('网络出了点问题~');
    }).always(function() {
        selectId = null;
    });
    return false;
});
zhangxiaoru authored
67
zhangxiaoru authored
68
// 添加地址
zhangxiaoru authored
69 70 71 72 73 74 75 76
if ($addressItem.length < 5) {
    $addAddress.attr('href', $addAddress.data('href'));
}
$addAddress.on('touchend', function() {
    if ($addressItem.length >= 5) {
        tip.show('您最多添加5个收货地址');
        return false;
    }
zhangxiaoru authored
77
});