taskXQ.html 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. <!DOCTYPE html>
  2. <html lang="zh-cn">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="format-detection" content="telephone=no" />
  6. <meta name="format-detection" content="email=no" />
  7. <title>mes</title>
  8. <link rel="stylesheet" href="../css/reset.css">
  9. <link rel="stylesheet" href="../css/style.css">
  10. <script src="../script/flexible.js"></script>
  11. <style>
  12. body{
  13. overflow-x: hidden;
  14. overflow-y: auto;
  15. }
  16. .taskXQ{
  17. display: none;
  18. padding-top: .23rem;
  19. }
  20. .taskXQ>div{
  21. margin-bottom: .1rem;
  22. background-color: #fff;
  23. padding: .3rem .3rem ;
  24. }
  25. .taskXQ>.task_taskCon{
  26. padding: .3rem .3rem .1rem;
  27. }
  28. .taskXQ>div h3{
  29. font-size: .4rem;
  30. color: #818181;
  31. font-weight: normal;
  32. margin-bottom: .1rem;
  33. }
  34. .taskXQ pre{
  35. display: block;
  36. width: 100%;
  37. }
  38. .task_taskCon p {
  39. height: .5rem;
  40. margin-bottom: .16rem;
  41. color: #818181;
  42. font-size: .41rem;
  43. }
  44. .task_taskCon p:nth-of-type(n+2){
  45. margin-bottom: .1rem;
  46. }
  47. .task_name{
  48. font-size: .5rem;
  49. }
  50. .task_dw,.task_people,.task_duty{
  51. color: #818181;
  52. }
  53. #delay{
  54. font-size: .31rem;
  55. }
  56. .delay{
  57. background-color: #f26522;
  58. padding: .05rem .1rem;
  59. color: #fff;
  60. border-radius: .06rem;
  61. }
  62. .icon_1{
  63. width: .3rem;
  64. height: .3rem;
  65. background: url("../image/task_icon_1.png") no-repeat 100% 110%/100%;
  66. margin-right: .1rem;
  67. }
  68. .icon_2{
  69. width: .3rem;
  70. height: .3rem;
  71. background: url("../image/task_icon_2.png") no-repeat 50% 140%/80%;
  72. margin-right: .1rem;
  73. }
  74. .task_dbqk {
  75. display: inline-block;
  76. font-size: .3rem;
  77. padding: 0 .1rem;
  78. border-radius: .03rem;
  79. color: #fff;
  80. margin-left: .26rem;
  81. white-space: nowrap;
  82. vertical-align: text-top;
  83. }
  84. .task_dbqk1{
  85. background-color: #f39700;
  86. }
  87. .task_dbqk2{
  88. background-color: #ff0000;
  89. }
  90. .task_dbqk3{
  91. background-color: #bbbc5f;
  92. }
  93. .task_dbqk4{
  94. background-color: #e60012;
  95. }
  96. .task_dbqk5{
  97. background-color: #cacbbb;
  98. }
  99. .task_pssj,
  100. .task_wcsj {
  101. display: inline-block;
  102. height: .4rem;
  103. line-height: .4rem;
  104. font-size: .3rem;
  105. padding: 0 .18rem;
  106. border-radius: .03rem;
  107. }
  108. .task_pssj {
  109. border: 1px solid #3aca74;
  110. color: #3aca74;
  111. margin-right: .2rem;
  112. }
  113. .task_wcsj {
  114. border: 1px solid #fd9b53;
  115. color: #fd9b53;
  116. }
  117. .gz{
  118. display: inline-block;
  119. width: .66rem;
  120. height: .66rem;
  121. background-image: url("../image/gz.png");
  122. background-size: 100%;
  123. margin-left: .5rem;
  124. margin-bottom: -.1rem;
  125. }
  126. .gz-active{
  127. display: inline-block;
  128. width: .66rem;
  129. height: .66rem;
  130. background-image: url("../image/gz-active.png");
  131. background-size: 100%;
  132. margin-left: .5rem;
  133. margin-bottom: -.1rem;
  134. }
  135. .task_text{
  136. font-size: .4rem;
  137. color: #818181;
  138. }
  139. .taskXQ>div.xcms{
  140. width: calc(100% - .66rem);
  141. background-color: #FAFAFA;
  142. border-radius: .1rem;
  143. border: 1px solid #efefef;
  144. margin: 0 auto;
  145. }
  146. .taskXQ>div.imgDiv{
  147. padding: .3rem .3rem .6rem;
  148. }
  149. .imgDiv div{
  150. width: 23.5%;
  151. height: 2rem;
  152. float: left;
  153. margin-right: 2%;
  154. border: 2px solid rgba(0,0,0,0);
  155. }
  156. .imgDiv div.active{
  157. border: 2px solid #00db00;
  158. }
  159. .imgDiv div:nth-of-type(4n){
  160. margin-right: 0;
  161. }
  162. .imgDiv div img{
  163. display: inline-block;
  164. width: 100%;
  165. height: 100%;
  166. border-radius: .1rem;
  167. }
  168. .imgDiv p{
  169. text-align: center;
  170. font-size: .3rem;
  171. color: #818181;
  172. }
  173. .startBtn{
  174. width: 100%;
  175. height: 1.06rem;
  176. line-height: 1.06rem;
  177. font-size: .42rem;
  178. text-align: center;
  179. color: #fff;
  180. background-color: #22ad38;
  181. border-radius: .1rem;
  182. margin-bottom: .3rem;
  183. }
  184. .removeBtn{
  185. width: 100%;
  186. height: 1.06rem;
  187. line-height: 1.06rem;
  188. font-size: .42rem;
  189. text-align: center;
  190. color: #fff;
  191. background-color: #f7941d;
  192. border-radius: .1rem;
  193. }
  194. .zzPopups{
  195. position: fixed;
  196. top: 0;
  197. right: 0;
  198. bottom: 0;
  199. left: 0;
  200. background-color: rgba(0,0,0,0.8);
  201. z-index: 99;
  202. display: none;
  203. }
  204. .zzPopups div{
  205. height: 80%;
  206. position: absolute;
  207. top: 50%;
  208. left: 10%;
  209. right: 10%;
  210. -webkit-transform: translateY(-50%);
  211. }
  212. .zzPopups div img{
  213. background-color: #fff;
  214. }
  215. .openBtn{
  216. width: 100%;
  217. height: 1.06rem;
  218. line-height: 1.06rem;
  219. font-size: .42rem;
  220. text-align: center;
  221. color: #fff;
  222. background-color: #22ad38;
  223. border-radius: .1rem;
  224. margin-bottom: .3rem;
  225. }
  226. .taskXQ>.hr{
  227. width: calc(100% - .66rem);
  228. height: 1px;
  229. background-color: #efefef;
  230. padding: 0;
  231. margin: 0 auto;
  232. }
  233. .remind1Warp,.remind2Warp,.remind3Warp{
  234. position: fixed;
  235. top: 0;
  236. right: 0;
  237. bottom: 0;
  238. left: 0;
  239. background-color: rgba(0,0,0,0.2);
  240. z-index: 99;
  241. }
  242. .remindDiv1,.remindDiv2,.remindDiv3{
  243. width: calc(100% - 2rem);
  244. height: 50%;
  245. background-color: #fff;
  246. position: absolute;
  247. left: 1rem;
  248. top: 25%;
  249. border-radius: .3rem;
  250. overflow: hidden;
  251. }
  252. .remindImg{
  253. width: 100%;
  254. height: 3.1rem;
  255. }
  256. .remindImg img{
  257. display: inline-block;
  258. width: 100%;
  259. height: 100%;
  260. }
  261. .remindText{
  262. font-size: .5rem;
  263. color: #3d3d3d;
  264. text-align: center;
  265. margin: .5rem 0;
  266. }
  267. .remindContent{
  268. font-size: .4rem;
  269. color: #818181;
  270. text-align: center;
  271. margin-bottom: .3rem;
  272. }
  273. .sureBtn,.clBtn{
  274. width: 70%;
  275. height: 1rem;
  276. line-height: 1rem;
  277. font-size: .42rem;
  278. text-align: center;
  279. color: #fff;
  280. background-color: #22ad38;
  281. border-radius: .1rem;
  282. margin:0 auto .3rem;
  283. }
  284. .hid{
  285. display: none;
  286. }
  287. </style>
  288. </head>
  289. <body>
  290. <div class="taskXQ">
  291. <div class="task_taskCon flex-con">
  292. <p><span class="task_name">{{name}}</span><span class="task_dbqk {{class}}">{{status}}</span></p>
  293. <p><i class="icon_1"></i>{{tasktype}}内容:<span class="task_duty">{{duty}}</span></p>
  294. <p><i class="icon_2"></i>地址:<span class="task_dw">{{enterprise}}</span></p>
  295. <p>变电柜:<span class="task_dw">{{bdgname}}</span></p>
  296. <p class="clearFix">审核人:<span class="task_dw">{{shren}}</span><span class="right delay {{isUser}}" id="delay">是否要延期</span></p>
  297. <p><span class="taskTypeName">检修人员:</span><span class="task_dw">{{xjren}}</span></p>
  298. <p>协助人员:<span class="task_dw">{{xzren}}</span></p>
  299. <p><span class="task_pssj">申请日期:{{pssj}}</span><!--<span class="task_wcsj">检修日期:{{wcsj}}</span>--></p>
  300. <p><span class="task_pssj">计划开始:{{jhks}}</span><span class="task_wcsj" id="upload">计划结束:{{jhjs}}</span></p>
  301. </div>
  302. <div class="hr"></div>
  303. <div class="imgDiv clearFix hid">
  304. <div rel="1"><img src="../image/moren.jpg" alt=""><p>锁具1</p></div>
  305. <div rel="2"><img src="../image/moren.jpg" alt=""><p>锁具2</p></div>
  306. <div rel="3"><img src="../image/moren.jpg" alt=""><p>锁具3</p></div>
  307. <div rel="4"><img src="../image/moren.jpg" alt=""><p>锁具4</p></div>
  308. </div>
  309. <div>
  310. <div class="openBtn " id="dhBtn">导航</div>
  311. <div class="openBtn " id="yddBtn">已到达目的地</div>
  312. <div class="openBtn hid" id="codeBtn">扫描二维码开锁</div>
  313. <div class="openBtn hid" id="GPRSBtn">输入编号开锁</div>
  314. </div>
  315. </div>
  316. <div class="zzPopups">
  317. <div></div>
  318. </div>
  319. <div class="remind1Warp hid">
  320. <div class="remindDiv1">
  321. <div class="remindImg"><img src="../image/openKey1.jpg" alt=""></div>
  322. <p class="remindText">开锁成功</p>
  323. <p class="remindContent">锁门编号:<span class="keyId"></span> 与检修相符</p>
  324. <div class="sureBtn">确认开门</div>
  325. </div>
  326. </div>
  327. <div class="remind2Warp hid">
  328. <div class="remindDiv2">
  329. <div class="remindImg"><img src="../image/openKey2.jpg" alt=""></div>
  330. <p class="remindText">开锁失败</p>
  331. <p class="remindContent">锁门编号:<span class="keyId"></span> 暂未打开</p>
  332. <div class="clBtn">请重试</div>
  333. </div>
  334. </div>
  335. <div class="remind3Warp hid">
  336. <div class="remindDiv3">
  337. <div class="remindImg"><img src="../image/openKey2.jpg" alt=""></div>
  338. <p class="remindText">开锁失败</p>
  339. <p class="remindContent">当前变电柜与检修不相符</p>
  340. <div class="clBtn">变电柜错误</div>
  341. </div>
  342. </div>
  343. <a href="" id="locationA"></a>
  344. <a href="" id="locationB"></a>
  345. <script src="../script/publicData.js"></script>
  346. <script src="../script/jqueryMin.js"></script>
  347. <script type="text/javascript" src="../script/api.js"></script>
  348. <script src="../script/test.js"></script>
  349. <!--<script src="../script/CRC.js"></script>-->
  350. <script>
  351. var ii=0;
  352. function showImg(that) {
  353. if(ii!=0) {
  354. api.toast({
  355. msg: '正在加载图片,请稍等...',
  356. duration: 2000,
  357. location: 'bottom'
  358. });
  359. return;
  360. }
  361. api.imageCache({
  362. url: that.getAttribute("src")
  363. }, function(ret, err) {
  364. if(ret.status){
  365. var url = ret.url;
  366. $(".zzPopups div").append("<img src='"+url+"'>");
  367. $(".zzPopups").css("display","block");
  368. ii++;
  369. }else {
  370. api.toast({
  371. msg: '加载图片失败',
  372. duration: 2000,
  373. location: 'bottom'
  374. });
  375. ii=0;
  376. }
  377. });
  378. }
  379. apiready = function() {
  380. api.showProgress({
  381. title: '努力加载中...',
  382. text: '请稍等...',
  383. modal: false
  384. });
  385. var dialogBox = api.require('dialogBox');
  386. var bluetooth = api.require('bluetooth');
  387. var ble = api.require('ble');
  388. var ulModel=$(".taskXQ").html(),str="";
  389. var task=$api.getStorage("taskXQ");
  390. var winWidth= api.winWidth/3-10;
  391. var ad=["1","3"];
  392. var BLESUUID="";
  393. var BLEPUUID="";
  394. var BLECUUID="";
  395. var keynum="1";
  396. var mac_address="";
  397. var bdg_code="";
  398. var key_num="";
  399. var ser_mac_address="";
  400. var ser_bdg_code="";
  401. var codeData={};
  402. var bleTime=null;
  403. var sid=0,returnNum=0,bleNum=0;
  404. var times=null,delay=null;
  405. var postData={
  406. id:task.taskID
  407. }
  408. $(".zzPopups").click(function () {
  409. $(".zzPopups").css("display","none");
  410. $(".zzPopups div").html(" ");
  411. ii=0;
  412. })
  413. api.ajax({
  414. url: pageUrl+"/index/task/show",
  415. method: 'get',
  416. timeout: 30,
  417. dataType: 'text',
  418. returnAll: false,
  419. data: {
  420. values: postData
  421. }
  422. }, function (data, err) {
  423. var data=JSON.parse(data)
  424. $api.setStorage("taskContent",data.data);
  425. // alert(JSON.stringify(data))
  426. var user="",dep="",dataImg=[],dataFile=[],str2="",shreny="",xzreny="";
  427. switch (data['data']['task_type']+""){
  428. case "0":
  429. str=ulModel.replace("{{status}}","常规").replace("{{class}}","task_dbqk1");
  430. break;
  431. case "1":
  432. str=ulModel.replace("{{status}}","紧急").replace("{{class}}","task_dbqk2");
  433. break;
  434. case "2":
  435. str=ulModel.replace("{{status}}","紧急").replace("{{class}}","task_dbqk2");
  436. break;
  437. case "3":
  438. str=ulModel.replace("{{status}}","紧急").replace("{{class}}","task_dbqk2");
  439. break;
  440. case "4":
  441. str=ulModel.replace("{{status}}","常规").replace("{{class}}","task_dbqk2");
  442. break;
  443. }
  444. if(data['data']['aduit'].length){
  445. for(var i in data['data']['aduit']){
  446. if(i==data['data']['aduit'].length-1){
  447. shreny+=data['data']['aduit'][i]['name']
  448. }else {
  449. shreny+=data['data']['aduit'][i]['name']+"、"
  450. }
  451. }
  452. }
  453. if(data['data']['helper'].length){
  454. for(var j in data['data']['helper']){
  455. if(j==data['data']['helper'].length-1){
  456. xzreny+=data['data']['helper'][j]['name']
  457. }else {
  458. xzreny+=data['data']['helper'][j]['name']+"、"
  459. }
  460. }
  461. }
  462. 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):"未设定")
  463. .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"?"检修":"巡查");
  464. var gzjlModel="<div><img src='{{img}}' alt=''></div>",str2="",imgStr="",fileStr="";
  465. if(data['data']['resultImg']){
  466. for(var num in data['data']['resultImg']){
  467. dataImg.push(data['data']['resultImg'][num]['img'])
  468. }
  469. }
  470. if(dataImg&&dataImg.length) {
  471. for (var imgIndex in dataImg) {
  472. str2=gzjlModel.replace("{{img}}",pageImg+dataImg[imgIndex]||"");
  473. }
  474. }
  475. imgStr="";
  476. dataImg=[];
  477. ser_mac_address=data['data']['bdg']['mac_address'];
  478. ser_bdg_code=data['data']['bdg']['code'];
  479. if(api.systemType=="android"){
  480. $("#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");
  481. }else if(api.systemType=="ios"){
  482. $("#locationA").prop("href","baidumap://map/geocoder?location="+$api.getStorage("taskXQ").lat+","+$api.getStorage("taskXQ").lon+"&coord_type=bd09ll&src=webapp.rgeo.卡瑞网络科技有限公司.云瞳");
  483. }
  484. // $("#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");
  485. $("#locationB").prop("href","http://api.map.baidu.com/geocoder?location="+$api.getStorage("taskXQ").lon+","+$api.getStorage("taskXQ").lat+"&coord_type=bd09ll&output=html&src=云瞳");
  486. str=str.replace("{{img}}",str2);
  487. api.hideProgress();
  488. $(".taskXQ").html(str).css("display","block");
  489. if(task.taskType=="patrol"){
  490. $(".taskTypeName").text("巡查人员:");
  491. }
  492. for(var p in data['data']['helper']){
  493. if($api.getStorage("user").id==data['data']['helper'][p]['id']&&$api.getStorage("user").id!=data['data']['user']['id']){
  494. $("#yddBtn").css("display","none");
  495. }
  496. }
  497. $("#dhBtn").click(function () {
  498. // api.openWin({
  499. // name: "Map",
  500. // url: './Map.html',
  501. // animation: {
  502. // type: 'push',
  503. // subType: 'from_right',
  504. // duration: 300
  505. // },
  506. // delay:300
  507. // });
  508. api.actionSheet({
  509. title: '选择地图',
  510. cancelTitle: '取消',
  511. buttons: ["百度地图"/*,"在线地图"*/]
  512. }, function (ret, err) {
  513. if(ret.buttonIndex==1){
  514. $("#locationA")[0].click();
  515. }
  516. // else if(ret.buttonIndex==2){
  517. // $("#locationB")[0].click();
  518. // }
  519. });
  520. })
  521. $("#yddBtn").click(function () {
  522. if(new Date(data['data']['created_at']).getTime()>new Date().getTime()){
  523. api.toast({
  524. msg: '还未到开始时间',
  525. duration: 2000,
  526. location: 'bottom'
  527. });
  528. }else if(new Date(data['data']['end_time']).getTime()<new Date().getTime()){
  529. api.toast({
  530. msg: '此任务已超时',
  531. duration: 2000,
  532. location: 'bottom'
  533. });
  534. }else {
  535. $("#dhBtn").addClass("hid");
  536. $("#yddBtn").addClass("hid");
  537. $("#codeBtn").removeClass("hid");
  538. $("#GPRSBtn").removeClass("hid");
  539. // $(".imgDiv div").eq(0).addClass("active")
  540. }
  541. })
  542. $("#delay").click(function () {
  543. var win= JSON.parse(localStorage.getItem("window"))
  544. api.openFrame({
  545. name: 'delayTime',
  546. url: './delayTime.html',
  547. bgColor : 'rgba(0,0,0,0)',
  548. rect: {
  549. x: 0,
  550. // y: win.headerH,
  551. y: 0,
  552. w: "auto",
  553. // h: win.mainH
  554. h: api.winHeight
  555. },
  556. pageParam: {val: task.taskID,time:data['data']['end_time']},
  557. bounces: false
  558. });
  559. })
  560. api.addEventListener({
  561. name: 'uploadTime'
  562. }, function (ret, err) {
  563. data['data']['end_time']=ret.value.time;
  564. $("#upload").text("计划结束:"+ret.value.time)
  565. });
  566. api.addEventListener({
  567. name: 'showCode'
  568. }, function (ret, err) {
  569. $("#dhBtn").addClass("hid");
  570. $("#yddBtn").addClass("hid");
  571. $("#codeBtn").removeClass("hid");
  572. $("#GPRSBtn").removeClass("hid");
  573. $(".imgDiv div").eq(0).addClass("active")
  574. });
  575. // if($api.getStorage("isTwo")=="true"){
  576. // $("#dhBtn").addClass("hid");
  577. // $("#yddBtn").addClass("hid");
  578. // $("#codeBtn").removeClass("hid");
  579. // $("#GPRSBtn").removeClass("hid");
  580. // $(".imgDiv div").eq(0).addClass("active")
  581. // $api.setStorage("isTwo",false)
  582. // }
  583. $("#codeBtn").click(function () {
  584. ble.initManager(function(ret, err){
  585. if(ret.state == "poweredOn"){//蓝牙4.0设备连接状态,设备开启状态 -- 可用状态
  586. //开始扫啊扫
  587. api.openWin({
  588. name: 'QRCode',
  589. url: './QRCode.html',
  590. pageParam: {
  591. name: 'QRData'
  592. }
  593. });
  594. api.addEventListener({
  595. name: 'QRData'
  596. }, function (ret, err) {
  597. var ret=ret.value.data;
  598. if (ret) {
  599. if(ret.eventType=="success"){
  600. api.showProgress({
  601. title: '正在开锁中...',
  602. text: '请稍等',
  603. modal: false
  604. });
  605. try {
  606. bdg_code=JSON.parse(ret.content)['code'];
  607. key_num=JSON.parse(ret.content)['lock_id'];
  608. mac_address=JSON.parse(ret.content)['mac'];
  609. }catch (e){
  610. api.hideProgress();
  611. alert("二维码识别失败");
  612. writeFS("二维码识别失败 "+new Date().toString()+"\r\n")
  613. return;
  614. }
  615. if(ser_bdg_code.indexOf(bdg_code)!=-1){
  616. writeFS("该主板与任务相关 "+new Date().toString()+"\r\n")
  617. ble_scan();
  618. }else {
  619. writeFS("该主板与任务不相关 "+new Date().toString()+"\r\n")
  620. api.hideProgress();
  621. $(".remind3Warp").removeClass("hid");
  622. $(".clBtn").click(function () {
  623. $(".remind3Warp").addClass("hid");
  624. })
  625. }
  626. }
  627. }
  628. });
  629. }else if(ret.state == "poweredOff"){
  630. api.alert({msg:'请打开蓝牙'});
  631. }else {
  632. api.toast({
  633. msg: '蓝牙出现未知错误',
  634. duration: 2000,
  635. location: 'bottom'
  636. });
  637. }
  638. });
  639. })
  640. /*GPRS 通信按钮*/
  641. $("#GPRSBtn").click(function () {
  642. api.prompt({
  643. title:"提示",
  644. msg:"请输入变电柜编码",
  645. buttons: ['取消', '确定']
  646. }, function(ret, err) {
  647. var index = ret.buttonIndex;
  648. if(index==2){
  649. doGPRS(ret.text);
  650. }
  651. });
  652. })
  653. });
  654. function doGPRS(val) {
  655. if(val.toLocaleUpperCase()!=ser_bdg_code.toLocaleUpperCase()){
  656. api.toast({
  657. msg: '任务与变电柜不相符',
  658. duration: 2000,
  659. location: 'bottom'
  660. });
  661. return;
  662. }
  663. var arr=["锁1","锁2","锁3","锁4"];
  664. api.actionSheet({
  665. title: '选择要打开的锁',
  666. buttons: arr
  667. }, function (ret, err) {
  668. if(ret.buttonIndex>arr.length) return;
  669. api.showProgress({
  670. title: '正在开锁中...',
  671. text: '请稍等...',
  672. modal: false
  673. });
  674. var postData={
  675. bdg_id:ser_bdg_code.toLocaleUpperCase(),
  676. lock_id:"0"+ret.buttonIndex.toString(),
  677. imei: api.deviceId
  678. }
  679. // clientServer(ret.buttonIndex);
  680. console.log(JSON.stringify(postData))
  681. $api.setStorage("selKey",ret.buttonIndex)
  682. api.ajax({
  683. url: pageUrl+"/index/socket/index",
  684. method: 'get',
  685. timeout: 30,
  686. dataType: 'text',
  687. returnAll: false,
  688. data: {
  689. values: postData
  690. }
  691. }, function (data, err) {
  692. var data=JSON.parse(data);
  693. console.log(JSON.stringify(data))
  694. if(data){
  695. if(data.code!=1) {
  696. // var socketManager = api.require('socketManager');
  697. // clSocket(sid,socketManager)
  698. api.hideProgress();
  699. api.toast({
  700. msg: data.info,
  701. duration: 2000,
  702. location: 'bottom'
  703. });
  704. }else {
  705. // api.hideProgress();
  706. // if(data.code==1){
  707. // $(".remind1Warp .keyId").text("锁"+ret.buttonIndex);
  708. // $(".remind1Warp").removeClass("hid");
  709. // $(".sureBtn").click(function () {
  710. // $(".remind1Warp").addClass("hid");
  711. // var jsfun1 = 'toFrame(7);';
  712. // api.execScript({
  713. // name: 'root',
  714. // script: jsfun1
  715. // });
  716. // $api.setStorage("isTwo",true)
  717. // })
  718. // }
  719. }
  720. }else {
  721. api.hideProgress();
  722. }
  723. api.execScript({
  724. name: 'root',
  725. script: 'totalTime(0);'
  726. });
  727. });
  728. });
  729. }
  730. api.addEventListener({
  731. name: 'isGetre'
  732. }, function (ret, err) {
  733. var data=ret.value.data;
  734. api.hideProgress();
  735. if(data[data.length-3]=="1"){
  736. $(".remind1Warp .keyId").text("锁"+$api.getStorage("selKey"));
  737. $(".remind1Warp").removeClass("hid");
  738. $(".sureBtn").click(function () {
  739. $(".remind1Warp").addClass("hid");
  740. $api.setStorage("isTwo",true);
  741. $api.setStorage("toList","2");
  742. var jsfun1 = 'toFrame(7);';
  743. api.execScript({
  744. name: 'root',
  745. script: jsfun1
  746. });
  747. })
  748. }else if(data[data.length-3]=="0"){
  749. $(".remind2Warp .keyId").text("锁"+$api.getStorage("selKey"));
  750. $(".remind2Warp").removeClass("hid");
  751. $(".clBtn").click(function () {
  752. $(".remind2Warp").addClass("hid");
  753. })
  754. }else if(data[data.length-3]=="2"){
  755. api.toast({
  756. msg: '连接超时',
  757. duration: 2000,
  758. location: 'bottom'
  759. });
  760. }
  761. });
  762. function toBig(val,num) {
  763. var arr=[],thisArr=val.split("");
  764. if(num){
  765. for(var i=0;i<thisArr.length;i++){
  766. arr.unshift(+thisArr[i]);
  767. }
  768. }else {
  769. for(var i=0;i<thisArr.length;i++){
  770. if(i%2){
  771. arr.unshift(thisArr[i-1]+thisArr[i]);
  772. }
  773. }
  774. }
  775. return arr.join("");
  776. }
  777. function ble_scan() {
  778. if(!bleTime){
  779. startTime();
  780. }
  781. var has=false;
  782. ble.scan({
  783. serviceUUIDs:[]//如果知道serviceUUID的话就直接 填上去 不知道的 蓝牙app 可以告诉你
  784. }, function( ret ){
  785. if( ret.status ){
  786. ble.getPeripheral(function(ret) {
  787. if (ret.peripherals.length>0){
  788. writeFS("正在搜索蓝牙 "+new Date().toString()+"\r\n")
  789. for(var i=0;i<ret.peripherals.length;i++){
  790. if(ret.peripherals[i]['uuid']==ser_mac_address){
  791. has=true;
  792. clearTimeout(bleTime)
  793. writeFS("正在连接蓝牙 "+new Date().toString()+"\r\n")
  794. ble_connect();
  795. }
  796. }
  797. if(!has){
  798. ble_scan();
  799. }
  800. }else {
  801. ble_scan();
  802. }
  803. });
  804. }
  805. });
  806. };
  807. function startTime() {
  808. if(bleNum==8){
  809. clearTimeout(bleTime)
  810. writeFS("扫描蓝牙失败,正使用GPRS开锁("+bdg_code+") "+new Date().toString()+"\r\n")
  811. api.toast({
  812. msg: '扫描蓝牙失败,正使用GPRS开锁',
  813. duration: 2000,
  814. location: 'bottom'
  815. });
  816. toGPRS(bdg_code,key_num)
  817. }
  818. bleTime=setTimeout(function () {
  819. bleNum++;
  820. startTime();
  821. },1000)
  822. }
  823. function ble_connect() {
  824. ble.isConnected({
  825. peripheralUUID: ser_mac_address
  826. }, function(ret) {
  827. BLEPUUID=ser_mac_address;
  828. $api.setStorage("BLEPUUID",BLEPUUID)
  829. if (ret.status) {
  830. // $(".imgDiv").removeClass("hid");
  831. // $(".imgDiv div").click(function () {
  832. // if($("#codeBtn").hasClass("hid")) return;
  833. // $(this).addClass("active").siblings().removeClass("active");
  834. // keynum=$(this).attr("rel");
  835. // ble_discoverService();
  836. // })
  837. clearTimeout(bleTime);
  838. if(BLEPUUID==mac_address){
  839. keynum=key_num;
  840. ble_discoverService();
  841. writeFS("蓝牙已连接("+bdg_code+") "+new Date().toString()+"\r\n")
  842. }else {
  843. writeFS("蓝牙已连接某主板,正在切换连接 "+new Date().toString()+"\r\n")
  844. disconnect(function () {
  845. ble_scan();
  846. });
  847. }
  848. }else {
  849. ble.connect({
  850. peripheralUUID: ser_mac_address
  851. },function(ret1 , err1){
  852. if(ret1.status) {
  853. // alert(JSON.stringify(ret1)+",已连接"+2)
  854. // $(".imgDiv").removeClass("hid");
  855. // api.toast({
  856. // msg: '请选择要打开的锁',
  857. // duration: 2000,
  858. // location: 'bottom'
  859. // });
  860. // $(".imgDiv div").click(function () {
  861. // if($("#codeBtn").hasClass("hid")) return;
  862. // $(this).addClass("active").siblings().removeClass("active");
  863. // keynum=$(this).attr("rel");
  864. // ble_discoverService();
  865. // })
  866. clearTimeout(bleTime);
  867. writeFS("蓝牙初始连接成功("+bdg_code+") "+new Date().toString()+"\r\n")
  868. keynum=key_num;
  869. ble_discoverService();
  870. }else {
  871. clearTimeout(bleTime);
  872. writeFS("没有搜索到任务蓝牙 "+new Date().toString()+"\r\n");
  873. api.hideProgress();
  874. api.toast({
  875. msg: '没有搜索到任务蓝牙',
  876. duration: 2000,
  877. location: 'bottom'
  878. });
  879. }
  880. });
  881. }
  882. });
  883. }
  884. function ble_discoverService() {
  885. ble.discoverService({
  886. peripheralUUID: BLEPUUID
  887. },function(ret2){
  888. if(ret2.status) {
  889. // alert(JSON.stringify(ret2)+",获取service");
  890. // BLESUUID=ret2['services'][3];
  891. BLESUUID="0000ffe5-0000-1000-8000-00805f9b34fb";
  892. ble.discoverCharacteristics({
  893. peripheralUUID: BLEPUUID,
  894. serviceUUID: BLESUUID
  895. },function(ret3 , err3){
  896. if(ret3.status) {
  897. // alert(JSON.stringify(ret3)+",获取char");
  898. //串口特征值 0000ffe4-0000-1000-8000-00805f9b34fb
  899. // BLECUUID=ret3['characteristics'][0]['uuid'];
  900. BLECUUID="0000ffe9-0000-1000-8000-00805f9b34fb";
  901. // alert("52434d5300010006"+"04"+bdg_code+"0"+keynum+"0000")
  902. writeFS("向主板蓝牙发送开锁数据("+bdg_code+") "+new Date().toString()+"\r\n")
  903. ble.writeValueForCharacteristic({
  904. peripheralUUID: BLEPUUID,
  905. serviceUUID: BLESUUID,
  906. characteristicUUID: BLECUUID,
  907. value:"52434d5300010006"+"04"+bdg_code+"0"+keynum+"0000",//字符串
  908. // value:"52434d5300010006"+"04"+"6ec81c96"+"0"+keynum+"0000",//字符串
  909. writeType:"withoutResponse"
  910. },function(ret4 , err4){
  911. if(ret4.status){
  912. writeFS("向主板蓝牙发送数据成功("+bdg_code+") "+new Date().toString()+"\r\n")
  913. ble.setNotify({
  914. peripheralUUID: BLEPUUID,
  915. serviceUUID: "0000ffe0-0000-1000-8000-00805f9b34fb",
  916. characteristicUUID: "0000ffe4-0000-1000-8000-00805f9b34fb"
  917. }, function(ret) {
  918. // alert(JSON.stringify(ret))
  919. writeFS("接收主板蓝牙数据成功("+bdg_code+") "+new Date().toString()+"\r\n")
  920. api.hideProgress();
  921. if (ret) {
  922. var bl=true;
  923. // alert(JSON.stringify(ret))
  924. if(ret.characteristic.value.slice(28,30)!="01"){
  925. bl=false;
  926. }else {
  927. if(keynum!=ret.characteristic.value.slice(27,28)){
  928. bl=false;
  929. }else {
  930. bl=true;
  931. }
  932. }
  933. if(bl){
  934. $(".remind1Warp .keyId").text("锁"+keynum);
  935. $(".remind1Warp").removeClass("hid");
  936. }else {
  937. $(".remind2Warp .keyId").text("锁"+keynum);
  938. $(".remind2Warp").removeClass("hid");
  939. }
  940. // disconnect();
  941. $(".sureBtn").click(function () {
  942. $(".remind1Warp").addClass("hid");
  943. // disconnect();
  944. var jsfun1 = 'toFrame(7);';
  945. api.execScript({
  946. name: 'root',
  947. script: jsfun1
  948. });
  949. // setTimeout(function () {
  950. // api.closeFrame({
  951. // name: 'taskXQ'
  952. // });
  953. // },300)
  954. $api.setStorage("isTwo",true)
  955. })
  956. $(".clBtn").click(function () {
  957. $(".remind2Warp").addClass("hid");
  958. })
  959. }
  960. });
  961. }else {
  962. writeFS("向主板蓝牙发送数据失败("+bdg_code+") "+new Date().toString()+"\r\n")
  963. api.toast({
  964. msg: '蓝牙异常,正使用GPRS开锁',
  965. duration: 2000,
  966. location: 'bottom'
  967. });
  968. toGPRS(bdg_code,keynum)
  969. }
  970. });
  971. }
  972. });
  973. }
  974. });
  975. }
  976. function getTime(time,bl) {
  977. var oldTime=new Date(time*1000),str="";
  978. var year=oldTime.getFullYear();
  979. var month=oldTime.getMonth()+1;
  980. var day=oldTime.getDate();
  981. var hours=oldTime.getHours();
  982. var minutes=oldTime.getMinutes();
  983. if(bl){
  984. str=year+"-"+checkTime(month)+"-"+checkTime(day)+" "+checkTime(hours)+":"+checkTime(minutes);
  985. }else {
  986. str=year+"-"+checkTime(month)+"-"+checkTime(day);
  987. }
  988. return str;
  989. }
  990. function checkTime(val) {
  991. var val=val;
  992. if((val+"").length==1){
  993. val="0"+val;
  994. }
  995. return val
  996. }
  997. function popupsBox(val,type) {
  998. dialogBox.alert({
  999. texts: {
  1000. title: '确认提示',
  1001. content: val,
  1002. leftBtnTitle: '取消',
  1003. rightBtnTitle: '确认'
  1004. },
  1005. styles: {
  1006. bg: '#fff',
  1007. w: 300,
  1008. title: {
  1009. marginT: 20,
  1010. icon: 'widget://res/gou.png',
  1011. iconSize: 40,
  1012. titleSize: 13,
  1013. titleColor: '#000'
  1014. },
  1015. content: {
  1016. color: '#000',
  1017. size: 16
  1018. },
  1019. left: {
  1020. marginB: 0,
  1021. marginL: 0,
  1022. w: 150,
  1023. h: 60,
  1024. corner: 2,
  1025. bg: '#f9f9f9',
  1026. color: '#818181',
  1027. size: 12
  1028. },
  1029. right: {
  1030. marginB: 0,
  1031. marginL: 0,
  1032. w: 150,
  1033. h:60,
  1034. corner: 2,
  1035. bg: '#51c4d4',
  1036. color: '#fff',
  1037. size: 12
  1038. }
  1039. }
  1040. }, function(ret) {
  1041. if (ret.eventType == 'right') {
  1042. var taskData={
  1043. task_id:task.taskID-0,
  1044. task_status:type
  1045. }
  1046. dialogBox.close({
  1047. dialogName: 'alert'
  1048. });
  1049. }else if (ret.eventType == 'left') {
  1050. dialogBox.close({
  1051. dialogName: 'alert'
  1052. });
  1053. }
  1054. });
  1055. }
  1056. }
  1057. function toGPRS(id,index) {
  1058. var postData={
  1059. bdg_id:id.toLocaleUpperCase(),
  1060. lock_id:"0"+index.toString(),
  1061. imei: api.deviceId
  1062. }
  1063. // clientServer(ret.buttonIndex);
  1064. $api.setStorage("selKey",index);
  1065. api.ajax({
  1066. url: pageUrl+"/index/socket/index",
  1067. method: 'get',
  1068. timeout: 30,
  1069. dataType: 'text',
  1070. returnAll: false,
  1071. data: {
  1072. values: postData
  1073. }
  1074. }, function (data, err) {
  1075. var data=JSON.parse(data);
  1076. if(data){
  1077. if(data.code!=1) {
  1078. api.hideProgress();
  1079. api.toast({
  1080. msg: data.info,
  1081. duration: 2000,
  1082. location: 'bottom'
  1083. });
  1084. }
  1085. }else {
  1086. api.hideProgress();
  1087. }
  1088. api.execScript({
  1089. name: 'root',
  1090. script: 'totalTime(0);'
  1091. });
  1092. });
  1093. }
  1094. function disconnect(fn) {
  1095. var ble = api.require('ble'),
  1096. id=$api.getStorage("BLEPUUID");
  1097. api.hideProgress();
  1098. ble.disconnect({
  1099. peripheralUUID: id
  1100. },function( ret ){
  1101. if(ret.status) {
  1102. fn();
  1103. }
  1104. });
  1105. }
  1106. function writeFS(val) {
  1107. var fs = api.require('fs');
  1108. var url='fs://log.txt';
  1109. var existRet = fs.existSync({
  1110. path: url
  1111. });
  1112. if (existRet.exist) {
  1113. api.writeFile({
  1114. path: url,
  1115. data: val,
  1116. append:true
  1117. }, function(ret, err) {})
  1118. } else {
  1119. var createRet = fs.createFileSync({
  1120. path: url
  1121. });
  1122. if (createRet.status) {
  1123. api.writeFile({
  1124. path: url,
  1125. data: val,
  1126. append:true
  1127. }, function(ret, err) {});
  1128. }
  1129. }
  1130. }
  1131. </script>
  1132. </body>
  1133. </html>