system.js 63 KB

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