loop.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052
  1. // pages/loop/loop.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. array:[],
  8. //回路调控
  9. crr:["回路1","回路2"],
  10. indexes:"0",
  11. //时间调控
  12. time:["00:00","00:00","00:00","00:00"],
  13. //时间调控(开关选择器)
  14. state:[false,false,false,false],//控制时控一开关和光控开关的状态
  15. state1:[false,false],//控制时控二开关的状态
  16. fixed1:"固定",
  17. fixed2:"固定",
  18. fixed3:"固定",
  19. fixed4:"固定",
  20. type1:"",
  21. type2:"",
  22. type3:"",
  23. type4:"",
  24. //时间调控(背景颜色)
  25. timecontrolcolor1:"#888888",
  26. timecontrolcolor2:"#888888",
  27. timecontrolcolor3:"#888888",
  28. timecontrolcolor4:"#888888",
  29. //时间调控(字体颜色)
  30. fontcolor1:"#cccccc",
  31. fontcolor2:"#cccccc",
  32. fontcolor3:"#cccccc",
  33. fontcolor4:"#cccccc",
  34. //固定经纬切换
  35. //日期调控
  36. address:[],
  37. recorddate:"",//记录后台传过来的日期参数
  38. //光控调整
  39. arr:[0],
  40. brr:[0],
  41. index:0,
  42. indexs:0,
  43. Lightcontrolcolor1:"#888888",
  44. Lightcontrolcolor2:"#888888",
  45. fontcolor5:"#cccccc",
  46. fontcolor6:"#cccccc",
  47. select1:"",
  48. select2:"",
  49. //报警状态
  50. radio1:false,
  51. radio2:false,
  52. radio3:false,
  53. alert:"",
  54. //扫码
  55. Title:"",
  56. status:"离线",
  57. zoom:0.8,
  58. },
  59. //扫码
  60. scanCodeEvent: function(){
  61. wx.scanCode({
  62. onlyFromCamera: true,// 只允许从相机扫码
  63. success(res){
  64. var arr = res.split(' ');
  65. var a = arr[0]
  66. var b = arr[1]
  67. wx.request({
  68. url: 'https://api.heclouds.com/devices/' + a,
  69. method:'GET',
  70. header:{
  71. 'api-key':b,
  72. },
  73. success(res){
  74. this.setData({
  75. Title:res.data.title,
  76. statu:res.data.online
  77. })
  78. if(this.data.statu == true){
  79. this.setData({
  80. status:"在线",
  81. })
  82. }
  83. else{
  84. this.setData({
  85. status:"离线"
  86. })
  87. }
  88. }
  89. })
  90. }
  91. })
  92. },
  93. //回路调控
  94. bindPickerChange3:function(e){
  95. this.setData({
  96. indexes: e.detail.value
  97. })
  98. var that = this
  99. wx.request({
  100. url: 'https://api.heclouds.com/devices/' + '773359551' + '/datastreams',
  101. header:{"api-key": 'YhyMeWv90ODkHVsNrwdzlhrwV04='},
  102. method:'GET',
  103. success:(res) => {
  104. let {data} = res.data
  105. //以下为回路
  106. for(let i = 1;i < data.length;i++){
  107. var Indexes = that.data.indexes
  108. Indexes++
  109. //时控一开时间
  110. if(data[i].id == "R"+ Indexes +"_DayOpenTime1"){
  111. var timeopen1 = data[i].current_value
  112. }
  113. //时控一关时间
  114. else if(data[i].id == "R"+ Indexes +"_DayCloseTime1"){
  115. var timeshut1 = data[i].current_value
  116. }
  117. //时控二开时间
  118. else if(data[i].id == "R"+ Indexes +"_DayOpenTime2"){
  119. var timeopen2 = data[i].current_value
  120. }
  121. //时控二关时间
  122. else if(data[i].id == "R"+ Indexes +"_DayCloseTime2"){
  123. var timeshut2 = data[i].current_value
  124. }
  125. //日期调控
  126. else if(data[i].id == "R"+ Indexes +"_Week"){
  127. var weeks = data[i].current_value
  128. that.setData({recorddate:weeks})
  129. weeks = parseInt(weeks)
  130. weeks = weeks.toString(2)
  131. weeks = weeks + ''
  132. weeks = weeks.slice(1)
  133. }
  134. //功能一
  135. else if(data[i].id == "R" + Indexes + "_FunctionStatus1"){
  136. var Function1 = data[i].current_value
  137. var par = parseInt(Function1)
  138. par = par.toString(2)
  139. par = par + ''
  140. switch (par.length) {
  141. case 1:
  142. par = '00000' + par
  143. break;
  144. case 2:
  145. par = '0000' + par
  146. break;
  147. case 3:
  148. par = '000' + par
  149. break;
  150. case 4:
  151. par = '00' + par
  152. break;
  153. case 5:
  154. par = '0' + par
  155. break;
  156. default:
  157. par = par
  158. }
  159. }
  160. //功能二
  161. else if(data[i].id == "R" + Indexes + "_FunctionStatus2"){
  162. var Function2 = data[i].current_value
  163. var qur = parseInt(Function2)
  164. qur = qur.toString(2)
  165. qur = qur + ''
  166. switch (qur.length) {
  167. case 1:
  168. qur = '000' + qur
  169. break;
  170. case 2:
  171. qur = '00' + qur
  172. break;
  173. case 3:
  174. qur = '0' + qur
  175. break;
  176. case 4:
  177. qur = qur
  178. break;
  179. }
  180. }
  181. //报警
  182. else if(data[i].id == "R"+ Indexes +"_RelayStatus"){
  183. var police = data[i].current_value
  184. console.log(police)
  185. }
  186. //光控开
  187. else if(data[i].id == "R" + Indexes + "_LcOn"){
  188. var Lightcontrolopen = data[i].current_value
  189. var trr = that.data.arr
  190. for(let i = 0;i < 100;i++){
  191. trr[i] = i
  192. }
  193. Lightcontrolopen = parseInt(Lightcontrolopen)
  194. that.setData({arr:trr,index:Lightcontrolopen})
  195. }
  196. //光控关
  197. else if(data[i].id == "R" + Indexes +"_LcOff"){
  198. var Lightcontrolshut = data[i].current_value
  199. var prr = that.data.brr
  200. for(let j =0;j < 100;j++){
  201. prr[j] = j
  202. }
  203. Lightcontrolshut = parseInt(Lightcontrolshut)
  204. that.setData({brr:prr,indexs:Lightcontrolshut})
  205. }
  206. }
  207. //时控一开时间
  208. var timeOpen1
  209. switch (timeopen1.length) {
  210. case 1:
  211. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0,1)
  212. break;
  213. case 2:
  214. timeOpen1 = '00' + ':' + timeopen1.substring(0,2)
  215. break;
  216. case 3:
  217. var timeOpen1 = '0' + timeopen1.substring(0,1) + ':' + timeopen1.substring(1,3)
  218. break;
  219. case 4:
  220. var timeOpen1 = timeopen1.substring(0,2) + ':' + timeopen1.substring(2,4)
  221. break;
  222. }
  223. //时控一关时间
  224. var timeShut1
  225. switch (timeshut1.length) {
  226. case 1:
  227. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0,1)
  228. break;
  229. case 2:
  230. timeShut1 = '00' + ':' + timeshut1.substring(0,2)
  231. break;
  232. case 3:
  233. var timeShut1 = '0' + timeshut1.substring(0,1) + ':' + timeshut1.substring(1,3)
  234. break;
  235. case 4:
  236. var timeShut1 = timeshut1.substring(0,2) + ':' + timeshut1.substring(2,4)
  237. break;
  238. }
  239. //时控二开时间
  240. var timeOpen2
  241. switch (timeopen2.length) {
  242. case 1:
  243. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0,1)
  244. break;
  245. case 2:
  246. timeOpen2 = '00' + ':' + timeopen2.substring(0,2)
  247. break;
  248. case 3:
  249. var timeOpen2 = '0' + timeopen2.substring(0,1) + ':' + timeopen2.substring(1,3)
  250. break;
  251. case 4:
  252. var timeOpen2 = timeopen2.substring(0,2) + ':' + timeopen2.substring(2,4)
  253. break;
  254. }
  255. //时控二关时间
  256. var timeShut2
  257. switch (timeshut2.length) {
  258. case 1:
  259. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0,1)
  260. break;
  261. case 2:
  262. timeShut2 = '00' + ':' + timeshut2.substring(0,2)
  263. break;
  264. case 3:
  265. var timeShut2 = '0' + timeshut2.substring(0,1) + ':' + timeshut2.substring(1,3)
  266. break;
  267. case 4:
  268. var timeShut2 = timeshut2.substring(0,2) + ':' + timeshut2.substring(2,4)
  269. break;
  270. }
  271. //功能1
  272. for(var i = 0;i < par.length;i++){
  273. var engry = that.data.state
  274. switch(par.substring(i,i+1)){
  275. case "0":
  276. switch (i) {
  277. case 0:
  278. engry[3] = false
  279. that.setData({state:engry})
  280. break;
  281. case 1:
  282. engry[2] = false
  283. that.setData({state:engry})
  284. break;
  285. case 2:
  286. that.setData({fixed2:"固定"})
  287. break;
  288. case 3:
  289. that.setData({fixed1:"固定"})
  290. break;
  291. case 4:
  292. engry[1] = false
  293. that.setData({state:engry})
  294. break;
  295. case 5:
  296. engry[0] = false
  297. that.setData({state:engry})
  298. break;
  299. }
  300. break;
  301. case "1":
  302. switch (i) {
  303. case 0:
  304. engry[3] = true
  305. that.setData({state:engry})
  306. break;
  307. case 1:
  308. engry[2] = true
  309. that.setData({state:engry})
  310. break;
  311. case 2:
  312. that.setData({fixed2:"经纬"})
  313. break;
  314. case 3:
  315. that.setData({fixed1:"经纬"})
  316. break;
  317. case 4:
  318. engry[1] = true
  319. that.setData({state:engry})
  320. break;
  321. case 5:
  322. engry[0] = true
  323. that.setData({state:engry})
  324. break;
  325. }
  326. break;
  327. }
  328. }
  329. //功能2
  330. for(let j = 0;j < qur.length;j++){
  331. var Engry = that.data.state1
  332. switch(qur.substring(j,j+1)){
  333. case "0":
  334. switch (j) {
  335. case 0:
  336. that.setData({fixed4:"固定"})
  337. break;
  338. case 1:
  339. that.setData({fixed3:"固定"})
  340. break;
  341. case 2:
  342. Engry[1] = false
  343. that.setData({state1:Engry})
  344. break;
  345. case 3:
  346. Engry[0] = false
  347. that.setData({state1:Engry})
  348. break;
  349. }
  350. break;
  351. case "1":
  352. switch (j) {
  353. case 0:
  354. that.setData({fixed4:"经纬"})
  355. break;
  356. case 1:
  357. that.setData({fixed3:"经纬"})
  358. break;
  359. case 2:
  360. Engry[1] = true
  361. that.setData({state1:Engry})
  362. break;
  363. case 3:
  364. Engry[0] = true
  365. console.log(Engry)
  366. that.setData({state1:Engry})
  367. break;
  368. }
  369. break;
  370. }
  371. }
  372. //日期调控
  373. var controladdress = that.data.address
  374. if (weeks == '0') {
  375. for(let x = 0;x < weeks.length; x++){
  376. controladdress[x] = "/image/false.png"
  377. }
  378. that.setData({
  379. address:controladdress,
  380. })
  381. }
  382. else{
  383. for(let i = 0;i < weeks.length;i++){
  384. switch (weeks.substring(i,i+1)) {
  385. case '0':
  386. controladdress[weeks.length-i-1] = "/image/false.png"
  387. that.setData({
  388. address:controladdress,
  389. })
  390. break;
  391. case '1':
  392. controladdress[weeks.length-i-1] = "/image/true.png"
  393. that.setData({
  394. address:controladdress,
  395. })
  396. break;
  397. }
  398. }
  399. }
  400. //报警状态
  401. switch(police){
  402. case "1":
  403. that.setData({radio1:true,alert:"1"})
  404. break;
  405. case "5":
  406. that.setData({radio2:true,alert:"5"})
  407. break;
  408. case "9":
  409. that.setData({radio3:true,alert:"9"})
  410. break;
  411. }
  412. var time = that.data.time
  413. time[0] = timeOpen1
  414. time[1] = timeShut1
  415. time[2] = timeOpen2
  416. time[3] = timeShut2
  417. that.setData({
  418. time:time
  419. })
  420. switch (that.data.state[0]) {
  421. case true:
  422. that.setData({
  423. type1:"time",
  424. timecontrolcolor1:"blue",
  425. fontcolor1:"white",
  426. })
  427. break;
  428. default:
  429. that.setData({
  430. type1:"",
  431. timecontrolcolor1:"#888888",
  432. fontcolor1:"#cccccc",
  433. })
  434. break;
  435. }
  436. switch (that.data.state[1]) {
  437. case true:
  438. that.setData({
  439. type2:"time",
  440. timecontrolcolor2:"blue",
  441. fontcolor2:"white",
  442. })
  443. break;
  444. default:
  445. that.setData({
  446. type2:"",
  447. timecontrolcolor2:"#888888",
  448. fontcolor2:"#cccccc",
  449. })
  450. break;
  451. }
  452. switch (that.data.state1[0]) {
  453. case true:
  454. that.setData({
  455. type3:"time",
  456. timecontrolcolor3:"blue",
  457. fontcolor3:"white",
  458. })
  459. break;
  460. default:
  461. that.setData({
  462. type3:"",
  463. timecontrolcolor3:"#888888",
  464. fontcolor3:"#cccccc",
  465. })
  466. break;
  467. }
  468. switch (that.data.state1[1]) {
  469. case true:
  470. that.setData({
  471. type4:"time",
  472. timecontrolcolor4:"blue",
  473. fontcolor4:"white",
  474. })
  475. break;
  476. default:
  477. that.setData({
  478. type4:"",
  479. timecontrolcolor4:"#888888",
  480. fontcolor4:"#cccccc",
  481. })
  482. break;
  483. }
  484. switch (that.data.state[2]) {
  485. case true:
  486. that.setData({
  487. Lightcontrolcolor1:"blue",
  488. fontcolor5:"white",
  489. select1:"selector"
  490. })
  491. break;
  492. default:
  493. that.setData({
  494. Lightcontrolcolor1:"#888888",
  495. fontcolor5:"#cccccc",
  496. select1:""
  497. })
  498. break;
  499. }
  500. switch (that.data.state[3]) {
  501. case true:
  502. that.setData({
  503. Lightcontrolcolor2:"blue",
  504. fontcolor6:"white",
  505. select2:"selector"
  506. })
  507. break;
  508. default:
  509. that.setData({
  510. Lightcontrolcolor2:"#888888",
  511. fontcolor6:"#cccccc",
  512. select2:""
  513. })
  514. break;
  515. }
  516. }
  517. })
  518. },
  519. //时间调控
  520. //时控开关选择器
  521. Controltime1:function(){
  522. var obtain1 = this.data.state
  523. obtain1[0] = !obtain1[0]
  524. if(obtain1[0] == true){
  525. this.setData({
  526. type1:"time",
  527. timecontrolcolor1:"blue",
  528. fontcolor1:"white",
  529. state:obtain1
  530. })
  531. }
  532. else{
  533. this.setData({
  534. type1:"",
  535. timecontrolcolor1:"#888888",
  536. fontcolor1:"#cccccc",
  537. state:obtain1
  538. })
  539. }
  540. },
  541. Controltime2:function(){
  542. var obtain2 = this.data.state
  543. obtain2[1] = !obtain2[1]
  544. if(obtain2[1] == true){
  545. this.setData({
  546. type2:"time",
  547. timecontrolcolor2:"blue",
  548. fontcolor2:"white",
  549. state:obtain2
  550. })
  551. }
  552. else{
  553. this.setData({
  554. type2:"",
  555. timecontrolcolor2:"#888888",
  556. fontcolor2:"#cccccc",
  557. state:obtain2
  558. })
  559. }
  560. },
  561. Controltime3:function(){
  562. var obtain3 = this.data.state1
  563. obtain3[0] = !obtain3[0]
  564. if(obtain3[0] == true){
  565. this.setData({
  566. type3:"time",
  567. timecontrolcolor3:"blue",
  568. fontcolor3:"white",
  569. state1:obtain3
  570. })
  571. }
  572. else{
  573. this.setData({
  574. type3:"",
  575. timecontrolcolor3:"#888888",
  576. fontcolor3:"#cccccc",
  577. state1:obtain3
  578. })
  579. }
  580. },
  581. Controltime4:function(){
  582. var obtain4 = this.data.state1
  583. obtain4[1] = !obtain4[1]
  584. if(obtain4[1] == true){
  585. this.setData({
  586. type4:"time",
  587. timecontrolcolor4:"blue",
  588. fontcolor4:"white",
  589. state1:obtain4
  590. })
  591. }
  592. else{
  593. this.setData({
  594. type4:"",
  595. timecontrolcolor4:"#888888",
  596. fontcolor4:"#cccccc",
  597. state1:obtain4
  598. })
  599. }
  600. },
  601. //固定与经纬的切换
  602. change1:function(){
  603. var change1 = this.data.fixed1
  604. if (change1 == "固定" && this.data.state[0] == true) {
  605. this.setData({
  606. fixed1:"经纬"
  607. })
  608. }
  609. else if(change1 == "经纬" && this.data.state[0] == true){
  610. this.setData({
  611. fixed1:"固定"
  612. })
  613. }
  614. },
  615. change2:function(){
  616. var change2 = this.data.fixed2
  617. if (change2 == "固定" && this.data.state[1] == true) {
  618. this.setData({
  619. fixed2:"经纬"
  620. })
  621. }
  622. else if(change2 == "经纬" && this.data.state[1] == true){
  623. this.setData({
  624. fixed2:"固定"
  625. })
  626. }
  627. },
  628. change3:function(){
  629. var change3 = this.data.fixed3
  630. if (change3 == "固定") {
  631. this.setData({
  632. fixed3:"经纬"
  633. })
  634. }
  635. else{
  636. this.setData({
  637. fixed3:"固定"
  638. })
  639. }
  640. },
  641. change4:function(){
  642. var change4 = this.data.fixed4
  643. if (change4 == "固定") {
  644. this.setData({
  645. fixed4:"经纬"
  646. })
  647. }
  648. else{
  649. this.setData({
  650. fixed4:"固定"
  651. })
  652. }
  653. },
  654. //显示改变后的时间的值
  655. bindTimeChange1: function(e) {
  656. var time1 = this.data.time
  657. time1[0] = e.detail.value
  658. this.setData({
  659. time: time1
  660. })
  661. },
  662. bindTimeChange2: function(e) {
  663. var time2 = this.data.time
  664. time2[1] = e.detail.value
  665. this.setData({
  666. time:time2
  667. })
  668. },
  669. bindTimeChange3: function(e) {
  670. var time3 = this.data.time
  671. time3[2] = e.detail.value
  672. this.setData({
  673. time:time3
  674. })
  675. },
  676. bindTimeChange4: function(e) {
  677. var time4 = this.data.time
  678. time4[3] = e.detail.value
  679. this.setData({
  680. time:time4
  681. })
  682. },
  683. //日期调控(图片切换)
  684. setbuty0:function(){
  685. var that = this
  686. var a0 = that.data.address
  687. if (that.data.address[0] == "/image/true.png") {
  688. a0[0] = "/image/false.png"
  689. this.setData({
  690. address:a0,
  691. })
  692. } else {
  693. a0[0] = "/image/true.png"
  694. this.setData({
  695. address:a0,
  696. })
  697. }
  698. },
  699. setbuty1:function(){
  700. var that = this
  701. var a1 = that.data.address
  702. if (that.data.address[1] == "/image/true.png") {
  703. a1[1] = "/image/false.png"
  704. this.setData({
  705. address:a1,
  706. })
  707. } else {
  708. a1[1] = "/image/true.png"
  709. this.setData({
  710. address:a1,
  711. })
  712. }
  713. },
  714. setbuty2:function(){
  715. var that = this
  716. var a2 = that.data.address
  717. if (that.data.address[2] == "/image/true.png") {
  718. a2[2] = "/image/false.png"
  719. this.setData({
  720. address:a2,
  721. })
  722. } else {
  723. a2[2] = "/image/true.png"
  724. this.setData({
  725. address:a2,
  726. })
  727. }
  728. },
  729. setbuty3:function(){
  730. var that = this
  731. var a3 = that.data.address
  732. if (that.data.address[3] == "/image/true.png") {
  733. a3[3] = "/image/false.png"
  734. this.setData({
  735. address:a3,
  736. })
  737. } else {
  738. a3[3] = "/image/true.png"
  739. this.setData({
  740. address:a3,
  741. })
  742. }
  743. },
  744. setbuty4:function(){
  745. var that = this
  746. var a4 = that.data.address
  747. if (that.data.address[4] == "/image/true.png") {
  748. a4[4] = "/image/false.png"
  749. this.setData({
  750. address:a4,
  751. })
  752. } else {
  753. a4[4] = "/image/true.png"
  754. this.setData({
  755. address:a4,
  756. })
  757. }
  758. },
  759. setbuty5:function(){
  760. var that = this
  761. var a5 = that.data.address
  762. if (that.data.address[5] == "/image/true.png") {
  763. a5[5] = "/image/false.png"
  764. this.setData({
  765. address:a5,
  766. })
  767. } else {
  768. a5[5] = "/image/true.png"
  769. this.setData({
  770. address:a5,
  771. })
  772. }
  773. },
  774. setbuty6:function(){
  775. var that = this
  776. var a6 = that.data.address
  777. if (that.data.address[6] == "/image/true.png") {
  778. a6[6] = "/image/false.png"
  779. this.setData({
  780. address:a6,
  781. })
  782. } else {
  783. a6[6] = "/image/true.png"
  784. this.setData({
  785. address:a6,
  786. })
  787. }
  788. },
  789. //光控
  790. //光控开关选择器
  791. Controltime5:function(){
  792. var Lightstatus = this.data.state
  793. Lightstatus[2] = !Lightstatus[2]
  794. console.log(Lightstatus[2])
  795. if(Lightstatus[2] == true){
  796. for (let a = 0; a < 100 ;a++){
  797. var arr1 = this.data.arr
  798. arr1[a] = a
  799. }
  800. this.setData({
  801. arr:arr1,
  802. fontcolor5:"white",
  803. Lightcontrolcolor1:"blue",
  804. select1:"selector"
  805. })
  806. }
  807. else{
  808. this.setData({
  809. Lightcontrolcolor1:"#888888",
  810. fontcolor5:"#cccccc",
  811. select1:""
  812. })
  813. }
  814. },
  815. Controltime6:function(){
  816. var Lightstatus = this.data.state
  817. Lightstatus[3] = !Lightstatus[3]
  818. if(Lightstatus[3] == true){
  819. for (let a = 0; a < 100 ;a++){
  820. var arr1 = this.data.arr
  821. arr1[a] = a
  822. }
  823. this.setData({
  824. arr:arr1,
  825. fontcolor6:"white",
  826. Lightcontrolcolor2:"blue",
  827. select2:"selector"
  828. })
  829. }
  830. else{
  831. this.setData({
  832. Lightcontrolcolor2:"#888888",
  833. fontcolor6:"#cccccc",
  834. select2:""
  835. })
  836. }
  837. },
  838. //调整光控显示的值
  839. bindPickerChange1: function(e) {
  840. this.setData({
  841. index: e.detail.value
  842. })
  843. },
  844. bindPickerChange2: function(e) {
  845. this.setData({
  846. indexs: e.detail.value
  847. })
  848. },
  849. //报警状态
  850. Changestate1:function(){
  851. this.setData({
  852. radio1:true,
  853. radio2:false,
  854. radio3:false,
  855. alert:"1"
  856. })
  857. },
  858. Changestate2:function(){
  859. this.setData({
  860. radio1:false,
  861. radio2:true,
  862. radio3:false,
  863. alert:"5"
  864. })
  865. },
  866. Changestate3:function(){
  867. this.setData({
  868. radio1:false,
  869. radio2:false,
  870. radio3:true,
  871. alert:"9"
  872. })
  873. },
  874. //刷新页面
  875. RefreshPage:function(){
  876. var that = this
  877. //日期调控
  878. var Address = that.data.address
  879. for(let q = 0; q < 7; q++){
  880. Address[q] = "/image/false.png"
  881. }
  882. that.setData({
  883. address:Address,
  884. })
  885. wx.request({
  886. url: 'https://api.heclouds.com/devices/' + '773359551' + '/datastreams',
  887. header:{"api-key": 'YhyMeWv90ODkHVsNrwdzlhrwV04='},
  888. method:'GET',
  889. success:(res) => {
  890. let {data} = res.data
  891. //以下为回路
  892. for(let i = 1;i < data.length;i++){
  893. //时控一开时间
  894. if(data[i].id == "R1_DayOpenTime1"){
  895. var timeopen1 = data[i].current_value
  896. }
  897. //时控一关时间
  898. else if(data[i].id == "R1_DayCloseTime1"){
  899. var timeshut1 = data[i].current_value
  900. }
  901. //时控二开时间
  902. else if(data[i].id == "R1_DayOpenTime2"){
  903. var timeopen2 = data[i].current_value
  904. }
  905. //时控二关时间
  906. else if(data[i].id == "R1_DayCloseTime2"){
  907. var timeshut2 = data[i].current_value
  908. }
  909. //日期调控
  910. else if(data[i].id == "R1_Week"){
  911. var weeks = data[i].current_value
  912. that.setData({recorddate:weeks})
  913. weeks = parseInt(weeks)
  914. weeks = weeks.toString(2)
  915. weeks = weeks + ''
  916. weeks = weeks.slice(1)
  917. }
  918. //功能1
  919. else if(data[i].id == "R1_FunctionStatus1"){
  920. var Function1 = data[i].current_value
  921. var par = parseInt(Function1)
  922. par = par.toString(2)
  923. par = par + ''
  924. switch (par.length) {
  925. case 1:
  926. par = '00000' + par
  927. break;
  928. case 2:
  929. par = '0000' + par
  930. break;
  931. case 3:
  932. par = '000' + par
  933. break;
  934. case 4:
  935. par = '00' + par
  936. break;
  937. case 5:
  938. par = '0' + par
  939. break;
  940. default:
  941. par = par
  942. }
  943. }
  944. //功能二
  945. else if(data[i].id == "R1_FunctionStatus2"){
  946. var Function2 = data[i].current_value
  947. var qur = parseInt(Function2)
  948. qur = qur.toString(2)
  949. qur = qur + ''
  950. switch (qur.length) {
  951. case 1:
  952. qur = '000' + qur
  953. break;
  954. case 2:
  955. qur = '00' + qur
  956. break;
  957. case 3:
  958. qur = '0' + qur
  959. break;
  960. case 4:
  961. qur = qur
  962. break;
  963. }
  964. }
  965. //报警
  966. else if(data[i].id == "R1_RelayStatus"){
  967. var police = data[i].current_value
  968. }
  969. //光控开
  970. else if(data[i].id == "R1_LcOn"){
  971. var Lightcontrolopen = data[i].current_value
  972. var trr = that.data.arr
  973. for(let i = 0;i < 100;i++){
  974. trr[i] = i
  975. }
  976. Lightcontrolopen = parseInt(Lightcontrolopen)
  977. that.setData({arr:trr,index:Lightcontrolopen})
  978. }
  979. //光控关
  980. else if(data[i].id == "R1_LcOff"){
  981. var Lightcontrolshut = data[i].current_value
  982. var prr = that.data.brr
  983. for(let j =0;j < 100;j++){
  984. prr[j] = j
  985. }
  986. Lightcontrolshut = parseInt(Lightcontrolshut)
  987. that.setData({brr:prr,indexs:Lightcontrolshut})
  988. }
  989. }
  990. //时控一开时间
  991. var timeOpen1
  992. switch (timeopen1.length) {
  993. case 1:
  994. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0,1)
  995. break;
  996. case 2:
  997. timeOpen1 = '00' + ':' + timeopen1.substring(0,2)
  998. break;
  999. case 3:
  1000. var timeOpen1 = '0' + timeopen1.substring(0,1) + ':' + timeopen1.substring(1,3)
  1001. break;
  1002. case 4:
  1003. var timeOpen1 = timeopen1.substring(0,2) + ':' + timeopen1.substring(2,4)
  1004. break;
  1005. }
  1006. //时控一关时间
  1007. var timeShut1
  1008. switch (timeshut1.length) {
  1009. case 1:
  1010. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0,1)
  1011. break;
  1012. case 2:
  1013. timeShut1 = '00' + ':' + timeshut1.substring(0,2)
  1014. break;
  1015. case 3:
  1016. var timeShut1 = '0' + timeshut1.substring(0,1) + ':' + timeshut1.substring(1,3)
  1017. break;
  1018. case 4:
  1019. var timeShut1 = timeshut1.substring(0,2) + ':' + timeshut1.substring(2,4)
  1020. break;
  1021. }
  1022. //时控二开时间
  1023. var timeOpen2
  1024. switch (timeopen2.length) {
  1025. case 1:
  1026. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0,1)
  1027. break;
  1028. case 2:
  1029. timeOpen2 = '00' + ':' + timeopen2.substring(0,2)
  1030. break;
  1031. case 3:
  1032. var timeOpen2 = '0' + timeopen2.substring(0,1) + ':' + timeopen2.substring(1,3)
  1033. break;
  1034. case 4:
  1035. var timeOpen2 = timeopen2.substring(0,2) + ':' + timeopen2.substring(2,4)
  1036. break;
  1037. }
  1038. //时控二关时间
  1039. var timeShut2
  1040. switch (timeshut2.length) {
  1041. case 1:
  1042. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0,1)
  1043. break;
  1044. case 2:
  1045. timeShut2 = '00' + ':' + timeshut2.substring(0,2)
  1046. break;
  1047. case 3:
  1048. var timeShut2 = '0' + timeshut2.substring(0,1) + ':' + timeshut2.substring(1,3)
  1049. break;
  1050. case 4:
  1051. var timeShut2 = timeshut2.substring(0,2) + ':' + timeshut2.substring(2,4)
  1052. break;
  1053. }
  1054. //功能1
  1055. for(var i = 0;i < par.length;i++){
  1056. var engry = that.data.state
  1057. switch(par.substring(i,i+1)){
  1058. case "0":
  1059. switch (i) {
  1060. case 0:
  1061. engry[3] = false
  1062. that.setData({state:engry})
  1063. break;
  1064. case 1:
  1065. engry[2] = false
  1066. that.setData({state:engry})
  1067. break;
  1068. case 2:
  1069. that.setData({fixed2:"固定"})
  1070. break;
  1071. case 3:
  1072. that.setData({fixed1:"固定"})
  1073. break;
  1074. case 4:
  1075. engry[1] = false
  1076. that.setData({state:engry})
  1077. break;
  1078. case 5:
  1079. engry[0] = false
  1080. that.setData({state:engry})
  1081. break;
  1082. }
  1083. break;
  1084. case "1":
  1085. switch (i) {
  1086. case 0:
  1087. engry[3] = true
  1088. that.setData({state:engry})
  1089. break;
  1090. case 1:
  1091. engry[2] = true
  1092. that.setData({state:engry})
  1093. break;
  1094. case 2:
  1095. that.setData({fixed2:"经纬"})
  1096. break;
  1097. case 3:
  1098. that.setData({fixed1:"经纬"})
  1099. break;
  1100. case 4:
  1101. engry[1] = true
  1102. that.setData({state:engry})
  1103. break;
  1104. case 5:
  1105. engry[0] = true
  1106. that.setData({state:engry})
  1107. break;
  1108. }
  1109. break;
  1110. }
  1111. }
  1112. //功能2
  1113. for(let j = 0;j < qur.length;j++){
  1114. var Engry = that.data.state1
  1115. switch(qur.substring(j,j+1)){
  1116. case "0":
  1117. switch (j) {
  1118. case 0:
  1119. that.setData({fixed4:"固定"})
  1120. break;
  1121. case 1:
  1122. that.setData({fixed3:"固定"})
  1123. break;
  1124. case 2:
  1125. Engry[1] = false
  1126. that.setData({state1:Engry})
  1127. break;
  1128. case 3:
  1129. Engry[0] = false
  1130. that.setData({state1:Engry})
  1131. break;
  1132. }
  1133. break;
  1134. case "1":
  1135. switch (j) {
  1136. case 0:
  1137. that.setData({fixed4:"经纬"})
  1138. break;
  1139. case 1:
  1140. that.setData({fixed3:"经纬"})
  1141. break;
  1142. case 2:
  1143. Engry[1] = true
  1144. that.setData({state1:Engry})
  1145. break;
  1146. case 3:
  1147. Engry[0] = true
  1148. console.log(Engry)
  1149. that.setData({state1:Engry})
  1150. break;
  1151. }
  1152. break;
  1153. }
  1154. }
  1155. //日期调控
  1156. var controladdress = that.data.address
  1157. if (weeks == '0') {
  1158. for(let x = 0;x < weeks.length; x++){
  1159. controladdress[x] = "/image/false.png"
  1160. }
  1161. that.setData({
  1162. address:controladdress,
  1163. })
  1164. }
  1165. else{
  1166. for(let i = 0;i < weeks.length;i++){
  1167. switch (weeks.substring(i,i+1)) {
  1168. case '0':
  1169. controladdress[weeks.length-i-1] = "/image/false.png"
  1170. that.setData({
  1171. address:controladdress,
  1172. })
  1173. break;
  1174. case '1':
  1175. controladdress[weeks.length-i-1] = "/image/true.png"
  1176. that.setData({
  1177. address:controladdress,
  1178. })
  1179. break;
  1180. }
  1181. }
  1182. }
  1183. //报警状态
  1184. switch(police){
  1185. case "1":
  1186. that.setData({radio1:true,alert:"1"})
  1187. break;
  1188. case "5":
  1189. that.setData({radio2:true,alert:"5"})
  1190. break;
  1191. case "9":
  1192. that.setData({radio3:true,alert:"9"})
  1193. break;
  1194. }
  1195. var time = that.data.time
  1196. time[0] = timeOpen1
  1197. time[1] = timeShut1
  1198. time[2] = timeOpen2
  1199. time[3] = timeShut2
  1200. that.setData({
  1201. time:time,
  1202. })
  1203. //监视开关状态(改变颜色,调整功能)
  1204. switch (that.data.state[0]) {
  1205. case true:
  1206. that.setData({
  1207. type1:"time",
  1208. timecontrolcolor1:"blue",
  1209. fontcolor1:"white",
  1210. })
  1211. break;
  1212. default:
  1213. that.setData({
  1214. type1:"",
  1215. timecontrolcolor1:"#888888",
  1216. fontcolor1:"#cccccc",
  1217. })
  1218. break;
  1219. }
  1220. switch (that.data.state[1]) {
  1221. case true:
  1222. that.setData({
  1223. type2:"time",
  1224. timecontrolcolor2:"blue",
  1225. fontcolor2:"white",
  1226. })
  1227. break;
  1228. default:
  1229. that.setData({
  1230. type2:"",
  1231. timecontrolcolor2:"#888888",
  1232. fontcolor2:"#cccccc",
  1233. })
  1234. break;
  1235. }
  1236. switch (that.data.state1[0]) {
  1237. case true:
  1238. that.setData({
  1239. type3:"time",
  1240. timecontrolcolor3:"blue",
  1241. fontcolor3:"white",
  1242. })
  1243. break;
  1244. default:
  1245. that.setData({
  1246. type3:"",
  1247. timecontrolcolor3:"#888888",
  1248. fontcolor3:"#cccccc",
  1249. })
  1250. break;
  1251. }
  1252. switch (that.data.state1[1]) {
  1253. case true:
  1254. that.setData({
  1255. type4:"time",
  1256. timecontrolcolor4:"blue",
  1257. fontcolor4:"white",
  1258. })
  1259. break;
  1260. default:
  1261. that.setData({
  1262. type4:"",
  1263. timecontrolcolor4:"#888888",
  1264. fontcolor4:"#cccccc",
  1265. })
  1266. break;
  1267. }
  1268. switch (that.data.state[2]) {
  1269. case true:
  1270. that.setData({
  1271. Lightcontrolcolor1:"blue",
  1272. fontcolor5:"white",
  1273. select1:"selector"
  1274. })
  1275. break;
  1276. default:
  1277. that.setData({
  1278. Lightcontrolcolor1:"#888888",
  1279. fontcolor5:"#cccccc",
  1280. select1:""
  1281. })
  1282. break;
  1283. }
  1284. switch (that.data.state[3]) {
  1285. case true:
  1286. that.setData({
  1287. Lightcontrolcolor2:"blue",
  1288. fontcolor6:"white",
  1289. select2:"selector"
  1290. })
  1291. break;
  1292. default:
  1293. that.setData({
  1294. Lightcontrolcolor2:"#888888",
  1295. fontcolor6:"#cccccc",
  1296. select2:""
  1297. })
  1298. break;
  1299. }
  1300. }
  1301. })
  1302. },
  1303. //存储数据
  1304. Storedata: function(){
  1305. var that = this
  1306. //功能一
  1307. var Storagetimeopen1
  1308. var Storagetimeshut1
  1309. var Storagetimeopenstate1
  1310. var Storagetimeshutstate1
  1311. var Storageopticalopen
  1312. var Storageopticalshut
  1313. //时控一开
  1314. switch(that.data.state[0]){
  1315. case true:
  1316. Storagetimeopen1 = "1"
  1317. break;
  1318. case false:
  1319. Storagetimeopen1 = "0"
  1320. break;
  1321. }
  1322. //时控一关
  1323. switch(that.data.state[1]){
  1324. case true:
  1325. Storagetimeshut1 = "1"
  1326. break;
  1327. case false:
  1328. Storagetimeshut1 = "0"
  1329. break;
  1330. }
  1331. //时控一开经纬
  1332. switch (that.data.fixed1) {
  1333. case "经纬":
  1334. Storagetimeopenstate1 = "1"
  1335. break;
  1336. case "固定":
  1337. Storagetimeopenstate1 = "0"
  1338. break;
  1339. }
  1340. //时控一关经纬
  1341. switch (that.data.fixed2) {
  1342. case "经纬":
  1343. Storagetimeshutstate1 = "1"
  1344. break;
  1345. case "固定":
  1346. Storagetimeshutstate1 = "0"
  1347. break;
  1348. }
  1349. //光控开
  1350. switch (that.data.state[2]) {
  1351. case true:
  1352. Storageopticalopen = "1"
  1353. break;
  1354. case false:
  1355. Storageopticalopen = "0"
  1356. break;
  1357. }
  1358. //光控关
  1359. switch (that.data.state[3]) {
  1360. case true:
  1361. Storageopticalshut = "1"
  1362. break;
  1363. case false:
  1364. Storageopticalshut = "0"
  1365. break;
  1366. }
  1367. var use1 = Storageopticalshut + Storageopticalopen + Storagetimeshutstate1 + Storagetimeopenstate1 + Storagetimeshut1 + Storagetimeopen1
  1368. use1 = parseInt(use1,2)
  1369. use1 = use1 + ''//传给后台的功能一数据
  1370. //功能二
  1371. var Storagetimeopen2
  1372. var Storagetimeshut2
  1373. var Storagetimeopenstate2
  1374. var Storagetimeshutstate2
  1375. //时控二开
  1376. switch (that.data.state1[0]) {
  1377. case true:
  1378. Storagetimeopen2 = "1"
  1379. break;
  1380. case false:
  1381. Storagetimeopen2 = "0"
  1382. break;
  1383. }
  1384. //时控二关
  1385. switch (that.data.state1[1]) {
  1386. case true:
  1387. Storagetimeshut2 = "1"
  1388. break;
  1389. case false:
  1390. Storagetimeshut2 = "0"
  1391. break;
  1392. }
  1393. //时控二开经纬
  1394. switch (that.data.fixed3) {
  1395. case "经纬":
  1396. Storagetimeopenstate2 = "1"
  1397. break;
  1398. case "固定":
  1399. Storagetimeopenstate2 = "0"
  1400. break;
  1401. }
  1402. //时控二关经纬
  1403. switch (that.data.fixed4) {
  1404. case "经纬":
  1405. Storagetimeshutstate2 = "1"
  1406. break;
  1407. case "固定":
  1408. Storagetimeshutstate2 = "0"
  1409. break;
  1410. }
  1411. var use2 = Storagetimeshutstate2 + Storagetimeopenstate2 + Storagetimeshut2 + Storagetimeopen2
  1412. use2 = parseInt(use2,2)
  1413. use2 = use2 + ''//传给后台的功能二数据
  1414. //时控一开时间
  1415. var Ontime1 = that.data.time[0]
  1416. var ontime1//传给后台的时控一开时间
  1417. if (Ontime1.substring(0,2) == '00' && Ontime1.substring(3,5) == '00') {
  1418. ontime1 = '0'
  1419. }
  1420. else if (Ontime1.substring(0,1) != '0') {
  1421. ontime1 = Ontime1.substring(0,2) + Ontime1.substring(3,5)
  1422. }
  1423. else if (Ontime1.substring(0,1) == '0' && Ontime1.substring(1,2) != '0' ) {
  1424. ontime1 = Ontime1.substring(1,2) + Ontime1.substring(3,5)
  1425. }
  1426. else if (Ontime1.substring(0,2) == '00' && Ontime1.substring(3,4) != '0') {
  1427. ontime1 = Ontime1.substring(3,5)
  1428. }
  1429. else{
  1430. ontime1 = Ontime1.substring(4,5)
  1431. }
  1432. //时控一关时间
  1433. var Closingtime1 = that.data.time[1]
  1434. var closingtime1//传给后台的时控一关时间
  1435. if (Closingtime1.substring(0,2) == '00' && Closingtime1.substring(3,5) == '00') {
  1436. closingtime1 = '0'
  1437. }
  1438. else if (Closingtime1.substring(0,1) != '0') {
  1439. closingtime1 = Closingtime1.substring(0,2) + Closingtime1.substring(3,5)
  1440. }
  1441. else if (Closingtime1.substring(0,1) == '0' && Closingtime1.substring(1,2) != '0' ) {
  1442. closingtime1 = Closingtime1.substring(1,2) + Closingtime1.substring(3,5)
  1443. }
  1444. else if (Closingtime1.substring(0,2) == '00' && Closingtime1.substring(3,4) != '0') {
  1445. closingtime1 = Closingtime1.substring(3,5)
  1446. }
  1447. else{
  1448. closingtime1 = Closingtime1.substring(4,5)
  1449. }
  1450. //时控二开时间
  1451. var Ontime2 = that.data.time[2]
  1452. var ontime2//传给后台的时控二开时间
  1453. if (Ontime2.substring(0,2) == '00' && Ontime2.substring(3,5) == '00') {
  1454. ontime2 = '0'
  1455. }
  1456. else if (Ontime2.substring(0,1) != '0') {
  1457. ontime2 = Ontime2.substring(0,2) + Ontime2.substring(3,5)
  1458. }
  1459. else if (Ontime2.substring(0,1) == '0' && Ontime2.substring(1,2) != '0' ) {
  1460. ontime2 = Ontime2.substring(1,2) + Ontime2.substring(3,5)
  1461. }
  1462. else if (Ontime2.substring(0,2) == '00' && Ontime2.substring(3,4) != '0') {
  1463. ontime2 = Ontime2.substring(3,5)
  1464. }
  1465. else{
  1466. ontime2 = Ontime2.substring(4,5)
  1467. }
  1468. //时控二关时间
  1469. var Closingtime2 = that.data.time[3]
  1470. var closingtime2//传给后台的时控二关时间
  1471. if (Closingtime2.substring(0,2) == '00' && Closingtime2.substring(3,5) == '00') {
  1472. closingtime2 = '0'
  1473. }
  1474. else if (Closingtime2.substring(0,1) != '0') {
  1475. closingtime2 = Closingtime2.substring(0,2) + Closingtime2.substring(3,5)
  1476. }
  1477. else if (Closingtime2.substring(0,1) == '0' && Closingtime2.substring(1,2) != '0' ) {
  1478. closingtime2 = Closingtime2.substring(1,2) + Closingtime2.substring(3,5)
  1479. }
  1480. else if (Closingtime2.substring(0,2) == '00' && Closingtime2.substring(3,4) != '0') {
  1481. closingtime2 = Closingtime2.substring(3,5)
  1482. }
  1483. else{
  1484. closingtime2 = Closingtime2.substring(4,5)
  1485. }
  1486. //报警状态
  1487. var alerts = that.data.alert
  1488. //光控开
  1489. var Lightcontrolon = that.data.arr[that.data.index]
  1490. Lightcontrolon = Lightcontrolon + ''
  1491. //光控关
  1492. var Lightcontroloff = that.data.brr[that.data.indexs]
  1493. Lightcontroloff = Lightcontroloff + ''
  1494. //星期
  1495. var myweek = ""
  1496. for(let w = 0;w < that.data.address.length;w++){
  1497. switch (that.data.address[w]) {
  1498. case "/image/false.png":
  1499. myweek = myweek.concat("0")
  1500. break;
  1501. default:
  1502. myweek = myweek.concat("1")
  1503. break;
  1504. }
  1505. }
  1506. if (myweek == "0000000") {
  1507. myweek = "0"
  1508. }
  1509. else{
  1510. myweek = "1" + myweek.split("").reverse().join("")
  1511. myweek = parseInt(myweek,2)
  1512. myweek = myweek
  1513. }
  1514. console.log(myweek)
  1515. //发起post请求
  1516. if(this.data.status == "在线"){
  1517. wx.request({
  1518. url: 'https://api.heclouds.com/cmds?device_id=' + 773359551,
  1519. method:'POST',
  1520. header:{"api-key":"YhyMeWv90ODkHVsNrwdzlhrwV04="},
  1521. data:{
  1522. "R1_Week":myweek,
  1523. },
  1524. success:function(res){
  1525. console.log(res)
  1526. }
  1527. })
  1528. }
  1529. else{
  1530. wx.showModal({
  1531. title:'提示',
  1532. content:'存储数据失败,请检查设备是否在线或者刷新页面',
  1533. showCancel:false,
  1534. })
  1535. }
  1536. },
  1537. /**
  1538. * 生命周期函数--监听页面加载
  1539. */
  1540. onLoad(options) {
  1541. var that = this
  1542. // wx.showToast({
  1543. // title: '获取数据中',
  1544. // duration:'2000',
  1545. // icon:'success',
  1546. // mask: true
  1547. // })
  1548. //获取机型改变switch大小
  1549. wx.getSystemInfo({
  1550. success:function(res){
  1551. if(res.model == 'iPad' || res.model == 'iPad Pro 10.5-inch' || res.model == 'iPad Pro 12.9-inch'){
  1552. console.log('修改开关')
  1553. that.setData({
  1554. zoom:1
  1555. })
  1556. }
  1557. }
  1558. })
  1559. wx.request({
  1560. url: 'https://api.heclouds.com/devices/' + '773359551',
  1561. method:'GET',
  1562. header:{"api-key": 'YhyMeWv90ODkHVsNrwdzlhrwV04='},
  1563. success:(res) =>{
  1564. if (res.data.data.online == true) {
  1565. that.setData({
  1566. status:"在线"
  1567. })
  1568. }
  1569. else{
  1570. that.setData({
  1571. status:"离线"
  1572. })
  1573. }
  1574. }
  1575. })
  1576. //日期调控
  1577. var Address = that.data.address
  1578. for(let q = 0; q < 7; q++){
  1579. Address[q] = "/image/false.png"
  1580. }
  1581. that.setData({
  1582. address:Address,
  1583. })
  1584. wx.request({
  1585. url: 'https://api.heclouds.com/devices/' + '773359551' + '/datastreams',
  1586. header:{"api-key": 'YhyMeWv90ODkHVsNrwdzlhrwV04='},
  1587. method:'GET',
  1588. success:(res) => {
  1589. let {data} = res.data
  1590. //以下为回路
  1591. for(let i = 1;i < data.length;i++){
  1592. //时控一开时间
  1593. if(data[i].id == "R1_DayOpenTime1"){
  1594. var timeopen1 = data[i].current_value
  1595. }
  1596. //时控一关时间
  1597. else if(data[i].id == "R1_DayCloseTime1"){
  1598. var timeshut1 = data[i].current_value
  1599. }
  1600. //时控二开时间
  1601. else if(data[i].id == "R1_DayOpenTime2"){
  1602. var timeopen2 = data[i].current_value
  1603. }
  1604. //时控二关时间
  1605. else if(data[i].id == "R1_DayCloseTime2"){
  1606. var timeshut2 = data[i].current_value
  1607. }
  1608. //日期调控
  1609. else if(data[i].id == "R1_Week"){
  1610. var weeks = data[i].current_value
  1611. that.setData({recorddate:weeks})
  1612. weeks = parseInt(weeks)
  1613. weeks = weeks.toString(2)
  1614. weeks = weeks + ''
  1615. weeks = weeks.slice(1)
  1616. }
  1617. //功能1
  1618. else if(data[i].id == "R1_FunctionStatus1"){
  1619. var Function1 = data[i].current_value
  1620. var par = parseInt(Function1)
  1621. par = par.toString(2)
  1622. par = par + ''
  1623. switch (par.length) {
  1624. case 1:
  1625. par = '00000' + par
  1626. break;
  1627. case 2:
  1628. par = '0000' + par
  1629. break;
  1630. case 3:
  1631. par = '000' + par
  1632. break;
  1633. case 4:
  1634. par = '00' + par
  1635. break;
  1636. case 5:
  1637. par = '0' + par
  1638. break;
  1639. default:
  1640. par = par
  1641. }
  1642. }
  1643. //功能二
  1644. else if(data[i].id == "R1_FunctionStatus2"){
  1645. var Function2 = data[i].current_value
  1646. var qur = parseInt(Function2)
  1647. qur = qur.toString(2)
  1648. qur = qur + ''
  1649. switch (qur.length) {
  1650. case 1:
  1651. qur = '000' + qur
  1652. break;
  1653. case 2:
  1654. qur = '00' + qur
  1655. break;
  1656. case 3:
  1657. qur = '0' + qur
  1658. break;
  1659. case 4:
  1660. qur = qur
  1661. break;
  1662. }
  1663. }
  1664. //报警
  1665. else if(data[i].id == "R1_RelayStatus"){
  1666. var police = data[i].current_value
  1667. }
  1668. //光控开
  1669. else if(data[i].id == "R1_LcOn"){
  1670. var Lightcontrolopen = data[i].current_value
  1671. var trr = that.data.arr
  1672. for(let i = 0;i < 100;i++){
  1673. trr[i] = i
  1674. }
  1675. Lightcontrolopen = parseInt(Lightcontrolopen)
  1676. that.setData({arr:trr,index:Lightcontrolopen})
  1677. }
  1678. //光控关
  1679. else if(data[i].id == "R1_LcOff"){
  1680. var Lightcontrolshut = data[i].current_value
  1681. var prr = that.data.brr
  1682. for(let j =0;j < 100;j++){
  1683. prr[j] = j
  1684. }
  1685. Lightcontrolshut = parseInt(Lightcontrolshut)
  1686. that.setData({brr:prr,indexs:Lightcontrolshut})
  1687. }
  1688. }
  1689. //时控一开时间
  1690. var timeOpen1
  1691. switch (timeopen1.length) {
  1692. case 1:
  1693. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0,1)
  1694. break;
  1695. case 2:
  1696. timeOpen1 = '00' + ':' + timeopen1.substring(0,2)
  1697. break;
  1698. case 3:
  1699. var timeOpen1 = '0' + timeopen1.substring(0,1) + ':' + timeopen1.substring(1,3)
  1700. break;
  1701. case 4:
  1702. var timeOpen1 = timeopen1.substring(0,2) + ':' + timeopen1.substring(2,4)
  1703. break;
  1704. }
  1705. //时控一关时间
  1706. var timeShut1
  1707. switch (timeshut1.length) {
  1708. case 1:
  1709. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0,1)
  1710. break;
  1711. case 2:
  1712. timeShut1 = '00' + ':' + timeshut1.substring(0,2)
  1713. break;
  1714. case 3:
  1715. var timeShut1 = '0' + timeshut1.substring(0,1) + ':' + timeshut1.substring(1,3)
  1716. break;
  1717. case 4:
  1718. var timeShut1 = timeshut1.substring(0,2) + ':' + timeshut1.substring(2,4)
  1719. break;
  1720. }
  1721. //时控二开时间
  1722. var timeOpen2
  1723. switch (timeopen2.length) {
  1724. case 1:
  1725. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0,1)
  1726. break;
  1727. case 2:
  1728. timeOpen2 = '00' + ':' + timeopen2.substring(0,2)
  1729. break;
  1730. case 3:
  1731. var timeOpen2 = '0' + timeopen2.substring(0,1) + ':' + timeopen2.substring(1,3)
  1732. break;
  1733. case 4:
  1734. var timeOpen2 = timeopen2.substring(0,2) + ':' + timeopen2.substring(2,4)
  1735. break;
  1736. }
  1737. //时控二关时间
  1738. var timeShut2
  1739. switch (timeshut2.length) {
  1740. case 1:
  1741. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0,1)
  1742. break;
  1743. case 2:
  1744. timeShut2 = '00' + ':' + timeshut2.substring(0,2)
  1745. break;
  1746. case 3:
  1747. var timeShut2 = '0' + timeshut2.substring(0,1) + ':' + timeshut2.substring(1,3)
  1748. break;
  1749. case 4:
  1750. var timeShut2 = timeshut2.substring(0,2) + ':' + timeshut2.substring(2,4)
  1751. break;
  1752. }
  1753. //功能1
  1754. for(var i = 0;i < par.length;i++){
  1755. var engry = that.data.state
  1756. switch(par.substring(i,i+1)){
  1757. case "0":
  1758. switch (i) {
  1759. case 0:
  1760. engry[3] = false
  1761. that.setData({state:engry})
  1762. break;
  1763. case 1:
  1764. engry[2] = false
  1765. that.setData({state:engry})
  1766. break;
  1767. case 2:
  1768. that.setData({fixed2:"固定"})
  1769. break;
  1770. case 3:
  1771. that.setData({fixed1:"固定"})
  1772. break;
  1773. case 4:
  1774. engry[1] = false
  1775. that.setData({state:engry})
  1776. break;
  1777. case 5:
  1778. engry[0] = false
  1779. that.setData({state:engry})
  1780. break;
  1781. }
  1782. break;
  1783. case "1":
  1784. switch (i) {
  1785. case 0:
  1786. engry[3] = true
  1787. that.setData({state:engry})
  1788. break;
  1789. case 1:
  1790. engry[2] = true
  1791. that.setData({state:engry})
  1792. break;
  1793. case 2:
  1794. that.setData({fixed2:"经纬"})
  1795. break;
  1796. case 3:
  1797. that.setData({fixed1:"经纬"})
  1798. break;
  1799. case 4:
  1800. engry[1] = true
  1801. that.setData({state:engry})
  1802. break;
  1803. case 5:
  1804. engry[0] = true
  1805. that.setData({state:engry})
  1806. break;
  1807. }
  1808. break;
  1809. }
  1810. }
  1811. //功能2
  1812. for(let j = 0;j < qur.length;j++){
  1813. var Engry = that.data.state1
  1814. switch(qur.substring(j,j+1)){
  1815. case "0":
  1816. switch (j) {
  1817. case 0:
  1818. that.setData({fixed4:"固定"})
  1819. break;
  1820. case 1:
  1821. that.setData({fixed3:"固定"})
  1822. break;
  1823. case 2:
  1824. Engry[1] = false
  1825. that.setData({state1:Engry})
  1826. break;
  1827. case 3:
  1828. Engry[0] = false
  1829. that.setData({state1:Engry})
  1830. break;
  1831. }
  1832. break;
  1833. case "1":
  1834. switch (j) {
  1835. case 0:
  1836. that.setData({fixed4:"经纬"})
  1837. break;
  1838. case 1:
  1839. that.setData({fixed3:"经纬"})
  1840. break;
  1841. case 2:
  1842. Engry[1] = true
  1843. that.setData({state1:Engry})
  1844. break;
  1845. case 3:
  1846. Engry[0] = true
  1847. console.log(Engry)
  1848. that.setData({state1:Engry})
  1849. break;
  1850. }
  1851. break;
  1852. }
  1853. }
  1854. //日期调控
  1855. var controladdress = that.data.address
  1856. if (weeks == '0') {
  1857. for(let x = 0;x < weeks.length; x++){
  1858. controladdress[x] = "/image/false.png"
  1859. }
  1860. that.setData({
  1861. address:controladdress,
  1862. })
  1863. }
  1864. else{
  1865. for(let i = 0;i < weeks.length;i++){
  1866. switch (weeks.substring(i,i+1)) {
  1867. case '0':
  1868. controladdress[weeks.length-i-1] = "/image/false.png"
  1869. that.setData({
  1870. address:controladdress,
  1871. })
  1872. break;
  1873. case '1':
  1874. controladdress[weeks.length-i-1] = "/image/true.png"
  1875. that.setData({
  1876. address:controladdress,
  1877. })
  1878. break;
  1879. }
  1880. }
  1881. }
  1882. //报警状态
  1883. switch(police){
  1884. case "1":
  1885. that.setData({radio1:true,alert:"1"})
  1886. break;
  1887. case "5":
  1888. that.setData({radio2:true,alert:"5"})
  1889. break;
  1890. case "9":
  1891. that.setData({radio3:true,alert:"9"})
  1892. break;
  1893. }
  1894. var time = that.data.time
  1895. time[0] = timeOpen1
  1896. time[1] = timeShut1
  1897. time[2] = timeOpen2
  1898. time[3] = timeShut2
  1899. that.setData({
  1900. time:time,
  1901. })
  1902. //监视开关状态(改变颜色,调整功能)
  1903. switch (that.data.state[0]) {
  1904. case true:
  1905. that.setData({
  1906. type1:"time",
  1907. timecontrolcolor1:"blue",
  1908. fontcolor1:"white",
  1909. })
  1910. break;
  1911. default:
  1912. that.setData({
  1913. type1:"",
  1914. timecontrolcolor1:"#888888",
  1915. fontcolor1:"#cccccc",
  1916. })
  1917. break;
  1918. }
  1919. switch (that.data.state[1]) {
  1920. case true:
  1921. that.setData({
  1922. type2:"time",
  1923. timecontrolcolor2:"blue",
  1924. fontcolor2:"white",
  1925. })
  1926. break;
  1927. default:
  1928. that.setData({
  1929. type2:"",
  1930. timecontrolcolor2:"#888888",
  1931. fontcolor2:"#cccccc",
  1932. })
  1933. break;
  1934. }
  1935. switch (that.data.state1[0]) {
  1936. case true:
  1937. that.setData({
  1938. type3:"time",
  1939. timecontrolcolor3:"blue",
  1940. fontcolor3:"white",
  1941. })
  1942. break;
  1943. default:
  1944. that.setData({
  1945. type3:"",
  1946. timecontrolcolor3:"#888888",
  1947. fontcolor3:"#cccccc",
  1948. })
  1949. break;
  1950. }
  1951. switch (that.data.state1[1]) {
  1952. case true:
  1953. that.setData({
  1954. type4:"time",
  1955. timecontrolcolor4:"blue",
  1956. fontcolor4:"white",
  1957. })
  1958. break;
  1959. default:
  1960. that.setData({
  1961. type4:"",
  1962. timecontrolcolor4:"#888888",
  1963. fontcolor4:"#cccccc",
  1964. })
  1965. break;
  1966. }
  1967. switch (that.data.state[2]) {
  1968. case true:
  1969. that.setData({
  1970. Lightcontrolcolor1:"blue",
  1971. fontcolor5:"white",
  1972. select1:"selector"
  1973. })
  1974. break;
  1975. default:
  1976. that.setData({
  1977. Lightcontrolcolor1:"#888888",
  1978. fontcolor5:"#cccccc",
  1979. select1:""
  1980. })
  1981. break;
  1982. }
  1983. switch (that.data.state[3]) {
  1984. case true:
  1985. that.setData({
  1986. Lightcontrolcolor2:"blue",
  1987. fontcolor6:"white",
  1988. select2:"selector"
  1989. })
  1990. break;
  1991. default:
  1992. that.setData({
  1993. Lightcontrolcolor2:"#888888",
  1994. fontcolor6:"#cccccc",
  1995. select2:""
  1996. })
  1997. break;
  1998. }
  1999. }
  2000. })
  2001. },
  2002. /**
  2003. * 生命周期函数--监听页面初次渲染完成
  2004. */
  2005. onReady() {
  2006. },
  2007. /**
  2008. * 生命周期函数--监听页面显示
  2009. */
  2010. onShow() {
  2011. // let setloop = getApp().globalData.setloop
  2012. // this.setData({crr:setloop})
  2013. },
  2014. /**
  2015. * 生命周期函数--监听页面隐藏
  2016. */
  2017. onHide() {
  2018. },
  2019. /**
  2020. * 生命周期函数--监听页面卸载
  2021. */
  2022. onUnload() {
  2023. },
  2024. /**
  2025. * 页面相关事件处理函数--监听用户下拉动作
  2026. */
  2027. onPullDownRefresh() {
  2028. },
  2029. /**
  2030. * 页面上拉触底事件的处理函数
  2031. */
  2032. onReachBottom() {
  2033. },
  2034. /**
  2035. * 用户点击右上角分享
  2036. */
  2037. onShareAppMessage() {
  2038. }
  2039. })