loop.js 104 KB

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