<!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">
    <title>紫光云引擎</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <style type="text/css">
        .aui-timeline .aui-timeline-item-label {
            width: 1rem;
            height: 1rem;
            line-height: 1.5rem;
            font-size: 0.7em;
            background-color: #ececec;
            position: absolute;
            border-radius: 1rem;
            text-align: center;
            left: 1.5rem;
            top: 0.5rem;
        }

        .btn-disable i,
        .btn-disable div {
            color: #ccc;
        }
        .cycle_style{
          display:inline-block;
          /*background:#55db25;*/
          border:1px solid #0065CF;
          width:20px;
          height:10px;
          text-align:center;
          color:#0065CF;
          line-height:8px;
          border-radius:10px;
          font-size:8px;
          vertical-align: middle;
        }

        .mode_style{
           display:inline-block;
           /*background:#55db25;*/
           width:20px;
           height:10px;
           text-align:center;
           color:#fff;
           line-height:10px;
           border-radius:10px;
           font-size:8px;
           vertical-align: middle;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" id="header">
        <a class="aui-pull-left aui-btn " tapmode onclick="closethisWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title" data-i18n="100357"></div>
        <a class="aui-pull-right aui-btn">

        </a>
    </header>
    <!-- <div class="selecttitle" style="display: none;position: fixed;background: #fff;line-height: 50px;width: 100%;z-index: 9999999999;">
        <div class="aui-row">
            <div class="aui-col-xs-4 aui-padded-l-10">
                &nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <div class="aui-col-xs-4 aui-text-center" data-i18n="6660043">
            </div>
            <div class="aui-col-xs-4 aui-text-right aui-padded-r-10">
            </div>
        </div>
    </div>
    <div class="selectmask" style="display: none; background: #fff;position: fixed;width: 100%;z-index: 9999999999;"></div> -->

    <div class="selecteqiptitle" style="display: none;position: fixed;background: #fff;line-height: 50px;width: 100%;z-index: 9999999999;">
        <div class="aui-row">
            <div class="aui-col-xs-4 aui-padded-l-10">
                <!-- <i class="aui-iconfont aui-icon-close selectequipclose"></i> -->
                &nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <div class="aui-col-xs-4 aui-text-center" data-i18n="300076">
            </div>
            <div class="aui-col-xs-4 aui-text-right aui-padded-r-10">
                <span class="selectequipdone" data-i18n="100354"></span>
            </div>
        </div>
    </div>

    <section class="aui-content-padded" id="detail" style="margin-top: 80px;">
        <script id="DotTemplate" type="text/x-dot-template">
            <div class="aui-card-list">
                <div class="aui-card-list-header aui-card-list-user">
                    <div class="aui-card-list-user-name">
                        <div class="aui-font-size-16">
                            <b>{{=it.location}}</b> &nbsp;
                            <span style="color:#ccc;"></span>&nbsp;
                        </div>
                        <small></small>
                    </div>
                </div>
                <div class="aui-card-list-content aui-border-t" style="margin-left: 1rem;">
                    <ul class="aui-list aui-list-noborder">

                        <div class="aui-list-item aui-padded-l-0">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-title aui-font-size-14 goods-title">{{= it.count}}{{=lang('6660004')}} {{=lang('800192')}}{{= it.standard_time}}{{=lang('200028')}}</div>
                                <div class="aui-list-item-right goods-price"></div>
                            </div>
                        </div>

                    </ul>
                </div>
            </div>
        </script>
    </section>

    <ul class="aui-list aui-margin-b-15  aui-form-list usersel" style="display: none;">
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label" data-i18n="200053">
                </div>
                <div class="aui-list-item-input">
                    <div class="userselected" data-i18n="600543"></div>
                    <input type="hidden" class="actual_mid">
                </div>
            </div>
        </li>
    </ul>

    <div class="aui-content maincontent" id="timelinePanel" style="margin-bottom: 80px;">

        <script id="TimeLineDotTemplate" type="text/x-dot-template">
            {{~it:value:index}}
            <ul class="aui-list aui-list-in">
                <li class="aui-list-header"> {{= value.date}} </li>
                {{~value.data:val:ind}}
                <div class="aui-card-list jhwhitem" time-id="{{=val.ptimeid}}" style="margin-bottom:0rem;">
                    <div class="aui-card-list-header aui-collapse-header" tapmode>
                        <div style="width:85%;">
                            {{ if(val.makeself==1){ }}
                                <span class="cycle_style">
                                      {{ if(val.mode==1){ }} AM {{ }else if(val.mode==2){ }} PM {{ }else if(val.mode==3){ }} CMP {{ }else{} }}
                                </span>
                            {{ }else if(val.makeself==2){ }}
                                <span class="cycle_style">
                                      {{ if(val.mode==1){ }} AM {{ }else if(val.mode==2){ }} PM {{ }else if(val.mode==3){ }} CMP {{ }else{} }}
                                </span>
                            {{ }else if(val.makeself==0){ }}
                                {{ if(val.mode==1){ }}<span class="mode_style" style="background:red;">AM</span>
                                {{ }else if(val.mode==2){ }}<span class="mode_style" style="background:gold;">PM</span>
                                {{ }else if(val.mode==3){ }}<span class="mode_style" style="background:green;">CMP</span>
                                {{ }else{} }}
                            {{ } }}
                            {{= val.content}}

                        </div>
                        <div class="rcon">

                            {{ if (val.value_type == 1) { }}
                            <input class="aui-checkbox checkjhwh check_{{=val.ptimeid}}" style="display:none;" type="checkbox" name="checkbox" onClick="event.cancelBubble = true" data-timeid="{{=val.ptimeid}}" data-itemid="{{=val.itemid}}" data-planid="{{=val.planid}}" data-value="true"
                                data-valuetype="{{=val.value_type}}" data-images="" data-spareid=""> {{ } else { }}
                            <div class="dc checkjhwh" style="display:none;" data-timeid="{{=val.ptimeid}}"><span class="aui-pull-left sc"><input type="text" name=""  class="ivalue check_{{=val.ptimeid}}" onClick="event.cancelBubble = true" data-timeid="{{=val.ptimeid}}" data-itemid="{{=val.itemid}}" data-planid="{{=val.planid}}" data-value="true" data-valuetype="{{=val.value_type}}" data-images="" data-spareid="" value="{{= val.value?val.value:''}}" style="width:50px;border:1px #ccc solid;height:30px;"></span>
                                <span class="aui-pull-left" style="margin-left: 10px;">{{=val.unit}}</span>
                            </div>
                            {{ } }}
                        </div>
                        <i class="aui-iconfont aui-icon-down aui-collapse-arrow"></i>

                    </div>
                    <div class="aui-card-list-content-padded aui-collapse-content">
                        <div class="aui-grid">
                            <div class="aui-row">
                                <div class="aui-list-item-inner">
                                    <div class="aui-flex-col" style="width:25%">
                                        {{=lang('6660141')}}
                                    </div>
                                    <div class="aui-flex-col" style="width:75%">
                                        {{=val.maintain_tool}}
                                    </div>
                                </div>
                            </div>
                            <div class="aui-row">
                                <div class="aui-list-item-inner">
                                    <div class="aui-flex-col" style="width:25%">
                                        {{=lang('6660142')}}
                                    </div>
                                    <div class="aui-flex-col" style="width:75%">
                                        {{=val.maintain_sparepart}}
                                    </div>
                                </div>
                            </div>


                            <div class="aui-row">
                                <div class="aui-list-item-inner">
                                    <div class="aui-flex-col" style="width:25%">
                                        {{=lang('6660147')}}
                                    </div>
                                    <div class="aui-flex-col" style="width:75%">
                                        <div class="aui-list-item-input">
                                            <input type="number" class="standard_time" id="standard_time_{{=val.ptimeid}}" style="border:1px #ccc solid;height:30px;" value="{{=val.standard_time}}"  onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode) ) )' readonly="readonly">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="aui-row">
                                <div class="aui-list-item-inner">
                                    <div class="aui-flex-col" style="width:25%">
                                        {{=lang('6660143')}}
                                    </div>
                                    <div class="aui-flex-col" style="width:75%">
                                        <div class="aui-list-item-input">
                                            <input type="text" class="maint_remakr" id="remak_{{=val.ptimeid}}" style="border:1px #ccc solid;height:30px;" value="{{=val.keep_remark}}" readonly="readonly"></input>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="aui-row ">
                                <div class="aui-col-xs-4  aui-padded-0 selectequip btn-disable">
                                    <i class="aui-iconfont aui-icon-image" style="font-size: 1rem;"></i>
                                    <div class="aui-grid-label" style="font-size: 0.4rem;">{{=lang('6660044')}}</div>
                                </div>
                                <div class="aui-col-xs-4 aui-padded-0 takephoto btn-disable">
                                    <i class="aui-iconfont aui-icon-camera" style="font-size: 1rem;"></i>
                                    <div class="aui-grid-label" style="font-size: 0.4rem;">{{=lang('6660045')}}</div>
                                </div>
                                <div class="aui-col-xs-4 aui-padded-0 btn-zhidaoshu" data-url="{{= val.work_instruction_url}}">
                                    <i class="aui-iconfont aui-icon-info" style="font-size: 1rem;"></i>
                                    <div class="aui-grid-label" style="font-size: 0.4rem;">{{=lang('6660046')}}</div>
                                </div>
                            </div>

                            <div class="aui-row">
                                <div class="aui-list-item-inner">
                                    <div class="aui-flex-col">
                                        <span class="aui-pull-left">{{=lang('8000101')}}</span>
                                          <span class="aui-pull-left add_repairuser" data_id="{{=val.ptimeid}}" onclick="getUserPage(this)" style="margin-left: 10px;display:none;">
                                            <img src="../image/plus.png" style="width:20px;height:20px;">
                                          </span>
                                    </div>
                                </div>
                                <div class="aui-content aui-margin-b-15">
                                  <ul class="aui-list ">
                                    <div class="aui-list-item">
                                      <div class="tagcon" id="userselected_{{=val.ptimeid}}">
                                        {{= maskEquip(val.corepairer_names)}}
                                      </div>
                                      <input type="hidden" name="" id="add_repairmid_{{=val.ptimeid}}"></li>
                                    </div>
                                  </ul>
                                </div>
                            </div>

                            <div class="tagcon equipselected">
                                {{= maskEquip(val.sparepartout)}}
                                <!--    <div class="tag"><div class="m-badge deleteuser">x</div>{{=lang('6660047')}}</div>
                                        <div class="tag"><div class="m-badge deleteuser">x</div>tes</div> -->
                            </div>

                            <div class="tagcon cphotos">
                                {{= maskPhoto(val.imgurl)}}
                            </div>
                        </div>
                    </div>
                    {{~}}
              </ul>
            {{~}}
        </script>
        </div>


        <footer class="aui-bar aui-bar-tab" id="footer" style="display:none;">
            <input type="hidden" name="repairstatus" class="repairstatus">
            <div class="aui-content-padded">
                <div class="aui-list-item-inner aui-list-item-center aui-list-item-btn" id="yjwx_btns">
                    <div class="aui-btn aui-btn-info aui-btn-block aui-btn-sm btn_qrcode" data-i18n="6660048"></div>
                </div>

            </div>
        </footer>


