function  viewBusiness(id) {
  window.open('/sign/confirmation/basicView?viewInitiation=1&historyId='+id)
  return false;
}

//下载
function dowmLoadBusiness(id) {
  $("#export").attr("href",'/sign/confirmation/downloadFileZip?id='+id);
  $("#export").get(0).click();
}

// 下载出证证明
function dowmLoadProve(id) {
    $("#export").attr("href",'/sign/confirmation/downloadReportFileZip?id='+id);
    $("#export").get(0).click();
}

//进度时间轴
function timeLime(id){
  $('.progressTimelinebox').empty();
  $.ajax({
      url:'/businessProcessingTask/doTimelineList',
      type:'get',
      data:{
          'businessKey':id,
          'businessType':'SignConfirmation'
      },
      success:function(data){
          if( data.success ){
              var text = '';
              for( var i=0;i<data.data.length;i++ ){
                  text += '<div class="progressTimeline"><div><span></span>'+data.data[i].formBusinessName+'</div>';
                  for( var j=0;j<data.data[i].logs.length;j++ ){
                      var assigneeName = data.data[i].logs[j].assigneeName ? data.data[i].logs[j].assigneeName : ''
                      text += '<p><span>'+data.data[i].logs[j].assigneeTypeName+'：'+ assigneeName +'</span>';
                      if( data.data[i].logs[j].status ){
                          text += '<span>状态：'+data.data[i].logs[j].status+'</span>';
                      };
                      if( data.data[i].logs[j].startTime ){
                          text += '<span style="width: 2.3rem">开始时间：'+data.data[i].logs[j].startTime+'</span>';
                      };
                      if( data.data[i].logs[j].endTime ){
                          text += '<span style="width: 2.3rem">完成时间：'+data.data[i].logs[j].endTime+'</span>';
                      };
                      text += '</p>'
                  };
                  j = null;
                  text += '</div>';
              };
              i = null;
              $('.progressTimelinebox').append(text);
          }else{
              new $.zui.Messager('获取时间轴信息失败:'+data.msg, {
                  type: 'danger'
              }).show();
          }
      },
      error:function(error){
          new $.zui.Messager('获取时间轴信息发生错误:'+error, {
              type: 'danger'
          }).show();
      }
  })
  $("#myModal-progressTimeline").modal('show')
};


$(function () {
  // 重新加载列表
  function reloadList(){
    $('#contractList').setGridParam({
      mtype:'GET',
      url : '/businessProcessingTask/doList?simpleClassName=SignConfirmation',
      datatype : 'json',
      postData: {
        'fastSearch':acceptancePendingQuery.searchName,
        'statusId':acceptancePendingQuery.statusId,
        taskId: messageJumpTakId
      },
      page : 1
    });
    $('#contractList').trigger('reloadGrid');
  };

  $("#searchName").val(acceptancePendingQuery.searchName);

  // 操作列
  function operateBusiness(cellValue,options,rowObject){
    var btnstr = '';
    // if( $('#timeLine').length>0 ){
      btnstr += '<p><span>时间进度轴</span><i class="operateIconfont operateIcon-shijianzhou" onclick="timeLime(' + rowObject.id + ')"></i></p>';
    //};
    //if( $('#viewContract').length>0 ){
      btnstr += '<p><span>查看</span><i class="operateIconfont operateIcon-chakan" onclick="viewBusiness('+rowObject.id+')"></i></p>';
    //};
    if( $('#signConfirmationDownloadFile').length>0 ) {
      if( rowObject.status.code == 'project_init_completed' ) {
          btnstr += '<p><span>下载</span><i class="operateIconfont operateIcon-xiazai" onclick="dowmLoadBusiness( '+rowObject.id+')"></i></p>';
      }
    }
    if( $('#signConfirmationDownloadReportFile').length>0 ) {
      if( rowObject.status.code == 'project_init_completed' ) {
          btnstr += '<p><span>下载出证文件</span><i class="operateIconfont operateIcon-xiazai" onclick="dowmLoadProve( '+rowObject.id+')"></i></p>';
      }
    }
    if( $('#dealContract').length>0 ){
      let handlerStatusName = ''
      if(rowObject.status) {
        switch (rowObject.status.code) {
          case 'acceptance_sheet_entry':
            handlerStatusName = '法务审核'
            break;
          case 'acceptance_sheet_create':
            handlerStatusName = '签署确认'
            break;
          default:
            break;
        }
      }
      btnstr += '<p><span>处理('+ handlerStatusName + ')</span><i class="operateIconfont operateIcon-chuli" onclick="dealBusiness(' + rowObject.taskId + ','+rowObject.id+')"></i></p>';
    };
    return '<div class="operateIcon noHover">'+btnstr+'</div>';
  };

  sxUtil.jqGrid('#contractList', {
    colNames: ['ID', '序号', '业务编号', '核心企业名称',  '业务名称', '签署来源', '当前阶段', '执行人', '状态', '操作'],
    colModel: [
      {name: 'id', label: 'ID', hidedlg: true, hidden: true, sortable: false, title: false},
      {name: 'orderNumber', label: '序号', sortable: false, width: 50, align: 'center', title: false},
      {name: 'businessNumber', label: '业务编号', sortable: false,align: 'center', title: false},
      {name: 'customerName', label: '核心企业名称', sortable: false,align: 'center', title: false},
      {name: 'businessName', label: '业务名称', sortable: false,align: 'center', title: false},
      {name: 'comeFrom', label: '签署来源', sortable: false, align: 'center', title: false},
      {name: 'taskName', label: '当前阶段', sortable: false, align: 'center', title: false},
      {name: 'assignee.name', label: '执行人', sortable: false, align: 'center', title: false},
      {name: 'status.name', label: '状态', sortable: false, align: 'center',  title: false},
      {
        name: 'remark',
        label: '操作',
        sortable: false,
        align: 'left',
        width: 140,
        title: false,
        formatter: operateBusiness
      }
    ],
    height: 'auto',
    mtype: 'GET',
    url: '/businessProcessingTask/doList?simpleClassName=SignConfirmation',
    pager: "#contractListPage",
    multiselect: false,
    rownumbers: false,
    postData: {
      'fastSearch':acceptancePendingQuery.searchName,
      taskId: messageJumpTakId
    },
    page: acceptancePendingQuery.listPage,
    loadError: function () {
      new $.zui.Messager('列表加载失败', {
        type: 'warning'
      }).show();
    }
  }, true);

  $(".status").each(function (i,ele) {
    $(ele).find('option[value=236]').remove();
    $(ele).find('option[value=237]').remove();
  })

  //搜索
  $("#searchBusiness").click(function () {
    acceptancePendingQuery.searchName = acceptanceQuery.detailId + $("#searchName").val();
    acceptancePendingQuery.statusId = acceptanceQuery.detailId + $(".status").val();
    acceptancePendingQuery.listPage = 1;
    reloadList();
  })

  //切换表格
  $(".projectListTab li").click(function () {
    if ($(this).text() == '待我处理') {
      $(".yk_rightcontent").load('/sign/confirmation/pendingList?businessBasicId='+acceptanceQuery.detailId2);
    } else if ($(this).text() == '我已处理') {
      $(".yk_rightcontent").load('/sign/confirmation/findMyCompletedList?businessBasicId='+acceptanceQuery.detailId2);
    }else if ($(this).text() == '全部') {
      $(".yk_rightcontent").load('/sign/confirmation/allList?businessBasicId='+acceptanceQuery.detailId2);
    }
  });
})
