1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153 |
- <!DOCTYPE html>
- <html lang="zh-cn">
- <head>
- <meta charset="UTF-8">
- <meta name="format-detection" content="telephone=no" />
- <meta name="format-detection" content="email=no" />
- <title>mes</title>
- <link rel="stylesheet" href="../css/reset.css">
- <link rel="stylesheet" href="../css/style.css">
- <script src="../script/flexible.js"></script>
- <style>
- body{
- overflow-x: hidden;
- overflow-y: auto;
- }
- .taskXQ{
- display: none;
- padding-top: .23rem;
- }
- .taskXQ>div{
- margin-bottom: .1rem;
- background-color: #fff;
- padding: .3rem .3rem ;
- }
- .taskXQ>.task_taskCon{
- padding: .3rem .3rem .1rem;
- }
- .taskXQ>div h3{
- font-size: .4rem;
- color: #818181;
- font-weight: normal;
- margin-bottom: .1rem;
- }
- .taskXQ pre{
- display: block;
- width: 100%;
- }
- .task_taskCon p {
- height: .5rem;
- margin-bottom: .16rem;
- color: #818181;
- font-size: .41rem;
- }
- .task_taskCon p:nth-of-type(n+2){
- margin-bottom: .1rem;
- }
- .task_name{
- font-size: .5rem;
- }
- .task_dw,.task_people,.task_duty{
- color: #818181;
- }
- #delay{
- font-size: .31rem;
- }
- .delay{
- background-color: #f26522;
- padding: .05rem .1rem;
- color: #fff;
- border-radius: .06rem;
- }
- .icon_1{
- width: .3rem;
- height: .3rem;
- background: url("../image/task_icon_1.png") no-repeat 100% 110%/100%;
- margin-right: .1rem;
- }
- .icon_2{
- width: .3rem;
- height: .3rem;
- background: url("../image/task_icon_2.png") no-repeat 50% 140%/80%;
- margin-right: .1rem;
- }
- .task_dbqk {
- display: inline-block;
- font-size: .3rem;
- padding: 0 .1rem;
- border-radius: .03rem;
- color: #fff;
- margin-left: .26rem;
- white-space: nowrap;
- vertical-align: text-top;
- }
- .task_dbqk1{
- background-color: #f39700;
- }
- .task_dbqk2{
- background-color: #ff0000;
- }
- .task_dbqk3{
- background-color: #bbbc5f;
- }
- .task_dbqk4{
- background-color: #e60012;
- }
- .task_dbqk5{
- background-color: #cacbbb;
- }
- .task_pssj,
- .task_wcsj {
- display: inline-block;
- height: .4rem;
- line-height: .4rem;
- font-size: .3rem;
- padding: 0 .18rem;
- border-radius: .03rem;
- }
- .task_pssj {
- border: 1px solid #3aca74;
- color: #3aca74;
- margin-right: .2rem;
- }
- .task_wcsj {
- border: 1px solid #fd9b53;
- color: #fd9b53;
- }
- .gz{
- display: inline-block;
- width: .66rem;
- height: .66rem;
- background-image: url("../image/gz.png");
- background-size: 100%;
- margin-left: .5rem;
- margin-bottom: -.1rem;
- }
- .gz-active{
- display: inline-block;
- width: .66rem;
- height: .66rem;
- background-image: url("../image/gz-active.png");
- background-size: 100%;
- margin-left: .5rem;
- margin-bottom: -.1rem;
- }
- .task_text{
- font-size: .4rem;
- color: #818181;
- }
- .taskXQ>div.xcms{
- width: calc(100% - .66rem);
- background-color: #FAFAFA;
- border-radius: .1rem;
- border: 1px solid #efefef;
- margin: 0 auto;
- }
- .taskXQ>div.imgDiv{
- padding: .3rem .3rem .6rem;
- }
- .imgDiv div{
- width: 23.5%;
- height: 2rem;
- float: left;
- margin-right: 2%;
- border: 2px solid rgba(0,0,0,0);
- }
- .imgDiv div.active{
- border: 2px solid #00db00;
- }
- .imgDiv div:nth-of-type(4n){
- margin-right: 0;
- }
- .imgDiv div img{
- display: inline-block;
- width: 100%;
- height: 100%;
- border-radius: .1rem;
- }
- .imgDiv p{
- text-align: center;
- font-size: .3rem;
- color: #818181;
- }
- .startBtn{
- width: 100%;
- height: 1.06rem;
- line-height: 1.06rem;
- font-size: .42rem;
- text-align: center;
- color: #fff;
- background-color: #22ad38;
- border-radius: .1rem;
- margin-bottom: .3rem;
- }
- .removeBtn{
- width: 100%;
- height: 1.06rem;
- line-height: 1.06rem;
- font-size: .42rem;
- text-align: center;
- color: #fff;
- background-color: #f7941d;
- border-radius: .1rem;
- }
- .zzPopups{
- position: fixed;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- background-color: rgba(0,0,0,0.8);
- z-index: 99;
- display: none;
- }
- .zzPopups div{
- height: 80%;
- position: absolute;
- top: 50%;
- left: 10%;
- right: 10%;
- -webkit-transform: translateY(-50%);
- }
- .zzPopups div img{
- background-color: #fff;
- }
- .openBtn{
- width: 100%;
- height: 1.06rem;
- line-height: 1.06rem;
- font-size: .42rem;
- text-align: center;
- color: #fff;
- background-color: #22ad38;
- border-radius: .1rem;
- margin-bottom: .3rem;
- }
- .taskXQ>.hr{
- width: calc(100% - .66rem);
- height: 1px;
- background-color: #efefef;
- padding: 0;
- margin: 0 auto;
- }
- .remind1Warp,.remind2Warp,.remind3Warp{
- position: fixed;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- background-color: rgba(0,0,0,0.2);
- z-index: 99;
- }
- .remindDiv1,.remindDiv2,.remindDiv3{
- width: calc(100% - 2rem);
- height: 50%;
- background-color: #fff;
- position: absolute;
- left: 1rem;
- top: 25%;
- border-radius: .3rem;
- overflow: hidden;
- }
- .remindImg{
- width: 100%;
- height: 3.1rem;
- }
- .remindImg img{
- display: inline-block;
- width: 100%;
- height: 100%;
- }
- .remindText{
- font-size: .5rem;
- color: #3d3d3d;
- text-align: center;
- margin: .5rem 0;
- }
- .remindContent{
- font-size: .4rem;
- color: #818181;
- text-align: center;
- margin-bottom: .3rem;
- }
- .sureBtn,.clBtn{
- width: 70%;
- height: 1rem;
- line-height: 1rem;
- font-size: .42rem;
- text-align: center;
- color: #fff;
- background-color: #22ad38;
- border-radius: .1rem;
- margin:0 auto .3rem;
- }
- .hid{
- display: none;
- }
- </style>
- </head>
- <body>
- <div class="taskXQ">
- <div class="task_taskCon flex-con">
- <p><span class="task_name">{{name}}</span><span class="task_dbqk {{class}}">{{status}}</span></p>
- <p><i class="icon_1"></i>{{tasktype}}内容:<span class="task_duty">{{duty}}</span></p>
- <p><i class="icon_2"></i>地址:<span class="task_dw">{{enterprise}}</span></p>
- <p>变电柜:<span class="task_dw">{{bdgname}}</span></p>
- <p class="clearFix">审核人:<span class="task_dw">{{shren}}</span><span class="right delay {{isUser}}" id="delay">是否要延期</span></p>
- <p><span class="taskTypeName">检修人员:</span><span class="task_dw">{{xjren}}</span></p>
- <p>协助人员:<span class="task_dw">{{xzren}}</span></p>
- <p><span class="task_pssj">申请日期:{{pssj}}</span><!--<span class="task_wcsj">检修日期:{{wcsj}}</span>--></p>
- <p><span class="task_pssj">计划开始:{{jhks}}</span><span class="task_wcsj" id="upload">计划结束:{{jhjs}}</span></p>
- </div>
- <div class="hr"></div>
- <div class="imgDiv clearFix hid">
- <div rel="1"><img src="../image/moren.jpg" alt=""><p>锁具1</p></div>
- <div rel="2"><img src="../image/moren.jpg" alt=""><p>锁具2</p></div>
- <div rel="3"><img src="../image/moren.jpg" alt=""><p>锁具3</p></div>
- <div rel="4"><img src="../image/moren.jpg" alt=""><p>锁具4</p></div>
- </div>
- <div>
- <div class="openBtn " id="dhBtn">导航</div>
- <div class="openBtn " id="yddBtn">已到达目的地</div>
- <div class="openBtn hid" id="codeBtn">扫描二维码开锁</div>
- <div class="openBtn hid" id="GPRSBtn">输入编号开锁</div>
- </div>
- </div>
- <div class="zzPopups">
- <div></div>
- </div>
- <div class="remind1Warp hid">
- <div class="remindDiv1">
- <div class="remindImg"><img src="../image/openKey1.jpg" alt=""></div>
- <p class="remindText">开锁成功</p>
- <p class="remindContent">锁门编号:<span class="keyId"></span> 与检修相符</p>
- <div class="sureBtn">确认开门</div>
- </div>
- </div>
- <div class="remind2Warp hid">
- <div class="remindDiv2">
- <div class="remindImg"><img src="../image/openKey2.jpg" alt=""></div>
- <p class="remindText">开锁失败</p>
- <p class="remindContent">锁门编号:<span class="keyId"></span> 暂未打开</p>
- <div class="clBtn">请重试</div>
- </div>
- </div>
- <div class="remind3Warp hid">
- <div class="remindDiv3">
- <div class="remindImg"><img src="../image/openKey2.jpg" alt=""></div>
- <p class="remindText">开锁失败</p>
- <p class="remindContent">当前变电柜与检修不相符</p>
- <div class="clBtn">变电柜错误</div>
- </div>
- </div>
- <a href="" id="locationA"></a>
- <a href="" id="locationB"></a>
- <script src="../script/publicData.js"></script>
- <script src="../script/jqueryMin.js"></script>
- <script type="text/javascript" src="../script/api.js"></script>
- <script src="../script/test.js"></script>
- <!--<script src="../script/CRC.js"></script>-->
- <script>
- var ii=0;
- function showImg(that) {
- if(ii!=0) {
- api.toast({
- msg: '正在加载图片,请稍等...',
- duration: 2000,
- location: 'bottom'
- });
- return;
- }
- api.imageCache({
- url: that.getAttribute("src")
- }, function(ret, err) {
- if(ret.status){
- var url = ret.url;
- $(".zzPopups div").append("<img src='"+url+"'>");
- $(".zzPopups").css("display","block");
- ii++;
- }else {
- api.toast({
- msg: '加载图片失败',
- duration: 2000,
- location: 'bottom'
- });
- ii=0;
- }
- });
- }
- apiready = function() {
- api.showProgress({
- title: '努力加载中...',
- text: '请稍等...',
- modal: false
- });
- var dialogBox = api.require('dialogBox');
- var bluetooth = api.require('bluetooth');
- var ble = api.require('ble');
- var ulModel=$(".taskXQ").html(),str="";
- var task=$api.getStorage("taskXQ");
- var winWidth= api.winWidth/3-10;
- var ad=["1","3"];
- var BLESUUID="";
- var BLEPUUID="";
- var BLECUUID="";
- var keynum="1";
- var mac_address="";
- var bdg_code="";
- var key_num="";
- var ser_mac_address="";
- var ser_bdg_code="";
- var codeData={};
- var bleTime=null;
- var sid=0,returnNum=0,bleNum=0;
- var times=null,delay=null;
- var postData={
- id:task.taskID
- }
- $(".zzPopups").click(function () {
- $(".zzPopups").css("display","none");
- $(".zzPopups div").html(" ");
- ii=0;
- })
- api.ajax({
- url: pageUrl+"/index/task/show",
- method: 'get',
- timeout: 30,
- dataType: 'text',
- returnAll: false,
- data: {
- values: postData
- }
- }, function (data, err) {
- var data=JSON.parse(data)
- $api.setStorage("taskContent",data.data);
- // alert(JSON.stringify(data))
- var user="",dep="",dataImg=[],dataFile=[],str2="",shreny="",xzreny="";
- switch (data['data']['task_type']+""){
- case "0":
- str=ulModel.replace("{{status}}","常规").replace("{{class}}","task_dbqk1");
- break;
- case "1":
- str=ulModel.replace("{{status}}","紧急").replace("{{class}}","task_dbqk2");
- break;
- case "2":
- str=ulModel.replace("{{status}}","紧急").replace("{{class}}","task_dbqk2");
- break;
- case "3":
- str=ulModel.replace("{{status}}","紧急").replace("{{class}}","task_dbqk2");
- break;
- case "4":
- str=ulModel.replace("{{status}}","常规").replace("{{class}}","task_dbqk2");
- break;
- }
- if(data['data']['aduit'].length){
- for(var i in data['data']['aduit']){
- if(i==data['data']['aduit'].length-1){
- shreny+=data['data']['aduit'][i]['name']
- }else {
- shreny+=data['data']['aduit'][i]['name']+"、"
- }
- }
- }
- if(data['data']['helper'].length){
- for(var j in data['data']['helper']){
- if(j==data['data']['helper'].length-1){
- xzreny+=data['data']['helper'][j]['name']
- }else {
- xzreny+=data['data']['helper'][j]['name']+"、"
- }
- }
- }
- str=str.replace("{{name}}",data['data']['title']).replace("{{bdgname}}",data['data']['bdg']['title']).replace("{{duty}}",data['data']['remark']).replace("{{pssj}}",data['data']['start_time']?data['data']['start_time'].slice(0,16):"").replace("{{wcsj}}",data['data']['end_at']?data['data']['end_at'].slice(0,16):"").replace("{{jhks}}",data['data']['created_at']?data['data']['created_at'].slice(0,16):"未设定").replace("{{jhjs}}",data['data']['end_time']?data['data']['end_time'].slice(0,16):"未设定")
- .replace("{{enterprise}}",data['data']['address']).replace("{{task_content}}",data["data"]['content']||"无").replace("{{xjren}}",data["data"]['user']['name']).replace("{{shren}}",shreny!=""?shreny:"无").replace("{{xzren}}",xzreny!=""?xzreny:"无").replace("{{isUser}}",$api.getStorage("user").id==data['data']['user']['id']?"":"hid").replace("{{tasktype}}",data['data']['type']=="2"?"检修":"巡查");
- var gzjlModel="<div><img src='{{img}}' alt=''></div>",str2="",imgStr="",fileStr="";
- if(data['data']['resultImg']){
- for(var num in data['data']['resultImg']){
- dataImg.push(data['data']['resultImg'][num]['img'])
- }
- }
- if(dataImg&&dataImg.length) {
- for (var imgIndex in dataImg) {
- str2=gzjlModel.replace("{{img}}",pageImg+dataImg[imgIndex]||"");
- }
- }
- imgStr="";
- dataImg=[];
- ser_mac_address=data['data']['bdg']['mac_address'];
- ser_bdg_code=data['data']['bdg']['code'];
- if(api.systemType=="android"){
- $("#locationA").prop("href","bdapp://map/marker?location="+$api.getStorage("taskXQ").lat+","+$api.getStorage("taskXQ").lon+"&title="+data['data']['bdg']['title']+"&content="+data['data']['bdg']['title']+"&traffic=on");
- }else if(api.systemType=="ios"){
- $("#locationA").prop("href","baidumap://map/geocoder?location="+$api.getStorage("taskXQ").lat+","+$api.getStorage("taskXQ").lon+"&coord_type=bd09ll&src=webapp.rgeo.卡瑞网络科技有限公司.云瞳");
- }
- // $("#locationB").prop("href","http://uri.amap.com/marker?position="+$api.getStorage("taskXQ").lon+","+$api.getStorage("taskXQ").lat+"&name="+data['data']['title']+"&src=云瞳&coordinate=wgs84&callnative=1");
- $("#locationB").prop("href","http://api.map.baidu.com/geocoder?location="+$api.getStorage("taskXQ").lon+","+$api.getStorage("taskXQ").lat+"&coord_type=bd09ll&output=html&src=云瞳");
- str=str.replace("{{img}}",str2);
- api.hideProgress();
- $(".taskXQ").html(str).css("display","block");
- if(task.taskType=="patrol"){
- $(".taskTypeName").text("巡查人员:");
- }
- for(var p in data['data']['helper']){
- if($api.getStorage("user").id==data['data']['helper'][p]['id']&&$api.getStorage("user").id!=data['data']['user']['id']){
- $("#yddBtn").css("display","none");
- }
- }
- $("#dhBtn").click(function () {
- // api.openWin({
- // name: "Map",
- // url: './Map.html',
- // animation: {
- // type: 'push',
- // subType: 'from_right',
- // duration: 300
- // },
- // delay:300
- // });
- api.actionSheet({
- title: '选择地图',
- cancelTitle: '取消',
- buttons: ["百度地图"/*,"在线地图"*/]
- }, function (ret, err) {
- if(ret.buttonIndex==1){
- $("#locationA")[0].click();
- }
- // else if(ret.buttonIndex==2){
- // $("#locationB")[0].click();
- // }
- });
- })
- $("#yddBtn").click(function () {
- if(new Date(data['data']['created_at']).getTime()>new Date().getTime()){
- api.toast({
- msg: '还未到开始时间',
- duration: 2000,
- location: 'bottom'
- });
- }else if(new Date(data['data']['end_time']).getTime()<new Date().getTime()){
- api.toast({
- msg: '此任务已超时',
- duration: 2000,
- location: 'bottom'
- });
- }else {
- $("#dhBtn").addClass("hid");
- $("#yddBtn").addClass("hid");
- $("#codeBtn").removeClass("hid");
- $("#GPRSBtn").removeClass("hid");
- // $(".imgDiv div").eq(0).addClass("active")
- }
- })
- $("#delay").click(function () {
- var win= JSON.parse(localStorage.getItem("window"))
- api.openFrame({
- name: 'delayTime',
- url: './delayTime.html',
- bgColor : 'rgba(0,0,0,0)',
- rect: {
- x: 0,
- // y: win.headerH,
- y: 0,
- w: "auto",
- // h: win.mainH
- h: api.winHeight
- },
- pageParam: {val: task.taskID,time:data['data']['end_time']},
- bounces: false
- });
- })
- api.addEventListener({
- name: 'uploadTime'
- }, function (ret, err) {
- data['data']['end_time']=ret.value.time;
- $("#upload").text("计划结束:"+ret.value.time)
- });
- api.addEventListener({
- name: 'showCode'
- }, function (ret, err) {
- $("#dhBtn").addClass("hid");
- $("#yddBtn").addClass("hid");
- $("#codeBtn").removeClass("hid");
- $("#GPRSBtn").removeClass("hid");
- $(".imgDiv div").eq(0).addClass("active")
- });
- // if($api.getStorage("isTwo")=="true"){
- // $("#dhBtn").addClass("hid");
- // $("#yddBtn").addClass("hid");
- // $("#codeBtn").removeClass("hid");
- // $("#GPRSBtn").removeClass("hid");
- // $(".imgDiv div").eq(0).addClass("active")
- // $api.setStorage("isTwo",false)
- // }
- $("#codeBtn").click(function () {
- ble.initManager(function(ret, err){
- if(ret.state == "poweredOn"){//蓝牙4.0设备连接状态,设备开启状态 -- 可用状态
- //开始扫啊扫
- api.openWin({
- name: 'QRCode',
- url: './QRCode.html',
- pageParam: {
- name: 'QRData'
- }
- });
- api.addEventListener({
- name: 'QRData'
- }, function (ret, err) {
- var ret=ret.value.data;
- if (ret) {
- if(ret.eventType=="success"){
- api.showProgress({
- title: '正在开锁中...',
- text: '请稍等',
- modal: false
- });
- try {
- bdg_code=JSON.parse(ret.content)['code'];
- key_num=JSON.parse(ret.content)['lock_id'];
- mac_address=JSON.parse(ret.content)['mac'];
- }catch (e){
- api.hideProgress();
- alert("二维码识别失败");
- writeFS("二维码识别失败 "+new Date().toString()+"\r\n")
- return;
- }
- if(ser_bdg_code.indexOf(bdg_code)!=-1){
- writeFS("该主板与任务相关 "+new Date().toString()+"\r\n")
- ble_scan();
- }else {
- writeFS("该主板与任务不相关 "+new Date().toString()+"\r\n")
- api.hideProgress();
- $(".remind3Warp").removeClass("hid");
- $(".clBtn").click(function () {
- $(".remind3Warp").addClass("hid");
- })
- }
- }
- }
- });
- }else if(ret.state == "poweredOff"){
- api.alert({msg:'请打开蓝牙'});
- }else {
- api.toast({
- msg: '蓝牙出现未知错误',
- duration: 2000,
- location: 'bottom'
- });
- }
- });
- })
- /*GPRS 通信按钮*/
- $("#GPRSBtn").click(function () {
- api.prompt({
- title:"提示",
- msg:"请输入变电柜编码",
- buttons: ['取消', '确定']
- }, function(ret, err) {
- var index = ret.buttonIndex;
- if(index==2){
- doGPRS(ret.text);
- }
- });
- })
- });
- function doGPRS(val) {
- if(val.toLocaleUpperCase()!=ser_bdg_code.toLocaleUpperCase()){
- api.toast({
- msg: '任务与变电柜不相符',
- duration: 2000,
- location: 'bottom'
- });
- return;
- }
- var arr=["锁1","锁2","锁3","锁4"];
- api.actionSheet({
- title: '选择要打开的锁',
- buttons: arr
- }, function (ret, err) {
- if(ret.buttonIndex>arr.length) return;
- api.showProgress({
- title: '正在开锁中...',
- text: '请稍等...',
- modal: false
- });
- var postData={
- bdg_id:ser_bdg_code.toLocaleUpperCase(),
- lock_id:"0"+ret.buttonIndex.toString(),
- imei: api.deviceId
- }
- // clientServer(ret.buttonIndex);
- console.log(JSON.stringify(postData))
- $api.setStorage("selKey",ret.buttonIndex)
- api.ajax({
- url: pageUrl+"/index/socket/index",
- method: 'get',
- timeout: 30,
- dataType: 'text',
- returnAll: false,
- data: {
- values: postData
- }
- }, function (data, err) {
- var data=JSON.parse(data);
- console.log(JSON.stringify(data))
- if(data){
- if(data.code!=1) {
- // var socketManager = api.require('socketManager');
- // clSocket(sid,socketManager)
- api.hideProgress();
- api.toast({
- msg: data.info,
- duration: 2000,
- location: 'bottom'
- });
- }else {
- // api.hideProgress();
- // if(data.code==1){
- // $(".remind1Warp .keyId").text("锁"+ret.buttonIndex);
- // $(".remind1Warp").removeClass("hid");
- // $(".sureBtn").click(function () {
- // $(".remind1Warp").addClass("hid");
- // var jsfun1 = 'toFrame(7);';
- // api.execScript({
- // name: 'root',
- // script: jsfun1
- // });
- // $api.setStorage("isTwo",true)
- // })
- // }
- }
- }else {
- api.hideProgress();
- }
- api.execScript({
- name: 'root',
- script: 'totalTime(0);'
- });
- });
- });
- }
- api.addEventListener({
- name: 'isGetre'
- }, function (ret, err) {
- var data=ret.value.data;
- api.hideProgress();
- if(data[data.length-3]=="1"){
- $(".remind1Warp .keyId").text("锁"+$api.getStorage("selKey"));
- $(".remind1Warp").removeClass("hid");
- $(".sureBtn").click(function () {
- $(".remind1Warp").addClass("hid");
- $api.setStorage("isTwo",true);
- $api.setStorage("toList","2");
- var jsfun1 = 'toFrame(7);';
- api.execScript({
- name: 'root',
- script: jsfun1
- });
- })
- }else if(data[data.length-3]=="0"){
- $(".remind2Warp .keyId").text("锁"+$api.getStorage("selKey"));
- $(".remind2Warp").removeClass("hid");
- $(".clBtn").click(function () {
- $(".remind2Warp").addClass("hid");
- })
- }else if(data[data.length-3]=="2"){
- api.toast({
- msg: '连接超时',
- duration: 2000,
- location: 'bottom'
- });
- }
- });
- function toBig(val,num) {
- var arr=[],thisArr=val.split("");
- if(num){
- for(var i=0;i<thisArr.length;i++){
- arr.unshift(+thisArr[i]);
- }
- }else {
- for(var i=0;i<thisArr.length;i++){
- if(i%2){
- arr.unshift(thisArr[i-1]+thisArr[i]);
- }
- }
- }
- return arr.join("");
- }
- function ble_scan() {
- if(!bleTime){
- startTime();
- }
- var has=false;
- ble.scan({
- serviceUUIDs:[]//如果知道serviceUUID的话就直接 填上去 不知道的 蓝牙app 可以告诉你
- }, function( ret ){
- if( ret.status ){
- ble.getPeripheral(function(ret) {
- if (ret.peripherals.length>0){
- writeFS("正在搜索蓝牙 "+new Date().toString()+"\r\n")
- for(var i=0;i<ret.peripherals.length;i++){
- if(ret.peripherals[i]['uuid']==ser_mac_address){
- has=true;
- clearTimeout(bleTime)
- writeFS("正在连接蓝牙 "+new Date().toString()+"\r\n")
- ble_connect();
- }
- }
- if(!has){
- ble_scan();
- }
- }else {
- ble_scan();
- }
- });
- }
- });
- };
- function startTime() {
- if(bleNum==8){
- clearTimeout(bleTime)
- writeFS("扫描蓝牙失败,正使用GPRS开锁("+bdg_code+") "+new Date().toString()+"\r\n")
- api.toast({
- msg: '扫描蓝牙失败,正使用GPRS开锁',
- duration: 2000,
- location: 'bottom'
- });
- toGPRS(bdg_code,key_num)
- }
- bleTime=setTimeout(function () {
- bleNum++;
- startTime();
- },1000)
- }
- function ble_connect() {
- ble.isConnected({
- peripheralUUID: ser_mac_address
- }, function(ret) {
- BLEPUUID=ser_mac_address;
- $api.setStorage("BLEPUUID",BLEPUUID)
- if (ret.status) {
- // $(".imgDiv").removeClass("hid");
- // $(".imgDiv div").click(function () {
- // if($("#codeBtn").hasClass("hid")) return;
- // $(this).addClass("active").siblings().removeClass("active");
- // keynum=$(this).attr("rel");
- // ble_discoverService();
- // })
- clearTimeout(bleTime);
- if(BLEPUUID==mac_address){
- keynum=key_num;
- ble_discoverService();
- writeFS("蓝牙已连接("+bdg_code+") "+new Date().toString()+"\r\n")
- }else {
- writeFS("蓝牙已连接某主板,正在切换连接 "+new Date().toString()+"\r\n")
- disconnect(function () {
- ble_scan();
- });
- }
- }else {
- ble.connect({
- peripheralUUID: ser_mac_address
- },function(ret1 , err1){
- if(ret1.status) {
- // alert(JSON.stringify(ret1)+",已连接"+2)
- // $(".imgDiv").removeClass("hid");
- // api.toast({
- // msg: '请选择要打开的锁',
- // duration: 2000,
- // location: 'bottom'
- // });
- // $(".imgDiv div").click(function () {
- // if($("#codeBtn").hasClass("hid")) return;
- // $(this).addClass("active").siblings().removeClass("active");
- // keynum=$(this).attr("rel");
- // ble_discoverService();
- // })
- clearTimeout(bleTime);
- writeFS("蓝牙初始连接成功("+bdg_code+") "+new Date().toString()+"\r\n")
- keynum=key_num;
- ble_discoverService();
- }else {
- clearTimeout(bleTime);
- writeFS("没有搜索到任务蓝牙 "+new Date().toString()+"\r\n");
- api.hideProgress();
- api.toast({
- msg: '没有搜索到任务蓝牙',
- duration: 2000,
- location: 'bottom'
- });
- }
- });
- }
- });
- }
- function ble_discoverService() {
- ble.discoverService({
- peripheralUUID: BLEPUUID
- },function(ret2){
- if(ret2.status) {
- // alert(JSON.stringify(ret2)+",获取service");
- // BLESUUID=ret2['services'][3];
- BLESUUID="0000ffe5-0000-1000-8000-00805f9b34fb";
- ble.discoverCharacteristics({
- peripheralUUID: BLEPUUID,
- serviceUUID: BLESUUID
- },function(ret3 , err3){
- if(ret3.status) {
- // alert(JSON.stringify(ret3)+",获取char");
- //串口特征值 0000ffe4-0000-1000-8000-00805f9b34fb
- // BLECUUID=ret3['characteristics'][0]['uuid'];
- BLECUUID="0000ffe9-0000-1000-8000-00805f9b34fb";
- // alert("52434d5300010006"+"04"+bdg_code+"0"+keynum+"0000")
- writeFS("向主板蓝牙发送开锁数据("+bdg_code+") "+new Date().toString()+"\r\n")
- ble.writeValueForCharacteristic({
- peripheralUUID: BLEPUUID,
- serviceUUID: BLESUUID,
- characteristicUUID: BLECUUID,
- value:"52434d5300010006"+"04"+bdg_code+"0"+keynum+"0000",//字符串
- // value:"52434d5300010006"+"04"+"6ec81c96"+"0"+keynum+"0000",//字符串
- writeType:"withoutResponse"
- },function(ret4 , err4){
- if(ret4.status){
- writeFS("向主板蓝牙发送数据成功("+bdg_code+") "+new Date().toString()+"\r\n")
- ble.setNotify({
- peripheralUUID: BLEPUUID,
- serviceUUID: "0000ffe0-0000-1000-8000-00805f9b34fb",
- characteristicUUID: "0000ffe4-0000-1000-8000-00805f9b34fb"
- }, function(ret) {
- // alert(JSON.stringify(ret))
- writeFS("接收主板蓝牙数据成功("+bdg_code+") "+new Date().toString()+"\r\n")
- api.hideProgress();
- if (ret) {
- var bl=true;
- // alert(JSON.stringify(ret))
- if(ret.characteristic.value.slice(28,30)!="01"){
- bl=false;
- }else {
- if(keynum!=ret.characteristic.value.slice(27,28)){
- bl=false;
- }else {
- bl=true;
- }
- }
- if(bl){
- $(".remind1Warp .keyId").text("锁"+keynum);
- $(".remind1Warp").removeClass("hid");
- }else {
- $(".remind2Warp .keyId").text("锁"+keynum);
- $(".remind2Warp").removeClass("hid");
- }
- // disconnect();
- $(".sureBtn").click(function () {
- $(".remind1Warp").addClass("hid");
- // disconnect();
- var jsfun1 = 'toFrame(7);';
- api.execScript({
- name: 'root',
- script: jsfun1
- });
- // setTimeout(function () {
- // api.closeFrame({
- // name: 'taskXQ'
- // });
- // },300)
- $api.setStorage("isTwo",true)
- })
- $(".clBtn").click(function () {
- $(".remind2Warp").addClass("hid");
- })
- }
- });
- }else {
- writeFS("向主板蓝牙发送数据失败("+bdg_code+") "+new Date().toString()+"\r\n")
- api.toast({
- msg: '蓝牙异常,正使用GPRS开锁',
- duration: 2000,
- location: 'bottom'
- });
- toGPRS(bdg_code,keynum)
- }
- });
- }
- });
- }
- });
- }
- function getTime(time,bl) {
- var oldTime=new Date(time*1000),str="";
- var year=oldTime.getFullYear();
- var month=oldTime.getMonth()+1;
- var day=oldTime.getDate();
- var hours=oldTime.getHours();
- var minutes=oldTime.getMinutes();
- if(bl){
- str=year+"-"+checkTime(month)+"-"+checkTime(day)+" "+checkTime(hours)+":"+checkTime(minutes);
- }else {
- str=year+"-"+checkTime(month)+"-"+checkTime(day);
- }
- return str;
- }
- function checkTime(val) {
- var val=val;
- if((val+"").length==1){
- val="0"+val;
- }
- return val
- }
- function popupsBox(val,type) {
- dialogBox.alert({
- texts: {
- title: '确认提示',
- content: val,
- leftBtnTitle: '取消',
- rightBtnTitle: '确认'
- },
- styles: {
- bg: '#fff',
- w: 300,
- title: {
- marginT: 20,
- icon: 'widget://res/gou.png',
- iconSize: 40,
- titleSize: 13,
- titleColor: '#000'
- },
- content: {
- color: '#000',
- size: 16
- },
- left: {
- marginB: 0,
- marginL: 0,
- w: 150,
- h: 60,
- corner: 2,
- bg: '#f9f9f9',
- color: '#818181',
- size: 12
- },
- right: {
- marginB: 0,
- marginL: 0,
- w: 150,
- h:60,
- corner: 2,
- bg: '#51c4d4',
- color: '#fff',
- size: 12
- }
- }
- }, function(ret) {
- if (ret.eventType == 'right') {
- var taskData={
- task_id:task.taskID-0,
- task_status:type
- }
- dialogBox.close({
- dialogName: 'alert'
- });
- }else if (ret.eventType == 'left') {
- dialogBox.close({
- dialogName: 'alert'
- });
- }
- });
- }
- }
- function toGPRS(id,index) {
- var postData={
- bdg_id:id.toLocaleUpperCase(),
- lock_id:"0"+index.toString(),
- imei: api.deviceId
- }
- // clientServer(ret.buttonIndex);
- $api.setStorage("selKey",index);
- api.ajax({
- url: pageUrl+"/index/socket/index",
- method: 'get',
- timeout: 30,
- dataType: 'text',
- returnAll: false,
- data: {
- values: postData
- }
- }, function (data, err) {
- var data=JSON.parse(data);
- if(data){
- if(data.code!=1) {
- api.hideProgress();
- api.toast({
- msg: data.info,
- duration: 2000,
- location: 'bottom'
- });
- }
- }else {
- api.hideProgress();
- }
- api.execScript({
- name: 'root',
- script: 'totalTime(0);'
- });
- });
- }
- function disconnect(fn) {
- var ble = api.require('ble'),
- id=$api.getStorage("BLEPUUID");
- api.hideProgress();
- ble.disconnect({
- peripheralUUID: id
- },function( ret ){
- if(ret.status) {
- fn();
- }
- });
- }
- function writeFS(val) {
- var fs = api.require('fs');
- var url='fs://log.txt';
- var existRet = fs.existSync({
- path: url
- });
- if (existRet.exist) {
- api.writeFile({
- path: url,
- data: val,
- append:true
- }, function(ret, err) {})
- } else {
- var createRet = fs.createFileSync({
- path: url
- });
- if (createRet.status) {
- api.writeFile({
- path: url,
- data: val,
- append:true
- }, function(ret, err) {});
- }
- }
- }
- </script>
- </body>
- </html>
|