
 
<div class="Hrow Hpadd-2per">
	
<div  class="Hpadd-15 Hbg-white Hround-10 Hform-med" style="max-width:700px;" name="frm" action="" method="post" enctype="text/plain" >
    <h3 clas="Hrow" style="padding-right:2%">ثبت | ویرایش  &nbsp; &nbsp;آدرس کاربر </h3>     

     <div class="Hrow Hpadd-1per">
             <label class="Hrow HpaddR-10" data-color="#424750">آدرس ها :</label>
             <div class="Hrow listShow-N2 HpaddT-10 HpaddB-10" id="addslist">
                 @{if model.data}
                 @{foreach m in model.data}
                 <div class="Hrow Hpadd-5 useraddress-list" >
                    <input type="hidden" value="@{m._id}"/>
                    <div class="Hcol-xlg-6 Hcol-lg-6 Hcol-xmd-6 Hcol-md-12 Hcol-xsm-6 Hcol-sm-12 Hcol-xs-12 Hcol-xss-12 Hpadd-5 Htxt-center"  idc="@{m._idc}" idp="@{m._idp}">@{m.province} - @{m.city}</div>
                    <div class="Hcol-xlg-6 Hcol-lg-6 Hcol-xmd-6 Hcol-md-12 Hcol-xsm-6 Hcol-sm-12 Hcol-xs-12 Hcol-xss-12 Hpadd-5 Htxt-center">@{m.postcode}</div>
                    <div class="Hrow Hpadd-5">@{m.address}</div>
                    <b class="Hbtn-mini Hbg-digired fas fa-trash-alt Hfloat-L remove-address" style="color:#fff;"></b>
                    <b class="Hbtn-mini Hbg-sharpyellow fas fa-pencil-alt Hfloat-L update-address" style="color:#fff;"></b>
                </div>
                @{end}
                @{fi}

             </div>
            <button class="trans0_25 Hbtn Hbtn-skyblue"  type="button" id="mdad" data-selector="#modal_address" data-target="Hmodal" data-action="" style="font-size:14px;"><b class="fa fa-plus HpaddL-5" style="position:relative;top:1px;"></b> افزودن آدرس</button>
            <button style="display:none" type="button" id="mdad2" data-selector="#modal_address" data-target="Hmodal" data-action="">  </button>

     </div> 
     
</div>



</div>
 
<div class="Hmodal" id="modal_address"> 
  <div class="Hmodal-sm Hcards" style="background:#fff;border-radius:5px;">
    <div class="Hcards-header">
      <div class="close"  style="background:#ff3333;border-radius:4px;"></div>
    </div>
    <div class="Hcards-content Hpadd-10">
        <form id="frm"  name="frm" action="" method="post" enctype="text/plain">
            <input type="hidden" name="addressid" id="addressid" value=""/>
            <label for="province" class="Hrow HpaddR-10" data-color="#424750">استان</label>
            <select class="Hrow Htxt-center Hbg-white" style="border:1px solid #bbb;" name="province" id="province">
                @{view('~partial/province',model)}
            </select>
            
            <label for="city" class="Hrow HpaddR-10" data-color="#424750">شهر</label>
            <select class="Hrow Htxt-center Hbg-white" style="border:1px solid #bbb;" disabled=true name="city" id="city" >
                <option value="0" disabled="disabled" selected>انتخاب شهر</option>
            </select>
            
            <label class="Hrow HpaddR-10" data-color="#424750">کد پستی</label>
            <input type="text" class="Hrow Htxt-center" style="border:1px solid #bbb;" id="Fpostcode" name="postcode" />
            <label class="Hrow HpaddR-10" data-color="#424750">آدرس</label>
            <textarea type="text" class="Hrow HpaddR-10 HmarB-10" style="border:1px solid #bbb;resize: none;" id="Faddress" name="address" ></textarea>
            <input  class="trans0_25 Hbtn-fullfix Hbtn-lightGreen Hpadd-15"  type="button" id="addaddress" value=" افزودن آدرس"/>
            <input  class="trans0_25 Hbtn-fullfix Hbtn-yellow2 Hpadd-15"  type="button" id="updaddress" value=" ویرایش آدرس"/>

        </form>
    </div>
    
  </div>
