
//驳回时审批意见必填
$('[name=approvalConclusion]').change(function(){
  if($("[name=approvalConclusion]:checked").val() == 'back'){
      $('.approvalComments').addClass('required_fileds_star')
  }else {
      $('.approvalComments').removeClass('required_fileds_star')
  }
})

$(function () {
  //提交
  function submitFunction(e){
    //驳回和否决时审批意见必填
    if($('[name=approvalConclusion]:checked').val() == 'back') {
      if($('[name=approvalComment]').val() == '') {
          $('.error').addClass('shows').show();
          return
      }else {
          $('.error').removeClass('shows').hide();        
      }
    }
    var postdata = {},tipword="提交";
    postdata = {
      'taskId': $('[name=taskId]').val(),
      'businessKey': $('[name=businessKey]').val(),
      'approvalConclusion':$('[name=approvalConclusion]:checked').val(),
      'approvalComment':$('[name=approvalComment]').val()
    }
    $.ajax({
      url:'acceptance/change/approval',
      type:'post',
      data:postdata,
      success:function(data){
        if( data.success ){
          new $.zui.Messager(tipword+'成功', {
            type: 'success'
          }).show();
          $(".yk_rightcontent").load('/acceptance/pendingList?businessBasicId='+acceptanceQuery.detailId2);
        }else{
          new $.zui.Messager(tipword+'失败:'+data.msg, {
            type: 'danger'
          }).show();
        }
      },
      error:function(){
        new $.zui.Messager(tipword+'时发生错误', {
          type: 'danger'
        }).show();
      }
    });
    return false;
  };

  var formRules = {
    approvalConclusion:{
      required:true
    }
  };

  var formMessages = {
    approvalConclusion:{
      required:'请选择审批结论'
    }
  };


  //表单验证
  function addNewCustomer(e){
    $("#acceptanceCheck-form").validate({
      promptPosition : "bottomLeft",
      submitHandler : function(form) {
        submitFunction(e);
      },
      rules:formRules,
      messages : formMessages
    });
  };

  // 提交按钮
  $(".yk_addNewMsg .save").click(function(e){
    addNewCustomer(e);
  });

  // 关闭按钮
  $(".yk_addNewMsg .btn-cancel,.newBackBtn").click(function(){
    $(".yk_rightcontent").load('/acceptance/pendingList?businessBasicId='+acceptanceQuery.detailId2);
    return false;
  });
})