control.js 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774
  1. // pages/control/control.js
  2. const {
  3. postDevice,
  4. getDevice,
  5. putDevice,
  6. delDevice,
  7. getloop,
  8. loopSwitchstate
  9. } = require('../../api/device')
  10. const {
  11. getBasic,
  12. getData,
  13. postData
  14. } = require('../../api/intell')
  15. const control = require('../../utils/control')
  16. Page({
  17. /**
  18. * 页面的初始数据
  19. */
  20. data: {
  21. statu: false,
  22. status: "离线",
  23. Title: "",
  24. quantity: "", //回路数量
  25. Color: ['#d5dbdf', '#d5dbdf', '#d5dbdf', '#d5dbdf', '#d5dbdf', '#d5dbdf', '#d5dbdf', '#d5dbdf', '#d5dbdf', '#d5dbdf',
  26. '#d5dbdf', '#d5dbdf'
  27. ], //字体颜色
  28. Size: ["calc(100vw * 16/375)", "calc(100vw * 16/375)", "calc(100vw * 16/375)", "calc(100vw * 16/375)",
  29. "calc(100vw * 16/375)", "calc(100vw * 16/375)", "calc(100vw * 16/375)", "calc(100vw * 16/375)",
  30. "calc(100vw * 16/375)", "calc(100vw * 16/375)", "calc(100vw * 16/375)", "calc(100vw * 16/375)"
  31. ], //字体大小
  32. lamp: ['https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  33. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  34. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  35. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  36. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  37. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  38. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  39. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  40. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  41. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  42. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png',
  43. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
  44. ], //灯泡图标
  45. address: ["", "", "", "", "", "", "", "", "", "", "", ""], //修改回路名称图标
  46. loop: ['回路1', '回路2', '回路3', '回路4', '回路5', '回路6', '回路7', '回路8', '回路9', '回路10', '回路11', '回路12'], //回路名称
  47. loops: 0, //用于记录回路数量
  48. Loop: [], //用于向回路界面传递回路名称
  49. Modecontrol: "",
  50. groupName: [],
  51. deviceName: [],
  52. groupIndex: 0,
  53. deviceIndex: 0,
  54. deviceId: '',
  55. deviceKey: '',
  56. moudule: 0,
  57. id: 0,
  58. play: 0,
  59. ID:0,//新设备的ID
  60. Groupno:0
  61. },
  62. //回路开
  63. Open(e) {
  64. var that = this
  65. var play = that.data.play
  66. var id = that.data.id
  67. var opens = e.target.dataset.open
  68. var loops = that.data.loops
  69. if (typeof (loops) == String) {
  70. loops = parseInt(loops)
  71. }
  72. if(play == 0){
  73. getBasic(that.data.deviceId,that.data.deviceKey).then(res => {
  74. if(res.data.errno == 0){
  75. if(res.data.data.online == true){
  76. that.setData({status:'在线'})
  77. }
  78. else{
  79. that.setData({status:'离线'})
  80. }
  81. }
  82. else{
  83. wx.showModal({
  84. title: '错误',
  85. content: res.data.error,
  86. showCancel:false
  87. })
  88. }
  89. })
  90. }
  91. else{
  92. getDevice(id,that.data.Groupno).then(dve => {
  93. if (dve.data.code == 0) {
  94. var state = dve.data.data
  95. switch (state.status) {
  96. case 0:
  97. that.setData({
  98. status: '离线'
  99. })
  100. break;
  101. case 1:
  102. that.setData({
  103. status: '在线'
  104. })
  105. break;
  106. }
  107. } else {
  108. wx.showModal({
  109. title: '错误',
  110. content: dve.data.msg,
  111. showCancel: false
  112. })
  113. }
  114. })
  115. }
  116. if (that.data.status == '在线') {
  117. if (opens == 1) {
  118. if (play == 0) {
  119. control.Switch(that.data.deviceId, that.data.deviceKey, {
  120. 'R1_RelayStatus': 13,
  121. 'Reflash': 3
  122. })
  123. } else {
  124. control.newSwitch({
  125. deviceId: id,
  126. relayId: 1,
  127. operation: 1
  128. })
  129. }
  130. } else if (opens == 2 && loops >= 2) {
  131. if (play == 0) {
  132. control.Switch(that.data.deviceId, that.data.deviceKey, {
  133. 'R2_RelayStatus': 13,
  134. 'Reflash': 3
  135. })
  136. } else {
  137. control.newSwitch({
  138. deviceId: id,
  139. relayId: 2,
  140. operation: 1
  141. })
  142. }
  143. } else if (opens == 3 && loops >= 3) {
  144. if (play == 0) {
  145. control.Switch(that.data.deviceId, that.data.deviceKey, {
  146. 'R3_RelayStatus': 13,
  147. 'Reflash': 3
  148. })
  149. } else {
  150. control.newSwitch({
  151. deviceId: id,
  152. relayId: 3,
  153. operation: 1
  154. })
  155. }
  156. } else if (opens == 4 && loops >= 4) {
  157. if (play == 0) {
  158. control.Switch(that.data.deviceId, that.data.deviceKey, {
  159. 'R4_RelayStatus': 13,
  160. 'Reflash': 3
  161. })
  162. } else {
  163. control.newSwitch({
  164. deviceId: id,
  165. relayId: 4,
  166. operation: 1
  167. })
  168. }
  169. } else if (opens == 5 && loops >= 5) {
  170. if (play == 0) {
  171. control.Switch(that.data.deviceId, that.data.deviceKey, {
  172. 'R5_RelayStatus': 13,
  173. 'Reflash': 3
  174. })
  175. } else {
  176. control.newSwitch({
  177. deviceId: id,
  178. relayId: 5,
  179. operation: 1
  180. })
  181. }
  182. } else if (opens == 6 && loops >= 6) {
  183. if (play == 0) {
  184. control.Switch(that.data.deviceId, that.data.deviceKey, {
  185. 'R6_RelayStatus': 13,
  186. 'Reflash': 3
  187. })
  188. } else {
  189. control.newSwitch({
  190. deviceId: id,
  191. relayId: 6,
  192. operation: 1
  193. })
  194. }
  195. } else if (opens == 7 && loops >= 7) {
  196. if (play == 0) {
  197. control.Switch(that.data.deviceId, that.data.deviceKey, {
  198. 'R7_RelayStatus': 13,
  199. 'Reflash': 3
  200. })
  201. } else {
  202. control.newSwitch({
  203. deviceId: id,
  204. relayId: 7,
  205. operation: 1
  206. })
  207. }
  208. } else if (opens == 8 && loops >= 8) {
  209. if (play == 0) {
  210. control.Switch(that.data.deviceId, that.data.deviceKey, {
  211. 'R8_RelayStatus': 13,
  212. 'Reflash': 3
  213. })
  214. } else {
  215. control.newSwitch({
  216. deviceId: id,
  217. relayId: 8,
  218. operation: 1
  219. })
  220. }
  221. } else if (opens == 9 && loops >= 9) {
  222. if (play == 0) {
  223. control.Switch(that.data.deviceId, that.data.deviceKey, {
  224. 'R9_RelayStatus': 13,
  225. 'Reflash': 3
  226. })
  227. } else {
  228. control.newSwitch({
  229. deviceId: id,
  230. relayId: 9,
  231. operation: 1
  232. })
  233. }
  234. } else if (opens == 10 && loops >= 10) {
  235. if (play == 0) {
  236. control.Switch(that.data.deviceId, that.data.deviceKey, {
  237. 'R10_RelayStatus': 13,
  238. 'Reflash': 3
  239. })
  240. } else {
  241. control.newSwitch({
  242. deviceId: id,
  243. relayId: 10,
  244. operation: 1
  245. })
  246. }
  247. } else if (opens == 11 && loops >= 11) {
  248. if (play == 0) {
  249. control.Switch(that.data.deviceId, that.data.deviceKey, {
  250. 'R11_RelayStatus': 13,
  251. 'Reflash': 3
  252. })
  253. } else {
  254. control.newSwitch({
  255. deviceId: id,
  256. relayId: 11,
  257. operation: 1
  258. })
  259. }
  260. } else if (opens == 12 && loops >= 12) {
  261. if (play == 0) {
  262. control.Switch(that.data.deviceId, that.data.deviceKey, {
  263. 'R12_RelayStatus': 13,
  264. 'Reflash': 3
  265. })
  266. } else {
  267. control.newSwitch({
  268. deviceId: id,
  269. relayId: 12,
  270. operation: 1
  271. })
  272. }
  273. }
  274. setTimeout(function () {
  275. //旧设备
  276. if (play == 0) {
  277. var lamp = wx.getStorageSync('lamp')
  278. getData(that.data.deviceId, that.data.deviceKey).then(bind => {
  279. if (bind.data.errno == 0) {
  280. let Bind = bind.data.data
  281. for (let r1 = 0; r1 < Bind.length; r1++) {
  282. if (Bind[r1].id == 'R1_RelayStatus') {
  283. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 0)
  284. } else if (Bind[r1].id == 'R2_RelayStatus') {
  285. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 1)
  286. } else if (Bind[r1].id == 'R3_RelayStatus') {
  287. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 2)
  288. } else if (Bind[r1].id == 'R4_RelayStatus') {
  289. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 3)
  290. } else if (Bind[r1].id == 'R5_RelayStatus') {
  291. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 4)
  292. } else if (Bind[r1].id == 'R6_RelayStatus') {
  293. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 5)
  294. } else if (Bind[r1].id == 'R7_RelayStatus') {
  295. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 6)
  296. } else if (Bind[r1].id == 'R8_RelayStatus') {
  297. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 7)
  298. } else if (Bind[r1].id == 'R9_RelayStatus') {
  299. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 8)
  300. } else if (Bind[r1].id == 'R10_RelayStatus') {
  301. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 9)
  302. } else if (Bind[r1].id == 'R11_RelayStatus') {
  303. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 10)
  304. } else if (Bind[r1].id == 'R12_RelayStatus') {
  305. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 11)
  306. }
  307. }
  308. wx.setStorageSync('lamp', switchReal)
  309. that.setData({
  310. lamp: wx.getStorageSync('lamp')
  311. })
  312. }
  313. else{
  314. wx.showModal({
  315. title: '错误',
  316. content: bind.data.error,
  317. showCancel:false
  318. })
  319. }
  320. })
  321. }
  322. //新设备
  323. else {
  324. var Switchstate = wx.getStorageSync('lamp')
  325. loopSwitchstate(id).then(res => {
  326. if (res.data.code == 0) {
  327. var relay = res.data.data
  328. if (relay[opens - 1].status == 1) {
  329. Switchstate[opens - 1] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp1.png'
  330. } else {
  331. Switchstate[opens - 1] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
  332. }
  333. } else {
  334. wx.showModal({
  335. title: '错误',
  336. content: res.data.msg,
  337. showCancel: false
  338. })
  339. }
  340. })
  341. setTimeout(function () {
  342. wx.setStorageSync('lamp', Switchstate)
  343. that.setData({
  344. lamp: wx.getStorageSync('lamp')
  345. })
  346. }, 500)
  347. }
  348. }, 3000)
  349. } else {
  350. wx.showModal({
  351. title: '提示',
  352. content: '设备处于离线状态',
  353. showCancel: false
  354. })
  355. }
  356. },
  357. //回路关
  358. Shut(e) {
  359. var that = this
  360. var play = that.data.play
  361. var id = that.data.id
  362. var lamp = wx.getStorageSync('lamp')
  363. var shuts = e.target.dataset.shut
  364. var loops = that.data.loops
  365. if (typeof (loops) == String) {
  366. loops = parseInt(loops)
  367. }
  368. if(play == 0){
  369. getBasic(that.data.deviceId,that.data.deviceKey).then(res => {
  370. if(res.data.errno == 0){
  371. if(res.data.data.online == true){
  372. that.setData({status:'在线'})
  373. }
  374. else{
  375. that.setData({status:'离线'})
  376. }
  377. }
  378. else{
  379. wx.showModal({
  380. title: '错误',
  381. content: res.data.error,
  382. showCancel:false
  383. })
  384. }
  385. })
  386. }
  387. else{
  388. getDevice(id,that.data.Groupno).then(dve => {
  389. if (dve.data.code == 0) {
  390. var state = dve.data.data
  391. switch (state.status) {
  392. case 0:
  393. that.setData({
  394. status: '离线'
  395. })
  396. break;
  397. case 1:
  398. that.setData({
  399. status: '在线'
  400. })
  401. break;
  402. }
  403. } else {
  404. wx.showModal({
  405. title: '错误',
  406. content: dve.data.msg,
  407. showCancel: false
  408. })
  409. }
  410. })
  411. }
  412. if (that.data.status == '在线') {
  413. if (shuts == 1) {
  414. if (play == 0) {
  415. control.Switch(that.data.deviceId, that.data.deviceKey, {
  416. 'R1_RelayStatus': 12,
  417. 'Reflash': 3
  418. })
  419. } else {
  420. control.newSwitch({
  421. deviceId: id,
  422. relayId: 1,
  423. operation: 0
  424. })
  425. }
  426. } else if (shuts == 2 && loops >= 2) {
  427. if (play == 0) {
  428. control.Switch(that.data.deviceId, that.data.deviceKey, {
  429. 'R2_RelayStatus': 12,
  430. 'Reflash': 3
  431. })
  432. } else {
  433. control.newSwitch({
  434. deviceId: id,
  435. relayId: 2,
  436. operation: 0
  437. })
  438. }
  439. } else if (shuts == 3 && loops >= 3) {
  440. if (play == 0) {
  441. control.Switch(that.data.deviceId, that.data.deviceKey, {
  442. 'R3_RelayStatus': 12,
  443. 'Reflash': 3
  444. })
  445. } else {
  446. control.newSwitch({
  447. deviceId: id,
  448. relayId: 3,
  449. operation: 0
  450. })
  451. }
  452. } else if (shuts == 4 && loops >= 4) {
  453. if (play == 0) {
  454. control.Switch(that.data.deviceId, that.data.deviceKey, {
  455. 'R4_RelayStatus': 12,
  456. 'Reflash': 3
  457. })
  458. } else {
  459. control.newSwitch({
  460. deviceId: id,
  461. relayId: 4,
  462. operation: 0
  463. })
  464. }
  465. } else if (shuts == 5 && loops >= 5) {
  466. if (play == 0) {
  467. control.Switch(that.data.deviceId, that.data.deviceKey, {
  468. 'R5_RelayStatus': 12,
  469. 'Reflash': 3
  470. })
  471. } else {
  472. control.newSwitch({
  473. deviceId: id,
  474. relayId: 5,
  475. operation: 0
  476. })
  477. }
  478. } else if (shuts == 6 && loops >= 6) {
  479. if (play == 0) {
  480. control.Switch(that.data.deviceId, that.data.deviceKey, {
  481. 'R6_RelayStatus': 12,
  482. 'Reflash': 3
  483. })
  484. } else {
  485. control.newSwitch({
  486. deviceId: id,
  487. relayId: 6,
  488. operation: 0
  489. })
  490. }
  491. } else if (shuts == 7 && loops >= 7) {
  492. if (play == 0) {
  493. control.Switch(that.data.deviceId, that.data.deviceKey, {
  494. 'R7_RelayStatus': 12,
  495. 'Reflash': 3
  496. })
  497. } else {
  498. control.newSwitch({
  499. deviceId: id,
  500. relayId: 7,
  501. operation: 0
  502. })
  503. }
  504. } else if (shuts == 8 && loops >= 8) {
  505. if (play == 0) {
  506. control.Switch(that.data.deviceId, that.data.deviceKey, {
  507. 'R8_RelayStatus': 12,
  508. 'Reflash': 3
  509. })
  510. } else {
  511. control.newSwitch({
  512. deviceId: id,
  513. relayId: 8,
  514. operation: 0
  515. })
  516. }
  517. } else if (shuts == 9 && loops >= 9) {
  518. if (play == 0) {
  519. control.Switch(that.data.deviceId, that.data.deviceKey, {
  520. 'R9_RelayStatus': 12,
  521. 'Reflash': 3
  522. })
  523. } else {
  524. control.newSwitch({
  525. deviceId: id,
  526. relayId: 9,
  527. operation: 0
  528. })
  529. }
  530. } else if (shuts == 10 && loops >= 10) {
  531. if (play == 0) {
  532. control.Switch(that.data.deviceId, that.data.deviceKey, {
  533. 'R10_RelayStatus': 12,
  534. 'Reflash': 3
  535. })
  536. } else {
  537. control.newSwitch({
  538. deviceId: id,
  539. relayId: 10,
  540. operation: 0
  541. })
  542. }
  543. } else if (shuts == 11 && loops >= 11) {
  544. if (play == 0) {
  545. control.Switch(that.data.deviceId, that.data.deviceKey, {
  546. 'R11_RelayStatus': 12,
  547. 'Reflash': 3
  548. })
  549. } else {
  550. control.newSwitch({
  551. deviceId: id,
  552. relayId: 11,
  553. operation: 0
  554. })
  555. }
  556. } else if (shuts == 12 && loops >= 12) {
  557. if (play == 0) {
  558. control.Switch(that.data.deviceId, that.data.deviceKey, {
  559. 'R12_RelayStatus': 12,
  560. 'Reflash': 3
  561. })
  562. } else {
  563. control.newSwitch({
  564. deviceId: id,
  565. relayId: 12,
  566. operation: 0
  567. })
  568. }
  569. }
  570. setTimeout(function () {
  571. if (play == 0) {
  572. getData(that.data.deviceId, that.data.deviceKey).then(bind => {
  573. if (bind.data.errno == 0) {
  574. let Bind = bind.data.data
  575. for (let r1 = 0; r1 < Bind.length; r1++) {
  576. if (Bind[r1].id == 'R1_RelayStatus') {
  577. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 0)
  578. } else if (Bind[r1].id == 'R2_RelayStatus') {
  579. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 1)
  580. } else if (Bind[r1].id == 'R3_RelayStatus') {
  581. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 2)
  582. } else if (Bind[r1].id == 'R4_RelayStatus') {
  583. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 3)
  584. } else if (Bind[r1].id == 'R5_RelayStatus') {
  585. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 4)
  586. } else if (Bind[r1].id == 'R6_RelayStatus') {
  587. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 5)
  588. } else if (Bind[r1].id == 'R7_RelayStatus') {
  589. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 6)
  590. } else if (Bind[r1].id == 'R8_RelayStatus') {
  591. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 7)
  592. } else if (Bind[r1].id == 'R9_RelayStatus') {
  593. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 8)
  594. } else if (Bind[r1].id == 'R10_RelayStatus') {
  595. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 9)
  596. } else if (Bind[r1].id == 'R11_RelayStatus') {
  597. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 10)
  598. } else if (Bind[r1].id == 'R12_RelayStatus') {
  599. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 11)
  600. }
  601. }
  602. wx.setStorageSync('lamp', switchReal)
  603. that.setData({
  604. lamp: wx.getStorageSync('lamp')
  605. })
  606. }
  607. else{
  608. wx.showModal({
  609. title: '错误',
  610. content: bind.data.error,
  611. showCancel:false
  612. })
  613. }
  614. })
  615. } else {
  616. var Switchstate = wx.getStorageSync('lamp')
  617. loopSwitchstate(id).then(res => {
  618. if (res.data.code == 0) {
  619. var relay = res.data.data
  620. if (relay[shuts - 1].status == 1) {
  621. Switchstate[shuts - 1] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp1.png'
  622. } else {
  623. Switchstate[shuts - 1] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
  624. }
  625. } else {
  626. wx.showModal({
  627. title: '错误',
  628. content: res.data.msg,
  629. showCancel: false
  630. })
  631. }
  632. })
  633. setTimeout(function () {
  634. wx.setStorageSync('lamp', Switchstate)
  635. that.setData({
  636. lamp: wx.getStorageSync('lamp')
  637. })
  638. }, 500)
  639. }
  640. }, 3000)
  641. } else {
  642. wx.showModal({
  643. title: '提示',
  644. content: '设备处于离线状态',
  645. showCancel: false
  646. })
  647. }
  648. },
  649. //回路名称调整
  650. loopname(e) {
  651. var that = this
  652. var address = that.data.address //回路名称图标
  653. var loop = that.data.loop //回路名称
  654. var slice //截取数组
  655. var loops = that.data.loops //回路数量
  656. var group = wx.getStorageSync('group')
  657. var groupName = that.data.groupName[that.data.groupIndex] //分组名称
  658. var deviceName = that.data.deviceName[that.data.deviceIndex] //设备名称
  659. for (let i = 0; i < group.length; i++) {
  660. if (groupName == group[i].groupName) {
  661. for (let j = 0; j < group[i].devices.length; j++) {
  662. if (deviceName == group[i].devices[j].deviceName) {
  663. var deviceid = group[i].devices[j].id
  664. var groupid = group[i].devices[j].groupId
  665. }
  666. }
  667. }
  668. }
  669. //回路1
  670. if (e.target.dataset.loopname == 1) {
  671. wx.showModal({
  672. title: '修改回路名称',
  673. editable: true,
  674. placeholderText: '请输入名称',
  675. success: res => {
  676. if (res.confirm) {
  677. if (res.content == '') {
  678. wx.showModal({
  679. title: '提示',
  680. content: '请输入名称',
  681. showCancel: false
  682. })
  683. } else if (res.content.length > 10) {
  684. wx.showModal({
  685. title: '提示',
  686. content: '回路名称不能大于10个字符',
  687. showCancel: false
  688. })
  689. } else {
  690. loop[0] = res.content
  691. slice = loop.slice(0, loops)
  692. slice = slice.toString()
  693. putDevice({
  694. id: deviceid,
  695. groupId: groupid,
  696. circuits: slice
  697. }).then(res => {
  698. if (res.data.code == 0) {
  699. for (let i = 0; i < group.length; i++) {
  700. if (groupName == group[i].groupName) {
  701. for (let j = 0; j < group[i].devices.length; j++) {
  702. if (deviceName == group[i].devices[j].deviceName) {
  703. group[i].devices[j].circuits = slice
  704. wx.setStorageSync('group', group)
  705. that.setData({
  706. loop: loop
  707. })
  708. }
  709. }
  710. }
  711. }
  712. } else {
  713. wx.showModal({
  714. title: '错误',
  715. content: res.data.msg,
  716. showCancel: false
  717. })
  718. }
  719. })
  720. }
  721. }
  722. }
  723. })
  724. }
  725. //回路2
  726. else if (e.target.dataset.loopname == 2 && address[1] != "") {
  727. wx.showModal({
  728. title: '修改回路名称',
  729. editable: true,
  730. placeholderText: '请输入名称',
  731. success: res => {
  732. if (res.confirm) {
  733. if (res.content == '') {
  734. wx.showModal({
  735. title: '提示',
  736. content: '请输入名称',
  737. showCancel: false
  738. })
  739. } else if (res.content.length > 10) {
  740. wx.showModal({
  741. title: '提示',
  742. content: '回路名称不能大于10个字符',
  743. showCancel: false
  744. })
  745. } else {
  746. loop[1] = res.content
  747. slice = loop.slice(0, loops)
  748. slice = slice.toString()
  749. putDevice({
  750. id: deviceid,
  751. groupId: groupid,
  752. circuits: slice
  753. }).then(res => {
  754. if (res.data.code == 0) {
  755. for (let i = 0; i < group.length; i++) {
  756. if (groupName == group[i].groupName) {
  757. for (let j = 0; j < group[i].devices.length; j++) {
  758. if (deviceName == group[i].devices[j].deviceName) {
  759. group[i].devices[j].circuits = slice
  760. wx.setStorageSync('group', group)
  761. that.setData({
  762. loop: loop
  763. })
  764. }
  765. }
  766. }
  767. }
  768. } else {
  769. wx.showModal({
  770. title: '错误',
  771. content: res.data.msg,
  772. showCancel: false
  773. })
  774. }
  775. })
  776. }
  777. }
  778. }
  779. })
  780. }
  781. //回路3
  782. else if (e.target.dataset.loopname == 3 && address[2] != "") {
  783. wx.showModal({
  784. title: '修改回路名称',
  785. editable: true,
  786. placeholderText: '请输入名称',
  787. success: res => {
  788. if (res.confirm) {
  789. if (res.content == '') {
  790. wx.showModal({
  791. title: '提示',
  792. content: '请输入名称',
  793. showCancel: false
  794. })
  795. } else if (res.content.length > 10) {
  796. wx.showModal({
  797. title: '提示',
  798. content: '回路名称不能大于10个字符',
  799. showCancel: false
  800. })
  801. } else {
  802. loop[2] = res.content
  803. slice = loop.slice(0, loops)
  804. slice = slice.toString()
  805. putDevice({
  806. id: deviceid,
  807. groupId: groupid,
  808. circuits: slice
  809. }).then(res => {
  810. if (res.data.code == 0) {
  811. for (let i = 0; i < group.length; i++) {
  812. if (groupName == group[i].groupName) {
  813. for (let j = 0; j < group[i].devices.length; j++) {
  814. if (deviceName == group[i].devices[j].deviceName) {
  815. group[i].devices[j].circuits = slice
  816. wx.setStorageSync('group', group)
  817. that.setData({
  818. loop: loop
  819. })
  820. }
  821. }
  822. }
  823. }
  824. } else {
  825. wx.showModal({
  826. title: '错误',
  827. content: res.data.msg,
  828. showCancel: false
  829. })
  830. }
  831. })
  832. }
  833. }
  834. }
  835. })
  836. }
  837. //回路4
  838. else if (e.target.dataset.loopname == 4 && address[3] != "") {
  839. wx.showModal({
  840. title: '修改回路名称',
  841. editable: true,
  842. placeholderText: '请输入名称',
  843. success: res => {
  844. if (res.confirm) {
  845. if (res.content == '') {
  846. wx.showModal({
  847. title: '提示',
  848. content: '请输入名称',
  849. showCancel: false
  850. })
  851. } else if (res.content.length > 10) {
  852. wx.showModal({
  853. title: '提示',
  854. content: '回路名称不能大于10个字符',
  855. showCancel: false
  856. })
  857. } else {
  858. loop[3] = res.content
  859. slice = loop.slice(0, loops)
  860. slice = slice.toString()
  861. putDevice({
  862. id: deviceid,
  863. groupId: groupid,
  864. circuits: slice
  865. }).then(res => {
  866. if (res.data.code == 0) {
  867. for (let i = 0; i < group.length; i++) {
  868. if (groupName == group[i].groupName) {
  869. for (let j = 0; j < group[i].devices.length; j++) {
  870. if (deviceName == group[i].devices[j].deviceName) {
  871. group[i].devices[j].circuits = slice
  872. wx.setStorageSync('group', group)
  873. that.setData({
  874. loop: loop
  875. })
  876. }
  877. }
  878. }
  879. }
  880. } else {
  881. wx.showModal({
  882. title: '错误',
  883. content: res.data.msg,
  884. showCancel: false
  885. })
  886. }
  887. })
  888. }
  889. }
  890. }
  891. })
  892. }
  893. //回路5
  894. else if (e.target.dataset.loopname == 5 && address[4] != "") {
  895. wx.showModal({
  896. title: '修改回路名称',
  897. editable: true,
  898. placeholderText: '请输入名称',
  899. success: res => {
  900. if (res.confirm) {
  901. if (res.content == '') {
  902. wx.showModal({
  903. title: '提示',
  904. content: '请输入名称',
  905. showCancel: false
  906. })
  907. } else if (res.content.length > 10) {
  908. wx.showModal({
  909. title: '提示',
  910. content: '回路名称不能大于10个字符',
  911. showCancel: false
  912. })
  913. } else {
  914. loop[4] = res.content
  915. slice = loop.slice(0, loops)
  916. slice = slice.toString()
  917. putDevice({
  918. id: deviceid,
  919. groupId: groupid,
  920. circuits: slice
  921. }).then(res => {
  922. if (res.data.code == 0) {
  923. for (let i = 0; i < group.length; i++) {
  924. if (groupName == group[i].groupName) {
  925. for (let j = 0; j < group[i].devices.length; j++) {
  926. if (deviceName == group[i].devices[j].deviceName) {
  927. group[i].devices[j].circuits = slice
  928. wx.setStorageSync('group', group)
  929. that.setData({
  930. loop: loop
  931. })
  932. }
  933. }
  934. }
  935. }
  936. } else {
  937. wx.showModal({
  938. title: '错误',
  939. content: res.data.msg,
  940. showCancel: false
  941. })
  942. }
  943. })
  944. }
  945. }
  946. }
  947. })
  948. }
  949. //回路6
  950. else if (e.target.dataset.loopname == 6 && address[5] != "") {
  951. wx.showModal({
  952. title: '修改回路名称',
  953. editable: true,
  954. placeholderText: '请输入名称',
  955. success: res => {
  956. if (res.confirm) {
  957. if (res.content == '') {
  958. wx.showModal({
  959. title: '提示',
  960. content: '请输入名称',
  961. showCancel: false
  962. })
  963. } else if (res.content.length > 10) {
  964. wx.showModal({
  965. title: '提示',
  966. content: '回路名称不能大于10个字符',
  967. showCancel: false
  968. })
  969. } else {
  970. loop[5] = res.content
  971. slice = loop.slice(0, loops)
  972. slice = slice.toString()
  973. putDevice({
  974. id: deviceid,
  975. groupId: groupid,
  976. circuits: slice
  977. }).then(res => {
  978. if (res.data.code == 0) {
  979. for (let i = 0; i < group.length; i++) {
  980. if (groupName == group[i].groupName) {
  981. for (let j = 0; j < group[i].devices.length; j++) {
  982. if (deviceName == group[i].devices[j].deviceName) {
  983. group[i].devices[j].circuits = slice
  984. wx.setStorageSync('group', group)
  985. that.setData({
  986. loop: loop
  987. })
  988. }
  989. }
  990. }
  991. }
  992. } else {
  993. wx.showModal({
  994. title: '错误',
  995. content: res.data.msg,
  996. showCancel: false
  997. })
  998. }
  999. })
  1000. }
  1001. }
  1002. }
  1003. })
  1004. }
  1005. //回路7
  1006. else if (e.target.dataset.loopname == 7 && address[6] != "") {
  1007. wx.showModal({
  1008. title: '修改回路名称',
  1009. editable: true,
  1010. placeholderText: '请输入名称',
  1011. success: res => {
  1012. if (res.confirm) {
  1013. if (res.content == '') {
  1014. wx.showModal({
  1015. title: '提示',
  1016. content: '请输入名称',
  1017. showCancel: false
  1018. })
  1019. } else if (res.content.length > 10) {
  1020. wx.showModal({
  1021. title: '提示',
  1022. content: '回路名称不能大于10个字符',
  1023. showCancel: false
  1024. })
  1025. } else {
  1026. loop[6] = res.content
  1027. slice = loop.slice(0, loops)
  1028. slice = slice.toString()
  1029. putDevice({
  1030. id: deviceid,
  1031. groupId: groupid,
  1032. circuits: slice
  1033. }).then(res => {
  1034. if (res.data.code == 0) {
  1035. for (let i = 0; i < group.length; i++) {
  1036. if (groupName == group[i].groupName) {
  1037. for (let j = 0; j < group[i].devices.length; j++) {
  1038. if (deviceName == group[i].devices[j].deviceName) {
  1039. group[i].devices[j].circuits = slice
  1040. wx.setStorageSync('group', group)
  1041. that.setData({
  1042. loop: loop
  1043. })
  1044. }
  1045. }
  1046. }
  1047. }
  1048. } else {
  1049. wx.showModal({
  1050. title: '错误',
  1051. content: res.data.msg,
  1052. showCancel: false
  1053. })
  1054. }
  1055. })
  1056. }
  1057. }
  1058. }
  1059. })
  1060. }
  1061. //回路8
  1062. else if (e.target.dataset.loopname == 8 && address[7] != "") {
  1063. wx.showModal({
  1064. title: '修改回路名称',
  1065. editable: true,
  1066. placeholderText: '请输入名称',
  1067. success: res => {
  1068. if (res.confirm) {
  1069. if (res.content == '') {
  1070. wx.showModal({
  1071. title: '提示',
  1072. content: '请输入名称',
  1073. showCancel: false
  1074. })
  1075. } else if (res.content.length > 10) {
  1076. wx.showModal({
  1077. title: '提示',
  1078. content: '回路名称不能大于10个字符',
  1079. showCancel: false
  1080. })
  1081. } else {
  1082. loop[7] = res.content
  1083. slice = loop.slice(0, loops)
  1084. slice = slice.toString()
  1085. putDevice({
  1086. id: deviceid,
  1087. groupId: groupid,
  1088. circuits: slice
  1089. }).then(res => {
  1090. if (res.data.code == 0) {
  1091. for (let i = 0; i < group.length; i++) {
  1092. if (groupName == group[i].groupName) {
  1093. for (let j = 0; j < group[i].devices.length; j++) {
  1094. if (deviceName == group[i].devices[j].deviceName) {
  1095. group[i].devices[j].circuits = slice
  1096. wx.setStorageSync('group', group)
  1097. that.setData({
  1098. loop: loop
  1099. })
  1100. }
  1101. }
  1102. }
  1103. }
  1104. } else {
  1105. wx.showModal({
  1106. title: '错误',
  1107. content: res.data.msg,
  1108. showCancel: false
  1109. })
  1110. }
  1111. })
  1112. }
  1113. }
  1114. }
  1115. })
  1116. }
  1117. //回路9
  1118. else if (e.target.dataset.loopname == 9 && address[8] != "") {
  1119. wx.showModal({
  1120. title: '修改回路名称',
  1121. editable: true,
  1122. placeholderText: '请输入名称',
  1123. success: res => {
  1124. if (res.confirm) {
  1125. if (res.content == '') {
  1126. wx.showModal({
  1127. title: '提示',
  1128. content: '请输入名称',
  1129. showCancel: false
  1130. })
  1131. } else if (res.content.length > 10) {
  1132. wx.showModal({
  1133. title: '提示',
  1134. content: '回路名称不能大于10个字符',
  1135. showCancel: false
  1136. })
  1137. } else {
  1138. loop[8] = res.content
  1139. slice = loop.slice(0, loops)
  1140. slice = slice.toString()
  1141. putDevice({
  1142. id: deviceid,
  1143. groupId: groupid,
  1144. circuits: slice
  1145. }).then(res => {
  1146. if (res.data.code == 0) {
  1147. for (let i = 0; i < group.length; i++) {
  1148. if (groupName == group[i].groupName) {
  1149. for (let j = 0; j < group[i].devices.length; j++) {
  1150. if (deviceName == group[i].devices[j].deviceName) {
  1151. group[i].devices[j].circuits = slice
  1152. wx.setStorageSync('group', group)
  1153. that.setData({
  1154. loop: loop
  1155. })
  1156. }
  1157. }
  1158. }
  1159. }
  1160. } else {
  1161. wx.showModal({
  1162. title: '错误',
  1163. content: res.data.msg,
  1164. showCancel: false
  1165. })
  1166. }
  1167. })
  1168. }
  1169. }
  1170. }
  1171. })
  1172. }
  1173. //回路10
  1174. else if (e.target.dataset.loopname == 10 && address[9] != "") {
  1175. wx.showModal({
  1176. title: '修改回路名称',
  1177. editable: true,
  1178. placeholderText: '请输入名称',
  1179. success: res => {
  1180. if (res.confirm) {
  1181. if (res.content == '') {
  1182. wx.showModal({
  1183. title: '提示',
  1184. content: '请输入名称',
  1185. showCancel: false
  1186. })
  1187. } else if (res.content.length > 10) {
  1188. wx.showModal({
  1189. title: '提示',
  1190. content: '回路名称不能大于10个字符',
  1191. showCancel: false
  1192. })
  1193. } else {
  1194. loop[9] = res.content
  1195. slice = loop.slice(0, loops)
  1196. slice = slice.toString()
  1197. putDevice({
  1198. id: deviceid,
  1199. groupId: groupid,
  1200. circuits: slice
  1201. }).then(res => {
  1202. if (res.data.code == 0) {
  1203. for (let i = 0; i < group.length; i++) {
  1204. if (groupName == group[i].groupName) {
  1205. for (let j = 0; j < group[i].devices.length; j++) {
  1206. if (deviceName == group[i].devices[j].deviceName) {
  1207. group[i].devices[j].circuits = slice
  1208. wx.setStorageSync('group', group)
  1209. that.setData({
  1210. loop: loop
  1211. })
  1212. }
  1213. }
  1214. }
  1215. }
  1216. } else {
  1217. wx.showModal({
  1218. title: '错误',
  1219. content: res.data.msg,
  1220. showCancel: false
  1221. })
  1222. }
  1223. })
  1224. }
  1225. }
  1226. }
  1227. })
  1228. }
  1229. //回路11
  1230. else if (e.target.dataset.loopname == 11 && address[10] != "") {
  1231. wx.showModal({
  1232. title: '修改回路名称',
  1233. editable: true,
  1234. placeholderText: '请输入名称',
  1235. success: res => {
  1236. if (res.confirm) {
  1237. if (res.content == '') {
  1238. wx.showModal({
  1239. title: '提示',
  1240. content: '请输入名称',
  1241. showCancel: false
  1242. })
  1243. } else if (res.content.length > 10) {
  1244. wx.showModal({
  1245. title: '提示',
  1246. content: '回路名称不能大于10个字符',
  1247. showCancel: false
  1248. })
  1249. } else {
  1250. loop[10] = res.content
  1251. slice = loop.slice(0, loops)
  1252. slice = slice.toString()
  1253. putDevice({
  1254. id: deviceid,
  1255. groupId: groupid,
  1256. circuits: slice
  1257. }).then(res => {
  1258. if (res.data.code == 0) {
  1259. for (let i = 0; i < group.length; i++) {
  1260. if (groupName == group[i].groupName) {
  1261. for (let j = 0; j < group[i].devices.length; j++) {
  1262. if (deviceName == group[i].devices[j].deviceName) {
  1263. group[i].devices[j].circuits = slice
  1264. wx.setStorageSync('group', group)
  1265. that.setData({
  1266. loop: loop
  1267. })
  1268. }
  1269. }
  1270. }
  1271. }
  1272. } else {
  1273. wx.showModal({
  1274. title: '错误',
  1275. content: res.data.msg,
  1276. showCancel: false
  1277. })
  1278. }
  1279. })
  1280. }
  1281. }
  1282. }
  1283. })
  1284. }
  1285. //回路12
  1286. else if (e.target.dataset.loopname == 12 && address[11] != "") {
  1287. wx.showModal({
  1288. title: '修改回路名称',
  1289. editable: true,
  1290. placeholderText: '请输入名称',
  1291. success: res => {
  1292. if (res.confirm) {
  1293. if (res.content == '') {
  1294. wx.showModal({
  1295. title: '提示',
  1296. content: '请输入名称',
  1297. showCancel: false
  1298. })
  1299. } else if (res.content.length > 10) {
  1300. wx.showModal({
  1301. title: '提示',
  1302. content: '回路名称不能大于10个字符',
  1303. showCancel: false
  1304. })
  1305. } else {
  1306. loop[11] = res.content
  1307. slice = loop.slice(0, loops)
  1308. slice = slice.toString()
  1309. putDevice({
  1310. id: deviceid,
  1311. groupId: groupid,
  1312. circuits: slice
  1313. }).then(res => {
  1314. if (res.data.code == 0) {
  1315. for (let i = 0; i < group.length; i++) {
  1316. if (groupName == group[i].groupName) {
  1317. for (let j = 0; j < group[i].devices.length; j++) {
  1318. if (deviceName == group[i].devices[j].deviceName) {
  1319. group[i].devices[j].circuits = slice
  1320. wx.setStorageSync('group', group)
  1321. that.setData({
  1322. loop: loop
  1323. })
  1324. }
  1325. }
  1326. }
  1327. }
  1328. } else {
  1329. wx.showModal({
  1330. title: '错误',
  1331. content: res.data.msg,
  1332. showCancel: false
  1333. })
  1334. }
  1335. })
  1336. }
  1337. }
  1338. }
  1339. })
  1340. }
  1341. },
  1342. //全开
  1343. Fullopen: function () {
  1344. var that = this
  1345. //获取设备的在线状态
  1346. getBasic(that.data.deviceId,that.data.deviceKey).then(res => {
  1347. if(res.data.errno == 0){
  1348. if(res.data.data.online == true){
  1349. that.setData({status:'在线'})
  1350. }
  1351. else{
  1352. that.setData({status:'离线'})
  1353. }
  1354. }
  1355. else{
  1356. wx.showModal({
  1357. title: '错误',
  1358. content: res.data.error,
  1359. showCancel:false
  1360. })
  1361. }
  1362. })
  1363. var obj = {
  1364. 'R1_RelayStatus': 13,
  1365. 'R2_RelayStatus': 13,
  1366. 'R3_RelayStatus': 13,
  1367. 'R4_RelayStatus': 13,
  1368. 'R5_RelayStatus': 13,
  1369. 'R6_RelayStatus': 13,
  1370. 'R7_RelayStatus': 13,
  1371. 'R8_RelayStatus': 13,
  1372. 'R9_RelayStatus': 13,
  1373. 'R10_RelayStatus': 13,
  1374. 'R11_RelayStatus': 13,
  1375. 'R12_RelayStatus': 13,
  1376. 'Reflash': 3
  1377. }
  1378. if(that.data.status == '在线'){
  1379. postData(that.data.deviceId, that.data.deviceKey, obj).then(res => {
  1380. if (res.data.errno == 0) {
  1381. wx.setStorageSync('lamp', [])
  1382. var lamp = wx.getStorageSync('lamp')
  1383. for (let h = 0; h < 12; h++) {
  1384. lamp.push("https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png")
  1385. }
  1386. setTimeout(function () {
  1387. getData(that.data.deviceId, that.data.deviceKey).then(bind => {
  1388. if (bind.data.errno == 0) {
  1389. let Bind = bind.data.data
  1390. for (let r1 = 0; r1 < Bind.length; r1++) {
  1391. if (Bind[r1].id == 'R1_RelayStatus') {
  1392. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 0)
  1393. } else if (Bind[r1].id == 'R2_RelayStatus') {
  1394. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 1)
  1395. } else if (Bind[r1].id == 'R3_RelayStatus') {
  1396. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 2)
  1397. } else if (Bind[r1].id == 'R4_RelayStatus') {
  1398. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 3)
  1399. } else if (Bind[r1].id == 'R5_RelayStatus') {
  1400. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 4)
  1401. } else if (Bind[r1].id == 'R6_RelayStatus') {
  1402. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 5)
  1403. } else if (Bind[r1].id == 'R7_RelayStatus') {
  1404. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 6)
  1405. } else if (Bind[r1].id == 'R8_RelayStatus') {
  1406. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 7)
  1407. } else if (Bind[r1].id == 'R9_RelayStatus') {
  1408. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 8)
  1409. } else if (Bind[r1].id == 'R10_RelayStatus') {
  1410. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 9)
  1411. } else if (Bind[r1].id == 'R11_RelayStatus') {
  1412. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 10)
  1413. } else if (Bind[r1].id == 'R12_RelayStatus') {
  1414. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 11)
  1415. }
  1416. }
  1417. wx.setStorageSync('lamp', switchReal)
  1418. that.setData({
  1419. lamp: wx.getStorageSync('lamp')
  1420. })
  1421. }
  1422. else{
  1423. wx.showModal({
  1424. title: '错误',
  1425. content: bind.data.error,
  1426. showCancel:false
  1427. })
  1428. }
  1429. })
  1430. }, 2000)
  1431. }
  1432. else {
  1433. wx.showModal({
  1434. title: '提示',
  1435. content: res.data.error,
  1436. showCancel: false
  1437. })
  1438. }
  1439. })
  1440. }
  1441. else{
  1442. wx.showModal({
  1443. title: '提示',
  1444. content: '设备处于离线状态',
  1445. showCancel:false
  1446. })
  1447. }
  1448. },
  1449. //全关
  1450. Allclosed: function () {
  1451. var that = this
  1452. getBasic(that.data.deviceId,that.data.deviceKey).then(res => {
  1453. if(res.data.errno == 0){
  1454. if(res.data.data.online == true){
  1455. that.setData({status:'在线'})
  1456. }
  1457. else{
  1458. that.setData({status:'离线'})
  1459. }
  1460. }
  1461. else{
  1462. wx.showModal({
  1463. title: '错误',
  1464. content: res.data.error,
  1465. showCancel:false
  1466. })
  1467. }
  1468. })
  1469. var obj = {
  1470. 'R1_RelayStatus': 12,
  1471. 'R2_RelayStatus': 12,
  1472. 'R3_RelayStatus': 12,
  1473. 'R4_RelayStatus': 12,
  1474. 'R5_RelayStatus': 12,
  1475. 'R6_RelayStatus': 12,
  1476. 'R7_RelayStatus': 12,
  1477. 'R8_RelayStatus': 12,
  1478. 'R9_RelayStatus': 12,
  1479. 'R10_RelayStatus': 12,
  1480. 'R11_RelayStatus': 12,
  1481. 'R12_RelayStatus': 12,
  1482. 'Reflash': 3
  1483. }
  1484. if(that.data.status == '在线'){
  1485. postData(that.data.deviceId, that.data.deviceKey, obj).then(res => {
  1486. if (res.data.errno == 0) {
  1487. wx.setStorageSync('lamp', [])
  1488. var lamp = wx.getStorageSync('lamp')
  1489. for (let h = 0; h < 12; h++) {
  1490. lamp.push("https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png")
  1491. }
  1492. setTimeout(function () {
  1493. getData(that.data.deviceId, that.data.deviceKey).then(bind => {
  1494. if (bind.data.errno == 0) {
  1495. let Bind = bind.data.data
  1496. for (let r1 = 0; r1 < Bind.length; r1++) {
  1497. if (Bind[r1].id == 'R1_RelayStatus') {
  1498. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 0)
  1499. } else if (Bind[r1].id == 'R2_RelayStatus') {
  1500. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 1)
  1501. } else if (Bind[r1].id == 'R3_RelayStatus') {
  1502. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 2)
  1503. } else if (Bind[r1].id == 'R4_RelayStatus') {
  1504. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 3)
  1505. } else if (Bind[r1].id == 'R5_RelayStatus') {
  1506. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 4)
  1507. } else if (Bind[r1].id == 'R6_RelayStatus') {
  1508. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 5)
  1509. } else if (Bind[r1].id == 'R7_RelayStatus') {
  1510. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 6)
  1511. } else if (Bind[r1].id == 'R8_RelayStatus') {
  1512. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 7)
  1513. } else if (Bind[r1].id == 'R9_RelayStatus') {
  1514. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 8)
  1515. } else if (Bind[r1].id == 'R10_RelayStatus') {
  1516. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 9)
  1517. } else if (Bind[r1].id == 'R11_RelayStatus') {
  1518. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 10)
  1519. } else if (Bind[r1].id == 'R12_RelayStatus') {
  1520. var switchReal = control.switchReal(Bind[r1].current_value, lamp, 11)
  1521. }
  1522. }
  1523. wx.setStorageSync('lamp', switchReal)
  1524. that.setData({
  1525. lamp: wx.getStorageSync('lamp')
  1526. })
  1527. }
  1528. else{
  1529. wx.showModal({
  1530. title: '错误',
  1531. content: bind.data.error,
  1532. showCancel:false
  1533. })
  1534. }
  1535. })
  1536. }, 2000)
  1537. }
  1538. else {
  1539. wx.showModal({
  1540. title: '提示',
  1541. content: res.data.error,
  1542. showCancel: false
  1543. })
  1544. }
  1545. })
  1546. }
  1547. else{
  1548. wx.showModal({
  1549. title: '提示',
  1550. content: '设备处于离线状态',
  1551. showCancel:false
  1552. })
  1553. }
  1554. },
  1555. //分组下拉
  1556. changegroup: function (e) {
  1557. var that = this
  1558. that.setData({
  1559. groupIndex: e.detail.value
  1560. })
  1561. var groupName = that.data.groupName[that.data.groupIndex] //选择的分组名称
  1562. wx.setStorageSync('groupName', groupName) //将修改的分组名称放入缓存
  1563. //获取设备名称下拉
  1564. var group = wx.getStorageSync('group')
  1565. var deviceName = that.data.deviceName
  1566. var deviceName = []
  1567. for (let i = 0; i < group.length; i++) {
  1568. if (group[i].groupName == groupName) {
  1569. if (group[i].devices != null && group[i].devices.length != 0) {
  1570. wx.showToast({
  1571. title: '刷新中',
  1572. icon: 'loading',
  1573. duration: 2000
  1574. })
  1575. for (let j = 0; j < group[i].devices.length; j++) {
  1576. deviceName.push(group[i].devices[j].deviceName)
  1577. }
  1578. that.setData({
  1579. deviceName: deviceName,
  1580. deviceIndex: 0
  1581. })
  1582. var groupNames = that.data.groupName[that.data.groupIndex] //当前分组
  1583. var deviceNames = that.data.deviceName[that.data.deviceIndex] //当前设备
  1584. wx.setStorageSync('deviceName', deviceNames) //将修改设备名放入缓存
  1585. //获取设备信息
  1586. for (let d = 0; d < group.length; d++) {
  1587. if (groupNames == group[d].groupName) {
  1588. var Groupno = group[d].id //分组id
  1589. for (let g = 0; g < group[d].devices.length; g++) {
  1590. if (deviceNames == group[d].devices[g].deviceName) {
  1591. //旧设备信息
  1592. if (group[d].devices[g].module == 0) {
  1593. var id = group[d].devices[g].id
  1594. var circuitNum = group[d].devices[g].circuitNum
  1595. var circuits = group[d].devices[g].circuits
  1596. var deviceId = group[d].devices[g].deviceId
  1597. var deviceKey = group[d].devices[g].deviceKey
  1598. var moudule = group[d].devices[g].module
  1599. that.setData({
  1600. play: 0
  1601. })
  1602. }
  1603. //新设备信息
  1604. else {
  1605. var circuitNum = group[d].devices[g].circuitNum
  1606. var circuits = group[d].devices[g].circuits
  1607. var moudule = group[d].devices[g].module
  1608. var id = group[d].devices[g].id
  1609. var ID = group[d].devices[g].deviceId
  1610. that.setData({
  1611. play: 1,
  1612. ID:ID
  1613. })
  1614. }
  1615. }
  1616. }
  1617. }
  1618. }
  1619. that.setData({
  1620. moudule: moudule,
  1621. id: id,
  1622. loops: circuitNum,
  1623. Groupno:Groupno
  1624. })
  1625. //灯泡图标缓存
  1626. wx.setStorageSync('lamp', [])
  1627. var lamp = wx.getStorageSync('lamp')
  1628. for (let h = 0; h < 12; h++) {
  1629. lamp.push("https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png")
  1630. }
  1631. //旧设备
  1632. if (moudule == 0) {
  1633. //重置状态
  1634. let combination = control.Refresh()
  1635. that.setData({
  1636. loop: combination[0],
  1637. address: combination[1],
  1638. lamp: combination[2],
  1639. size: combination[3],
  1640. Color: combination[4]
  1641. })
  1642. //..............................
  1643. that.setData({
  1644. deviceId: deviceId,
  1645. deviceKey: deviceKey
  1646. })
  1647. var Circuits = circuits.split(',')
  1648. let loop = that.data.loop
  1649. for (let vr = 0; vr < circuitNum; vr++) {
  1650. loop[vr] = Circuits[vr]
  1651. }
  1652. that.setData({
  1653. loop: loop
  1654. })
  1655. postData(deviceId, deviceKey, {
  1656. "Reflash": 3
  1657. }).then(res => {
  1658. if(res.data.errno == 0 || res.data.errno == 10){
  1659. setTimeout(function () {
  1660. getBasic(deviceId, deviceKey).then(ever => {
  1661. if (ever.data.errno == 0) {
  1662. if (ever.data.data.online == true) {
  1663. that.setData({
  1664. status: "在线"
  1665. })
  1666. } else {
  1667. that.setData({
  1668. status: "离线"
  1669. })
  1670. }
  1671. getData(deviceId, deviceKey).then(ver => {
  1672. if (ver.data.errno == 0) {
  1673. let data = ver.data.data
  1674. for (let i = 0; i < data.length; i++) {
  1675. if (data[i].id == "RelayCount") {
  1676. var quantity = data[i].current_value
  1677. that.setData({
  1678. loops: quantity
  1679. })
  1680. } else if (data[i].id == "ManualStatus") {
  1681. if (data[i].current_value == 0) {
  1682. that.setData({
  1683. Modecontrol: "自动"
  1684. })
  1685. } else {
  1686. that.setData({
  1687. Modecontrol: "手动"
  1688. })
  1689. }
  1690. }
  1691. //回路1
  1692. else if (data[i].id == 'R1_RelayStatus') {
  1693. let police = data[i].current_value
  1694. var lamps = control.switchReal(police, lamp, 0)
  1695. } else if (data[i].id == 'R2_RelayStatus') {
  1696. let police = data[i].current_value
  1697. var lamps = control.switchReal(police, lamp, 1)
  1698. } else if (data[i].id == 'R3_RelayStatus') {
  1699. let police = data[i].current_value
  1700. var lamps = control.switchReal(police, lamp, 2)
  1701. } else if (data[i].id == 'R4_RelayStatus') {
  1702. let police = data[i].current_value
  1703. var lamps = control.switchReal(police, lamp, 3)
  1704. } else if (data[i].id == 'R5_RelayStatus') {
  1705. let police = data[i].current_value
  1706. var lamps = control.switchReal(police, lamp, 4)
  1707. } else if (data[i].id == 'R6_RelayStatus') {
  1708. let police = data[i].current_value
  1709. var lamps = control.switchReal(police, lamp, 5)
  1710. } else if (data[i].id == 'R7_RelayStatus') {
  1711. let police = data[i].current_value
  1712. var lamps = control.switchReal(police, lamp, 6)
  1713. } else if (data[i].id == 'R8_RelayStatus') {
  1714. let police = data[i].current_value
  1715. var lamps = control.switchReal(police, lamp, 7)
  1716. } else if (data[i].id == 'R9_RelayStatus') {
  1717. let police = data[i].current_value
  1718. var lamps = control.switchReal(police, lamp, 8)
  1719. } else if (data[i].id == 'R10_RelayStatus') {
  1720. let police = data[i].current_value
  1721. var lamps = control.switchReal(police, lamp, 9)
  1722. } else if (data[i].id == 'R11_RelayStatus') {
  1723. let police = data[i].current_value
  1724. var lamps = control.switchReal(police, lamp, 10)
  1725. } else if (data[i].id == 'R12_RelayStatus') {
  1726. let police = data[i].current_value
  1727. var lamps = control.switchReal(police, lamp, 11)
  1728. }
  1729. wx.setStorageSync('lamp', lamps)
  1730. that.setData({
  1731. lamp: wx.getStorageSync('lamp')
  1732. })
  1733. }
  1734. var Loop = that.data.Loop
  1735. var color = that.data.Color
  1736. var size = that.data.Size
  1737. var Address = that.data.address
  1738. var enloop = that.data.loop
  1739. for (let i = 0; i < quantity; i++) {
  1740. Loop[i] = enloop[i]
  1741. color[i] = "black"
  1742. size[i] = "calc(100vw * 16/375)",
  1743. Address[i] = "/image/modify.png"
  1744. }
  1745. that.setData({
  1746. Color: color,
  1747. Size: size,
  1748. address: Address,
  1749. Loop: Loop
  1750. })
  1751. } else {
  1752. wx.showModal({
  1753. title: '错误',
  1754. content: ver.data.error,
  1755. showCancel: false
  1756. })
  1757. }
  1758. })
  1759. } else {
  1760. wx.showModal({
  1761. title: '错误',
  1762. content: ever.data.error,
  1763. showCancel: false
  1764. })
  1765. }
  1766. })
  1767. }, 2000)
  1768. }
  1769. else{
  1770. setTimeout(function(){
  1771. wx.showModal({
  1772. title: '错误',
  1773. content: res.data.error,
  1774. showCancel:false
  1775. })
  1776. },2000)
  1777. }
  1778. })
  1779. }
  1780. //新设备
  1781. else {
  1782. //重置状态
  1783. let combination = control.Refresh()
  1784. that.setData({
  1785. loop: combination[0],
  1786. address: combination[1],
  1787. lamp: combination[2],
  1788. size: combination[3],
  1789. Color: combination[4]
  1790. })
  1791. //..............................
  1792. //获取设备在线状态
  1793. getDevice(id, Groupno).then(dve => {
  1794. if (dve.data.code == 0) {
  1795. var state = dve.data.data
  1796. switch (state.status) {
  1797. case 0:
  1798. that.setData({
  1799. status: '离线'
  1800. })
  1801. break;
  1802. case 1:
  1803. that.setData({
  1804. status: '在线'
  1805. })
  1806. break;
  1807. }
  1808. } else {
  1809. wx.showModal({
  1810. title: '错误',
  1811. content: dve.data.msg,
  1812. showCancel: false
  1813. })
  1814. }
  1815. })
  1816. var Circuits = circuits.split(',')
  1817. let loop = that.data.loop
  1818. for (let vr = 0; vr < circuitNum; vr++) {
  1819. loop[vr] = Circuits[vr]
  1820. }
  1821. that.setData({
  1822. loop: loop
  1823. })
  1824. getloop(id).then(res => {
  1825. if (res.data.code == 0) {
  1826. let loopState = res.data.data
  1827. //loopState.length可以视为回路数量
  1828. var Loop = that.data.Loop
  1829. var color = that.data.Color
  1830. var size = that.data.Size
  1831. var Address = that.data.address
  1832. for (let n = 0; n < loopState.length; n++) {
  1833. Loop[n] = that.data.Loop[n]
  1834. color[n] = "black"
  1835. size[n] = "calc(100vw * 16/375)",
  1836. Address[n] = "/image/modify.png"
  1837. }
  1838. that.setData({
  1839. Color: color,
  1840. Size: size,
  1841. address: Address,
  1842. Loop: Loop
  1843. })
  1844. } else {
  1845. wx.showModal({
  1846. title: '错误',
  1847. content: res.data.msg,
  1848. showCancel: false
  1849. })
  1850. }
  1851. })
  1852. loopSwitchstate(id).then(res => {
  1853. if (res.data.code == 0) {
  1854. var relay = res.data.data
  1855. for (let e = 0; e < relay.length; e++) {
  1856. if (relay[e].status == 1) {
  1857. lamp[e] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp1.png'
  1858. } else if (relay[e].status == 0) {
  1859. lamp[e] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
  1860. } else {
  1861. lamp[e] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
  1862. }
  1863. }
  1864. } else {
  1865. wx.showModal({
  1866. title: '错误',
  1867. content: res.data.msg,
  1868. showCancel: false
  1869. })
  1870. }
  1871. })
  1872. setTimeout(function () {
  1873. wx.setStorageSync('lamp', lamp)
  1874. that.setData({
  1875. lamp: wx.getStorageSync('lamp')
  1876. })
  1877. }, 2000)
  1878. }
  1879. } else {
  1880. that.setData({
  1881. status: '离线',
  1882. deviceName: []
  1883. })
  1884. wx.setStorageSync('deviceName', '') //清空设备名称缓存
  1885. }
  1886. }
  1887. }
  1888. },
  1889. //设备下拉
  1890. changedevice: function (e) {
  1891. wx.showToast({
  1892. title: '刷新中',
  1893. icon: 'loading',
  1894. duration: 2000
  1895. })
  1896. var that = this
  1897. that.setData({
  1898. deviceIndex: e.detail.value
  1899. })
  1900. var group = wx.getStorageSync('group')
  1901. var groupName = that.data.groupName[that.data.groupIndex]
  1902. var deviceName = that.data.deviceName[that.data.deviceIndex]
  1903. wx.setStorageSync('groupName', groupName) //分组名称
  1904. wx.setStorageSync('deviceName', deviceName) //设备名称
  1905. for (let index = 0; index < group.length; index++) {
  1906. if (groupName == group[index].groupName) {
  1907. var Groupno = group[index].id //分组id
  1908. for (let t = 0; t < group[index].devices.length; t++) {
  1909. if (deviceName == group[index].devices[t].deviceName) {
  1910. //旧设备信息
  1911. if (group[index].devices[t].module == 0) {
  1912. var id = group[index].devices[t].id
  1913. var circuitNum = group[index].devices[t].circuitNum
  1914. var circuits = group[index].devices[t].circuits
  1915. var deviceId = group[index].devices[t].deviceId
  1916. var deviceKey = group[index].devices[t].deviceKey
  1917. var moudule = group[index].devices[t].module
  1918. that.setData({
  1919. play: 0
  1920. })
  1921. }
  1922. //新设备信息
  1923. else {
  1924. var circuitNum = group[index].devices[t].circuitNum
  1925. var circuits = group[index].devices[t].circuits
  1926. var moudule = group[index].devices[t].module
  1927. var id = group[index].devices[t].id
  1928. var ID = group[index].devices[t].deviceId
  1929. that.setData({
  1930. play: 1,
  1931. ID:ID,
  1932. })
  1933. }
  1934. }
  1935. }
  1936. }
  1937. }
  1938. that.setData({
  1939. moudule: moudule,
  1940. id: id,
  1941. loops: circuitNum,
  1942. Groupno:Groupno
  1943. })
  1944. //灯泡图标缓存
  1945. wx.setStorageSync('lamp', [])
  1946. var lamp = wx.getStorageSync('lamp')
  1947. for (let h = 0; h < 12; h++) {
  1948. lamp.push("https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png")
  1949. }
  1950. //旧设备
  1951. if (moudule == 0) {
  1952. //重置状态
  1953. let combination = control.Refresh()
  1954. that.setData({
  1955. loop: combination[0],
  1956. address: combination[1],
  1957. lamp: combination[2],
  1958. size: combination[3],
  1959. Color: combination[4]
  1960. })
  1961. //..............................
  1962. that.setData({
  1963. deviceId: deviceId,
  1964. deviceKey: deviceKey
  1965. })
  1966. var Circuits = circuits.split(',')
  1967. let loop = that.data.loop
  1968. for (let vr = 0; vr < circuitNum; vr++) {
  1969. loop[vr] = Circuits[vr]
  1970. }
  1971. that.setData({
  1972. loop: loop
  1973. })
  1974. postData(deviceId, deviceKey, {
  1975. "Reflash": 3
  1976. }).then(res => {
  1977. if(res.data.errno == 0 || res.data.errno == 10){
  1978. setTimeout(function () {
  1979. getBasic(deviceId, deviceKey).then(ever => {
  1980. if (ever.data.errno == 0) {
  1981. if (ever.data.data.online == true) {
  1982. that.setData({
  1983. status: "在线"
  1984. })
  1985. } else {
  1986. that.setData({
  1987. status: "离线"
  1988. })
  1989. }
  1990. getData(deviceId, deviceKey).then(ver => {
  1991. if (ver.data.errno == 0) {
  1992. let data = ver.data.data
  1993. for (let i = 0; i < data.length; i++) {
  1994. if (data[i].id == "RelayCount") {
  1995. var quantity = data[i].current_value
  1996. that.setData({
  1997. loops: quantity
  1998. })
  1999. } else if (data[i].id == "ManualStatus") {
  2000. if (data[i].current_value == 0) {
  2001. that.setData({
  2002. Modecontrol: "自动"
  2003. })
  2004. } else {
  2005. that.setData({
  2006. Modecontrol: "手动"
  2007. })
  2008. }
  2009. }
  2010. //回路1
  2011. else if (data[i].id == 'R1_RelayStatus') {
  2012. let police = data[i].current_value
  2013. var lamps = control.switchReal(police, lamp, 0)
  2014. } else if (data[i].id == 'R2_RelayStatus') {
  2015. let police = data[i].current_value
  2016. var lamps = control.switchReal(police, lamp, 1)
  2017. } else if (data[i].id == 'R3_RelayStatus') {
  2018. let police = data[i].current_value
  2019. var lamps = control.switchReal(police, lamp, 2)
  2020. } else if (data[i].id == 'R4_RelayStatus') {
  2021. let police = data[i].current_value
  2022. var lamps = control.switchReal(police, lamp, 3)
  2023. } else if (data[i].id == 'R5_RelayStatus') {
  2024. let police = data[i].current_value
  2025. var lamps = control.switchReal(police, lamp, 4)
  2026. } else if (data[i].id == 'R6_RelayStatus') {
  2027. let police = data[i].current_value
  2028. var lamps = control.switchReal(police, lamp, 5)
  2029. } else if (data[i].id == 'R7_RelayStatus') {
  2030. let police = data[i].current_value
  2031. var lamps = control.switchReal(police, lamp, 6)
  2032. } else if (data[i].id == 'R8_RelayStatus') {
  2033. let police = data[i].current_value
  2034. var lamps = control.switchReal(police, lamp, 7)
  2035. } else if (data[i].id == 'R9_RelayStatus') {
  2036. let police = data[i].current_value
  2037. var lamps = control.switchReal(police, lamp, 8)
  2038. } else if (data[i].id == 'R10_RelayStatus') {
  2039. let police = data[i].current_value
  2040. var lamps = control.switchReal(police, lamp, 9)
  2041. } else if (data[i].id == 'R11_RelayStatus') {
  2042. let police = data[i].current_value
  2043. var lamps = control.switchReal(police, lamp, 10)
  2044. } else if (data[i].id == 'R12_RelayStatus') {
  2045. let police = data[i].current_value
  2046. var lamps = control.switchReal(police, lamp, 11)
  2047. }
  2048. wx.setStorageSync('lamp', lamps)
  2049. that.setData({
  2050. lamp: wx.getStorageSync('lamp')
  2051. })
  2052. }
  2053. var Loop = that.data.Loop
  2054. var color = that.data.Color
  2055. var size = that.data.Size
  2056. var Address = that.data.address
  2057. var enloop = that.data.loop
  2058. for (let i = 0; i < quantity; i++) {
  2059. Loop[i] = enloop[i]
  2060. color[i] = "black"
  2061. size[i] = "calc(100vw * 16/375)",
  2062. Address[i] = "/image/modify.png"
  2063. }
  2064. that.setData({
  2065. Color: color,
  2066. Size: size,
  2067. address: Address,
  2068. Loop: Loop
  2069. })
  2070. } else {
  2071. wx.showModal({
  2072. title: '错误',
  2073. content: ver.data.error,
  2074. showCancel: false
  2075. })
  2076. }
  2077. })
  2078. } else {
  2079. wx.showModal({
  2080. title: '错误',
  2081. content: ever.data.error,
  2082. showCancel: false
  2083. })
  2084. }
  2085. })
  2086. }, 2000)
  2087. }
  2088. else if(res.data.errno == 10){
  2089. setTimeout(function(){
  2090. that.setData({status:'离线'})
  2091. },2000)
  2092. }
  2093. else{
  2094. setTimeout(function(){
  2095. wx.showModal({
  2096. title: '错误',
  2097. content: res.data.error,
  2098. showCancel:false
  2099. })
  2100. },2000)
  2101. }
  2102. })
  2103. }
  2104. //新设备
  2105. else {
  2106. //重置状态
  2107. let combination = control.Refresh()
  2108. that.setData({
  2109. loop: combination[0],
  2110. address: combination[1],
  2111. lamp: combination[2],
  2112. size: combination[3],
  2113. Color: combination[4]
  2114. })
  2115. //..............................
  2116. //获取设备在线状态
  2117. getDevice(id, Groupno).then(dve => {
  2118. if (dve.data.code == 0) {
  2119. var state = dve.data.data
  2120. switch (state.status) {
  2121. case 0:
  2122. that.setData({
  2123. status: '离线'
  2124. })
  2125. break;
  2126. case 1:
  2127. that.setData({
  2128. status: '在线'
  2129. })
  2130. break;
  2131. }
  2132. } else {
  2133. wx.showModal({
  2134. title: '错误',
  2135. content: dve.data.msg,
  2136. showCancel: false
  2137. })
  2138. }
  2139. })
  2140. var Circuits = circuits.split(',')
  2141. let loop = that.data.loop
  2142. for (let vr = 0; vr < circuitNum; vr++) {
  2143. loop[vr] = Circuits[vr]
  2144. }
  2145. that.setData({
  2146. loop: loop
  2147. })
  2148. getloop(id).then(res => {
  2149. if (res.data.code == 0) {
  2150. let loopState = res.data.data
  2151. //loopState.length可以视为回路数量
  2152. var Loop = that.data.Loop
  2153. var color = that.data.Color
  2154. var size = that.data.Size
  2155. var Address = that.data.address
  2156. for (let n = 0; n < loopState.length; n++) {
  2157. Loop[n] = that.data.Loop[n]
  2158. color[n] = "black"
  2159. size[n] = "calc(100vw * 16/375)",
  2160. Address[n] = "/image/modify.png"
  2161. }
  2162. that.setData({
  2163. Color: color,
  2164. Size: size,
  2165. address: Address,
  2166. Loop: Loop
  2167. })
  2168. } else {
  2169. wx.showModal({
  2170. title: '错误',
  2171. content: res.data.msg,
  2172. showCancel: false
  2173. })
  2174. }
  2175. })
  2176. loopSwitchstate(id).then(res => {
  2177. if (res.data.code == 0) {
  2178. var relay = res.data.data
  2179. for (let e = 0; e < relay.length; e++) {
  2180. if (relay[e].status == 1) {
  2181. lamp[e] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp1.png'
  2182. } else if (relay[e].status == 0) {
  2183. lamp[e] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
  2184. } else {
  2185. lamp[e] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
  2186. }
  2187. }
  2188. } else {
  2189. wx.showModal({
  2190. title: '错误',
  2191. content: res.data.msg,
  2192. showCancel: false
  2193. })
  2194. }
  2195. })
  2196. setTimeout(function () {
  2197. wx.setStorageSync('lamp', lamp)
  2198. that.setData({
  2199. lamp: wx.getStorageSync('lamp')
  2200. })
  2201. }, 2000)
  2202. }
  2203. },
  2204. //手动
  2205. manual: function (e) {
  2206. var that = this
  2207. getBasic(that.data.deviceId,that.data.deviceKey).then(res => {
  2208. if(res.data.errno == 0){
  2209. if(res.data.data.online == true){
  2210. that.setData({status:'在线'})
  2211. }
  2212. else{
  2213. that.setData({status:'离线'})
  2214. }
  2215. }
  2216. else{
  2217. wx.showModal({
  2218. title: '错误',
  2219. content: res.data.error,
  2220. showCancel:false
  2221. })
  2222. }
  2223. })
  2224. var deviceId = that.data.deviceId
  2225. var deviceKey = that.data.deviceKey
  2226. if(that.data.status == '在线'){
  2227. postData(deviceId, deviceKey, {
  2228. 'ManualStatus': 1,
  2229. 'Reflash': 3
  2230. }).then(res => {
  2231. if (res.data.errno == 0) {
  2232. setTimeout(function(){
  2233. getData(deviceId,deviceKey).then(res =>{
  2234. if(res.data.errno == 0){
  2235. var data = res.data.data
  2236. for(let i = 0;i < data.length;i++){
  2237. if(data[i].id == 'ManualStatus'){
  2238. if(data[i].current_value == '0'){
  2239. that.setData({
  2240. Modecontrol: '自动'
  2241. })
  2242. }
  2243. else{
  2244. that.setData({
  2245. Modecontrol: '手动'
  2246. })
  2247. }
  2248. }
  2249. }
  2250. }
  2251. else{
  2252. wx.showModal({
  2253. title: '错误',
  2254. content: res.data.error,
  2255. showCancel:false
  2256. })
  2257. }
  2258. })
  2259. },2000)
  2260. } else {
  2261. wx.showModal({
  2262. title: '错误',
  2263. content: res.data.error,
  2264. showCancel: false
  2265. })
  2266. }
  2267. })
  2268. }
  2269. else{
  2270. wx.showModal({
  2271. title: '提示',
  2272. content: '设备处于离线状态',
  2273. showCancel:false
  2274. })
  2275. }
  2276. },
  2277. //自动
  2278. automatic: function (e) {
  2279. var that = this
  2280. getBasic(that.data.deviceId,that.data.deviceKey).then(res => {
  2281. if(res.data.errno == 0){
  2282. if(res.data.data.online == true){
  2283. that.setData({status:'在线'})
  2284. }
  2285. else{
  2286. that.setData({status:'离线'})
  2287. }
  2288. }
  2289. else{
  2290. wx.showModal({
  2291. title: '错误',
  2292. content: res.data.error,
  2293. showCancel:false
  2294. })
  2295. }
  2296. })
  2297. var deviceId = that.data.deviceId
  2298. var deviceKey = that.data.deviceKey
  2299. if(that.data.status == '在线'){
  2300. postData(deviceId, deviceKey, {
  2301. 'ManualStatus': 0,
  2302. 'Reflash': 3
  2303. }).then(res => {
  2304. if (res.data.errno == 0) {
  2305. setTimeout(function(){
  2306. getData(deviceId,deviceKey).then(res =>{
  2307. if(res.data.errno == 0){
  2308. var data = res.data.data
  2309. for(let i = 0;i < data.length;i++){
  2310. if(data[i].id == 'ManualStatus'){
  2311. if(data[i].current_value == '0'){
  2312. that.setData({
  2313. Modecontrol: '自动'
  2314. })
  2315. }
  2316. else{
  2317. that.setData({
  2318. Modecontrol: '手动'
  2319. })
  2320. }
  2321. }
  2322. }
  2323. }
  2324. else{
  2325. wx.showModal({
  2326. title: '错误',
  2327. content: res.data.error,
  2328. showCancel:false
  2329. })
  2330. }
  2331. })
  2332. },2000)
  2333. } else {
  2334. wx.showModal({
  2335. title: '错误',
  2336. content: res.data.error,
  2337. showCancel: false
  2338. })
  2339. }
  2340. })
  2341. }
  2342. else{
  2343. wx.showModal({
  2344. title: '提示',
  2345. content: '设备处于离线状态',
  2346. showCancel:false
  2347. })
  2348. }
  2349. },
  2350. //刷新页面
  2351. /**
  2352. * 生命周期函数--监听页面加载
  2353. */
  2354. onLoad(options) {
  2355. },
  2356. /**
  2357. * 生命周期函数--监听页面初次渲染完成
  2358. */
  2359. onReady() {
  2360. },
  2361. /**
  2362. * 生命周期函数--监听页面显示
  2363. */
  2364. onShow() {
  2365. wx.showToast({
  2366. title: '加载中',
  2367. icon: 'loading',
  2368. duration: 2000
  2369. })
  2370. var that = this
  2371. var group = wx.getStorageSync('group')
  2372. if (group != null && group.length != 0) {
  2373. //获取分组下拉
  2374. var groups = []
  2375. for (let i = 0; i < group.length; i++) {
  2376. groups.push(group[i].groupName)
  2377. }
  2378. that.setData({
  2379. groupName: groups
  2380. })
  2381. //改变分组下标
  2382. if (wx.getStorageSync('groupName') != '') {
  2383. let GroupName = that.data.groupName
  2384. for (let n = 0; n < GroupName.length; n++) {
  2385. if (GroupName[n] == wx.getStorageSync('groupName')) {
  2386. that.setData({
  2387. groupIndex: n
  2388. })
  2389. }
  2390. }
  2391. } else {
  2392. that.setData({groupIndex:0})
  2393. wx.setStorageSync('groupName', that.data.groupName[that.data.groupIndex])
  2394. }
  2395. //获取设备下拉
  2396. var device = []
  2397. var groupName = that.data.groupName
  2398. var groupIndex = that.data.groupIndex
  2399. for (let j = 0; j < group.length; j++) {
  2400. if (groupName[groupIndex] == group[j].groupName) {
  2401. if (group[j].devices != null && group[j].devices.length != 0) {
  2402. for (let p = 0; p < group[j].devices.length; p++) {
  2403. device.push(group[j].devices[p].deviceName)
  2404. }
  2405. that.setData({
  2406. deviceName: device
  2407. })
  2408. //改变设备下标
  2409. if (wx.getStorageSync('deviceName') != '') {
  2410. var DeviceName = that.data.deviceName
  2411. for (let m = 0; m < DeviceName.length; m++) {
  2412. if (DeviceName[m] == wx.getStorageSync('deviceName')) {
  2413. that.setData({
  2414. deviceIndex: m
  2415. })
  2416. }
  2417. }
  2418. } else {
  2419. that.setData({deviceIndex:0})
  2420. wx.setStorageSync('deviceName', that.data.deviceName[that.data.deviceIndex])
  2421. }
  2422. //根据分组名和设备信息
  2423. var groupNames = that.data.groupName[that.data.groupIndex]
  2424. var deviceNames = that.data.deviceName[that.data.deviceIndex]
  2425. for (let d = 0; d < group.length; d++) {
  2426. if (groupNames == group[d].groupName) {
  2427. var Groupno = group[d].id //分组id
  2428. for (let g = 0; g < group[d].devices.length; g++) {
  2429. if (deviceNames == group[d].devices[g].deviceName) {
  2430. //旧设备信息
  2431. if (group[d].devices[g].module == 0) {
  2432. var id = group[d].devices[g].id //设备的序号
  2433. var circuitNum = group[d].devices[g].circuitNum
  2434. var circuits = group[d].devices[g].circuits
  2435. var deviceId = group[d].devices[g].deviceId
  2436. var deviceKey = group[d].devices[g].deviceKey
  2437. var moudule = group[d].devices[g].module
  2438. that.setData({
  2439. play: 0
  2440. })
  2441. }
  2442. //新设备信息
  2443. else {
  2444. var circuitNum = group[d].devices[g].circuitNum
  2445. var circuits = group[d].devices[g].circuits
  2446. var moudule = group[d].devices[g].module
  2447. var id = group[d].devices[g].id //设备的序号
  2448. var deviceID = group[d].devices[g].deviceId//设备ID
  2449. that.setData({
  2450. play: 1,
  2451. ID:deviceID
  2452. })
  2453. }
  2454. }
  2455. }
  2456. }
  2457. }
  2458. //用于区分两种设备以及记录回路数量
  2459. that.setData({
  2460. moudule: moudule,
  2461. id: id,
  2462. loops: circuitNum,
  2463. Groupno:Groupno
  2464. })
  2465. //灯泡图标缓存
  2466. wx.setStorageSync('lamp', [])
  2467. var lamp = wx.getStorageSync('lamp')
  2468. for (let h = 0; h < 12; h++) {
  2469. lamp.push("https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png")
  2470. }
  2471. //旧设备
  2472. if (moudule == 0) {
  2473. //重置状态
  2474. let combination = control.Refresh()
  2475. that.setData({
  2476. loop: combination[0],
  2477. address: combination[1],
  2478. lamp: combination[2],
  2479. size: combination[3],
  2480. Color: combination[4]
  2481. })
  2482. //..............................
  2483. that.setData({
  2484. deviceId: deviceId,
  2485. deviceKey: deviceKey
  2486. })
  2487. var Circuits = circuits.split(',')
  2488. let loop = that.data.loop
  2489. for (let vr = 0; vr < circuitNum; vr++) {
  2490. loop[vr] = Circuits[vr]
  2491. }
  2492. that.setData({
  2493. loop: loop
  2494. })
  2495. postData(deviceId, deviceKey, {
  2496. "Reflash": 3
  2497. }).then(res => {
  2498. if(res.data.errno == 0 || res.data.errno == 10){
  2499. setTimeout(function () {
  2500. getBasic(deviceId, deviceKey).then(ever => {
  2501. if(ever.data.errno == 0){
  2502. if (ever.data.data.online == true) {
  2503. that.setData({
  2504. status: "在线"
  2505. })
  2506. } else {
  2507. that.setData({
  2508. status: "离线"
  2509. })
  2510. }
  2511. }
  2512. else{
  2513. wx.showModal({
  2514. title: '错误',
  2515. content: ever.data.error,
  2516. showCancel:false
  2517. })
  2518. }
  2519. getData(deviceId, deviceKey).then(ver => {
  2520. if (ver.data.errno == 0) {
  2521. let data = ver.data.data
  2522. for (let i = 0; i < data.length; i++) {
  2523. if (data[i].id == "RelayCount") {
  2524. var quantity = data[i].current_value
  2525. that.setData({
  2526. loops: quantity
  2527. })
  2528. } else if (data[i].id == "ManualStatus") {
  2529. if (data[i].current_value == 0) {
  2530. that.setData({
  2531. Modecontrol: "自动"
  2532. })
  2533. } else {
  2534. that.setData({
  2535. Modecontrol: "手动"
  2536. })
  2537. }
  2538. }
  2539. //回路1
  2540. else if (data[i].id == 'R1_RelayStatus') {
  2541. let police = data[i].current_value
  2542. var lamps = control.switchReal(police, lamp, 0)
  2543. } else if (data[i].id == 'R2_RelayStatus') {
  2544. let police = data[i].current_value
  2545. var lamps = control.switchReal(police, lamp, 1)
  2546. } else if (data[i].id == 'R3_RelayStatus') {
  2547. let police = data[i].current_value
  2548. var lamps = control.switchReal(police, lamp, 2)
  2549. } else if (data[i].id == 'R4_RelayStatus') {
  2550. let police = data[i].current_value
  2551. var lamps = control.switchReal(police, lamp, 3)
  2552. } else if (data[i].id == 'R5_RelayStatus') {
  2553. let police = data[i].current_value
  2554. var lamps = control.switchReal(police, lamp, 4)
  2555. } else if (data[i].id == 'R6_RelayStatus') {
  2556. let police = data[i].current_value
  2557. var lamps = control.switchReal(police, lamp, 5)
  2558. } else if (data[i].id == 'R7_RelayStatus') {
  2559. let police = data[i].current_value
  2560. var lamps = control.switchReal(police, lamp, 6)
  2561. } else if (data[i].id == 'R8_RelayStatus') {
  2562. let police = data[i].current_value
  2563. var lamps = control.switchReal(police, lamp, 7)
  2564. } else if (data[i].id == 'R9_RelayStatus') {
  2565. let police = data[i].current_value
  2566. var lamps = control.switchReal(police, lamp, 8)
  2567. } else if (data[i].id == 'R10_RelayStatus') {
  2568. let police = data[i].current_value
  2569. var lamps = control.switchReal(police, lamp, 9)
  2570. } else if (data[i].id == 'R11_RelayStatus') {
  2571. let police = data[i].current_value
  2572. var lamps = control.switchReal(police, lamp, 10)
  2573. } else if (data[i].id == 'R12_RelayStatus') {
  2574. let police = data[i].current_value
  2575. var lamps = control.switchReal(police, lamp, 11)
  2576. }
  2577. wx.setStorageSync('lamp', lamps)
  2578. that.setData({
  2579. lamp: wx.getStorageSync('lamp')
  2580. })
  2581. }
  2582. var Loop = that.data.Loop
  2583. var color = that.data.Color
  2584. var size = that.data.Size
  2585. var Address = that.data.address
  2586. var enloop = that.data.loop
  2587. for (let i = 0; i < quantity; i++) {
  2588. Loop[i] = enloop[i]
  2589. color[i] = "black"
  2590. size[i] = "calc(100vw * 16/375)",
  2591. Address[i] = "/image/modify.png"
  2592. }
  2593. that.setData({
  2594. Color: color,
  2595. Size: size,
  2596. address: Address,
  2597. Loop: Loop
  2598. })
  2599. } else {
  2600. wx.showModal({
  2601. title: '错误',
  2602. content: ver.data.error,
  2603. showCancel: false
  2604. })
  2605. }
  2606. })
  2607. })
  2608. }, 2000)
  2609. }
  2610. else{
  2611. setTimeout(function(){
  2612. wx.showModal({
  2613. title: '提示',
  2614. content: res.data.error,
  2615. showCancel:false
  2616. })
  2617. },2000)
  2618. }
  2619. })
  2620. }
  2621. //新设备
  2622. else {
  2623. //重置状态
  2624. let combination = control.Refresh()
  2625. that.setData({
  2626. loop: combination[0],
  2627. address: combination[1],
  2628. lamp: combination[2],
  2629. size: combination[3],
  2630. Color: combination[4]
  2631. })
  2632. //..............................
  2633. //获取设备在线状态
  2634. getDevice(id, Groupno).then(dve => {
  2635. if (dve.data.code == 0) {
  2636. var state = dve.data.data
  2637. switch (state.status) {
  2638. case 0:
  2639. that.setData({
  2640. status: '离线'
  2641. })
  2642. break;
  2643. case 1:
  2644. that.setData({
  2645. status: '在线'
  2646. })
  2647. break;
  2648. }
  2649. } else {
  2650. wx.showModal({
  2651. title: '错误',
  2652. content: dve.data.msg,
  2653. showCancel: false
  2654. })
  2655. }
  2656. })
  2657. var Circuits = circuits.split(',')
  2658. let loop = that.data.loop
  2659. for (let vr = 0; vr < circuitNum; vr++) {
  2660. loop[vr] = Circuits[vr]
  2661. }
  2662. that.setData({
  2663. loop: loop
  2664. })
  2665. getloop(id).then(res => {
  2666. if (res.data.code == 0) {
  2667. let loopState = res.data.data
  2668. //loopState.length可以视为回路数量
  2669. var Loop = that.data.Loop
  2670. var color = that.data.Color
  2671. var size = that.data.Size
  2672. var Address = that.data.address
  2673. for (let n = 0; n < loopState.length; n++) {
  2674. Loop[n] = that.data.Loop[n]
  2675. color[n] = "black"
  2676. size[n] = "calc(100vw * 16/375)",
  2677. Address[n] = "/image/modify.png"
  2678. }
  2679. that.setData({
  2680. Color: color,
  2681. Size: size,
  2682. address: Address,
  2683. Loop: Loop
  2684. })
  2685. } else {
  2686. wx.showModal({
  2687. title: '错误',
  2688. content: res.data.msg,
  2689. showCancel: false
  2690. })
  2691. }
  2692. })
  2693. loopSwitchstate(id).then(ret => {
  2694. if (ret.data.code == 0) {
  2695. var relay = ret.data.data
  2696. for (let e = 0; e < relay.length; e++) {
  2697. if (relay[e].status == 1) {
  2698. lamp[e] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp1.png'
  2699. } else if (relay[e].status == 0) {
  2700. lamp[e] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
  2701. } else {
  2702. lamp[e] = 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png'
  2703. }
  2704. }
  2705. } else {
  2706. wx.showModal({
  2707. title: '错误',
  2708. content: ret.data.msg,
  2709. showCancel: false
  2710. })
  2711. }
  2712. })
  2713. setTimeout(function () {
  2714. wx.setStorageSync('lamp', lamp)
  2715. that.setData({
  2716. lamp: wx.getStorageSync('lamp')
  2717. })
  2718. }, 2000)
  2719. }
  2720. } else {
  2721. that.setData({
  2722. status: '离线',
  2723. deviceName: []
  2724. })
  2725. }
  2726. }
  2727. }
  2728. } else {
  2729. that.setData({
  2730. status:'离线',
  2731. deviceName: [],
  2732. groupName: []
  2733. })
  2734. }
  2735. },
  2736. /**
  2737. * 生命周期函数--监听页面隐藏
  2738. */
  2739. onHide() {
  2740. },
  2741. /**
  2742. * 生命周期函数--监听页面卸载
  2743. */
  2744. onUnload() {
  2745. },
  2746. /**
  2747. * 页面相关事件处理函数--监听用户下拉动作
  2748. */
  2749. onPullDownRefresh() {
  2750. },
  2751. /**
  2752. * 页面上拉触底事件的处理函数
  2753. */
  2754. onReachBottom() {
  2755. },
  2756. /**
  2757. * 用户点击右上角分享
  2758. */
  2759. onShareAppMessage() {
  2760. }
  2761. })