<!--{include file="<!--{$mpath}-->block_header.tpl"}-->
<!--loading页开始-->
<div class="loading">
    <div class="loader">
        <div class="loader-inner pacman">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
</div>
<!--loading页结束-->
<body>
<header class="mui-bar mui-bar-nav report-header box-s" id="header">
    <a href="javascript:history.go(-1)"><i class="iconfont icon-fanhui fl"></i></a>
    <p>添加新地址</p>
    <span class="fr baocun">保存</span>
</header>
<div id="main" class="mui-clearfix add-address">
    <input type="hidden" id="id" value="<!--{$addressid}-->"/>
    <div class="plist clearfloat data">
        <ul>
            <li class="clearfloat">
                <a href="#">
                    <p class="fl">收货人</p>
                    <input type="text" class="fr shuru" name="name" id="name" value="<!--{$data.name}-->" placeholder="" />
                </a>
            </li>
            <li class="clearfloat">
                <a href="#">
                    <p class="fl">联系电话</p>
                    <input type="text" class="fr shuru" name="phone" id="phone" value="<!--{$data.phone}-->" placeholder="" />

                </a>
            </li>
            <li class="clearfloat">
                <a href="#">
                    <p class="fl">所在地区</p>
                </a>
                <select onchange="get_city(this);" id="province" name="provinceid"  class="form-control" style="width:33.3%; float: left;">
                    <option value="">选择省份</option>
                    <!--{foreach $province as $volist}-->
                    <option value="<!--{$volist.id}-->"  <!--{if $volist.name == <!--{$data.province}-->}-->selected<!--{/if}--> ><!--{$volist.name}--></option>
                    <!--{/foreach}-->
                </select>
                <select onchange="get_area(this)" id="city" name="cityid" class="form-control" style="width:33.3%; float: left; margin-left: 20px;">
                    <option value="">请选择市</option>
                    <!--{foreach $city as $volist}-->
                    <option value="<!--{$volist.id}-->" <!--{if $volist.name == <!--{$data.city}-->}-->selected<!--{/if}--> ><!--{$volist.name}--></option>
                    <!--{/foreach}-->
                </select>
                <select id="district" name="countyid" title="请选择所在区县" class="form-control"  style="width:33.3%; float: left;">
                    <option value="">请选择县/区</option>
                    <!--{foreach $area as $volist}-->
                    <option value="<!--{$volist.id}-->" <!--{if $volist.name == <!--{$data.county}-->}-->selected<!--{/if}--> ><!--{$volist.name}--></option>
                    <!--{/foreach}-->
                </select>
            </li>
        </ul>
    </div>
    <textarea id="address" name="address" rows="4" cols="" placeholder="请填写详细地址" class="textare box-s"><!--{$data.address}--></textarea>
    <div class="address-btn clearfloat">
        <span class="szwmr fl">设为默认</span>
        <!--{if $data.is_mo == '1'}-->
        <a href="#" class="toggle toggle--off fr" id="xuan"></a>
        <!--{else}-->
        <a href="#" class="toggle toggle--on fr" id="xuan"></a>
        <!--{/if}-->

    </div>
</div>
</body>
<script type="text/javascript" src="<!--{$mpath}-->js/jquery-1.8.3.min.js" ></script>
<script src="<!--{$mpath}-->layer_mobile/layer.js"></script>
<script src="<!--{$mpath}-->js/fastclick.js"></script>
<script src="<!--{$mpath}-->js/mui.min.js"></script>
<script type="text/javascript" src="<!--{$mpath}-->js/hmt.js" ></script>
<script type="text/javascript" src="<!--{$mpath}-->js/jquery.min.js"></script>
<!--默认按钮-->
<script type="text/javascript">
    $('.baocun').click(function(e){
            var name = $("#name").val();
            var phone = $("#phone").val();
            var address = $("#address").val();
            var id = $("#id").val();
            var province = $("#province").val();
            var city = $("#city").val();
            var district = $("#district").val();

            if($('#xuan').hasClass('toggle--off')){
                var is_mo= 'on';
            }
            $.post("<!--{$urlpath}-->index.php?c=user&a=add_address", {
                name: name,
                phone: phone,
                address: address,
                provinceid:province,
                cityid:city,
                countyid:district,
                id:id,
                is_mo:is_mo
            }, function (data) {
                if (data.response == '1') {
                        layer.open({
                            content: data.result
                            ,skin: 'msg'
                            ,time: 2 //2秒后自动关闭
                        });
                        setTimeout( function(){
                            javascript:history.go(-1);
                        }, 2 * 1000 );//延迟5000毫米
                } else {
                    layer.open({
                        content: data.result
                        ,skin: 'msg'
                        ,time: 2 //2秒后自动关闭
                    });
                }
            }, "json");

    });


    $('.toggle').click(function(e){

        var toggle = this;

        e.preventDefault();

        $(toggle).toggleClass('toggle--on').toggleClass('toggle--off').addClass('toggle--moving');

        setTimeout(function(){
            $(toggle).removeClass('toggle--moving');
        }, 200)

    });
    /**
     * 获取省份
     */
    function get_province() {
        var url = 'index.php?c=product&a=getRegion&level=1&parent_id=0';
        $.ajax({
            type: "GET",
            url: url,
            error: function (request) {
                alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function (v) {
                v = '<option value="0">选择省份</option>' + v;
                $('#province').empty().html(v);
            }
        });
    }

    /**
     * 获取城市
     * @param t  省份select对象
     */
    function get_city(t) {
        var parent_id = $(t).val();
        if (!parent_id > 0) {
            return;
        }
        $('#district').empty().css('display', 'none');
        $('#twon').empty().css('display', 'none');
        var url = 'index.php?c=product&a=getRegion&level=2&parent_id=' + parent_id;
        $.ajax({
            type: "GET",
            url: url,
            error: function (request) {
                alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function (v) {
                v = '<option value="0">选择城市</option>' + v;
                $('#city').empty().html(v);
            }
        });
    }

    /**
     * 获取地区
     * @param t  城市select对象
     */
    function get_area(t) {
        var parent_id = $(t).val();
        if (!parent_id > 0) {
            return;
        }
        $('#district').empty().css('display', 'inline');
        $('#twon').empty().css('display', 'none');
        var url = 'index.php?c=product&a=getRegion&level=3&parent_id=' + parent_id;
        $.ajax({
            type: "GET",
            url: url,
            error: function (request) {
                alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function (v) {
                v = '<option>选择区域</option>' + v;
                $('#district').empty().html(v);
            }
        });
    }
</script>
</html>

