control.js 83 KB

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