// setInterval(function () {
//   let taskId = $('[name=taskId]').val()
//   let businessKey = $('[name=businessKey]').val()
//   $(".yk_rightcontent").load("/businessProcessingTask/dispatchMyTask?taskId="+taskId + '&businessKey='+ businessKey)
// },20000)

$('.signList').on('click', '.copyAuthUrl', function () {
	$(this).parent().find('.copyUrl').select()
	if(document.execCommand('copy')) {
		document.execCommand('copy');
		new $.zui.Messager('复制成功', {
				type: 'success'
		}).show();
	}
})

//认证状态刷新
$('.signList').on('click', '.authRefresh', function () {
  let taskId = $('[name=taskId]').val()
  let businessKey = $('[name=businessKey]').val()
  $(".yk_rightcontent").load("/businessProcessingTask/dispatchMyTask?taskId="+taskId + '&businessKey='+ businessKey)
  let that = $(this)
  $.ajax({
      url:"/purchContract/confirm/getAuthStatus?customerId="+$(this).attr('fddCustomerId'),
      type:'get',
      processData:false,
      contentType:false,
      success: function (data) {
        if(data.success) {
          if(data.data.authStatus){
            that.parent().find('.certificationStatus').val('已认证')
          }else{
            that.parent().find('.certificationStatus').val('未认证')
          }
        }
      },
      error:function(status){
        new $.zui.Messager('刷新时发生错误:'+status, {
            type: 'danger'
        }).show();
      }
  });
})

//签署状态刷新
$('.signList').on('click','.signRefresh',function () {
  let that = $(this)
  $.ajax({
      url:"/sign/confirmation/signType?contractId="+$(this).attr('contractId')+'&customerId='+$(this).attr('fddCustomerId')+'&transactionId='+$(this).attr('transactionId'),
      type:'get',
      processData:false,
      contentType:false,
      success: function (data) {
        if(data.success) {
          if(data.data){
            that.parent().find('.signStatus').val('已签署')
          }else{
            that.parent().find('.signStatus').val('未签署')
          }
        }
      },
      error:function(status){
        new $.zui.Messager('刷新时发生错误:'+status, {
            type: 'danger'
        }).show();
      }
  });
})

//签署结论默认完成
if($('[name=conclusion]:checked').val() == undefined){
  $('[name=conclusion]').get(0).checked = true
}

//保存
function submitFunction(){
  //签署校验
  for(let i = 0; i<$('.signStatus').length; i++) {
    if($("[name=conclusion]:checked").val() == 1) {
      if($('.signStatus').eq(i).val() == '未签署' || $('.certificationStatus').val() == '未认证'){
        new $.zui.Messager('请进行签署确认操作', {
          type: 'danger'
        }).show();
        return false
      }
    }
  }
  var postdata = new FormData();
  postdata.append('signConclusion',$("[name=conclusion]:checked").val());
  postdata.append('remark',$("[name=remark]").val());
  postdata.append('id',$("[name=id]").val());
  postdata.append('taskId',$("[name=taskId]").val());
  $.ajax({
      url:'/sign/confirmation/confirm',
      type:'post',
      data:postdata,
      processData:false,
      contentType:false,
      success:function(data){
          if( data.success ){
              new $.zui.Messager( '签署确认成功', {
                  type: 'success'
              }).show();
              $.get('/sign/confirmation/pendingList',function(data){
                  $(".yk_rightcontent").empty().append(data);
              });
          }else{
              new $.zui.Messager('签署确认失败:'+data.msg, {
                  type: 'danger'
              }).show();
          }
      },
      error:function(status){
          new $.zui.Messager('签署确认时发生错误:'+status, {
              type: 'danger'
          }).show();
      }
  });
  return false;
};

//提交按钮
$(".yk_addNewMsg .save").click(function () {
  submitFunction()
  return false
});

//关闭按钮
$(".yk_addNewMsg .btn-cancel, .newBackBtn").click(function(){
  $.get('/sign/confirmation/pendingList',function(data){
      $(".yk_rightcontent").empty().append(data);
  });
  return false;
});