control.js 86 KB

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