loop.js 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259
  1. const {
  2. getBasic,
  3. getData,
  4. postData,
  5. } = require('../../api/intell')
  6. const {
  7. getDevice,
  8. getloop,
  9. postloop,
  10. looplightlist,
  11. } = require('../../api/device')
  12. const enloop = require('../../utils/loop')
  13. // pages/loop/loop.js
  14. Page({
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. array: [],
  20. //回路调控
  21. crr: [],
  22. indexes: 0,
  23. //时间调控
  24. time: ["00:00", "00:00", "00:00", "00:00"],
  25. //时间调控(开关选择器)
  26. state: [false, false, false, false], //控制时控一开关和光控开关的状态
  27. state1: [false, false], //控制时控二开关的状态
  28. fixed1: "固定",
  29. fixed2: "固定",
  30. fixed3: "固定",
  31. fixed4: "固定",
  32. type1: "",
  33. type2: "",
  34. type3: "",
  35. type4: "",
  36. //时间调控(背景颜色)
  37. timecontrolcolor1: "#888888",
  38. timecontrolcolor2: "#888888",
  39. timecontrolcolor3: "#888888",
  40. timecontrolcolor4: "#888888",
  41. //时间调控(字体颜色)
  42. fontcolor1: "#cccccc",
  43. fontcolor2: "#cccccc",
  44. fontcolor3: "#cccccc",
  45. fontcolor4: "#cccccc",
  46. //固定经纬切换
  47. //日期调控
  48. address: ["/image/false.png", "/image/false.png", "/image/false.png", "/image/false.png",
  49. "/image/false.png",
  50. "/image/false.png", "/image/false.png"
  51. ],
  52. recorddate: "", //记录后台传过来的日期参数
  53. //光控调整
  54. arr: [0],
  55. brr: [0],
  56. index: 0,
  57. indexs: 0,
  58. Lightcontrolcolor1: "#888888",
  59. Lightcontrolcolor2: "#888888",
  60. fontcolor5: "#cccccc",
  61. fontcolor6: "#cccccc",
  62. select1: "",
  63. select2: "",
  64. //报警状态
  65. radio1: false,
  66. radio2: false,
  67. radio3: false,
  68. alert: "",
  69. //扫码
  70. Title: "",
  71. status: "离线",
  72. zoom: 0.8,
  73. Modecontrol: "",
  74. groupName: [],
  75. deviceName: [],
  76. groupIndex: 0,
  77. deviceIndex: 0,
  78. deviceId: '',
  79. deviceKey: '',
  80. num: 0, //记录回路数量
  81. play: 0, //新老设备的页面切换
  82. //新设备数据
  83. timeValue: ['00:00', '00:00', '00:00', '00:00', '00:00', '00:00'],
  84. newcolor: ["#888888", "#888888", "#888888"],
  85. newfont: ["#cccccc", "#cccccc", "#cccccc"],
  86. newSwitch: [false, false, false],
  87. newSwitchstate: ["", "", ""],
  88. equipment: 0, //记录当前设备的序号(服务器传的id)
  89. subset: 0, //记录当前分组的id
  90. ID: 0, //记录设备的ID
  91. // 启动条件(多选框)
  92. disabled: false,
  93. choice: [],
  94. lightlist: [], //新设备回路开启条件,
  95. popup: false, //开启条件弹窗
  96. openModal:'手动',
  97. shutModal:'手动',
  98. beginTime:'',
  99. closeTimes:''
  100. },
  101. //分组下拉
  102. changegroup: function(e) {
  103. wx.showToast({
  104. title: '刷新中',
  105. icon: 'loading',
  106. duration: 2000
  107. })
  108. var that = this
  109. that.setData({
  110. groupIndex: e.detail.value
  111. })
  112. wx.setStorageSync('groupIndex', e.detail.value)
  113. var groupName = that.data.groupName[that.data.groupIndex] //选择的分组名称
  114. wx.setStorageSync('groupName', groupName) //将修改的分组名称放入缓存
  115. var group = wx.getStorageSync('group')
  116. var deviceName = []
  117. for (let i = 0; i < group.length; i++) {
  118. if (group[i].groupName == groupName) {
  119. if (group[i].devices != null && group[i].devices.length != 0) {
  120. for (let j = 0; j < group[i].devices.length; j++) {
  121. deviceName.push(group[i].devices[j].deviceName)
  122. }
  123. that.setData({
  124. deviceName: deviceName,
  125. deviceIndex: 0
  126. })
  127. var groupNames = that.data.groupName[that.data.groupIndex]
  128. var deviceNames = that.data.deviceName[that.data.deviceIndex]
  129. wx.setStorageSync('deviceName', deviceNames) //将修改的设备名放入缓存
  130. //获取设备信息
  131. var Message = enloop.deviceMessage(groupNames, deviceNames)
  132. that.setData({
  133. equipment: Message.Device,
  134. subset: Message.id,
  135. ID: Message.ID,
  136. indexes: 0
  137. }) //记录当前的设备id和分组id
  138. if (Message.modules == 0) {
  139. that.setData({
  140. play: 0,
  141. deviceKey: Message.deviceKey,
  142. deviceId: Message.deviceId
  143. })
  144. getBasic(Message.deviceId, Message.deviceKey).then(res => {
  145. if (res.data.errno == 0) {
  146. if (res.data.data.online == true) {
  147. that.setData({
  148. status: '在线'
  149. })
  150. } else {
  151. that.setData({
  152. status: '离线'
  153. })
  154. }
  155. getData(Message.deviceId, Message.deviceKey).then(ever => {
  156. if (ever.data.errno == 0) {
  157. let {
  158. data
  159. } = ever.data
  160. //判断设备是否处于初始化状态
  161. var initialization = true
  162. for (let t = 0; t < data.length; t++) {
  163. if ('current_value' in data[t] == false) {
  164. initialization = false
  165. }
  166. }
  167. if (initialization == true) {
  168. let loopnum = Message.loopnum
  169. var Summary = enloop.deviceinfo(data, loopnum,
  170. that.data.arr, that.data.brr, that.data
  171. .time, that.data.state,
  172. that.data.state1, that.data.fixed1, that
  173. .data.fixed2, that.data.fixed3,
  174. that.data.fixed4, that.data.address,
  175. that.data.radio1, that.data.radio2,
  176. that.data.radio3, that.data.index, that
  177. .data.indexs)
  178. that.setData({
  179. crr: Summary.crr,
  180. arr: Summary.arr,
  181. brr: Summary.brr,
  182. fixed1: Summary.fixed1,
  183. fixed2: Summary.fixed2,
  184. fixed3: Summary.fixed3,
  185. fixed4: Summary.fixed4,
  186. index: Summary.index,
  187. indexs: Summary.indexs,
  188. radio1: Summary.radio1,
  189. radio2: Summary.radio2,
  190. radio3: Summary.radio3,
  191. recorddate: Summary.recorddate,
  192. state: Summary.state,
  193. state1: Summary.state1,
  194. time: Summary.time,
  195. address: Summary.address,
  196. play: 0
  197. })
  198. //监视开关状态(改变颜色,调整功能)
  199. switch (that.data.state[0]) {
  200. case true:
  201. that.setData({
  202. type1: "time",
  203. timecontrolcolor1: "blue",
  204. fontcolor1: "white",
  205. })
  206. break;
  207. default:
  208. that.setData({
  209. type1: "",
  210. timecontrolcolor1: "#888888",
  211. fontcolor1: "#cccccc",
  212. })
  213. break;
  214. }
  215. switch (that.data.state[1]) {
  216. case true:
  217. that.setData({
  218. type2: "time",
  219. timecontrolcolor2: "blue",
  220. fontcolor2: "white",
  221. })
  222. break;
  223. default:
  224. that.setData({
  225. type2: "",
  226. timecontrolcolor2: "#888888",
  227. fontcolor2: "#cccccc",
  228. })
  229. break;
  230. }
  231. switch (that.data.state1[0]) {
  232. case true:
  233. that.setData({
  234. type3: "time",
  235. timecontrolcolor3: "blue",
  236. fontcolor3: "white",
  237. })
  238. break;
  239. default:
  240. that.setData({
  241. type3: "",
  242. timecontrolcolor3: "#888888",
  243. fontcolor3: "#cccccc",
  244. })
  245. break;
  246. }
  247. switch (that.data.state1[1]) {
  248. case true:
  249. that.setData({
  250. type4: "time",
  251. timecontrolcolor4: "blue",
  252. fontcolor4: "white",
  253. })
  254. break;
  255. default:
  256. that.setData({
  257. type4: "",
  258. timecontrolcolor4: "#888888",
  259. fontcolor4: "#cccccc",
  260. })
  261. break;
  262. }
  263. switch (that.data.state[2]) {
  264. case true:
  265. that.setData({
  266. Lightcontrolcolor1: "blue",
  267. fontcolor5: "white",
  268. select1: "selector"
  269. })
  270. break;
  271. default:
  272. that.setData({
  273. Lightcontrolcolor1: "#888888",
  274. fontcolor5: "#cccccc",
  275. select1: ""
  276. })
  277. break;
  278. }
  279. switch (that.data.state[3]) {
  280. case true:
  281. that.setData({
  282. Lightcontrolcolor2: "blue",
  283. fontcolor6: "white",
  284. select2: "selector"
  285. })
  286. break;
  287. default:
  288. that.setData({
  289. Lightcontrolcolor2: "#888888",
  290. fontcolor6: "#cccccc",
  291. select2: ""
  292. })
  293. break;
  294. }
  295. } else {
  296. getDevice(Message.Device, Message.id).then(
  297. rgb => {
  298. if (rgb.data.code == 0) {
  299. var rgbs = rgb.data.data
  300. .circuits
  301. rgbs = rgbs.split(',')
  302. that.setData({
  303. crr: rgbs
  304. })
  305. } else {
  306. wx.showModal({
  307. title: '错误',
  308. content: rgb.data
  309. .msg,
  310. showCancel: false
  311. })
  312. }
  313. })
  314. }
  315. } else {
  316. wx.showModal({
  317. title: '错误',
  318. content: ever.data.error,
  319. showCancel: false
  320. })
  321. }
  322. })
  323. } else {
  324. wx.showModal({
  325. title: '错误',
  326. content: res.data.error,
  327. showCancel: false
  328. })
  329. }
  330. })
  331. } else {
  332. that.setData({
  333. play: 1
  334. })
  335. //新设备在线状态
  336. getDevice(Message.Device, Message.id).then(nrg => {
  337. if (nrg.data.code == 0) {
  338. var nrg = nrg.data.data
  339. if (nrg.status == 1) {
  340. that.setData({
  341. status: '在线'
  342. })
  343. } else {
  344. that.setData({
  345. status: '离线'
  346. })
  347. }
  348. getloop(Message.Device).then(suc => {
  349. if (suc.data.code == 0) {
  350. var suc = suc.data.data
  351. var index = that.data.indexes
  352. for (let i = 0; i < suc.length; i++) {
  353. if (index == i) {
  354. let Suc = suc[i]
  355. var newSwitch = that.data.newSwitch
  356. var timeValue = that.data.timeValue
  357. var newSwitchstate = that.data.newSwitchstate
  358. var choice = that.data.choice
  359. var model = Suc.ctlMode
  360. var beginTime = Suc.realTimeCondition1OnTime
  361. var closeTimes = Suc.realTimeCondition1OffTime
  362. //光控启动条件
  363. if (Suc.lightControlCondition.includes(
  364. ',') == true) {
  365. var light = Suc.lightControlCondition
  366. .split(',')
  367. for (let i = 0; i < light.length; i++) {
  368. switch (light[i]) {
  369. case '晴天':
  370. choice[0] = true
  371. break;
  372. case '多云':
  373. choice[1] = true
  374. break;
  375. case '阴天':
  376. choice[2] = true
  377. break;
  378. case '大阴天':
  379. choice[3] = true
  380. break;
  381. }
  382. }
  383. } else {
  384. choice = [false, false, false, false]
  385. switch (Suc.lightControlCondition) {
  386. case '晴天':
  387. choice[0] = true
  388. break;
  389. case '多云':
  390. choice[1] = true
  391. break;
  392. case '阴天':
  393. choice[2] = true
  394. break;
  395. case '大阴天':
  396. choice[3] = true
  397. break;
  398. }
  399. }
  400. that.setData({
  401. choice: choice
  402. })
  403. var lightCondition = Suc
  404. .lightControlCondition
  405. //光控启动条件
  406. looplightlist().then(res => {
  407. if (res.data.code == 0) {
  408. var lightlist = res.data
  409. .data
  410. that.setData({
  411. lightlist: lightlist
  412. })
  413. for (let i = 0; i <
  414. lightlist.length; i++) {
  415. choice[i] = false
  416. }
  417. if (lightCondition.includes(
  418. ',') == true) {
  419. lightCondition =
  420. lightCondition
  421. .split(',')
  422. for (let j = 0; j <
  423. lightCondition
  424. .length; j++) {
  425. if (lightCondition[
  426. j] == '1') {
  427. choice[0] = true
  428. } else if (
  429. lightCondition[
  430. j] == '2') {
  431. choice[1] = true
  432. } else if (
  433. lightCondition[
  434. j] == '3') {
  435. choice[2] = true
  436. } else if (
  437. lightCondition[
  438. j] == '4') {
  439. choice[3] = true
  440. }
  441. }
  442. } else {
  443. if (lightCondition ==
  444. '1') {
  445. choice[0] = true
  446. } else if (
  447. lightCondition ==
  448. '2') {
  449. choice[1] = true
  450. } else if (
  451. lightCondition ==
  452. '3') {
  453. choice[2] = true
  454. } else if (
  455. lightCondition ==
  456. '4') {
  457. choice[3] = true
  458. }
  459. }
  460. that.setData({
  461. choice: choice
  462. })
  463. } else {
  464. wx.showModal({
  465. title: '错误',
  466. content: res
  467. .data.msg,
  468. showCancel: false
  469. })
  470. }
  471. })
  472. //时控1
  473. if (Suc.timeCondition1Switch == 1) {
  474. newSwitch[0] = true
  475. newSwitchstate[0] = 'time'
  476. } else {
  477. newSwitch[0] = false
  478. newSwitchstate[0] = ''
  479. }
  480. timeValue[0] = Suc.timeCondition1OnTime
  481. timeValue[1] = Suc.timeCondition1OffTime
  482. //时控2
  483. if (Suc.timeCondition2Switch == 1) {
  484. newSwitch[1] = true
  485. newSwitchstate[1] = 'time'
  486. } else {
  487. newSwitch[1] = false
  488. newSwitchstate[1] = ''
  489. }
  490. timeValue[2] = Suc.timeCondition2OnTime
  491. timeValue[3] = Suc.timeCondition2OffTime
  492. //光控
  493. if (Suc.lightControlSwitch == 1) {
  494. newSwitch[2] = true
  495. newSwitchstate[2] = 'time'
  496. } else {
  497. newSwitch[2] = false
  498. newSwitchstate[2] = ''
  499. }
  500. timeValue[4] = Suc.lightControlStart
  501. timeValue[5] = Suc.lightControlEnd
  502. for (let j = 0; j < timeValue.length; j++) {
  503. if (timeValue[j] == "") {
  504. timeValue[j] = '00:00'
  505. }
  506. }
  507. var messageNum = Message.loopnum
  508. messageNum.push('所有回路')
  509. that.setData({
  510. crr: messageNum,
  511. timeValue: timeValue,
  512. newSwitch: newSwitch,
  513. newChange:model,
  514. beginTime:beginTime,
  515. closeTimes:closeTimes
  516. })
  517. //监视新设备开关状态
  518. var newSwitchs = that.data.newSwitch
  519. var newfonts = that.data.newfont
  520. var newcolors = that.data.newcolor
  521. var newSwitchstates = that.data
  522. .newSwitchstate
  523. var disableds = that.data.disabled
  524. if (newSwitchs[0] == true) {
  525. newfonts[0] = "white"
  526. newcolors[0] = "blue"
  527. newSwitchstates[0] = "time"
  528. } else {
  529. newfonts[0] = "#cccccc"
  530. newcolors[0] = "#888888"
  531. newSwitchstates[0] = ""
  532. }
  533. if (newSwitchs[1] == true) {
  534. newfonts[1] = "white"
  535. newcolors[1] = "blue"
  536. newSwitchstates[1] = "time"
  537. } else {
  538. newfonts[1] = "#cccccc"
  539. newcolors[1] = "#888888"
  540. newSwitchstates[1] = ""
  541. }
  542. if (newSwitchs[2] == true) {
  543. newfonts[2] = "white"
  544. newcolors[2] = "blue"
  545. newSwitchstates[2] = "time"
  546. disableds = false
  547. } else {
  548. newfonts[2] = "#cccccc"
  549. newcolors[2] = "#888888"
  550. newSwitchstates[2] = ""
  551. disableds = true
  552. }
  553. that.setData({
  554. newcolor: newcolors,
  555. newfont: newfonts,
  556. newSwitch: newSwitchs,
  557. newSwitchstate: newSwitchstates,
  558. disabled: disableds
  559. })
  560. }
  561. }
  562. } else {
  563. console.log('获取新设备回路参数失败')
  564. wx.showModal({
  565. title: '错误',
  566. content: suc.data.msg,
  567. showCancel: false
  568. })
  569. }
  570. })
  571. } else {
  572. console.log('新设备获取信息失败')
  573. wx.showModal({
  574. title: '错误',
  575. content: nrg.data.msg,
  576. showCancel: false
  577. })
  578. }
  579. })
  580. }
  581. } else {
  582. wx.setStorageSync('deviceName', '')
  583. that.setData({
  584. status: '离线',
  585. deviceName: []
  586. })
  587. }
  588. }
  589. }
  590. },
  591. //设备下拉
  592. changedevice: function(e) {
  593. var that = this
  594. wx.showToast({
  595. title: '刷新中',
  596. icon: 'loading',
  597. duration: 2000
  598. })
  599. that.setData({
  600. deviceIndex: e.detail.value
  601. })
  602. var groupName = that.data.groupName[that.data.groupIndex]
  603. var deviceName = that.data.deviceName[that.data.deviceIndex]
  604. wx.setStorageSync('groupName', groupName) //分组名称
  605. wx.setStorageSync('deviceName', deviceName) //设备名称
  606. //获取设备信息
  607. var Message = enloop.deviceMessage(groupName, deviceName)
  608. that.setData({
  609. equipment: Message.Device,
  610. subset: Message.id,
  611. ID: Message.ID,
  612. indexes: 0
  613. }) //记录当前的设备id和分组id
  614. if (Message.modules == 0) {
  615. that.setData({
  616. play: 0,
  617. deviceKey: Message.deviceKey,
  618. deviceId: Message.deviceId
  619. })
  620. getBasic(Message.deviceId, Message.deviceKey).then(res => {
  621. if (res.data.errno == 0) {
  622. if (res.data.data.online == true) {
  623. that.setData({
  624. status: '在线'
  625. })
  626. } else {
  627. that.setData({
  628. status: '离线'
  629. })
  630. }
  631. getData(Message.deviceId, Message.deviceKey).then(ever => {
  632. if (ever.data.errno == 0) {
  633. let {
  634. data
  635. } = ever.data
  636. //判断设备是否处于初始化状态
  637. var initialization = true
  638. for (let t = 0; t < data.length; t++) {
  639. if ('current_value' in data[t] == false) {
  640. initialization = false
  641. }
  642. }
  643. if (initialization == true) {
  644. let loopnum = Message.loopnum
  645. var Summary = enloop.deviceinfo(data, loopnum, that.data
  646. .arr, that.data.brr, that.data.time, that.data
  647. .state,
  648. that.data.state1, that.data.fixed1, that.data
  649. .fixed2, that.data.fixed3,
  650. that.data.fixed4, that.data.address, that.data
  651. .radio1, that.data.radio2,
  652. that.data.radio3, that.data.index, that.data.indexs)
  653. that.setData({
  654. crr: Summary.crr,
  655. arr: Summary.arr,
  656. brr: Summary.brr,
  657. fixed1: Summary.fixed1,
  658. fixed2: Summary.fixed2,
  659. fixed3: Summary.fixed3,
  660. fixed4: Summary.fixed4,
  661. index: Summary.index,
  662. indexs: Summary.indexs,
  663. radio1: Summary.radio1,
  664. radio2: Summary.radio2,
  665. radio3: Summary.radio3,
  666. recorddate: Summary.recorddate,
  667. state: Summary.state,
  668. state1: Summary.state1,
  669. time: Summary.time,
  670. address: Summary.address,
  671. play: 0
  672. })
  673. //监视开关状态(改变颜色,调整功能)
  674. switch (that.data.state[0]) {
  675. case true:
  676. that.setData({
  677. type1: "time",
  678. timecontrolcolor1: "blue",
  679. fontcolor1: "white",
  680. })
  681. break;
  682. default:
  683. that.setData({
  684. type1: "",
  685. timecontrolcolor1: "#888888",
  686. fontcolor1: "#cccccc",
  687. })
  688. break;
  689. }
  690. switch (that.data.state[1]) {
  691. case true:
  692. that.setData({
  693. type2: "time",
  694. timecontrolcolor2: "blue",
  695. fontcolor2: "white",
  696. })
  697. break;
  698. default:
  699. that.setData({
  700. type2: "",
  701. timecontrolcolor2: "#888888",
  702. fontcolor2: "#cccccc",
  703. })
  704. break;
  705. }
  706. switch (that.data.state1[0]) {
  707. case true:
  708. that.setData({
  709. type3: "time",
  710. timecontrolcolor3: "blue",
  711. fontcolor3: "white",
  712. })
  713. break;
  714. default:
  715. that.setData({
  716. type3: "",
  717. timecontrolcolor3: "#888888",
  718. fontcolor3: "#cccccc",
  719. })
  720. break;
  721. }
  722. switch (that.data.state1[1]) {
  723. case true:
  724. that.setData({
  725. type4: "time",
  726. timecontrolcolor4: "blue",
  727. fontcolor4: "white",
  728. })
  729. break;
  730. default:
  731. that.setData({
  732. type4: "",
  733. timecontrolcolor4: "#888888",
  734. fontcolor4: "#cccccc",
  735. })
  736. break;
  737. }
  738. switch (that.data.state[2]) {
  739. case true:
  740. that.setData({
  741. Lightcontrolcolor1: "blue",
  742. fontcolor5: "white",
  743. select1: "selector"
  744. })
  745. break;
  746. default:
  747. that.setData({
  748. Lightcontrolcolor1: "#888888",
  749. fontcolor5: "#cccccc",
  750. select1: ""
  751. })
  752. break;
  753. }
  754. switch (that.data.state[3]) {
  755. case true:
  756. that.setData({
  757. Lightcontrolcolor2: "blue",
  758. fontcolor6: "white",
  759. select2: "selector"
  760. })
  761. break;
  762. default:
  763. that.setData({
  764. Lightcontrolcolor2: "#888888",
  765. fontcolor6: "#cccccc",
  766. select2: ""
  767. })
  768. break;
  769. }
  770. } else {
  771. getDevice(Message.Device, Message.id).then(rgb => {
  772. if (rgb.data.code == 0) {
  773. var rgbs = rgb.data.data.circuits
  774. rgbs = rgbs.split(',')
  775. that.setData({
  776. crr: rgbs
  777. })
  778. } else {
  779. wx.showModal({
  780. title: '错误',
  781. content: rgb.data.msg,
  782. showCancel: false
  783. })
  784. }
  785. })
  786. }
  787. } else {
  788. wx.showModal({
  789. title: '错误',
  790. content: ever.data.error,
  791. showCancel: false
  792. })
  793. }
  794. })
  795. } else {
  796. wx.showModal({
  797. title: '错误',
  798. content: res.data.error,
  799. showCancel: false
  800. })
  801. }
  802. })
  803. } else {
  804. that.setData({
  805. play: 1
  806. })
  807. //新设备在线状态
  808. getDevice(Message.Device, Message.id).then(nrg => {
  809. if (nrg.data.code == 0) {
  810. var nrg = nrg.data.data
  811. if (nrg.status == 1) {
  812. that.setData({
  813. status: '在线'
  814. })
  815. } else {
  816. that.setData({
  817. status: '离线'
  818. })
  819. }
  820. getloop(Message.Device).then(suc => {
  821. if (suc.data.code == 0) {
  822. var suc = suc.data.data
  823. var index = that.data.indexes
  824. for (let i = 0; i < suc.length; i++) {
  825. if (index == i) {
  826. let Suc = suc[i]
  827. var newSwitch = that.data.newSwitch
  828. var timeValue = that.data.timeValue
  829. var newSwitchstate = that.data.newSwitchstate
  830. var choice = that.data.choice
  831. var lightCondition = Suc.lightControlCondition
  832. var model = Suc.ctlMode
  833. var beginTime = Suc.realTimeCondition1OnTime
  834. var closeTimes = Suc.realTimeCondition1OffTime
  835. //光控启动条件
  836. looplightlist().then(res => {
  837. if (res.data.code == 0) {
  838. var lightlist = res.data.data
  839. that.setData({
  840. lightlist: lightlist
  841. })
  842. for (let i = 0; i < lightlist
  843. .length; i++) {
  844. choice[i] = false
  845. }
  846. if (lightCondition.includes(',') ==
  847. true) {
  848. lightCondition = lightCondition
  849. .split(',')
  850. for (let j = 0; j < lightCondition
  851. .length; j++) {
  852. if (lightCondition[j] == '1') {
  853. choice[0] = true
  854. } else if (lightCondition[j] ==
  855. '2') {
  856. choice[1] = true
  857. } else if (lightCondition[j] ==
  858. '3') {
  859. choice[2] = true
  860. } else if (lightCondition[j] ==
  861. '4') {
  862. choice[3] = true
  863. }
  864. }
  865. } else {
  866. if (lightCondition == '1') {
  867. choice[0] = true
  868. } else if (lightCondition == '2') {
  869. choice[1] = true
  870. } else if (lightCondition == '3') {
  871. choice[2] = true
  872. } else if (lightCondition == '4') {
  873. choice[3] = true
  874. }
  875. }
  876. that.setData({
  877. choice: choice
  878. })
  879. } else {
  880. wx.showModal({
  881. title: '错误',
  882. content: res.data.msg,
  883. showCancel: false
  884. })
  885. }
  886. })
  887. //时控1
  888. if (Suc.timeCondition1Switch == 1) {
  889. newSwitch[0] = true
  890. newSwitchstate[0] = 'time'
  891. } else {
  892. newSwitch[0] = false
  893. newSwitchstate[0] = ''
  894. }
  895. timeValue[0] = Suc.timeCondition1OnTime
  896. timeValue[1] = Suc.timeCondition1OffTime
  897. //时控2
  898. if (Suc.timeCondition2Switch == 1) {
  899. newSwitch[1] = true
  900. newSwitchstate[1] = 'time'
  901. } else {
  902. newSwitch[1] = false
  903. newSwitchstate[1] = ''
  904. }
  905. timeValue[2] = Suc.timeCondition2OnTime
  906. timeValue[3] = Suc.timeCondition2OffTime
  907. //光控
  908. if (Suc.lightControlSwitch == 1) {
  909. newSwitch[2] = true
  910. newSwitchstate[2] = 'time'
  911. } else {
  912. newSwitch[2] = false
  913. newSwitchstate[2] = ''
  914. }
  915. timeValue[4] = Suc.lightControlStart
  916. timeValue[5] = Suc.lightControlEnd
  917. for (let j = 0; j < timeValue.length; j++) {
  918. if (timeValue[j] == "") {
  919. timeValue[j] = '00:00'
  920. }
  921. }
  922. var messageNum = Message.loopnum
  923. messageNum.push('所有回路')
  924. that.setData({
  925. crr:messageNum,
  926. timeValue: timeValue,
  927. newSwitch: newSwitch,
  928. })
  929. //监视新设备开关状态
  930. var newSwitchs = that.data.newSwitch
  931. var newfonts = that.data.newfont
  932. var newcolors = that.data.newcolor
  933. var newSwitchstates = that.data.newSwitchstate
  934. var disableds = that.data.disabled
  935. if (newSwitchs[0] == true) {
  936. newfonts[0] = "white"
  937. newcolors[0] = "blue"
  938. newSwitchstates[0] = "time"
  939. } else {
  940. newfonts[0] = "#cccccc"
  941. newcolors[0] = "#888888"
  942. newSwitchstates[0] = ""
  943. }
  944. if (newSwitchs[1] == true) {
  945. newfonts[1] = "white"
  946. newcolors[1] = "blue"
  947. newSwitchstates[1] = "time"
  948. } else {
  949. newfonts[1] = "#cccccc"
  950. newcolors[1] = "#888888"
  951. newSwitchstates[1] = ""
  952. }
  953. if (newSwitchs[2] == true) {
  954. newfonts[2] = "white"
  955. newcolors[2] = "blue"
  956. newSwitchstates[2] = "time"
  957. disableds = false
  958. } else {
  959. newfonts[2] = "#cccccc"
  960. newcolors[2] = "#888888"
  961. newSwitchstates[2] = ""
  962. disableds = true
  963. }
  964. that.setData({
  965. newcolor: newcolors,
  966. newfont: newfonts,
  967. newSwitch: newSwitchs,
  968. newSwitchstate: newSwitchstates,
  969. disabled: disableds,
  970. newChange:model,
  971. beginTime:beginTime,
  972. closeTimes:closeTimes
  973. })
  974. }
  975. }
  976. } else {
  977. console.log('获取新设备回路参数失败')
  978. wx.showModal({
  979. title: '错误',
  980. content: suc.data.msg,
  981. showCancel: false
  982. })
  983. }
  984. })
  985. } else {
  986. console.log('新设备获取信息失败')
  987. wx.showModal({
  988. title: '错误',
  989. content: nrg.data.msg,
  990. showCancel: false
  991. })
  992. }
  993. })
  994. }
  995. },
  996. //回路调控
  997. bindPickerChange3: function(e) {
  998. wx.showToast({
  999. title: '刷新中',
  1000. icon: 'loading',
  1001. duration: 2000
  1002. })
  1003. var that = this
  1004. var play = that.data.play
  1005. var indexes = parseInt(e.detail.value)
  1006. that.setData({
  1007. indexes: indexes
  1008. })
  1009. //旧设备
  1010. if (play == 0) {
  1011. getData(that.data.deviceId, that.data.deviceKey).then(res => {
  1012. if (res.data.errno == 0) {
  1013. var {
  1014. data
  1015. } = res.data
  1016. var Indexes = that.data.indexes
  1017. Indexes = Indexes + 1
  1018. var crr = that.data.crr.length
  1019. if (Indexes == crr) {
  1020. } else {
  1021. //以下为回路
  1022. for (let i = 1; i < data.length; i++) {
  1023. //时控一开时间
  1024. if (data[i].id == "R" + Indexes + "_DayOpenTime1") {
  1025. var timeopen1 = data[i].current_value
  1026. }
  1027. //时控一关时间
  1028. else if (data[i].id == "R" + Indexes + "_DayCloseTime1") {
  1029. var timeshut1 = data[i].current_value
  1030. }
  1031. //时控二开时间
  1032. else if (data[i].id == "R" + Indexes + "_DayOpenTime2") {
  1033. var timeopen2 = data[i].current_value
  1034. }
  1035. //时控二关时间
  1036. else if (data[i].id == "R" + Indexes + "_DayCloseTime2") {
  1037. var timeshut2 = data[i].current_value
  1038. }
  1039. //日期调控
  1040. else if (data[i].id == "R" + Indexes + "_Week") {
  1041. var weeks = data[i].current_value
  1042. that.setData({
  1043. recorddate: weeks
  1044. })
  1045. weeks = parseInt(weeks)
  1046. weeks = weeks.toString(2)
  1047. weeks = weeks + ''
  1048. if (weeks != '0') {
  1049. weeks = weeks.slice(1)
  1050. }
  1051. }
  1052. //功能一
  1053. else if (data[i].id == "R" + Indexes + "_FunctionStatus1") {
  1054. var Function1 = data[i].current_value
  1055. var par = parseInt(Function1)
  1056. par = par.toString(2)
  1057. par = par + ''
  1058. switch (par.length) {
  1059. case 1:
  1060. par = '00000' + par
  1061. break;
  1062. case 2:
  1063. par = '0000' + par
  1064. break;
  1065. case 3:
  1066. par = '000' + par
  1067. break;
  1068. case 4:
  1069. par = '00' + par
  1070. break;
  1071. case 5:
  1072. par = '0' + par
  1073. break;
  1074. default:
  1075. par = par
  1076. }
  1077. }
  1078. //功能二
  1079. else if (data[i].id == "R" + Indexes + "_FunctionStatus2") {
  1080. var Function2 = data[i].current_value
  1081. var qur = parseInt(Function2)
  1082. qur = qur.toString(2)
  1083. qur = qur + ''
  1084. switch (qur.length) {
  1085. case 1:
  1086. qur = '000' + qur
  1087. break;
  1088. case 2:
  1089. qur = '00' + qur
  1090. break;
  1091. case 3:
  1092. qur = '0' + qur
  1093. break;
  1094. case 4:
  1095. qur = qur
  1096. break;
  1097. }
  1098. }
  1099. //报警
  1100. else if (data[i].id == "R" + Indexes + "_RelayStatus") {
  1101. var police = data[i].current_value
  1102. }
  1103. //光控开
  1104. else if (data[i].id == "R" + Indexes + "_LcOn") {
  1105. var Lightcontrolopen = data[i].current_value
  1106. var trr = that.data.arr
  1107. for (let i = 0; i < 100; i++) {
  1108. trr[i] = i
  1109. }
  1110. Lightcontrolopen = parseInt(Lightcontrolopen)
  1111. that.setData({
  1112. arr: trr,
  1113. index: Lightcontrolopen
  1114. })
  1115. }
  1116. //光控关
  1117. else if (data[i].id == "R" + Indexes + "_LcOff") {
  1118. var Lightcontrolshut = data[i].current_value
  1119. var prr = that.data.brr
  1120. for (let j = 0; j < 100; j++) {
  1121. prr[j] = j
  1122. }
  1123. Lightcontrolshut = parseInt(Lightcontrolshut)
  1124. that.setData({
  1125. brr: prr,
  1126. indexs: Lightcontrolshut
  1127. })
  1128. }
  1129. }
  1130. //时控一开时间
  1131. var timeOpen1
  1132. switch (timeopen1.length) {
  1133. case 1:
  1134. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0, 1)
  1135. break;
  1136. case 2:
  1137. timeOpen1 = '00' + ':' + timeopen1.substring(0, 2)
  1138. break;
  1139. case 3:
  1140. var timeOpen1 = '0' + timeopen1.substring(0, 1) + ':' + timeopen1
  1141. .substring(1, 3)
  1142. break;
  1143. case 4:
  1144. var timeOpen1 = timeopen1.substring(0, 2) + ':' + timeopen1
  1145. .substring(2, 4)
  1146. break;
  1147. }
  1148. //时控一关时间
  1149. var timeShut1
  1150. switch (timeshut1.length) {
  1151. case 1:
  1152. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0, 1)
  1153. break;
  1154. case 2:
  1155. timeShut1 = '00' + ':' + timeshut1.substring(0, 2)
  1156. break;
  1157. case 3:
  1158. var timeShut1 = '0' + timeshut1.substring(0, 1) + ':' + timeshut1
  1159. .substring(1, 3)
  1160. break;
  1161. case 4:
  1162. var timeShut1 = timeshut1.substring(0, 2) + ':' + timeshut1
  1163. .substring(2, 4)
  1164. break;
  1165. }
  1166. //时控二开时间
  1167. var timeOpen2
  1168. switch (timeopen2.length) {
  1169. case 1:
  1170. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0, 1)
  1171. break;
  1172. case 2:
  1173. timeOpen2 = '00' + ':' + timeopen2.substring(0, 2)
  1174. break;
  1175. case 3:
  1176. var timeOpen2 = '0' + timeopen2.substring(0, 1) + ':' + timeopen2
  1177. .substring(1, 3)
  1178. break;
  1179. case 4:
  1180. var timeOpen2 = timeopen2.substring(0, 2) + ':' + timeopen2
  1181. .substring(2, 4)
  1182. break;
  1183. }
  1184. //时控二关时间
  1185. var timeShut2
  1186. switch (timeshut2.length) {
  1187. case 1:
  1188. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0, 1)
  1189. break;
  1190. case 2:
  1191. timeShut2 = '00' + ':' + timeshut2.substring(0, 2)
  1192. break;
  1193. case 3:
  1194. var timeShut2 = '0' + timeshut2.substring(0, 1) + ':' + timeshut2
  1195. .substring(1, 3)
  1196. break;
  1197. case 4:
  1198. var timeShut2 = timeshut2.substring(0, 2) + ':' + timeshut2
  1199. .substring(2, 4)
  1200. break;
  1201. }
  1202. //功能1
  1203. for (var i = 0; i < par.length; i++) {
  1204. var engry = that.data.state
  1205. switch (par.substring(i, i + 1)) {
  1206. case "0":
  1207. switch (i) {
  1208. case 0:
  1209. engry[3] = false
  1210. that.setData({
  1211. state: engry
  1212. })
  1213. break;
  1214. case 1:
  1215. engry[2] = false
  1216. that.setData({
  1217. state: engry
  1218. })
  1219. break;
  1220. case 2:
  1221. that.setData({
  1222. fixed2: "固定"
  1223. })
  1224. break;
  1225. case 3:
  1226. that.setData({
  1227. fixed1: "固定"
  1228. })
  1229. break;
  1230. case 4:
  1231. engry[1] = false
  1232. that.setData({
  1233. state: engry
  1234. })
  1235. break;
  1236. case 5:
  1237. engry[0] = false
  1238. that.setData({
  1239. state: engry
  1240. })
  1241. break;
  1242. }
  1243. break;
  1244. case "1":
  1245. switch (i) {
  1246. case 0:
  1247. engry[3] = true
  1248. that.setData({
  1249. state: engry
  1250. })
  1251. break;
  1252. case 1:
  1253. engry[2] = true
  1254. that.setData({
  1255. state: engry
  1256. })
  1257. break;
  1258. case 2:
  1259. that.setData({
  1260. fixed2: "经纬"
  1261. })
  1262. break;
  1263. case 3:
  1264. that.setData({
  1265. fixed1: "经纬"
  1266. })
  1267. break;
  1268. case 4:
  1269. engry[1] = true
  1270. that.setData({
  1271. state: engry
  1272. })
  1273. break;
  1274. case 5:
  1275. engry[0] = true
  1276. that.setData({
  1277. state: engry
  1278. })
  1279. break;
  1280. }
  1281. break;
  1282. }
  1283. }
  1284. //功能2
  1285. for (let j = 0; j < qur.length; j++) {
  1286. var Engry = that.data.state1
  1287. switch (qur.substring(j, j + 1)) {
  1288. case "0":
  1289. switch (j) {
  1290. case 0:
  1291. that.setData({
  1292. fixed4: "固定"
  1293. })
  1294. break;
  1295. case 1:
  1296. that.setData({
  1297. fixed3: "固定"
  1298. })
  1299. break;
  1300. case 2:
  1301. Engry[1] = false
  1302. that.setData({
  1303. state1: Engry
  1304. })
  1305. break;
  1306. case 3:
  1307. Engry[0] = false
  1308. that.setData({
  1309. state1: Engry
  1310. })
  1311. break;
  1312. }
  1313. break;
  1314. case "1":
  1315. switch (j) {
  1316. case 0:
  1317. that.setData({
  1318. fixed4: "经纬"
  1319. })
  1320. break;
  1321. case 1:
  1322. that.setData({
  1323. fixed3: "经纬"
  1324. })
  1325. break;
  1326. case 2:
  1327. Engry[1] = true
  1328. that.setData({
  1329. state1: Engry
  1330. })
  1331. break;
  1332. case 3:
  1333. Engry[0] = true
  1334. that.setData({
  1335. state1: Engry
  1336. })
  1337. break;
  1338. }
  1339. break;
  1340. }
  1341. }
  1342. //日期调控
  1343. var controladdress = that.data.address
  1344. if (weeks == '0') {
  1345. for (let x = 0; x < 7; x++) {
  1346. controladdress[x] = "/image/false.png"
  1347. }
  1348. that.setData({
  1349. address: controladdress,
  1350. })
  1351. } else {
  1352. for (let i = 0; i < weeks.length; i++) {
  1353. switch (weeks.substring(i, i + 1)) {
  1354. case '0':
  1355. controladdress[weeks.length - i - 1] = "/image/false.png"
  1356. that.setData({
  1357. address: controladdress,
  1358. })
  1359. break;
  1360. case '1':
  1361. controladdress[weeks.length - i - 1] = "/image/true.png"
  1362. that.setData({
  1363. address: controladdress,
  1364. })
  1365. break;
  1366. }
  1367. }
  1368. }
  1369. //报警状态
  1370. police = parseInt(police)
  1371. police = police.toString(2)
  1372. switch (police.length) {
  1373. case 1:
  1374. police = '000' + police
  1375. break;
  1376. case 2:
  1377. police = '00' + police
  1378. break;
  1379. case 3:
  1380. police = '0' + police
  1381. break;
  1382. default:
  1383. police = police
  1384. break;
  1385. }
  1386. if (police.substring(1, 2) == '0' && police.substring(0, 1) == '0') {
  1387. that.setData({
  1388. radio1: true
  1389. })
  1390. } else if (police.substring(1, 2) == '1' && police.substring(0, 1) == '0') {
  1391. that.setData({
  1392. radio2: true
  1393. })
  1394. } else if (police.substring(1, 2) == '0' && police.substring(0, 1) == '1') {
  1395. that.setData({
  1396. radio3: true
  1397. })
  1398. }
  1399. var time = that.data.time
  1400. time[0] = timeOpen1
  1401. time[1] = timeShut1
  1402. time[2] = timeOpen2
  1403. time[3] = timeShut2
  1404. that.setData({
  1405. time: time
  1406. })
  1407. switch (that.data.state[0]) {
  1408. case true:
  1409. that.setData({
  1410. type1: "time",
  1411. timecontrolcolor1: "blue",
  1412. fontcolor1: "white",
  1413. })
  1414. break;
  1415. default:
  1416. that.setData({
  1417. type1: "",
  1418. timecontrolcolor1: "#888888",
  1419. fontcolor1: "#cccccc",
  1420. })
  1421. break;
  1422. }
  1423. switch (that.data.state[1]) {
  1424. case true:
  1425. that.setData({
  1426. type2: "time",
  1427. timecontrolcolor2: "blue",
  1428. fontcolor2: "white",
  1429. })
  1430. break;
  1431. default:
  1432. that.setData({
  1433. type2: "",
  1434. timecontrolcolor2: "#888888",
  1435. fontcolor2: "#cccccc",
  1436. })
  1437. break;
  1438. }
  1439. switch (that.data.state1[0]) {
  1440. case true:
  1441. that.setData({
  1442. type3: "time",
  1443. timecontrolcolor3: "blue",
  1444. fontcolor3: "white",
  1445. })
  1446. break;
  1447. default:
  1448. that.setData({
  1449. type3: "",
  1450. timecontrolcolor3: "#888888",
  1451. fontcolor3: "#cccccc",
  1452. })
  1453. break;
  1454. }
  1455. switch (that.data.state1[1]) {
  1456. case true:
  1457. that.setData({
  1458. type4: "time",
  1459. timecontrolcolor4: "blue",
  1460. fontcolor4: "white",
  1461. })
  1462. break;
  1463. default:
  1464. that.setData({
  1465. type4: "",
  1466. timecontrolcolor4: "#888888",
  1467. fontcolor4: "#cccccc",
  1468. })
  1469. break;
  1470. }
  1471. switch (that.data.state[2]) {
  1472. case true:
  1473. that.setData({
  1474. Lightcontrolcolor1: "blue",
  1475. fontcolor5: "white",
  1476. select1: "selector"
  1477. })
  1478. break;
  1479. default:
  1480. that.setData({
  1481. Lightcontrolcolor1: "#888888",
  1482. fontcolor5: "#cccccc",
  1483. select1: ""
  1484. })
  1485. break;
  1486. }
  1487. switch (that.data.state[3]) {
  1488. case true:
  1489. that.setData({
  1490. Lightcontrolcolor2: "blue",
  1491. fontcolor6: "white",
  1492. select2: "selector"
  1493. })
  1494. break;
  1495. default:
  1496. that.setData({
  1497. Lightcontrolcolor2: "#888888",
  1498. fontcolor6: "#cccccc",
  1499. select2: ""
  1500. })
  1501. break;
  1502. }
  1503. }
  1504. } else {
  1505. wx.showModal({
  1506. title: '错误',
  1507. content: res.data.error,
  1508. showCancel: false
  1509. })
  1510. }
  1511. })
  1512. }
  1513. //新设备
  1514. else {
  1515. var Equip = that.data.equipment //设备id
  1516. var crr = that.data.crr
  1517. if(crr[indexes] == '所有回路'){
  1518. return
  1519. }
  1520. getloop(Equip).then(suc => {
  1521. if (suc.data.code == 0) {
  1522. var suc = suc.data.data
  1523. var index = that.data.indexes
  1524. for (let i = 0; i < suc.length; i++) {
  1525. if (index == i) {
  1526. let Suc = suc[i]
  1527. var newSwitch = that.data.newSwitch
  1528. var timeValue = that.data.timeValue
  1529. var newSwitchstate = that.data.newSwitchstate
  1530. var choice = that.data.choice
  1531. var lightCondition = Suc.lightControlCondition
  1532. var model = Suc.ctlMode
  1533. var beginTime = Suc.realTimeCondition1OnTime
  1534. var closeTimes = Suc.realTimeCondition1OffTime
  1535. //光控启动条件
  1536. looplightlist().then(res => {
  1537. if (res.data.code == 0) {
  1538. var lightlist = res.data.data
  1539. that.setData({
  1540. lightlist: lightlist
  1541. })
  1542. for (let i = 0; i < lightlist.length; i++) {
  1543. choice[i] = false
  1544. }
  1545. if (lightCondition.includes(',') == true) {
  1546. lightCondition = lightCondition.split(',')
  1547. for (let j = 0; j < lightCondition.length; j++) {
  1548. if (lightCondition[j] == '1') {
  1549. choice[0] = true
  1550. } else if (lightCondition[j] == '2') {
  1551. choice[1] = true
  1552. } else if (lightCondition[j] == '3') {
  1553. choice[2] = true
  1554. } else if (lightCondition[j] == '4') {
  1555. choice[3] = true
  1556. }
  1557. }
  1558. } else {
  1559. if (lightCondition == '1') {
  1560. choice[0] = true
  1561. } else if (lightCondition == '2') {
  1562. choice[1] = true
  1563. } else if (lightCondition == '3') {
  1564. choice[2] = true
  1565. } else if (lightCondition == '4') {
  1566. choice[3] = true
  1567. }
  1568. }
  1569. that.setData({
  1570. choice: choice
  1571. })
  1572. } else {
  1573. wx.showModal({
  1574. title: '错误',
  1575. content: res.data.msg,
  1576. showCancel: false
  1577. })
  1578. }
  1579. })
  1580. //时控1
  1581. if (Suc.timeCondition1Switch == 1) {
  1582. newSwitch[0] = true
  1583. newSwitchstate[0] = 'time'
  1584. } else {
  1585. newSwitch[0] = false
  1586. newSwitchstate[0] = ''
  1587. }
  1588. timeValue[0] = Suc.timeCondition1OnTime
  1589. timeValue[1] = Suc.timeCondition1OffTime
  1590. //时控2
  1591. if (Suc.timeCondition2Switch == 1) {
  1592. newSwitch[1] = true
  1593. newSwitchstate[1] = 'time'
  1594. } else {
  1595. newSwitch[1] = false
  1596. newSwitchstate[1] = ''
  1597. }
  1598. timeValue[2] = Suc.timeCondition2OnTime
  1599. timeValue[3] = Suc.timeCondition2OffTime
  1600. //光控
  1601. if (Suc.lightControlSwitch == 1) {
  1602. newSwitch[2] = true
  1603. newSwitchstate[2] = 'time'
  1604. newSwitchstate[3] = 'selector'
  1605. } else {
  1606. newSwitch[2] = false
  1607. newSwitchstate[2] = ''
  1608. newSwitchstate[3] = ''
  1609. }
  1610. timeValue[4] = Suc.lightControlStart
  1611. timeValue[5] = Suc.lightControlEnd
  1612. for (let j = 0; j < timeValue.length; j++) {
  1613. if (timeValue[j] == "") {
  1614. timeValue[j] = '00:00'
  1615. }
  1616. }
  1617. that.setData({
  1618. timeValue: timeValue,
  1619. newSwitch: newSwitch,
  1620. newChange:model,
  1621. beginTime:beginTime,
  1622. closeTimes:closeTimes
  1623. })
  1624. //监视新设备开关状态
  1625. var newSwitchs = that.data.newSwitch
  1626. var newfonts = that.data.newfont
  1627. var newcolors = that.data.newcolor
  1628. var newSwitchstates = that.data.newSwitchstate
  1629. var disableds = that.data.disabled
  1630. if (newSwitchs[0] == true) {
  1631. newfonts[0] = "white"
  1632. newcolors[0] = "blue"
  1633. newSwitchstates[0] = "time"
  1634. } else {
  1635. newfonts[0] = "#cccccc"
  1636. newcolors[0] = "#888888"
  1637. newSwitchstates[0] = ""
  1638. }
  1639. if (newSwitchs[1] == true) {
  1640. newfonts[1] = "white"
  1641. newcolors[1] = "blue"
  1642. newSwitchstates[1] = "time"
  1643. } else {
  1644. newfonts[1] = "#cccccc"
  1645. newcolors[1] = "#888888"
  1646. newSwitchstates[1] = ""
  1647. }
  1648. if (newSwitchs[2] == true) {
  1649. newfonts[2] = "white"
  1650. newcolors[2] = "blue"
  1651. newSwitchstates[2] = "time"
  1652. disableds = false
  1653. } else {
  1654. newfonts[2] = "#cccccc"
  1655. newcolors[2] = "#888888"
  1656. newSwitchstates[2] = ""
  1657. disableds = true
  1658. }
  1659. that.setData({
  1660. newcolor: newcolors,
  1661. newfont: newfonts,
  1662. newSwitch: newSwitchs,
  1663. newSwitchstate: newSwitchstates,
  1664. disabled: disableds
  1665. })
  1666. }
  1667. }
  1668. } else {
  1669. console.log('获取新设备回路参数失败')
  1670. wx.showModal({
  1671. title: '错误',
  1672. content: suc.data.msg,
  1673. showCancel: false
  1674. })
  1675. }
  1676. })
  1677. }
  1678. },
  1679. //新设备模式切换
  1680. openModal(){
  1681. var that = this
  1682. var openModal = that.data.openModal
  1683. openModal = openModal == '手动' ? '经纬' : '手动'
  1684. that.setData({openModal:openModal})
  1685. },
  1686. shutModal(){
  1687. var that = this
  1688. var shutModal = that.data.shutModal
  1689. shutModal = shutModal == '手动' ? '经纬' : '手动'
  1690. that.setData({shutModal:shutModal})
  1691. },
  1692. //时间调控
  1693. //时控开关选择器(1-4旧设备,5-6新设备)
  1694. Controltime1: function() {
  1695. var obtain1 = this.data.state
  1696. obtain1[0] = !obtain1[0]
  1697. if (obtain1[0] == true) {
  1698. this.setData({
  1699. type1: "time",
  1700. timecontrolcolor1: "blue",
  1701. fontcolor1: "white",
  1702. state: obtain1
  1703. })
  1704. } else {
  1705. this.setData({
  1706. type1: "",
  1707. timecontrolcolor1: "#888888",
  1708. fontcolor1: "#cccccc",
  1709. state: obtain1
  1710. })
  1711. }
  1712. },
  1713. Controltime2: function() {
  1714. var obtain2 = this.data.state
  1715. obtain2[1] = !obtain2[1]
  1716. if (obtain2[1] == true) {
  1717. this.setData({
  1718. type2: "time",
  1719. timecontrolcolor2: "blue",
  1720. fontcolor2: "white",
  1721. state: obtain2
  1722. })
  1723. } else {
  1724. this.setData({
  1725. type2: "",
  1726. timecontrolcolor2: "#888888",
  1727. fontcolor2: "#cccccc",
  1728. state: obtain2
  1729. })
  1730. }
  1731. },
  1732. Controltime3: function() {
  1733. var obtain3 = this.data.state1
  1734. obtain3[0] = !obtain3[0]
  1735. if (obtain3[0] == true) {
  1736. this.setData({
  1737. type3: "time",
  1738. timecontrolcolor3: "blue",
  1739. fontcolor3: "white",
  1740. state1: obtain3
  1741. })
  1742. } else {
  1743. this.setData({
  1744. type3: "",
  1745. timecontrolcolor3: "#888888",
  1746. fontcolor3: "#cccccc",
  1747. state1: obtain3
  1748. })
  1749. }
  1750. },
  1751. Controltime4: function() {
  1752. var obtain4 = this.data.state1
  1753. obtain4[1] = !obtain4[1]
  1754. if (obtain4[1] == true) {
  1755. this.setData({
  1756. type4: "time",
  1757. timecontrolcolor4: "blue",
  1758. fontcolor4: "white",
  1759. state1: obtain4
  1760. })
  1761. } else {
  1762. this.setData({
  1763. type4: "",
  1764. timecontrolcolor4: "#888888",
  1765. fontcolor4: "#cccccc",
  1766. state1: obtain4
  1767. })
  1768. }
  1769. },
  1770. Controltime6: function() {
  1771. let newSwitch = this.data.newSwitch
  1772. let newcolor = this.data.newcolor
  1773. let newfont = this.data.newfont
  1774. let newSwitchstate = this.data.newSwitchstate
  1775. newSwitch[1] = !newSwitch[1]
  1776. if (newSwitch[1] == true) {
  1777. newcolor[1] = "blue"
  1778. newfont[1] = "white"
  1779. newSwitchstate[1] = "time"
  1780. } else {
  1781. newcolor[1] = "#888888"
  1782. newfont[1] = "#cccccc"
  1783. newSwitchstate[1] = ""
  1784. }
  1785. this.setData({
  1786. newSwitch: newSwitch,
  1787. newcolor: newcolor,
  1788. newfont: newfont,
  1789. newSwitchstate: newSwitchstate
  1790. })
  1791. },
  1792. Controltime7: function() {
  1793. let newSwitch = this.data.newSwitch
  1794. let newcolor = this.data.newcolor
  1795. let newfont = this.data.newfont
  1796. let newSwitchstate = this.data.newSwitchstate
  1797. let disabled = this.data.disabled
  1798. newSwitch[2] = !newSwitch[2]
  1799. if (newSwitch[2] == true) {
  1800. newcolor[2] = "blue"
  1801. newfont[2] = "white"
  1802. newSwitchstate[2] = "time"
  1803. newSwitchstate[3] = "selector"
  1804. disabled = false
  1805. } else {
  1806. newcolor[2] = "#888888"
  1807. newfont[2] = "#cccccc"
  1808. newSwitchstate[2] = ""
  1809. newSwitchstate[3] = ""
  1810. disabled = true
  1811. }
  1812. this.setData({
  1813. newSwitch: newSwitch,
  1814. newcolor: newcolor,
  1815. newfont: newfont,
  1816. newSwitchstate: newSwitchstate,
  1817. disabled: disabled
  1818. })
  1819. },
  1820. //固定与经纬的切换
  1821. change1: function() {
  1822. var change1 = this.data.fixed1
  1823. if (change1 == "固定" && this.data.state[0] == true) {
  1824. this.setData({
  1825. fixed1: "经纬"
  1826. })
  1827. } else if (change1 == "经纬" && this.data.state[0] == true) {
  1828. this.setData({
  1829. fixed1: "固定"
  1830. })
  1831. }
  1832. },
  1833. change2: function() {
  1834. var change2 = this.data.fixed2
  1835. if (change2 == "固定" && this.data.state[1] == true) {
  1836. this.setData({
  1837. fixed2: "经纬"
  1838. })
  1839. } else if (change2 == "经纬" && this.data.state[1] == true) {
  1840. this.setData({
  1841. fixed2: "固定"
  1842. })
  1843. }
  1844. },
  1845. change3: function() {
  1846. var change3 = this.data.fixed3
  1847. if (change3 == "固定") {
  1848. this.setData({
  1849. fixed3: "经纬"
  1850. })
  1851. } else {
  1852. this.setData({
  1853. fixed3: "固定"
  1854. })
  1855. }
  1856. },
  1857. change4: function() {
  1858. var change4 = this.data.fixed4
  1859. if (change4 == "固定") {
  1860. this.setData({
  1861. fixed4: "经纬"
  1862. })
  1863. } else {
  1864. this.setData({
  1865. fixed4: "固定"
  1866. })
  1867. }
  1868. },
  1869. //显示改变后的时间的值(1-4旧设备,5-11新设备)
  1870. bindTimeChange1: function(e) {
  1871. let time = this.data.time
  1872. time[0] = e.detail.value
  1873. this.setData({
  1874. time: time
  1875. })
  1876. },
  1877. bindTimeChange2: function(e) {
  1878. let time = this.data.time
  1879. time[1] = e.detail.value
  1880. this.setData({
  1881. time: time
  1882. })
  1883. },
  1884. bindTimeChange3: function(e) {
  1885. let time = this.data.time
  1886. time[2] = e.detail.value
  1887. this.setData({
  1888. time: time
  1889. })
  1890. },
  1891. bindTimeChange4: function(e) {
  1892. let time = this.data.time
  1893. time[3] = e.detail.value
  1894. this.setData({
  1895. time: time
  1896. })
  1897. },
  1898. bindTimeChange5: function(e) {
  1899. let time = this.data.timeValue
  1900. time[0] = e.detail.value
  1901. this.setData({
  1902. timeValue: time
  1903. })
  1904. },
  1905. bindTimeChange6: function(e) {
  1906. let time = this.data.timeValue
  1907. time[1] = e.detail.value
  1908. this.setData({
  1909. timeValue: time
  1910. })
  1911. },
  1912. bindTimeChange7: function(e) {
  1913. let time = this.data.timeValue
  1914. time[2] = e.detail.value
  1915. this.setData({
  1916. timeValue: time
  1917. })
  1918. },
  1919. bindTimeChange8: function(e) {
  1920. let time = this.data.timeValue
  1921. time[3] = e.detail.value
  1922. this.setData({
  1923. timeValue: time
  1924. })
  1925. },
  1926. bindTimeChange9: function(e) {
  1927. let time = this.data.timeValue
  1928. time[4] = e.detail.value
  1929. this.setData({
  1930. timeValue: time
  1931. })
  1932. },
  1933. bindTimeChange10: function(e) {
  1934. let time = this.data.timeValue
  1935. time[5] = e.detail.value
  1936. this.setData({
  1937. timeValue: time
  1938. })
  1939. },
  1940. //日期调控(图片切换)
  1941. setbuty0: function() {
  1942. var that = this
  1943. var a0 = that.data.address
  1944. if (that.data.address[0] == "/image/true.png") {
  1945. a0[0] = "/image/false.png"
  1946. this.setData({
  1947. address: a0,
  1948. })
  1949. } else {
  1950. a0[0] = "/image/true.png"
  1951. this.setData({
  1952. address: a0,
  1953. })
  1954. }
  1955. },
  1956. setbuty1: function() {
  1957. var that = this
  1958. var a1 = that.data.address
  1959. if (that.data.address[1] == "/image/true.png") {
  1960. a1[1] = "/image/false.png"
  1961. this.setData({
  1962. address: a1,
  1963. })
  1964. } else {
  1965. a1[1] = "/image/true.png"
  1966. this.setData({
  1967. address: a1,
  1968. })
  1969. }
  1970. },
  1971. setbuty2: function() {
  1972. var that = this
  1973. var a2 = that.data.address
  1974. if (that.data.address[2] == "/image/true.png") {
  1975. a2[2] = "/image/false.png"
  1976. this.setData({
  1977. address: a2,
  1978. })
  1979. } else {
  1980. a2[2] = "/image/true.png"
  1981. this.setData({
  1982. address: a2,
  1983. })
  1984. }
  1985. },
  1986. setbuty3: function() {
  1987. var that = this
  1988. var a3 = that.data.address
  1989. if (that.data.address[3] == "/image/true.png") {
  1990. a3[3] = "/image/false.png"
  1991. this.setData({
  1992. address: a3,
  1993. })
  1994. } else {
  1995. a3[3] = "/image/true.png"
  1996. this.setData({
  1997. address: a3,
  1998. })
  1999. }
  2000. },
  2001. setbuty4: function() {
  2002. var that = this
  2003. var a4 = that.data.address
  2004. if (that.data.address[4] == "/image/true.png") {
  2005. a4[4] = "/image/false.png"
  2006. this.setData({
  2007. address: a4,
  2008. })
  2009. } else {
  2010. a4[4] = "/image/true.png"
  2011. this.setData({
  2012. address: a4,
  2013. })
  2014. }
  2015. },
  2016. setbuty5: function() {
  2017. var that = this
  2018. var a5 = that.data.address
  2019. if (that.data.address[5] == "/image/true.png") {
  2020. a5[5] = "/image/false.png"
  2021. this.setData({
  2022. address: a5,
  2023. })
  2024. } else {
  2025. a5[5] = "/image/true.png"
  2026. this.setData({
  2027. address: a5,
  2028. })
  2029. }
  2030. },
  2031. setbuty6: function() {
  2032. var that = this
  2033. var a6 = that.data.address
  2034. if (that.data.address[6] == "/image/true.png") {
  2035. a6[6] = "/image/false.png"
  2036. this.setData({
  2037. address: a6,
  2038. })
  2039. } else {
  2040. a6[6] = "/image/true.png"
  2041. this.setData({
  2042. address: a6,
  2043. })
  2044. }
  2045. },
  2046. //光控
  2047. //光控开关选择器
  2048. Controllight1: function() {
  2049. var Lightstatus = this.data.state
  2050. Lightstatus[2] = !Lightstatus[2]
  2051. if (Lightstatus[2] == true) {
  2052. for (let a = 0; a < 100; a++) {
  2053. var arr1 = this.data.arr
  2054. arr1[a] = a
  2055. }
  2056. this.setData({
  2057. arr: arr1,
  2058. fontcolor5: "white",
  2059. Lightcontrolcolor1: "blue",
  2060. select1: "selector"
  2061. })
  2062. } else {
  2063. this.setData({
  2064. Lightcontrolcolor1: "#888888",
  2065. fontcolor5: "#cccccc",
  2066. select1: ""
  2067. })
  2068. }
  2069. },
  2070. Controllight2: function() {
  2071. var Lightstatus = this.data.state
  2072. Lightstatus[3] = !Lightstatus[3]
  2073. if (Lightstatus[3] == true) {
  2074. for (let a = 0; a < 100; a++) {
  2075. var arr1 = this.data.arr
  2076. arr1[a] = a
  2077. }
  2078. this.setData({
  2079. arr: arr1,
  2080. fontcolor6: "white",
  2081. Lightcontrolcolor2: "blue",
  2082. select2: "selector"
  2083. })
  2084. } else {
  2085. this.setData({
  2086. Lightcontrolcolor2: "#888888",
  2087. fontcolor6: "#cccccc",
  2088. select2: ""
  2089. })
  2090. }
  2091. },
  2092. //调整光控显示的值
  2093. bindPickerChange1: function(e) {
  2094. this.setData({
  2095. index: e.detail.value
  2096. })
  2097. },
  2098. bindPickerChange2: function(e) {
  2099. this.setData({
  2100. indexs: e.detail.value
  2101. })
  2102. },
  2103. //报警状态
  2104. Changestate1: function() {
  2105. this.setData({
  2106. radio1: true,
  2107. radio2: false,
  2108. radio3: false,
  2109. alert: "1"
  2110. })
  2111. },
  2112. Changestate2: function() {
  2113. this.setData({
  2114. radio1: false,
  2115. radio2: true,
  2116. radio3: false,
  2117. alert: "5"
  2118. })
  2119. },
  2120. Changestate3: function() {
  2121. this.setData({
  2122. radio1: false,
  2123. radio2: false,
  2124. radio3: true,
  2125. alert: "9"
  2126. })
  2127. },
  2128. //刷新页面
  2129. RefreshPage: function() {
  2130. wx.showToast({
  2131. title: '刷新中',
  2132. icon: 'loading',
  2133. duration: 2000
  2134. })
  2135. var that = this
  2136. //获取机型改变switch大小
  2137. wx.getSystemInfo({
  2138. success: function(res) {
  2139. if (res.model == 'iPad' || res.model == 'iPad Pro 10.5-inch' || res.model ==
  2140. 'iPad Pro 12.9-inch') {
  2141. that.setData({
  2142. zoom: 1
  2143. })
  2144. }
  2145. }
  2146. })
  2147. var group = wx.getStorageSync('group')
  2148. if (group != null && group.length != 0) {
  2149. //分组下拉
  2150. var group = wx.getStorageSync('group')
  2151. var groups = []
  2152. for (let i = 0; i < group.length; i++) {
  2153. groups.push(group[i].groupName)
  2154. }
  2155. that.setData({
  2156. groupName: groups
  2157. })
  2158. //改变分组下标
  2159. if (wx.getStorageSync('groupName') != '') {
  2160. let GroupName = groups
  2161. for (let n = 0; n < GroupName.length; n++) {
  2162. if (GroupName[n] == wx.getStorageSync('groupName')) {
  2163. that.setData({
  2164. groupIndex: n
  2165. })
  2166. }
  2167. }
  2168. } else {
  2169. wx.setStorageSync('groupName', groups[0])
  2170. }
  2171. //设备下拉
  2172. var device = []
  2173. var groupName = that.data.groupName
  2174. var groupIndex = that.data.groupIndex
  2175. for (let j = 0; j < group.length; j++) {
  2176. if (groupName[groupIndex] == group[j].groupName) {
  2177. if (group[j].devices != null && group[j].devices.length != 0) {
  2178. for (let p = 0; p < group[j].devices.length; p++) {
  2179. device.push(group[j].devices[p].deviceName)
  2180. }
  2181. that.setData({
  2182. deviceName: device
  2183. })
  2184. //改变设备下标
  2185. if (wx.getStorageSync('deviceName') != '') {
  2186. for (let m = 0; m < device.length; m++) {
  2187. if (device[m] == wx.getStorageSync('deviceName')) {
  2188. that.setData({
  2189. deviceIndex: m
  2190. })
  2191. }
  2192. }
  2193. } else {
  2194. wx.setStorageSync('deviceName', device[0])
  2195. }
  2196. //获取设备信息
  2197. var currentGroup = that.data.groupName[that.data.groupIndex]
  2198. var currentDevice = that.data.deviceName[that.data.deviceIndex]
  2199. var message = enloop.deviceMessage(currentGroup, currentDevice)
  2200. that.setData({
  2201. equipment: message.Device,
  2202. subset: message.id,
  2203. }) //记录当前的设备id和分组id
  2204. //旧设备
  2205. if (message.modules == 0) {
  2206. that.setData({
  2207. play: 0,
  2208. deviceKey: message.deviceKey,
  2209. deviceId: message.deviceId
  2210. })
  2211. getBasic(message.deviceId, message.deviceKey).then(res => {
  2212. if (res.data.errno == 0) {
  2213. if (res.data.data.online == true) {
  2214. that.setData({
  2215. status: '在线'
  2216. })
  2217. } else {
  2218. that.setData({
  2219. status: '离线'
  2220. })
  2221. }
  2222. getData(message.deviceId, message.deviceKey).then(ever => {
  2223. if (ever.data.errno == 0) {
  2224. var {
  2225. data
  2226. } = ever.data
  2227. //判断设备是否处于初始化状态
  2228. var initialization = true
  2229. for (let t = 0; t < data.length; t++) {
  2230. if ('current_value' in data[t] == false) {
  2231. initialization = false
  2232. }
  2233. }
  2234. if (initialization == true) {
  2235. var Indexes = that.data.indexes
  2236. Indexes = Indexes + 1
  2237. var crr = that.data.crr.length
  2238. if (Indexes == crr) {
  2239. } else {
  2240. //以下为回路
  2241. for (let i = 1; i < data.length; i++) {
  2242. //时控一开时间
  2243. if (data[i].id == "R" + Indexes +
  2244. "_DayOpenTime1") {
  2245. var timeopen1 = data[i]
  2246. .current_value
  2247. }
  2248. //时控一关时间
  2249. else if (data[i].id == "R" +
  2250. Indexes + "_DayCloseTime1") {
  2251. var timeshut1 = data[i]
  2252. .current_value
  2253. }
  2254. //时控二开时间
  2255. else if (data[i].id == "R" +
  2256. Indexes + "_DayOpenTime2") {
  2257. var timeopen2 = data[i]
  2258. .current_value
  2259. }
  2260. //时控二关时间
  2261. else if (data[i].id == "R" +
  2262. Indexes + "_DayCloseTime2") {
  2263. var timeshut2 = data[i]
  2264. .current_value
  2265. }
  2266. //日期调控
  2267. else if (data[i].id == "R" +
  2268. Indexes + "_Week") {
  2269. var weeks = data[i]
  2270. .current_value
  2271. that.setData({
  2272. recorddate: weeks
  2273. })
  2274. weeks = parseInt(weeks)
  2275. weeks = weeks.toString(2)
  2276. weeks = weeks + ''
  2277. if (weeks != '0') {
  2278. weeks = weeks.slice(1)
  2279. }
  2280. }
  2281. //功能一
  2282. else if (data[i].id == "R" +
  2283. Indexes + "_FunctionStatus1") {
  2284. var Function1 = data[i]
  2285. .current_value
  2286. var par = parseInt(Function1)
  2287. par = par.toString(2)
  2288. par = par + ''
  2289. switch (par.length) {
  2290. case 1:
  2291. par = '00000' + par
  2292. break;
  2293. case 2:
  2294. par = '0000' + par
  2295. break;
  2296. case 3:
  2297. par = '000' + par
  2298. break;
  2299. case 4:
  2300. par = '00' + par
  2301. break;
  2302. case 5:
  2303. par = '0' + par
  2304. break;
  2305. default:
  2306. par = par
  2307. }
  2308. }
  2309. //功能二
  2310. else if (data[i].id == "R" +
  2311. Indexes + "_FunctionStatus2") {
  2312. var Function2 = data[i]
  2313. .current_value
  2314. var qur = parseInt(Function2)
  2315. qur = qur.toString(2)
  2316. qur = qur + ''
  2317. switch (qur.length) {
  2318. case 1:
  2319. qur = '000' + qur
  2320. break;
  2321. case 2:
  2322. qur = '00' + qur
  2323. break;
  2324. case 3:
  2325. qur = '0' + qur
  2326. break;
  2327. case 4:
  2328. qur = qur
  2329. break;
  2330. }
  2331. }
  2332. //报警
  2333. else if (data[i].id == "R" +
  2334. Indexes + "_RelayStatus") {
  2335. var police = data[i]
  2336. .current_value
  2337. }
  2338. //光控开
  2339. else if (data[i].id == "R" +
  2340. Indexes + "_LcOn") {
  2341. var Lightcontrolopen = data[i]
  2342. .current_value
  2343. var trr = that.data.arr
  2344. for (let i = 0; i < 100; i++) {
  2345. trr[i] = i
  2346. }
  2347. Lightcontrolopen = parseInt(
  2348. Lightcontrolopen)
  2349. that.setData({
  2350. arr: trr,
  2351. index: Lightcontrolopen
  2352. })
  2353. }
  2354. //光控关
  2355. else if (data[i].id == "R" +
  2356. Indexes + "_LcOff") {
  2357. var Lightcontrolshut = data[i]
  2358. .current_value
  2359. var prr = that.data.brr
  2360. for (let j = 0; j < 100; j++) {
  2361. prr[j] = j
  2362. }
  2363. Lightcontrolshut = parseInt(
  2364. Lightcontrolshut)
  2365. that.setData({
  2366. brr: prr,
  2367. indexs: Lightcontrolshut
  2368. })
  2369. }
  2370. }
  2371. //时控一开时间
  2372. var timeOpen1
  2373. switch (timeopen1.length) {
  2374. case 1:
  2375. timeOpen1 = '00' + ':' + '0' +
  2376. timeopen1.substring(0, 1)
  2377. break;
  2378. case 2:
  2379. timeOpen1 = '00' + ':' +
  2380. timeopen1.substring(0, 2)
  2381. break;
  2382. case 3:
  2383. var timeOpen1 = '0' + timeopen1
  2384. .substring(0, 1) + ':' +
  2385. timeopen1.substring(1, 3)
  2386. break;
  2387. case 4:
  2388. var timeOpen1 = timeopen1
  2389. .substring(0, 2) + ':' +
  2390. timeopen1.substring(2, 4)
  2391. break;
  2392. }
  2393. //时控一关时间
  2394. var timeShut1
  2395. switch (timeshut1.length) {
  2396. case 1:
  2397. timeShut1 = '00' + ':' + '0' +
  2398. timeshut1.substring(0, 1)
  2399. break;
  2400. case 2:
  2401. timeShut1 = '00' + ':' +
  2402. timeshut1.substring(0, 2)
  2403. break;
  2404. case 3:
  2405. var timeShut1 = '0' + timeshut1
  2406. .substring(0, 1) + ':' +
  2407. timeshut1.substring(1, 3)
  2408. break;
  2409. case 4:
  2410. var timeShut1 = timeshut1
  2411. .substring(0, 2) + ':' +
  2412. timeshut1.substring(2, 4)
  2413. break;
  2414. }
  2415. //时控二开时间
  2416. var timeOpen2
  2417. switch (timeopen2.length) {
  2418. case 1:
  2419. timeOpen2 = '00' + ':' + '0' +
  2420. timeopen2.substring(0, 1)
  2421. break;
  2422. case 2:
  2423. timeOpen2 = '00' + ':' +
  2424. timeopen2.substring(0, 2)
  2425. break;
  2426. case 3:
  2427. var timeOpen2 = '0' + timeopen2
  2428. .substring(0, 1) + ':' +
  2429. timeopen2.substring(1, 3)
  2430. break;
  2431. case 4:
  2432. var timeOpen2 = timeopen2
  2433. .substring(0, 2) + ':' +
  2434. timeopen2.substring(2, 4)
  2435. break;
  2436. }
  2437. //时控二关时间
  2438. var timeShut2
  2439. switch (timeshut2.length) {
  2440. case 1:
  2441. timeShut2 = '00' + ':' + '0' +
  2442. timeshut2.substring(0, 1)
  2443. break;
  2444. case 2:
  2445. timeShut2 = '00' + ':' +
  2446. timeshut2.substring(0, 2)
  2447. break;
  2448. case 3:
  2449. var timeShut2 = '0' + timeshut2
  2450. .substring(0, 1) + ':' +
  2451. timeshut2.substring(1, 3)
  2452. break;
  2453. case 4:
  2454. var timeShut2 = timeshut2
  2455. .substring(0, 2) + ':' +
  2456. timeshut2.substring(2, 4)
  2457. break;
  2458. }
  2459. //功能1
  2460. for (var i = 0; i < par.length; i++) {
  2461. var engry = that.data.state
  2462. switch (par.substring(i, i + 1)) {
  2463. case "0":
  2464. switch (i) {
  2465. case 0:
  2466. engry[3] = false
  2467. that.setData({
  2468. state: engry
  2469. })
  2470. break;
  2471. case 1:
  2472. engry[2] = false
  2473. that.setData({
  2474. state: engry
  2475. })
  2476. break;
  2477. case 2:
  2478. that.setData({
  2479. fixed2: "固定"
  2480. })
  2481. break;
  2482. case 3:
  2483. that.setData({
  2484. fixed1: "固定"
  2485. })
  2486. break;
  2487. case 4:
  2488. engry[1] = false
  2489. that.setData({
  2490. state: engry
  2491. })
  2492. break;
  2493. case 5:
  2494. engry[0] = false
  2495. that.setData({
  2496. state: engry
  2497. })
  2498. break;
  2499. }
  2500. break;
  2501. case "1":
  2502. switch (i) {
  2503. case 0:
  2504. engry[3] = true
  2505. that.setData({
  2506. state: engry
  2507. })
  2508. break;
  2509. case 1:
  2510. engry[2] = true
  2511. that.setData({
  2512. state: engry
  2513. })
  2514. break;
  2515. case 2:
  2516. that.setData({
  2517. fixed2: "经纬"
  2518. })
  2519. break;
  2520. case 3:
  2521. that.setData({
  2522. fixed1: "经纬"
  2523. })
  2524. break;
  2525. case 4:
  2526. engry[1] = true
  2527. that.setData({
  2528. state: engry
  2529. })
  2530. break;
  2531. case 5:
  2532. engry[0] = true
  2533. that.setData({
  2534. state: engry
  2535. })
  2536. break;
  2537. }
  2538. break;
  2539. }
  2540. }
  2541. //功能2
  2542. for (let j = 0; j < qur.length; j++) {
  2543. var Engry = that.data.state1
  2544. switch (qur.substring(j, j + 1)) {
  2545. case "0":
  2546. switch (j) {
  2547. case 0:
  2548. that.setData({
  2549. fixed4: "固定"
  2550. })
  2551. break;
  2552. case 1:
  2553. that.setData({
  2554. fixed3: "固定"
  2555. })
  2556. break;
  2557. case 2:
  2558. Engry[1] = false
  2559. that.setData({
  2560. state1: Engry
  2561. })
  2562. break;
  2563. case 3:
  2564. Engry[0] = false
  2565. that.setData({
  2566. state1: Engry
  2567. })
  2568. break;
  2569. }
  2570. break;
  2571. case "1":
  2572. switch (j) {
  2573. case 0:
  2574. that.setData({
  2575. fixed4: "经纬"
  2576. })
  2577. break;
  2578. case 1:
  2579. that.setData({
  2580. fixed3: "经纬"
  2581. })
  2582. break;
  2583. case 2:
  2584. Engry[1] = true
  2585. that.setData({
  2586. state1: Engry
  2587. })
  2588. break;
  2589. case 3:
  2590. Engry[0] = true
  2591. that.setData({
  2592. state1: Engry
  2593. })
  2594. break;
  2595. }
  2596. break;
  2597. }
  2598. }
  2599. //日期调控
  2600. var controladdress = that.data.address
  2601. if (weeks == '0') {
  2602. for (let x = 0; x < 7; x++) {
  2603. controladdress[x] =
  2604. "/image/false.png"
  2605. }
  2606. that.setData({
  2607. address: controladdress,
  2608. })
  2609. } else {
  2610. for (let i = 0; i < weeks
  2611. .length; i++) {
  2612. switch (weeks.substring(i, i +
  2613. 1)) {
  2614. case '0':
  2615. controladdress[weeks
  2616. .length - i - 1
  2617. ] =
  2618. "/image/false.png"
  2619. that.setData({
  2620. address: controladdress,
  2621. })
  2622. break;
  2623. case '1':
  2624. controladdress[weeks
  2625. .length - i - 1
  2626. ] =
  2627. "/image/true.png"
  2628. that.setData({
  2629. address: controladdress,
  2630. })
  2631. break;
  2632. }
  2633. }
  2634. }
  2635. //报警状态
  2636. police = parseInt(police)
  2637. police = police.toString(2)
  2638. switch (police.length) {
  2639. case 1:
  2640. police = '000' + police
  2641. break;
  2642. case 2:
  2643. police = '00' + police
  2644. break;
  2645. case 3:
  2646. police = '0' + police
  2647. break;
  2648. default:
  2649. police = police
  2650. break;
  2651. }
  2652. if (police.substring(1, 2) == '0' &&
  2653. police.substring(0, 1) == '0') {
  2654. that.setData({
  2655. radio1: true
  2656. })
  2657. } else if (police.substring(1, 2) ==
  2658. '1' && police.substring(0, 1) == '0'
  2659. ) {
  2660. that.setData({
  2661. radio2: true
  2662. })
  2663. } else if (police.substring(1, 2) ==
  2664. '0' && police.substring(0, 1) == '1'
  2665. ) {
  2666. that.setData({
  2667. radio3: true
  2668. })
  2669. }
  2670. var time = that.data.time
  2671. time[0] = timeOpen1
  2672. time[1] = timeShut1
  2673. time[2] = timeOpen2
  2674. time[3] = timeShut2
  2675. that.setData({
  2676. time: time
  2677. })
  2678. switch (that.data.state[0]) {
  2679. case true:
  2680. that.setData({
  2681. type1: "time",
  2682. timecontrolcolor1: "blue",
  2683. fontcolor1: "white",
  2684. })
  2685. break;
  2686. default:
  2687. that.setData({
  2688. type1: "",
  2689. timecontrolcolor1: "#888888",
  2690. fontcolor1: "#cccccc",
  2691. })
  2692. break;
  2693. }
  2694. switch (that.data.state[1]) {
  2695. case true:
  2696. that.setData({
  2697. type2: "time",
  2698. timecontrolcolor2: "blue",
  2699. fontcolor2: "white",
  2700. })
  2701. break;
  2702. default:
  2703. that.setData({
  2704. type2: "",
  2705. timecontrolcolor2: "#888888",
  2706. fontcolor2: "#cccccc",
  2707. })
  2708. break;
  2709. }
  2710. switch (that.data.state1[0]) {
  2711. case true:
  2712. that.setData({
  2713. type3: "time",
  2714. timecontrolcolor3: "blue",
  2715. fontcolor3: "white",
  2716. })
  2717. break;
  2718. default:
  2719. that.setData({
  2720. type3: "",
  2721. timecontrolcolor3: "#888888",
  2722. fontcolor3: "#cccccc",
  2723. })
  2724. break;
  2725. }
  2726. switch (that.data.state1[1]) {
  2727. case true:
  2728. that.setData({
  2729. type4: "time",
  2730. timecontrolcolor4: "blue",
  2731. fontcolor4: "white",
  2732. })
  2733. break;
  2734. default:
  2735. that.setData({
  2736. type4: "",
  2737. timecontrolcolor4: "#888888",
  2738. fontcolor4: "#cccccc",
  2739. })
  2740. break;
  2741. }
  2742. switch (that.data.state[2]) {
  2743. case true:
  2744. that.setData({
  2745. Lightcontrolcolor1: "blue",
  2746. fontcolor5: "white",
  2747. select1: "selector"
  2748. })
  2749. break;
  2750. default:
  2751. that.setData({
  2752. Lightcontrolcolor1: "#888888",
  2753. fontcolor5: "#cccccc",
  2754. select1: ""
  2755. })
  2756. break;
  2757. }
  2758. switch (that.data.state[3]) {
  2759. case true:
  2760. that.setData({
  2761. Lightcontrolcolor2: "blue",
  2762. fontcolor6: "white",
  2763. select2: "selector"
  2764. })
  2765. break;
  2766. default:
  2767. that.setData({
  2768. Lightcontrolcolor2: "#888888",
  2769. fontcolor6: "#cccccc",
  2770. select2: ""
  2771. })
  2772. break;
  2773. }
  2774. }
  2775. } else {
  2776. getDevice(message.Device, message.id).then(
  2777. rgb => {
  2778. if (rgb.data.code == 0) {
  2779. var rgbs = rgb.data.data
  2780. .circuits
  2781. rgbs = rgbs.split(',')
  2782. that.setData({
  2783. crr: rgbs
  2784. })
  2785. } else {
  2786. wx.showModal({
  2787. title: '错误',
  2788. content: rgb
  2789. .data.msg,
  2790. showCancel: false
  2791. })
  2792. }
  2793. })
  2794. }
  2795. } else {
  2796. wx.showModal({
  2797. title: '错误',
  2798. content: ever.data.error,
  2799. showCancel: false
  2800. })
  2801. }
  2802. })
  2803. } else {
  2804. wx.showModal({
  2805. title: '错误',
  2806. content: res.data.error,
  2807. showCancel: false
  2808. })
  2809. }
  2810. })
  2811. }
  2812. //新设备
  2813. else {
  2814. that.setData({
  2815. play: 1
  2816. })
  2817. //新设备在线状态
  2818. getDevice(message.Device, message.id).then(nrg => {
  2819. if (nrg.data.code == 0) {
  2820. var nrg = nrg.data.data
  2821. if (nrg.status == 1) {
  2822. that.setData({
  2823. status: '在线'
  2824. })
  2825. } else {
  2826. that.setData({
  2827. status: '离线'
  2828. })
  2829. }
  2830. getloop(message.Device).then(suc => {
  2831. if (suc.data.code == 0) {
  2832. var suc = suc.data.data
  2833. var index = that.data.indexes
  2834. for (let i = 0; i < suc.length; i++) {
  2835. if (index == i) {
  2836. let Suc = suc[i]
  2837. var newSwitch = that.data.newSwitch
  2838. var timeValue = that.data.timeValue
  2839. var newSwitchstate = that.data.newSwitchstate
  2840. var choice = that.data.choice
  2841. var lightCondition = Suc.lightControlCondition
  2842. var model = Suc.ctlMode
  2843. var beginTime = Suc.realTimeCondition1OnTime
  2844. var closeTimes = Suc.realTimeCondition1OffTime
  2845. //光控启动条件
  2846. looplightlist().then(res => {
  2847. if (res.data.code == 0) {
  2848. var lightlist = res.data.data
  2849. that.setData({
  2850. lightlist: lightlist
  2851. })
  2852. for (let i = 0; i <
  2853. lightlist
  2854. .length; i++) {
  2855. choice[i] = false
  2856. }
  2857. if (lightCondition
  2858. .includes(',') ==
  2859. true) {
  2860. lightCondition =
  2861. lightCondition
  2862. .split(',')
  2863. for (let j = 0; j <
  2864. lightCondition
  2865. .length; j++) {
  2866. if (lightCondition[
  2867. j] ==
  2868. '1') {
  2869. choice[0] =
  2870. true
  2871. } else if (
  2872. lightCondition[
  2873. j] ==
  2874. '2') {
  2875. choice[1] =
  2876. true
  2877. } else if (
  2878. lightCondition[
  2879. j] ==
  2880. '3') {
  2881. choice[2] =
  2882. true
  2883. } else if (
  2884. lightCondition[
  2885. j] ==
  2886. '4') {
  2887. choice[3] =
  2888. true
  2889. }
  2890. }
  2891. } else {
  2892. if (lightCondition ==
  2893. '1') {
  2894. choice[0] = true
  2895. } else if (
  2896. lightCondition ==
  2897. '2') {
  2898. choice[1] = true
  2899. } else if (
  2900. lightCondition ==
  2901. '3') {
  2902. choice[2] = true
  2903. } else if (
  2904. lightCondition ==
  2905. '4') {
  2906. choice[3] = true
  2907. }
  2908. }
  2909. that.setData({
  2910. choice: choice
  2911. })
  2912. } else {
  2913. wx.showModal({
  2914. title: '错误',
  2915. content: res
  2916. .data
  2917. .msg,
  2918. showCancel: false
  2919. })
  2920. }
  2921. })
  2922. //时控1
  2923. if (Suc.timeCondition1Switch == 1) {
  2924. newSwitch[0] = true
  2925. newSwitchstate[0] = 'time'
  2926. } else {
  2927. newSwitch[0] = false
  2928. newSwitchstate[0] = ''
  2929. }
  2930. timeValue[0] = Suc.timeCondition1OnTime
  2931. timeValue[1] = Suc.timeCondition1OffTime
  2932. //时控2
  2933. if (Suc.timeCondition2Switch == 1) {
  2934. newSwitch[1] = true
  2935. newSwitchstate[1] = 'time'
  2936. } else {
  2937. newSwitch[1] = false
  2938. newSwitchstate[1] = ''
  2939. }
  2940. timeValue[2] = Suc.timeCondition2OnTime
  2941. timeValue[3] = Suc.timeCondition2OffTime
  2942. //光控
  2943. if (Suc.lightControlSwitch == 1) {
  2944. newSwitch[2] = true
  2945. newSwitchstate[2] = 'time'
  2946. newSwitchstate[3] = 'selector'
  2947. } else {
  2948. newSwitch[2] = false
  2949. newSwitchstate[2] = ''
  2950. newSwitchstate[3] = ''
  2951. }
  2952. timeValue[4] = Suc.lightControlStart
  2953. timeValue[5] = Suc.lightControlEnd
  2954. for (let j = 0; j < timeValue
  2955. .length; j++) {
  2956. if (timeValue[j] == "") {
  2957. timeValue[j] = '00:00'
  2958. }
  2959. }
  2960. var messageNum = message.loopnum
  2961. messageNum.push('所有回路')
  2962. that.setData({
  2963. crr: messageNum,
  2964. timeValue: timeValue,
  2965. newSwitch: newSwitch
  2966. })
  2967. //监视新设备开关状态
  2968. var newSwitchs = that.data.newSwitch
  2969. var newfonts = that.data.newfont
  2970. var newcolors = that.data.newcolor
  2971. var newSwitchstates = that.data
  2972. .newSwitchstate
  2973. var disableds = that.data.disabled
  2974. if (newSwitchs[0] == true) {
  2975. newfonts[0] = "white"
  2976. newcolors[0] = "blue"
  2977. newSwitchstates[0] = "time"
  2978. } else {
  2979. newfonts[0] = "#cccccc"
  2980. newcolors[0] = "#888888"
  2981. newSwitchstates[0] = ""
  2982. }
  2983. if (newSwitchs[1] == true) {
  2984. newfonts[1] = "white"
  2985. newcolors[1] = "blue"
  2986. newSwitchstates[1] = "time"
  2987. } else {
  2988. newfonts[1] = "#cccccc"
  2989. newcolors[1] = "#888888"
  2990. newSwitchstates[1] = ""
  2991. }
  2992. if (newSwitchs[2] == true) {
  2993. newfonts[2] = "white"
  2994. newcolors[2] = "blue"
  2995. newSwitchstates[2] = "time"
  2996. disableds = false
  2997. } else {
  2998. newfonts[2] = "#cccccc"
  2999. newcolors[2] = "#888888"
  3000. newSwitchstates[2] = ""
  3001. disableds = true
  3002. }
  3003. that.setData({
  3004. newcolor: newcolors,
  3005. newfont: newfonts,
  3006. newSwitch: newSwitchs,
  3007. newSwitchstate: newSwitchstates,
  3008. disabled: disableds,
  3009. newChange:model,
  3010. beginTime:beginTime,
  3011. closeTimes:closeTimes
  3012. })
  3013. }
  3014. }
  3015. } else {
  3016. console.log('获取新设备回路参数失败')
  3017. wx.showModal({
  3018. title: '错误',
  3019. content: suc.data.msg,
  3020. showCancel: false
  3021. })
  3022. }
  3023. })
  3024. } else {
  3025. console.log('新设备获取信息失败')
  3026. wx.showModal({
  3027. title: '错误',
  3028. content: nrg.data.msg,
  3029. showCancel: false
  3030. })
  3031. }
  3032. })
  3033. }
  3034. } else {
  3035. that.setData({
  3036. status: '离线',
  3037. deviceName: []
  3038. })
  3039. }
  3040. }
  3041. }
  3042. } else {
  3043. that.setData({
  3044. deviceName: [],
  3045. groupName: []
  3046. })
  3047. }
  3048. },
  3049. //新设备多选框
  3050. point1: function() {
  3051. var choice = this.data.choice
  3052. if (choice[0] == true) {
  3053. choice[0] = false
  3054. } else {
  3055. choice[0] = true
  3056. }
  3057. this.setData({
  3058. choice: choice
  3059. })
  3060. },
  3061. point2: function() {
  3062. var choice = this.data.choice
  3063. if (choice[1] == true) {
  3064. choice[1] = false
  3065. } else {
  3066. choice[1] = true
  3067. }
  3068. this.setData({
  3069. choice: choice
  3070. })
  3071. },
  3072. point3: function() {
  3073. var choice = this.data.choice
  3074. if (choice[2] == true) {
  3075. choice[2] = false
  3076. } else {
  3077. choice[2] = true
  3078. }
  3079. this.setData({
  3080. choice: choice
  3081. })
  3082. },
  3083. point4: function() {
  3084. var choice = this.data.choice
  3085. if (choice[3] == true) {
  3086. choice[3] = false
  3087. } else {
  3088. choice[3] = true
  3089. }
  3090. this.setData({
  3091. choice: choice
  3092. })
  3093. },
  3094. //存储数据
  3095. Storedata: function() {
  3096. wx.showToast({
  3097. title: '存储数据中',
  3098. icon: 'loading',
  3099. duration: 3000
  3100. })
  3101. var that = this
  3102. var play = that.data.play
  3103. //旧设备
  3104. if (play == 0) {
  3105. var indexes = that.data.indexes
  3106. var lamp = wx.getStorageSync('lamp')
  3107. var radio1 = that.data.radio1
  3108. var radio2 = that.data.radio2
  3109. var radio3 = that.data.radio3
  3110. var jude
  3111. if (lamp[indexes] ==
  3112. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png' && radio1 ==
  3113. true) {
  3114. jude = 0
  3115. } else if (lamp[indexes] ==
  3116. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png' && radio2 ==
  3117. true) {
  3118. jude = 4
  3119. } else if (lamp[indexes] ==
  3120. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp.png' && radio3 ==
  3121. true) {
  3122. jude = 8
  3123. } else if (lamp[indexes] ==
  3124. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp1.png' && radio1 ==
  3125. true) {
  3126. jude = 1
  3127. } else if (lamp[indexes] ==
  3128. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp1.png' && radio2 ==
  3129. true) {
  3130. jude = 5
  3131. } else if (lamp[indexes] ==
  3132. 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image/lamp1.png' && radio3 ==
  3133. true) {
  3134. jude = 9
  3135. }
  3136. //功能一
  3137. var Storagetimeopen1
  3138. var Storagetimeshut1
  3139. var Storagetimeopenstate1
  3140. var Storagetimeshutstate1
  3141. var Storageopticalopen
  3142. var Storageopticalshut
  3143. //时控一开
  3144. switch (that.data.state[0]) {
  3145. case true:
  3146. Storagetimeopen1 = "1"
  3147. break;
  3148. case false:
  3149. Storagetimeopen1 = "0"
  3150. break;
  3151. }
  3152. //时控一关
  3153. switch (that.data.state[1]) {
  3154. case true:
  3155. Storagetimeshut1 = "1"
  3156. break;
  3157. case false:
  3158. Storagetimeshut1 = "0"
  3159. break;
  3160. }
  3161. //时控一开经纬
  3162. switch (that.data.fixed1) {
  3163. case "经纬":
  3164. Storagetimeopenstate1 = "1"
  3165. break;
  3166. case "固定":
  3167. Storagetimeopenstate1 = "0"
  3168. break;
  3169. }
  3170. //时控一关经纬
  3171. switch (that.data.fixed2) {
  3172. case "经纬":
  3173. Storagetimeshutstate1 = "1"
  3174. break;
  3175. case "固定":
  3176. Storagetimeshutstate1 = "0"
  3177. break;
  3178. }
  3179. //光控开
  3180. switch (that.data.state[2]) {
  3181. case true:
  3182. Storageopticalopen = "1"
  3183. break;
  3184. case false:
  3185. Storageopticalopen = "0"
  3186. break;
  3187. }
  3188. //光控关
  3189. switch (that.data.state[3]) {
  3190. case true:
  3191. Storageopticalshut = "1"
  3192. break;
  3193. case false:
  3194. Storageopticalshut = "0"
  3195. break;
  3196. }
  3197. var use1 = Storageopticalshut + Storageopticalopen + Storagetimeshutstate1 +
  3198. Storagetimeopenstate1 + Storagetimeshut1 + Storagetimeopen1
  3199. use1 = parseInt(use1, 2)
  3200. use1 = use1 //传给后台的功能一数据
  3201. //功能二
  3202. var Storagetimeopen2
  3203. var Storagetimeshut2
  3204. var Storagetimeopenstate2
  3205. var Storagetimeshutstate2
  3206. //时控二开
  3207. switch (that.data.state1[0]) {
  3208. case true:
  3209. Storagetimeopen2 = "1"
  3210. break;
  3211. case false:
  3212. Storagetimeopen2 = "0"
  3213. break;
  3214. }
  3215. //时控二关
  3216. switch (that.data.state1[1]) {
  3217. case true:
  3218. Storagetimeshut2 = "1"
  3219. break;
  3220. case false:
  3221. Storagetimeshut2 = "0"
  3222. break;
  3223. }
  3224. //时控二开经纬
  3225. switch (that.data.fixed3) {
  3226. case "经纬":
  3227. Storagetimeopenstate2 = "1"
  3228. break;
  3229. case "固定":
  3230. Storagetimeopenstate2 = "0"
  3231. break;
  3232. }
  3233. //时控二关经纬
  3234. switch (that.data.fixed4) {
  3235. case "经纬":
  3236. Storagetimeshutstate2 = "1"
  3237. break;
  3238. case "固定":
  3239. Storagetimeshutstate2 = "0"
  3240. break;
  3241. }
  3242. var use2 = Storagetimeshutstate2 + Storagetimeopenstate2 + Storagetimeshut2 + Storagetimeopen2
  3243. use2 = parseInt(use2, 2)
  3244. use2 = use2 //传给后台的功能二数据
  3245. //时控一开时间
  3246. var Ontime1 = that.data.time[0]
  3247. var ontime1 //传给后台的时控一开时间
  3248. if (Ontime1.substring(0, 2) == '00' && Ontime1.substring(3, 5) == '00') {
  3249. ontime1 = '0'
  3250. } else if (Ontime1.substring(0, 1) != '0') {
  3251. ontime1 = Ontime1.substring(0, 2) + Ontime1.substring(3, 5)
  3252. } else if (Ontime1.substring(0, 1) == '0' && Ontime1.substring(1, 2) != '0') {
  3253. ontime1 = Ontime1.substring(1, 2) + Ontime1.substring(3, 5)
  3254. } else if (Ontime1.substring(0, 2) == '00' && Ontime1.substring(3, 4) != '0') {
  3255. ontime1 = Ontime1.substring(3, 5)
  3256. } else {
  3257. ontime1 = Ontime1.substring(4, 5)
  3258. }
  3259. ontime1 = parseInt(ontime1)
  3260. //时控一关时间
  3261. var Closingtime1 = that.data.time[1]
  3262. var closingtime1 //传给后台的时控一关时间
  3263. if (Closingtime1.substring(0, 2) == '00' && Closingtime1.substring(3, 5) == '00') {
  3264. closingtime1 = '0'
  3265. } else if (Closingtime1.substring(0, 1) != '0') {
  3266. closingtime1 = Closingtime1.substring(0, 2) + Closingtime1.substring(3, 5)
  3267. } else if (Closingtime1.substring(0, 1) == '0' && Closingtime1.substring(1, 2) != '0') {
  3268. closingtime1 = Closingtime1.substring(1, 2) + Closingtime1.substring(3, 5)
  3269. } else if (Closingtime1.substring(0, 2) == '00' && Closingtime1.substring(3, 4) != '0') {
  3270. closingtime1 = Closingtime1.substring(3, 5)
  3271. } else {
  3272. closingtime1 = Closingtime1.substring(4, 5)
  3273. }
  3274. closingtime1 = parseInt(closingtime1)
  3275. //时控二开时间
  3276. var Ontime2 = that.data.time[2]
  3277. var ontime2 //传给后台的时控二开时间
  3278. if (Ontime2.substring(0, 2) == '00' && Ontime2.substring(3, 5) == '00') {
  3279. ontime2 = '0'
  3280. } else if (Ontime2.substring(0, 1) != '0') {
  3281. ontime2 = Ontime2.substring(0, 2) + Ontime2.substring(3, 5)
  3282. } else if (Ontime2.substring(0, 1) == '0' && Ontime2.substring(1, 2) != '0') {
  3283. ontime2 = Ontime2.substring(1, 2) + Ontime2.substring(3, 5)
  3284. } else if (Ontime2.substring(0, 2) == '00' && Ontime2.substring(3, 4) != '0') {
  3285. ontime2 = Ontime2.substring(3, 5)
  3286. } else {
  3287. ontime2 = Ontime2.substring(4, 5)
  3288. }
  3289. ontime2 = parseInt(ontime2)
  3290. //时控二关时间
  3291. var Closingtime2 = that.data.time[3]
  3292. var closingtime2 //传给后台的时控二关时间
  3293. if (Closingtime2.substring(0, 2) == '00' && Closingtime2.substring(3, 5) == '00') {
  3294. closingtime2 = '0'
  3295. } else if (Closingtime2.substring(0, 1) != '0') {
  3296. closingtime2 = Closingtime2.substring(0, 2) + Closingtime2.substring(3, 5)
  3297. } else if (Closingtime2.substring(0, 1) == '0' && Closingtime2.substring(1, 2) != '0') {
  3298. closingtime2 = Closingtime2.substring(1, 2) + Closingtime2.substring(3, 5)
  3299. } else if (Closingtime2.substring(0, 2) == '00' && Closingtime2.substring(3, 4) != '0') {
  3300. closingtime2 = Closingtime2.substring(3, 5)
  3301. } else {
  3302. closingtime2 = Closingtime2.substring(4, 5)
  3303. }
  3304. closingtime2 = parseInt(closingtime2)
  3305. //光控开
  3306. var Lightcontrolon = that.data.arr[that.data.index]
  3307. Lightcontrolon = Lightcontrolon
  3308. //光控关
  3309. var Lightcontroloff = that.data.brr[that.data.indexs]
  3310. Lightcontroloff = Lightcontroloff
  3311. //星期
  3312. var myweek = ""
  3313. var address = that.data.address
  3314. for (let w = 0; w < address.length; w++) {
  3315. switch (address[w]) {
  3316. case "/image/false.png":
  3317. myweek += '0'
  3318. break;
  3319. default:
  3320. myweek += '1'
  3321. break;
  3322. }
  3323. }
  3324. if (myweek == "0000000") {
  3325. myweek = 0
  3326. } else {
  3327. myweek = "1" + myweek.split("").reverse().join("")
  3328. myweek = parseInt(myweek, 2)
  3329. myweek = myweek
  3330. }
  3331. //发起post请求
  3332. getBasic(that.data.deviceId, that.data.deviceKey).then(res => {
  3333. if (res.data.errno == 0) {
  3334. if (res.data.data.online == true) {
  3335. that.setData({
  3336. status: '在线'
  3337. })
  3338. } else {
  3339. that.setData({
  3340. status: '离线'
  3341. })
  3342. }
  3343. } else {
  3344. wx.showModal({
  3345. title: '错误',
  3346. content: res.data.error,
  3347. showCancel: false
  3348. })
  3349. }
  3350. })
  3351. if (that.data.status == "在线") {
  3352. var indexes = that.data.indexes
  3353. indexes = parseInt(indexes)
  3354. var crr = that.data.crr
  3355. if (crr[indexes] != '所有回路') {
  3356. var reflash = [11, 12, 13, 14, 15, 16, 17, 18]
  3357. var i = indexes + 1
  3358. var week = "R" + i + "_Week"
  3359. var FunctionStatus1 = 'R' + i + '_FunctionStatus1'
  3360. var FunctionStatus2 = 'R' + i + '_FunctionStatus2'
  3361. var DayOpenTime1 = 'R' + i + '_DayOpenTime1'
  3362. var DayCloseTime1 = 'R' + i + '_DayCloseTime1'
  3363. var DayOpenTime2 = 'R' + i + '_DayOpenTime2'
  3364. var DayCloseTime2 = 'R' + i + '_DayCloseTime2'
  3365. var LcOn = 'R' + i + '_LcOn'
  3366. var LcOff = 'R' + i + '_LcOff'
  3367. var RelayStatus = 'R' + i + '_RelayStatus'
  3368. var object = {
  3369. "Reflash": reflash[indexes],
  3370. [week]: myweek,
  3371. [FunctionStatus1]: use1,
  3372. [FunctionStatus2]: use2,
  3373. [DayOpenTime1]: ontime1,
  3374. [DayCloseTime1]: closingtime1,
  3375. [DayOpenTime2]: ontime2,
  3376. [DayCloseTime2]: closingtime2,
  3377. [LcOn]: Lightcontrolon,
  3378. [LcOff]: Lightcontroloff,
  3379. [RelayStatus]: jude,
  3380. }
  3381. postData(that.data.deviceId, that.data.deviceKey, JSON.stringify(object)).then(res => {
  3382. if (res.data.errno != 0) {
  3383. wx.showModal({
  3384. title: '错误',
  3385. content: res.data.error,
  3386. showCancel: false
  3387. })
  3388. }
  3389. })
  3390. } else {
  3391. var object1 = {
  3392. "Reflash": 11,
  3393. "R1_Week": myweek, //星期
  3394. "R1_FunctionStatus1": use1, //功能1
  3395. "R1_FunctionStatus2": use2, //功能2
  3396. "R1_DayOpenTime1": ontime1, //时控1开
  3397. "R1_DayCloseTime1": closingtime1, //时控1关
  3398. "R1_DayOpenTime2": ontime2, //时控2开
  3399. "R1_DayCloseTime2": closingtime2, //时控2关
  3400. "R1_LcOn": Lightcontrolon, //光控开
  3401. "R1_LcOff": Lightcontroloff, //光控关
  3402. "R1_RelayStatus": jude, //开关状态
  3403. }
  3404. var object2 = {
  3405. "Reflash": 12,
  3406. "R2_FunctionStatus1": use1, //功能1
  3407. "R2_FunctionStatus2": use2, //功能2
  3408. "R2_DayOpenTime1": ontime1, //时控1开
  3409. "R2_DayCloseTime1": closingtime1, //时控1关
  3410. "R2_DayOpenTime2": ontime2, //时控2开
  3411. "R2_DayCloseTime2": closingtime2, //时控2关
  3412. "R2_Week": myweek, //星期
  3413. "R2_LcOn": Lightcontrolon, //光控开
  3414. "R2_LcOff": Lightcontroloff, //光控关
  3415. "R2_RelayStatus": jude, //开关状态
  3416. }
  3417. var object3 = {
  3418. "Reflash": 13,
  3419. "R3_FunctionStatus1": use1, //功能1
  3420. "R3_FunctionStatus2": use2, //功能2
  3421. "R3_DayOpenTime1": ontime1, //时控1开
  3422. "R3_DayCloseTime1": closingtime1, //时控1关
  3423. "R3_DayOpenTime2": ontime2, //时控2开
  3424. "R3_DayCloseTime2": closingtime2, //时控2关
  3425. "R3_Week": myweek, //星期
  3426. "R3_LcOn": Lightcontrolon, //光控开
  3427. "R3_LcOff": Lightcontroloff, //光控关
  3428. "R3_RelayStatus": jude, //开关状态
  3429. }
  3430. var object4 = {
  3431. "Reflash": 14,
  3432. "R4_FunctionStatus1": use1, //功能1
  3433. "R4_FunctionStatus2": use2, //功能2
  3434. "R4_DayOpenTime1": ontime1, //时控1开
  3435. "R4_DayCloseTime1": closingtime1, //时控1关
  3436. "R4_DayOpenTime2": ontime2, //时控2开
  3437. "R4_DayCloseTime2": closingtime2, //时控2关
  3438. "R4_Week": myweek, //星期
  3439. "R4_LcOn": Lightcontrolon, //光控开
  3440. "R4_LcOff": Lightcontroloff, //光控关
  3441. "R4_RelayStatus": jude, //开关状态
  3442. }
  3443. var object5 = {
  3444. "Reflash": 15,
  3445. "R5_FunctionStatus1": use1, //功能1
  3446. "R5_FunctionStatus2": use2, //功能2
  3447. "R5_DayOpenTime1": ontime1, //时控1开
  3448. "R5_DayCloseTime1": closingtime1, //时控1关
  3449. "R5_DayOpenTime2": ontime2, //时控2开
  3450. "R5_DayCloseTime2": closingtime2, //时控2关
  3451. "R5_Week": myweek, //星期
  3452. "R5_LcOn": Lightcontrolon, //光控开
  3453. "R5_LcOff": Lightcontroloff, //光控关
  3454. "R5_RelayStatus": jude, //开关状态
  3455. }
  3456. var object6 = {
  3457. "Reflash": 16,
  3458. "R6_FunctionStatus1": use1, //功能1
  3459. "R6_FunctionStatus2": use2, //功能2
  3460. "R6_DayOpenTime1": ontime1, //时控1开
  3461. "R6_DayCloseTime1": closingtime1, //时控1关
  3462. "R6_DayOpenTime2": ontime2, //时控2开
  3463. "R6_DayCloseTime2": closingtime2, //时控2关
  3464. "R6_Week": myweek, //星期
  3465. "R6_LcOn": Lightcontrolon, //光控开
  3466. "R6_LcOff": Lightcontroloff, //光控关
  3467. "R6_RelayStatus": jude, //开关状态
  3468. }
  3469. var object7 = {
  3470. "Reflash": 17,
  3471. "R7_FunctionStatus1": use1, //功能1
  3472. "R7_FunctionStatus2": use2, //功能2
  3473. "R7_DayOpenTime1": ontime1, //时控1开
  3474. "R7_DayCloseTime1": closingtime1, //时控1关
  3475. "R7_DayOpenTime2": ontime2, //时控2开
  3476. "R7_DayCloseTime2": closingtime2, //时控2关
  3477. "R7_Week": myweek, //星期
  3478. "R7_LcOn": Lightcontrolon, //光控开
  3479. "R7_LcOff": Lightcontroloff, //光控关
  3480. "R7_RelayStatus": jude, //开关状态
  3481. }
  3482. var object8 = {
  3483. "Reflash": 18,
  3484. "R8_FunctionStatus1": use1, //功能1
  3485. "R8_FunctionStatus2": use2, //功能2
  3486. "R8_DayOpenTime1": ontime1, //时控1开
  3487. "R8_DayCloseTime1": closingtime1, //时控1关
  3488. "R8_DayOpenTime2": ontime2, //时控2开
  3489. "R8_DayCloseTime2": closingtime2, //时控2关
  3490. "R8_Week": myweek, //星期
  3491. "R8_LcOn": Lightcontrolon, //光控开
  3492. "R8_LcOff": Lightcontroloff, //光控关
  3493. "R8_RelayStatus": jude, //开关状态
  3494. }
  3495. postData(that.data.deviceId, that.data.deviceKey, JSON.stringify(object1)).then(res => {
  3496. if (res.data.errno != 0) {
  3497. wx.showModal({
  3498. title: '错误',
  3499. content: res.data.error,
  3500. showCancel: false
  3501. })
  3502. }
  3503. })
  3504. postData(that.data.deviceId, that.data.deviceKey, JSON.stringify(object2)).then(res => {
  3505. if (res.data.errno != 0) {
  3506. wx.showModal({
  3507. title: '错误',
  3508. content: res.data.error,
  3509. showCancel: false
  3510. })
  3511. }
  3512. })
  3513. postData(that.data.deviceId, that.data.deviceKey, JSON.stringify(object3)).then(res => {
  3514. if (res.data.errno != 0) {
  3515. wx.showModal({
  3516. title: '错误',
  3517. content: res.data.error,
  3518. showCancel: false
  3519. })
  3520. }
  3521. })
  3522. postData(that.data.deviceId, that.data.deviceKey, JSON.stringify(object4)).then(res => {
  3523. if (res.data.errno != 0) {
  3524. wx.showModal({
  3525. title: '错误',
  3526. content: res.data.error,
  3527. showCancel: false
  3528. })
  3529. }
  3530. })
  3531. postData(that.data.deviceId, that.data.deviceKey, JSON.stringify(object5)).then(res => {
  3532. if (res.data.errno != 0) {
  3533. wx.showModal({
  3534. title: '错误',
  3535. content: res.data.error,
  3536. showCancel: false
  3537. })
  3538. }
  3539. })
  3540. postData(that.data.deviceId, that.data.deviceKey, JSON.stringify(object6)).then(res => {
  3541. if (res.data.errno != 0) {
  3542. wx.showModal({
  3543. title: '错误',
  3544. content: res.data.error,
  3545. showCancel: false
  3546. })
  3547. }
  3548. })
  3549. postData(that.data.deviceId, that.data.deviceKey, JSON.stringify(object7)).then(res => {
  3550. if (res.data.errno != 0) {
  3551. wx.showModal({
  3552. title: '错误',
  3553. content: res.data.error,
  3554. showCancel: false
  3555. })
  3556. }
  3557. })
  3558. postData(that.data.deviceId, that.data.deviceKey, JSON.stringify(object8)).then(res => {
  3559. if (res.data.errno != 0) {
  3560. wx.showModal({
  3561. title: '错误',
  3562. content: res.data.error,
  3563. showCancel: false
  3564. })
  3565. }
  3566. })
  3567. }
  3568. } else {
  3569. setTimeout(function() {
  3570. wx.showModal({
  3571. title: '提示',
  3572. content: '存储数据失败,请检查设备是否在线或者刷新页面',
  3573. showCancel: false,
  3574. })
  3575. }, 3000)
  3576. }
  3577. }
  3578. //新设备
  3579. else {
  3580. getDevice(that.data.equipment, that.data.subset).then(nrg => {
  3581. if (nrg.data.code == 0) {
  3582. var nrg = nrg.data.data
  3583. if (nrg.status == 1) {
  3584. that.setData({
  3585. status: '在线'
  3586. })
  3587. } else {
  3588. that.setData({
  3589. status: '离线'
  3590. })
  3591. }
  3592. } else {
  3593. wx.showModal({
  3594. title: '错误',
  3595. content: res.data.msg,
  3596. showCancel: false
  3597. })
  3598. }
  3599. })
  3600. if (that.data.status == "在线") {
  3601. var timeValues = that.data.timeValue //时间
  3602. var newChange = that.data.newChange
  3603. var crrs = that.data.crr //回路名称集合
  3604. var Crrindex = that.data.indexes //回路下标
  3605. Crrindex = Crrindex + 1
  3606. var ID = that.data.equipment
  3607. ID = parseInt(ID)
  3608. var newSwitch = that.data.newSwitch //设备开关
  3609. for (let x = 0; x < newSwitch.length; x++) {
  3610. if (newSwitch[x] == true) {
  3611. newSwitch[x] = 1
  3612. } else {
  3613. newSwitch[x] = 0
  3614. }
  3615. }
  3616. //开启条件(天气)
  3617. var choice = that.data.choice
  3618. var Choice = ''
  3619. for (let q = 0; q < choice.length; q++) {
  3620. if (choice[q] == true) {
  3621. Choice += ((q + 1) + ',')
  3622. }
  3623. }
  3624. if (Choice.length > 0) {
  3625. Choice = Choice.slice(0, Choice.length - 1)
  3626. }
  3627. if(crrs[Crrindex - 1] != '所有回路'){
  3628. var postobject = {
  3629. "deviceId": ID,
  3630. "relays": [{
  3631. "relayId": Crrindex,
  3632. "name": crrs[Crrindex - 1],
  3633. "timeCondition1Switch": newSwitch[0],
  3634. "timeCondition1OnTime": timeValues[0],
  3635. "timeCondition1OffTime": timeValues[1],
  3636. "timeCondition2Switch": newSwitch[1],
  3637. "timeCondition2OnTime": timeValues[2],
  3638. "timeCondition2OffTime": timeValues[3],
  3639. "lightControlSwitch": newSwitch[2],
  3640. "lightControlStart": timeValues[4],
  3641. "lightControlEnd": timeValues[5],
  3642. "lightControlCondition": Choice,
  3643. "ctlMode":newChange
  3644. }]
  3645. }
  3646. }
  3647. else{
  3648. var postobject = {
  3649. "deviceId": ID
  3650. }
  3651. var relays = []
  3652. for(let e = 0; e < crrs.length - 1; e++){
  3653. relays.push(
  3654. {
  3655. "relayId": e+1,
  3656. "timeCondition1Switch": newSwitch[0],
  3657. "timeCondition1OnTime": timeValues[0],
  3658. "timeCondition1OffTime": timeValues[1],
  3659. "timeCondition2Switch": newSwitch[1],
  3660. "timeCondition2OnTime": timeValues[2],
  3661. "timeCondition2OffTime": timeValues[3],
  3662. "lightControlSwitch": newSwitch[2],
  3663. "lightControlStart": timeValues[4],
  3664. "lightControlEnd": timeValues[5],
  3665. "lightControlCondition": Choice,
  3666. "ctlMode":newChange
  3667. }
  3668. )
  3669. }
  3670. postobject.relays = relays
  3671. }
  3672. console.log(postobject)
  3673. postloop(postobject).then(upload => {
  3674. if (upload.data.code != 0) {
  3675. wx.showModal({
  3676. title: '错误',
  3677. content: upload.data.msg,
  3678. showCancel: false
  3679. })
  3680. }
  3681. })
  3682. } else {
  3683. wx.showModal({
  3684. title: '提示',
  3685. content: '存储数据失败,请检查设备是否在线或者刷新页面',
  3686. showCancel: false,
  3687. })
  3688. }
  3689. }
  3690. },
  3691. //开启条件按钮
  3692. Opening: function() {
  3693. var disabled = this.data.disabled
  3694. if (disabled == true) {
  3695. this.setData({
  3696. popup: false
  3697. })
  3698. } else {
  3699. this.setData({
  3700. popup: true
  3701. })
  3702. }
  3703. },
  3704. //对话框确定回调
  3705. complete: function() {
  3706. this.setData({
  3707. popup: false
  3708. })
  3709. },
  3710. /**
  3711. * 生命周期函数--监听页面加载
  3712. */
  3713. onLoad(options) {},
  3714. /**
  3715. * 生命周期函数--监听页面初次渲染完成
  3716. */
  3717. onReady() {
  3718. },
  3719. /**
  3720. * 生命周期函数--监听页面显示
  3721. */
  3722. onShow() {
  3723. wx.showToast({
  3724. title: '获取数据中',
  3725. icon: 'loading',
  3726. duration: 2000
  3727. })
  3728. var that = this
  3729. //获取机型改变switch大小
  3730. wx.getSystemInfo({
  3731. success: function(res) {
  3732. if (res.model == 'iPad' || res.model == 'iPad Pro 10.5-inch' || res.model ==
  3733. 'iPad Pro 12.9-inch') {
  3734. that.setData({
  3735. zoom: 1
  3736. })
  3737. }
  3738. }
  3739. })
  3740. var group = wx.getStorageSync('group')
  3741. if (group != null && group.length != 0) {
  3742. //分组下拉
  3743. var group = wx.getStorageSync('group')
  3744. var groups = []
  3745. for (let i = 0; i < group.length; i++) {
  3746. groups.push(group[i].groupName)
  3747. }
  3748. that.setData({
  3749. groupName: groups
  3750. })
  3751. //改变分组下标
  3752. if (wx.getStorageSync('groupName') != '') {
  3753. let GroupName = groups
  3754. for (let n = 0; n < GroupName.length; n++) {
  3755. if (GroupName[n] == wx.getStorageSync('groupName')) {
  3756. that.setData({
  3757. groupIndex: n
  3758. })
  3759. }
  3760. }
  3761. } else {
  3762. that.setData({
  3763. groupIndex: 0
  3764. })
  3765. wx.setStorageSync('groupName', that.data.groupName[that.data.groupIndex])
  3766. }
  3767. //设备下拉
  3768. var device = []
  3769. var groupName = that.data.groupName
  3770. var groupIndex = that.data.groupIndex
  3771. for (let j = 0; j < group.length; j++) {
  3772. if (groupName[groupIndex] == group[j].groupName) {
  3773. if (group[j].devices != null && group[j].devices.length != 0) {
  3774. for (let p = 0; p < group[j].devices.length; p++) {
  3775. device.push(group[j].devices[p].deviceName)
  3776. }
  3777. that.setData({
  3778. deviceName: device
  3779. })
  3780. //改变设备下标
  3781. if (wx.getStorageSync('deviceName') != '') {
  3782. for (let m = 0; m < device.length; m++) {
  3783. if (device[m] == wx.getStorageSync('deviceName')) {
  3784. that.setData({
  3785. deviceIndex: m
  3786. })
  3787. }
  3788. }
  3789. } else {
  3790. that.setData({
  3791. deviceIndex: 0
  3792. })
  3793. wx.setStorageSync('deviceName', that.data.deviceName[that.data.deviceIndex])
  3794. }
  3795. //获取设备信息
  3796. var currentGroup = that.data.groupName[that.data.groupIndex]
  3797. var currentDevice = that.data.deviceName[that.data.deviceIndex]
  3798. var message = enloop.deviceMessage(currentGroup, currentDevice)
  3799. that.setData({
  3800. equipment: message.Device,
  3801. subset: message.id,
  3802. ID: message.ID,
  3803. indexes: 0 //将回路重新调回回路1
  3804. }) //记录当前的设备id和分组id
  3805. //旧设备
  3806. if (message.modules == 0) {
  3807. that.setData({
  3808. play: 0,
  3809. deviceKey: message.deviceKey,
  3810. deviceId: message.deviceId
  3811. })
  3812. getBasic(message.deviceId, message.deviceKey).then(res => {
  3813. if (res.data.errno == 0) {
  3814. if (res.data.data.online == true) {
  3815. that.setData({
  3816. status: '在线'
  3817. })
  3818. } else {
  3819. that.setData({
  3820. status: '离线'
  3821. })
  3822. }
  3823. getData(message.deviceId, message.deviceKey).then(ever => {
  3824. if (ever.data.errno == 0) {
  3825. let {
  3826. data
  3827. } = ever.data
  3828. //判断设备是否处于初始化状态
  3829. var initialization = true
  3830. for (let t = 0; t < data.length; t++) {
  3831. if ('current_value' in data[t] == false) {
  3832. initialization = false
  3833. }
  3834. }
  3835. if (initialization == true) {
  3836. let loopnum = message.loopnum
  3837. var Summary = enloop.deviceinfo(data, loopnum,
  3838. that.data.arr, that.data.brr, that.data
  3839. .time, that.data.state,
  3840. that.data.state1, that.data.fixed1, that
  3841. .data.fixed2, that.data.fixed3,
  3842. that.data.fixed4, that.data.address,
  3843. that.data.radio1, that.data.radio2,
  3844. that.data.radio3, that.data.index, that
  3845. .data.indexs)
  3846. that.setData({
  3847. crr: Summary.crr,
  3848. arr: Summary.arr,
  3849. brr: Summary.brr,
  3850. fixed1: Summary.fixed1,
  3851. fixed2: Summary.fixed2,
  3852. fixed3: Summary.fixed3,
  3853. fixed4: Summary.fixed4,
  3854. index: Summary.index,
  3855. indexs: Summary.indexs,
  3856. radio1: Summary.radio1,
  3857. radio2: Summary.radio2,
  3858. radio3: Summary.radio3,
  3859. recorddate: Summary.recorddate,
  3860. state: Summary.state,
  3861. state1: Summary.state1,
  3862. time: Summary.time,
  3863. address: Summary.address,
  3864. play: 0
  3865. })
  3866. //监视开关状态(改变颜色,调整功能)
  3867. switch (that.data.state[0]) {
  3868. case true:
  3869. that.setData({
  3870. type1: "time",
  3871. timecontrolcolor1: "blue",
  3872. fontcolor1: "white",
  3873. })
  3874. break;
  3875. default:
  3876. that.setData({
  3877. type1: "",
  3878. timecontrolcolor1: "#888888",
  3879. fontcolor1: "#cccccc",
  3880. })
  3881. break;
  3882. }
  3883. switch (that.data.state[1]) {
  3884. case true:
  3885. that.setData({
  3886. type2: "time",
  3887. timecontrolcolor2: "blue",
  3888. fontcolor2: "white",
  3889. })
  3890. break;
  3891. default:
  3892. that.setData({
  3893. type2: "",
  3894. timecontrolcolor2: "#888888",
  3895. fontcolor2: "#cccccc",
  3896. })
  3897. break;
  3898. }
  3899. switch (that.data.state1[0]) {
  3900. case true:
  3901. that.setData({
  3902. type3: "time",
  3903. timecontrolcolor3: "blue",
  3904. fontcolor3: "white",
  3905. })
  3906. break;
  3907. default:
  3908. that.setData({
  3909. type3: "",
  3910. timecontrolcolor3: "#888888",
  3911. fontcolor3: "#cccccc",
  3912. })
  3913. break;
  3914. }
  3915. switch (that.data.state1[1]) {
  3916. case true:
  3917. that.setData({
  3918. type4: "time",
  3919. timecontrolcolor4: "blue",
  3920. fontcolor4: "white",
  3921. })
  3922. break;
  3923. default:
  3924. that.setData({
  3925. type4: "",
  3926. timecontrolcolor4: "#888888",
  3927. fontcolor4: "#cccccc",
  3928. })
  3929. break;
  3930. }
  3931. switch (that.data.state[2]) {
  3932. case true:
  3933. that.setData({
  3934. Lightcontrolcolor1: "blue",
  3935. fontcolor5: "white",
  3936. select1: "selector"
  3937. })
  3938. break;
  3939. default:
  3940. that.setData({
  3941. Lightcontrolcolor1: "#888888",
  3942. fontcolor5: "#cccccc",
  3943. select1: ""
  3944. })
  3945. break;
  3946. }
  3947. switch (that.data.state[3]) {
  3948. case true:
  3949. that.setData({
  3950. Lightcontrolcolor2: "blue",
  3951. fontcolor6: "white",
  3952. select2: "selector"
  3953. })
  3954. break;
  3955. default:
  3956. that.setData({
  3957. Lightcontrolcolor2: "#888888",
  3958. fontcolor6: "#cccccc",
  3959. select2: ""
  3960. })
  3961. break;
  3962. }
  3963. } else {
  3964. getDevice(message.Device, message.id).then(
  3965. rgb => {
  3966. if (rgb.data.code == 0) {
  3967. var rgbs = rgb.data.data
  3968. .circuits
  3969. rgbs = rgbs.split(',')
  3970. that.setData({
  3971. crr: rgbs
  3972. })
  3973. } else {
  3974. wx.showModal({
  3975. title: '错误',
  3976. content: rgb.data
  3977. .msg,
  3978. showCancel: false
  3979. })
  3980. }
  3981. })
  3982. }
  3983. } else {
  3984. wx.showModal({
  3985. title: '错误',
  3986. content: ever.data.error,
  3987. showCancel: false
  3988. })
  3989. }
  3990. })
  3991. } else {
  3992. wx.showModal({
  3993. title: '错误',
  3994. content: res.data.error,
  3995. showCancel: false
  3996. })
  3997. }
  3998. })
  3999. }
  4000. //新设备
  4001. else {
  4002. that.setData({
  4003. play: 1
  4004. })
  4005. //新设备在线状态
  4006. getDevice(message.Device, message.id).then(nrg => {
  4007. if (nrg.data.code == 0) {
  4008. var nrg = nrg.data.data
  4009. if (nrg.status == 1) {
  4010. that.setData({
  4011. status: '在线'
  4012. })
  4013. } else {
  4014. that.setData({
  4015. status: '离线'
  4016. })
  4017. }
  4018. getloop(message.Device).then(suc => {
  4019. if (suc.data.code == 0) {
  4020. var suc = suc.data.data
  4021. var index = that.data.indexes
  4022. for (let i = 0; i < suc.length; i++) {
  4023. if (index == i) {
  4024. let Suc = suc[i]
  4025. var newSwitch = that.data.newSwitch
  4026. var timeValue = that.data.timeValue
  4027. var newSwitchstate = that.data.newSwitchstate
  4028. var choice = that.data.choice
  4029. var lightCondition = Suc.lightControlCondition
  4030. var model = Suc.ctlMode
  4031. //光控启动条件
  4032. looplightlist().then(res => {
  4033. if (res.data.code == 0) {
  4034. var lightlist = res.data.data
  4035. that.setData({
  4036. lightlist: lightlist
  4037. })
  4038. for (let i = 0; i < lightlist.length; i++) {
  4039. choice[i] = false
  4040. }
  4041. if (lightCondition.includes(',') == true) {
  4042. lightCondition = lightCondition.split(',')
  4043. for (let j = 0; j < lightCondition.length; j++) {
  4044. if (lightCondition[j] == '1') {
  4045. choice[0] = true
  4046. } else if (
  4047. lightCondition[
  4048. j] == '2') {
  4049. choice[1] = true
  4050. } else if (
  4051. lightCondition[
  4052. j] == '3') {
  4053. choice[2] = true
  4054. } else if (
  4055. lightCondition[
  4056. j] == '4') {
  4057. choice[3] = true
  4058. }
  4059. }
  4060. } else {
  4061. if (lightCondition ==
  4062. '1') {
  4063. choice[0] = true
  4064. } else if (
  4065. lightCondition ==
  4066. '2') {
  4067. choice[1] = true
  4068. } else if (
  4069. lightCondition ==
  4070. '3') {
  4071. choice[2] = true
  4072. } else if (
  4073. lightCondition ==
  4074. '4') {
  4075. choice[3] = true
  4076. }
  4077. }
  4078. that.setData({
  4079. choice: choice
  4080. })
  4081. } else {
  4082. wx.showModal({
  4083. title: '错误',
  4084. content: res
  4085. .data.msg,
  4086. showCancel: false
  4087. })
  4088. }
  4089. })
  4090. //时控1
  4091. if (Suc.timeCondition1Switch == 1) {
  4092. newSwitch[0] = true
  4093. newSwitchstate[0] = 'time'
  4094. } else {
  4095. newSwitch[0] = false
  4096. newSwitchstate[0] = ''
  4097. }
  4098. timeValue[0] = Suc.timeCondition1OnTime
  4099. timeValue[1] = Suc.timeCondition1OffTime
  4100. //时控2
  4101. if (Suc.timeCondition2Switch == 1) {
  4102. newSwitch[1] = true
  4103. newSwitchstate[1] = 'time'
  4104. } else {
  4105. newSwitch[1] = false
  4106. newSwitchstate[1] = ''
  4107. }
  4108. timeValue[2] = Suc.timeCondition2OnTime
  4109. timeValue[3] = Suc.timeCondition2OffTime
  4110. //光控
  4111. if (Suc.lightControlSwitch == 1) {
  4112. newSwitch[2] = true
  4113. newSwitchstate[2] = 'time'
  4114. newSwitchstate[3] = 'selector'
  4115. } else {
  4116. newSwitch[2] = false
  4117. newSwitchstate[2] = ''
  4118. newSwitchstate[3] = ''
  4119. }
  4120. timeValue[4] = Suc.lightControlStart
  4121. timeValue[5] = Suc.lightControlEnd
  4122. for (let j = 0; j < timeValue.length; j++) {
  4123. if (timeValue[j] == "") {
  4124. timeValue[j] = '00:00'
  4125. }
  4126. }
  4127. var messageNum = message.loopnum
  4128. messageNum.push('所有回路')
  4129. that.setData({
  4130. crr: messageNum,
  4131. timeValue: timeValue,
  4132. newSwitch: newSwitch,
  4133. beginTime:Suc.realTimeCondition1OnTime,
  4134. closeTimes:Suc.realTimeCondition1OffTime,
  4135. newChange:model
  4136. })
  4137. //监视新设备开关状态
  4138. var newSwitchs = that.data.newSwitch
  4139. var newfonts = that.data.newfont
  4140. var newcolors = that.data.newcolor
  4141. var newSwitchstates = that.data
  4142. .newSwitchstate
  4143. var disableds = that.data.disabled
  4144. if (newSwitchs[0] == true) {
  4145. newfonts[0] = "white"
  4146. newcolors[0] = "blue"
  4147. newSwitchstates[0] = "time"
  4148. } else {
  4149. newfonts[0] = "#cccccc"
  4150. newcolors[0] = "#888888"
  4151. newSwitchstates[0] = ""
  4152. }
  4153. if (newSwitchs[1] == true) {
  4154. newfonts[1] = "white"
  4155. newcolors[1] = "blue"
  4156. newSwitchstates[1] = "time"
  4157. } else {
  4158. newfonts[1] = "#cccccc"
  4159. newcolors[1] = "#888888"
  4160. newSwitchstates[1] = ""
  4161. }
  4162. if (newSwitchs[2] == true) {
  4163. newfonts[2] = "white"
  4164. newcolors[2] = "blue"
  4165. newSwitchstates[2] = "time"
  4166. disableds = false
  4167. } else {
  4168. newfonts[2] = "#cccccc"
  4169. newcolors[2] = "#888888"
  4170. newSwitchstates[2] = ""
  4171. disableds = true
  4172. }
  4173. that.setData({
  4174. newcolor: newcolors,
  4175. newfont: newfonts,
  4176. newSwitch: newSwitchs,
  4177. newSwitchstate: newSwitchstates,
  4178. disabled: disableds
  4179. })
  4180. }
  4181. }
  4182. } else {
  4183. console.log('获取新设备回路参数失败')
  4184. wx.showModal({
  4185. title: '错误',
  4186. content: suc.data.msg,
  4187. showCancel: false
  4188. })
  4189. }
  4190. })
  4191. } else {
  4192. console.log('新设备获取信息失败')
  4193. wx.showModal({
  4194. title: '错误',
  4195. content: nrg.data.msg,
  4196. showCancel: false
  4197. })
  4198. }
  4199. })
  4200. }
  4201. } else {
  4202. that.setData({
  4203. status: '离线',
  4204. deviceName: []
  4205. })
  4206. }
  4207. }
  4208. }
  4209. } else {
  4210. that.setData({
  4211. status: '离线',
  4212. deviceName: [],
  4213. groupName: []
  4214. })
  4215. }
  4216. },
  4217. /**
  4218. * 生命周期函数--监听页面隐藏
  4219. */
  4220. onHide() {
  4221. },
  4222. /**
  4223. * 生命周期函数--监听页面卸载
  4224. */
  4225. onUnload() {
  4226. },
  4227. /**
  4228. * 页面相关事件处理函数--监听用户下拉动作
  4229. */
  4230. onPullDownRefresh() {
  4231. },
  4232. /**
  4233. * 页面上拉触底事件的处理函数
  4234. */
  4235. onReachBottom() {
  4236. },
  4237. /**
  4238. * 用户点击右上角分享
  4239. */
  4240. onShareAppMessage() {
  4241. }
  4242. })