</div>


@{section footer}
  <script type="text/javascript">



function show_res2(result){
    switch(result.status){
     case 200:
            var city=$("#city option:selected").text();
            var province=$("#province option:selected").text();
            var id=$("#addressid").val();
            var obj=$(".useraddress-list input[value='"+id+"']").parent();
            
            obj.children("div").eq(0).text(province +' - '+ city);
            obj.children("div").eq(0).attr("idc",$("#city").val());
            obj.children("div").eq(0).attr("idp",$("#province").val());
            obj.children("div").eq(1).text($("#Fpostcode").val());
            obj.children("div").eq(2).text($("#Faddress").val());
            $("#modal_address .close").trigger("click");
            document.getElementById("frm").reset();
            Hnotification({status:"success",Cstyle:[{color:"#000000"}],Ctext:result.data});
      break;
        default:
            Hnotification({status:"warning",Cstyle:[{color:"#000000"}],Ctext:result.data});
      break;
    }
}


function show_res3(result){
    switch(result.status){
     case 200:
            Hnotification({status:"success",Cstyle:[{color:"#000000"}],Ctext:result.data});
            var obj=$(".useraddress-list input[value='"+result.id+"']").parent().remove();
            
      break;
        default:
            Hnotification({status:"warning",Cstyle:[{color:"#000000"}],Ctext:result.data});
      break;
    }
}


var opensubmit=[0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1];






$(document).ready(function(){

    
    
    

    
    
    $("#province").change(async function(event,city=false,idcity=0){
                
                $("#city").attr("disabled",true);
                if($(this).val()!=0){
                    var res=await jqajax("/city/","province="+$(this).val(),"get","loader");
                    $("#city").html("");
                    if(res.status==200){
                        if(city){
                           
                            $("#city").html($("#city").html()+'<option value="0" disabled="disabled" selected>انتخاب شهر</option>');
                            for(m in res.data){
                                if(idcity!=res.data[m]._id){
                                    $("#city").html($("#city").html()+"<option value="+res.data[m]._id+" >"+res.data[m].city+"</option>");
                                }else{
                                    $("#city").html($("#city").html()+"<option value="+res.data[m]._id+" selected>"+res.data[m].city+"</option>");
                                }
                                
                            }
                            $("#city").attr("disabled",false);
                        }else{
                            $("#city").html($("#city").html()+'<option value="0" disabled="disabled" selected>انتخاب شهر</option>');
                            for(m in res.data){
                                $("#city").html($("#city").html()+"<option value="+res.data[m]._id+" >"+res.data[m].city+"</option>");
                            }
                            $("#city").attr("disabled",false);
                        }
                        
                    }
                }else{
                      $("#city").attr("disabled",true);
                }
    });
    
    
    
    $("#mdad").click(function(){
        $("#addaddress").css("display","block");
        $("#updaddress").css("display","none");

    });
    
    $("#mdad2").click(function(){
        $("#addaddress").css("display","none");
        $("#updaddress").css("display","block"); 
    });
    
    $(document).on("click",".update-address",function(){
        $("#mdad2").trigger("click");
        var citypro=$(this).parent().children("div").eq(0);
        $("#province").val(citypro.attr("idp"));
        $("#province").trigger("change",[true,citypro.attr("idc")]);
        
        $("#Fpostcode").val($(this).parent().children("div").eq(1).text());
        $("#Faddress").val($(this).parent().children("div").eq(2).text());
        
        $("#addressid").val($(this).parent().children("input").eq(0).val());
    });
    
    
    
});

</script>


@{end}