loop.js 112 KB

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