loop.js 97 KB

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