<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<link href="/plugins/addons/{$GzhxPluginPath}/template/js/layui/css/layui.css" rel="stylesheet" />
<style>
  .layui-layer-msg{
    z-index: 99999999999999!important;
  }
  .table-switch{
    display: block;
    min-height: unset;
  }
  .domain-table-tools{
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
  .domain-table-tools>a{
    flex-basis: auto;
    flex-grow: 0;
    flex-shrink: 0;
  }
  .domain-table-tools>input{
    width: 200px;
  }
  .pagination {
    display: flex;
    justify-content: center;
    padding-left: 0;
    margin: 20px 0;
    border-radius: 4px;

  }
  .pagination > li {
    display: inline;
  }
  .pagination > li > a, .pagination > li > span {
    position: relative;
    float: left;
    padding: 6px 12px;
    margin-left: -1px;
    line-height: 1.42857143;
    color: #337ab7;
    text-decoration: none;
    background-color: #fff;
    border: 1px solid #ddd;
  }
  .pagination > .active > a, .pagination > .active > span, .pagination > .active > a:hover, .pagination > .active > span:hover, .pagination > .active > a:focus, .pagination > .active > span:focus {
    z-index: 2;
    color: #fff;
    cursor: default;
    background-color: #337ab7;
    border-color: #337ab7;
  }
  .gzhx-navigation{
    display: flex;
    align-items: center;
  }
  .gzhx-navigation>span{
    height: 30px;
    line-height: 30px;
    position:relative;
    margin: 0 20px;
  }
  .underline>a{
    font-weight: bold;
    color: #2D93CA;
  }

  .gzhx-navigation>span:hover:after,.underline:after {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 5px;
    content: '';
    -webkit-transform: scaleY(.5);
    transform: scaleY(.5);
    background-color: #2D93CA;
  }
  .gzhx-navigation>.btn{
    flex-grow: 0;
    flex-shrink: 0;
    flex-basis: auto;
  }
  .is-moblie{
    display: block;
  }
  .form-records-edit-group{
    display: flex;
    align-items: center;
  }
  .form-records-edit-group>label{
    width: 80px;
  }
  .form-domain-flex{
    display: flex;
    align-items: center;
    flex-wrap: wrap;
  }
  .form-domain-flex>div{
    width: 100px;
    margin: 0 0 10px 0;
  }
  @media screen and (max-width: 500px)  {
    .gzhx-navigation{
      flex-direction: column;
      align-items: flex-start;
      width: 100%;
    }
    .gzhx-navigation>span{

      margin: 5px 0;
    }
    .gzhx-navigation>.btn{
      border-radius: 0;
      width: 100%;
    }
    .domain-table-tools{
      flex-direction: column;
    }
    .domain-table-tools>a,.domain-table-tools>input{
      width: 100%;
      margin-top: 10px;
    }
    .is-moblie{
      display: none;
    }


    .form-domain-edit-group{
      flex-direction: column;
      align-items: flex-start;

    }
    .form-domain-edit-group>.btn{
      width: 100%;
      border-radius: 0;
    }
    .form-domain-edit-group>.col-sm-10{
      padding-left: 0;
      padding-right: 0;
      max-width: unset!important;
    }

    .form-domain-edit-group .form-check{
      width: 25%;
    }
    table .form-control{
      min-width: 100px;
    }
  }
</style><div class="is-moblie"></div>
<section class="admin-main">
  <div class="container-fluid">
    <div class="page-container">
      <div class="card">
        <div class="card-body">
          <!-- class="col-lg-1 col-md-12 col-sm-12" -->
          <div class="card-title row">
            <div class="pl-4 pr-4" id="PageTitle"></div>
            <div class="col-lg-8 col-md-12 col-sm-12 gzhx-navigation">
              <span  class="ml-2 underline" data-name="index"><a  class="h5" href="#_action=index">奖品领取</a></span>


            </div>
          </div>
          <div class="tab-content mt-4" id="GzhxPageContent">

          </div>
        </div>
      </div>
    </div>
  </div>
</section>
<script src="/plugins/addons/{$GzhxPluginPath}/template/js/pagination.js"></script>
<script src="/plugins/addons/{$GzhxPluginPath}/template/js/layer/layer.js"></script>
<script src="/plugins/addons/{$GzhxPluginPath}/template/js/layui/layui.js"></script>
<script src="/plugins/addons/{$GzhxPluginPath}/template/js/echarts.min.js"></script>
<script>
  window.GZHXAjaxUri="";
  let queryToJson=function (hash){
    let str=hash?(hash===true?window.location.hash:hash):window.location.search
    if( !str ) return { };
    if(str) str=str.substr(1);
    if( !str ) return { };
    let arr = str.split('&');
    let data={ };
    $.each( arr, function (k,v) {

      if(v.indexOf("=")>-1){
        let d=v.indexOf("=");
        data[ decodeURIComponent(v.substr(0,d)) ]=decodeURIComponent(v.substr(d+1));

      }

    } );
    return data;
  }
  let jsonToQuery=function (json){
    return  Object.keys(json).map(function (key) {
      return json[key]? (key + "=" + encodeURIComponent(json[key])):"";
    }).join("&");
  }
  let GzhxLoading=function (str){
    return layer.msg(str, {
      time: 0,
      icon:16
      ,shade: 0,zIndex: layer.zIndex
      ,success:function (layero) {
        layero.css({
          backgroundColor:'#000',
          color:'#fff'
        })
        layer.setTop(layero);
      }

    });
  }
  let ajax=function (option){
    let load=GzhxLoading("执行中");
    $.ajax({
              dataType: "json",
              type: option.type||"post",

              headers: {
                "X-Requested-With": "XMLHttpRequest",

              },
              url: option.url||window.GZHXAjaxUri,
              data:option.data,
              async:true,
              success: function (t) {
                layer.close(load);


                if( t.status==1 ){
                  if(option.success)  option.success(t.info);
                }else{
                  if(option.error) {
                    option.error(t.info);
                  }
                  else{
                    layer.msg(t.info);
                  }
                }
              },

              error: function (request, status, errorThrown) {
                layer.close(load);
                if(option.error) {
                  option.error("网络错误，请重试");
                }
                else{
                  layer.msg("网络错误，请重试");
                }
              }
            }
    );
  }
  /**公共操作**/
  let renewCloud=function (Info){
    ajax({
      url:'/addons?_plugin=cloud_gzhx&_controller=index&_action=index&cache=2021',
      data:{
        action:'Setting',
        api_id:Info.api_id
      },
      success:function (Setting){


        let regHtml='<h3 style="text-align: center;">'+Info.domain+'</h3><form class="form cycles-setting" id="newDomainRegistrant" style="display: flex;flex-direction: column;align-items: flex-start;">';
        regHtml +='<div class="btn-group"><a href="javascript:;" class="btn btn-dark">续费年限</a>';
        $.each(Setting.Period,function (k,v){
          regHtml +='<a href="javascript:;" class="btn btn-default" data-paySelect="'+k+'">'+v+'</a>';
        })
        regHtml +='</div>' +
                '<div class="btn-group" style="margin-top: 20px;"><a href="javascript:;" class="btn btn-dark">续费价格</a>' +
                '<a href="javascript:;" class="btn btn-default btnn-price"></a>' +
                '</div><button type="submit" class="btn btn-primary btn-lg btn-block" style="margin-top: 20px;">续费此主机</button>';
        regHtml +='<button type="button" class="btn btn-default btn-lg btn-block btnn-close" style="margin-top: 20px;">关闭续费</button></form>';
        let w=$(window).width();
        if(w>600) w=600;
        layer.open({
          type:1,
          area:w+'px',
          title:'续费'+Info.domain,
          content:'<div style="padding: 20px;">'+regHtml+'</div>',
          btn:false,
          success:function (b,a){
            let payPrice={ };
            b.find('.btnn-close').off('click').on('click',function (){
              layer.close(a);
            })

            let paySelect=function (p){
              b.find('a[data-paySelect].btn-primary').addClass('btn-default').removeClass('btn-primary');
              b.find('a[data-paySelect="'+p+'"]').addClass('btn-primary').removeClass('btn-default');
              if(!payPrice.hasOwnProperty(p)){
                ajax({
                  url:'/addons?_plugin=cloud_gzhx&_controller=index&_action=index&cache=2021',
                  data:{
                    action:'renew_price',
                    id:Info.id,
                    Period:p
                  },
                  success:function (r){
                    let t=  b.find('a[data-paySelect="'+p+'"]').html();

                    b.find('.btnn-price').html(r+'元/'+t);
                    payPrice[p]=r+'元/'+t;
                  }
                })
              }else{
                b.find('.btnn-price').html(payPrice[p]);
              }
            }



            b.find('a[data-paySelect]').off("click").on("click",function (){
              let p=$(this).attr('data-paySelect');
              paySelect(p);
            })
            b.find('a[data-paySelect]:eq(0)').trigger('click')
            b.find('#newDomainRegistrant').off("submit").on("submit",function (){
              let organization=$(this).find('select[name="organization"]').val();
              let Years=b.find('a[data-paySelect].btn-primary').attr('data-paySelect');



              ajax({
                url:'/addons?_plugin=cloud_gzhx&_controller=index&_action=index&cache=2021',
                data:{
                  action:'Renew',

                  id:Info.id,
                  years:Years,
                  manual:"续费："+b.find('a[data-paySelect].btn-primary').text()

                },
                success:function (msg){
                  layer.close(a);
                  if(msg.success){
                    layer.alert("续费成功");
                  }else{
                    window.location.hash='#_action=operate_log';
                    GzhxDomainTpl( {
                      _action:'operate_log'
                    } );
                  }

                },error:function (msg){

                  layer.alert(msg);
                }
              })
              return false;
            })
          }
        })


      }

    })
  }
  /**公共操作**/
  window.QueryList=queryToJson();
  let hashInit=function (){
    $('a[href^="#"]').off("click").on("click",function (){
      GzhxDomainTpl( queryToJson($(this).attr('href') ));
    })
  }
  let GzhxRandomCoding=function (n){
    let arr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','0'];
    let idvalue ='';
    for(var i=0;i<n;i++){
      idvalue+=arr[Math.floor(Math.random()*62)];
    }
    return idvalue;
  }
  let GzhxDomainTpl=function (query){
    query.cache="2021";
    let load=GzhxLoading("加载中");
    window.GZHXAjaxUri='/addons?'+jsonToQuery(Object.assign(window.QueryList,query));
    $.ajax({
              //  dataType: "text/html",
              type: "get",
              url:window.GZHXAjaxUri,
              async:true,
              success: function (t) {
                layer.close(load);
                $('#GzhxPageContent').html(t);
                $(window).scrollTop(0)
                hashInit();
              },
              error: function (request, status, errorThrown) {
                layer.close(load);
                layer.msg("网络错误");
                return false;
              }
            }
    );
  }
  $(function (){
    let PageQuery=queryToJson(true);
    if(PageQuery._action){
      GzhxDomainTpl(PageQuery)
    }else{
      GzhxDomainTpl({
        _action:'index'
      })
    }
  //  hashInit();
  })
</script>