<!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" href="../../css/select.css">
    <style media="screen">
        body,html{
            margin: 0;
            background: #fff;
        }
        *{
          box-sizing: border-box;
        }
        .recode-warp{
          margin-top: 10px;
        }
        .col>label{
          color: #333;
          font-size: 16px;
          padding: 15px 0 ;
          position: relative;
          padding-left: 15px;
          width: 100%;
        }
        .col>label:before{
          content: '';
          position: absolute;
          top: 13px;
          left: 0;
          width: 3px;
          height: 26px;
          background: #009fe8;
        }
        .col>label:after{
          content: '';
          position: absolute;
          bottom: 0;
          left: 0;
          width: 100%;
          height: 1px;
          background: #ECF0F1;
        }
        .recode-warp{
            padding: 5px 10px;
        }
        .input-recode{
            position: relative;
        }
        .title{
            font-size: 16px;
            color: #333;
            font-weight: normal;
            margin-bottom: 10px;
        }
        .title span{
            color: red;
        }
        .input-recode .input{
            margin: 0;
            height: 45px;
            border: 1px solid #e1e5e9;
            background: #ffffff;
            font-size: 14px;
            width: 100%;
            -webkit-border-radius: 3px;
            border-radius: 3px;
            padding-left: 15px;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            color: #333;
        }
        .modula:not(:first-child){
            margin-top: 18px;
        }

        .ico{
            display: block;
            position: absolute;
            top: 16px;
            right: 8px;
            width: 18px;
            height: 13px;
            background: url(../../icon/ico.png) no-repeat;
            background-size: cover;
        }
        /*录音*/
        .input-recode audio{
          width: 100%;
        }
        .upload-btn{
            width: 100px;
            height: 33px;
            background: url(../../icon/mp3.jpg);
            background-size: cover;
            display: block;
            cursor: pointer;
        }
        .del-btn{
            display: none;
            width: 60px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            color: #fff;
            background: #07c160;
            border-radius: 3px;
            font-size: 14px;
            margin-bottom: 10px;
        }
        /*文件*/
        .file-items{
            border: 1px dashed #D9D9D9;
            padding: 10px 10px 0 10px;
            display: flex;
            justify-content: flex-start;
            flex-wrap: wrap;
            box-sizing: border-box;
        }
        .file-width{
            width: 33.3333333%;
            box-sizing: border-box;
            font-size: 14px;
            color: #333;
            margin-bottom: 10px;
        }
        .file-item{
            text-align: center;
        }
        .file-item img{
            width: 35px;
            height: 35px;
            margin-bottom: 5px;
        }
        .file-item p{
            padding: 0 5px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            height: auto;
        }
        .upload img{
            width: 80px;
            height: 80px;
            margin-left: 15px;
        }
        /*图片*/
        .img-item{
            text-align: center;
        }
        .img-item img{
            width: 80px;
            height: 80px;
            border-radius: 3px;
            object-fit: cover;
        }
        .img-items .upload{
            text-align: center;
        }
        .img-items .upload img{
            width: 80px;
            height: 80px;
            margin: 0;
        }
        /*视频*/
        .upload-btn1{
            width: 100px;
            height: 33px;
            background: url(../../icon/vedio.png);
            background-size: cover;
            display: block;
            cursor: pointer;
        }
        .submit-btn{
          width: 100%;
          font-size: 18px;
          background: #009fe8;
          height: 55px;
          line-height: 55px;
          letter-spacing: 5px;
          color: #fff;
          border-radius: 3px;
          margin-top: 20px;
          margin-bottom: 20px;
        }
        /*检查项*/
        .radio-wrap{
            font-size: 14px;
            display: flex;
            justify-content: flex-start;
            flex-wrap: wrap;
            padding-top: 10px;
        }
        .radio-wrap label{
          margin-right: 10px;
          padding: 5px 0;
        }
        .radio-wrap label input{
          margin-right: 10px;
        }
        /*position*/
        .flex-start{
            display: flex;
            justify-content: space-between;
            white-space: nowrap;
            align-items: center;
        }
        .flex-space{
            display: flex;
            justify-content: space-between;
            white-space: nowrap;
            align-items: center;
        }
        .ico-map{
            width: 25px;
            height: 25px;
            background: url("../../icon/position.png") no-repeat;
            background-position: center;
            background-size: cover;
        }
        .position{
            padding: 5px 0;
            padding-left: 15px;
            padding-right: 10px;
            border-radius: 50px;
            background: #F0F0F0;
            font-size: 14px;
            margin-top:10px;
        }
        .map1{
            color: #009FE8;
            margin-bottom: 5px;
        }
        .again{
            color: #6C6F74;
        }
        .map-name {
          width: 78%;
        }
        .names{
          width: 85%;
          white-space: normal;
        }
        #position_warp{
          padding: 0 10px;
        }
        .textarea{
          height: 45px;
          line-height: 1.5;
        }
        .classSign img{
          width: 100%;
          height: auto;
        }
    </style>
