addBDG.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. <!DOCTYPE html>
  2. <html lang="zh-cn">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="format-detection" content="email=no" />
  6. <meta name="format-detection" content="telephone=no" />
  7. <title>添加变电柜</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. html,body{
  13. height: 100%;
  14. }
  15. html::-webkit-scrollbar {display:none}
  16. body::-webkit-scrollbar {display:none}
  17. .flex-wrap{
  18. display: -webkit-box;
  19. display: -webkit-flex;
  20. display: flex;
  21. }
  22. .flex-con{
  23. -webkit-box-flex: 1;
  24. -webkit-flex: 1;
  25. flex: 1;
  26. }
  27. body{
  28. display: -webkit-box;
  29. display: -webkit-flex;
  30. display: flex;
  31. -webkit-box-orient: vertical;
  32. -webkit-flex-flow: column;
  33. flex-flow: column;
  34. background-color: #fff;
  35. }
  36. #header {
  37. min-height: 1.3rem;
  38. line-height: 1.3rem;
  39. background-color: #fff;
  40. color: #0b0b0b;
  41. position: relative;
  42. /*box-sizing: content-box;*/
  43. }
  44. #backBtn {
  45. width: 1.2rem;
  46. height: 1.4rem;
  47. line-height: 1rem;
  48. text-align: center;
  49. font-size: 1.3rem;
  50. position: absolute;
  51. left: 0;
  52. bottom: 0;
  53. }
  54. #backBtn img{
  55. display: inline-block;
  56. width: 50%;
  57. height: 40%;
  58. }
  59. .headTit {
  60. text-align: center;
  61. line-height: 1.4rem;
  62. font-size: .5rem;
  63. font-weight: normal;
  64. }
  65. .headGN {
  66. position: absolute;
  67. right: 0;
  68. bottom: 0;
  69. }
  70. .headGN li {
  71. display: none;
  72. width: 2.3rem;
  73. line-height: 1.4rem;
  74. font-size: .42rem;
  75. }
  76. .headGN li.active {
  77. display: block;
  78. }
  79. ::-webkit-input-placeholder{
  80. color: #b4b4b4;
  81. }
  82. main{
  83. overflow-x: hidden;
  84. overflow-y: auto;
  85. }
  86. .hr{
  87. width: 100%;
  88. height: .23rem;
  89. background-color: #fafafa;
  90. }
  91. .taskXQ{
  92. padding: .3rem;
  93. }
  94. .taskXQ>div{
  95. margin-bottom: .3rem;
  96. }
  97. .taskXQ>div h3{
  98. font-size: .42rem;
  99. color: #818181;
  100. font-weight: normal;
  101. margin-bottom: .1rem;
  102. }
  103. .task_taskCon p {
  104. margin-bottom: .2rem;
  105. color: #818181;
  106. font-size: .42rem;
  107. }
  108. .selectDiv>label{
  109. width: 100%;
  110. position: relative;
  111. }
  112. .selectDiv input{
  113. display: inline-block;
  114. width: 100%;
  115. font-size: .42rem;
  116. padding: .2rem;
  117. color: #818181;
  118. background-color: #fafafa;
  119. border: 1px solid #f0f0f0;
  120. }
  121. .xcms,.jwd,.zbbm,.selectUDiv,.selectStreet,.wxry,.lymac,.sctp,.s1,.s2,.s3,.s4{
  122. background-color: #fafafa;
  123. border: 1px solid #f0f0f0;
  124. padding: .2rem;
  125. }
  126. .searchBtn{
  127. width: 1.8rem;
  128. height: .9rem;
  129. line-height: 1rem;
  130. text-align: center;
  131. color: #fff;
  132. font-size: .4rem;
  133. background-color: dodgerblue;
  134. border-radius: .1rem;
  135. }
  136. label{
  137. padding: .1rem 0;
  138. color: #515151;
  139. }
  140. label input{
  141. border: none;
  142. outline: none;
  143. background-color: #fafafa;
  144. }
  145. .type_icon{
  146. color: #818181;
  147. font-size: .42rem;
  148. position: absolute;
  149. right: 0.16rem;
  150. top: 0;
  151. }
  152. .task_text{
  153. width: 100%;
  154. height: .6rem;
  155. max-height: .6rem;
  156. font-size: .42rem;
  157. color: #818181;
  158. background-color: #fafafa;
  159. resize: none;
  160. border: none;
  161. overflow-y: auto;
  162. }
  163. input.task_text2{
  164. width: 100%;
  165. font-size: .42rem;
  166. color: #818181;
  167. background-color: #fafafa;
  168. resize: none;
  169. border: none;
  170. overflow-x: auto;
  171. }
  172. .startBtn{
  173. width: 100%;
  174. height: 1.2rem;
  175. line-height: 1.2rem;
  176. font-size: .42rem;
  177. text-align: center;
  178. color: #fff;
  179. background-color: #22ad38;
  180. border-radius: .1rem;
  181. margin-top: .3rem;
  182. }
  183. .imgDiv div{
  184. width: 31.5%;
  185. height: 3.2rem;
  186. float: left;
  187. margin-right: 2%;
  188. margin-bottom: .1rem;
  189. }
  190. .imgDiv div:nth-of-type(3n){
  191. margin-right: 0;
  192. }
  193. .imgDiv div img{
  194. display: inline-block;
  195. width: 100%;
  196. height: 2.8rem;
  197. }
  198. .imgDiv div p{
  199. text-align: center;
  200. font-size: .3rem;
  201. line-height: .38rem;
  202. color: #717171;
  203. }
  204. .h3{
  205. font-size: .42rem;
  206. color: #515151;
  207. margin: .1rem 0 .2rem;
  208. }
  209. </style>
  210. </head>
  211. <body>
  212. <header>
  213. <div id="header">
  214. <i id="backBtn"><img src="../image/backBtn.png" alt=""></i>
  215. <h3 class="headTit">添加变电柜</h3>
  216. <!--<ul class="headGN">-->
  217. <!--<li></li>-->
  218. <!--</ul>-->
  219. </div>
  220. </header>
  221. <main class="flex-con">
  222. <div class="hr"></div>
  223. <div class="taskXQ">
  224. <div class="xcms">
  225. <h3>变电柜名称:</h3>
  226. <input id="name" class="task_text2">
  227. </div>
  228. <div class="jwd">
  229. <h3>变电柜经纬度:</h3>
  230. <label>经度:<input type="text" readonly="readonly" id="lon"></label><br>
  231. <label>纬度:<input type="text" readonly="readonly" id="lat"></label>
  232. </div>
  233. <div class="xcms">
  234. <h3>变电柜详细地址:</h3>
  235. <textarea id="address" class="task_text"></textarea>
  236. </div>
  237. <div class="sctp">
  238. <h3>变电柜图片:</h3>
  239. <div class="imgDiv clearFix"></div>
  240. </div>
  241. <div class="selectStreet">
  242. <h3>所属街道:</h3>
  243. <input id="selectStreet" class="task_text2" readonly="readonly" value="">
  244. </div>
  245. <div class="selectUDiv">
  246. <h3>维修人员:</h3>
  247. <input id="selectUser" class="task_text2" readonly="readonly" value="">
  248. </div>
  249. <div class="zbbm" rel="main">
  250. <h3>主板编码:</h3>
  251. <input id="code" class="task_text2" readonly="readonly">
  252. </div>
  253. <div class="lymac" rel="main">
  254. <h3>蓝牙mac:</h3>
  255. <input id="BleCode" class="task_text2" readonly="readonly">
  256. </div>
  257. <div>
  258. <div class="startBtn" id="bdgBtn">确认添加变电柜</div>
  259. </div>
  260. </div>
  261. </main>
  262. <script src="../script/jqueryMin.js"></script>
  263. <script src="../script/createTime.js"></script>
  264. <script src="../script/publicData.js"></script>
  265. <script src="../script/api.js"></script>
  266. <script>
  267. apiready=function () {
  268. $("#selectUser").val($api.getStorage("user").name);
  269. var imgdata=[],bl=false,bdgid=null,street=[];
  270. var arr=["锁1","锁2","锁3","锁4"];
  271. var selectData=[],userArr=[];
  272. var UIMediaScanner = api.require('UIMediaScanner');
  273. var streetList=$api.getStorage("streetList");
  274. $(".zbbm,.lymac").click(function () {
  275. showCode($(".zbbm").find('input'),$(".lymac").find('input'))
  276. })
  277. $(".s1,.s2,.s3,.s4").click(function () {
  278. showCode($(this).find('input'))
  279. })
  280. $(".jwd").click(function () {
  281. getLoc($("#lat"),$("#lon"),$("#address"));
  282. api.toast({
  283. msg: '正在获取当前位置',
  284. duration: 2000,
  285. location: 'bottom'
  286. });
  287. })
  288. $(".sctp").click(function () {
  289. getPhoto($(".imgDiv"));
  290. })
  291. $(".imgDiv").on('click','div',function (e) {
  292. e.stopPropagation();
  293. uploading($(this),imgdata);
  294. })
  295. var selectData=$api.getStorage("userList");
  296. $(".selectUDiv").click(function () {
  297. showBox($(".selectUDiv"),selectData,true);
  298. })
  299. $(".selectStreet").click(function () {
  300. showBox($(".selectStreet"),streetList,true);
  301. })
  302. $(".selectDiv label").click(function () {
  303. api.actionSheet({
  304. title: '选择锁',
  305. buttons: arr
  306. }, function (ret, err) {
  307. if(ret.buttonIndex>arr.length) return;
  308. $("#type").val(arr[ret.buttonIndex-1])
  309. $("#key1").val("0"+ret.buttonIndex.toString())
  310. });
  311. })
  312. $("#bdgBtn").click(function () {
  313. checkNull($("#name"));
  314. checkNull($("#address"));
  315. checkNull($("#lat"));
  316. checkNull($("#lon"));
  317. checkNull($("#code"));
  318. checkNull($("#BleCode"));
  319. checkNull($("#selectStreet"));
  320. if(imgdata.length==0){
  321. bl=true;
  322. }
  323. if (bl) {
  324. api.toast({
  325. msg: '还有未填项',
  326. duration: 2000,
  327. location: 'bottom'
  328. });
  329. bl=false;
  330. return;
  331. }
  332. var postData = {
  333. title: $("#name").val(),
  334. address: $("#address").val(),
  335. lat: $("#lat").val(),
  336. lon: $("#lon").val(),
  337. code: $("#code").val().toLocaleUpperCase(),
  338. mac_address: $("#BleCode").val(),
  339. street_id:street[0],
  340. img: imgdata[0],
  341. temperature: 0,
  342. humidity: 0,
  343. user_id: userArr[0]||$api.getStorage("user").id
  344. }
  345. api.showProgress({
  346. title: '正在添加中...',
  347. text: '请稍等...',
  348. modal: false
  349. });
  350. api.ajax({
  351. url: pageUrl + "/index/bdg/addbdg",
  352. method: 'post',
  353. timeout: 30,
  354. dataType: 'text',
  355. returnAll: false,
  356. data: {
  357. values: postData
  358. }
  359. }, function (data, err) {
  360. var data = JSON.parse(data);
  361. api.hideProgress();
  362. if (data.status) {
  363. bdgid = data.bdg_id;
  364. $("#name").val(" ");
  365. $("#address").val(" ");
  366. $("#lat").val(" ");
  367. $("#lon").val(" ");
  368. $("#code").val(" ");
  369. $("#BleCode").val(" ");
  370. imgdata = [];
  371. $(".imgDiv").html(" ")
  372. api.openWin({
  373. name: 'addKey',
  374. url: './addKey.html',
  375. pageParam: {bdgid: bdgid}
  376. });
  377. setTimeout(function () {
  378. api.closeWin();
  379. },300)
  380. }
  381. api.toast({
  382. msg: data.status == "0" ? "添加失败" : "添加成功",
  383. duration: 2000,
  384. location: 'bottom'
  385. });
  386. api.execScript({
  387. name: 'root',
  388. script: 'totalTime(0);'
  389. });
  390. });
  391. })
  392. function showBox(that,data,bl) {
  393. var UIMultiSelector= api.require('UIMultiSelector');
  394. if(data.length==0) {
  395. api.toast({
  396. msg: '暂无数据',
  397. duration: 2000,
  398. location: 'bottom'
  399. });
  400. return;
  401. }
  402. var user=$api.getStorage("user");
  403. UIMultiSelector.open({
  404. rect: {
  405. h: 244
  406. },
  407. text: {
  408. title: '',
  409. leftBtn: '',
  410. rightBtn: '',
  411. selectAll: '全选'
  412. },
  413. max: 0,
  414. singleSelection:bl,
  415. styles: {
  416. mask: 'rgba(0,0,0,0.2)',
  417. title: {
  418. bg: '#efefef',
  419. h: 44
  420. },
  421. leftButton: {
  422. w: 60,
  423. h: 30,
  424. marginT: 5,
  425. marginL: 8,
  426. bg:"widget://image/cancel.png"
  427. },
  428. rightButton: {
  429. w: 60,
  430. h: 30,
  431. marginT: 5,
  432. marginR: 8,
  433. bg:"widget://image/finish.png"
  434. },
  435. item: {
  436. h: 40,
  437. bg: '#fff',
  438. bgActive: '#fff',
  439. bgHighlight: '#fff',
  440. color: '#818181',
  441. active: '#818181',
  442. highlight: '#818181',
  443. size: 14,
  444. lineColor: '#efefef',
  445. textAlign: 'left',
  446. marginR:5
  447. },
  448. icon: {
  449. w: 20,
  450. h: 20,
  451. marginT: 11,
  452. marginH: 8,
  453. bg: 'widget://image/select.png',
  454. bgActive: 'widget://image/selected.png',
  455. align: 'left'
  456. }
  457. },
  458. animation: true,
  459. items: data
  460. }, function(ret, err) {
  461. if (ret) {
  462. if(ret.eventType=="clickRight"){
  463. var nameStr="",arr=[],arr2=[];
  464. try{
  465. for(var i in ret.items){
  466. arr[i]={
  467. type:ret.items[i].id,
  468. name:ret.items[i].text
  469. }
  470. arr2.push(ret.items[i].id)
  471. if(i==ret.items.length-1||ret.items.length==1){
  472. nameStr+=ret.items[i].text;
  473. }else {
  474. nameStr+=ret.items[i].text+"、";
  475. }
  476. }
  477. if(that.hasClass("selectUDiv")){
  478. userArr= arr2;
  479. }else if(that.hasClass("selectStreet")){
  480. street= arr2;
  481. }
  482. }catch (e){
  483. nameStr="";
  484. }
  485. that.find("input").val(nameStr);
  486. UIMultiSelector.close();
  487. }else if(ret.eventType=="clickLeft"){
  488. UIMultiSelector.close();
  489. }
  490. } else {
  491. // alert(JSON.stringify(err));
  492. }
  493. });
  494. }
  495. function getLoc(this_lat,this_lon,address) {
  496. var map = api.require('bMap');
  497. map.getLocationServices(function(ret, err) {
  498. if (ret.enable) {
  499. map.getLocation({
  500. accuracy: '10m',
  501. autoStop: true,
  502. filter: 1
  503. }, function (ret, err) {
  504. if (ret.status) {
  505. this_lon.val(ret.lon);
  506. this_lat.val(ret.lat);
  507. map.stopLocation();
  508. map.getNameFromCoords({
  509. lon: ret.lon,
  510. lat: ret.lat
  511. }, function(ret, err) {
  512. if (ret.status) {
  513. address.val(ret.address)
  514. }
  515. });
  516. }
  517. else {
  518. // alert(err.code);
  519. }
  520. });
  521. }else {
  522. api.toast({
  523. msg: '未开启定位功能!',
  524. duration: 2000,
  525. location: 'bottom'
  526. });
  527. }
  528. })
  529. }
  530. function showCode(that,xll) {
  531. // var FNScanner = api.require('FNScanner');
  532. // FNScanner.openScanner({
  533. // autorotation: true
  534. // }, function(ret) {
  535. //
  536. // });
  537. api.openWin({
  538. name: 'QRCode',
  539. url: './QRCode.html',
  540. pageParam: {
  541. name: 'BdgQRData'
  542. }
  543. });
  544. api.addEventListener({
  545. name: 'BdgQRData'
  546. }, function (ret, err) {
  547. var ret = ret.value.data;
  548. if (ret) {
  549. if(ret.eventType=="success"){
  550. if(xll){
  551. that.val(JSON.parse(ret.content)['code'])
  552. xll.val(JSON.parse(ret.content)['mac'])
  553. }else {
  554. that.val(JSON.parse(ret.content)['code'])
  555. }
  556. }
  557. }
  558. })
  559. }
  560. function uploading(that,arr) {
  561. if(that.hasClass("uploadImg")){
  562. api.actionSheet({
  563. title: '上传/删除图片',
  564. cancelTitle: '取消',
  565. buttons: ['上传', '删除']
  566. }, function(ret, err) {
  567. var index = ret.buttonIndex;
  568. if(index==1){
  569. var imageFilter = api.require('imageFilter');
  570. var imageName = "znmsimg";
  571. var imageCachePath = api.cacheDir;
  572. var newimg="";
  573. imageFilter.compress({
  574. img: that.children('img').attr('src'),
  575. quality:0.8,
  576. size:{
  577. w:550,
  578. h:480
  579. },
  580. save: {
  581. album: false,
  582. imgPath: imageCachePath,
  583. imgName: imageName + '.jpg'
  584. }
  585. }, function(ret, err) {
  586. var tx = imageCachePath + '/' + imageName + '.jpg';
  587. that.children('p').text('正在上传中');
  588. api.ajax({
  589. url: pageUrl + "/api/uploadImage",
  590. method: 'post',
  591. timeout: 30,
  592. dataType: 'json',
  593. returnAll: false,
  594. data: {
  595. files: {
  596. file: tx
  597. }
  598. }
  599. }, function (ret, err) {
  600. // var data=JSON.parse(ret);
  601. // alert(JSON.stringify(ret));
  602. that.children('p').text(ret.status == 1 ? "上传成功" : "上传失败");
  603. if (ret.status == 1) {
  604. arr[0] = ret.uri;
  605. }
  606. api.execScript({
  607. name: 'root',
  608. script: 'totalTime(0);'
  609. });
  610. });
  611. })
  612. }else if(index==2){
  613. that.remove();
  614. }
  615. })
  616. }
  617. }
  618. function getPhoto(that) {
  619. api.actionSheet({
  620. title: '上传图片',
  621. cancelTitle: '取消',
  622. buttons: ['相册', '相机']
  623. }, function(ret, err) {
  624. var index = ret.buttonIndex;
  625. if(index==1){
  626. UIMediaScanner.open({
  627. type: 'picture',
  628. column: 4,
  629. max: 1,
  630. sort: {
  631. key: 'time',
  632. order: 'desc'
  633. },
  634. texts: {
  635. stateText: '已选择*项',
  636. cancelText: '取消',
  637. finishText: '完成'
  638. },
  639. styles: {
  640. bg: '#fff',
  641. mark: {
  642. icon: '',
  643. position: 'bottom_left',
  644. size: 20
  645. },
  646. nav: {
  647. bg: '#eee',
  648. stateColor: '#000',
  649. stateSize: 18,
  650. cancelBg: 'rgba(0,0,0,0)',
  651. cancelColor: '#000',
  652. cancelSize: 18,
  653. finishBg: 'rgba(0,0,0,0)',
  654. finishColor: '#000',
  655. finishSize: 18
  656. }
  657. },
  658. exchange: true
  659. }, function(ret) {
  660. if (ret.eventType=="confirm") {
  661. for(var i in ret.list){
  662. if(api.systemType=="ios"){
  663. UIMediaScanner.transPath({
  664. path: ret.list[i]["path"]
  665. }, function(ret, err) {
  666. if (ret) {
  667. that.html("<div class='uploadImg'><img src='file://"+ret.path+"' alt=''><p class='imgRemind'>点击图片上传</p></div>");
  668. // imgData.push("file://"+ret.path);
  669. } else {
  670. // alert(JSON.stringify(err));
  671. }
  672. });
  673. }else {
  674. that.html("<div class='uploadImg'><img src='file://"+ret.list[i]["path"]+"' alt=''><p class='imgRemind'>点击图片上传</p></div>");
  675. // imgData.push("file://"+ret.list[i]["path"]);
  676. }
  677. }
  678. }
  679. });
  680. }else if(index==2){
  681. api.getPicture({
  682. sourceType: 'camera',
  683. encodingType: 'jpg',
  684. mediaValue: 'pic',
  685. saveToPhotoAlbum:'true',
  686. destinationType: 'url',
  687. quality: 50
  688. }, function(ret, err) {
  689. if (ret) {
  690. if(!ret.data) return;
  691. // imgData.push("file://"+ret.data);
  692. that.html("<div class='uploadImg'><img src='file://"+ret.data+"' alt=''><p class='imgRemind'>点击图片上传</p></div>");
  693. } else {
  694. // alert(JSON.stringify(err));
  695. }
  696. });
  697. }else {}
  698. });
  699. }
  700. function checkNull(that) {
  701. if(that.val()==""){
  702. bl=true;
  703. }
  704. return that.val()
  705. }
  706. $("#backBtn").click(function () {
  707. api.closeToWin({
  708. name: 'root',
  709. animation: {
  710. type: 'push',
  711. subType: 'from_left',
  712. duration: 300
  713. },
  714. delay:300
  715. });
  716. })
  717. }
  718. </script>
  719. </body>
  720. </html>