
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <meta name="format-detection"content="telephone=no">
    <title>记录列表</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/popoPicker.css"/>
    <link rel="stylesheet" href="../../css/style.css">
    <style media="screen">
      body,html{
        margin: 0;
        background: #fff;
        overflow-x: hidden;
      }
      .hide{
        display: none;
      }
      /*name*/
      .date-lists{
          width: 100%;
          overflow-x: scroll;
          white-space: nowrap;
          box-sizing: border-box;
      }
      .date-lists::-webkit-scrollbar{
        display: none;
      }
      .date-wrap{
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        box-sizing: border-box;
        z-index: 9999;
        background: #fff;
      }
      .date-lists li{
          margin-right: 20px;
          padding: 14px 10px;
          font-size: 16px;
          color: #333;
          position: relative;
      }
      .date-lists .active{
          color: #009FE8;
      }
      .date-lists .active:after{
          content: "";
          position: absolute;
          bottom: 0;
          left: 0;
          width: 100%;
          height: 2px;
          background: #009FE8;
      }
       /*记录列表*/
      .recode-wraps{
        width: 95%;
        border: 1px dashed #ECF0F1;
        margin: auto;
        margin-top: 10px;
        border-radius: 5px;
        padding-bottom: 5px;
      }
      .time{
          background: #31A5FF;
          padding: 5px 10px;
          font-size: 14px;
          display: inline-block;
          color: #fff;
          border-radius: 10px;
          position: relative;
          margin-bottom: 5px;
      }
      .recodeTitle{
        display: block;
        margin-top: 3px;
      }
      .name{
          color: #000;
          font-size: 14px;
          /*font-weight: bold;*/
          line-height: 1.6;
      }
      .main{
          padding-left: 50px;
          position: relative;
          padding-bottom: 10px;
      }
      .main:after{
          content: '';
          position: absolute;
          top: 0;
          left: 30px;
          width:2px;
          background: #31A5FF;
          height: 100%;
      }
      .main:before{
          content: '';
          position: absolute;
          top: 5px;
          left:23px;
          width:15px;
          background: #31A5FF;
          height: 15px;
          border-radius: 50%;
      }
      /*三角形*/
      .Triangle{
          position: absolute;
          top: 5px;
          left: -14px;
          width: 0;
          height: 0;
          border-width: 8px;
          border-style: solid;
          border-color: transparent #31A5FF transparent transparent;
          transform: rotate(360deg);
      }
      .recode-img{
          display: inline-block;
          width: 38px;
          height: 46px;
          background: url("../../icon/recode.png")  center no-repeat;
          background-size: contain;
          position: relative;
          left: 12px;
          top: 9px;
      }
      .state{
        padding-left: 50px;
        position: relative;
      }
      .stop{
        position: absolute;
        top: 6px;
        left: 23px;
        width: 15px;
        height: 15px;
        background: url("../../icon/stop.png")  center no-repeat;
        background-size: contain;
        z-index: 800;
      }
      .state:after{
          content: '';
          position: absolute;
          top: -2px;
          left: 30px;
          width:2px;
          background: #31A5FF;
          height: 10px;
        }
        .recode-more{
          padding: 20px;
          text-align: center;
        }
        #recode_item{
          padding-top: 50px;
        }
        /*tool*/
        .tool_itme{
            padding: 10px;
        }
        .tool_time{
          display: flex;
          justify-content: space-between;
        }
        .tool_time input{
            border: 1px solid #ccc;
            padding: 8px 10px;
            border-radius: 3px;
            width: 46%;
            box-sizing: border-box;
           -webkit-appearance: none;
           text-align: center;
        }
        .tool_seacrh_export{
            padding: 10px 0;
        }
        .tool_seacrh_export button{
            padding: 10px 0;
            color: #fff;
            background: #009FE8;
            width: 100px;
            border-radius: 4px;
            text-align: center;
            cursor: pointer;
        }
        .tool_seacrh_export button{
            margin-right: 20px;
        }
    </style>
</head>
<body>
  <div class="date-wrap" id="date_wrap">

  </div>
  <div class="api_layout" id="recode_item">
      <div class="tool_itme">
          <div class="tool_time ">
              <input type="text" class="start_time" readonly placeholder="开始时间">
              <input type="text" class="end_time" readonly placeholder="结束时间">
          </div>
          <div class="tool_seacrh_export">
            <button type="button" onclick="searchRecode()">查询</button>
            <button type="button" onclick="exportRecode()">导出</button>
          </div>
      </div>
      <div id="recode_content">

      </div>
  </div>
  <div class="noText hide">
    <img src="../../image/noText.png" alt="">
  </div>
  <a href="javascript:;" class="upload_file"></a>
