loop.js 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504
  1. // pages/loop/loop.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. array:[],
  8. //回路调控
  9. crr:[],
  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:["/image/false.png","/image/false.png","/image/false.png","/image/false.png","/image/false.png",
  37. "/image/false.png","/image/false.png","/image/false.png"],
  38. recorddate:"",//记录后台传过来的日期参数
  39. //光控调整
  40. arr:[0],
  41. brr:[0],
  42. index:0,
  43. indexs:0,
  44. Lightcontrolcolor1:"#888888",
  45. Lightcontrolcolor2:"#888888",
  46. fontcolor5:"#cccccc",
  47. fontcolor6:"#cccccc",
  48. select1:"",
  49. select2:"",
  50. //报警状态
  51. radio1:false,
  52. radio2:false,
  53. radio3:false,
  54. alert:"",
  55. //扫码
  56. Title:"",
  57. status:"离线",
  58. zoom:0.8,
  59. Modecontrol:"",
  60. groupName:[],
  61. deviceName:[],
  62. groupIndex:0,
  63. deviceIndex:0,
  64. deviceId:'',
  65. deviceKey:'',
  66. num:0,//记录回路数量
  67. play:1,//新老设备的页面切换
  68. timeValue:'00:00',
  69. },
  70. //分组下拉
  71. changegroup:function(e){
  72. var that = this
  73. that.setData({groupIndex:e.detail.value})
  74. wx.setStorageSync('groupIndex', e.detail.value)
  75. var groupName = that.data.groupName[that.data.groupIndex]//选择的分组名称
  76. wx.setStorageSync('groupName',groupName)//将修改的分组名称放入缓存
  77. //获取设备名称下拉
  78. var group = wx.getStorageSync('group')
  79. var deviceName = that.data.deviceName
  80. var deviceName = []
  81. for(let i = 0;i < group.length;i++){
  82. if(group[i].groupName == groupName){
  83. if(group[i].devices != null){
  84. wx.showToast({
  85. title:'刷新中',
  86. icon:'loading',
  87. duration: 2000
  88. })
  89. for(let j = 0;j < group[i].devices.length;j++){
  90. deviceName.push(group[i].devices[j].deviceName)
  91. }
  92. }
  93. else{
  94. wx.showModal({
  95. title:'提示',
  96. content:'工程中不存在设备',
  97. showCancel:false
  98. })
  99. console.log('回路分组下拉到没有设备的工程')
  100. that.setData({status:'离线'})
  101. }
  102. }
  103. }
  104. that.setData({
  105. deviceName:deviceName
  106. })
  107. //重新获取设备id和key
  108. if(that.data.deviceName.length != 0){
  109. var groupNames = that.data.groupName[that.data.groupIndex]
  110. var deviceNames = that.data.deviceName[that.data.deviceIndex]
  111. for(let d = 0;d < group.length;d++){
  112. if(groupNames == group[d].groupName){
  113. for(let g = 0;g < group[d].devices.length;g++){
  114. if(deviceNames == group[d].devices[g].deviceName){
  115. var deviceId = group[d].devices[g].deviceId
  116. var deviceKey = group[d].devices[g].deviceKey
  117. var loopnum = group[d].devices[g].circuits
  118. }
  119. }
  120. }
  121. }
  122. wx.setStorageSync('deviceName',deviceNames)//将修改设备名放入缓存
  123. that.setData({
  124. deviceId:deviceId,
  125. deviceKey:deviceKey
  126. })
  127. wx.request({
  128. url: 'https://api.heclouds.com/devices/' + deviceId,
  129. method:'GET',
  130. header:{"api-key": deviceKey},
  131. success:(res) =>{
  132. if (res.data.data.online == true) {
  133. that.setData({
  134. status:"在线"
  135. })
  136. wx.request({
  137. url: 'https://api.heclouds.com/devices/' + deviceId + '/datastreams',
  138. header:{"api-key": deviceKey},
  139. method:'GET',
  140. success:(res) => {
  141. let {data} = res.data
  142. //以下为回路
  143. for(let i = 1;i < data.length;i++){
  144. //回路数量
  145. if(data[i].id == "RelayCount"){
  146. var num = data[i].current_value
  147. num = parseInt(num)
  148. loopnum = loopnum.split(',')
  149. var num1 = []
  150. for(let a = 0;a < num;a++){
  151. num1.push(loopnum[a])
  152. }
  153. num1.push('所有回路')
  154. that.setData({
  155. crr:num1,
  156. })
  157. }
  158. //时控一开时间
  159. else if(data[i].id == "R1_DayOpenTime1"){
  160. var timeopen1 = data[i].current_value
  161. }
  162. //时控一关时间
  163. else if(data[i].id == "R1_DayCloseTime1"){
  164. var timeshut1 = data[i].current_value
  165. }
  166. //时控二开时间
  167. else if(data[i].id == "R1_DayOpenTime2"){
  168. var timeopen2 = data[i].current_value
  169. }
  170. //时控二关时间
  171. else if(data[i].id == "R1_DayCloseTime2"){
  172. var timeshut2 = data[i].current_value
  173. }
  174. //日期调控
  175. else if(data[i].id == "R1_Week"){
  176. var weeks = data[i].current_value
  177. that.setData({recorddate:weeks})
  178. weeks = parseInt(weeks)
  179. weeks = weeks.toString(2)
  180. weeks = weeks + ''
  181. if(weeks != '0'){
  182. weeks = weeks.slice(1)
  183. }
  184. }
  185. //功能1
  186. else if(data[i].id == "R1_FunctionStatus1"){
  187. var Function1 = data[i].current_value
  188. var par = parseInt(Function1)
  189. par = par.toString(2)
  190. par = par + ''
  191. switch (par.length) {
  192. case 1:
  193. par = '00000' + par
  194. break;
  195. case 2:
  196. par = '0000' + par
  197. break;
  198. case 3:
  199. par = '000' + par
  200. break;
  201. case 4:
  202. par = '00' + par
  203. break;
  204. case 5:
  205. par = '0' + par
  206. break;
  207. default:
  208. par = par
  209. }
  210. }
  211. //功能二
  212. else if(data[i].id == "R1_FunctionStatus2"){
  213. var Function2 = data[i].current_value
  214. var qur = parseInt(Function2)
  215. qur = qur.toString(2)
  216. qur = qur + ''
  217. switch (qur.length) {
  218. case 1:
  219. qur = '000' + qur
  220. break;
  221. case 2:
  222. qur = '00' + qur
  223. break;
  224. case 3:
  225. qur = '0' + qur
  226. break;
  227. case 4:
  228. qur = qur
  229. break;
  230. }
  231. }
  232. //报警
  233. else if(data[i].id == "R1_RelayStatus"){
  234. var police = data[i].current_value
  235. }
  236. //光控开
  237. else if(data[i].id == "R1_LcOn"){
  238. var Lightcontrolopen = data[i].current_value
  239. var trr = that.data.arr
  240. for(let i = 0;i < 100;i++){
  241. trr[i] = i
  242. }
  243. Lightcontrolopen = parseInt(Lightcontrolopen)
  244. that.setData({arr:trr,index:Lightcontrolopen})
  245. }
  246. //光控关
  247. else if(data[i].id == "R1_LcOff"){
  248. var Lightcontrolshut = data[i].current_value
  249. var prr = that.data.brr
  250. for(let j =0;j < 100;j++){
  251. prr[j] = j
  252. }
  253. Lightcontrolshut = parseInt(Lightcontrolshut)
  254. that.setData({brr:prr,indexs:Lightcontrolshut})
  255. }
  256. }
  257. //时控一开时间
  258. var timeOpen1
  259. switch (timeopen1.length) {
  260. case 1:
  261. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0,1)
  262. break;
  263. case 2:
  264. timeOpen1 = '00' + ':' + timeopen1.substring(0,2)
  265. break;
  266. case 3:
  267. var timeOpen1 = '0' + timeopen1.substring(0,1) + ':' + timeopen1.substring(1,3)
  268. break;
  269. case 4:
  270. var timeOpen1 = timeopen1.substring(0,2) + ':' + timeopen1.substring(2,4)
  271. break;
  272. }
  273. //时控一关时间
  274. var timeShut1
  275. switch (timeshut1.length) {
  276. case 1:
  277. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0,1)
  278. break;
  279. case 2:
  280. timeShut1 = '00' + ':' + timeshut1.substring(0,2)
  281. break;
  282. case 3:
  283. var timeShut1 = '0' + timeshut1.substring(0,1) + ':' + timeshut1.substring(1,3)
  284. break;
  285. case 4:
  286. var timeShut1 = timeshut1.substring(0,2) + ':' + timeshut1.substring(2,4)
  287. break;
  288. }
  289. //时控二开时间
  290. var timeOpen2
  291. switch (timeopen2.length) {
  292. case 1:
  293. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0,1)
  294. break;
  295. case 2:
  296. timeOpen2 = '00' + ':' + timeopen2.substring(0,2)
  297. break;
  298. case 3:
  299. var timeOpen2 = '0' + timeopen2.substring(0,1) + ':' + timeopen2.substring(1,3)
  300. break;
  301. case 4:
  302. var timeOpen2 = timeopen2.substring(0,2) + ':' + timeopen2.substring(2,4)
  303. break;
  304. }
  305. //时控二关时间
  306. var timeShut2
  307. switch (timeshut2.length) {
  308. case 1:
  309. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0,1)
  310. break;
  311. case 2:
  312. timeShut2 = '00' + ':' + timeshut2.substring(0,2)
  313. break;
  314. case 3:
  315. var timeShut2 = '0' + timeshut2.substring(0,1) + ':' + timeshut2.substring(1,3)
  316. break;
  317. case 4:
  318. var timeShut2 = timeshut2.substring(0,2) + ':' + timeshut2.substring(2,4)
  319. break;
  320. }
  321. //功能1
  322. for(var i = 0;i < par.length;i++){
  323. var engry = that.data.state
  324. switch(par.substring(i,i+1)){
  325. case "0":
  326. switch (i) {
  327. case 0:
  328. engry[3] = false
  329. that.setData({state:engry})
  330. break;
  331. case 1:
  332. engry[2] = false
  333. that.setData({state:engry})
  334. break;
  335. case 2:
  336. that.setData({fixed2:"固定"})
  337. break;
  338. case 3:
  339. that.setData({fixed1:"固定"})
  340. break;
  341. case 4:
  342. engry[1] = false
  343. that.setData({state:engry})
  344. break;
  345. case 5:
  346. engry[0] = false
  347. that.setData({state:engry})
  348. break;
  349. }
  350. break;
  351. case "1":
  352. switch (i) {
  353. case 0:
  354. engry[3] = true
  355. that.setData({state:engry})
  356. break;
  357. case 1:
  358. engry[2] = true
  359. that.setData({state:engry})
  360. break;
  361. case 2:
  362. that.setData({fixed2:"经纬"})
  363. break;
  364. case 3:
  365. that.setData({fixed1:"经纬"})
  366. break;
  367. case 4:
  368. engry[1] = true
  369. that.setData({state:engry})
  370. break;
  371. case 5:
  372. engry[0] = true
  373. that.setData({state:engry})
  374. break;
  375. }
  376. break;
  377. }
  378. }
  379. //功能2
  380. for(let j = 0;j < qur.length;j++){
  381. var Engry = that.data.state1
  382. switch(qur.substring(j,j+1)){
  383. case "0":
  384. switch (j) {
  385. case 0:
  386. that.setData({fixed4:"固定"})
  387. break;
  388. case 1:
  389. that.setData({fixed3:"固定"})
  390. break;
  391. case 2:
  392. Engry[1] = false
  393. that.setData({state1:Engry})
  394. break;
  395. case 3:
  396. Engry[0] = false
  397. that.setData({state1:Engry})
  398. break;
  399. }
  400. break;
  401. case "1":
  402. switch (j) {
  403. case 0:
  404. that.setData({fixed4:"经纬"})
  405. break;
  406. case 1:
  407. that.setData({fixed3:"经纬"})
  408. break;
  409. case 2:
  410. Engry[1] = true
  411. that.setData({state1:Engry})
  412. break;
  413. case 3:
  414. Engry[0] = true
  415. that.setData({state1:Engry})
  416. break;
  417. }
  418. break;
  419. }
  420. }
  421. //日期调控
  422. var controladdress = that.data.address
  423. if (weeks == '0') {
  424. for(let x = 0;x < weeks.length; x++){
  425. controladdress[x] = "/image/false.png"
  426. }
  427. that.setData({
  428. address:controladdress,
  429. })
  430. }
  431. else{
  432. for(let i = 0;i < weeks.length;i++){
  433. switch (weeks.substring(i,i+1)) {
  434. case '0':
  435. controladdress[weeks.length-i-1] = "/image/false.png"
  436. that.setData({
  437. address:controladdress,
  438. })
  439. break;
  440. case '1':
  441. controladdress[weeks.length-i-1] = "/image/true.png"
  442. that.setData({
  443. address:controladdress,
  444. })
  445. break;
  446. }
  447. }
  448. }
  449. //报警状态
  450. police = parseInt(police)
  451. police = police.toString(2)
  452. switch(police.length){
  453. case 1:
  454. police = '000' + police
  455. break;
  456. case 2:
  457. police = '00' + police
  458. break;
  459. case 3:
  460. police = '0' + police
  461. break;
  462. default:
  463. police = police
  464. break;
  465. }
  466. if(police.substring(1,2) == '0' && police.substring(0,1) == '0'){
  467. that.setData({
  468. radio1:true
  469. })
  470. }
  471. else if(police.substring(1,2) == '1' && police.substring(0,1) == '0'){
  472. that.setData({
  473. radio2:true
  474. })
  475. }
  476. else if(police.substring(1,2) == '0' && police.substring(0,1) == '1'){
  477. that.setData({
  478. radio3:true
  479. })
  480. }
  481. var time = that.data.time
  482. time[0] = timeOpen1
  483. time[1] = timeShut1
  484. time[2] = timeOpen2
  485. time[3] = timeShut2
  486. that.setData({
  487. time:time,
  488. })
  489. //监视开关状态(改变颜色,调整功能)
  490. switch (that.data.state[0]) {
  491. case true:
  492. that.setData({
  493. type1:"time",
  494. timecontrolcolor1:"blue",
  495. fontcolor1:"white",
  496. })
  497. break;
  498. default:
  499. that.setData({
  500. type1:"",
  501. timecontrolcolor1:"#888888",
  502. fontcolor1:"#cccccc",
  503. })
  504. break;
  505. }
  506. switch (that.data.state[1]) {
  507. case true:
  508. that.setData({
  509. type2:"time",
  510. timecontrolcolor2:"blue",
  511. fontcolor2:"white",
  512. })
  513. break;
  514. default:
  515. that.setData({
  516. type2:"",
  517. timecontrolcolor2:"#888888",
  518. fontcolor2:"#cccccc",
  519. })
  520. break;
  521. }
  522. switch (that.data.state1[0]) {
  523. case true:
  524. that.setData({
  525. type3:"time",
  526. timecontrolcolor3:"blue",
  527. fontcolor3:"white",
  528. })
  529. break;
  530. default:
  531. that.setData({
  532. type3:"",
  533. timecontrolcolor3:"#888888",
  534. fontcolor3:"#cccccc",
  535. })
  536. break;
  537. }
  538. switch (that.data.state1[1]) {
  539. case true:
  540. that.setData({
  541. type4:"time",
  542. timecontrolcolor4:"blue",
  543. fontcolor4:"white",
  544. })
  545. break;
  546. default:
  547. that.setData({
  548. type4:"",
  549. timecontrolcolor4:"#888888",
  550. fontcolor4:"#cccccc",
  551. })
  552. break;
  553. }
  554. switch (that.data.state[2]) {
  555. case true:
  556. that.setData({
  557. Lightcontrolcolor1:"blue",
  558. fontcolor5:"white",
  559. select1:"selector"
  560. })
  561. break;
  562. default:
  563. that.setData({
  564. Lightcontrolcolor1:"#888888",
  565. fontcolor5:"#cccccc",
  566. select1:""
  567. })
  568. break;
  569. }
  570. switch (that.data.state[3]) {
  571. case true:
  572. that.setData({
  573. Lightcontrolcolor2:"blue",
  574. fontcolor6:"white",
  575. select2:"selector"
  576. })
  577. break;
  578. default:
  579. that.setData({
  580. Lightcontrolcolor2:"#888888",
  581. fontcolor6:"#cccccc",
  582. select2:""
  583. })
  584. break;
  585. }
  586. }
  587. })
  588. }
  589. else{
  590. that.setData({
  591. status:"离线"
  592. })
  593. }
  594. }
  595. })
  596. }
  597. else{
  598. wx.setStorageSync('deviceName','')//清空设备名称缓存
  599. }
  600. },
  601. //设备下拉
  602. changedevice:function(e){
  603. var that = this
  604. wx.showToast({
  605. title:'刷新中',
  606. icon:'loading',
  607. duration: 2000
  608. })
  609. that.setData({
  610. deviceIndex:e.detail.value
  611. })
  612. var group = wx.getStorageSync('group')
  613. var groupName = that.data.groupName[that.data.groupIndex]
  614. var deviceName = that.data.deviceName[that.data.deviceIndex]
  615. wx.setStorageSync('groupName', groupName)//分组名称
  616. wx.setStorageSync('deviceName', deviceName)//设备名称
  617. for (let index = 0; index < group.length; index++) {
  618. if(groupName == group[index].groupName){
  619. for(let t = 0;t < group[index].devices.length;t++){
  620. if(deviceName == group[index].devices[t].deviceName){
  621. var deviceId = group[index].devices[t].deviceId
  622. var deviceKey = group[index].devices[t].deviceKey
  623. var loopnum = group[index].devices[t].circuits
  624. }
  625. }
  626. }
  627. }
  628. that.setData({
  629. deviceId:deviceId,
  630. deviceKey:deviceKey
  631. })
  632. wx.request({
  633. url: 'https://api.heclouds.com/devices/' + deviceId,
  634. method:'GET',
  635. header:{"api-key": deviceKey},
  636. success:(res) =>{
  637. if (res.data.data.online == true) {
  638. that.setData({
  639. status:"在线"
  640. })
  641. wx.request({
  642. url: 'https://api.heclouds.com/devices/' + deviceId + '/datastreams',
  643. header:{"api-key": deviceKey},
  644. method:'GET',
  645. success:(res) => {
  646. let {data} = res.data
  647. //以下为回路
  648. for(let i = 1;i < data.length;i++){
  649. //回路数量
  650. if(data[i].id == "RelayCount"){
  651. var num = data[i].current_value
  652. num = parseInt(num)
  653. loopnum = loopnum.split(',')
  654. var num1 = []
  655. for(let a = 0;a < num;a++){
  656. num1.push(loopnum[a])
  657. }
  658. num1.push('所有回路')
  659. that.setData({
  660. crr:num1,
  661. })
  662. }
  663. //时控一开时间
  664. else if(data[i].id == "R1_DayOpenTime1"){
  665. var timeopen1 = data[i].current_value
  666. }
  667. //时控一关时间
  668. else if(data[i].id == "R1_DayCloseTime1"){
  669. var timeshut1 = data[i].current_value
  670. }
  671. //时控二开时间
  672. else if(data[i].id == "R1_DayOpenTime2"){
  673. var timeopen2 = data[i].current_value
  674. }
  675. //时控二关时间
  676. else if(data[i].id == "R1_DayCloseTime2"){
  677. var timeshut2 = data[i].current_value
  678. }
  679. //日期调控
  680. else if(data[i].id == "R1_Week"){
  681. var weeks = data[i].current_value
  682. that.setData({recorddate:weeks})
  683. weeks = parseInt(weeks)
  684. weeks = weeks.toString(2)
  685. weeks = weeks + ''
  686. if(weeks != '0'){
  687. weeks = weeks.slice(1)
  688. }
  689. }
  690. //功能1
  691. else if(data[i].id == "R1_FunctionStatus1"){
  692. var Function1 = data[i].current_value
  693. var par = parseInt(Function1)
  694. par = par.toString(2)
  695. par = par + ''
  696. switch (par.length) {
  697. case 1:
  698. par = '00000' + par
  699. break;
  700. case 2:
  701. par = '0000' + par
  702. break;
  703. case 3:
  704. par = '000' + par
  705. break;
  706. case 4:
  707. par = '00' + par
  708. break;
  709. case 5:
  710. par = '0' + par
  711. break;
  712. default:
  713. par = par
  714. }
  715. }
  716. //功能二
  717. else if(data[i].id == "R1_FunctionStatus2"){
  718. var Function2 = data[i].current_value
  719. var qur = parseInt(Function2)
  720. qur = qur.toString(2)
  721. qur = qur + ''
  722. switch (qur.length) {
  723. case 1:
  724. qur = '000' + qur
  725. break;
  726. case 2:
  727. qur = '00' + qur
  728. break;
  729. case 3:
  730. qur = '0' + qur
  731. break;
  732. case 4:
  733. qur = qur
  734. break;
  735. }
  736. }
  737. //报警
  738. else if(data[i].id == "R1_RelayStatus"){
  739. var police = data[i].current_value
  740. }
  741. //光控开
  742. else if(data[i].id == "R1_LcOn"){
  743. var Lightcontrolopen = data[i].current_value
  744. var trr = that.data.arr
  745. for(let i = 0;i < 100;i++){
  746. trr[i] = i
  747. }
  748. Lightcontrolopen = parseInt(Lightcontrolopen)
  749. that.setData({arr:trr,index:Lightcontrolopen})
  750. }
  751. //光控关
  752. else if(data[i].id == "R1_LcOff"){
  753. var Lightcontrolshut = data[i].current_value
  754. var prr = that.data.brr
  755. for(let j =0;j < 100;j++){
  756. prr[j] = j
  757. }
  758. Lightcontrolshut = parseInt(Lightcontrolshut)
  759. that.setData({brr:prr,indexs:Lightcontrolshut})
  760. }
  761. }
  762. //时控一开时间
  763. var timeOpen1
  764. switch (timeopen1.length) {
  765. case 1:
  766. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0,1)
  767. break;
  768. case 2:
  769. timeOpen1 = '00' + ':' + timeopen1.substring(0,2)
  770. break;
  771. case 3:
  772. var timeOpen1 = '0' + timeopen1.substring(0,1) + ':' + timeopen1.substring(1,3)
  773. break;
  774. case 4:
  775. var timeOpen1 = timeopen1.substring(0,2) + ':' + timeopen1.substring(2,4)
  776. break;
  777. }
  778. //时控一关时间
  779. var timeShut1
  780. switch (timeshut1.length) {
  781. case 1:
  782. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0,1)
  783. break;
  784. case 2:
  785. timeShut1 = '00' + ':' + timeshut1.substring(0,2)
  786. break;
  787. case 3:
  788. var timeShut1 = '0' + timeshut1.substring(0,1) + ':' + timeshut1.substring(1,3)
  789. break;
  790. case 4:
  791. var timeShut1 = timeshut1.substring(0,2) + ':' + timeshut1.substring(2,4)
  792. break;
  793. }
  794. //时控二开时间
  795. var timeOpen2
  796. switch (timeopen2.length) {
  797. case 1:
  798. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0,1)
  799. break;
  800. case 2:
  801. timeOpen2 = '00' + ':' + timeopen2.substring(0,2)
  802. break;
  803. case 3:
  804. var timeOpen2 = '0' + timeopen2.substring(0,1) + ':' + timeopen2.substring(1,3)
  805. break;
  806. case 4:
  807. var timeOpen2 = timeopen2.substring(0,2) + ':' + timeopen2.substring(2,4)
  808. break;
  809. }
  810. //时控二关时间
  811. var timeShut2
  812. switch (timeshut2.length) {
  813. case 1:
  814. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0,1)
  815. break;
  816. case 2:
  817. timeShut2 = '00' + ':' + timeshut2.substring(0,2)
  818. break;
  819. case 3:
  820. var timeShut2 = '0' + timeshut2.substring(0,1) + ':' + timeshut2.substring(1,3)
  821. break;
  822. case 4:
  823. var timeShut2 = timeshut2.substring(0,2) + ':' + timeshut2.substring(2,4)
  824. break;
  825. }
  826. //功能1
  827. for(var i = 0;i < par.length;i++){
  828. var engry = that.data.state
  829. switch(par.substring(i,i+1)){
  830. case "0":
  831. switch (i) {
  832. case 0:
  833. engry[3] = false
  834. that.setData({state:engry})
  835. break;
  836. case 1:
  837. engry[2] = false
  838. that.setData({state:engry})
  839. break;
  840. case 2:
  841. that.setData({fixed2:"固定"})
  842. break;
  843. case 3:
  844. that.setData({fixed1:"固定"})
  845. break;
  846. case 4:
  847. engry[1] = false
  848. that.setData({state:engry})
  849. break;
  850. case 5:
  851. engry[0] = false
  852. that.setData({state:engry})
  853. break;
  854. }
  855. break;
  856. case "1":
  857. switch (i) {
  858. case 0:
  859. engry[3] = true
  860. that.setData({state:engry})
  861. break;
  862. case 1:
  863. engry[2] = true
  864. that.setData({state:engry})
  865. break;
  866. case 2:
  867. that.setData({fixed2:"经纬"})
  868. break;
  869. case 3:
  870. that.setData({fixed1:"经纬"})
  871. break;
  872. case 4:
  873. engry[1] = true
  874. that.setData({state:engry})
  875. break;
  876. case 5:
  877. engry[0] = true
  878. that.setData({state:engry})
  879. break;
  880. }
  881. break;
  882. }
  883. }
  884. //功能2
  885. for(let j = 0;j < qur.length;j++){
  886. var Engry = that.data.state1
  887. switch(qur.substring(j,j+1)){
  888. case "0":
  889. switch (j) {
  890. case 0:
  891. that.setData({fixed4:"固定"})
  892. break;
  893. case 1:
  894. that.setData({fixed3:"固定"})
  895. break;
  896. case 2:
  897. Engry[1] = false
  898. that.setData({state1:Engry})
  899. break;
  900. case 3:
  901. Engry[0] = false
  902. that.setData({state1:Engry})
  903. break;
  904. }
  905. break;
  906. case "1":
  907. switch (j) {
  908. case 0:
  909. that.setData({fixed4:"经纬"})
  910. break;
  911. case 1:
  912. that.setData({fixed3:"经纬"})
  913. break;
  914. case 2:
  915. Engry[1] = true
  916. that.setData({state1:Engry})
  917. break;
  918. case 3:
  919. Engry[0] = true
  920. that.setData({state1:Engry})
  921. break;
  922. }
  923. break;
  924. }
  925. }
  926. //日期调控
  927. var controladdress = that.data.address
  928. if (weeks == '0') {
  929. for(let x = 0;x < weeks.length; x++){
  930. controladdress[x] = "/image/false.png"
  931. }
  932. that.setData({
  933. address:controladdress,
  934. })
  935. }
  936. else{
  937. for(let i = 0;i < weeks.length;i++){
  938. switch (weeks.substring(i,i+1)) {
  939. case '0':
  940. controladdress[weeks.length-i-1] = "/image/false.png"
  941. that.setData({
  942. address:controladdress,
  943. })
  944. break;
  945. case '1':
  946. controladdress[weeks.length-i-1] = "/image/true.png"
  947. that.setData({
  948. address:controladdress,
  949. })
  950. break;
  951. }
  952. }
  953. }
  954. //报警状态
  955. police = parseInt(police)
  956. police = police.toString(2)
  957. switch(police.length){
  958. case 1:
  959. police = '000' + police
  960. break;
  961. case 2:
  962. police = '00' + police
  963. break;
  964. case 3:
  965. police = '0' + police
  966. break;
  967. default:
  968. police = police
  969. break;
  970. }
  971. if(police.substring(1,2) == '0' && police.substring(0,1) == '0'){
  972. that.setData({
  973. radio1:true
  974. })
  975. }
  976. else if(police.substring(1,2) == '1' && police.substring(0,1) == '0'){
  977. that.setData({
  978. radio2:true
  979. })
  980. }
  981. else if(police.substring(1,2) == '0' && police.substring(0,1) == '1'){
  982. that.setData({
  983. radio3:true
  984. })
  985. }
  986. var time = that.data.time
  987. time[0] = timeOpen1
  988. time[1] = timeShut1
  989. time[2] = timeOpen2
  990. time[3] = timeShut2
  991. that.setData({
  992. time:time,
  993. })
  994. //监视开关状态(改变颜色,调整功能)
  995. switch (that.data.state[0]) {
  996. case true:
  997. that.setData({
  998. type1:"time",
  999. timecontrolcolor1:"blue",
  1000. fontcolor1:"white",
  1001. })
  1002. break;
  1003. default:
  1004. that.setData({
  1005. type1:"",
  1006. timecontrolcolor1:"#888888",
  1007. fontcolor1:"#cccccc",
  1008. })
  1009. break;
  1010. }
  1011. switch (that.data.state[1]) {
  1012. case true:
  1013. that.setData({
  1014. type2:"time",
  1015. timecontrolcolor2:"blue",
  1016. fontcolor2:"white",
  1017. })
  1018. break;
  1019. default:
  1020. that.setData({
  1021. type2:"",
  1022. timecontrolcolor2:"#888888",
  1023. fontcolor2:"#cccccc",
  1024. })
  1025. break;
  1026. }
  1027. switch (that.data.state1[0]) {
  1028. case true:
  1029. that.setData({
  1030. type3:"time",
  1031. timecontrolcolor3:"blue",
  1032. fontcolor3:"white",
  1033. })
  1034. break;
  1035. default:
  1036. that.setData({
  1037. type3:"",
  1038. timecontrolcolor3:"#888888",
  1039. fontcolor3:"#cccccc",
  1040. })
  1041. break;
  1042. }
  1043. switch (that.data.state1[1]) {
  1044. case true:
  1045. that.setData({
  1046. type4:"time",
  1047. timecontrolcolor4:"blue",
  1048. fontcolor4:"white",
  1049. })
  1050. break;
  1051. default:
  1052. that.setData({
  1053. type4:"",
  1054. timecontrolcolor4:"#888888",
  1055. fontcolor4:"#cccccc",
  1056. })
  1057. break;
  1058. }
  1059. switch (that.data.state[2]) {
  1060. case true:
  1061. that.setData({
  1062. Lightcontrolcolor1:"blue",
  1063. fontcolor5:"white",
  1064. select1:"selector"
  1065. })
  1066. break;
  1067. default:
  1068. that.setData({
  1069. Lightcontrolcolor1:"#888888",
  1070. fontcolor5:"#cccccc",
  1071. select1:""
  1072. })
  1073. break;
  1074. }
  1075. switch (that.data.state[3]) {
  1076. case true:
  1077. that.setData({
  1078. Lightcontrolcolor2:"blue",
  1079. fontcolor6:"white",
  1080. select2:"selector"
  1081. })
  1082. break;
  1083. default:
  1084. that.setData({
  1085. Lightcontrolcolor2:"#888888",
  1086. fontcolor6:"#cccccc",
  1087. select2:""
  1088. })
  1089. break;
  1090. }
  1091. }
  1092. })
  1093. }
  1094. else{
  1095. that.setData({
  1096. status:"离线"
  1097. })
  1098. }
  1099. }
  1100. })
  1101. },
  1102. //回路调控
  1103. bindPickerChange3:function(e){
  1104. this.setData({
  1105. indexes: e.detail.value
  1106. })
  1107. var that = this
  1108. var crr = that.data.crr.length
  1109. wx.request({
  1110. url: 'https://api.heclouds.com/devices/' + that.data.deviceId + '/datastreams',
  1111. header:{"api-key":that.data.deviceKey},
  1112. method:'GET',
  1113. success:(res) => {
  1114. let {data} = res.data
  1115. var Indexes = that.data.indexes
  1116. Indexes = parseInt(Indexes)
  1117. Indexes = Indexes + 1
  1118. if(Indexes == crr){
  1119. }
  1120. else{
  1121. //以下为回路
  1122. for(let i = 1;i < data.length;i++){
  1123. //时控一开时间
  1124. if(data[i].id == "R"+ Indexes +"_DayOpenTime1"){
  1125. var timeopen1 = data[i].current_value
  1126. }
  1127. //时控一关时间
  1128. else if(data[i].id == "R"+ Indexes +"_DayCloseTime1"){
  1129. var timeshut1 = data[i].current_value
  1130. }
  1131. //时控二开时间
  1132. else if(data[i].id == "R"+ Indexes +"_DayOpenTime2"){
  1133. var timeopen2 = data[i].current_value
  1134. }
  1135. //时控二关时间
  1136. else if(data[i].id == "R"+ Indexes +"_DayCloseTime2"){
  1137. var timeshut2 = data[i].current_value
  1138. }
  1139. //日期调控
  1140. else if(data[i].id == "R"+ Indexes +"_Week"){
  1141. var weeks = data[i].current_value
  1142. that.setData({recorddate:weeks})
  1143. weeks = parseInt(weeks)
  1144. weeks = weeks.toString(2)
  1145. weeks = weeks + ''
  1146. if(weeks != '0'){
  1147. weeks = weeks.slice(1)
  1148. }
  1149. }
  1150. //功能一
  1151. else if(data[i].id == "R" + Indexes + "_FunctionStatus1"){
  1152. var Function1 = data[i].current_value
  1153. var par = parseInt(Function1)
  1154. par = par.toString(2)
  1155. par = par + ''
  1156. switch (par.length) {
  1157. case 1:
  1158. par = '00000' + par
  1159. break;
  1160. case 2:
  1161. par = '0000' + par
  1162. break;
  1163. case 3:
  1164. par = '000' + par
  1165. break;
  1166. case 4:
  1167. par = '00' + par
  1168. break;
  1169. case 5:
  1170. par = '0' + par
  1171. break;
  1172. default:
  1173. par = par
  1174. }
  1175. }
  1176. //功能二
  1177. else if(data[i].id == "R" + Indexes + "_FunctionStatus2"){
  1178. var Function2 = data[i].current_value
  1179. var qur = parseInt(Function2)
  1180. qur = qur.toString(2)
  1181. qur = qur + ''
  1182. switch (qur.length) {
  1183. case 1:
  1184. qur = '000' + qur
  1185. break;
  1186. case 2:
  1187. qur = '00' + qur
  1188. break;
  1189. case 3:
  1190. qur = '0' + qur
  1191. break;
  1192. case 4:
  1193. qur = qur
  1194. break;
  1195. }
  1196. }
  1197. //报警
  1198. else if(data[i].id == "R"+ Indexes +"_RelayStatus"){
  1199. var police = data[i].current_value
  1200. }
  1201. //光控开
  1202. else if(data[i].id == "R" + Indexes + "_LcOn"){
  1203. var Lightcontrolopen = data[i].current_value
  1204. var trr = that.data.arr
  1205. for(let i = 0;i < 100;i++){
  1206. trr[i] = i
  1207. }
  1208. Lightcontrolopen = parseInt(Lightcontrolopen)
  1209. that.setData({arr:trr,index:Lightcontrolopen})
  1210. }
  1211. //光控关
  1212. else if(data[i].id == "R" + Indexes +"_LcOff"){
  1213. var Lightcontrolshut = data[i].current_value
  1214. var prr = that.data.brr
  1215. for(let j =0;j < 100;j++){
  1216. prr[j] = j
  1217. }
  1218. Lightcontrolshut = parseInt(Lightcontrolshut)
  1219. that.setData({brr:prr,indexs:Lightcontrolshut})
  1220. }
  1221. }
  1222. //时控一开时间
  1223. var timeOpen1
  1224. switch (timeopen1.length) {
  1225. case 1:
  1226. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0,1)
  1227. break;
  1228. case 2:
  1229. timeOpen1 = '00' + ':' + timeopen1.substring(0,2)
  1230. break;
  1231. case 3:
  1232. var timeOpen1 = '0' + timeopen1.substring(0,1) + ':' + timeopen1.substring(1,3)
  1233. break;
  1234. case 4:
  1235. var timeOpen1 = timeopen1.substring(0,2) + ':' + timeopen1.substring(2,4)
  1236. break;
  1237. }
  1238. //时控一关时间
  1239. var timeShut1
  1240. switch (timeshut1.length) {
  1241. case 1:
  1242. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0,1)
  1243. break;
  1244. case 2:
  1245. timeShut1 = '00' + ':' + timeshut1.substring(0,2)
  1246. break;
  1247. case 3:
  1248. var timeShut1 = '0' + timeshut1.substring(0,1) + ':' + timeshut1.substring(1,3)
  1249. break;
  1250. case 4:
  1251. var timeShut1 = timeshut1.substring(0,2) + ':' + timeshut1.substring(2,4)
  1252. break;
  1253. }
  1254. //时控二开时间
  1255. var timeOpen2
  1256. switch (timeopen2.length) {
  1257. case 1:
  1258. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0,1)
  1259. break;
  1260. case 2:
  1261. timeOpen2 = '00' + ':' + timeopen2.substring(0,2)
  1262. break;
  1263. case 3:
  1264. var timeOpen2 = '0' + timeopen2.substring(0,1) + ':' + timeopen2.substring(1,3)
  1265. break;
  1266. case 4:
  1267. var timeOpen2 = timeopen2.substring(0,2) + ':' + timeopen2.substring(2,4)
  1268. break;
  1269. }
  1270. //时控二关时间
  1271. var timeShut2
  1272. switch (timeshut2.length) {
  1273. case 1:
  1274. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0,1)
  1275. break;
  1276. case 2:
  1277. timeShut2 = '00' + ':' + timeshut2.substring(0,2)
  1278. break;
  1279. case 3:
  1280. var timeShut2 = '0' + timeshut2.substring(0,1) + ':' + timeshut2.substring(1,3)
  1281. break;
  1282. case 4:
  1283. var timeShut2 = timeshut2.substring(0,2) + ':' + timeshut2.substring(2,4)
  1284. break;
  1285. }
  1286. //功能1
  1287. for(var i = 0;i < par.length;i++){
  1288. var engry = that.data.state
  1289. switch(par.substring(i,i+1)){
  1290. case "0":
  1291. switch (i) {
  1292. case 0:
  1293. engry[3] = false
  1294. that.setData({state:engry})
  1295. break;
  1296. case 1:
  1297. engry[2] = false
  1298. that.setData({state:engry})
  1299. break;
  1300. case 2:
  1301. that.setData({fixed2:"固定"})
  1302. break;
  1303. case 3:
  1304. that.setData({fixed1:"固定"})
  1305. break;
  1306. case 4:
  1307. engry[1] = false
  1308. that.setData({state:engry})
  1309. break;
  1310. case 5:
  1311. engry[0] = false
  1312. that.setData({state:engry})
  1313. break;
  1314. }
  1315. break;
  1316. case "1":
  1317. switch (i) {
  1318. case 0:
  1319. engry[3] = true
  1320. that.setData({state:engry})
  1321. break;
  1322. case 1:
  1323. engry[2] = true
  1324. that.setData({state:engry})
  1325. break;
  1326. case 2:
  1327. that.setData({fixed2:"经纬"})
  1328. break;
  1329. case 3:
  1330. that.setData({fixed1:"经纬"})
  1331. break;
  1332. case 4:
  1333. engry[1] = true
  1334. that.setData({state:engry})
  1335. break;
  1336. case 5:
  1337. engry[0] = true
  1338. that.setData({state:engry})
  1339. break;
  1340. }
  1341. break;
  1342. }
  1343. }
  1344. //功能2
  1345. for(let j = 0;j < qur.length;j++){
  1346. var Engry = that.data.state1
  1347. switch(qur.substring(j,j+1)){
  1348. case "0":
  1349. switch (j) {
  1350. case 0:
  1351. that.setData({fixed4:"固定"})
  1352. break;
  1353. case 1:
  1354. that.setData({fixed3:"固定"})
  1355. break;
  1356. case 2:
  1357. Engry[1] = false
  1358. that.setData({state1:Engry})
  1359. break;
  1360. case 3:
  1361. Engry[0] = false
  1362. that.setData({state1:Engry})
  1363. break;
  1364. }
  1365. break;
  1366. case "1":
  1367. switch (j) {
  1368. case 0:
  1369. that.setData({fixed4:"经纬"})
  1370. break;
  1371. case 1:
  1372. that.setData({fixed3:"经纬"})
  1373. break;
  1374. case 2:
  1375. Engry[1] = true
  1376. that.setData({state1:Engry})
  1377. break;
  1378. case 3:
  1379. Engry[0] = true
  1380. that.setData({state1:Engry})
  1381. break;
  1382. }
  1383. break;
  1384. }
  1385. }
  1386. //日期调控
  1387. var controladdress = that.data.address
  1388. if (weeks == '0') {
  1389. for(let x = 0;x < 7; x++){
  1390. controladdress[x] = "/image/false.png"
  1391. }
  1392. that.setData({
  1393. address:controladdress,
  1394. })
  1395. }
  1396. else{
  1397. for(let i = 0;i < weeks.length;i++){
  1398. switch (weeks.substring(i,i+1)) {
  1399. case '0':
  1400. controladdress[weeks.length-i-1] = "/image/false.png"
  1401. that.setData({
  1402. address:controladdress,
  1403. })
  1404. break;
  1405. case '1':
  1406. controladdress[weeks.length-i-1] = "/image/true.png"
  1407. that.setData({
  1408. address:controladdress,
  1409. })
  1410. break;
  1411. }
  1412. }
  1413. }
  1414. //报警状态
  1415. police = parseInt(police)
  1416. police = police.toString(2)
  1417. switch(police.length){
  1418. case 1:
  1419. police = '000' + police
  1420. break;
  1421. case 2:
  1422. police = '00' + police
  1423. break;
  1424. case 3:
  1425. police = '0' + police
  1426. break;
  1427. default:
  1428. police = police
  1429. break;
  1430. }
  1431. if(police.substring(1,2) == '0' && police.substring(0,1) == '0'){
  1432. that.setData({
  1433. radio1:true
  1434. })
  1435. }
  1436. else if(police.substring(1,2) == '1' && police.substring(0,1) == '0'){
  1437. that.setData({
  1438. radio2:true
  1439. })
  1440. }
  1441. else if(police.substring(1,2) == '0' && police.substring(0,1) == '1'){
  1442. that.setData({
  1443. radio3:true
  1444. })
  1445. }
  1446. var time = that.data.time
  1447. time[0] = timeOpen1
  1448. time[1] = timeShut1
  1449. time[2] = timeOpen2
  1450. time[3] = timeShut2
  1451. that.setData({
  1452. time:time
  1453. })
  1454. switch (that.data.state[0]) {
  1455. case true:
  1456. that.setData({
  1457. type1:"time",
  1458. timecontrolcolor1:"blue",
  1459. fontcolor1:"white",
  1460. })
  1461. break;
  1462. default:
  1463. that.setData({
  1464. type1:"",
  1465. timecontrolcolor1:"#888888",
  1466. fontcolor1:"#cccccc",
  1467. })
  1468. break;
  1469. }
  1470. switch (that.data.state[1]) {
  1471. case true:
  1472. that.setData({
  1473. type2:"time",
  1474. timecontrolcolor2:"blue",
  1475. fontcolor2:"white",
  1476. })
  1477. break;
  1478. default:
  1479. that.setData({
  1480. type2:"",
  1481. timecontrolcolor2:"#888888",
  1482. fontcolor2:"#cccccc",
  1483. })
  1484. break;
  1485. }
  1486. switch (that.data.state1[0]) {
  1487. case true:
  1488. that.setData({
  1489. type3:"time",
  1490. timecontrolcolor3:"blue",
  1491. fontcolor3:"white",
  1492. })
  1493. break;
  1494. default:
  1495. that.setData({
  1496. type3:"",
  1497. timecontrolcolor3:"#888888",
  1498. fontcolor3:"#cccccc",
  1499. })
  1500. break;
  1501. }
  1502. switch (that.data.state1[1]) {
  1503. case true:
  1504. that.setData({
  1505. type4:"time",
  1506. timecontrolcolor4:"blue",
  1507. fontcolor4:"white",
  1508. })
  1509. break;
  1510. default:
  1511. that.setData({
  1512. type4:"",
  1513. timecontrolcolor4:"#888888",
  1514. fontcolor4:"#cccccc",
  1515. })
  1516. break;
  1517. }
  1518. switch (that.data.state[2]) {
  1519. case true:
  1520. that.setData({
  1521. Lightcontrolcolor1:"blue",
  1522. fontcolor5:"white",
  1523. select1:"selector"
  1524. })
  1525. break;
  1526. default:
  1527. that.setData({
  1528. Lightcontrolcolor1:"#888888",
  1529. fontcolor5:"#cccccc",
  1530. select1:""
  1531. })
  1532. break;
  1533. }
  1534. switch (that.data.state[3]) {
  1535. case true:
  1536. that.setData({
  1537. Lightcontrolcolor2:"blue",
  1538. fontcolor6:"white",
  1539. select2:"selector"
  1540. })
  1541. break;
  1542. default:
  1543. that.setData({
  1544. Lightcontrolcolor2:"#888888",
  1545. fontcolor6:"#cccccc",
  1546. select2:""
  1547. })
  1548. break;
  1549. }
  1550. }
  1551. }
  1552. })
  1553. },
  1554. //时间调控
  1555. //时控开关选择器
  1556. Controltime1:function(){
  1557. var obtain1 = this.data.state
  1558. obtain1[0] = !obtain1[0]
  1559. if(obtain1[0] == true){
  1560. this.setData({
  1561. type1:"time",
  1562. timecontrolcolor1:"blue",
  1563. fontcolor1:"white",
  1564. state:obtain1
  1565. })
  1566. }
  1567. else{
  1568. this.setData({
  1569. type1:"",
  1570. timecontrolcolor1:"#888888",
  1571. fontcolor1:"#cccccc",
  1572. state:obtain1
  1573. })
  1574. }
  1575. },
  1576. Controltime2:function(){
  1577. var obtain2 = this.data.state
  1578. obtain2[1] = !obtain2[1]
  1579. if(obtain2[1] == true){
  1580. this.setData({
  1581. type2:"time",
  1582. timecontrolcolor2:"blue",
  1583. fontcolor2:"white",
  1584. state:obtain2
  1585. })
  1586. }
  1587. else{
  1588. this.setData({
  1589. type2:"",
  1590. timecontrolcolor2:"#888888",
  1591. fontcolor2:"#cccccc",
  1592. state:obtain2
  1593. })
  1594. }
  1595. },
  1596. Controltime3:function(){
  1597. var obtain3 = this.data.state1
  1598. obtain3[0] = !obtain3[0]
  1599. if(obtain3[0] == true){
  1600. this.setData({
  1601. type3:"time",
  1602. timecontrolcolor3:"blue",
  1603. fontcolor3:"white",
  1604. state1:obtain3
  1605. })
  1606. }
  1607. else{
  1608. this.setData({
  1609. type3:"",
  1610. timecontrolcolor3:"#888888",
  1611. fontcolor3:"#cccccc",
  1612. state1:obtain3
  1613. })
  1614. }
  1615. },
  1616. Controltime4:function(){
  1617. var obtain4 = this.data.state1
  1618. obtain4[1] = !obtain4[1]
  1619. if(obtain4[1] == true){
  1620. this.setData({
  1621. type4:"time",
  1622. timecontrolcolor4:"blue",
  1623. fontcolor4:"white",
  1624. state1:obtain4
  1625. })
  1626. }
  1627. else{
  1628. this.setData({
  1629. type4:"",
  1630. timecontrolcolor4:"#888888",
  1631. fontcolor4:"#cccccc",
  1632. state1:obtain4
  1633. })
  1634. }
  1635. },
  1636. //固定与经纬的切换
  1637. change1:function(){
  1638. var change1 = this.data.fixed1
  1639. if (change1 == "固定" && this.data.state[0] == true) {
  1640. this.setData({
  1641. fixed1:"经纬"
  1642. })
  1643. }
  1644. else if(change1 == "经纬" && this.data.state[0] == true){
  1645. this.setData({
  1646. fixed1:"固定"
  1647. })
  1648. }
  1649. },
  1650. change2:function(){
  1651. var change2 = this.data.fixed2
  1652. if (change2 == "固定" && this.data.state[1] == true) {
  1653. this.setData({
  1654. fixed2:"经纬"
  1655. })
  1656. }
  1657. else if(change2 == "经纬" && this.data.state[1] == true){
  1658. this.setData({
  1659. fixed2:"固定"
  1660. })
  1661. }
  1662. },
  1663. change3:function(){
  1664. var change3 = this.data.fixed3
  1665. if (change3 == "固定") {
  1666. this.setData({
  1667. fixed3:"经纬"
  1668. })
  1669. }
  1670. else{
  1671. this.setData({
  1672. fixed3:"固定"
  1673. })
  1674. }
  1675. },
  1676. change4:function(){
  1677. var change4 = this.data.fixed4
  1678. if (change4 == "固定") {
  1679. this.setData({
  1680. fixed4:"经纬"
  1681. })
  1682. }
  1683. else{
  1684. this.setData({
  1685. fixed4:"固定"
  1686. })
  1687. }
  1688. },
  1689. //显示改变后的时间的值
  1690. bindTimeChange1: function(e) {
  1691. var time1 = this.data.time
  1692. time1[0] = e.detail.value
  1693. this.setData({
  1694. time: time1
  1695. })
  1696. },
  1697. bindTimeChange2: function(e) {
  1698. var time2 = this.data.time
  1699. time2[1] = e.detail.value
  1700. this.setData({
  1701. time:time2
  1702. })
  1703. },
  1704. bindTimeChange3: function(e) {
  1705. var time3 = this.data.time
  1706. time3[2] = e.detail.value
  1707. this.setData({
  1708. time:time3
  1709. })
  1710. },
  1711. bindTimeChange4: function(e) {
  1712. var time4 = this.data.time
  1713. time4[3] = e.detail.value
  1714. this.setData({
  1715. time:time4
  1716. })
  1717. },
  1718. //日期调控(图片切换)
  1719. setbuty0:function(){
  1720. var that = this
  1721. var a0 = that.data.address
  1722. if (that.data.address[0] == "/image/true.png") {
  1723. a0[0] = "/image/false.png"
  1724. this.setData({
  1725. address:a0,
  1726. })
  1727. } else {
  1728. a0[0] = "/image/true.png"
  1729. this.setData({
  1730. address:a0,
  1731. })
  1732. }
  1733. },
  1734. setbuty1:function(){
  1735. var that = this
  1736. var a1 = that.data.address
  1737. if (that.data.address[1] == "/image/true.png") {
  1738. a1[1] = "/image/false.png"
  1739. this.setData({
  1740. address:a1,
  1741. })
  1742. } else {
  1743. a1[1] = "/image/true.png"
  1744. this.setData({
  1745. address:a1,
  1746. })
  1747. }
  1748. },
  1749. setbuty2:function(){
  1750. var that = this
  1751. var a2 = that.data.address
  1752. if (that.data.address[2] == "/image/true.png") {
  1753. a2[2] = "/image/false.png"
  1754. this.setData({
  1755. address:a2,
  1756. })
  1757. } else {
  1758. a2[2] = "/image/true.png"
  1759. this.setData({
  1760. address:a2,
  1761. })
  1762. }
  1763. },
  1764. setbuty3:function(){
  1765. var that = this
  1766. var a3 = that.data.address
  1767. if (that.data.address[3] == "/image/true.png") {
  1768. a3[3] = "/image/false.png"
  1769. this.setData({
  1770. address:a3,
  1771. })
  1772. } else {
  1773. a3[3] = "/image/true.png"
  1774. this.setData({
  1775. address:a3,
  1776. })
  1777. }
  1778. },
  1779. setbuty4:function(){
  1780. var that = this
  1781. var a4 = that.data.address
  1782. if (that.data.address[4] == "/image/true.png") {
  1783. a4[4] = "/image/false.png"
  1784. this.setData({
  1785. address:a4,
  1786. })
  1787. } else {
  1788. a4[4] = "/image/true.png"
  1789. this.setData({
  1790. address:a4,
  1791. })
  1792. }
  1793. },
  1794. setbuty5:function(){
  1795. var that = this
  1796. var a5 = that.data.address
  1797. if (that.data.address[5] == "/image/true.png") {
  1798. a5[5] = "/image/false.png"
  1799. this.setData({
  1800. address:a5,
  1801. })
  1802. } else {
  1803. a5[5] = "/image/true.png"
  1804. this.setData({
  1805. address:a5,
  1806. })
  1807. }
  1808. },
  1809. setbuty6:function(){
  1810. var that = this
  1811. var a6 = that.data.address
  1812. if (that.data.address[6] == "/image/true.png") {
  1813. a6[6] = "/image/false.png"
  1814. this.setData({
  1815. address:a6,
  1816. })
  1817. } else {
  1818. a6[6] = "/image/true.png"
  1819. this.setData({
  1820. address:a6,
  1821. })
  1822. }
  1823. },
  1824. //光控
  1825. //光控开关选择器
  1826. Controltime5:function(){
  1827. var Lightstatus = this.data.state
  1828. Lightstatus[2] = !Lightstatus[2]
  1829. if(Lightstatus[2] == true){
  1830. for (let a = 0; a < 100 ;a++){
  1831. var arr1 = this.data.arr
  1832. arr1[a] = a
  1833. }
  1834. this.setData({
  1835. arr:arr1,
  1836. fontcolor5:"white",
  1837. Lightcontrolcolor1:"blue",
  1838. select1:"selector"
  1839. })
  1840. }
  1841. else{
  1842. this.setData({
  1843. Lightcontrolcolor1:"#888888",
  1844. fontcolor5:"#cccccc",
  1845. select1:""
  1846. })
  1847. }
  1848. },
  1849. Controltime6:function(){
  1850. var Lightstatus = this.data.state
  1851. Lightstatus[3] = !Lightstatus[3]
  1852. if(Lightstatus[3] == true){
  1853. for (let a = 0; a < 100 ;a++){
  1854. var arr1 = this.data.arr
  1855. arr1[a] = a
  1856. }
  1857. this.setData({
  1858. arr:arr1,
  1859. fontcolor6:"white",
  1860. Lightcontrolcolor2:"blue",
  1861. select2:"selector"
  1862. })
  1863. }
  1864. else{
  1865. this.setData({
  1866. Lightcontrolcolor2:"#888888",
  1867. fontcolor6:"#cccccc",
  1868. select2:""
  1869. })
  1870. }
  1871. },
  1872. //调整光控显示的值
  1873. bindPickerChange1: function(e) {
  1874. this.setData({
  1875. index: e.detail.value
  1876. })
  1877. },
  1878. bindPickerChange2: function(e) {
  1879. this.setData({
  1880. indexs: e.detail.value
  1881. })
  1882. },
  1883. //报警状态
  1884. Changestate1:function(){
  1885. this.setData({
  1886. radio1:true,
  1887. radio2:false,
  1888. radio3:false,
  1889. alert:"1"
  1890. })
  1891. },
  1892. Changestate2:function(){
  1893. this.setData({
  1894. radio1:false,
  1895. radio2:true,
  1896. radio3:false,
  1897. alert:"5"
  1898. })
  1899. },
  1900. Changestate3:function(){
  1901. this.setData({
  1902. radio1:false,
  1903. radio2:false,
  1904. radio3:true,
  1905. alert:"9"
  1906. })
  1907. },
  1908. //刷新页面
  1909. RefreshPage:function(){
  1910. wx.showToast({
  1911. title:'刷新中',
  1912. icon:'loading',
  1913. duration: 2000
  1914. })
  1915. var that = this
  1916. //获取机型改变switch大小
  1917. wx.getSystemInfo({
  1918. success:function(res){
  1919. if(res.model == 'iPad' || res.model == 'iPad Pro 10.5-inch' || res.model == 'iPad Pro 12.9-inch'){
  1920. that.setData({
  1921. zoom:1
  1922. })
  1923. }
  1924. }
  1925. })
  1926. var group = wx.getStorageSync('group')
  1927. //获取分组下拉
  1928. var groups = []
  1929. var device = []
  1930. for(let i = 0;i < group.length;i++){
  1931. groups.push(group[i].groupName)
  1932. }
  1933. that.setData({
  1934. groupName:groups
  1935. })
  1936. //改变分组下标
  1937. if(wx.getStorageSync('groupName') != ''){
  1938. let GroupName = that.data.groupName
  1939. for(let n = 0;n < GroupName.length;n++){
  1940. if(GroupName[n] == wx.getStorageSync('groupName')){
  1941. that.setData({
  1942. groupIndex:n
  1943. })
  1944. }
  1945. }
  1946. }
  1947. else{
  1948. wx.setStorageSync('groupName',that.data.groupName[that.data.groupIndex])
  1949. }
  1950. //获取设备下拉
  1951. var groupName = that.data.groupName
  1952. var groupIndex = that.data.groupIndex
  1953. for(let j = 0;j < group.length;j++){
  1954. if(groupName[groupIndex] == group[j].groupName){
  1955. if(group[j].devices != null && group[j].devices.length != 0){
  1956. for(let p = 0;p < group[j].devices.length;p++){
  1957. device.push(group[j].devices[p].deviceName)
  1958. }
  1959. that.setData({deviceName:device})
  1960. if(wx.getStorageSync('deviceName') != ''){
  1961. var DeviceName = that.data.deviceName
  1962. for(let m = 0;m < DeviceName.length;m++){
  1963. if(DeviceName[m] == wx.getStorageSync('deviceName')){
  1964. that.setData({
  1965. deviceIndex:m
  1966. })
  1967. }
  1968. }
  1969. }
  1970. else{
  1971. wx.setStorageSync('deviceName', that.data.deviceName[that.data.deviceIndex])
  1972. }
  1973. //根据分组名和设备名获取key和id以及回路名称
  1974. var groupNames = that.data.groupName[that.data.groupIndex]
  1975. var deviceNames = that.data.deviceName[that.data.deviceIndex]
  1976. for(let d = 0;d < group.length;d++){
  1977. if(groupNames == group[d].groupName){
  1978. for(let g = 0;g < group[d].devices.length;g++){
  1979. if(deviceNames == group[d].devices[g].deviceName){
  1980. var loopnum = group[d].devices[g].circuits
  1981. var deviceId = group[d].devices[g].deviceId
  1982. var deviceKey = group[d].devices[g].deviceKey
  1983. }
  1984. }
  1985. }
  1986. }
  1987. that.setData({deviceId:deviceId,deviceKey:deviceKey})
  1988. wx.request({
  1989. url: 'https://api.heclouds.com/devices/' + deviceId,
  1990. method:'GET',
  1991. header:{"api-key": deviceKey},
  1992. success:(res) =>{
  1993. if (res.data.data.online == true) {
  1994. that.setData({
  1995. status:"在线"
  1996. })
  1997. wx.request({
  1998. url: 'https://api.heclouds.com/devices/' + deviceId + '/datastreams',
  1999. header:{"api-key": deviceKey},
  2000. method:'GET',
  2001. success:(res) => {
  2002. let {data} = res.data
  2003. //以下为回路
  2004. for(let i = 1;i < data.length;i++){
  2005. //回路数量
  2006. if(data[i].id == "RelayCount"){
  2007. var num = data[i].current_value
  2008. num = parseInt(num)
  2009. loopnum = loopnum.split(',')
  2010. var num1 = []
  2011. for(let a = 0;a < num;a++){
  2012. num1.push(loopnum[a])
  2013. }
  2014. num1.push('所有回路')
  2015. that.setData({
  2016. crr:num1,
  2017. })
  2018. }
  2019. //时控一开时间
  2020. else if(data[i].id == "R1_DayOpenTime1"){
  2021. var timeopen1 = data[i].current_value
  2022. }
  2023. //时控一关时间
  2024. else if(data[i].id == "R1_DayCloseTime1"){
  2025. var timeshut1 = data[i].current_value
  2026. }
  2027. //时控二开时间
  2028. else if(data[i].id == "R1_DayOpenTime2"){
  2029. var timeopen2 = data[i].current_value
  2030. }
  2031. //时控二关时间
  2032. else if(data[i].id == "R1_DayCloseTime2"){
  2033. var timeshut2 = data[i].current_value
  2034. }
  2035. //日期调控
  2036. else if(data[i].id == "R1_Week"){
  2037. var weeks = data[i].current_value
  2038. that.setData({recorddate:weeks})
  2039. weeks = parseInt(weeks)
  2040. weeks = weeks.toString(2)
  2041. weeks = weeks + ''
  2042. if(weeks != '0'){
  2043. weeks = weeks.slice(1)
  2044. }
  2045. }
  2046. //功能1
  2047. else if(data[i].id == "R1_FunctionStatus1"){
  2048. var Function1 = data[i].current_value
  2049. var par = parseInt(Function1)
  2050. par = par.toString(2)
  2051. par = par + ''
  2052. switch (par.length) {
  2053. case 1:
  2054. par = '00000' + par
  2055. break;
  2056. case 2:
  2057. par = '0000' + par
  2058. break;
  2059. case 3:
  2060. par = '000' + par
  2061. break;
  2062. case 4:
  2063. par = '00' + par
  2064. break;
  2065. case 5:
  2066. par = '0' + par
  2067. break;
  2068. default:
  2069. par = par
  2070. }
  2071. }
  2072. //功能二
  2073. else if(data[i].id == "R1_FunctionStatus2"){
  2074. var Function2 = data[i].current_value
  2075. var qur = parseInt(Function2)
  2076. qur = qur.toString(2)
  2077. qur = qur + ''
  2078. switch (qur.length) {
  2079. case 1:
  2080. qur = '000' + qur
  2081. break;
  2082. case 2:
  2083. qur = '00' + qur
  2084. break;
  2085. case 3:
  2086. qur = '0' + qur
  2087. break;
  2088. case 4:
  2089. qur = qur
  2090. break;
  2091. }
  2092. }
  2093. //报警
  2094. else if(data[i].id == "R1_RelayStatus"){
  2095. var police = data[i].current_value
  2096. }
  2097. //光控开
  2098. else if(data[i].id == "R1_LcOn"){
  2099. var Lightcontrolopen = data[i].current_value
  2100. var trr = that.data.arr
  2101. for(let i = 0;i < 100;i++){
  2102. trr[i] = i
  2103. }
  2104. Lightcontrolopen = parseInt(Lightcontrolopen)
  2105. that.setData({arr:trr,index:Lightcontrolopen})
  2106. }
  2107. //光控关
  2108. else if(data[i].id == "R1_LcOff"){
  2109. var Lightcontrolshut = data[i].current_value
  2110. var prr = that.data.brr
  2111. for(let j =0;j < 100;j++){
  2112. prr[j] = j
  2113. }
  2114. Lightcontrolshut = parseInt(Lightcontrolshut)
  2115. that.setData({brr:prr,indexs:Lightcontrolshut})
  2116. }
  2117. }
  2118. //时控一开时间
  2119. var timeOpen1
  2120. switch (timeopen1.length) {
  2121. case 1:
  2122. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0,1)
  2123. break;
  2124. case 2:
  2125. timeOpen1 = '00' + ':' + timeopen1.substring(0,2)
  2126. break;
  2127. case 3:
  2128. var timeOpen1 = '0' + timeopen1.substring(0,1) + ':' + timeopen1.substring(1,3)
  2129. break;
  2130. case 4:
  2131. var timeOpen1 = timeopen1.substring(0,2) + ':' + timeopen1.substring(2,4)
  2132. break;
  2133. }
  2134. //时控一关时间
  2135. var timeShut1
  2136. switch (timeshut1.length) {
  2137. case 1:
  2138. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0,1)
  2139. break;
  2140. case 2:
  2141. timeShut1 = '00' + ':' + timeshut1.substring(0,2)
  2142. break;
  2143. case 3:
  2144. var timeShut1 = '0' + timeshut1.substring(0,1) + ':' + timeshut1.substring(1,3)
  2145. break;
  2146. case 4:
  2147. var timeShut1 = timeshut1.substring(0,2) + ':' + timeshut1.substring(2,4)
  2148. break;
  2149. }
  2150. //时控二开时间
  2151. var timeOpen2
  2152. switch (timeopen2.length) {
  2153. case 1:
  2154. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0,1)
  2155. break;
  2156. case 2:
  2157. timeOpen2 = '00' + ':' + timeopen2.substring(0,2)
  2158. break;
  2159. case 3:
  2160. var timeOpen2 = '0' + timeopen2.substring(0,1) + ':' + timeopen2.substring(1,3)
  2161. break;
  2162. case 4:
  2163. var timeOpen2 = timeopen2.substring(0,2) + ':' + timeopen2.substring(2,4)
  2164. break;
  2165. }
  2166. //时控二关时间
  2167. var timeShut2
  2168. switch (timeshut2.length) {
  2169. case 1:
  2170. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0,1)
  2171. break;
  2172. case 2:
  2173. timeShut2 = '00' + ':' + timeshut2.substring(0,2)
  2174. break;
  2175. case 3:
  2176. var timeShut2 = '0' + timeshut2.substring(0,1) + ':' + timeshut2.substring(1,3)
  2177. break;
  2178. case 4:
  2179. var timeShut2 = timeshut2.substring(0,2) + ':' + timeshut2.substring(2,4)
  2180. break;
  2181. }
  2182. //功能1
  2183. for(var i = 0;i < par.length;i++){
  2184. var engry = that.data.state
  2185. switch(par.substring(i,i+1)){
  2186. case "0":
  2187. switch (i) {
  2188. case 0:
  2189. engry[3] = false
  2190. that.setData({state:engry})
  2191. break;
  2192. case 1:
  2193. engry[2] = false
  2194. that.setData({state:engry})
  2195. break;
  2196. case 2:
  2197. that.setData({fixed2:"固定"})
  2198. break;
  2199. case 3:
  2200. that.setData({fixed1:"固定"})
  2201. break;
  2202. case 4:
  2203. engry[1] = false
  2204. that.setData({state:engry})
  2205. break;
  2206. case 5:
  2207. engry[0] = false
  2208. that.setData({state:engry})
  2209. break;
  2210. }
  2211. break;
  2212. case "1":
  2213. switch (i) {
  2214. case 0:
  2215. engry[3] = true
  2216. that.setData({state:engry})
  2217. break;
  2218. case 1:
  2219. engry[2] = true
  2220. that.setData({state:engry})
  2221. break;
  2222. case 2:
  2223. that.setData({fixed2:"经纬"})
  2224. break;
  2225. case 3:
  2226. that.setData({fixed1:"经纬"})
  2227. break;
  2228. case 4:
  2229. engry[1] = true
  2230. that.setData({state:engry})
  2231. break;
  2232. case 5:
  2233. engry[0] = true
  2234. that.setData({state:engry})
  2235. break;
  2236. }
  2237. break;
  2238. }
  2239. }
  2240. //功能2
  2241. for(let j = 0;j < qur.length;j++){
  2242. var Engry = that.data.state1
  2243. switch(qur.substring(j,j+1)){
  2244. case "0":
  2245. switch (j) {
  2246. case 0:
  2247. that.setData({fixed4:"固定"})
  2248. break;
  2249. case 1:
  2250. that.setData({fixed3:"固定"})
  2251. break;
  2252. case 2:
  2253. Engry[1] = false
  2254. that.setData({state1:Engry})
  2255. break;
  2256. case 3:
  2257. Engry[0] = false
  2258. that.setData({state1:Engry})
  2259. break;
  2260. }
  2261. break;
  2262. case "1":
  2263. switch (j) {
  2264. case 0:
  2265. that.setData({fixed4:"经纬"})
  2266. break;
  2267. case 1:
  2268. that.setData({fixed3:"经纬"})
  2269. break;
  2270. case 2:
  2271. Engry[1] = true
  2272. that.setData({state1:Engry})
  2273. break;
  2274. case 3:
  2275. Engry[0] = true
  2276. that.setData({state1:Engry})
  2277. break;
  2278. }
  2279. break;
  2280. }
  2281. }
  2282. //日期调控
  2283. var controladdress = that.data.address
  2284. if (weeks == '0') {
  2285. for(let x = 0;x < weeks.length; x++){
  2286. controladdress[x] = "/image/false.png"
  2287. }
  2288. that.setData({
  2289. address:controladdress,
  2290. })
  2291. }
  2292. else{
  2293. for(let i = 0;i < weeks.length;i++){
  2294. switch (weeks.substring(i,i+1)) {
  2295. case '0':
  2296. controladdress[weeks.length-i-1] = "/image/false.png"
  2297. that.setData({
  2298. address:controladdress,
  2299. })
  2300. break;
  2301. case '1':
  2302. controladdress[weeks.length-i-1] = "/image/true.png"
  2303. that.setData({
  2304. address:controladdress,
  2305. })
  2306. break;
  2307. }
  2308. }
  2309. }
  2310. //报警状态
  2311. police = parseInt(police)
  2312. police = police.toString(2)
  2313. switch(police.length){
  2314. case 1:
  2315. police = '000' + police
  2316. break;
  2317. case 2:
  2318. police = '00' + police
  2319. break;
  2320. case 3:
  2321. police = '0' + police
  2322. break;
  2323. default:
  2324. police = police
  2325. break;
  2326. }
  2327. if(police.substring(1,2) == '0' && police.substring(0,1) == '0'){
  2328. that.setData({
  2329. radio1:true
  2330. })
  2331. }
  2332. else if(police.substring(1,2) == '1' && police.substring(0,1) == '0'){
  2333. that.setData({
  2334. radio2:true
  2335. })
  2336. }
  2337. else if(police.substring(1,2) == '0' && police.substring(0,1) == '1'){
  2338. that.setData({
  2339. radio3:true
  2340. })
  2341. }
  2342. var time = that.data.time
  2343. time[0] = timeOpen1
  2344. time[1] = timeShut1
  2345. time[2] = timeOpen2
  2346. time[3] = timeShut2
  2347. that.setData({
  2348. time:time,
  2349. })
  2350. //监视开关状态(改变颜色,调整功能)
  2351. switch (that.data.state[0]) {
  2352. case true:
  2353. that.setData({
  2354. type1:"time",
  2355. timecontrolcolor1:"blue",
  2356. fontcolor1:"white",
  2357. })
  2358. break;
  2359. default:
  2360. that.setData({
  2361. type1:"",
  2362. timecontrolcolor1:"#888888",
  2363. fontcolor1:"#cccccc",
  2364. })
  2365. break;
  2366. }
  2367. switch (that.data.state[1]) {
  2368. case true:
  2369. that.setData({
  2370. type2:"time",
  2371. timecontrolcolor2:"blue",
  2372. fontcolor2:"white",
  2373. })
  2374. break;
  2375. default:
  2376. that.setData({
  2377. type2:"",
  2378. timecontrolcolor2:"#888888",
  2379. fontcolor2:"#cccccc",
  2380. })
  2381. break;
  2382. }
  2383. switch (that.data.state1[0]) {
  2384. case true:
  2385. that.setData({
  2386. type3:"time",
  2387. timecontrolcolor3:"blue",
  2388. fontcolor3:"white",
  2389. })
  2390. break;
  2391. default:
  2392. that.setData({
  2393. type3:"",
  2394. timecontrolcolor3:"#888888",
  2395. fontcolor3:"#cccccc",
  2396. })
  2397. break;
  2398. }
  2399. switch (that.data.state1[1]) {
  2400. case true:
  2401. that.setData({
  2402. type4:"time",
  2403. timecontrolcolor4:"blue",
  2404. fontcolor4:"white",
  2405. })
  2406. break;
  2407. default:
  2408. that.setData({
  2409. type4:"",
  2410. timecontrolcolor4:"#888888",
  2411. fontcolor4:"#cccccc",
  2412. })
  2413. break;
  2414. }
  2415. switch (that.data.state[2]) {
  2416. case true:
  2417. that.setData({
  2418. Lightcontrolcolor1:"blue",
  2419. fontcolor5:"white",
  2420. select1:"selector"
  2421. })
  2422. break;
  2423. default:
  2424. that.setData({
  2425. Lightcontrolcolor1:"#888888",
  2426. fontcolor5:"#cccccc",
  2427. select1:""
  2428. })
  2429. break;
  2430. }
  2431. switch (that.data.state[3]) {
  2432. case true:
  2433. that.setData({
  2434. Lightcontrolcolor2:"blue",
  2435. fontcolor6:"white",
  2436. select2:"selector"
  2437. })
  2438. break;
  2439. default:
  2440. that.setData({
  2441. Lightcontrolcolor2:"#888888",
  2442. fontcolor6:"#cccccc",
  2443. select2:""
  2444. })
  2445. break;
  2446. }
  2447. }
  2448. })
  2449. }
  2450. else{
  2451. that.setData({
  2452. status:"离线"
  2453. })
  2454. }
  2455. }
  2456. })
  2457. }
  2458. else{
  2459. that.setData({status:'离线'})
  2460. }
  2461. }
  2462. }
  2463. },
  2464. //存储数据
  2465. Storedata: function(){
  2466. var that = this
  2467. var indexes = that.data.indexes
  2468. var lamp = wx.getStorageSync('lamp')
  2469. var radio1 = that.data.radio1
  2470. var radio2 = that.data.radio2
  2471. var radio3 = that.data.radio3
  2472. var jude
  2473. if(lamp[indexes] == '/image/lamp.png' && radio1 == true){
  2474. jude = 0
  2475. }
  2476. else if(lamp[indexes] == '/image/lamp.png' && radio2 == true){
  2477. jude = 4
  2478. }
  2479. else if(lamp[indexes] == '/image/lamp.png' && radio3 == true){
  2480. jude = 8
  2481. }
  2482. else if(lamp[indexes] == '/image/lamp1.png' && radio1 == true){
  2483. jude = 1
  2484. }
  2485. else if(lamp[indexes] == '/image/lamp1.png' && radio2 == true){
  2486. jude = 5
  2487. }
  2488. else if(lamp[indexes] == '/image/lamp1.png' && radio3 == true){
  2489. jude = 9
  2490. }
  2491. //功能一
  2492. var Storagetimeopen1
  2493. var Storagetimeshut1
  2494. var Storagetimeopenstate1
  2495. var Storagetimeshutstate1
  2496. var Storageopticalopen
  2497. var Storageopticalshut
  2498. //时控一开
  2499. switch(that.data.state[0]){
  2500. case true:
  2501. Storagetimeopen1 = "1"
  2502. break;
  2503. case false:
  2504. Storagetimeopen1 = "0"
  2505. break;
  2506. }
  2507. //时控一关
  2508. switch(that.data.state[1]){
  2509. case true:
  2510. Storagetimeshut1 = "1"
  2511. break;
  2512. case false:
  2513. Storagetimeshut1 = "0"
  2514. break;
  2515. }
  2516. //时控一开经纬
  2517. switch (that.data.fixed1) {
  2518. case "经纬":
  2519. Storagetimeopenstate1 = "1"
  2520. break;
  2521. case "固定":
  2522. Storagetimeopenstate1 = "0"
  2523. break;
  2524. }
  2525. //时控一关经纬
  2526. switch (that.data.fixed2) {
  2527. case "经纬":
  2528. Storagetimeshutstate1 = "1"
  2529. break;
  2530. case "固定":
  2531. Storagetimeshutstate1 = "0"
  2532. break;
  2533. }
  2534. //光控开
  2535. switch (that.data.state[2]) {
  2536. case true:
  2537. Storageopticalopen = "1"
  2538. break;
  2539. case false:
  2540. Storageopticalopen = "0"
  2541. break;
  2542. }
  2543. //光控关
  2544. switch (that.data.state[3]) {
  2545. case true:
  2546. Storageopticalshut = "1"
  2547. break;
  2548. case false:
  2549. Storageopticalshut = "0"
  2550. break;
  2551. }
  2552. var use1 = Storageopticalshut + Storageopticalopen + Storagetimeshutstate1 + Storagetimeopenstate1 + Storagetimeshut1 + Storagetimeopen1
  2553. use1 = parseInt(use1,2)
  2554. use1 = use1//传给后台的功能一数据
  2555. //功能二
  2556. var Storagetimeopen2
  2557. var Storagetimeshut2
  2558. var Storagetimeopenstate2
  2559. var Storagetimeshutstate2
  2560. //时控二开
  2561. switch (that.data.state1[0]) {
  2562. case true:
  2563. Storagetimeopen2 = "1"
  2564. break;
  2565. case false:
  2566. Storagetimeopen2 = "0"
  2567. break;
  2568. }
  2569. //时控二关
  2570. switch (that.data.state1[1]) {
  2571. case true:
  2572. Storagetimeshut2 = "1"
  2573. break;
  2574. case false:
  2575. Storagetimeshut2 = "0"
  2576. break;
  2577. }
  2578. //时控二开经纬
  2579. switch (that.data.fixed3) {
  2580. case "经纬":
  2581. Storagetimeopenstate2 = "1"
  2582. break;
  2583. case "固定":
  2584. Storagetimeopenstate2 = "0"
  2585. break;
  2586. }
  2587. //时控二关经纬
  2588. switch (that.data.fixed4) {
  2589. case "经纬":
  2590. Storagetimeshutstate2 = "1"
  2591. break;
  2592. case "固定":
  2593. Storagetimeshutstate2 = "0"
  2594. break;
  2595. }
  2596. var use2 = Storagetimeshutstate2 + Storagetimeopenstate2 + Storagetimeshut2 + Storagetimeopen2
  2597. use2 = parseInt(use2,2)
  2598. use2 = use2//传给后台的功能二数据
  2599. //时控一开时间
  2600. var Ontime1 = that.data.time[0]
  2601. var ontime1//传给后台的时控一开时间
  2602. if (Ontime1.substring(0,2) == '00' && Ontime1.substring(3,5) == '00') {
  2603. ontime1 = '0'
  2604. }
  2605. else if (Ontime1.substring(0,1) != '0') {
  2606. ontime1 = Ontime1.substring(0,2) + Ontime1.substring(3,5)
  2607. }
  2608. else if (Ontime1.substring(0,1) == '0' && Ontime1.substring(1,2) != '0' ) {
  2609. ontime1 = Ontime1.substring(1,2) + Ontime1.substring(3,5)
  2610. }
  2611. else if (Ontime1.substring(0,2) == '00' && Ontime1.substring(3,4) != '0') {
  2612. ontime1 = Ontime1.substring(3,5)
  2613. }
  2614. else{
  2615. ontime1 = Ontime1.substring(4,5)
  2616. }
  2617. ontime1 = parseInt(ontime1)
  2618. //时控一关时间
  2619. var Closingtime1 = that.data.time[1]
  2620. var closingtime1//传给后台的时控一关时间
  2621. if (Closingtime1.substring(0,2) == '00' && Closingtime1.substring(3,5) == '00') {
  2622. closingtime1 = '0'
  2623. }
  2624. else if (Closingtime1.substring(0,1) != '0') {
  2625. closingtime1 = Closingtime1.substring(0,2) + Closingtime1.substring(3,5)
  2626. }
  2627. else if (Closingtime1.substring(0,1) == '0' && Closingtime1.substring(1,2) != '0' ) {
  2628. closingtime1 = Closingtime1.substring(1,2) + Closingtime1.substring(3,5)
  2629. }
  2630. else if (Closingtime1.substring(0,2) == '00' && Closingtime1.substring(3,4) != '0') {
  2631. closingtime1 = Closingtime1.substring(3,5)
  2632. }
  2633. else{
  2634. closingtime1 = Closingtime1.substring(4,5)
  2635. }
  2636. closingtime1 = parseInt(closingtime1)
  2637. //时控二开时间
  2638. var Ontime2 = that.data.time[2]
  2639. var ontime2//传给后台的时控二开时间
  2640. if (Ontime2.substring(0,2) == '00' && Ontime2.substring(3,5) == '00') {
  2641. ontime2 = '0'
  2642. }
  2643. else if (Ontime2.substring(0,1) != '0') {
  2644. ontime2 = Ontime2.substring(0,2) + Ontime2.substring(3,5)
  2645. }
  2646. else if (Ontime2.substring(0,1) == '0' && Ontime2.substring(1,2) != '0' ) {
  2647. ontime2 = Ontime2.substring(1,2) + Ontime2.substring(3,5)
  2648. }
  2649. else if (Ontime2.substring(0,2) == '00' && Ontime2.substring(3,4) != '0') {
  2650. ontime2 = Ontime2.substring(3,5)
  2651. }
  2652. else{
  2653. ontime2 = Ontime2.substring(4,5)
  2654. }
  2655. ontime2 = parseInt(ontime2)
  2656. //时控二关时间
  2657. var Closingtime2 = that.data.time[3]
  2658. var closingtime2//传给后台的时控二关时间
  2659. if (Closingtime2.substring(0,2) == '00' && Closingtime2.substring(3,5) == '00') {
  2660. closingtime2 = '0'
  2661. }
  2662. else if (Closingtime2.substring(0,1) != '0') {
  2663. closingtime2 = Closingtime2.substring(0,2) + Closingtime2.substring(3,5)
  2664. }
  2665. else if (Closingtime2.substring(0,1) == '0' && Closingtime2.substring(1,2) != '0' ) {
  2666. closingtime2 = Closingtime2.substring(1,2) + Closingtime2.substring(3,5)
  2667. }
  2668. else if (Closingtime2.substring(0,2) == '00' && Closingtime2.substring(3,4) != '0') {
  2669. closingtime2 = Closingtime2.substring(3,5)
  2670. }
  2671. else{
  2672. closingtime2 = Closingtime2.substring(4,5)
  2673. }
  2674. closingtime2 = parseInt(closingtime2)
  2675. //报警状态
  2676. var alerts = that.data.alert
  2677. //光控开
  2678. var Lightcontrolon = that.data.arr[that.data.index]
  2679. Lightcontrolon = Lightcontrolon
  2680. //光控关
  2681. var Lightcontroloff = that.data.brr[that.data.indexs]
  2682. Lightcontroloff = Lightcontroloff
  2683. //星期
  2684. var myweek = ""
  2685. for(let w = 0;w < that.data.address.length;w++){
  2686. switch (that.data.address[w]) {
  2687. case "/image/false.png":
  2688. myweek = myweek.concat("0")
  2689. break;
  2690. default:
  2691. myweek = myweek.concat("1")
  2692. break;
  2693. }
  2694. }
  2695. if (myweek == "0000000") {
  2696. myweek = 0
  2697. }
  2698. else{
  2699. myweek = "1" + myweek.split("").reverse().join("")
  2700. myweek = parseInt(myweek,2)
  2701. myweek = myweek
  2702. }
  2703. //发起post请求
  2704. if(that.data.status == "在线"){
  2705. wx.showToast({
  2706. title:'存储数据中',
  2707. icon:'success',
  2708. duration: 4000
  2709. })
  2710. var indexes = that.data.indexes
  2711. indexes = parseInt(indexes)
  2712. var crr = that.data.crr
  2713. if(crr[indexes] != '所有回路'){
  2714. var reflash = [11,12,13,14,15,16,17,18]
  2715. var i = indexes + 1
  2716. var week = "R" + i +"_Week"
  2717. var FunctionStatus1 = 'R' + i + '_FunctionStatus1'
  2718. var FunctionStatus2 = 'R' + i + '_FunctionStatus2'
  2719. var DayOpenTime1 = 'R' + i + '_DayOpenTime1'
  2720. var DayCloseTime1 = 'R' + i + '_DayCloseTime1'
  2721. var DayOpenTime2 = 'R' + i + '_DayOpenTime2'
  2722. var DayCloseTime2 = 'R' + i + '_DayCloseTime2'
  2723. var LcOn = 'R' + i + '_LcOn'
  2724. var LcOff ='R' + i + '_LcOff'
  2725. var RelayStatus = 'R' + i + '_RelayStatus'
  2726. var object ={"Reflash":reflash[indexes],[week]:myweek,[FunctionStatus1]:use1,[FunctionStatus2]:use2,
  2727. [DayOpenTime1]:ontime1,[DayCloseTime1]:closingtime1,[DayOpenTime2]:ontime2,
  2728. [DayCloseTime2]:closingtime2,[LcOn]:Lightcontrolon,[LcOff]:Lightcontroloff,[RelayStatus]:jude,}
  2729. wx.request({
  2730. url: 'https://api.heclouds.com/cmds?device_id=' + that.data.deviceId,
  2731. method:'POST',
  2732. header:{"api-key":that.data.deviceKey},
  2733. data:JSON.stringify(object),
  2734. success:function(res){
  2735. }
  2736. })
  2737. }
  2738. else{
  2739. var object1 = {
  2740. "Reflash":11,
  2741. "R1_Week":myweek,//星期
  2742. "R1_FunctionStatus1":use1,//功能1
  2743. "R1_FunctionStatus2":use2,//功能2
  2744. "R1_DayOpenTime1":ontime1,//时控1开
  2745. "R1_DayCloseTime1":closingtime1,//时控1关
  2746. "R1_DayOpenTime2":ontime2,//时控2开
  2747. "R1_DayCloseTime2":closingtime2,//时控2关
  2748. "R1_LcOn":Lightcontrolon,//光控开
  2749. "R1_LcOff":Lightcontroloff,//光控关
  2750. "R1_RelayStatus":jude,//开关状态
  2751. }
  2752. var object2 = {
  2753. "Reflash":12,
  2754. "R2_FunctionStatus1":use1,//功能1
  2755. "R2_FunctionStatus2":use2,//功能2
  2756. "R2_DayOpenTime1":ontime1,//时控1开
  2757. "R2_DayCloseTime1":closingtime1,//时控1关
  2758. "R2_DayOpenTime2":ontime2,//时控2开
  2759. "R2_DayCloseTime2":closingtime2,//时控2关
  2760. "R2_Week":myweek,//星期
  2761. "R2_LcOn":Lightcontrolon,//光控开
  2762. "R2_LcOff":Lightcontroloff,//光控关
  2763. "R2_RelayStatus":jude,//开关状态
  2764. }
  2765. var object3 = {
  2766. "Reflash":13,
  2767. "R3_FunctionStatus1":use1,//功能1
  2768. "R3_FunctionStatus2":use2,//功能2
  2769. "R3_DayOpenTime1":ontime1,//时控1开
  2770. "R3_DayCloseTime1":closingtime1,//时控1关
  2771. "R3_DayOpenTime2":ontime2,//时控2开
  2772. "R3_DayCloseTime2":closingtime2,//时控2关
  2773. "R3_Week":myweek,//星期
  2774. "R3_LcOn":Lightcontrolon,//光控开
  2775. "R3_LcOff":Lightcontroloff,//光控关
  2776. "R3_RelayStatus":jude,//开关状态
  2777. }
  2778. var object4 = {
  2779. "Reflash":14,
  2780. "R4_FunctionStatus1":use1,//功能1
  2781. "R4_FunctionStatus2":use2,//功能2
  2782. "R4_DayOpenTime1":ontime1,//时控1开
  2783. "R4_DayCloseTime1":closingtime1,//时控1关
  2784. "R4_DayOpenTime2":ontime2,//时控2开
  2785. "R4_DayCloseTime2":closingtime2,//时控2关
  2786. "R4_Week":myweek,//星期
  2787. "R4_LcOn":Lightcontrolon,//光控开
  2788. "R4_LcOff":Lightcontroloff,//光控关
  2789. "R4_RelayStatus":jude,//开关状态
  2790. }
  2791. var object5 = {
  2792. "Reflash":15,
  2793. "R5_FunctionStatus1":use1,//功能1
  2794. "R5_FunctionStatus2":use2,//功能2
  2795. "R5_DayOpenTime1":ontime1,//时控1开
  2796. "R5_DayCloseTime1":closingtime1,//时控1关
  2797. "R5_DayOpenTime2":ontime2,//时控2开
  2798. "R5_DayCloseTime2":closingtime2,//时控2关
  2799. "R5_Week":myweek,//星期
  2800. "R5_LcOn":Lightcontrolon,//光控开
  2801. "R5_LcOff":Lightcontroloff,//光控关
  2802. "R5_RelayStatus":jude,//开关状态
  2803. }
  2804. var object6 = {
  2805. "Reflash":16,
  2806. "R6_FunctionStatus1":use1,//功能1
  2807. "R6_FunctionStatus2":use2,//功能2
  2808. "R6_DayOpenTime1":ontime1,//时控1开
  2809. "R6_DayCloseTime1":closingtime1,//时控1关
  2810. "R6_DayOpenTime2":ontime2,//时控2开
  2811. "R6_DayCloseTime2":closingtime2,//时控2关
  2812. "R6_Week":myweek,//星期
  2813. "R6_LcOn":Lightcontrolon,//光控开
  2814. "R6_LcOff":Lightcontroloff,//光控关
  2815. "R6_RelayStatus":jude,//开关状态
  2816. }
  2817. var object7 = {
  2818. "Reflash":17,
  2819. "R7_FunctionStatus1":use1,//功能1
  2820. "R7_FunctionStatus2":use2,//功能2
  2821. "R7_DayOpenTime1":ontime1,//时控1开
  2822. "R7_DayCloseTime1":closingtime1,//时控1关
  2823. "R7_DayOpenTime2":ontime2,//时控2开
  2824. "R7_DayCloseTime2":closingtime2,//时控2关
  2825. "R7_Week":myweek,//星期
  2826. "R7_LcOn":Lightcontrolon,//光控开
  2827. "R7_LcOff":Lightcontroloff,//光控关
  2828. "R7_RelayStatus":jude,//开关状态
  2829. }
  2830. var object8 = {
  2831. "Reflash":18,
  2832. "R8_FunctionStatus1":use1,//功能1
  2833. "R8_FunctionStatus2":use2,//功能2
  2834. "R8_DayOpenTime1":ontime1,//时控1开
  2835. "R8_DayCloseTime1":closingtime1,//时控1关
  2836. "R8_DayOpenTime2":ontime2,//时控2开
  2837. "R8_DayCloseTime2":closingtime2,//时控2关
  2838. "R8_Week":myweek,//星期
  2839. "R8_LcOn":Lightcontrolon,//光控开
  2840. "R8_LcOff":Lightcontroloff,//光控关
  2841. "R8_RelayStatus":jude,//开关状态
  2842. }
  2843. wx.request({
  2844. url: 'https://api.heclouds.com/cmds?device_id=' + that.data.deviceId,
  2845. method:'POST',
  2846. header:{"api-key":that.data.deviceKey},
  2847. data:JSON.stringify(object1),
  2848. })
  2849. wx.request({
  2850. url: 'https://api.heclouds.com/cmds?device_id=' + that.data.deviceId,
  2851. method:'POST',
  2852. header:{"api-key":that.data.deviceKey},
  2853. data:JSON.stringify(object2),
  2854. })
  2855. wx.request({
  2856. url: 'https://api.heclouds.com/cmds?device_id=' + that.data.deviceId,
  2857. method:'POST',
  2858. header:{"api-key":that.data.deviceKey},
  2859. data:JSON.stringify(object3),
  2860. })
  2861. wx.request({
  2862. url: 'https://api.heclouds.com/cmds?device_id=' + that.data.deviceId,
  2863. method:'POST',
  2864. header:{"api-key":that.data.deviceKey},
  2865. data:JSON.stringify(object4),
  2866. })
  2867. wx.request({
  2868. url: 'https://api.heclouds.com/cmds?device_id=' + that.data.deviceId,
  2869. method:'POST',
  2870. header:{"api-key":that.data.deviceKey},
  2871. data:JSON.stringify(object5),
  2872. })
  2873. wx.request({
  2874. url: 'https://api.heclouds.com/cmds?device_id=' + that.data.deviceId,
  2875. method:'POST',
  2876. header:{"api-key":that.data.deviceKey},
  2877. data:JSON.stringify(object6),
  2878. })
  2879. wx.request({
  2880. url: 'https://api.heclouds.com/cmds?device_id=' + that.data.deviceId,
  2881. method:'POST',
  2882. header:{"api-key":that.data.deviceKey},
  2883. data:JSON.stringify(object7),
  2884. })
  2885. wx.request({
  2886. url: 'https://api.heclouds.com/cmds?device_id=' + that.data.deviceId,
  2887. method:'POST',
  2888. header:{"api-key":that.data.deviceKey},
  2889. data:JSON.stringify(object8),
  2890. })
  2891. }
  2892. }
  2893. else{
  2894. wx.showModal({
  2895. title:'提示',
  2896. content:'存储数据失败,请检查设备是否在线或者刷新页面',
  2897. showCancel:false,
  2898. })
  2899. }
  2900. },
  2901. /**
  2902. * 生命周期函数--监听页面加载
  2903. */
  2904. onLoad(options) {
  2905. },
  2906. /**
  2907. * 生命周期函数--监听页面初次渲染完成
  2908. */
  2909. onReady() {
  2910. },
  2911. /**
  2912. * 生命周期函数--监听页面显示
  2913. */
  2914. onShow() {
  2915. wx.showToast({
  2916. title:'获取数据中',
  2917. icon:'loading',
  2918. duration: 2000
  2919. })
  2920. var that = this
  2921. //获取机型改变switch大小
  2922. wx.getSystemInfo({
  2923. success:function(res){
  2924. if(res.model == 'iPad' || res.model == 'iPad Pro 10.5-inch' || res.model == 'iPad Pro 12.9-inch'){
  2925. that.setData({
  2926. zoom:1
  2927. })
  2928. }
  2929. }
  2930. })
  2931. var group = wx.getStorageSync('group')
  2932. //获取分组下拉
  2933. var groups = []
  2934. var device = []
  2935. for(let i = 0;i < group.length;i++){
  2936. groups.push(group[i].groupName)
  2937. }
  2938. that.setData({
  2939. groupName:groups
  2940. })
  2941. //改变分组下标
  2942. if(wx.getStorageSync('groupName') != ''){
  2943. let GroupName = that.data.groupName
  2944. for(let n = 0;n < GroupName.length;n++){
  2945. if(GroupName[n] == wx.getStorageSync('groupName')){
  2946. that.setData({
  2947. groupIndex:n
  2948. })
  2949. }
  2950. }
  2951. }
  2952. //获取设备下拉
  2953. var groupName = that.data.groupName
  2954. var groupIndex = that.data.groupIndex
  2955. for(let j = 0;j < group.length;j++){
  2956. if(groupName[groupIndex] == group[j].groupName){
  2957. if(group[j].devices != null && group[j].devices.length != 0){
  2958. for(let p = 0;p < group[j].devices.length;p++){
  2959. device.push(group[j].devices[p].deviceName)
  2960. }
  2961. that.setData({deviceName:device})
  2962. if(wx.getStorageSync('deviceName') != ''){
  2963. var DeviceName = that.data.deviceName
  2964. for(let m = 0;m < DeviceName.length;m++){
  2965. if(DeviceName[m] == wx.getStorageSync('deviceName')){
  2966. that.setData({
  2967. deviceIndex:m
  2968. })
  2969. }
  2970. }
  2971. }
  2972. //根据分组名和设备名获取key和id以及回路名称
  2973. var groupNames = that.data.groupName[that.data.groupIndex]
  2974. var deviceNames = that.data.deviceName[that.data.deviceIndex]
  2975. for(let d = 0;d < group.length;d++){
  2976. if(groupNames == group[d].groupName){
  2977. for(let g = 0;g < group[d].devices.length;g++){
  2978. if(deviceNames == group[d].devices[g].deviceName){
  2979. var loopnum = group[d].devices[g].circuits
  2980. var deviceId = group[d].devices[g].deviceId
  2981. var deviceKey = group[d].devices[g].deviceKey
  2982. }
  2983. }
  2984. }
  2985. }
  2986. that.setData({deviceId:deviceId,deviceKey:deviceKey})
  2987. wx.request({
  2988. url: 'https://api.heclouds.com/devices/' + deviceId,
  2989. method:'GET',
  2990. header:{"api-key": deviceKey},
  2991. success:(res) =>{
  2992. if (res.data.data.online == true) {
  2993. that.setData({
  2994. status:"在线"
  2995. })
  2996. wx.request({
  2997. url: 'https://api.heclouds.com/devices/' + deviceId + '/datastreams',
  2998. header:{"api-key": deviceKey},
  2999. method:'GET',
  3000. success:(res) => {
  3001. let {data} = res.data
  3002. //以下为回路
  3003. for(let i = 1;i < data.length;i++){
  3004. //回路数量
  3005. if(data[i].id == "RelayCount"){
  3006. var num = data[i].current_value
  3007. num = parseInt(num)
  3008. loopnum = loopnum.split(',')
  3009. var num1 = []
  3010. for(let a = 0;a < num;a++){
  3011. num1.push(loopnum[a])
  3012. }
  3013. num1.push('所有回路')
  3014. that.setData({
  3015. crr:num1,
  3016. })
  3017. }
  3018. //时控一开时间
  3019. else if(data[i].id == "R1_DayOpenTime1"){
  3020. var timeopen1 = data[i].current_value
  3021. }
  3022. //时控一关时间
  3023. else if(data[i].id == "R1_DayCloseTime1"){
  3024. var timeshut1 = data[i].current_value
  3025. }
  3026. //时控二开时间
  3027. else if(data[i].id == "R1_DayOpenTime2"){
  3028. var timeopen2 = data[i].current_value
  3029. }
  3030. //时控二关时间
  3031. else if(data[i].id == "R1_DayCloseTime2"){
  3032. var timeshut2 = data[i].current_value
  3033. }
  3034. //日期调控
  3035. else if(data[i].id == "R1_Week"){
  3036. var weeks = data[i].current_value
  3037. that.setData({recorddate:weeks})
  3038. weeks = parseInt(weeks)
  3039. weeks = weeks.toString(2)
  3040. weeks = weeks + ''
  3041. if(weeks != '0'){
  3042. weeks = weeks.slice(1)
  3043. }
  3044. }
  3045. //功能1
  3046. else if(data[i].id == "R1_FunctionStatus1"){
  3047. var Function1 = data[i].current_value
  3048. var par = parseInt(Function1)
  3049. par = par.toString(2)
  3050. par = par + ''
  3051. switch (par.length) {
  3052. case 1:
  3053. par = '00000' + par
  3054. break;
  3055. case 2:
  3056. par = '0000' + par
  3057. break;
  3058. case 3:
  3059. par = '000' + par
  3060. break;
  3061. case 4:
  3062. par = '00' + par
  3063. break;
  3064. case 5:
  3065. par = '0' + par
  3066. break;
  3067. default:
  3068. par = par
  3069. }
  3070. }
  3071. //功能二
  3072. else if(data[i].id == "R1_FunctionStatus2"){
  3073. var Function2 = data[i].current_value
  3074. var qur = parseInt(Function2)
  3075. qur = qur.toString(2)
  3076. qur = qur + ''
  3077. switch (qur.length) {
  3078. case 1:
  3079. qur = '000' + qur
  3080. break;
  3081. case 2:
  3082. qur = '00' + qur
  3083. break;
  3084. case 3:
  3085. qur = '0' + qur
  3086. break;
  3087. case 4:
  3088. qur = qur
  3089. break;
  3090. }
  3091. }
  3092. //报警
  3093. else if(data[i].id == "R1_RelayStatus"){
  3094. var police = data[i].current_value
  3095. }
  3096. //光控开
  3097. else if(data[i].id == "R1_LcOn"){
  3098. var Lightcontrolopen = data[i].current_value
  3099. var trr = that.data.arr
  3100. for(let i = 0;i < 100;i++){
  3101. trr[i] = i
  3102. }
  3103. Lightcontrolopen = parseInt(Lightcontrolopen)
  3104. that.setData({arr:trr,index:Lightcontrolopen})
  3105. }
  3106. //光控关
  3107. else if(data[i].id == "R1_LcOff"){
  3108. var Lightcontrolshut = data[i].current_value
  3109. var prr = that.data.brr
  3110. for(let j =0;j < 100;j++){
  3111. prr[j] = j
  3112. }
  3113. Lightcontrolshut = parseInt(Lightcontrolshut)
  3114. that.setData({brr:prr,indexs:Lightcontrolshut})
  3115. }
  3116. }
  3117. //时控一开时间
  3118. var timeOpen1
  3119. switch (timeopen1.length) {
  3120. case 1:
  3121. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0,1)
  3122. break;
  3123. case 2:
  3124. timeOpen1 = '00' + ':' + timeopen1.substring(0,2)
  3125. break;
  3126. case 3:
  3127. var timeOpen1 = '0' + timeopen1.substring(0,1) + ':' + timeopen1.substring(1,3)
  3128. break;
  3129. case 4:
  3130. var timeOpen1 = timeopen1.substring(0,2) + ':' + timeopen1.substring(2,4)
  3131. break;
  3132. }
  3133. //时控一关时间
  3134. var timeShut1
  3135. switch (timeshut1.length) {
  3136. case 1:
  3137. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0,1)
  3138. break;
  3139. case 2:
  3140. timeShut1 = '00' + ':' + timeshut1.substring(0,2)
  3141. break;
  3142. case 3:
  3143. var timeShut1 = '0' + timeshut1.substring(0,1) + ':' + timeshut1.substring(1,3)
  3144. break;
  3145. case 4:
  3146. var timeShut1 = timeshut1.substring(0,2) + ':' + timeshut1.substring(2,4)
  3147. break;
  3148. }
  3149. //时控二开时间
  3150. var timeOpen2
  3151. switch (timeopen2.length) {
  3152. case 1:
  3153. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0,1)
  3154. break;
  3155. case 2:
  3156. timeOpen2 = '00' + ':' + timeopen2.substring(0,2)
  3157. break;
  3158. case 3:
  3159. var timeOpen2 = '0' + timeopen2.substring(0,1) + ':' + timeopen2.substring(1,3)
  3160. break;
  3161. case 4:
  3162. var timeOpen2 = timeopen2.substring(0,2) + ':' + timeopen2.substring(2,4)
  3163. break;
  3164. }
  3165. //时控二关时间
  3166. var timeShut2
  3167. switch (timeshut2.length) {
  3168. case 1:
  3169. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0,1)
  3170. break;
  3171. case 2:
  3172. timeShut2 = '00' + ':' + timeshut2.substring(0,2)
  3173. break;
  3174. case 3:
  3175. var timeShut2 = '0' + timeshut2.substring(0,1) + ':' + timeshut2.substring(1,3)
  3176. break;
  3177. case 4:
  3178. var timeShut2 = timeshut2.substring(0,2) + ':' + timeshut2.substring(2,4)
  3179. break;
  3180. }
  3181. //功能1
  3182. for(var i = 0;i < par.length;i++){
  3183. var engry = that.data.state
  3184. switch(par.substring(i,i+1)){
  3185. case "0":
  3186. switch (i) {
  3187. case 0:
  3188. engry[3] = false
  3189. that.setData({state:engry})
  3190. break;
  3191. case 1:
  3192. engry[2] = false
  3193. that.setData({state:engry})
  3194. break;
  3195. case 2:
  3196. that.setData({fixed2:"固定"})
  3197. break;
  3198. case 3:
  3199. that.setData({fixed1:"固定"})
  3200. break;
  3201. case 4:
  3202. engry[1] = false
  3203. that.setData({state:engry})
  3204. break;
  3205. case 5:
  3206. engry[0] = false
  3207. that.setData({state:engry})
  3208. break;
  3209. }
  3210. break;
  3211. case "1":
  3212. switch (i) {
  3213. case 0:
  3214. engry[3] = true
  3215. that.setData({state:engry})
  3216. break;
  3217. case 1:
  3218. engry[2] = true
  3219. that.setData({state:engry})
  3220. break;
  3221. case 2:
  3222. that.setData({fixed2:"经纬"})
  3223. break;
  3224. case 3:
  3225. that.setData({fixed1:"经纬"})
  3226. break;
  3227. case 4:
  3228. engry[1] = true
  3229. that.setData({state:engry})
  3230. break;
  3231. case 5:
  3232. engry[0] = true
  3233. that.setData({state:engry})
  3234. break;
  3235. }
  3236. break;
  3237. }
  3238. }
  3239. //功能2
  3240. for(let j = 0;j < qur.length;j++){
  3241. var Engry = that.data.state1
  3242. switch(qur.substring(j,j+1)){
  3243. case "0":
  3244. switch (j) {
  3245. case 0:
  3246. that.setData({fixed4:"固定"})
  3247. break;
  3248. case 1:
  3249. that.setData({fixed3:"固定"})
  3250. break;
  3251. case 2:
  3252. Engry[1] = false
  3253. that.setData({state1:Engry})
  3254. break;
  3255. case 3:
  3256. Engry[0] = false
  3257. that.setData({state1:Engry})
  3258. break;
  3259. }
  3260. break;
  3261. case "1":
  3262. switch (j) {
  3263. case 0:
  3264. that.setData({fixed4:"经纬"})
  3265. break;
  3266. case 1:
  3267. that.setData({fixed3:"经纬"})
  3268. break;
  3269. case 2:
  3270. Engry[1] = true
  3271. that.setData({state1:Engry})
  3272. break;
  3273. case 3:
  3274. Engry[0] = true
  3275. that.setData({state1:Engry})
  3276. break;
  3277. }
  3278. break;
  3279. }
  3280. }
  3281. //日期调控
  3282. var controladdress = that.data.address
  3283. if (weeks == '0') {
  3284. for(let x = 0;x < weeks.length; x++){
  3285. controladdress[x] = "/image/false.png"
  3286. }
  3287. that.setData({
  3288. address:controladdress,
  3289. })
  3290. }
  3291. else{
  3292. for(let i = 0;i < weeks.length;i++){
  3293. switch (weeks.substring(i,i+1)) {
  3294. case '0':
  3295. controladdress[weeks.length-i-1] = "/image/false.png"
  3296. that.setData({
  3297. address:controladdress,
  3298. })
  3299. break;
  3300. case '1':
  3301. controladdress[weeks.length-i-1] = "/image/true.png"
  3302. that.setData({
  3303. address:controladdress,
  3304. })
  3305. break;
  3306. }
  3307. }
  3308. }
  3309. //报警状态
  3310. police = parseInt(police)
  3311. police = police.toString(2)
  3312. switch(police.length){
  3313. case 1:
  3314. police = '000' + police
  3315. break;
  3316. case 2:
  3317. police = '00' + police
  3318. break;
  3319. case 3:
  3320. police = '0' + police
  3321. break;
  3322. default:
  3323. police = police
  3324. break;
  3325. }
  3326. if(police.substring(1,2) == '0' && police.substring(0,1) == '0'){
  3327. that.setData({
  3328. radio1:true
  3329. })
  3330. }
  3331. else if(police.substring(1,2) == '1' && police.substring(0,1) == '0'){
  3332. that.setData({
  3333. radio2:true
  3334. })
  3335. }
  3336. else if(police.substring(1,2) == '0' && police.substring(0,1) == '1'){
  3337. that.setData({
  3338. radio3:true
  3339. })
  3340. }
  3341. var time = that.data.time
  3342. time[0] = timeOpen1
  3343. time[1] = timeShut1
  3344. time[2] = timeOpen2
  3345. time[3] = timeShut2
  3346. that.setData({
  3347. time:time,
  3348. })
  3349. //监视开关状态(改变颜色,调整功能)
  3350. switch (that.data.state[0]) {
  3351. case true:
  3352. that.setData({
  3353. type1:"time",
  3354. timecontrolcolor1:"blue",
  3355. fontcolor1:"white",
  3356. })
  3357. break;
  3358. default:
  3359. that.setData({
  3360. type1:"",
  3361. timecontrolcolor1:"#888888",
  3362. fontcolor1:"#cccccc",
  3363. })
  3364. break;
  3365. }
  3366. switch (that.data.state[1]) {
  3367. case true:
  3368. that.setData({
  3369. type2:"time",
  3370. timecontrolcolor2:"blue",
  3371. fontcolor2:"white",
  3372. })
  3373. break;
  3374. default:
  3375. that.setData({
  3376. type2:"",
  3377. timecontrolcolor2:"#888888",
  3378. fontcolor2:"#cccccc",
  3379. })
  3380. break;
  3381. }
  3382. switch (that.data.state1[0]) {
  3383. case true:
  3384. that.setData({
  3385. type3:"time",
  3386. timecontrolcolor3:"blue",
  3387. fontcolor3:"white",
  3388. })
  3389. break;
  3390. default:
  3391. that.setData({
  3392. type3:"",
  3393. timecontrolcolor3:"#888888",
  3394. fontcolor3:"#cccccc",
  3395. })
  3396. break;
  3397. }
  3398. switch (that.data.state1[1]) {
  3399. case true:
  3400. that.setData({
  3401. type4:"time",
  3402. timecontrolcolor4:"blue",
  3403. fontcolor4:"white",
  3404. })
  3405. break;
  3406. default:
  3407. that.setData({
  3408. type4:"",
  3409. timecontrolcolor4:"#888888",
  3410. fontcolor4:"#cccccc",
  3411. })
  3412. break;
  3413. }
  3414. switch (that.data.state[2]) {
  3415. case true:
  3416. that.setData({
  3417. Lightcontrolcolor1:"blue",
  3418. fontcolor5:"white",
  3419. select1:"selector"
  3420. })
  3421. break;
  3422. default:
  3423. that.setData({
  3424. Lightcontrolcolor1:"#888888",
  3425. fontcolor5:"#cccccc",
  3426. select1:""
  3427. })
  3428. break;
  3429. }
  3430. switch (that.data.state[3]) {
  3431. case true:
  3432. that.setData({
  3433. Lightcontrolcolor2:"blue",
  3434. fontcolor6:"white",
  3435. select2:"selector"
  3436. })
  3437. break;
  3438. default:
  3439. that.setData({
  3440. Lightcontrolcolor2:"#888888",
  3441. fontcolor6:"#cccccc",
  3442. select2:""
  3443. })
  3444. break;
  3445. }
  3446. }
  3447. })
  3448. }
  3449. else{
  3450. that.setData({
  3451. status:"离线"
  3452. })
  3453. }
  3454. }
  3455. })
  3456. }
  3457. else{
  3458. that.setData({status:'离线'})
  3459. }
  3460. }
  3461. }
  3462. },
  3463. /**
  3464. * 生命周期函数--监听页面隐藏
  3465. */
  3466. onHide() {
  3467. },
  3468. /**
  3469. * 生命周期函数--监听页面卸载
  3470. */
  3471. onUnload() {
  3472. },
  3473. /**
  3474. * 页面相关事件处理函数--监听用户下拉动作
  3475. */
  3476. onPullDownRefresh() {
  3477. },
  3478. /**
  3479. * 页面上拉触底事件的处理函数
  3480. */
  3481. onReachBottom() {
  3482. },
  3483. /**
  3484. * 用户点击右上角分享
  3485. */
  3486. onShareAppMessage() {
  3487. }
  3488. })