<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>2.6新增地址</title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1, minimum-scale=1">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/base.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/swiper.min.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/weui.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/myweui.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/common/add_address.css">
    <script src="__TMPL__/public/assets/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__TMPL__/public/assets/js/weui.js" type="text/javascript" charset="utf-8"></script>
    <script src="__TMPL__/public/assets/js/myweui.js" type="text/javascript" charset="utf-8"></script>
    <script src="__TMPL__/public/assets/js/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="__TMPL__/public/assets/js/citypicker.js" type="text/javascript" charset="utf-8"></script>
    <style>

    </style>
</head>

<body>
    <div class="container">
        <p class="link_man"><img class="user_pic" src="__TMPL__/public/assets/images/user.png" alt="">联系人</p>
        <div class="user_box">
            <p class="user_name"><span>姓名:</span>
                <input type="text" placeholder="请输入姓名" class="name">
            </p>
            <p class="user_tel"><span>电话:</span>
                <input type="text" placeholder="请输入手机或固定电话" class="tel">
            </p>
        </div>
        <p class="link_man"><img class="user_pic" src="__TMPL__/public/assets/images/dizhi.png" alt="">收货地址</p>
        <div class="address_box">
            <p class="user_diqu"><span>选择地区:</span>
                <input class="select_city" type="text" placeholder="请选择省份/城市/地区" readonly>
                <input class="city_number" type="hidden" >
                <!--<img class="local_icon" src="__TMPL__/public/assets/images/aaaaaa@2x.png" alt="">-->
            </p>
            <p class="user_dizhi"><span>详细地址:</span>
                <input type="text" placeholder="请输入街道/楼层/门牌号" class="address">
            </p>
        </div>
    </div>
    </div>
    <footer class="footer">
        <p class="add_address">保存收货地址</p>
    </footer>
    </div>
    <script>
    $('.select_city').on('click', function() {
        weui.picker(rawCitiesData, {
            defaultValue: ["110000", "110000", "110101"],
            onConfirm: function(result) {
                console.log(result)
                $('.select_city').val(result[0].label + '-' + result[1].label + '-' + result[2].label);
                $('.city_number').val(result[0].value + '-' + result[1].value + '-' + result[2].value);
            }
        });
    })

    // 提交
    $('.add_address').click(function () {
        var name = $('.name').val();
        var tel = $('.tel').val();
        var city = $('.select_city').val();
        var address = $('.address').val();
        var city_number = $('.city_number').val();
        var nameReg = /^[\u4e00-\u9fa5]+$/;
        if (!nameReg.test(name)){
            alert("姓名只能是汉字");
        }else if(tel.length == 0){
            alert("手机号不能为空");
        }else if(city.length == 0){
            alert("地区不能为空");
        }else if(address.length == 0){
            alert("详细地址不能为空");
        }else{
            $.ajax({
                type:"POST",
                url:"{:url('Address/add')}",
                data:{
                    "name":name,
                    "tel":tel,
                    "city":city,
                    "address":address,
                    "city_number":city_number,
                },
                success:function (data) {
                    alert(data.message);
                    if(data.code == 1){
                        window.location.href = "{:url('Address/index')}";
                    }
                },
                error:function () {
                }
            })
        }
        // var pattern = /^1[3|4|5|6|7|8|9]\d{1}\s\d{4}\s\d{4}$/;

    })
    </script>
</body>

</html>