loop.js 94 KB

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