</head>
<body>
  <div id="position_warp"></div>
  <div class="recode-warp" id="recode_warp"></div>
</body>
</html>
<script type="text/template" id="recodeTemplate">
    <!-- 是否开启定位 -->
    {{?it.position == true}}
      {{=getLonLat(false)}}
    {{?}}
    <!-- 状态-->
    {{?it.recordStatusList != "" && it.recordStatusList != null}}
      {{ for(var i= 0;i<it.recordStatusList.length;i++) { }}
        <div class="modula state">
            <label class="title isOptionals" isOptional="true">
                <span>*</span>
                {{=it.recordStatusList[i].statusContent}}：
            </label>
            <div class="text-input input-recode">
                <input type="text" placeholder="请选择{{=it.recordStatusList[i].statusContent}}" statusId="{{=it.recordStatusList[i].statusId}}" class="isOptional input moreStatusA" id="moreStatus{{=it.recordStatusList[i].id}}" readonly>
                <i class="ico"></i>
            </div>
        </div>
        {{?it.recordStatusList[i].choseType === 'checkbox'}}
          {{=statusCheckbox('moreStatus'+it.recordStatusList[i].id,it.recordStatusList[i].statusItemList,it.recordStatusList[i].statusContent)}}
        {{??}}
          {{=statusRadio('moreStatus'+it.recordStatusList[i].id,it.recordStatusList[i].statusItemList,it.recordStatusList[i].statusContent)}}
        {{?}}
      {{ } }}
    {{??it.statusName !=""}}
      <div class="modula state">
          <label class="title isOptionals" isOptional="true">
              <span>*</span>
              {{=it.statusName}}：
          </label>
          <div class="text-input input-recode">
              <input type="text" placeholder="请输入{{=it.statusName}}" class="isOptional input statusContent">
          </div>
      </div>
    {{?}}
    <!-- 记录项 -->
    {{ for(var key in it.inputList) { }}
      <div class="col">
        <label style="display:{{=key==""?'none':'block'}}">{{=key}}</label>
        <div class="content" style="padding-top:15px;">
          {{ for(var i=0;i<it.inputList[key].length;i++) { }}
              {{?it.inputList[key][i].inputType === 'text'}}
                <div class="modula text">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <textarea oninput="Oninput(this)" placeholder="请输入{{=it.inputList[key][i].inputName}}" style="padding: 10px 15px" recordTrem-id="{{=it.inputList[key][i].id}}" class="isOptional input recordTrems textarea"></textarea>
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'name_auto'}}
                <div class="modula text">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                      <input type="text" readonly value="{{=userNames}}" class="isOptional input recordTrems" recordTrem-id="{{=it.inputList[key][i].id}}">
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'handrSign_auto'}}
                <div class="modula text">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode classSign" recordTrem-id="{{=it.inputList[key][i].id}}">
                      {{? sign == ''}}
                        <p>暂无手写签名，请去个人中心设置！</p>
                      {{??}}
                        <img src="{{=sign}}" alt="">
                      {{?}}
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'date_auto'}}
                <div class="modula text">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="text" readonly value="{{=getYearMonthDate()}}" class="isOptional input recordTrems" recordTrem-id="{{=it.inputList[key][i].id}}">
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'dateTime_auto'}}
                <div class="modula text">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="text" readonly value="{{=getYearMonthDateTime()}}" class="isOptional input recordTrems" recordTrem-id="{{=it.inputList[key][i].id}}">
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'text_phone'}}
                <div class="modula text">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="tel" placeholder="请填写手机号" value="{{=JSON.parse($api.getStorage('data')).data.user.mobile == null?'':JSON.parse($api.getStorage('data')).data.user.mobile}}" class="isOptional input recordTrems" recordTrem-id="{{=it.inputList[key][i].id}}">
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'text_id'}}
                <div class="modula text">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="text" placeholder="请填写身份证号"  value="{{=JSON.parse($api.getStorage('data')).data.user.identity_card == null?'':JSON.parse($api.getStorage('data')).data.user.identity_card }}" class="isOptional input recordTrems" recordTrem-id="{{=it.inputList[key][i].id}}">
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'company_auto'}}
                <div class="modula text">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="text" readonly value="{{=JSON.parse($api.getStorage('data')).data.user.section}}" class="isOptional input recordTrems" recordTrem-id="{{=it.inputList[key][i].id}}">
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'dateTime'}}
                <div class="modula date-time">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="datetime-local" data-datetime="true" class="isOptional input recordTrems" recordTrem-id="{{=it.inputList[key][i].id}}">
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'date'}}
                <div class="modula date">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="date" class="isOptional input recordTrems" recordTrem-id="{{=it.inputList[key][i].id}}">
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'file'}}
                <div class="modula file-warp">
                    <label class="title" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode file-items fileList_warp" recordTrem-id="{{=it.inputList[key][i].id}}">
                       <div class="upload file-width" onclick="browseFile(this,'file')">
                           <img src="../../image/upload.png" alt="">
                       </div>
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'mp3'}}
                <div class="modula audio-warp">
                    <h4 class="title" isOptional="{{=it.inputList[key][i].isOptional}}">
                      <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                      {{=it.inputList[key][i].inputName}}：
                    </h4>
                    <div class="text-input input-recode mp3_wrap" recordTrem-id="{{=it.inputList[key][i].id}}">
                        <div class="upload-audio">
                          <span class="upload-btn" onclick="browseFile(this,'mp3')"></span>
                          <button type="button" class="del-btn hide" onclick="delAudio(this)">删除</button>
                        </div>
                        <div class="audio-content">

                        </div>
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'number'}}
                <div class="modula number">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                      <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                      {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="number" placeholder="请输入{{=it.inputList[key][i].inputName}}" recordTrem-id="{{=it.inputList[key][i].id}}" class="isOptional input recordTrems">
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'photo'}}
                <div class="modula img-warp">
                    <label class="title" isOptional="{{=it.inputList[key][i].isOptional}}">
                        <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                        {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode file-items img-items photoFile" isOptional="{{=it.inputList[key][i].isOptional}}" recordTrem-id="{{=it.inputList[key][i].id}}">
                        <div class="upload file-width" onclick="uploadImg('{{=it.inputList[key][i].businessType}}',this)">
                            <img src="../../image/upload.png" alt="">
                        </div>
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'radio'}}
                <div class="modula radio">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                      <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                      {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="text" placeholder="请选择" class="isOptional input changeInput" recordTrem-id="{{=it.inputList[key][i].id}}" id="radio{{=i}}" readonly>
                        <i class="ico"></i>
                    </div>
                </div>
                {{=radioRecord('radio'+i,it.inputList[key][i].inputItemList)}}
              {{??it.inputList[key][i].inputType === 'video'}}
                <div class="modula vedio-warp">
                    <h4 class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                      <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                      {{=it.inputList[key][i].inputName}}：
                    </h4>
                    <div class="text-input input-recode mp4_wrap" recordTrem-id="{{=it.inputList[key][i].id}}">
                        <div class="upload-audio">
                            <span class="upload-btn1" onclick="browseFile(this,'mp4')"></span>
                            <button type="button" class="del-btn hide" onclick="delVedio(this)">删除</button>
                        </div>
                        <div class="audio-content">

                        </div>
                    </div>
                </div>
              {{??it.inputList[key][i].inputType === 'checkbox'}}
                <div class="modula checkbox">
                    <label class="title isOptionals" isOptional="{{=it.inputList[key][i].isOptional}}">
                      <span style="display:{{=it.inputList[key][i].isOptional== true?'inline-block':'none'}}">*</span>
                      {{=it.inputList[key][i].inputName}}：
                    </label>
                    <div class="text-input input-recode">
                        <input type="text" placeholder="请选择" class="isOptional input changeInput" recordTrem-id="{{=it.inputList[key][i].id}}"  id="checkbox{{=i}}" readonly>
                        <i class="ico"></i>
                    </div>
                </div>
                {{=checkboxRecord('checkbox'+i,it.inputList[key][i].inputItemList)}}
              {{?}}
          {{ } }}
        </div>
      </div>
    {{ } }}
    <!-- 检查项 -->
    {{?it.checkItemList != ""}}
      {{ for(var i= 0;i<it.checkItemList.length;i++) { }}
        <div class="modula checkbox-term">
          <label class="title" style="margin-bottom: 0">
              {{=it.checkItemList[i].group.groupName}}：
          </label>
          <div class="radio-wrap">
            {{?it.checkItemList[i].group.checkType == 'radio'}}
              {{ for(var t=0;t<it.checkItemList[i].checkItemList.length;t++) { }}
                <label>
                  <input class="aui-radio checked" type="radio" value="{{=it.checkItemList[i].checkItemList[t].id}}" name="{{=it.checkItemList[i].group.groupName}}">
                  {{=it.checkItemList[i].checkItemList[t].itemValue}}
                </label>
              {{ } }}
            {{??}}
              {{ for(var t=0;t<it.checkItemList[i].checkItemList.length;t++) { }}
                <label>
                  <input class="aui-checkbox checked" type="checkbox" value="{{=it.checkItemList[i].checkItemList[t].id}}" name="{{=it.checkItemList[i].group.groupName}}">
                  {{=it.checkItemList[i].checkItemList[t].itemValue}}
                </label>
              {{ } }}
            {{?}}
          </div>
        </div>
      {{ } }}
    {{?}}
    <button type="button" name="button" class="submit-btn" onclick="submitRecode()">提交记录</button>