</body>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/md5.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/swipe.js"></script>
<script type="text/javascript" src="../script/SHA1.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/remotedb.js"></script>
<script type="text/javascript" src="../script/list.js"></script>
<script type="text/javascript" src="../script/aui-tab.js"></script>
<script type="text/javascript" src="../script/aui-toast.js"></script>
<script type="text/javascript" src="../script/aui-selectbox.js"></script>
<script type="text/javascript" src="../script/aui-popup-new.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/CryptoJS/core.js"></script>
<script type="text/javascript" src="../script/CryptoJS/cipher-core.js"></script>
<script type="text/javascript" src="../script/CryptoJS/mode-ecb.js"></script>
<script type="text/javascript" src="../script/CryptoJS/aes.js"></script>
<script type="text/javascript" src="../script/aui-collapse.js"></script>

<script type="text/javascript" src="../script/i18next-12.0.0.min.js"></script>
<script type="text/javascript" src="../script/i18nextLocizeBackend.min.js"></script>
<script type="text/javascript" src="../script/jquery-i18next.min.js"></script>
<script type="text/javascript" src="../script/jquery.cookie.js"></script>
<script type="text/javascript" src="../script/i18n-app.js"></script>

<script type="text/javascript">
    var isopened, camera, host, machineid, qrcode, params, popup, selectbox, user, editable = 0,
        wostatus, params, straight, datetype, lang, i18next, midfromqr,state;

    var currentrow = 0;

    apiready = function() {
        isopened = 0;
        fnReady();
        ajaxsetup();
        initRequire();
        host = $api.getStorage('host');
        user = JSON.parse($api.getStorage('current_user'));
        selectbox = new auiSelectbox();
        popup = new auiPopup();
        machineid = api.pageParam.machineid;
        wostatus = api.pageParam.status;
        qrcode = api.pageParam.qrcode;
        params = api.pageParam.params;
        datetype = api.pageParam.DateType;
        state = api.pageParam.state;
        if(state == 1){
          $("#footer").hide();
        }
        else{
          $("#footer").show();
        }
        if (headerHeight > 69) {
            $("#detail").attr("style", "margin-top: 104px;");
        }
        load_i18n(function(t, i18n) {
            lang = t;
            i18next = i18n;
            // $('.equipselected').hide();
            // $('.cphotos').hide();
            $('.userselected').html(user.name);
            $('.actual_mid').val(user.mid);

            if (params) {
                var obj = JSON.parse(decodeURIComponent(params));
                straight = obj.straight;
                if (straight == 1) {
                    wostatus = "1";
                    var idindex = qrcode.indexOf('id=');
                    if (idindex < 0) {
                        getMachineId(qrcode, '1');
                    } else {
                        machineid = qrcode.substring(qrcode.indexOf('id=') + 3);
                    }
                    if (!machineid) {
                        customToast(lang('600184'), 2000);
                        setTimeout(function() {
                            api.closeFrame();
                            // api.closeWin();
                        }, 1000);
                        return;
                    }
                } else {
                    machineid = obj.machineid;
                    wostatus = obj.wostatus;
                }
            }
            getPlan(machineid);
        });
        console.log(JSON.stringify(api.pageParam));
    };

    function dohit(pitemid) {
        if (editable === 1) {
            $('.unhit_' + pitemid).css("background-color", "#C0C0C0");
            $('.hit_' + pitemid).css("background-color", "#AFEEEE");
            event.stopPropagation();
        }
    }

    function dounhit(pitemid) {
        if (editable === 1) {
            $('.hit_' + pitemid).css("background-color", "#C0C0C0");
            $('.unhit_' + pitemid).css("background-color", "#AFEEEE");
            event.stopPropagation();
        }
    }

    function getMachineId(pEquipAcc, psetrestu) {
        $.ajax({
            url: host + '/config/Machine/GetMachineIdByCode',
            data: JSON.stringify({
                "code": pEquipAcc
            }),
            type: 'POST',
            async: false,
            success: function(result) {
                console.log(JSON.stringify(result));
                if (result.ret == 1) {
                    if ('1' == psetrestu) {
                        machineid = result.data;
                    } else {
                        midfromqr = result.data;
                    }
                    // } else {
                    //     customToast(lang('600184'), 2000);
                }
            }
        });
    }

    /*****************************选择人员 start*********************************/
      function getUserPage(obj)
      {
          let ptimeid = $(obj).attr("data_id");//点击的项目
          let selectuids = $('#add_repairmid_'+ptimeid).val();
          //选择人员
          api.openFrame({
              name: 'tpm_selectPeople',
              url: './tpm_selectPeople.html',
              pageParam: {
                  type: 2, //1单选，2多选
                  pageTitle: '合作维护人',
                  userIds:selectuids
              },
              rect: { // 采用 margin相对布局
                  marginTop: 0,
                  h: 'auto',
                  w: 'auto'
              },
              bounces: false,
              bgColor: 'rgba(0,0,0,0)',
          });

          //监听选中人员
          api.addEventListener({
              name: 'tpm_jihuaweihurenyuan'
          }, function(ret, err) {
              if (ret) {
                  var datartn = eval('(' + JSON.stringify(ret) + ')');
                  var rtnLst = datartn['value']['selectPeople'];
                  if (rtnLst.length > 0) {
                      var html = '';
                      var arr = [];
                      $.each(rtnLst, function(index, val){
                          // html+='<div class="aui-col-xs-3"><div class="aui-badge deleteuser" data-id="'+val.employee_id+'">x</div><div class="aui-btn  aui-btn-block aui-btn-sm">'+val.name+'</div></div>';
                          html += '<div class="tag"><div class="m-badge deleteuser" div_id="'+ptimeid+'" onclick="deleteUser(this)"  data-id="' + val.employee_id + '">x</div>' + val.name + '</div>';
                          arr.push(val.employee_id);
                      });
                      $('#userselected_'+ptimeid).html(html);
                      $('#add_repairmid_'+ptimeid).val(arr.join(","));
                  }
              }
              api.removeEventListener({
                  name: 'tpm_jihuaweihurenyuan'
              });
          });
      }

      //删除人员
      function deleteUser(obj)
      {
          let id = $(obj).attr("data-id");
          let ptimeid = $(obj).attr("div_id");
          let add_repairmid = $('#add_repairmid_'+ptimeid).val().split(",");
          let index = add_repairmid.indexOf(id);
          if(index !== -1){
               add_repairmid.splice(index, 1);
          }
          $('#add_repairmid_'+ptimeid).val(add_repairmid.join(","));
          $(obj).parent().remove();
      }
    /*******************************选择人员 end***********************************/

    function updateSignInfo(pmachineid) {
        $.ajax({
            url: host + "/tpm/AppPlan/PlanSign",
            data: JSON.stringify({
                "machineID": parseInt(pmachineid)
            }),
            dataType: 'json',
            contentType: 'application/json',
            type: 'POST',
            success: function(result) {
                console.log(JSON.stringify(result));
                if (result.ret == 1) {
                    editable = 1;
                    customToast(lang('6660049'), 2000);
                    makeeditable();
                } else {
                    customToast(lang(result.msg), 2000);
                }
            },
            error: function(error) {
                // console.log(JSON.stringify(error))
                if ('404' == error.status) {
                    // console.log('404');
                    editable = 1;
                    customToast(lang('6660049'), 2000);
                    makeeditable();
                } else {
                    customToast(lang('9999999'), 2000);
                }
            }
        })
    }

    function makeeditable() {
        setTimeout(function() {
            $('.checkjhwh').show();
            $('.usersel').show();
            $(".maint_remakr").removeAttr("readonly");
            $(".standard_time").removeAttr("readonly");
            $(".add_repairuser").show();
            $('.selectequip').removeClass('btn-disable');
            $('.takephoto').removeClass('btn-disable');
            // $('#timelinePanel').show();
        }, 800);
        $('#yjwx_btns').html('<div class="aui-btn aui-btn-info aui-btn-block aui-btn-sm btn_submit">' + lang('6660051') + '</div>');
        listen_submitInfo();
    }


    var collapse = new auiCollapse({
        autoHide: false //是否自动隐藏已经展开的容器
    });


    function listequip() {

        $(".selectequip").click(function() {
            if (editable === 1) {
                currentrow = $(this).parent().parent().parent().prev().find('.rcon>.checkjhwh').attr('data-timeid');
                if (isopened == 1) {
                    // equipSelect.show();
                    $('.selectmask').show();
                    $('.selectmask').css("top", headerHeight + 50);
                    $('.selectmask').css("height", api.screenHeight);
                    $('.selecteqiptitle').show();
                    $('.selecteqiptitle').css("top", headerHeight);
                    $('#footer').hide();
                    return;
                }

                selectcart();
                api.addEventListener({
                    name: 'selectedbj'
                }, function(ret, err) {
                    if (ret) {
                        // alert(JSON.stringify(ret))
                        var datartn = eval('(' + JSON.stringify(ret) + ')');
                        var rtnLst = datartn['value']['result'];
                        // console.log('rtnLst.length is : ' + rtnLst.length);
                        if (rtnLst.length > 0) {
                            setSparaInfos(rtnLst)
                        }
                    }
                    api.removeEventListener({
                        name: 'selectedbj'
                    });
                });
            }
        });

    }

    function setSparaInfos(presult) {
        var html = '';
        var arr = [];
        var arrids = [];
        for (var i = 0; i < presult.length; i++) {
            var title = presult[i]['index'].split("|")[1] + "×" + presult[i]['val'];
            var id = presult[i]['index'].split("|")[0];
            var sudata = id + "*" + presult[i]['val'];
            html += '<div class="tag"><div class="m-badge deleteequip"  data-id="' + sudata + '">x</div>' + title + '</div>';
            arr.push(sudata);
            arrids.push(presult[i]['index']);
        }
        var vtype = $('.check_' + currentrow).attr('data-valuetype');
        if (vtype == '1') {
            $('.check_' + currentrow).parent().parent().next().find('.equipselected').html(html);
        } else {
            $('.check_' + currentrow).parent().parent().parent().parent().next().find('.equipselected').html(html);
        }
        $('.check_' + currentrow).attr('data-spareid', arr.join(","));

        listen_equipdel();
    }

    function selectcart() {
        api.openWin({
            name: 'tpmbjlb',
            url: './tpm_bjlb.html',
            pageParam: {
                machineId: machineid,
                selVals: $('.check_' + currentrow).attr('data-spareid'),
                titleHtml: $('#title').html()
            },
            bounces: false,
            bgColor: 'rgba(0,0,0,0)'
        });

    };




    // $(".deleteuser").click(function() {
    //     console.log('asdasdf');
    //     console.log($(this).parent().html());
    //     $(this).parent().remove();
    // });


    // $(".userselected").click(function() {
    //     console.log(headerHeight);
    //     getUserList(2);
    //     $('.selectmask').show();
    //     $('.selectmask').css("top", headerHeight + 50);
    //     $('.selectmask').css("height", api.screenHeight);
    //     $('.selecttitle').show();
    //     $('.selecttitle').css("top", headerHeight);
    //     $('#footer').hide();
    //
    // });

    // $(".selectuserclose").click(function() {
    //     fnClose();
    //     $('.selecttitle').hide();
    //     $('.selectmask').hide();
    //     $('#footer').show();
    // });

    $(".selectequipclose").click(function() {
        equipClose();
        $('.selecteqiptitle').hide();
        $('.selectmask').hide();
        $('#footer').show();
    });

    function listen_equipdel() {
        $(".deleteequip").click(function() {
            var id = $(this).attr("data-id");
            var add_repairmid = $('.check_' + currentrow).attr('data-spareid').split(",");
            var index = add_repairmid.indexOf(id);
            if (index !== -1) add_repairmid.splice(index, 1);
            $('.check_' + currentrow).attr('data-spareid', add_repairmid.join(","));
            $(this).parent().remove();

        });
    }



    // function fnOpen(data) {
    //
    //     userSelect.open({
    //         bgColor: '#ffffff',
    //         isRadio: true,
    //         rect: {
    //             x: 0,
    //             y: headerHeight + 50,
    //             // y : api.frameHeight/2,
    //             w: api.frameWidth,
    //             h: api.frameHeight
    //         },
    //         contacts: data,
    //         fixedOn: api.frameName
    //     }, function(ret) {
    //         if (ret) {
    //             if (ret.contact) {
    //
    //                 // var ret = userSelect.getSelectedSync();
    //                 $('.userselected').html(ret.contact.name);
    //                 $('.actual_mid').val(ret.contact.employee_id);
    //
    //
    //                 $('.selecttitle').hide();
    //                 $('.selectmask').hide();
    //                 $('#footer').show();
    //                 fnClose();
    //
    //             }
    //
    //         }
    //     });
    //
    //     var userids = $('.add_repairmid').val();
    //
    //     var arr = [parseInt(userids)];
    //
    //     fnSetSelected(arr);
    //
    // }

    // function fnClose() {
    //     userSelect.close();
    // }

    function equipClose() {
        // equipSelect.hide();
    }


    // function fnGetActive() {
    //     userSelect.getActive(function(ret, err) {
    //         if (ret) {
    //             alert(JSON.stringify(ret));
    //         } else {
    //             alert(JSON.stringify(err));
    //         }
    //     });
    // }
    //
    // function fnSetSelected(data) {
    //
    //     userSelect.setSelected({
    //         contacts: data
    //     });
    // }



    // function fnGetSelectedSync() {
    //     var ret = userSelect.getSelectedSync();
    //     api.alert({
    //         msg: JSON.stringify(ret)
    //     });
    // }
    //
    // function getUserList(type) {
    //     $.ajax({
    //         url: host + "/tpm/AppRepair/GetUserListByType",
    //         // data: JSON.stringify({
    //         //     "type": type
    //         // }),
    //         data: JSON.stringify({
    //             "type": 0
    //         }),
    //         dataType: 'json',
    //         　　　　　　contentType: 'application/json',
    //         type: 'POST',
    //         success: function(result) {
    //             // console.log(JSON.stringify(result));
    //             fnOpen(result.data);
    //             // console.log(JSON.stringify(result));
    //         }
    //     })
    // }

    function getPlan(machineid) {
        // console.log(machineid);
        // console.log(wostatus);

        var url = "";
        if (wostatus == "1") {
            url = host + '/tpm/AppPlan/PlanListByMachine';
        } else if (wostatus == "2") {
            $('#yjwx_btns').html('<div class="aui-btn aui-btn-block aui-btn-sm ">' + lang('6660035') + '</div>');
            url = host + '/tpm/AppPlan/PlanHistoryInfo';
        }
        // console.log(url);
        // console.log(machineid);
        // var host='http://61.177.28.246:8100';
        var postdata = {
            "machineID": parseInt(machineid),
            "state":state
        };
        if (datetype) {
            postdata = {
                "machineID": parseInt(machineid),
                "DateType": parseInt(datetype)
            };
        }
        // console.log(JSON.stringify(postdata));
        // console.log(url);
        $.ajax({
            url: url,
            data: JSON.stringify(postdata),
            dataType: 'json',
            contentType: 'application/json',
            type: 'post',
            success: function(result) {
                // console.log(JSON.stringify(result));
                if (result.ret == 1) {

                    var testTemplate = doT.template($("#DotTemplate").text());
                    $("#detail").html(testTemplate(result.data));
                    // $("#title").html(result.data.location);
                    // $("#title").html("");
                    var location = result.data.location;
                    let m_name = machineid;
                    if(location && location!="")
                    {
                        let l_a = location.split('-');
                        if(l_a.length > 1)
                        {
                            m_name = l_a[l_a.length-1];
                        }

                    }
                    $(".detail-machineid").html(m_name);
                    // listen_submitInfo();




                    //时间线分组

                    var newarr = groupJson(result.data.planlist);
                    // console.log(newarr);
                    var timeTemplate = doT.template($("#TimeLineDotTemplate").text());
                    $("#timelinePanel").html(timeTemplate(newarr));

                    if (url == host + '/tpm/AppPlan/PlanHistoryInfo') {
                        doSkfset(result.data.planlist);
                    }

                    listequip();
                    takePicture();
                    lit_zhidaoshu();
                    var collapse = new auiCollapse({
                        autoHide: false //是否自动隐藏已经展开的容器
                    });

                    if (wostatus == "2") {
                        $('.usersel').show();
                        $('.checkjhwh').show();
                        $(".userselected").unbind("click");
                        if ($('.checkjhwh').is(':checkbox')) {
                            $('.checkjhwh').attr('checked', true);
                        }
                        $('.m-badge').hide();
                        $('.tag').css('padding-left', '20px');
                        $('.photo-badge').hide();
                    }
                    $(".imgin").unbind("click");
                    $(".imgin").click(function() {
                        fnOpenLightBoxThisCon(this);
                    });
                    $('.add_repairmid').val(result.data.add_repairmid);
                    $('.repairid').val(result.data.repairid);
                    $('.fault_description').val(result.data.fault_description);
                    $('.fault_desc_img').val(result.data.fault_desc_img);
                    $('.repair_process').val(result.data.repair_process);
                    $('.repair_remark').val(result.data.repairremark);
                    $('.real_faultid_desc').val(result.data.fault_description);
                    $('.sparepartoutid').val(result.data.sparepartoutid);

                    if (straight == 1) {
                        updateSignInfo(machineid)
                            // editable = 1;
                            // makeeditable();
                        return;
                    }
                    if (qrcode) {
                        if (qrcode.indexOf('id=') > -1) {
                            midfromqr = qrcode.substring(qrcode.indexOf('id=') + 3);
                        } else {
                            getMachineId(qrcode, '2');
                        }
                        if (midfromqr == machineid) {
                            // editable = 1;
                            updateSignInfo(machineid);
                        } else {
                            customToast(lang('6660050'), 2000);
                        }
                    }

                } else {
                    customToast(lang(result.msg), 2000);
                }
            }
        })
    }

    function doSkfset(pplanlist) {
        if (pplanlist) {
            for (var i = 0; i < pplanlist.length; i++) {
                if (pplanlist[i]['hit_type'] == 0) {
                    $('.unhit_' + pplanlist[i]['ptimeid']).css("background-color", "#AFEEEE");
                    $('.hit_' + pplanlist[i]['ptimeid']).css("background-color", "#C0C0C0");
                } else if (pplanlist[i]['hit_type'] == 1) {
                    $('.hit_' + pplanlist[i]['ptimeid']).css("background-color", "#AFEEEE");
                    $('.unhit_' + pplanlist[i]['ptimeid']).css("background-color", "#C0C0C0");
                }
            }
        }
    }

    function listen_submitInfo() {
        $(".btn_submit").click(function() {
            var postdata = {};
            if ($('.actual_mid').val()) {
                postdata.actual_mid = parseInt($('.actual_mid').val());
            } else {
                customToast(lang('6660052'), 2000);
                return;
            }

            // console.log(JSON.stringify(postdata));
            var planarr = [];
            var temptimeid;
            var haserr = false;
            $(".jhwhitem").each(function() {
                temptimeid = $(this).attr('time-id');
                // console.log($('.remak_' + temptimeid).val());
                var valhitmark;
                // console.log($($(this).find('.aui-collapse-header>.hit_info>.hitval')).css("background-color") == "rgb(192, 192, 192)");
                if ($('.hit_' + temptimeid).css("background-color") == "rgb(175, 238, 238)") {
                    valhitmark = 1;
                }
                if ($('.unhit_' + temptimeid).css("background-color") == "rgb(175, 238, 238)") {
                    valhitmark = 0;
                }
                // console.log('valhitmark is ' + valhitmark);
                if ($(this).find('.aui-collapse-header>.rcon>input.checkjhwh').prop('checked')) {
                    // console.log($(this).find('.aui-collapse-header>.rcon>input.checkjhwh').prop('checked'))
                    // console.log($(this).find('.aui-collapse-header>.rcon>input.checkjhwh').is(':checked'))  判断有bug
                    // console.log('bb');
                    // console.log($(this).find('.aui-collapse-header>input').attr('data-timeid'));
                    var plan = {};
                    plan['timeid'] = $(this).find('.aui-collapse-header>.rcon>input').attr('data-timeid');
                    plan['itemid'] = $(this).find('.aui-collapse-header>.rcon>input').attr('data-itemid');
                    plan['planid'] = $(this).find('.aui-collapse-header>.rcon>input').attr('data-planid');
                    plan['value_type'] = $(this).find('.aui-collapse-header>.rcon>input').attr('data-valuetype');
                    plan['value'] = "true";
                    plan['images'] = $(this).find('.aui-collapse-header>.rcon>input').attr('data-images');
                    plan['sparepartoutid'] = $(this).find('.aui-collapse-header>.rcon>input').attr('data-spareid');

                    //命中信息不验证
                    // if (valhitmark != 0 && valhitmark != 1) {
                    //     customToast(lang('6660144'), 2000);
                    //     haserr = true;
                    //     return false;
                    // }
                    plan['hit_type'] = valhitmark;
                    plan['keep_remark'] = $('#remak_' + temptimeid).val();//备注
                    plan['standard_time'] = $('#standard_time_' + temptimeid).val();//停机时间
                    plan['corepairer'] = $('#add_repairmid_' + temptimeid).val();//合作维护人
                    // console.log(JSON.stringify(plan));
                    planarr.push(plan);

                }
                if ($(this).find('.aui-collapse-header>.rcon>.dc>.sc>input.ivalue').val()) {
                    if ($(this).find('.aui-collapse-header>.rcon>.dc>.sc>input.ivalue').val().length > 0) {
                        // console.log('cccc');
                        var plan = {};
                        plan['timeid'] = parseInt($(this).find('.aui-collapse-header>.rcon>.dc>.sc>input.ivalue').attr('data-timeid'));
                        plan['itemid'] = parseInt($(this).find('.aui-collapse-header>.rcon>.dc>.sc>input.ivalue').attr('data-itemid'));
                        plan['planid'] = parseInt($(this).find('.aui-collapse-header>.rcon>.dc>.sc>input.ivalue').attr('data-planid'));
                        plan['value_type'] = parseInt($(this).find('.aui-collapse-header>.rcon>.dc>.sc>input.ivalue').attr('data-valuetype'));
                        plan['value'] = $(this).find('.aui-collapse-header>.rcon>.dc>.sc>input.ivalue').val();
                        plan['images'] = $(this).find('.aui-collapse-header>.rcon>.dc>.sc>input.ivalue').attr('data-images');
                        plan['sparepartoutid'] = $(this).find('.aui-collapse-header>.rcon>.dc>.sc>input.ivalue').attr('data-spareid');
                        // console.log(JSON.stringify(plan));

                        //命中信息不验证
                        // if (valhitmark != 0 && valhitmark != 1) {
                        //     customToast(lang('6660144'), 2000);
                        //     haserr = true;
                        //     return false;
                        // }

                        plan['hit_type'] = valhitmark;
                        plan['keep_remark'] = $('#remak_' + temptimeid).val();
                        plan['standard_time'] = $('#standard_time_' + temptimeid).val();//停机时间
                        plan['corepairer'] = $('#add_repairmid_' + temptimeid).val();//合作维护人
                        planarr.push(plan);
                        // console.log(JSON.stringify(planarr));

                    }
                }
            });
            if (haserr) {
                return;
            }
            postdata.planlist = planarr;

            // console.log(JSON.stringify(postdata))
            // return false;

            $.ajax({
                url: host + '/tpm/AppPlan/ExecutionPlan',
                data: JSON.stringify(postdata),
                type: 'POST',
                success: function(result) {
                    // console.log(JSON.stringify(result));
                    if (result.ret == 1) {
                        customToast(lang(result.msg), 2000);
                        setTimeout(function() {

                            api.execScript({
                                name: 'root',
                                frameName: 'tpm_jhwh',
                                script: 'reloadMe();'
                            });

                            api.closeFrame();
                            // api.closeWin();
                        }, 1000);
                    } else {
                        customToast(lang(result.msg), 2000);
                    }
                }
            });
        });
    }



    function groupJson(arr) {
        var map = {},
            dest = [];
        for (var i = 0; i < arr.length; i++) {
            var ai = arr[i];

            var time = ai.yeartime;
            // console.log(time);

            if (!map[time]) {
                dest.push({
                    date: time,
                    data: [ai]
                });
                map[time] = ai;
            } else {
                for (var j = 0; j < dest.length; j++) {
                    var dj = dest[j];
                    var time = ai.yeartime;
                    if (dj.date == time) {
                        dj.data.push(ai);
                        break;
                    }
                }
            }

        }
        return dest;

    }




    function showPopup(location) {
        popup.init({
            frameBounces: true, //当前页面是否弹动，（主要针对安卓端）
            location: location, //位置，top(默认：顶部中间),top-left top-right,bottom,bottom-left,bottom-right
            buttons: [{
                image: '',
                text: ' ' + lang('6660053') + '<input type="checkbox" class="aui-switch" checked>',
                value: 'wx' //可选
            }, {
                image: '../image/share/wx-circle.png',
                text: lang('6660054'),
                value: 'wx-circle'
            }],
        }, function(ret) {
            if (ret) {
                document.getElementById("button-index").textContent = ret.buttonIndex;
                document.getElementById("button-value").textContent = ret.buttonValue;
            }
        })
    }


    function takePicture() {
        $(".takephoto").click(function() {

            if (editable === 1) {
                currentrow = $(this).parent().parent().parent().prev().find('.checkjhwh').attr('data-timeid');

                // var imgPath,imgComperssPath,base64img;
                //  camera.takePictureClick({
                //          albumName:''
                //         },function(ret,err){
                //           compress(ret.image.imagePath,function (blob) {
                //             uploadimg(blob);
                //           })
                //  });

                FNPhotograph.open({
                    path: 'fs://savePath',
                    album: true,
                    quality: 'medium'
                }, function(ret) {
                    // alert(JSON.stringify(ret));
                    if (ret.eventType == 'takePhoto') {
                        FNPhotograph.close();
                        compress(ret.imagePath, function(blob) {
                            uploadimg(blob);
                        });
                    } else if (ret.eventType == 'close') {
                        FNPhotograph.close();
                    }
                });

            }
        });

    }

    function uploadimg(base64img) {
        $.ajax({
            url: host + "/tpm/Upload/UploadThumbnail",
            timeout: 30000,
            data: JSON.stringify({
                "image": base64img
            }),
            type: 'POST',
            success: function(data) {
                console.log(JSON.stringify(data));
                api.hideProgress();
                var html = '<div class="imgthumb"> <div class="photo-badge deletephoto" data-value="' + host + '/' + data.data + '">x</div> <div class="imgin"><img src="' + host + '/' + data.data +
                    '" style="width:100%;height:100%;"></div> </div>';
                // console.log(html);
                var imgarrstr = $('.check_' + currentrow).attr('data-images');
                var imgarr = [];
                if (imgarrstr.length > 0) {
                    imgarr = imgarrstr.split(",");
                }
                imgarr.push(host + "/" + data.data);


                var vtype = $('.check_' + currentrow).attr('data-valuetype');
                if (vtype == '1') {
                    $('.check_' + currentrow).parent().parent().next().find('.cphotos').append(html);
                } else {
                    console.log('xxxxxx');
                    console.log(currentrow);
                    $('.check_' + currentrow).parent().parent().parent().parent().next().find('.cphotos').append(html);
                    // console.log(JSON.stringify($('.check_'+currentrow)));
                    // console.log(JSON.stringify($('.check_'+currentrow)));
                    console.log($('.check_' + currentrow).parent().html());
                }
                $('.check_' + currentrow).attr('data-images', imgarr.join(","));
                // $('.check_'+currentrow).parent().next().find('.cphotos').append(html);
                $(".imgin").unbind("click");
                $(".imgin").click(function() {
                    fnOpenLightBoxThisCon(this);
                });
                // console.log($('.check_'+currentrow).attr('data-images'));
                listen_deletephoto();
            },
            error: function(ret) {
                console.log(JSON.stringify(ret));
            }
        })
    }

    function listen_deletephoto() {
        $(".deletephoto").click(function() {
            var val = $(this).attr("data-value");
            console.log(val);
            $(this).parent().remove();
            var imgarrstr = $('.check_' + currentrow).attr('data-images');
            var imgarr = [];
            if (imgarrstr.length > 0) {
                imgarr = imgarrstr.split(",");
                var index = imgarr.indexOf(val);
                if (index > -1) {
                    imgarr.splice(index, 1);
                }
            }
            $('.fault_desc_img').val(imgarr.join(","));

        });
    }

    function lit_zhidaoshu() {
        $(".btn-zhidaoshu").click(function() {

            var _this = $(this);
            var url = _this.attr('data-url');
            // var url = 'http://sigerweb.rc3cr.com/t.mp4';
            var filename = GetFilename(url);
            console.log(host + '/' + url);
            console.log(filename);
            var fileurl = url;
            if(url.indexOf('http') == -1){
              var filehost = host.indexOf('/apis')!=-1?host.slice(0,-4):host;
            //   fileurl = filehost + '/' + url;
            fileurl = host +'/'+url;

            }

            if (filename) {
                loading(lang('6660118'));
                var downloadManager = api.require('downloadManager');
                downloadManager.enqueue({
                    url: fileurl,
                    // url: url,
                    savePath: 'fs://' + filename,
                    cache: true,
                    allowResume: true,
                    title: lang('6660056'),
                    networkTypes: 'all'
                }, function(ret, err) {

                    downloadManager.openManagerView({
                        title: lang('6660119')
                    }, function(ret, err) {
                        if (ret) {
                            downloadManager.openDownloadedFile({
                                id: ret.id
                            }, function(ret, err) {});
                        }
                    });

                    if (ret) {
                        api.hideProgress();

                        setTimeout(function() {
                            downloadManager.openDownloadedFile({
                                id: ret.id
                            }, function(ret, err) {});
                        }, 500);

                    }
                });

            } else {
                customToast(lang('6660120'), 2000);
            }

        });
    }
    $(".btn_qrcode").click(function() {
        console.log(machineid);
        console.log(wostatus);
        var obj = {
            "machineid": machineid,
            "wostatus": wostatus
        };

        setTimeout(function() {
            api.closeWin({
                name: 'tpm_jhwhdetail'
            });
        }, 500);

        api.execScript({
            name: 'root',
            script: 'fnOpenSimpleQRCode("tpm_jhwhdetail","' + lang('6660055') + '","' + encodeURIComponent(JSON.stringify(obj)) + '");'
        });
    });
</script>

</html>
