system.js 68 KB

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