</body>
</html>

<script type="text/template" id="recodeTemplate">
  {{~it:value}}
       <div class="recode-wraps">
           <span class="recode-img"></span>
           <div class="recode-list">
              {{ for (var t=0;t<value.length;t++) { }}
                 <div class="main" onclick="openRecordDe('{{=value[t].recordParentId}}')">
                     <p class="time">
                         {{=value[t].createDate}}
                         <span class="Triangle"></span>
                         <span class="recodeTitle">{{=value[t].templateName}}</span>
                     </p>
                     <p class="name">{{=value[t].createName}}</p>
                     <div class="name">
                       {{?value[t].recordStatusInstanceList != null}}
                         {{ for(var i= 0;i<value[t].recordStatusInstanceList.length;i++){ }}
                           <div class="state-items">
                             <p class="state-title" style="width:auto;display:{{=value[t].statusName == ""?'none':'inline-block'}}">{{=value[t].recordStatusInstanceList[i].statusName}}：</p>
                               {{ for(var j= 0;j<value[t].recordStatusInstanceList[i].recordStatusInstanceItemList.length;j++){ }}
                                 {{?value[t].recordStatusInstanceList[i].recordStatusInstanceItemList.length == 1}}
                                   <span>{{=value[t].recordStatusInstanceList[i].recordStatusInstanceItemList[j].statusContent}}</span>
                                 {{??}}
                                   <span>{{=value[t].recordStatusInstanceList[i].recordStatusInstanceItemList[j].statusContent}},</span>
                                 {{?}}
                               {{ } }}
                            </div>
                          {{ } }}
                        {{??}}
                          <div class="state-items">
                            <p class="state-title" style="width:auto;display:{{=value[t].statusName == ""?'none':'inline-block'}}">{{=value[t].statusName}}:</p>
                            <span>{{=value[t].statusContent}}</span>
                           </div>
                        {{?}}
                     </div>
                 </div>
                 {{?t == value.length-1}}
                 {{?value[value.length-1].continueStatus == false}}
                     <div class="state">
                         <p class="time">
                             结束：{{=value[t].createDate}}
                             <span class="Triangle" style="top:6px;"></span>
                         </p>
                         <i class="stop"></i>
                     </div>
                   {{??}}
                     <div class="state wait">
                         <p class="time" style="background:#F7A329">
                             等待处理......
                             <span class="Triangle" style="top:6px;border-color: transparent #F7A329 transparent transparent;"></span>
                         </p>
                         <i class="stop" style="background: url('../../icon/Continue.png')  center no-repeat;background-size: contain;"></i>
                     </div>
                   {{?}}
                 {{?}}
             {{ } }}
           </div>
       </div>
  {{~}}
</script>
<script type="text/template" id="TemplateName">
  <ul class="date-lists flex-start">
    {{~it:value:index}}
        {{?index == 0}}
          <li class="active" onclick="randomSwitchBtn(this,'{{=value.parentId}}','{{=value.templateId}}')">{{=value.templateName}}</li>
        {{??}}
          <li onclick="randomSwitchBtn(this,'{{=value.parentId}}','{{=value.templateId}}')">{{=value.templateName}}</li>
        {{?}}
    {{~}}
  </ul>
</script>

