system.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  1. // pages/system/system.js
  2. const {
  3. getBasic,
  4. getData,
  5. postData
  6. } = require('../../api/intell')
  7. const {
  8. getDevice
  9. } = require('../../api/device')
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. dates: "", //日期
  16. times: "", //时间
  17. Illuminance: "", //光照度
  18. Firealarmtext: "", //消防报警文字
  19. Firealarmcolor: "", //消防报警颜色
  20. longitude: "", //经度
  21. latitude: "", //纬度
  22. Sunrisetime: "", //日出时间
  23. Sunsettime: "", //日落时间
  24. array: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
  25. '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'
  26. ], //开关延时
  27. index: 0,
  28. switchtime: 0,
  29. multiItems: [
  30. [],
  31. []
  32. ], //经度显示
  33. multiIndex: [0, 0],
  34. multiItems2: [
  35. [],
  36. []
  37. ], //纬度显示
  38. multiIndex2: [0, 0],
  39. Title: "",
  40. statu: "false",
  41. status: "离线",
  42. loops: "", //记录回路数量
  43. Storage: [], //储存发送数据
  44. Modecontrol: "",
  45. groupName: [],
  46. deviceName: [],
  47. groupIndex: 0,
  48. deviceIndex: 0,
  49. deviceId: '',
  50. deviceKey: '',
  51. play: 0,
  52. },
  53. //开关延时
  54. bindPickerChange: function(e) {
  55. this.setData({
  56. index: e.detail.value,
  57. })
  58. },
  59. //分组下拉
  60. changegroup: function(e) {
  61. wx.showToast({
  62. title: '刷新中',
  63. icon: 'loading',
  64. duration: 2000
  65. })
  66. var that = this
  67. that.setData({
  68. groupIndex: e.detail.value
  69. })
  70. wx.setStorageSync('groupIndex', e.detail.value)
  71. var groupNames = that.data.groupName[that.data.groupIndex] //选择的分组名称
  72. wx.setStorageSync('groupName', groupNames) //将修改的分组名称放入缓存
  73. //获取设备名称下拉
  74. var group = wx.getStorageSync('group')
  75. var deviceName = that.data.deviceName
  76. var deviceName = []
  77. for (let i = 0; i < group.length; i++) {
  78. if (group[i].groupName == groupNames) {
  79. if (group[i].devices != null && group[i].devices.length != 0) {
  80. for (let j = 0; j < group[i].devices.length; j++) {
  81. deviceName.push(group[i].devices[j].deviceName)
  82. }
  83. that.setData({
  84. deviceName: deviceName,
  85. deviceIndex: 0
  86. })
  87. var deviceNames = that.data.deviceName[that.data.deviceIndex]
  88. wx.setStorageSync('deviceName', deviceNames)
  89. for (let d = 0; d < group.length; d++) {
  90. if (groupNames == group[d].groupName) {
  91. var Group = group[d].id
  92. for (let g = 0; g < group[d].devices.length; g++) {
  93. if (deviceNames == group[d].devices[g].deviceName) {
  94. if (group[d].devices[g].module == 0) {
  95. that.setData({
  96. play: 0
  97. })
  98. var moudule = group[d].devices[g].module
  99. var deviceId = group[d].devices[g].deviceId
  100. var deviceKey = group[d].devices[g].deviceKey
  101. } else {
  102. that.setData({
  103. play: 1
  104. })
  105. var moudule = group[d].devices[g].module
  106. var Device = group[d].devices[g].id
  107. }
  108. }
  109. }
  110. }
  111. }
  112. if (moudule == 0) {
  113. that.setData({
  114. deviceId: deviceId,
  115. deviceKey: deviceKey
  116. })
  117. getBasic(deviceId, deviceKey).then(res => {
  118. if (res.data.errno == 0) {
  119. if (res.data.data.online == true) {
  120. that.setData({
  121. status: "在线"
  122. })
  123. } else {
  124. that.setData({
  125. status: "离线"
  126. })
  127. }
  128. } else {
  129. wx.showModal({
  130. title: '错误',
  131. content: res.data.error,
  132. showCancel: false
  133. })
  134. }
  135. })
  136. getData(deviceId, deviceKey).then(res => {
  137. if (res.data.errno == 0) {
  138. let {
  139. data
  140. } = res.data
  141. for (let i = 0; i < data.length; i++) {
  142. //时间
  143. if (data[i].id == "SysTime") {
  144. var times = data[i].current_value
  145. } else if (data[i].id == "RelayCount") {
  146. var quantity = data[i].current_value
  147. that.setData({
  148. loops: quantity
  149. })
  150. }
  151. //日期
  152. else if (data[i].id == "SysDate") {
  153. var dates = data[i].current_value
  154. }
  155. //光照度
  156. else if (data[i].id == "lightLuxValue") {
  157. var Illuminance = data[i].current_value
  158. }
  159. //日出时间
  160. else if (data[i].id == "RiseTime") {
  161. var Sunrisetime = data[i].current_value
  162. }
  163. //日落时间
  164. else if (data[i].id == "SetTime") {
  165. var Sunsettime = data[i].current_value
  166. }
  167. //经度
  168. else if (data[i].id == "Longitude") {
  169. var longitude = data[i].current_value
  170. }
  171. //纬度
  172. else if (data[i].id == "Latitude") {
  173. var latitude = data[i].current_value
  174. }
  175. //消防报警
  176. else if (data[i].id == "AlarmState") {
  177. var Firealarm = data[i].current_value
  178. }
  179. //回路数量
  180. else if (data[i].id == "RelayCount") {
  181. var loops = data[i].current_value
  182. }
  183. //开关延时
  184. else if (data[i].id == "DeviceID") {
  185. var device = data[i].current_value
  186. that.setData({
  187. index: device,
  188. switchtime: device
  189. })
  190. }
  191. }
  192. //时间
  193. if (times.length == 5) {
  194. var a = "0" + times.substring(0, 1) + ':' + times.substring(1,
  195. 3) + ':' + times.substring(3, 5)
  196. } else if (times.length == 6) {
  197. var a = times.substring(0, 2) + ':' + times.substring(2, 4) +
  198. ':' + times.substring(4, 6)
  199. } else {
  200. a = times
  201. }
  202. //日期
  203. var b = '20' + dates.substring(0, 2) + '-' + dates.substring(2, 4) +
  204. '-' + dates.substring(4, 6)
  205. //日出时间
  206. var c = Sunrisetime.substring(0, 1) + ':' + Sunrisetime.substring(1,
  207. 3)
  208. //日落时间
  209. var d = Sunsettime.substring(0, 2) + ':' + Sunsettime.substring(2,
  210. 4)
  211. //经度
  212. var multiIndex = that.data.multiIndex
  213. if (longitude.length == 5) {
  214. var e = longitude.substring(0, 3) + "," + longitude.substring(3,
  215. 5) + "'"
  216. multiIndex[0] = parseInt(longitude.substring(0, 3))
  217. multiIndex[1] = parseInt(longitude.substring(3, 5))
  218. that.setData({
  219. multiIndex: multiIndex
  220. })
  221. } else if (longitude.length == 4) {
  222. var e = longitude.substring(0, 2) + "," + longitude.substring(2,
  223. 4) + "'"
  224. multiIndex[0] = parseInt(longitude.substring(0, 2))
  225. multiIndex[1] = parseInt(longitude.substring(2, 4))
  226. that.setData({
  227. multiIndex: multiIndex
  228. })
  229. } else if (longitude.length == 3) {
  230. var e = longitude.substring(0, 1) + "," + longitude.substring(1,
  231. 3) + "'"
  232. multiIndex[0] = parseInt(longitude.substring(0, 1))
  233. multiIndex[1] = parseInt(longitude.substring(1, 3))
  234. that.setData({
  235. multiIndex: multiIndex
  236. })
  237. } else if (longitude.length == 2) {
  238. var e = 0 + "," + longitude.substring(0, 2) + "'"
  239. multiIndex[0] = 0
  240. multiIndex[1] = parseInt(longitude.substring(0, 2))
  241. that.setData({
  242. multiIndex: multiIndex
  243. })
  244. } else {
  245. var e = 0 + "," + longitude.substring(0, 1) + "'"
  246. multiIndex[0] = 0
  247. multiIndex[1] = parseInt(longitude.substring(0, 1))
  248. that.setData({
  249. multiIndex: multiIndex
  250. })
  251. }
  252. //纬度
  253. var multiIndex2 = that.data.multiIndex2
  254. if (latitude.length == 5) {
  255. var f = latitude.substring(0, 3) + "," + latitude.substring(3,
  256. 5) + "'"
  257. multiIndex2[0] = parseInt(latitude.substring(0, 3))
  258. multiIndex2[1] = parseInt(latitude.substring(3, 5))
  259. that.setData({
  260. multiIndex2: multiIndex2
  261. })
  262. } else if (latitude.length == 4) {
  263. var f = latitude.substring(0, 2) + "," + latitude.substring(2,
  264. 4) + "'"
  265. multiIndex2[0] = parseInt(latitude.substring(0, 2))
  266. multiIndex2[1] = parseInt(latitude.substring(2, 4))
  267. that.setData({
  268. multiIndex2: multiIndex2
  269. })
  270. } else if (latitude.length == 3) {
  271. var f = latitude.substring(0, 1) + "," + latitude.substring(1,
  272. 3) + "'"
  273. multiIndex2[0] = parseInt(latitude.substring(0, 1))
  274. multiIndex2[1] = parseInt(latitude.substring(1, 3))
  275. that.setData({
  276. multiIndex2: multiIndex2
  277. })
  278. } else if (latitude.length == 2) {
  279. var f = 0 + "," + latitude.substring(0, 2) + "'"
  280. multiIndex2[0] = 0
  281. multiIndex2[1] = parseInt(latitude.substring(0, 2))
  282. that.setData({
  283. multiIndex2: multiIndex2
  284. })
  285. } else {
  286. var f = 0 + "," + latitude.substring(0, 1) + "'"
  287. multiIndex2[0] = 0
  288. multiIndex2[1] = parseInt(latitude.substring(0, 1))
  289. that.setData({
  290. multiIndex2: multiIndex2
  291. })
  292. }
  293. //光照度
  294. var g = Illuminance
  295. //消防报警
  296. if (Firealarm == "0") {
  297. that.setData({
  298. Firealarmtext: "正常",
  299. Firealarmcolor: "#5cfe03"
  300. })
  301. } else {
  302. that.setData({
  303. Firealarmtext: "异常",
  304. Firealarmcolor: "red"
  305. })
  306. }
  307. that.setData({
  308. times: a,
  309. dates: b,
  310. Sunrisetime: c,
  311. Sunsettime: d,
  312. longitude: e,
  313. latitude: f,
  314. Illuminance: g,
  315. loops: loops,
  316. })
  317. } else {
  318. wx.showModal({
  319. title: '错误',
  320. content: res.data.error,
  321. showCancel: false
  322. })
  323. }
  324. })
  325. postData(deviceId, deviceKey, {
  326. "Reflash": 4
  327. }).then(res => {
  328. if (res.data.errno == 0) {
  329. setTimeout(function() {
  330. getData(that.data.deviceId, that.data.deviceKey).then(
  331. ever => {
  332. if (ever.data.errno == 0) {
  333. let {
  334. data
  335. } = ever.data
  336. for (let i = 0; i < data.length; i++) {
  337. //时间
  338. if (data[i].id == "SysTime") {
  339. var times = data[i]
  340. .current_value
  341. }
  342. //日期
  343. else if (data[i].id == "SysDate") {
  344. var dates = data[i]
  345. .current_value
  346. }
  347. }
  348. if (times.length == 5) {
  349. var a = "0" + times.substring(0,
  350. 1) + ':' + times.substring(1,
  351. 3) + ':' + times.substring(3, 5)
  352. } else if (times.length == 6) {
  353. var a = times.substring(0, 2) +
  354. ':' + times.substring(2, 4) +
  355. ':' + times.substring(4, 6)
  356. } else {
  357. a = times
  358. }
  359. //日期
  360. var b = '20' + dates.substring(0, 2) +
  361. '-' + dates.substring(2, 4) + '-' +
  362. dates.substring(4, 6)
  363. that.setData({
  364. times: a,
  365. dates: b
  366. })
  367. } else {
  368. wx.showModal({
  369. title: '错误',
  370. content: ever.data.error,
  371. showCancel: false
  372. })
  373. }
  374. })
  375. }, 2000)
  376. } else if (res.data.errno == 10) {
  377. setTimeout(function() {
  378. wx.showModal({
  379. title: '错误',
  380. content: '获取时间数据失败,请检查设备是否在线,或者刷新页面',
  381. showCancel: false
  382. })
  383. }, 2000)
  384. } else {
  385. setTimeout(function() {
  386. wx.showModal({
  387. title: '错误',
  388. content: res.data.error,
  389. showCancel: false
  390. })
  391. }, 2000)
  392. }
  393. })
  394. } else {
  395. getDevice(Device, Group).then(res => {
  396. if (res.data.code == 0) {
  397. if (res.data.data.status == 1) {
  398. that.setData({
  399. status: "在线"
  400. })
  401. } else {
  402. that.setData({
  403. status: "离线"
  404. })
  405. }
  406. var loops = res.data.data
  407. var myDate = new Date();
  408. //年
  409. var year = myDate.getFullYear().toString()
  410. year = year.slice(2, 4)
  411. //月
  412. var month = myDate.getMonth() + 1
  413. month = month.toString()
  414. if (month.length == 1) {
  415. month = '0' + month
  416. }
  417. //日
  418. var date = myDate.getDate()
  419. date = date.toString()
  420. if (date.length == 1) {
  421. date = '0' + date
  422. }
  423. //小时
  424. var hour = myDate.getHours()
  425. hour = hour.toString()
  426. if (hour.length == 1) {
  427. hour = '0' + hour
  428. }
  429. //分钟
  430. var minutes = myDate.getMinutes()
  431. minutes = minutes.toString()
  432. if (minutes.length == 1) {
  433. minutes = '0' + minutes
  434. }
  435. //秒
  436. var seconds = myDate.getSeconds()
  437. seconds = seconds.toString()
  438. if (seconds.length == 1) {
  439. seconds = '0' + seconds
  440. }
  441. var datas = '20' + year + '-' + month + '-' + date
  442. var time = hour + ':' + minutes + ':' + seconds
  443. that.setData({
  444. loops: loops.circuitNum,
  445. dates: datas,
  446. times: time
  447. })
  448. } else {
  449. wx.showModal({
  450. title: '错误',
  451. content: dve.data.msg,
  452. showCancel: false
  453. })
  454. }
  455. })
  456. }
  457. } else {
  458. that.setData({
  459. status: '离线',
  460. deviceName: []
  461. })
  462. wx.setStorageSync('deviceName', '') //清空设备名称缓存
  463. }
  464. }
  465. }
  466. },
  467. //设备下拉
  468. changedevice: function(e) {
  469. var that = this
  470. wx.showToast({
  471. title: '刷新中',
  472. icon: 'loading',
  473. duration: 2000
  474. })
  475. that.setData({
  476. deviceIndex: e.detail.value
  477. })
  478. var group = wx.getStorageSync('group')
  479. var groupNames = that.data.groupName[that.data.groupIndex]
  480. var deviceNames = that.data.deviceName[that.data.deviceIndex]
  481. wx.setStorageSync('groupName', groupNames) //分组名称
  482. wx.setStorageSync('deviceName', deviceNames) //设备名称
  483. //根据分组名和设备名获取信息
  484. for (let d = 0; d < group.length; d++) {
  485. if (groupNames == group[d].groupName) {
  486. var Group = group[d].id
  487. for (let g = 0; g < group[d].devices.length; g++) {
  488. if (deviceNames == group[d].devices[g].deviceName) {
  489. if (group[d].devices[g].module == 0) {
  490. that.setData({
  491. play: 0
  492. })
  493. var moudule = group[d].devices[g].module
  494. var deviceId = group[d].devices[g].deviceId
  495. var deviceKey = group[d].devices[g].deviceKey
  496. } else {
  497. that.setData({
  498. play: 1
  499. })
  500. var moudule = group[d].devices[g].module
  501. var Device = group[d].devices[g].id
  502. }
  503. }
  504. }
  505. }
  506. }
  507. if (moudule == 0) {
  508. that.setData({
  509. deviceId: deviceId,
  510. deviceKey: deviceKey
  511. })
  512. getBasic(deviceId, deviceKey).then(res => {
  513. if (res.data.errno == 0) {
  514. if (res.data.data.online == true) {
  515. that.setData({
  516. status: "在线"
  517. })
  518. } else {
  519. that.setData({
  520. status: "离线"
  521. })
  522. }
  523. } else {
  524. wx.showModal({
  525. title: '错误',
  526. content: res.data.error,
  527. showCancel: false
  528. })
  529. }
  530. })
  531. getData(deviceId, deviceKey).then(res => {
  532. if (res.data.errno == 0) {
  533. let {
  534. data
  535. } = res.data
  536. for (let i = 0; i < data.length; i++) {
  537. //时间
  538. if (data[i].id == "SysTime") {
  539. var times = data[i].current_value
  540. } else if (data[i].id == "RelayCount") {
  541. var quantity = data[i].current_value
  542. that.setData({
  543. loops: quantity
  544. })
  545. }
  546. //日期
  547. else if (data[i].id == "SysDate") {
  548. var dates = data[i].current_value
  549. }
  550. //光照度
  551. else if (data[i].id == "lightLuxValue") {
  552. var Illuminance = data[i].current_value
  553. }
  554. //日出时间
  555. else if (data[i].id == "RiseTime") {
  556. var Sunrisetime = data[i].current_value
  557. }
  558. //日落时间
  559. else if (data[i].id == "SetTime") {
  560. var Sunsettime = data[i].current_value
  561. }
  562. //经度
  563. else if (data[i].id == "Longitude") {
  564. var longitude = data[i].current_value
  565. }
  566. //纬度
  567. else if (data[i].id == "Latitude") {
  568. var latitude = data[i].current_value
  569. }
  570. //消防报警
  571. else if (data[i].id == "AlarmState") {
  572. var Firealarm = data[i].current_value
  573. }
  574. //回路数量
  575. else if (data[i].id == "RelayCount") {
  576. var loops = data[i].current_value
  577. }
  578. //开关延时
  579. else if (data[i].id == "DeviceID") {
  580. var device = data[i].current_value
  581. that.setData({
  582. index: device,
  583. switchtime: device
  584. })
  585. }
  586. }
  587. //时间
  588. if (times.length == 5) {
  589. var a = "0" + times.substring(0, 1) + ':' + times.substring(1, 3) + ':' +
  590. times.substring(3, 5)
  591. } else if (times.length == 6) {
  592. var a = times.substring(0, 2) + ':' + times.substring(2, 4) + ':' + times
  593. .substring(4, 6)
  594. } else {
  595. a = times
  596. }
  597. //日期
  598. var b = '20' + dates.substring(0, 2) + '-' + dates.substring(2, 4) + '-' + dates
  599. .substring(4, 6)
  600. //日出时间
  601. var c = Sunrisetime.substring(0, 1) + ':' + Sunrisetime.substring(1, 3)
  602. //日落时间
  603. var d = Sunsettime.substring(0, 2) + ':' + Sunsettime.substring(2, 4)
  604. //经度
  605. var multiIndex = that.data.multiIndex
  606. if (longitude.length == 5) {
  607. var e = longitude.substring(0, 3) + "," + longitude.substring(3, 5) + "'"
  608. multiIndex[0] = parseInt(longitude.substring(0, 3))
  609. multiIndex[1] = parseInt(longitude.substring(3, 5))
  610. that.setData({
  611. multiIndex: multiIndex
  612. })
  613. } else if (longitude.length == 4) {
  614. var e = longitude.substring(0, 2) + "," + longitude.substring(2, 4) + "'"
  615. multiIndex[0] = parseInt(longitude.substring(0, 2))
  616. multiIndex[1] = parseInt(longitude.substring(2, 4))
  617. that.setData({
  618. multiIndex: multiIndex
  619. })
  620. } else if (longitude.length == 3) {
  621. var e = longitude.substring(0, 1) + "," + longitude.substring(1, 3) + "'"
  622. multiIndex[0] = parseInt(longitude.substring(0, 1))
  623. multiIndex[1] = parseInt(longitude.substring(1, 3))
  624. that.setData({
  625. multiIndex: multiIndex
  626. })
  627. } else if (longitude.length == 2) {
  628. var e = 0 + "," + longitude.substring(0, 2) + "'"
  629. multiIndex[0] = 0
  630. multiIndex[1] = parseInt(longitude.substring(0, 2))
  631. that.setData({
  632. multiIndex: multiIndex
  633. })
  634. } else {
  635. var e = 0 + "," + longitude.substring(0, 1) + "'"
  636. multiIndex[0] = 0
  637. multiIndex[1] = parseInt(longitude.substring(0, 1))
  638. that.setData({
  639. multiIndex: multiIndex
  640. })
  641. }
  642. //纬度
  643. var multiIndex2 = that.data.multiIndex2
  644. if (latitude.length == 5) {
  645. var f = latitude.substring(0, 3) + "," + latitude.substring(3, 5) + "'"
  646. multiIndex2[0] = parseInt(latitude.substring(0, 3))
  647. multiIndex2[1] = parseInt(latitude.substring(3, 5))
  648. that.setData({
  649. multiIndex2: multiIndex2
  650. })
  651. } else if (latitude.length == 4) {
  652. var f = latitude.substring(0, 2) + "," + latitude.substring(2, 4) + "'"
  653. multiIndex2[0] = parseInt(latitude.substring(0, 2))
  654. multiIndex2[1] = parseInt(latitude.substring(2, 4))
  655. that.setData({
  656. multiIndex2: multiIndex2
  657. })
  658. } else if (latitude.length == 3) {
  659. var f = latitude.substring(0, 1) + "," + latitude.substring(1, 3) + "'"
  660. multiIndex2[0] = parseInt(latitude.substring(0, 1))
  661. multiIndex2[1] = parseInt(latitude.substring(1, 3))
  662. that.setData({
  663. multiIndex2: multiIndex2
  664. })
  665. } else if (latitude.length == 2) {
  666. var f = 0 + "," + latitude.substring(0, 2) + "'"
  667. multiIndex2[0] = 0
  668. multiIndex2[1] = parseInt(latitude.substring(0, 2))
  669. that.setData({
  670. multiIndex2: multiIndex2
  671. })
  672. } else {
  673. var f = 0 + "," + latitude.substring(0, 1) + "'"
  674. multiIndex2[0] = 0
  675. multiIndex2[1] = parseInt(latitude.substring(0, 1))
  676. that.setData({
  677. multiIndex2: multiIndex2
  678. })
  679. }
  680. //光照度
  681. var g = Illuminance
  682. //消防报警
  683. if (Firealarm == "0") {
  684. that.setData({
  685. Firealarmtext: "正常",
  686. Firealarmcolor: "#5cfe03"
  687. })
  688. } else {
  689. that.setData({
  690. Firealarmtext: "异常",
  691. Firealarmcolor: "red"
  692. })
  693. }
  694. that.setData({
  695. times: a,
  696. dates: b,
  697. Sunrisetime: c,
  698. Sunsettime: d,
  699. longitude: e,
  700. latitude: f,
  701. Illuminance: g,
  702. loops: loops,
  703. })
  704. } else {
  705. wx.showModal({
  706. title: '错误',
  707. content: res.data.error,
  708. showCancel: false
  709. })
  710. }
  711. })
  712. postData(deviceId, deviceKey, {
  713. "Reflash": 4
  714. }).then(res => {
  715. if (res.data.errno == 0) {
  716. setTimeout(function() {
  717. getData(that.data.deviceId, that.data.deviceKey).then(ever => {
  718. if (ever.data.errno == 0) {
  719. let {
  720. data
  721. } = ever.data
  722. for (let i = 0; i < data.length; i++) {
  723. //时间
  724. if (data[i].id == "SysTime") {
  725. var times = data[i].current_value
  726. }
  727. //日期
  728. else if (data[i].id == "SysDate") {
  729. var dates = data[i].current_value
  730. }
  731. }
  732. if (times.length == 5) {
  733. var a = "0" + times.substring(0, 1) + ':' +
  734. times.substring(1, 3) + ':' + times
  735. .substring(3, 5)
  736. } else if (times.length == 6) {
  737. var a = times.substring(0, 2) + ':' + times
  738. .substring(2, 4) + ':' + times.substring(4,
  739. 6)
  740. } else {
  741. a = times
  742. }
  743. //日期
  744. var b = '20' + dates.substring(0, 2) + '-' + dates
  745. .substring(2, 4) + '-' + dates.substring(4, 6)
  746. that.setData({
  747. times: a,
  748. dates: b
  749. })
  750. } else {
  751. wx.showModal({
  752. title: '错误',
  753. content: ever.data.error,
  754. showCancel: false
  755. })
  756. }
  757. })
  758. }, 2000)
  759. } else if (res.data.errno == 10) {
  760. setTimeout(function() {
  761. wx.showModal({
  762. title: '错误',
  763. content: '获取时间数据失败,请检查设备是否在线,或者刷新页面',
  764. showCancel: false
  765. })
  766. }, 2000)
  767. } else {
  768. setTimeout(function() {
  769. wx.showModal({
  770. title: '错误',
  771. content: res.data.error,
  772. showCancel: false
  773. })
  774. }, 2000)
  775. }
  776. })
  777. } else {
  778. getDevice(Device, Group).then(res => {
  779. if (res.data.code == 0) {
  780. if (res.data.data.status == 1) {
  781. that.setData({
  782. status: "在线"
  783. })
  784. } else {
  785. that.setData({
  786. status: "离线"
  787. })
  788. }
  789. var loops = res.data.data
  790. var myDate = new Date();
  791. //年
  792. var year = myDate.getFullYear().toString()
  793. year = year.slice(2, 4)
  794. //月
  795. var month = myDate.getMonth() + 1
  796. month = month.toString()
  797. if (month.length == 1) {
  798. month = '0' + month
  799. }
  800. //日
  801. var date = myDate.getDate()
  802. date = date.toString()
  803. if (date.length == 1) {
  804. date = '0' + date
  805. }
  806. //小时
  807. var hour = myDate.getHours()
  808. hour = hour.toString()
  809. if (hour.length == 1) {
  810. hour = '0' + hour
  811. }
  812. //分钟
  813. var minutes = myDate.getMinutes()
  814. minutes = minutes.toString()
  815. if (minutes.length == 1) {
  816. minutes = '0' + minutes
  817. }
  818. //秒
  819. var seconds = myDate.getSeconds()
  820. seconds = seconds.toString()
  821. if (seconds.length == 1) {
  822. seconds = '0' + seconds
  823. }
  824. var datas = '20' + year + '-' + month + '-' + date
  825. var time = hour + ':' + minutes + ':' + seconds
  826. that.setData({
  827. loops: loops.circuitNum,
  828. dates: datas,
  829. times: time
  830. })
  831. } else {
  832. wx.showModal({
  833. title: '错误',
  834. content: dve.data.msg,
  835. showCancel: false
  836. })
  837. }
  838. })
  839. }
  840. },
  841. //校准时间
  842. Calibrationtime: function() {
  843. var that = this
  844. var myDate = new Date();
  845. //年
  846. var year = myDate.getFullYear().toString()
  847. year = year.slice(2, 4)
  848. //月
  849. var month = myDate.getMonth() + 1
  850. month = month.toString()
  851. if (month.length == 1) {
  852. month = '0' + month
  853. }
  854. //日
  855. var date = myDate.getDate()
  856. date = date.toString()
  857. if (date.length == 1) {
  858. date = '0' + date
  859. }
  860. //小时
  861. var hour = myDate.getHours()
  862. hour = hour.toString()
  863. if (hour.length == 1) {
  864. hour = '0' + hour
  865. }
  866. //分钟
  867. var minutes = myDate.getMinutes()
  868. minutes = minutes.toString()
  869. if (minutes.length == 1) {
  870. minutes = '0' + minutes
  871. }
  872. //秒
  873. var seconds = myDate.getSeconds()
  874. seconds = seconds.toString()
  875. if (seconds.length == 1) {
  876. seconds = '0' + seconds
  877. }
  878. var play = that.data.play
  879. if (play == 0) {
  880. var datas = year + month + date
  881. datas = parseInt(datas)
  882. var time = hour + minutes + seconds
  883. time = parseInt(time)
  884. postData(that.data.deviceId, that.data.deviceKey, {
  885. "SysTime": time,
  886. "SysDate": datas,
  887. "Reflash": 4
  888. }).then(res => {
  889. if (res.data.errno == 0) {
  890. wx.showToast({
  891. title: '校准中',
  892. icon: 'loading',
  893. duration: 2000
  894. })
  895. setTimeout(function() {
  896. getData(that.data.deviceId, that.data.deviceKey).then(ever => {
  897. if (ever.data.errno == 0) {
  898. let {
  899. data
  900. } = ever.data
  901. for (let i = 0; i < data.length; i++) {
  902. //时间
  903. if (data[i].id == "SysTime") {
  904. var times = data[i].current_value
  905. }
  906. //日期
  907. else if (data[i].id == "SysDate") {
  908. var dates = data[i].current_value
  909. }
  910. }
  911. if (times.length == 5) {
  912. var a = "0" + times.substring(0, 1) + ':' +
  913. times.substring(1, 3) + ':' + times
  914. .substring(3, 5)
  915. } else if (times.length == 6) {
  916. var a = times.substring(0, 2) + ':' + times
  917. .substring(2, 4) + ':' + times.substring(4,
  918. 6)
  919. } else {
  920. a = times
  921. }
  922. //日期
  923. var b = '20' + dates.substring(0, 2) + '-' + dates
  924. .substring(2, 4) + '-' + dates.substring(4, 6)
  925. that.setData({
  926. times: a,
  927. dates: b
  928. })
  929. } else {
  930. wx.showModal({
  931. title: '错误',
  932. content: ever.data.error,
  933. showCancel: false
  934. })
  935. }
  936. })
  937. }, 2000)
  938. } else if (res.data.errno == 10) {
  939. wx.showModal({
  940. title: '错误',
  941. content: '校准失败,请检查设备是否处于在线状态,或者刷新页面',
  942. showCancel: false
  943. })
  944. } else {
  945. wx.showModal({
  946. title: '错误',
  947. content: 'res.data.error',
  948. showCancel: false
  949. })
  950. }
  951. })
  952. } else if (play == 1) {
  953. var datas = '20' + year + '-' + month + '-' + date
  954. var time = hour + ':' + minutes + ':' + seconds
  955. that.setData({
  956. dates: datas,
  957. times: time
  958. })
  959. }
  960. },
  961. //经度调整
  962. handleMulti(e) {
  963. this.setData({
  964. multiIndex: e.detail.value
  965. })
  966. },
  967. //纬度调整
  968. handleMulti2(e) {
  969. this.setData({
  970. multiIndex2: e.detail.value
  971. })
  972. },
  973. //刷新页面
  974. RefreshPage: function() {
  975. wx.showToast({
  976. title: '刷新中',
  977. icon: 'loading',
  978. duration: 2000
  979. })
  980. var that = this
  981. var group = wx.getStorageSync('group')
  982. if (group != null && group.length != 0) {
  983. //获取分组下拉
  984. var groups = []
  985. for (let i = 0; i < group.length; i++) {
  986. groups.push(group[i].groupName)
  987. }
  988. that.setData({
  989. groupName: groups
  990. })
  991. //改变分组下标
  992. if (wx.getStorageSync('groupName') != '') {
  993. let GroupName = that.data.groupName
  994. for (let n = 0; n < GroupName.length; n++) {
  995. if (GroupName[n] == wx.getStorageSync('groupName')) {
  996. that.setData({
  997. groupIndex: n
  998. })
  999. }
  1000. }
  1001. } else {
  1002. wx.setStorageSync('groupName', that.data.groupName[that.data.groupIndex])
  1003. }
  1004. //获取设备下拉
  1005. var groupName = that.data.groupName
  1006. var groupIndex = that.data.groupIndex
  1007. var device = []
  1008. for (let j = 0; j < group.length; j++) {
  1009. if (groupName[groupIndex] == group[j].groupName) {
  1010. if (group[j].devices != null && group[j].devices.length != 0) {
  1011. for (let p = 0; p < group[j].devices.length; p++) {
  1012. device.push(group[j].devices[p].deviceName)
  1013. }
  1014. that.setData({
  1015. deviceName: device
  1016. })
  1017. if (wx.getStorageSync('deviceName') != '') {
  1018. var DeviceName = that.data.deviceName
  1019. for (let m = 0; m < DeviceName.length; m++) {
  1020. if (DeviceName[m] == wx.getStorageSync('deviceName')) {
  1021. that.setData({
  1022. deviceIndex: m
  1023. })
  1024. }
  1025. }
  1026. } else {
  1027. wx.setStorageSync('deviceName', that.data.deviceName[that.data.deviceIndex])
  1028. }
  1029. //根据分组名和设备名获取信息
  1030. var groupNames = that.data.groupName[that.data.groupIndex]
  1031. var deviceNames = that.data.deviceName[that.data.deviceIndex]
  1032. for (let d = 0; d < group.length; d++) {
  1033. if (groupNames == group[d].groupName) {
  1034. var Group = group[d].id
  1035. for (let g = 0; g < group[d].devices.length; g++) {
  1036. if (deviceNames == group[d].devices[g].deviceName) {
  1037. if (group[d].devices[g].module == 0) {
  1038. that.setData({
  1039. play: 0
  1040. })
  1041. var moudule = group[d].devices[g].module
  1042. var deviceId = group[d].devices[g].deviceId
  1043. var deviceKey = group[d].devices[g].deviceKey
  1044. } else {
  1045. that.setData({
  1046. play: 1
  1047. })
  1048. var moudule = group[d].devices[g].module
  1049. var Device = group[d].devices[g].id
  1050. }
  1051. }
  1052. }
  1053. }
  1054. }
  1055. if (moudule == 0) {
  1056. that.setData({
  1057. deviceId: deviceId,
  1058. deviceKey: deviceKey
  1059. })
  1060. getBasic(deviceId, deviceKey).then(res => {
  1061. if (res.data.errno == 0) {
  1062. if (res.data.data.online == true) {
  1063. that.setData({
  1064. status: "在线"
  1065. })
  1066. } else {
  1067. that.setData({
  1068. status: "离线"
  1069. })
  1070. }
  1071. } else {
  1072. wx.showModal({
  1073. title: '错误',
  1074. content: res.data.error,
  1075. showCancel: false
  1076. })
  1077. }
  1078. })
  1079. getData(deviceId, deviceKey).then(res => {
  1080. if (res.data.errno == 0) {
  1081. let {
  1082. data
  1083. } = res.data
  1084. for (let i = 0; i < data.length; i++) {
  1085. //时间
  1086. if (data[i].id == "SysTime") {
  1087. var times = data[i].current_value
  1088. } else if (data[i].id == "RelayCount") {
  1089. var quantity = data[i].current_value
  1090. that.setData({
  1091. loops: quantity
  1092. })
  1093. }
  1094. //日期
  1095. else if (data[i].id == "SysDate") {
  1096. var dates = data[i].current_value
  1097. }
  1098. //光照度
  1099. else if (data[i].id == "lightLuxValue") {
  1100. var Illuminance = data[i].current_value
  1101. }
  1102. //日出时间
  1103. else if (data[i].id == "RiseTime") {
  1104. var Sunrisetime = data[i].current_value
  1105. }
  1106. //日落时间
  1107. else if (data[i].id == "SetTime") {
  1108. var Sunsettime = data[i].current_value
  1109. }
  1110. //经度
  1111. else if (data[i].id == "Longitude") {
  1112. var longitude = data[i].current_value
  1113. }
  1114. //纬度
  1115. else if (data[i].id == "Latitude") {
  1116. var latitude = data[i].current_value
  1117. }
  1118. //消防报警
  1119. else if (data[i].id == "AlarmState") {
  1120. var Firealarm = data[i].current_value
  1121. }
  1122. //回路数量
  1123. else if (data[i].id == "RelayCount") {
  1124. var loops = data[i].current_value
  1125. }
  1126. //开关延时
  1127. else if (data[i].id == "DeviceID") {
  1128. var device = data[i].current_value
  1129. that.setData({
  1130. index: device,
  1131. switchtime: device
  1132. })
  1133. }
  1134. }
  1135. //时间
  1136. if (times.length == 5) {
  1137. var a = "0" + times.substring(0, 1) + ':' + times.substring(
  1138. 1, 3) + ':' + times.substring(3, 5)
  1139. } else if (times.length == 6) {
  1140. var a = times.substring(0, 2) + ':' + times.substring(2,
  1141. 4) + ':' + times.substring(4, 6)
  1142. } else {
  1143. a = times
  1144. }
  1145. //日期
  1146. var b = '20' + dates.substring(0, 2) + '-' + dates.substring(2,
  1147. 4) + '-' + dates.substring(4, 6)
  1148. //日出时间
  1149. var c = Sunrisetime.substring(0, 1) + ':' + Sunrisetime
  1150. .substring(1, 3)
  1151. //日落时间
  1152. var d = Sunsettime.substring(0, 2) + ':' + Sunsettime.substring(
  1153. 2, 4)
  1154. //经度
  1155. var multiIndex = that.data.multiIndex
  1156. if (longitude.length == 5) {
  1157. var e = longitude.substring(0, 3) + "," + longitude
  1158. .substring(3, 5) + "'"
  1159. multiIndex[0] = parseInt(longitude.substring(0, 3))
  1160. multiIndex[1] = parseInt(longitude.substring(3, 5))
  1161. that.setData({
  1162. multiIndex: multiIndex
  1163. })
  1164. } else if (longitude.length == 4) {
  1165. var e = longitude.substring(0, 2) + "," + longitude
  1166. .substring(2, 4) + "'"
  1167. multiIndex[0] = parseInt(longitude.substring(0, 2))
  1168. multiIndex[1] = parseInt(longitude.substring(2, 4))
  1169. that.setData({
  1170. multiIndex: multiIndex
  1171. })
  1172. } else if (longitude.length == 3) {
  1173. var e = longitude.substring(0, 1) + "," + longitude
  1174. .substring(1, 3) + "'"
  1175. multiIndex[0] = parseInt(longitude.substring(0, 1))
  1176. multiIndex[1] = parseInt(longitude.substring(1, 3))
  1177. that.setData({
  1178. multiIndex: multiIndex
  1179. })
  1180. } else if (longitude.length == 2) {
  1181. var e = 0 + "," + longitude.substring(0, 2) + "'"
  1182. multiIndex[0] = 0
  1183. multiIndex[1] = parseInt(longitude.substring(0, 2))
  1184. that.setData({
  1185. multiIndex: multiIndex
  1186. })
  1187. } else {
  1188. var e = 0 + "," + longitude.substring(0, 1) + "'"
  1189. multiIndex[0] = 0
  1190. multiIndex[1] = parseInt(longitude.substring(0, 1))
  1191. that.setData({
  1192. multiIndex: multiIndex
  1193. })
  1194. }
  1195. //纬度
  1196. var multiIndex2 = that.data.multiIndex2
  1197. if (latitude.length == 5) {
  1198. var f = latitude.substring(0, 3) + "," + latitude.substring(
  1199. 3, 5) + "'"
  1200. multiIndex2[0] = parseInt(latitude.substring(0, 3))
  1201. multiIndex2[1] = parseInt(latitude.substring(3, 5))
  1202. that.setData({
  1203. multiIndex2: multiIndex2
  1204. })
  1205. } else if (latitude.length == 4) {
  1206. var f = latitude.substring(0, 2) + "," + latitude.substring(
  1207. 2, 4) + "'"
  1208. multiIndex2[0] = parseInt(latitude.substring(0, 2))
  1209. multiIndex2[1] = parseInt(latitude.substring(2, 4))
  1210. that.setData({
  1211. multiIndex2: multiIndex2
  1212. })
  1213. } else if (latitude.length == 3) {
  1214. var f = latitude.substring(0, 1) + "," + latitude.substring(
  1215. 1, 3) + "'"
  1216. multiIndex2[0] = parseInt(latitude.substring(0, 1))
  1217. multiIndex2[1] = parseInt(latitude.substring(1, 3))
  1218. that.setData({
  1219. multiIndex2: multiIndex2
  1220. })
  1221. } else if (latitude.length == 2) {
  1222. var f = 0 + "," + latitude.substring(0, 2) + "'"
  1223. multiIndex2[0] = 0
  1224. multiIndex2[1] = parseInt(latitude.substring(0, 2))
  1225. that.setData({
  1226. multiIndex2: multiIndex2
  1227. })
  1228. } else {
  1229. var f = 0 + "," + latitude.substring(0, 1) + "'"
  1230. multiIndex2[0] = 0
  1231. multiIndex2[1] = parseInt(latitude.substring(0, 1))
  1232. that.setData({
  1233. multiIndex2: multiIndex2
  1234. })
  1235. }
  1236. //光照度
  1237. var g = Illuminance
  1238. //消防报警
  1239. if (Firealarm == "0") {
  1240. that.setData({
  1241. Firealarmtext: "正常",
  1242. Firealarmcolor: "#5cfe03"
  1243. })
  1244. } else {
  1245. that.setData({
  1246. Firealarmtext: "异常",
  1247. Firealarmcolor: "red"
  1248. })
  1249. }
  1250. that.setData({
  1251. times: a,
  1252. dates: b,
  1253. Sunrisetime: c,
  1254. Sunsettime: d,
  1255. longitude: e,
  1256. latitude: f,
  1257. Illuminance: g,
  1258. loops: loops,
  1259. })
  1260. } else {
  1261. wx.showModal({
  1262. title: '错误',
  1263. content: res.data.error,
  1264. showCancel: false
  1265. })
  1266. }
  1267. })
  1268. postData(deviceId, deviceKey, {
  1269. "Reflash": 4
  1270. }).then(res => {
  1271. if (res.data.errno == 0) {
  1272. setTimeout(function() {
  1273. getData(that.data.deviceId, that.data.deviceKey)
  1274. .then(ever => {
  1275. if (ever.data.errno == 0) {
  1276. let {
  1277. data
  1278. } = ever.data
  1279. for (let i = 0; i < data
  1280. .length; i++) {
  1281. //时间
  1282. if (data[i].id == "SysTime") {
  1283. var times = data[i]
  1284. .current_value
  1285. }
  1286. //日期
  1287. else if (data[i].id ==
  1288. "SysDate") {
  1289. var dates = data[i]
  1290. .current_value
  1291. }
  1292. }
  1293. if (times.length == 5) {
  1294. var a = "0" + times.substring(0,
  1295. 1) + ':' + times
  1296. .substring(1, 3) + ':' +
  1297. times.substring(3, 5)
  1298. } else if (times.length == 6) {
  1299. var a = times.substring(0, 2) +
  1300. ':' + times.substring(2,
  1301. 4) + ':' + times.substring(
  1302. 4, 6)
  1303. } else {
  1304. a = times
  1305. }
  1306. //日期
  1307. var b = '20' + dates.substring(0,
  1308. 2) + '-' + dates.substring(2,
  1309. 4) + '-' + dates.substring(4, 6)
  1310. that.setData({
  1311. times: a,
  1312. dates: b
  1313. })
  1314. } else {
  1315. wx.showModal({
  1316. title: '错误',
  1317. content: ever.data
  1318. .error,
  1319. showCancel: false
  1320. })
  1321. }
  1322. })
  1323. }, 2000)
  1324. } else if (res.data.errno == 10) {
  1325. setTimeout(function() {
  1326. wx.showModal({
  1327. title: '错误',
  1328. content: '获取时间数据失败,请检查设备是否在线',
  1329. showCancel: false
  1330. })
  1331. }, 2000)
  1332. } else {
  1333. setTimeout(function() {
  1334. wx.showModal({
  1335. title: '错误',
  1336. content: res.data.error,
  1337. showCancel: false
  1338. })
  1339. }, 2000)
  1340. }
  1341. })
  1342. } else {
  1343. getDevice(Device, Group).then(res => {
  1344. if (res.data.code == 0) {
  1345. var onlines = res.data.data
  1346. if (onlines[0].status == 1) {
  1347. that.setData({
  1348. status: "在线"
  1349. })
  1350. } else {
  1351. that.setData({
  1352. status: "离线"
  1353. })
  1354. }
  1355. var loops = res.data.data
  1356. var myDate = new Date();
  1357. //年
  1358. var year = myDate.getFullYear().toString()
  1359. year = year.slice(2, 4)
  1360. //月
  1361. var month = myDate.getMonth() + 1
  1362. month = month.toString()
  1363. if (month.length == 1) {
  1364. month = '0' + month
  1365. }
  1366. //日
  1367. var date = myDate.getDate()
  1368. date = date.toString()
  1369. if (date.length == 1) {
  1370. date = '0' + date
  1371. }
  1372. //小时
  1373. var hour = myDate.getHours()
  1374. hour = hour.toString()
  1375. if (hour.length == 1) {
  1376. hour = '0' + hour
  1377. }
  1378. //分钟
  1379. var minutes = myDate.getMinutes()
  1380. minutes = minutes.toString()
  1381. if (minutes.length == 1) {
  1382. minutes = '0' + minutes
  1383. }
  1384. //秒
  1385. var seconds = myDate.getSeconds()
  1386. seconds = seconds.toString()
  1387. if (seconds.length == 1) {
  1388. seconds = '0' + seconds
  1389. }
  1390. var datas = '20' + year + '-' + month + '-' + date
  1391. var time = hour + ':' + minutes + ':' + seconds
  1392. that.setData({
  1393. loops: loops[0].circuitNum,
  1394. dates: datas,
  1395. times: time
  1396. })
  1397. } else {
  1398. wx.showModal({
  1399. title: '错误',
  1400. content: dve.data.msg,
  1401. showCancel: false
  1402. })
  1403. }
  1404. })
  1405. }
  1406. } else {
  1407. that.setData({
  1408. status: '离线',
  1409. deviceName: []
  1410. })
  1411. }
  1412. }
  1413. }
  1414. } else {
  1415. that.setData({
  1416. deviceName: [],
  1417. groupName: []
  1418. })
  1419. }
  1420. },
  1421. //存储数据
  1422. Storedata: function() {
  1423. var that = this
  1424. var switchtime = that.data.array[that.data.index]
  1425. switchtime = parseInt(switchtime)
  1426. //经度
  1427. var longitude
  1428. var longitude1 = that.data.multiItems[0][that.data.multiIndex[0]]
  1429. var longitude2 = that.data.multiItems[1][that.data.multiIndex[1]]
  1430. if (longitude1 == 0) {
  1431. longitude = longitude2
  1432. } else {
  1433. longitude1 = longitude1 + ''
  1434. longitude2 = longitude2 + ''
  1435. if (longitude2.length == 2) {
  1436. longitude = longitude1 + longitude2
  1437. longitude = parseInt(longitude)
  1438. } else {
  1439. longitude = longitude1 + '0' + longitude2
  1440. longitude = parseInt(longitude)
  1441. }
  1442. }
  1443. //纬度
  1444. var latitude
  1445. var latitude1 = that.data.multiItems2[0][that.data.multiIndex2[0]]
  1446. var latitude2 = that.data.multiItems2[1][that.data.multiIndex2[1]]
  1447. if (latitude1 == 0) {
  1448. latitude = latitude2
  1449. } else {
  1450. latitude1 = latitude1 + ''
  1451. latitude2 = latitude2 + ''
  1452. if (latitude2.length == 2) {
  1453. latitude = latitude1 + latitude2
  1454. latitude = parseInt(latitude)
  1455. } else {
  1456. latitude = latitude1 + '0' + latitude2
  1457. latitude = parseInt(latitude)
  1458. }
  1459. }
  1460. postData(that.data.deviceId, that.data.deviceKey, {
  1461. "DeviceID": switchtime,
  1462. "Longitude": longitude,
  1463. "Latitude": latitude,
  1464. "Reflash": 0,
  1465. }).then(res => {
  1466. if (res.data.errno == 0) {
  1467. wx.showToast({
  1468. title: '存储数据中',
  1469. icon: 'success',
  1470. duration: 2000
  1471. })
  1472. that.setData({
  1473. switchtime: switchtime
  1474. })
  1475. } else if (res.data.errno == 10) {
  1476. wx.showModal({
  1477. title: '提示',
  1478. content: '存储数据失败,请检查设备是否在线或者刷新页面',
  1479. showCancel: false,
  1480. })
  1481. } else {
  1482. wx.showModal({
  1483. title: '提示',
  1484. content: res.data.error,
  1485. showCancel: false,
  1486. })
  1487. }
  1488. })
  1489. },
  1490. /**
  1491. * 生命周期函数--监听页面加载
  1492. */
  1493. onLoad(options) {},
  1494. /**
  1495. * 生命周期函数--监听页面初次渲染完成
  1496. */
  1497. onReady() {
  1498. },
  1499. /**
  1500. * 生命周期函数--监听页面显示
  1501. */
  1502. onShow() {
  1503. wx.showToast({
  1504. title: '刷新数据中',
  1505. icon: 'loading',
  1506. duration: 2000
  1507. })
  1508. var that = this
  1509. //经度显示
  1510. var pt = [
  1511. [],
  1512. []
  1513. ]
  1514. for (let i = 0; i < 180; i++) {
  1515. pt[0].push(i)
  1516. }
  1517. for (let j = 0; j < 59; j++) {
  1518. pt[1].push(j)
  1519. }
  1520. that.setData({
  1521. multiItems: pt
  1522. })
  1523. //纬度显示
  1524. var pt1 = [
  1525. [],
  1526. []
  1527. ]
  1528. for (let i = 0; i < 180; i++) {
  1529. pt1[0].push(i)
  1530. }
  1531. for (let j = 0; j < 59; j++) {
  1532. pt1[1].push(j)
  1533. }
  1534. that.setData({
  1535. multiItems2: pt
  1536. })
  1537. var group = wx.getStorageSync('group')
  1538. if (group != null && group.length != 0) {
  1539. //获取分组下拉
  1540. var groups = []
  1541. for (let i = 0; i < group.length; i++) {
  1542. groups.push(group[i].groupName)
  1543. }
  1544. that.setData({
  1545. groupName: groups
  1546. })
  1547. //改变分组下标
  1548. if (wx.getStorageSync('groupName') != '') {
  1549. let GroupName = that.data.groupName
  1550. for (let n = 0; n < GroupName.length; n++) {
  1551. if (GroupName[n] == wx.getStorageSync('groupName')) {
  1552. that.setData({
  1553. groupIndex: n
  1554. })
  1555. }
  1556. }
  1557. } else {
  1558. that.setData({
  1559. groupIndex: 0
  1560. })
  1561. wx.setStorageSync('groupName', that.data.groupName[that.data.groupIndex])
  1562. }
  1563. //获取设备下拉
  1564. var groupName = that.data.groupName
  1565. var groupIndex = that.data.groupIndex
  1566. var device = []
  1567. for (let j = 0; j < group.length; j++) {
  1568. if (groupName[groupIndex] == group[j].groupName) {
  1569. if (group[j].devices != null && group[j].devices.length != 0) {
  1570. for (let p = 0; p < group[j].devices.length; p++) {
  1571. device.push(group[j].devices[p].deviceName)
  1572. }
  1573. that.setData({
  1574. deviceName: device
  1575. })
  1576. if (wx.getStorageSync('deviceName') != '') {
  1577. var DeviceName = that.data.deviceName
  1578. for (let m = 0; m < DeviceName.length; m++) {
  1579. if (DeviceName[m] == wx.getStorageSync('deviceName')) {
  1580. that.setData({
  1581. deviceIndex: m
  1582. })
  1583. }
  1584. }
  1585. } else {
  1586. that.setData({
  1587. deviceIndex: 0
  1588. })
  1589. wx.setStorageSync('deviceName', that.data.deviceName[that.data.deviceIndex])
  1590. }
  1591. //根据分组名和设备名获取信息
  1592. var groupNames = that.data.groupName[that.data.groupIndex]
  1593. var deviceNames = that.data.deviceName[that.data.deviceIndex]
  1594. for (let d = 0; d < group.length; d++) {
  1595. if (groupNames == group[d].groupName) {
  1596. var Group = group[d].id
  1597. for (let g = 0; g < group[d].devices.length; g++) {
  1598. if (deviceNames == group[d].devices[g].deviceName) {
  1599. if (group[d].devices[g].module == 0) {
  1600. that.setData({
  1601. play: 0
  1602. })
  1603. var moudule = group[d].devices[g].module
  1604. var deviceId = group[d].devices[g].deviceId
  1605. var deviceKey = group[d].devices[g].deviceKey
  1606. } else {
  1607. that.setData({
  1608. play: 1
  1609. })
  1610. var moudule = group[d].devices[g].module
  1611. var Device = group[d].devices[g].id
  1612. }
  1613. }
  1614. }
  1615. }
  1616. }
  1617. if (moudule == 0) {
  1618. that.setData({
  1619. deviceId: deviceId,
  1620. deviceKey: deviceKey
  1621. })
  1622. getBasic(deviceId, deviceKey).then(res => {
  1623. if (res.data.errno == 0) {
  1624. if (res.data.data.online == true) {
  1625. that.setData({
  1626. status: "在线"
  1627. })
  1628. } else {
  1629. that.setData({
  1630. status: "离线"
  1631. })
  1632. }
  1633. } else {
  1634. wx.showModal({
  1635. title: '错误',
  1636. content: res.data.error,
  1637. showCancel: false
  1638. })
  1639. }
  1640. })
  1641. getData(deviceId, deviceKey).then(res => {
  1642. if (res.data.errno == 0) {
  1643. let {
  1644. data
  1645. } = res.data
  1646. for (let i = 0; i < data.length; i++) {
  1647. //时间
  1648. if (data[i].id == "SysTime") {
  1649. var times = data[i].current_value
  1650. } else if (data[i].id == "RelayCount") {
  1651. var quantity = data[i].current_value
  1652. that.setData({
  1653. loops: quantity
  1654. })
  1655. }
  1656. //日期
  1657. else if (data[i].id == "SysDate") {
  1658. var dates = data[i].current_value
  1659. }
  1660. //光照度
  1661. else if (data[i].id == "lightLuxValue") {
  1662. var Illuminance = data[i].current_value
  1663. }
  1664. //日出时间
  1665. else if (data[i].id == "RiseTime") {
  1666. var Sunrisetime = data[i].current_value
  1667. }
  1668. //日落时间
  1669. else if (data[i].id == "SetTime") {
  1670. var Sunsettime = data[i].current_value
  1671. }
  1672. //经度
  1673. else if (data[i].id == "Longitude") {
  1674. var longitude = data[i].current_value
  1675. }
  1676. //纬度
  1677. else if (data[i].id == "Latitude") {
  1678. var latitude = data[i].current_value
  1679. }
  1680. //消防报警
  1681. else if (data[i].id == "AlarmState") {
  1682. var Firealarm = data[i].current_value
  1683. }
  1684. //回路数量
  1685. else if (data[i].id == "RelayCount") {
  1686. var loops = data[i].current_value
  1687. }
  1688. //开关延时
  1689. else if (data[i].id == "DeviceID") {
  1690. var device = data[i].current_value
  1691. that.setData({
  1692. index: device,
  1693. switchtime: device
  1694. })
  1695. }
  1696. }
  1697. //时间
  1698. if (times.length == 5) {
  1699. var a = "0" + times.substring(0, 1) + ':' + times.substring(1,
  1700. 3) + ':' + times.substring(3, 5)
  1701. } else if (times.length == 6) {
  1702. var a = times.substring(0, 2) + ':' + times.substring(2, 4) +
  1703. ':' + times.substring(4, 6)
  1704. } else {
  1705. a = times
  1706. }
  1707. //日期
  1708. var b = '20' + dates.substring(0, 2) + '-' + dates.substring(2, 4) +
  1709. '-' + dates.substring(4, 6)
  1710. //日出时间
  1711. var c = Sunrisetime.substring(0, 1) + ':' + Sunrisetime.substring(1,
  1712. 3)
  1713. //日落时间
  1714. var d = Sunsettime.substring(0, 2) + ':' + Sunsettime.substring(2,
  1715. 4)
  1716. //经度
  1717. var multiIndex = that.data.multiIndex
  1718. if (longitude.length == 5) {
  1719. var e = longitude.substring(0, 3) + "," + longitude.substring(3,
  1720. 5) + "'"
  1721. multiIndex[0] = parseInt(longitude.substring(0, 3))
  1722. multiIndex[1] = parseInt(longitude.substring(3, 5))
  1723. that.setData({
  1724. multiIndex: multiIndex
  1725. })
  1726. } else if (longitude.length == 4) {
  1727. var e = longitude.substring(0, 2) + "," + longitude.substring(2,
  1728. 4) + "'"
  1729. multiIndex[0] = parseInt(longitude.substring(0, 2))
  1730. multiIndex[1] = parseInt(longitude.substring(2, 4))
  1731. that.setData({
  1732. multiIndex: multiIndex
  1733. })
  1734. } else if (longitude.length == 3) {
  1735. var e = longitude.substring(0, 1) + "," + longitude.substring(1,
  1736. 3) + "'"
  1737. multiIndex[0] = parseInt(longitude.substring(0, 1))
  1738. multiIndex[1] = parseInt(longitude.substring(1, 3))
  1739. that.setData({
  1740. multiIndex: multiIndex
  1741. })
  1742. } else if (longitude.length == 2) {
  1743. var e = 0 + "," + longitude.substring(0, 2) + "'"
  1744. multiIndex[0] = 0
  1745. multiIndex[1] = parseInt(longitude.substring(0, 2))
  1746. that.setData({
  1747. multiIndex: multiIndex
  1748. })
  1749. } else {
  1750. var e = 0 + "," + longitude.substring(0, 1) + "'"
  1751. multiIndex[0] = 0
  1752. multiIndex[1] = parseInt(longitude.substring(0, 1))
  1753. that.setData({
  1754. multiIndex: multiIndex
  1755. })
  1756. }
  1757. //纬度
  1758. var multiIndex2 = that.data.multiIndex2
  1759. if (latitude.length == 5) {
  1760. var f = latitude.substring(0, 3) + "," + latitude.substring(3,
  1761. 5) + "'"
  1762. multiIndex2[0] = parseInt(latitude.substring(0, 3))
  1763. multiIndex2[1] = parseInt(latitude.substring(3, 5))
  1764. that.setData({
  1765. multiIndex2: multiIndex2
  1766. })
  1767. } else if (latitude.length == 4) {
  1768. var f = latitude.substring(0, 2) + "," + latitude.substring(2,
  1769. 4) + "'"
  1770. multiIndex2[0] = parseInt(latitude.substring(0, 2))
  1771. multiIndex2[1] = parseInt(latitude.substring(2, 4))
  1772. that.setData({
  1773. multiIndex2: multiIndex2
  1774. })
  1775. } else if (latitude.length == 3) {
  1776. var f = latitude.substring(0, 1) + "," + latitude.substring(1,
  1777. 3) + "'"
  1778. multiIndex2[0] = parseInt(latitude.substring(0, 1))
  1779. multiIndex2[1] = parseInt(latitude.substring(1, 3))
  1780. that.setData({
  1781. multiIndex2: multiIndex2
  1782. })
  1783. } else if (latitude.length == 2) {
  1784. var f = 0 + "," + latitude.substring(0, 2) + "'"
  1785. multiIndex2[0] = 0
  1786. multiIndex2[1] = parseInt(latitude.substring(0, 2))
  1787. that.setData({
  1788. multiIndex2: multiIndex2
  1789. })
  1790. } else {
  1791. var f = 0 + "," + latitude.substring(0, 1) + "'"
  1792. multiIndex2[0] = 0
  1793. multiIndex2[1] = parseInt(latitude.substring(0, 1))
  1794. that.setData({
  1795. multiIndex2: multiIndex2
  1796. })
  1797. }
  1798. //光照度
  1799. var g = Illuminance
  1800. //消防报警
  1801. if (Firealarm == "0") {
  1802. that.setData({
  1803. Firealarmtext: "正常",
  1804. Firealarmcolor: "#5cfe03"
  1805. })
  1806. } else {
  1807. that.setData({
  1808. Firealarmtext: "异常",
  1809. Firealarmcolor: "red"
  1810. })
  1811. }
  1812. that.setData({
  1813. times: a,
  1814. dates: b,
  1815. Sunrisetime: c,
  1816. Sunsettime: d,
  1817. longitude: e,
  1818. latitude: f,
  1819. Illuminance: g,
  1820. loops: loops,
  1821. })
  1822. } else {
  1823. wx.showModal({
  1824. title: '错误',
  1825. content: res.data.error,
  1826. showCancel: false
  1827. })
  1828. }
  1829. })
  1830. postData(deviceId, deviceKey, {
  1831. "Reflash": 4
  1832. }).then(res => {
  1833. if (res.data.errno == 0) {
  1834. setTimeout(function() {
  1835. getData(that.data.deviceId, that.data.deviceKey).then(
  1836. ever => {
  1837. if (ever.data.errno == 0) {
  1838. let {
  1839. data
  1840. } = ever.data
  1841. for (let i = 0; i < data.length; i++) {
  1842. //时间
  1843. if (data[i].id == "SysTime") {
  1844. var times = data[i]
  1845. .current_value
  1846. }
  1847. //日期
  1848. else if (data[i].id == "SysDate") {
  1849. var dates = data[i]
  1850. .current_value
  1851. }
  1852. }
  1853. if (times.length == 5) {
  1854. var a = "0" + times.substring(0,
  1855. 1) + ':' + times.substring(1,
  1856. 3) + ':' + times.substring(3, 5)
  1857. } else if (times.length == 6) {
  1858. var a = times.substring(0, 2) +
  1859. ':' + times.substring(2, 4) +
  1860. ':' + times.substring(4, 6)
  1861. } else {
  1862. a = times
  1863. }
  1864. //日期
  1865. var b = '20' + dates.substring(0, 2) +
  1866. '-' + dates.substring(2, 4) + '-' +
  1867. dates.substring(4, 6)
  1868. that.setData({
  1869. times: a,
  1870. dates: b
  1871. })
  1872. } else {
  1873. wx.showModal({
  1874. title: '错误',
  1875. content: ever.data.error,
  1876. showCancel: false
  1877. })
  1878. }
  1879. })
  1880. }, 2000)
  1881. } else if (res.data.errno == 10) {
  1882. setTimeout(function() {
  1883. wx.showModal({
  1884. title: '错误',
  1885. content: '获取时间数据失败,请检查设备是否在线,或者刷新页面',
  1886. showCancel: false
  1887. })
  1888. }, 2000)
  1889. } else {
  1890. setTimeout(function() {
  1891. wx.showModal({
  1892. title: '错误',
  1893. content: res.data.error,
  1894. showCancel: false
  1895. })
  1896. }, 2000)
  1897. }
  1898. })
  1899. } else {
  1900. getDevice(Device, Group).then(res => {
  1901. if (res.data.code == 0) {
  1902. var onlines = res.data.data
  1903. if (onlines.status == 1) {
  1904. that.setData({
  1905. status: "在线"
  1906. })
  1907. } else {
  1908. that.setData({
  1909. status: "离线"
  1910. })
  1911. }
  1912. var loops = res.data.data
  1913. var myDate = new Date();
  1914. //年
  1915. var year = myDate.getFullYear().toString()
  1916. year = year.slice(2, 4)
  1917. //月
  1918. var month = myDate.getMonth() + 1
  1919. month = month.toString()
  1920. if (month.length == 1) {
  1921. month = '0' + month
  1922. }
  1923. //日
  1924. var date = myDate.getDate()
  1925. date = date.toString()
  1926. if (date.length == 1) {
  1927. date = '0' + date
  1928. }
  1929. //小时
  1930. var hour = myDate.getHours()
  1931. hour = hour.toString()
  1932. if (hour.length == 1) {
  1933. hour = '0' + hour
  1934. }
  1935. //分钟
  1936. var minutes = myDate.getMinutes()
  1937. minutes = minutes.toString()
  1938. if (minutes.length == 1) {
  1939. minutes = '0' + minutes
  1940. }
  1941. //秒
  1942. var seconds = myDate.getSeconds()
  1943. seconds = seconds.toString()
  1944. if (seconds.length == 1) {
  1945. seconds = '0' + seconds
  1946. }
  1947. var datas = '20' + year + '-' + month + '-' + date
  1948. var time = hour + ':' + minutes + ':' + seconds
  1949. that.setData({
  1950. loops: loops.circuitNum,
  1951. dates: datas,
  1952. times: time
  1953. })
  1954. } else {
  1955. wx.showModal({
  1956. title: '错误',
  1957. content: dve.data.msg,
  1958. showCancel: false
  1959. })
  1960. }
  1961. })
  1962. }
  1963. } else {
  1964. that.setData({
  1965. status: '离线',
  1966. deviceName: []
  1967. })
  1968. }
  1969. }
  1970. }
  1971. } else {
  1972. that.setData({
  1973. deviceName: [],
  1974. groupName: [],
  1975. status: '离线'
  1976. })
  1977. }
  1978. },
  1979. /**
  1980. * 生命周期函数--监听页面隐藏
  1981. */
  1982. onHide() {
  1983. },
  1984. /**
  1985. * 生命周期函数--监听页面卸载
  1986. */
  1987. onUnload() {
  1988. },
  1989. /**
  1990. * 页面相关事件处理函数--监听用户下拉动作
  1991. */
  1992. onPullDownRefresh() {
  1993. },
  1994. /**
  1995. * 页面上拉触底事件的处理函数
  1996. */
  1997. onReachBottom() {
  1998. },
  1999. /**
  2000. * 用户点击右上角分享
  2001. */
  2002. onShareAppMessage() {
  2003. }
  2004. })