</script>
<script type="text/template" id="mapTemplate">
  <div class="position flex-space">
      <div class="map-name flex-start">
        <i class="ico-map"></i>
        <div class="names">
          <p class="map1">{{=it.address}}</p>
        </div>
      </div>
      <p class="again" onclick="getLonLat(true)">重新定位</p>
  </div>
</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 type="text/javascript" src="../../script/select.js"></script>
<script src="../../script/config.js" charset="utf-8"></script>
<script type="text/javascript">
    var imgarr = [], UIAlbumBrowser= "",sign ='';
    var pageId="", pageRecordParentId= "", recordParentId= "",
    templateId="", templateName="",departmentId="",userId= "",userName= "";
    var i = 0;
    apiready = function () {
      var info = $api.getStorage('data');
      userNames = name = JSON.parse(info).data.user.name;
      sign = JSON.parse(info).data.user.sign
      UIAlbumBrowser = api.require('UIAlbumBrowser');
      pageId = api.pageParam.pageId
      departmentId = api.pageParam.organizationIds
      userId= api.pageParam.createBy
      userName= api.pageParam.createName
      recordParentId= api.pageParam.recordTrueID
      recodeContent(api.pageParam.pageId, api.pageParam.pageRecordId)
    }
    // 记录模版内容
    function recodeContent(id,recodeId) {
      var param={
        pageId:id,
        pageRecordId:recodeId,
        recordParentId:recordParentId,
      }
      $http.requestShowProgress(UrlRouter.getInspection,'get',param)
      .then(ret=>{
        if (ret.code === '200') {
          pageRecordParentId = ret.data.parentId;
          templateId = ret.data.recordTemplate.id
          templateName = ret.data.recordTemplate.templateName
          $apis.html(recode_warp, '#recodeTemplate',ret.data.recordTemplate);
        }
      }).catch(err=>{})
    }
    // 录音
    // 删除录音
    function delAudio(that) {
        $(that).hide();
        $(that).parent().find('.upload-btn').show();
        $(that).parent().parent().find('audio').remove();
    }
    // 视频
    // 删除视频
    function delVedio(that) {
        $(that).hide();
        $(that).parent().find('.upload-btn1').show();
        $(that).parent().parent().find('video').remove();
    }
    // 状态
    function checkbox(el,list,titles) {
        var itmes = {title:'',value:''},itmesArray = [];
        for (var j= 0;j<list.length;j++) {
            itmes = {};
            itmes.title = list[j].statusContent;
            itmes.value = list[j].id;
            itmesArray.push(itmes)
        }

        setTimeout(function () {
          $('#'+el).select({
              title: titles,
              multi: true,
              items: itmesArray
          });
        },1000)
        return ''
    }
    // 记录项多选-单选
    function checkboxRecord(el,list) {
        var itmes = {title:'',value:''},itmesArray = [],idArray=[],titleArray=[];
        for (var j= 0;j<list.length;j++) {
            itmes = {};
            if (list[j].isDefault === true) {
              titleArray.push(list[j].itemValue)
              idArray.push(list[j].id)
            }
            itmes.title = list[j].itemValue;
            itmes.value = list[j].id;
            itmesArray.push(itmes)
        }
        setTimeout(function () {
          $("#"+el).select({
              multi: true,
              items: itmesArray
          });
          $("#"+el).attr("data-values",idArray.join(','))
          $("#"+el).attr("value",titleArray.join(','))
        },1000)
        return ''
    }
    function radioRecord(el,list) {
        var itmes = {title:'',value:''},itmesArray = [],idArray=[],titleArray=[];
        for (var j= 0;j<list.length;j++) {
            itmes = {};
            if (list[j].isDefault === true) {
              titleArray.push(list[j].itemValue)
              idArray.push(list[j].id)
            }
            itmes.title = list[j].itemValue;
            itmes.value = list[j].id;
            itmesArray.push(itmes)
        }
         setTimeout(function () {
           $("#"+el).select({
               multi: false,
               items: itmesArray
           });
           $("#"+el).attr("data-values",idArray.join(','))
           $("#"+el).attr("value",titleArray.join(','))
         },1000)
        return ''
    }

    //状态
    // 多选
    function statusCheckbox(el,list,titles) {
      var itmes = {title:'',value:''},itmesArray = [];
      for (var j= 0;j<list.length;j++) {
          itmes = {};
          itmes.title = list[j].statusContent;
          itmes.value = list[j].id;
          itmesArray.push(itmes)
      }
      setTimeout(function () {
        $("#"+el).select({
            title: titles,
            multi: true,
            items: itmesArray
        });
      },1000)
      return ''
    }
    // 单选
    function statusRadio(el,list,titles) {
      var itmes = {title:'',value:''},itmesArray = [];
      for (var j= 0;j<list.length;j++) {
          itmes = {};
          itmes.title = list[j].statusContent;
          itmes.value = list[j].id;
          itmesArray.push(itmes)
      }
      setTimeout(function () {
        $("#"+el).select({
            title: titles,
            multi: false,
            items: itmesArray
        });
      },1000)
      return ''
    }
    // 上传图片
    function uploadImg(type,that) {
       if (type == 'remote') {
         api.getPicture({
             sourceType: 'camera'
         }, function(ret, err){
             if(ret && ret.data!=""){
                 uploadHead(ret.data,that);
             }
         });
       }else {
         api.actionSheet({
             title: '选择',
             cancelTitle: '取消',
             buttons: ['相机','相册']
         }, function(ret, err) {
             if (ret.buttonIndex !=3) {
                 var type = 'camera';
                 if(ret.buttonIndex == 1){
                     type = 'camera';
                     api.getPicture({
                         sourceType: type
                     }, function(ret, err){
                         if(ret && ret.data!=""){
                             uploadHead(ret.data,that);
                         }
                     });
                 }else {
                     type = 'album';
                     // 支持多图片上传，UIAlbumBrowser模块获取图片路径
                     changeImageUrl(that)
                 }
             }
         });
       }
    }
    // upload img
    function uploadHead(imgUrl,that){
      $http.fileUploadRequest(UrlRouter.uploadFile,'post',{file:imgUrl})
      .then(ret=>{
        if(ret.code === '200'){
            var html = `<div class="img-item file-width" img-Url="${ret.data.fullURL}">
                          <img src="${ret.data.fullURL}" alt="">
                        </div>`;
            $api.append(that.parentNode,html);
            api.toast({
                msg: '上传成功',
                duration: 2000,
                location: 'top'
            });
        }else {
            api.toast({
                msg: '上传失败',
                duration: 2000,
                location: 'top'
            });
        }
      })
      .catch(err=>{
        api.toast({
            msg: '网络错误',
            duration: 2000,
            location: 'top'
        });
      })
    }
    // 获取相册图片路径
    function changeImageUrl(el) {
        UIAlbumBrowser.imagePicker({
            max: 9,
            styles: {
                bg: '#000000',
                //cameraImg: 'widget://res/cameraImg.png',
                mark: {
                    position: 'top_right',
                    size: 20
                },
                nav: {
                    bg: '#000000',
                    cancelColor: '#fff',
                    cancelSize: 16,
                    nextStepColor: '#7fff00',
                    nextStepSize: 16
                },
                thumbnail: {
                    w: 100,
                    h: 100
                }
            },
            animation: true,
        }, function(ret) {
            if (ret.eventType == 'nextStep') {
                UIAlbumBrowser.closePicker();
                if (ret.list && ret.list.length > 0) {
                    imgarr = ret.list;
                    // 转换缩略图路径 ios
                    UIAlbumBrowser_transPath(el);
                }
            }
            if (ret.originalPath && ret.originalPath.length > 0) {
                uploadHead(ret.originalPath,el)
            }
        });
    }
    // 转换缩略图路径 ios
    function UIAlbumBrowser_transPath(el) {
        UIAlbumBrowser.transPath({
            path: imgarr[i].path
        }, function(ret, err) {
            if (ret) {
                i++;
                if (i < imgarr.length) {
                    UIAlbumBrowser_transPath(el);
                } else {
                    i = 0;
                }
                uploadHead(ret.path,el)
            }
        });
    }
    // 上传文件
    // 浏览手机文件夹,获取文件路径
    function browseFile(el,type) {
      var fileBrowser = api.require('fileBrowser');
      fileBrowser.open(function(ret) {
        if (ret) {
            var type = ret.name.substring(ret.name.lastIndexOf('.'))
            if (
              type === '.xls' ||
              type === '.ppt' ||
              type === '.pptx' ||
              type === '.xlsx' ||
              type === '.doc' ||
              type === '.docx' ||
              type === '.zip' ||
              type === '.rar' ||
              type === '.pdf'
            ) {
              setTimeout(function () {
                uploadFile(el,ret.url)
              },500)
            }else if (type === '.mp3') {
              setTimeout(function () {
                uploadAudio(el,ret.url)
              },500)
            }else if(type === '.mp4'){
              setTimeout(function () {
                uploadVedio(el,ret.url)
              },500)
            }else {
              alert('选择文件格式不正确');
            }
        }
      });
      fileBrowser.skin({
          skin:1
      });
    }
    // 上传文件
    function uploadFile(el,fileUrl) {
        $http.fileUploadRequest(UrlRouter.uploadFile,'post',{file:fileUrl})
        .then(ret=>{
          if(ret.code === '200'){
              api.toast({
                  msg: '上传成功',
                  duration: 2000,
                  location: 'top'
              });
              var fileType = ret.data.fileName.substr(ret.data.fileName.length-3,3);
              if (
                  fileType == 'ppt' ||
                  fileType == 'ptx' ||
                  fileType == 'lsx' ||
                  fileType == 'xls' ||
                  fileType == 'doc' ||
                  fileType == 'ocx' ||
                  fileType == 'zip' ||
                  fileType == 'rar' ||
                  fileType == 'pdf'
              ){
                  var html = `<div class="file-item file-width" file-Url="${ret.data.fullURL}" file-Name="${ret.data.fileName}">
                            <img src="../../icon/${ret.data.fullURL.substr(ret.data.fullURL.length-3,3)}.png"/>
                            <p>${ret.data.fileName}</p>
                        </div>`;
                  $api.append(el.parentNode,html);
              }else {
                  api.toast({
                      msg: '文件格式不对',
                      duration: 2000,
                      location: 'top'
                  });
              }
          }else {
              api.toast({
                  msg: '上传失败',
                  duration: 2000,
                  location: 'top'
              });
          }
        })
        .catch(err=>{
          api.toast({
              msg: '网络错误',
              duration: 2000,
              location: 'top'
          });
        })
    }
    // 上传音频
    function uploadAudio(el,fileUrl) {
      $http.fileUploadRequest(UrlRouter.uploadFile,'post',{file:fileUrl})
      .then(ret=>{
        if(ret.code === '200'){
            api.toast({
                msg: '上传成功',
                duration: 2000,
                location: 'top'
            });
            var fileType = ret.data.fileExt;
            if (
                fileType == 'm4a' ||
                fileType == 'mp3' ||
                fileType == 'amr' ||
                fileType == 'AMR' ||
                fileType == 'WAV' ||
                fileType == 'wav' ||
                fileType == 'AWB' ||
                fileType == 'awb'
            ){
                $(el).hide();
                $(el).parent().find('.del-btn').show();
                var html = `<audio src="${ret.data.fullURL}" controls></audio>`;
                $(el).parent().parent().find('.audio-content').html(html)
            }else {
                api.toast({
                    msg: '音频格式不对',
                    duration: 2000,
                    location: 'top'
                });
            }
        }else {
            api.toast({
                msg: '上传失败',
                duration: 2000,
                location: 'top'
            });
        }
      })
      .catch(err=>{
        api.toast({
            msg: '网络错误',
            duration: 2000,
            location: 'top'
        });
      })
    }
    // 上传视频
    function uploadVedio(el,fileUrl) {
      $http.fileUploadRequest(UrlRouter.uploadFile,'post',{file:fileUrl})
      .then(ret=>{
        if(ret.code === '200'){
            api.toast({
                msg: '上传成功',
                duration: 2000,
                location: 'top'
            });
            var fileType = ret.data.fileExt;
            if (
                fileType == 'mp4' ||
                fileType == 'avi' ||
                fileType == 'wmv' ||
                fileType == '3gp' ||
                fileType == 'mkv' ||
                fileType == 'flv' ||
                fileType == 'rmvb'
            ){
                $(el).hide();
                $(el).parent().find('.del-btn').show();
                var html = `<video controls="controls" style="width: 100%;height: 200px;">
                    <source src="${ret.data.fullURL}">
                    当前不支持播放该视频
                </video>`;
                $(el).parent().parent().find('.audio-content').html(html)
            }else {
                api.toast({
                    msg: '视频格式不对',
                    duration: 2000,
                    location: 'top'
                });
            }
        }else {
            api.toast({
                msg: '上传失败',
                duration: 2000,
                location: 'top'
            });
        }
      })
      .catch(err=>{
        api.toast({
            msg: '网络错误',
            duration: 2000,
            location: 'top'
        });
      })
    }
    //提交
    function mvalidate() {
      var isOptionals = $('.isOptionals')
      var opnum=0,eachnum=0;
      isOptionals.each(function (index) {
       if ($(this).attr('isOptional') == 'true'){
          ++opnum;
       }
       if ($(this).attr('isOptional') == 'true' && $(this).parent().find('.isOptional').val() !== "") {
        ++eachnum
        }
      })
      if (opnum == eachnum) {
        return true;
      }else {
        return false;
      }
    }
    function submitRecode() {
      if (mvalidate()) {
        var inutItme =[],recordTrems = $('.recordTrems'),inputObj = {inputId:'',inputValue:''},changeInput = $('.changeInput');
        //6.图片
        var photoFile = $('.photoFile'),photoArray = [];
        var isOptional = true
        photoFile.each(function () {
             inputObj = {};
             photoArray =[];
             inputObj.inputId = $(this).attr('recordTrem-id');
             var photoList = $(this).find('.img-item');
             photoList.each(function () {
                 photoArray.push($(this).attr('img-Url'));
             });
             inputObj.inputValue = photoArray.join(',');
             if ($(this).attr('isOptional') === "true" && inputObj.inputValue =="") {
                 isOptional = false
             }
             inutItme.push(inputObj);
         });
       if (isOptional === false) {
           return api.toast({
               msg: '请上传带*号的图片',
               duration: 2000,
               location: 'bottom'
           });
        }
        api.showProgress({
          title: '',
          text: '提交中...',
          modal: true
        });
        // 检查项
        var inspectTremA = $('.checked'),checkItemArray = [];
        var obj = {checkItemId:'',instanceValue:''}
        for (var i = 0; i < inspectTremA.length; i++) {
          obj = {}
          if (inspectTremA[i].checked) {
              obj.checkItemId = inspectTremA[i].value
              obj.instanceValue = true;
              checkItemArray.push(obj)
          }
        }
        // 记录项
         //// 1.文本, 时间，日期，数字
         recordTrems.each(function () {
             inputObj = {};
             var inputValue = $(this).val(),
             inputId = $(this).attr('recordTrem-id'),
             datetime = $(this).attr('data-datetime');;
             if (datetime) {
               inputObj.inputId = inputId;
               inputObj.inputValue = inputValue.replace("T"," ");
             }else {
               inputObj.inputId = inputId;
               inputObj.inputValue = inputValue;
             }
             inutItme.push(inputObj);
         });
         var classSign = $('.classSign')
          // 记录项，手写签名
          classSign.each(function () {
            inputObj = {};
            $(this).attr('recordTrem-id')
            inputObj.inputId = $(this).attr('recordTrem-id')
            inputObj.inputValue = sign
            inutItme.push(inputObj);
          })
         //2.多选,单选
         changeInput.each(function () {
            inputObj = {};
            inputObj.inputId = $(this).attr('recordTrem-id');
            inputObj.inputValue = $(this).attr('data-values');
            inutItme.push(inputObj);
         });
         //3.录音
         var mp3_wrap = $('.mp3_wrap');
         mp3_wrap.each(function () {
              inputObj = {};
              inputObj.inputId = $(this).attr('recordTrem-id');
              inputObj.inputValue = $(this).find('audio').attr('src');
              inutItme.push(inputObj);
          });
         //4.视频
         var mp4_wrap = $('.mp4_wrap');
         mp4_wrap.each(function () {
              inputObj = {};
              inputObj.inputId = $(this).attr('recordTrem-id');
              inputObj.inputValue = $(this).find('video>source').attr('src');
              inutItme.push(inputObj);
          });
         //5.文件
         var fileList_warp = $('.fileList_warp'),fileArray = [],fileName = [],num = 0;
         fileList_warp.each(function (index) {
            inputObj = {};
            fileArray= [];
            inputObj.inputId = $(this).attr('recordTrem-id');
            var fileList = $(this).find('.file-item');
            fileList.each(function () {
                fileArray.push($(this).attr('file-Url')+"-"+$(this).attr('file-Name'));
            });
            inputObj.inputValue = fileArray.join(',');
            inutItme.push(inputObj);
         });
        // 状态项
        // 状态
        var moreStatusA = $('.moreStatusA'),statusA = [],statusObj = {statusId:"",statusValue:''};
        moreStatusA.each(function () {
            statusObj = {};
            statusObj.statusId = $(this).attr('statusId');
            statusObj.statusValue = $(this).attr('data-values');
            statusA.push(statusObj);
        });
        var filterl= inutItme.filter(function (item) {
            if (item.inputValue != undefined){
                return item.inputValue !=""
            }
        });
        var param= {
            checkItems: checkItemArray,
            createBy: userId,
            createName: userName,
            inputs:filterl,
            pageId:pageId,
            pageRecordParentId:pageRecordParentId,
            recordParentId:recordParentId,
            status:statusA.length !=0? statusA : [],
            statusContent:$('.statusContent').val(),
            templateId:templateId,
            templateName:templateName,
            departmentId:departmentId,
            spName:spName,
            lng:lon,
            lat:lat
        }
        $.ajax({
          url: UrlRouter.addRecordInstance,
        	type: 'post',
          contentType:'application/json;charset=UTF-8',
        	dataType: 'json',
        	data: JSON.stringify(param),
          success: function (ret) {
            if(ret.code === '200') {
              $('.submit-btn').attr('disabled','disabled')
              api.hideProgress()
              $event.openTabLayout('recodeDetails'+Math.random(),'recodeDetails','记录详情',{recordParentId:ret.data});
            }else if (ret.code == 422) {
              api.hideProgress()
              api.alert({
                  title: '提示',
                  msg: '请填写记录项',
              });
            }
          },
          error:function (err) {
            api.hideProgress()
            api.toast({
              msg: err,
              duration: 3000,
              location: 'top'
            });
          }
        })
      }else {
        api.toast({
          msg: '请填写带*号的内容！',
          duration: 3000,
          location: 'top'
        });
      }
    }
    // 定位初始化
    var  spName = '',lon='',lat='';
    function getLonLat(flag) {
      if (flag) {
        api.showProgress({
            title: '提示',
            text: '定位中...',
        });
      }
      var aMap = api.require('aMap');
      aMap.getLocation(function(ret, err) {
          if (ret.status) {
            api.hideProgress();
            lon= ret.lon; lat=ret.lat;
            aMap.getNameFromCoords({
                lon: ret.lon,
                lat: ret.lat
            }, function(ret, err) {
                if (ret.status) {
                    spName = ret.address
                    $apis.html(position_warp, '#mapTemplate',ret);
                } else {
                  api.toast({
                      msg: '请打开手机定位',
                      duration: 2000,
                      location: 'top'
                  });
                }
            });
          } else {
            api.hideProgress();
            api.toast({
                msg: '定位失败请重新定位',
                duration: 2000,
                location: 'top'
            });
          }
      });
      return '';
    }
    // textarea根据文字多少自适应高度
    function Oninput(that) {
        $(that).height(that.scrollHeight);
    }
</script>