<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/doT.min.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script src="../../script/popoPicker.js"></script>
<script src="../../script/config.js" charset="utf-8"></script>
<script type="text/javascript">
    var pageId = "",departmentID="",name="",uuid="",isLoadding = false;
    var skip = 1,parentId = "",templateId="";
    var startTime = '',endTime = '',scrolltobottomFlat = true;
    apiready = function () {
      pageId = api.pageParam.id
      departmentID= api.pageParam.departmentID
      name= api.pageParam.name
      uuid= api.pageParam.uuid
      TemplateName(api.pageParam.id)
      // 上拉加载
      api.addEventListener({
        name : 'scrolltobottom',
        extra : {
          threshold : 0 //设置距离底部多少距离时触发，默认值为0，数字类型
        }
      }, function(ret, err) {
        if (!isLoadding && scrolltobottomFlat) {
          isLoadding = true;
          recodeList(parentId)
        }
      });
    }
    // TemplateName Nav
    var num=0;
    function TemplateName(pageID) {
      $http.fnReuestDataNologing(UrlRouter.selectRecordByGetPageId+pageID,'','get','',function (ret, err) {
          if (ret.code == '200' && ret.data != "") {
              $apis.html(date_wrap,'#TemplateName',ret.data);
              parentId = ret.data[0].parentId;
              templateId = ret.data[0].templateId
              recodeList(ret.data[0].parentId,false)
          }
      })
    }
    function recodeList(ParentId) {
      api.showProgress({
          title: '努力加载中...',
          text: '先喝杯茶...',
          modal: true
      });
      var parm= {
        pageId:pageId,
        pageRecordParentId: ParentId,
        startTime: startTime,
        endTime: endTime,
        pageNumber:skip,
        pageSize: 10
      }
      $http.fnReuestDataNologing(UrlRouter.getPageRecordInstanceList,'','get',parm,function (ret, err) {
          isLoadding = false;
          api.hideProgress();
          if (ret.data.length == 0 && skip == 1) {
              $api.removeCls($api.dom('.noText'), 'hide');
              $apis.html(recode_content,'#recodeTemplate','');
              isLoadding = true;
              return false;
          }else {
              $api.addCls($api.dom('.noText'), 'hide');
          }
          if (ret) {
            if (ret.data.length > 0) {
              skip += 1;
              $apis.append(recode_content,'#recodeTemplate',ret.data);
              // $api.addCls($api.dom('.noText'), 'hide');
              // $api.removeCls($api.dom('.noText'), 'hide');
            } else {
               isLoadding =true;
                api.toast({
                    msg: '没有更多数据',
                    duration: 2000,
                    location: 'bottom'
                });
            }
          }else {
            api.toast({
                msg: '加载超时，请检查网络',
                duration: 2000,
                location: 'bottom'
            });
          }
      })
    }
    // 模版名称
    function randomSwitchBtn( tag ,ParentId,temId) {
        if( tag == $api.dom('.date-lists li.active') )return;
        var eFootLis = $api.domAll('.date-lists li');
        skip = 1;
        index = 0;
        $apis.html(recode_content,'#recodeTemplate','');
        for (var i = 0,len = eFootLis.length; i < len; i++) {
            if( tag == eFootLis[i] ){
                index = i;
            }else{
                $api.removeCls(eFootLis[i], 'active');
            }
        }
        $api.addCls( eFootLis[index], 'active');
        templateId = temId
        startTime = ''
        endTime = ''
        $('.start_time').val('')
        $('.end_time').val('')
        parentId = ParentId
        recodeList(ParentId)
    }
    // 记录详情
    function openRecordDe(id) {
      $event.openTabLayout('recodeDetails','recodeDetails','记录详情',{recordParentId:id});
    }
    new popoDateT('.start_time',{
        container:'.tool_time',
        background:'light',
        save:function (data) {
            startTime = data
        }
    });
    new popoDateT('.end_time',{
        container:'.tool_time',
        background:'light',
        save:function (data) {
            endTime = data
        }
    });
    // 查询
    function searchRecode() {
      scrolltobottomFlat = false
      var parm= {
        pageId:pageId,
        pageRecordParentId: parentId,
        startTime: startTime,
        endTime: endTime,
        pageNumber:0,
        pageSize: 0
      }
      $http.requestShowProgress(UrlRouter.getPageRecordInstanceList,'get',parm)
      .then(ret=>{
        if (ret.data.length > 0) {
          $api.addCls($api.dom('.noText'), 'hide');
          $apis.html(recode_content,'#recodeTemplate',ret.data);
        } else {
            api.toast({
                msg: '没有更多数据',
                duration: 2000,
                location: 'bottom'
            });
            $apis.html(recode_content,'#recodeTemplate',"");
            $api.removeCls($api.dom('.noText'), 'hide');
        }
      }).catch(err=>{
        api.toast({
            msg: '加载超时，请检查网络',
            duration: 2000,
            location: 'bottom'
        });
      })
    }
    // 导出
    function exportRecode(that) {
      if (startTime == "" && startTime =="") {
        api.toast({
            msg: '请选择时间',
            duration: 2000,
            location: 'top'
        });
        return false
      }
      var uploadFileElm=$('.upload_file')
      var url = UrlRouter.getRecordInstanceDetailListMobileExcel+"?startTime="+ startTime +"&endTime="+ endTime
      +"&templateId="+templateId
      $http.requestShowProgress(url,'get','')
      .then(ret=>{
        if (ret.code === '200') {
          var fileUrl= ret.data
          api.confirm({
              title: '提示',
              msg: '是否导出记录',
              buttons: ['确定', '取消']
          }, function(ret, err) {
              var index = ret.buttonIndex;
              if (index === 1) {
                uploadFileElm.attr('href',fileUrl)
                uploadFileElm.attr('download',fileUrl)
                uploadFileElm.click()
              }
          });
        }
      }).catch(err=>{
        api.toast({
            msg: '下载失败',
            duration: 2000,
            location: 'top'
        });
      })
    }
</script>
