details.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  1. <template>
  2. <view class="box">
  3. <view class="status_bar"></view>
  4. <view style="position: fixed;z-index: 100;width: 100%;">
  5. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="水肥详情"></uni-nav-bar>
  6. </view>
  7. <!-- 上面要素值 -->
  8. <view class="bigBox bigOpen" v-if="show">
  9. <view class="topInfo">
  10. <u-row gutter="10">
  11. <u-col span="3" v-for="item in ElementList" :key="item.id">
  12. <view class="item">
  13. <view>{{item.value}}</view>
  14. <view>{{item.unit}}</view>
  15. <view>{{item.name}}</view>
  16. </view>
  17. </u-col>
  18. </u-row>
  19. <view class="readmore" v-if="!show" @click="show=true;getHistoryData()">
  20. 查看详情<u-icon name="arrow-down" color="#93FFDE" size="28"></u-icon>
  21. </view>
  22. </view>
  23. <!-- 统计图 -->
  24. <view class="hisBox" v-show="show">
  25. <view class="axiosBox">
  26. <view class="title">
  27. 历史数据
  28. </view>
  29. <view class="histimeBox">
  30. <u-icon name="calendar" color="#C1C1C1" size="24"></u-icon>
  31. <view class="time" @click="calendarshow = true">
  32. {{historyTime.startDate ? historyTime.startDate : timestampToDateTime(new Date().getTime()/1000)}}
  33. </view>
  34. <view class="">至</view>
  35. <view class="time" @click="calendarshow = true">
  36. {{historyTime.endDate ? historyTime.endDate : timestampToDateTime(new Date().getTime()/1000)}}
  37. </view>
  38. <u-icon name="close-circle" color="#C1C1C1" size="28" @click="historyTime={};getHistoryData()"
  39. v-if="historyTime.startDate"></u-icon>
  40. </view>
  41. <u-calendar v-model="calendarshow" mode="range" @change="changeDate"></u-calendar>
  42. <view class="chartBox">
  43. <canvas canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  44. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)"
  45. @touchend="touchEndLineA($event)"></canvas>
  46. </view>
  47. </view>
  48. <view class="readmoreHIs" @click="show=false">
  49. 收起详情<u-icon name="arrow-up" color="#14A478" size="28"></u-icon>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="bigBox" v-else>
  54. <view class="topInfo">
  55. <u-row gutter="10">
  56. <u-col span="3" v-for="item in ElementList" :key="item.id">
  57. <view class="item">
  58. <view>{{item.value}}</view>
  59. <view>{{item.unit}}</view>
  60. <view>{{item.name}}</view>
  61. </view>
  62. </u-col>
  63. </u-row>
  64. <view class="readmore" v-if="!show" @click="show=true;getHistoryData()">
  65. 查看详情<u-icon name="arrow-down" color="#93FFDE" size="28"></u-icon>
  66. </view>
  67. </view>
  68. <!-- 统计图 -->
  69. <view class="hisBox" v-show="show">
  70. <view class="axiosBox">
  71. <view class="title">
  72. 历史数据
  73. </view>
  74. <view class="histimeBox">
  75. <u-icon name="calendar" color="#C1C1C1" size="24"></u-icon>
  76. <view class="time" @click="calendarshow = true">
  77. {{historyTime.startDate ? historyTime.startDate : timestampToDateTime(new Date().getTime()/1000)}}
  78. </view>
  79. <view class="">至</view>
  80. <view class="time" @click="calendarshow = true">
  81. {{historyTime.endDate ? historyTime.endDate : timestampToDateTime(new Date().getTime()/1000)}}
  82. </view>
  83. <u-icon name="close-circle" color="#C1C1C1" size="28" @click="historyTime={};getHistoryData()"
  84. v-if="historyTime.startDate"></u-icon>
  85. </view>
  86. <u-calendar v-model="calendarshow" mode="range" @change="changeDate"></u-calendar>
  87. <view class="chartBox">
  88. <canvas canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  89. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)"
  90. @touchend="touchEndLineA($event)"></canvas>
  91. </view>
  92. </view>
  93. <view class="readmoreHIs" @click="show=false">
  94. 收起详情<u-icon name="arrow-up" color="#14A478" size="28"></u-icon>
  95. </view>
  96. </view>
  97. </view>
  98. <view class="" v-if="!show">
  99. <!-- 历史记录弹框 -->
  100. <u-tabs :list="list" active-color="#14A478" bar-width="100" :is-scroll="false" :current="current"
  101. @change="change"></u-tabs>
  102. <!-- 设备图 -->
  103. <view class="devicePhoto" v-if="current == 0">
  104. <view class="titleBox">
  105. <u-alert-tips type="primary" :title-style="alertTipColor" title="点击按钮可对应控制阀门开关,开即打开,关即关闭"
  106. :show-icon="true"></u-alert-tips>
  107. <!-- <view class="btn" @click="statusPanel=true">控制面板</view> -->
  108. <!-- <u-popup v-model="statusPanel" mode="bottom">
  109. <view class="consoleBox">
  110. <view class="swichBox">
  111. <u-row :gutter="16" justify="space-between">
  112. <u-col span="6" v-for="(item, index) in buttonList" v-if="(index + 1) % 2 == 1">
  113. <view class="preSwich">
  114. <view>肥料{{ (index + 1) / 2 > 1 ? (index + 2) / 2 : 1 }}</view>
  115. <u-switch v-model="item.off" active-color="#14A478" inactive-color="#AEB4C2"
  116. :loading="item.disabled"
  117. @change="switchchange($event, item.number, item, index, true)"></u-switch>
  118. </view>
  119. </u-col>
  120. <u-col span="6" v-for="(item, index) in facilityvalve"
  121. v-if="index > buttonList.length - 1">
  122. <view class="preSwich">
  123. <view>{{item.name}}</view>
  124. <u-switch v-model="item.off" active-color="#14A478" inactive-color="#AEB4C2"
  125. :loading="item.disabled"
  126. @change="switchchange($event, item.number, item, index)"></u-switch>
  127. </view>
  128. </u-col>
  129. </u-row>
  130. </view>
  131. <u-button type="success" @click="statusPanel=false">确定</u-button>
  132. </view>
  133. </u-popup> -->
  134. </view>
  135. <view class="main">
  136. <image class="mainContent" src="../../static/images/waterandfernew/mainNew.png"></image>
  137. <!-- <view class="sourceBox">
  138. <view class="smallBox">
  139. 水源
  140. </view>
  141. </view> -->
  142. <!-- 桶 -->
  143. <view class="colList">
  144. <view class="preClo" v-for="item, index in pickBtnList" :key="item.type">
  145. <view>
  146. 肥料{{ index + 1}}
  147. </view>
  148. <image src="../../static/images/waterandfernew/colNew.png" v-if="pickBtnList.length == 1">
  149. </image>
  150. <image src="../../static/images/waterandfernew/colLeft.png"
  151. v-else-if="pickBtnList.length > 1 && index == 0"></image>
  152. <image src="../../static/images/waterandfernew/colRight.png"
  153. v-else-if="pickBtnList.length > 1 && index == pickBtnList.length - 1"></image>
  154. <image src="../../static/images/waterandfernew/colCenter.png" v-else></image>
  155. <view class="jiaoBtn" v-if="resultBan.length > 0">
  156. <u-switch v-model="resultBan[index]['off']" active-color="#14A478"
  157. inactive-color="#AEB4C2" :loading="resultBan[index]['disabled']"
  158. @change="switchchange($event, resultBan[index]['number'], resultBan[index], index)"></u-switch>
  159. </view>
  160. <view class="shanBox" v-if="resultBan.length > 0">
  161. <image v-if="!resultBan[index]['off']"
  162. src="../../static/images/waterandfernew/shan.png"></image>
  163. <image v-else class="circleAnm"
  164. src="../../static/images/waterandfernew/shanannimate.png"></image>
  165. </view>
  166. <view class="btnBox" @click="switchchange($event, item.number, item, index, true)">
  167. <image v-if="item.off" src="../../static/images/waterandfernew/feiopen.png"></image>
  168. <image v-else src="../../static/images/waterandfernew/feiclose.png"></image>
  169. </view>
  170. </view>
  171. </view>
  172. <!-- 废料管口 -->
  173. <view class="exit">
  174. <image src="../../static/images/waterandfernew/exit.png"></image>
  175. </view>
  176. <!-- 注肥泵 -->
  177. <view class="feiLight"
  178. @click="switchchange(!feiBeng, facilityvalve[feiBengIndex].number, facilityvalve[feiBengIndex], feiBengIndex)">
  179. <image v-if="feiBeng" src="../../static/images/waterandfernew/feiAllopen.png"></image>
  180. <image v-else src="../../static/images/waterandfernew/feiAllclose.png"></image>
  181. </view>
  182. <!-- 控制柜 -->
  183. <view class="kongBox">
  184. <image v-if="feiBeng" src="../../static/images/waterandfernew/kongclose.png"></image>
  185. <image v-else src="../../static/images/waterandfernew/kongopen.png"></image>
  186. </view>
  187. <!-- 进水泵 -->
  188. <view class="warterIn"
  189. @click="switchchange(!mainBeng, facilityvalve[mainBengIndex].number, facilityvalve[mainBengIndex], mainBengIndex)">
  190. <image v-if="mainBeng" src="../../static/images/waterandfernew/feiopen.png"></image>
  191. <image v-else src="../../static/images/waterandfernew/feiclose.png"></image>
  192. </view>
  193. <!-- 进水指示 -->
  194. <view class="warterLight">
  195. <image v-if="mainBeng" src="../../static/images/waterandfernew/bengopen.png"></image>
  196. <image v-else src="../../static/images/waterandfernew/bengclose.png"></image>
  197. </view>
  198. <!-- 电风扇 -->
  199. <!-- <view class="fengBox">
  200. <view class="relativeBox">
  201. <image src="../../static/images/waterandfernew/fengmain.png"></image>
  202. <image :class="feiBeng ? 'circleAnm' : ''"
  203. src="../../static/images/waterandfernew/fengleafs.png"></image>
  204. </view>
  205. </view> -->
  206. <!-- 水管控制阀 -->
  207. <view class="benList">
  208. <!-- <view class="preBen" v-for="item, index in buttonList" v-if="(index + 1) % 2 == 1"
  209. @click="switchchange(!item.off, item.number, item, index, true)">
  210. <image class="daoguan" src="../../static/images/waterandfernew/bottomNew.png"
  211. v-if="(index + 1) % 2 < 4"></image>
  212. <view class="info">
  213. 肥料{{ (index + 1) / 2 > 1 ? (index + 2) / 2 : 1 }}开关
  214. </view>
  215. <image class="status" v-if="item.off" src="../../static/images/waterandfernew/open.png">
  216. </image>
  217. <image class="status" v-else src="../../static/images/waterandfernew/close.png"></image>
  218. </view> -->
  219. <view class="preBen" v-for="item, index in faList"
  220. @click="switchchange(!item.off, item.number, item, index)">
  221. <image class="daoguan" src="../../static/images/waterandfernew/bottomNew.png"
  222. v-if="index < 5"></image>
  223. <view class="info">
  224. {{item.e_name}}
  225. </view>
  226. <image class="status" v-if="item.off" src="../../static/images/waterandfernew/open.png">
  227. </image>
  228. <image class="status" v-else src="../../static/images/waterandfernew/close.png"></image>
  229. </view>
  230. </view>
  231. </view>
  232. </view>
  233. <!-- 操作记录 -->
  234. <view class="consoleList" v-else>
  235. <view class="histimeBox">
  236. <u-icon name="calendar" color="#C1C1C1" size="24"></u-icon>
  237. <view class="time" @click="consoleshow = true">
  238. {{consoleTime.startDate ? consoleTime.startDate : '开始'}}
  239. </view>
  240. <view class="">至</view>
  241. <view class="time" @click="consoleshow = true">{{consoleTime.endDate ? consoleTime.endDate : '结束'}}
  242. </view>
  243. <u-icon name="close-circle" color="#C1C1C1" size="28" @click="clearContime"
  244. v-if="consoleTime.startDate"></u-icon>
  245. </view>
  246. <u-calendar v-model="consoleshow" mode="range" @change="changeConsoleDate"></u-calendar>
  247. <view class="tableList tableTitle">
  248. <view>设备名称</view>
  249. <view>操作内容</view>
  250. <view>操作时间</view>
  251. </view>
  252. <view class="tableList" v-for="(item, index) in tableData" :key="item.uptime">
  253. <view>{{item.device_name}}</view>
  254. <view :class="item.status ? 'success' : 'error'">{{item.operation_content}}</view>
  255. <view>{{item.uptime}}</view>
  256. </view>
  257. <u-loadmore :status="status" />
  258. </view>
  259. </view>
  260. </view>
  261. </template>
  262. <script>
  263. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  264. var canvaColumnA = null;
  265. var canvasRing = null;
  266. export default {
  267. data() {
  268. return {
  269. typeObj: {
  270. 1: '控制柜',
  271. 2: '灌溉泵',
  272. 3: '搅拌机',
  273. 4: '注肥泵',
  274. 5: '阀控器',
  275. 6: '施肥桶'
  276. }, //阀控器类型对应
  277. pickBtnList: [], // 肥料开关列表
  278. resultBan: [], // 搅拌机开关列表
  279. faList: [], // 发空气开关列表
  280. alertTipColor: {
  281. color: '#1890FF',
  282. fontSize: "12px"
  283. },
  284. device_id: '',
  285. mainBengIndex: 0, // 进水泵的位置
  286. mainBeng: false,
  287. feiBeng: false,
  288. feiBengIndex: 0, // 施肥泵的位置
  289. calendarshow: false,
  290. historyTime: {},
  291. cWidth: '350',
  292. cHeight: '350',
  293. pixelRatio: 1,
  294. facilityvalve: [],
  295. feiNum: 0, //肥料桶实际占据通道个数
  296. buttonList: [], // 肥料开关列表
  297. colomRoundList: ['j1', 'j2', 'j3', 'j4', 'j5', 'j6', 'j7', 'j8'], // 废料桶的通道
  298. ElementList: [],
  299. typename: [
  300. "-",
  301. "风机",
  302. "水泵",
  303. "增氧机",
  304. "湿帘",
  305. "遮阳",
  306. "开窗",
  307. "保温",
  308. "投食机",
  309. ],
  310. show: false,
  311. list: [{
  312. name: '设备控制'
  313. }, {
  314. name: '执行结果'
  315. }, {
  316. name: '操作记录'
  317. }],
  318. statusPanel: false,
  319. current: 0,
  320. consoleshow: false,
  321. consoleTime: {},
  322. tableData: [],
  323. page: 1,
  324. total: 0,
  325. status: 'loadmore'
  326. }
  327. },
  328. methods: {
  329. clickLeft() {
  330. uni.navigateBack({
  331. delta: 1
  332. })
  333. },
  334. changeTimeStatus(item, changeIndex) {
  335. this.timer = setTimeout(() => {
  336. item.disabled = false; // 改变值
  337. this.facilityvalve[changeIndex].disabled = false;
  338. this.getEquipstatus()
  339. this.timer = null; // 清空定时器引用
  340. }, 15000);
  341. },
  342. // 选择日期
  343. changeDate(e) {
  344. console.log(e)
  345. this.historyTime = e;
  346. this.getHistoryData()
  347. },
  348. // 绘制折线图
  349. showColumn(id, xtitle, xinfo) {
  350. var _self = this
  351. canvaColumnA = new uCharts({
  352. canvasId: id,
  353. type: 'line',
  354. legend: {
  355. position: "top"
  356. },
  357. fontSize: 11,
  358. background: '#FFFFFF',
  359. pixelRatio: 1,
  360. animation: true,
  361. dataLabel: false,
  362. categories: xtitle,
  363. series: xinfo,
  364. enableScroll: true, //开启图表拖拽功能
  365. xAxis: {
  366. disabled: true,
  367. disableGrid: false,
  368. type: 'grid',
  369. gridType: 'dash',
  370. itemCount: 15, //x轴单屏显示数据的数量,默认为5个
  371. scrollShow: true, //新增是否显示滚动条,默认false
  372. scrollAlign: 'right', //滚动条初始位置
  373. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  374. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  375. },
  376. yAxis: {},
  377. width: _self.cWidth * 1,
  378. height: _self.cHeight * 1,
  379. extra: {
  380. line: {
  381. type: 'curve'
  382. }
  383. }
  384. });
  385. },
  386. touchLineA(e) {
  387. // console.log(e)
  388. canvaColumnA.scrollStart(e);
  389. },
  390. moveLineA(e) {
  391. canvaColumnA.scroll(e);
  392. },
  393. touchEndLineA(e) {
  394. canvaColumnA.touchLegend(e);
  395. // canvaColumnA.showToolTip(e);
  396. canvaColumnA.scrollEnd(e);
  397. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  398. canvaColumnA.showToolTip(e, {
  399. format: function(item, category) {
  400. return category + ' ' + item.name + ':' + item.data
  401. }
  402. });
  403. },
  404. // 时间戳转换
  405. timestampToDateTime(timestamp, isTime) {
  406. var date = new Date(timestamp * 1000); // 将时间戳转换为毫秒并创建一个日期对象
  407. var year = date.getFullYear(); // 获取年份
  408. var month = ('0' + (date.getMonth() + 1)).slice(-2); // 获取月份,并补零
  409. var day = ('0' + date.getDate()).slice(-2); // 获取日期,并补零
  410. var hours = ('0' + date.getHours()).slice(-2); // 获取小时,并补零
  411. var minutes = ('0' + date.getMinutes()).slice(-2); // 获取分钟,并补零
  412. var seconds = ('0' + date.getSeconds()).slice(-2); // 获取秒数,并补零
  413. if (isTime) {
  414. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  415. } else {
  416. return `${year}-${month}-${day}`;
  417. }
  418. },
  419. // 历史数据
  420. async getHistoryData() {
  421. uni.showLoading({
  422. title: '加载中'
  423. });
  424. const {
  425. historyTime
  426. } = this;
  427. // 获取当前日期
  428. var currentDate = new Date();
  429. // 设置时间为 0 点
  430. currentDate.setHours(0, 0, 0, 0);
  431. let begin = historyTime.startDate ? (new Date(historyTime.startDate).getTime() / 1000) - 8 * 3600 : (
  432. Math.floor(currentDate.getTime() / 1000));
  433. // 设置时间为 24 点
  434. currentDate.setHours(24, 0, 0, 0);
  435. let end = historyTime.endDate ? (new Date(historyTime.endDate).getTime() / 1000) - 8 * 3600 : (Math
  436. .floor(currentDate.getTime() / 1000));
  437. //折线图数据
  438. let res = await this.$myRequest({
  439. url: "/api/api_gateway?method=weather.weather.sf_data_chart",
  440. data: {
  441. device_id: this.device_id,
  442. begin: begin,
  443. end: end,
  444. },
  445. })
  446. uni.hideLoading();
  447. var conf = res.conf.eleName;
  448. var dat = res.dat.reverse();
  449. //console.log(dat);
  450. conf = conf.split("/");
  451. // var arr1 = [];
  452. var regroupData = []; //重组数据
  453. let options = [];
  454. var timeList = [];
  455. for (var i = 0; i < conf.length; i++) {
  456. // var arr = [];
  457. if (conf[i] != "-") {
  458. var optionobj = {};
  459. optionobj.value = i;
  460. optionobj.label = conf[i];
  461. options.push(optionobj);
  462. var reddata = [];
  463. dat.forEach((item, index) => {
  464. if (timeList.length < dat.length) {
  465. timeList.push(this.timestampToDateTime(item.uptime, true));
  466. }
  467. var status = item.device_status.split(",");
  468. // //console.log(status);
  469. var arr = [];
  470. for (var j = 0; j < status.length; j++) {
  471. if (status[j].indexOf("e") + 1) {
  472. arr.push(status[j]);
  473. }
  474. }
  475. // //console.log(arr)
  476. var dataobj = {};
  477. for (var k = 0; k < arr.length; k++) {
  478. var indexs = arr[k].indexOf(":");
  479. // //console.log(arr[k])
  480. if (k == 0) {
  481. dataobj[arr[k].slice(1, indexs).trim()] = arr[k]
  482. .substr(indexs + 1)
  483. .trim();
  484. } else {
  485. dataobj[arr[k].slice(0, indexs).trim()] = arr[k]
  486. .substr(indexs + 1)
  487. .trim();
  488. }
  489. }
  490. // //console.log(dataobj)
  491. for (var key in dataobj) {
  492. // //console.log(i)
  493. var str = "'e" + (i + 1) + "'";
  494. // //console.log(key,str);
  495. if (key == str) {
  496. if (Number(dataobj[key]) == 32767) {
  497. // reddata.push([]);
  498. } else {
  499. reddata.push(Number(dataobj[key]));
  500. }
  501. }
  502. }
  503. });
  504. regroupData.push({
  505. name: conf[i],
  506. type: "spline",
  507. fillColor: {
  508. linearGradient: [0, 0, 0, 300],
  509. },
  510. data: reddata,
  511. });
  512. }
  513. }
  514. // console.log(timeList);
  515. this.showColumn('canvasColumnA', timeList, regroupData)
  516. },
  517. // 切换选项卡
  518. change(index) {
  519. this.page = 1;
  520. this.total = 0;
  521. this.current = index;
  522. this.status = 'loadmore';
  523. this.tableData = [];
  524. this.getEquipcontroldata();
  525. },
  526. // 获取要素实时数据
  527. async getElmentInfo() {
  528. uni.showLoading({
  529. title: '加载中'
  530. });
  531. let res = await this.$myRequest({
  532. url: "/api/api_gateway?method=xphsp.views.device_elements",
  533. data: {
  534. device_id: this.device_id,
  535. },
  536. })
  537. uni.hideLoading();
  538. var conf = res.conf.eleName.split('/');
  539. var dataList = [res.data.device_data];
  540. if (dataList.length == 0) return
  541. this.ElementList = [];
  542. conf.forEach((item, index) => {
  543. let obj = {}
  544. if (item == '-') return
  545. obj.name = item;
  546. let valList = dataList[0][`e${index + 1}`].split('#');
  547. obj.value = valList[0];
  548. obj.unit = valList[1];
  549. obj.time = dataList[0].uptime;
  550. this.ElementList.push(obj)
  551. })
  552. // console.log(this.ElementList)
  553. },
  554. // 当前配置的元素列表
  555. async getPickList() {
  556. // e_type类型对应
  557. // 1:'控制柜',
  558. // 2:'灌溉泵',
  559. // 3:'搅拌机',
  560. // 4:'注肥泵',
  561. // 5:'阀控器',
  562. // 6:'施肥桶'
  563. let res = await this.$myRequest({
  564. url: "/api/api_gateway?method=xphsp.views.sf_valve_location_list",
  565. data: {
  566. sf_device_id: this.device_id,
  567. },
  568. });
  569. let pickList = [];
  570. let pickBtnList = []; // 肥料开关
  571. let pickBanList = []; // 肥料搅拌机开关
  572. let faList = []; // 管道阀开关
  573. this.facilityvalve.forEach(item => {
  574. res.forEach((pick, index) => {
  575. if (pick.e_key == item.type) {
  576. let pickObj = Object.assign(pick,item);
  577. // 获取当前灌溉泵位置
  578. if (pick.e_type == 2) {
  579. this.mainBengIndex = pickList.length;
  580. this.mainBeng = pickObj.off;
  581. }
  582. // 获取当前施肥泵位置
  583. if (pick.e_type == 4) {
  584. this.feiBengIndex = pickList.length;
  585. this.feiBeng = pickObj.off;
  586. }
  587. // 获取肥料开关列表
  588. if (pick.e_type == 6) {
  589. pickBtnList.push(pickObj)
  590. }
  591. // 获取搅拌机开关列表
  592. if (pick.e_type == 3) {
  593. pickBanList.push(pickObj)
  594. }
  595. // 获取管道阀开关列表
  596. if (pick.e_type == 1 || pick.e_type == 5) {
  597. faList.push(pickObj)
  598. }
  599. pickList.push(pickObj)
  600. }
  601. })
  602. })
  603. // 把肥料和搅拌机位置对应起来(根据创建时间)
  604. let resultBan = [];
  605. pickBtnList.forEach(fei => {
  606. pickBanList.forEach(ban => {
  607. if (fei.create_time == ban.create_time) {
  608. resultBan.push(ban)
  609. }
  610. })
  611. })
  612. this.pickBtnList = pickBtnList;
  613. this.resultBan = resultBan;
  614. this.faList = faList;
  615. console.log(pickBtnList, pickBanList, resultBan, faList)
  616. },
  617. // 元素状态
  618. async getEquipstatus() {
  619. uni.showLoading({
  620. title: '加载中'
  621. });
  622. this.facilityvalve = [];
  623. let res = await this.$myRequest({
  624. url: "/api/api_gateway?method=xphsp.views.device_info",
  625. data: {
  626. device_id: this.device_id,
  627. },
  628. })
  629. uni.hideLoading();
  630. var conf = res.conf.relayName;
  631. var dataobj = res.device_status;
  632. var relayNum = res.conf.relayNum;
  633. var arr = [];
  634. function numberToArray(number) {
  635. // 将数字转换为字符串
  636. let numString = number.toString();
  637. // 创建一个空数组,用于存储结果
  638. let result = [];
  639. // 遍历字符串的每个字符,并将其转换为对应的数字
  640. for (let i = 0; i < numString.length; i++) {
  641. result.push(parseInt(numString.charAt(i)));
  642. }
  643. return result;
  644. }
  645. for (var i = 0; i < dataobj.length; i++) {
  646. // if (offobj[i].indexOf("j") + 1) {
  647. arr.push(offobj[i]);
  648. // }
  649. }
  650. conf = conf.split("/");
  651. relayNum = relayNum.split("/");
  652. var arr1 = [];
  653. var reg = /\d/;
  654. let totalP = Math.ceil((conf.length) / 32); //总圈数
  655. for (var i = 0; i < conf.length; i++) {
  656. var obj = {};
  657. obj.name = conf[i];
  658. // if (reg.test(conf[i])) {
  659. // obj.name2 = conf[i].slice(0, conf[i].length - 1);
  660. // } else {
  661. // obj.name2 = conf[i];
  662. // }
  663. obj.name2 = this.typename[relayNum[i]];
  664. obj.number = i;
  665. obj.type = `j${i + 1}`;
  666. obj.disabled = false;
  667. // "state": 1 继电器打开 ;"state": 0 继电器关闭
  668. // 处理开关值
  669. // J开头表示状态,总共只有32长度,超过32则从头赋值 位数多一位
  670. // 例:1和33是都在J1里面,返回值是一个二进制数 倒数第一位表示第一个 第二位表示33状态 以此类推
  671. // 根据总长度 为超过32的j赋值
  672. // 当前是循环的第几轮
  673. let baseP = Math.ceil((i + 1) / 32);
  674. if (i > 31) {
  675. dataobj[`j${i + 1}`] = dataobj[
  676. `j${(i + 1) % 32 == 0 ? 32 : (i + 1) % 32}`]; // 当前脚标/32取余 当恰好整除的时候 取32
  677. }
  678. dataobj[`j${i + 1}`] = dataobj[`j${i + 1}`].slice(-totalP); // 截取当前圈数的最后几位数字
  679. let baseOff = numberToArray(dataobj[`j${i + 1}`]); // 把当前值根据位数 转换为数组
  680. obj.off = baseOff[baseP - 1] == '0' ? false : true; // 根据当前圈数,取对应的数组的值
  681. arr1.push(obj);
  682. }
  683. for (var i = 0; i < arr1.length; i++) {
  684. if (arr1[i].name != "-") {
  685. this.facilityvalve.push(arr1[i]);
  686. }
  687. }
  688. let feiNum = 0; // 记录废料桶占据通道个数,两个通道为一个肥料桶
  689. this.buttonList = [];
  690. this.facilityvalve.forEach((item, index) => {
  691. if (this.colomRoundList.indexOf(item.type) > -1) {
  692. feiNum++;
  693. this.buttonList.push(item);
  694. }
  695. })
  696. this.feiNum = feiNum;
  697. this.getPickList();
  698. console.log(this.facilityvalve)
  699. },
  700. async getEquipcontrol(num, state, double_order) {
  701. //设备控制
  702. uni.showLoading({
  703. title: '正在下发指令'
  704. });
  705. let res = await this.$myRequest({
  706. url: "/api/api_gateway?method=xphsp.views.control_order",
  707. data: {
  708. device_id: this.device_id,
  709. relayNum: num,
  710. relayState: state,
  711. double_order
  712. },
  713. })
  714. uni.hideLoading();
  715. if (res.msg_code == 200) {
  716. uni.showToast({
  717. title: '指令下发成功',
  718. duration: 2000,
  719. icon: 'none'
  720. });
  721. } else {
  722. uni.showToast({
  723. title: res.msg,
  724. duration: 2000,
  725. icon: 'none'
  726. })
  727. setTimeout(() => {
  728. this.getEquipstatus()
  729. }, 2000)
  730. }
  731. },
  732. // sf_control_data
  733. // 操作记录日期
  734. changeConsoleDate(e) {
  735. this.consoleTime = e;
  736. this.tableData = [];
  737. this.page = 1;
  738. this.getEquipcontroldata()
  739. },
  740. clearContime() {
  741. this.consoleTime = {};
  742. this.tableData = [];
  743. this.page = 1;
  744. this.getEquipcontroldata()
  745. },
  746. //操作记录
  747. async getEquipcontroldata() {
  748. uni.showLoading({
  749. title: '加载中'
  750. });
  751. const {
  752. consoleTime
  753. } = this;
  754. let begin = consoleTime.startDate ? new Date(consoleTime.startDate).getTime() / 1000 : '';
  755. let end = consoleTime.endDate ? new Date(consoleTime.endDate).getTime() / 1000 : '';
  756. //操作记录
  757. let res = await this.$myRequest({
  758. method: "POST",
  759. url: "/api/api_gateway?method=xphsp.views.control_log",
  760. data: {
  761. device_id: this.device_id,
  762. page_num: this.page,
  763. page_size: 15,
  764. start: begin,
  765. end: end,
  766. sys_control: this.current - 1
  767. },
  768. })
  769. uni.hideLoading();
  770. // this.tableData = [];
  771. var record = res.result;
  772. this.tableData = [...this.tableData, ...record];
  773. this.total = res.count;
  774. if (this.page * 15 > this.total) {
  775. this.status = 'nomore'
  776. } else {
  777. this.status = 'loadmore'
  778. }
  779. // console.log(this.tableData);
  780. },
  781. switchchange(e, state, item, index, isfeiButton) {
  782. // 是否是肥料开关,是的话 两个合并为一个
  783. item.disabled = true;
  784. if (isfeiButton) {
  785. item.off = e;
  786. this.changeTimeStatus(item, index);
  787. // 当前是打开
  788. if (e) {
  789. // 打开通道传1,关闭通道传0
  790. this.getEquipcontrol(state, 1, 1);
  791. // this.getEquipcontrol(state + 1, 0);
  792. } else {
  793. // this.getEquipcontrol(state + 1, 0);
  794. this.getEquipcontrol(state, 0, 1);
  795. }
  796. return
  797. }
  798. item.off = e;
  799. if (item.type == 'j10') {
  800. // 判断注水泵是否打开
  801. this.mainBeng = e;
  802. }
  803. if (item.type == 'j9') {
  804. // 判断施肥阀是否打开
  805. this.feiBeng = e;
  806. }
  807. // if (this.colomRoundList.indexOf(item.type) > -1) {
  808. // let changeIndex = index;
  809. // if ((index + 1) % 2 == 0) {
  810. // // 偶数 往前取值
  811. // this.facilityvalve[index - 1].disabled = true;
  812. // changeIndex = index - 1;
  813. // } else if ((index + 1) % 2 == 1) {
  814. // // 基数 往后取值
  815. // this.facilityvalve[index + 1].disabled = true;
  816. // changeIndex = index + 1;
  817. // }
  818. // item.disabled = true;
  819. // this.changeTimeStatus(item, changeIndex);
  820. // this.getEquipcontrol(changeIndex, Number(!e));
  821. // } else {
  822. // }
  823. item.disabled = true;
  824. this.changeTimeStatus(item, index);
  825. //console.log(Number(e), state);
  826. this.getEquipcontrol(state, Number(e));
  827. },
  828. currentchange(e) {
  829. //页码
  830. if (this.type == 0) {
  831. this.pageDialog = e;
  832. } else {
  833. this.page = e;
  834. }
  835. this.getEquipcontroldata(this.type);
  836. },
  837. },
  838. onReachBottom() {
  839. if (this.current != 0 && this.status == 'loadmore') {
  840. this.page++;
  841. this.getEquipcontroldata()
  842. }
  843. },
  844. onLoad(option) {
  845. let deviceItem = JSON.parse(option.shebei)
  846. this.device_id = deviceItem.device_id;
  847. this.getEquipstatus();
  848. this.getElmentInfo();
  849. this.getEquipcontroldata();
  850. // this.getPickList();
  851. }
  852. }
  853. </script>
  854. <style scoped lang="less">
  855. .circleAnm {
  856. animation: ancirle 1s linear infinite;
  857. }
  858. // 旋转
  859. @keyframes ancirle {
  860. 0% {
  861. transform: rotate(360deg);
  862. }
  863. 100% {
  864. transform: rotate(0);
  865. }
  866. }
  867. .box {
  868. position: relative;
  869. width: 100%;
  870. min-height: 100vh;
  871. overflow: auto;
  872. padding-top: 40px;
  873. }
  874. .bigBox {
  875. width: 100%;
  876. padding-top: 40px;
  877. }
  878. .bigOpen {
  879. height: 100vh;
  880. }
  881. /deep/ .u-flex {
  882. display: flex;
  883. justify-content: center;
  884. }
  885. .topInfo {
  886. background: #14A478;
  887. color: #fff;
  888. font-size: 28rpx;
  889. padding-bottom: 32rpx;
  890. box-sizing: border-box;
  891. border-bottom-left-radius: 16rpx;
  892. border-bottom-right-radius: 16rpx;
  893. /deep/ .u-col {
  894. box-sizing: border-box;
  895. margin-top: 32rpx;
  896. box-sizing: border-box;
  897. .item {
  898. text-align: center;
  899. view:first-child {
  900. font-size: 40rpx;
  901. }
  902. view:nth-child(2) {
  903. font-size: 24rpx;
  904. line-height: 40rpx;
  905. opacity: .72;
  906. }
  907. }
  908. }
  909. }
  910. .readmore {
  911. text-align: center;
  912. font-size: 26rpx;
  913. line-height: 40rpx;
  914. margin-top: 32rpx;
  915. color: #93FFDE;
  916. .u-icon {
  917. margin-left: 15rpx;
  918. }
  919. }
  920. .histimeBox {
  921. display: flex;
  922. align-items: center;
  923. justify-content: space-between;
  924. height: 56rpx;
  925. padding: 6rpx 24rpx;
  926. box-sizing: border-box;
  927. border-radius: 8rpx;
  928. margin-top: 54rpx;
  929. border: 2rpx solid var(--neutral-color-border-light, #E4EDEA);
  930. .u-icon {
  931. z-index: 10;
  932. }
  933. .time {
  934. width: 280rpx;
  935. color: #C1C1C1;
  936. }
  937. view {
  938. color: #333333;
  939. text-align: center;
  940. }
  941. }
  942. .consoleBox {
  943. position: relative;
  944. max-height: 75vh;
  945. padding-bottom: 80rpx;
  946. overflow: auto;
  947. .u-row {
  948. box-sizing: border-box;
  949. .u-col {
  950. box-sizing: border-box;
  951. }
  952. }
  953. .u-btn {
  954. position: absolute;
  955. bottom: 0;
  956. left: 0;
  957. right: 0;
  958. background: #14A478;
  959. }
  960. .swichBox {
  961. position: relative;
  962. padding: 32rpx;
  963. overflow: hidden;
  964. .preSwich {
  965. display: flex;
  966. align-items: center;
  967. justify-content: space-between;
  968. padding: 24rpx 18rpx;
  969. border-radius: 8rpx;
  970. background: #EFF2FA;
  971. margin-bottom: 32rpx;
  972. view {
  973. color: #333333;
  974. font-size: 28rpx;
  975. }
  976. }
  977. }
  978. }
  979. .hisBox {
  980. position: relative;
  981. width: 100vw;
  982. padding-bottom: 100rpx;
  983. box-sizing: border-box;
  984. overflow-y: scroll;
  985. .axiosBox {
  986. position: relative;
  987. padding: 48rpx 32rpx;
  988. .title {
  989. color: #333333;
  990. font-size: 28rpx;
  991. font-weight: 700;
  992. }
  993. .chartBox {
  994. position: relative;
  995. margin-top: 32rpx;
  996. height: 800rpx;
  997. overflow: hidden;
  998. #canvasColumnA {
  999. width: 100%;
  1000. height: 800rpx;
  1001. }
  1002. }
  1003. }
  1004. .readmoreHIs {
  1005. position: absolute;
  1006. bottom: 60rpx;
  1007. left: 50%;
  1008. transform: translate(-50%);
  1009. color: #14A478;
  1010. z-index: 5;
  1011. }
  1012. }
  1013. .devicePhoto {
  1014. padding: 32rpx;
  1015. .titleBox {
  1016. display: flex;
  1017. align-items: center;
  1018. justify-content: space-between;
  1019. .btn {
  1020. padding: 10rpx 14rpx;
  1021. border-radius: 8rpx;
  1022. background: #14A478;
  1023. color: #fff;
  1024. font-size: 28rpx;
  1025. }
  1026. }
  1027. .main {
  1028. position: relative;
  1029. width: 678rpx;
  1030. height: 612rpx;
  1031. margin-top: 10px;
  1032. .mainContent {
  1033. position: absolute;
  1034. left: 50%;
  1035. transform: translateX(-50%);
  1036. width: 678rpx;
  1037. top: 10rpx;
  1038. height: 602rpx;
  1039. z-index: 1;
  1040. }
  1041. .sourceBox {
  1042. position: absolute;
  1043. left: 20rpx;
  1044. z-index: 2;
  1045. display: flex;
  1046. align-items: center;
  1047. justify-content: center;
  1048. width: 112rpx;
  1049. height: 112rpx;
  1050. background: #E3FDFF;
  1051. border-radius: 112rpx;
  1052. color: #fff;
  1053. view {
  1054. width: 85rpx;
  1055. height: 85rpx;
  1056. background: #1890FF;
  1057. border-radius: 85rpx;
  1058. text-align: center;
  1059. line-height: 85rpx;
  1060. font-size: 28rpx;
  1061. }
  1062. }
  1063. .colList {
  1064. position: absolute;
  1065. z-index: 2;
  1066. top: 44rpx;
  1067. left: 154rpx;
  1068. width: 528rpx;
  1069. display: flex;
  1070. justify-content: center;
  1071. overflow: hidden;
  1072. .preClo {
  1073. position: relative;
  1074. float: left;
  1075. width: 88rpx;
  1076. // margin-left: 40rpx;
  1077. view {
  1078. text-align: center;
  1079. color: #333333;
  1080. font-size: 28rpx;
  1081. margin-bottom: 20rpx;
  1082. }
  1083. image {
  1084. width: 88rpx;
  1085. height: 272rpx;
  1086. }
  1087. .shanBox {
  1088. position: absolute;
  1089. width: 64rpx;
  1090. height: 64rpx;
  1091. top: 116rpx;
  1092. left: 50%;
  1093. transform: translateX(-50%);
  1094. z-index: 2;
  1095. image {
  1096. width: 64rpx;
  1097. height: 64rpx;
  1098. }
  1099. }
  1100. .jiaoBtn {
  1101. position: absolute;
  1102. width: 64rpx;
  1103. height: 32rpx;
  1104. top: 72rpx;
  1105. left: 50%;
  1106. transform: translateX(-50%);
  1107. z-index: 2;
  1108. /deep/ .u-switch__node {
  1109. width: 28rpx !important;
  1110. height: 28rpx !important;
  1111. top: 2rpx !important;
  1112. }
  1113. /deep/ .u-switch__loading {
  1114. height: 20rpx !important;
  1115. }
  1116. /deep/ .u-switch {
  1117. width: 64rpx;
  1118. height: 32rpx;
  1119. }
  1120. /deep/ .u-switch--on .u-switch__node {
  1121. transform: translateX(36rpx) !important;
  1122. }
  1123. }
  1124. .btnBox {
  1125. position: absolute;
  1126. width: 66rpx;
  1127. height: 72rpx;
  1128. bottom: 40rpx;
  1129. left: 22rpx;
  1130. z-index: 2;
  1131. image {
  1132. width: 66rpx;
  1133. height: 72rpx;
  1134. }
  1135. }
  1136. }
  1137. }
  1138. .benList {
  1139. position: absolute;
  1140. width: 678rpx;
  1141. left: 50%;
  1142. transform: translateX(-50%);
  1143. top: 610rpx;
  1144. .preBen {
  1145. float: left;
  1146. text-align: center;
  1147. width: 20%;
  1148. .daoguan {
  1149. width: 20rpx;
  1150. height: 40rpx;
  1151. }
  1152. .info {
  1153. color: #333333;
  1154. font-size: 12px;
  1155. font-weight: 400;
  1156. }
  1157. .status {
  1158. width: 76rpx;
  1159. height: 100rpx;
  1160. margin-top: 10rpx;
  1161. }
  1162. }
  1163. }
  1164. .lineExit {}
  1165. .exit {
  1166. position: absolute;
  1167. width: 22rpx;
  1168. height: 20rpx;
  1169. top: 360rpx;
  1170. right: 251rpx;
  1171. z-index: 2;
  1172. image {
  1173. width: 22rpx;
  1174. height: 20rpx;
  1175. }
  1176. }
  1177. .warterIn {
  1178. position: absolute;
  1179. width: 66rpx;
  1180. height: 72rpx;
  1181. top: 190rpx;
  1182. left: 52rpx;
  1183. z-index: 3;
  1184. image {
  1185. width: 66rpx;
  1186. height: 72rpx;
  1187. }
  1188. }
  1189. .warterLight {
  1190. position: absolute;
  1191. width: 72rpx;
  1192. height: 48rpx;
  1193. top: 506rpx;
  1194. left: 110rpx;
  1195. z-index: 3;
  1196. image {
  1197. width: 72rpx;
  1198. height: 48rpx;
  1199. }
  1200. }
  1201. .feiLight {
  1202. position: absolute;
  1203. width: 72rpx;
  1204. height: 66rpx;
  1205. top: 424rpx;
  1206. right: 140rpx;
  1207. z-index: 3;
  1208. image {
  1209. width: 72rpx;
  1210. height: 66rpx;
  1211. }
  1212. }
  1213. .kongBox {
  1214. position: absolute;
  1215. width: 84rpx;
  1216. height: 108rpx;
  1217. top: 390rpx;
  1218. right: 228rpx;
  1219. z-index: 3;
  1220. image {
  1221. width: 84rpx;
  1222. height: 108rpx;
  1223. }
  1224. }
  1225. .fengBox {
  1226. position: absolute;
  1227. right: 12rpx;
  1228. top: 270rpx;
  1229. width: 55rpx;
  1230. height: 44rpx;
  1231. z-index: 2;
  1232. .relativeBox {
  1233. position: relative;
  1234. width: 100%;
  1235. height: 100%;
  1236. image:nth-child(1) {
  1237. width: 16rpx;
  1238. height: 32rpx;
  1239. }
  1240. image:nth-child(2) {
  1241. position: absolute;
  1242. right: 0;
  1243. top: -6rpx;
  1244. width: 44rpx;
  1245. height: 44rpx;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. .consoleList {
  1252. padding: 0 32rpx;
  1253. .histimeBox {
  1254. margin: 32rpx 0;
  1255. }
  1256. .tableTitle {
  1257. background: #E8F3F0;
  1258. color: #333;
  1259. font-weight: 600;
  1260. }
  1261. .tableList {
  1262. font-size: 28rpx;
  1263. height: 78rpx;
  1264. color: #666666;
  1265. display: flex;
  1266. justify-content: space-between;
  1267. align-items: center;
  1268. border-bottom: 2rpx solid var(--neutral-color-border-base, #DCE6E3);
  1269. view {
  1270. text-align: center;
  1271. }
  1272. .success {
  1273. color: #14A478;
  1274. }
  1275. .error {
  1276. color: #FF5951;
  1277. }
  1278. view:nth-child(1) {
  1279. width: 120rpx;
  1280. text-align: left;
  1281. }
  1282. view:nth-child(2) {
  1283. width: 280rpx;
  1284. }
  1285. view:nth-child(3) {
  1286. width: 280rpx;
  1287. }
  1288. }
  1289. }
  1290. </style>