function signContractConfirm() {
  bootbox.confirm({
      title : '签署已完成',
      message : '<div style="text-align:left;font-size:0.12rem">流程已进入后续环节，请知悉</div>',
      size : 'small',
      buttons : {
          cancel :  {
            className:  'delete-cancel-btn'
          },
          confirm : {
              label : '确定',
              className:'btn-white btn-info colorbtn'
          }
      },
      callback:function(result){
          if (result) {
              $(".yk_rightcontent").load('/bill/pendingList');
          };
      }
  })
}



$(function () {
  var signStatusTime = null
  // 获取签署状态
  function getSignStatus() {
      var postdata = new FormData();
      postdata.append('electronicInfoId',$('[name=electronicInfoId]').val())
      postdata.append('taskId',$('[name=taskId]').val())
      postdata.append('basicId',$('[name=bill]').val())
    //   postdata.append('signType',$('[name=signType]').val())
      $.ajax({
          url:'/bill/signType',
          type:'post',
          data:postdata,
          processData:false,
          contentType:false,
          success: function (data) {
              if(data.data) {
                  signContractConfirm()
                  $('[name=signStatus]').val('已签署')
                  $('[name=authStatus]').val('已认证')
                //   clearInterval(signStatusTime)
              }
          },
          error:function(status){
              new $.zui.Messager('获取状态时发错误:'+status, {
                  type: 'danger'
              }).show();
          }
      });
  }

//   signStatusTime = setInterval(() => {
//       getSignStatus()
//   }, 1000 * 20);
    $('.signRefresh').on('click',function () {
        getSignStatus()
    })

    //获取认证状态刷新
    // function getAuthRefresh() {
    //     $.ajax({
    //         url:'/purchContract/confirm/getAuthStatus?customerId='+$('[name=customerId]').val(),
    //         type:'get',
    //         data:{},
    //         processData:false,
    //         contentType:false,
    //         success: function (data) {
    //             if(data.data) {
    //                 signContractConfirm()
    //                 $('[name=authStatus]').val('已认证')
    //             }
    //         },
    //         error:function(status){
    //             new $.zui.Messager(tipword+'时发生错误:'+status, {
    //                 type: 'danger'
    //             }).show();
    //         }
    //     });s
    // }
    // $('.authRefresh').on('click',function () {
    //     getAuthRefresh()
	// })

  //提交
  function submitFunction(e){
      $(".newTabAddUpdateBtnBox .save,.newTabAddUpdateBtnBox .btn-cancel").addClass("loadingCircle");
      var postdata = new FormData(),tipword="提交";
      postdata.append('taskId',$('[name=taskId]').val())
      postdata.append('businessKey',$('[name=businessKey]').val())

      postdata.append('purchContractElectronicInfo.certifyStatus',$('[name=authStatusBack]').val())
      postdata.append('purchContractElectronicInfo.signStatus',$('[name=signStatusBack]').val())

      //postdata.append('purchContractElectronicInfo.certifyStatus',$('[name=electronicInfoId]').val())
      postdata.append('purchContractElectronicInfo.id',$('[name=electronicInfoId]').val())

      postdata.append('purchContractSignConfirm.conclusion','complete')

      $.ajax({
          url:'/purchContract/confirm/doSign',
          type:'post',
          data:postdata,
          processData:false,
          contentType:false,
          success:function(data){
              if( data.success ){
                  new $.zui.Messager(tipword+'成功', {
                      type: 'success'
                  }).show();

                  $(".yk_rightcontent").load('/purchContract/list');

              }else{
                  new $.zui.Messager(tipword+'失败:'+data.msg, {
                      type: 'danger'
                  }).show();
                  $(".newTabAddUpdateBtnBox .save,.newTabAddUpdateBtnBox .btn-cancel").removeClass("loadingCircle");
              }
          },
          error:function(status){
              new $.zui.Messager(tipword+'时发生错误:'+status, {
                  type: 'danger'
              }).show();
              $(".newTabAddUpdateBtnBox .save,.newTabAddUpdateBtnBox .btn-cancel").removeClass("loadingCircle");
          }
      });
      return false;
  };

  var formRules = {

  };

  var formMessages = {

  };


  //表单验证
  function addNewCustomer(e){

      $("#contractSign-form").validate({
          promptPosition : "bottomLeft",
          submitHandler : function(form) {
              if( $('.error.shows').length>0 ){
                  $('.error.shows:first').prev().focus();
                  return;
              };
              submitFunction(e);
          },
          rules:formRules,
          messages : formMessages
      });
  };

  // 提交按钮
  //$(".yk_addNewMsg .save").click(addNewCustomer);
  $(".yk_addNewMsg .save").click(function(e){
      if( !$(this).hasClass('loadingCircle') ){
          addNewCustomer(e);
      };
  });

  $('#copyAuthUrl').click(function () {
      $('[name=authUrl]').select();
      if(document.execCommand('copy')) {
          document.execCommand('copy');
          new $.zui.Messager('复制成功。', {
              type: 'success'
          }).show();
      }
  })
  $('#copyConUrl').click(function () {
      $('[name=signUrl]').select();
      if(document.execCommand('copy')) {
          document.execCommand('copy');
          new $.zui.Messager('复制成功。', {
              type: 'success'
          }).show();
      }
  })

  //退回
  $(".yk_addNewMsg .back").click(function () {
      $(".newTabAddUpdateBtnBox .save,.newTabAddUpdateBtnBox .btn-cancel").addClass("loadingCircle");
      var postdata = new FormData(),tipword="退回";
      postdata.append('taskId',$('[name=taskId]').val())
      postdata.append('businessKey',$('[name=businessKey]').val())

      postdata.append('purchContractElectronicInfo.certifyStatus',1)
      postdata.append('purchContractElectronicInfo.signStatus',1)

      postdata.append('purchContractSignConfirm.conclusion','back')

      $.ajax({
          url:'/purchContract/confirm/doSign',
          type:'post',
          data:postdata,
          processData:false,
          contentType:false,
          success:function(data){
              if( data.success ){
                  new $.zui.Messager(tipword+'成功', {
                      type: 'success'
                  }).show();

                  $(".yk_rightcontent").load('/purchContract/list');

              }else{
                  new $.zui.Messager(tipword+'失败:'+data.msg, {
                      type: 'danger'
                  }).show();
                  $(".newTabAddUpdateBtnBox .save,.newTabAddUpdateBtnBox .btn-cancel").removeClass("loadingCircle");
              }
          },
          error:function(){
              new $.zui.Messager(tipword+'时发生错误:'+status, {
                  type: 'danger'
              }).show();
              $(".newTabAddUpdateBtnBox .save,.newTabAddUpdateBtnBox .btn-cancel").removeClass("loadingCircle");
          }
      });
      return false;
  })

  // 关闭按钮
  $(".yk_addNewMsg .btn-cancel,.newBackBtn").click(function(){
      if( !$(this).hasClass('loadingCircle') ){
          $(".yk_rightcontent").load('/bill/pendingList');
      };

      return false;
  });

})
