details.vue 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  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. {{resultBan[index].e_name}}
  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.e_status, 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.e_status" 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. res.forEach((pick, index) => {
  574. this.facilityvalve.forEach(item => {
  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. this.$forceUpdate()
  846. let deviceItem = JSON.parse(option.shebei)
  847. this.device_id = deviceItem.device_id;
  848. this.getEquipstatus();
  849. this.getElmentInfo();
  850. this.getEquipcontroldata();
  851. // this.getPickList();
  852. }
  853. }
  854. </script>
  855. <style scoped lang="less">
  856. .circleAnm {
  857. animation: ancirle 1s linear infinite;
  858. }
  859. // 旋转
  860. @keyframes ancirle {
  861. 0% {
  862. transform: rotate(360deg);
  863. }
  864. 100% {
  865. transform: rotate(0);
  866. }
  867. }
  868. .box {
  869. position: relative;
  870. width: 100%;
  871. min-height: 100vh;
  872. overflow: auto;
  873. padding-top: 40px;
  874. }
  875. .bigBox {
  876. width: 100%;
  877. padding-top: 40px;
  878. }
  879. .bigOpen {
  880. height: 100vh;
  881. }
  882. /deep/ .u-flex {
  883. display: flex;
  884. justify-content: center;
  885. }
  886. .topInfo {
  887. background: #14A478;
  888. color: #fff;
  889. font-size: 28rpx;
  890. padding-bottom: 32rpx;
  891. box-sizing: border-box;
  892. border-bottom-left-radius: 16rpx;
  893. border-bottom-right-radius: 16rpx;
  894. /deep/ .u-col {
  895. box-sizing: border-box;
  896. margin-top: 32rpx;
  897. box-sizing: border-box;
  898. .item {
  899. text-align: center;
  900. view:first-child {
  901. font-size: 40rpx;
  902. }
  903. view:nth-child(2) {
  904. font-size: 24rpx;
  905. line-height: 40rpx;
  906. opacity: .72;
  907. }
  908. }
  909. }
  910. }
  911. .readmore {
  912. text-align: center;
  913. font-size: 26rpx;
  914. line-height: 40rpx;
  915. margin-top: 32rpx;
  916. color: #93FFDE;
  917. .u-icon {
  918. margin-left: 15rpx;
  919. }
  920. }
  921. .histimeBox {
  922. display: flex;
  923. align-items: center;
  924. justify-content: space-between;
  925. height: 56rpx;
  926. padding: 6rpx 24rpx;
  927. box-sizing: border-box;
  928. border-radius: 8rpx;
  929. margin-top: 54rpx;
  930. border: 2rpx solid var(--neutral-color-border-light, #E4EDEA);
  931. .u-icon {
  932. z-index: 10;
  933. }
  934. .time {
  935. width: 280rpx;
  936. color: #C1C1C1;
  937. }
  938. view {
  939. color: #333333;
  940. text-align: center;
  941. }
  942. }
  943. .consoleBox {
  944. position: relative;
  945. max-height: 75vh;
  946. padding-bottom: 80rpx;
  947. overflow: auto;
  948. .u-row {
  949. box-sizing: border-box;
  950. .u-col {
  951. box-sizing: border-box;
  952. }
  953. }
  954. .u-btn {
  955. position: absolute;
  956. bottom: 0;
  957. left: 0;
  958. right: 0;
  959. background: #14A478;
  960. }
  961. .swichBox {
  962. position: relative;
  963. padding: 32rpx;
  964. overflow: hidden;
  965. .preSwich {
  966. display: flex;
  967. align-items: center;
  968. justify-content: space-between;
  969. padding: 24rpx 18rpx;
  970. border-radius: 8rpx;
  971. background: #EFF2FA;
  972. margin-bottom: 32rpx;
  973. view {
  974. color: #333333;
  975. font-size: 28rpx;
  976. }
  977. }
  978. }
  979. }
  980. .hisBox {
  981. position: relative;
  982. width: 100vw;
  983. padding-bottom: 100rpx;
  984. box-sizing: border-box;
  985. overflow-y: scroll;
  986. .axiosBox {
  987. position: relative;
  988. padding: 48rpx 32rpx;
  989. .title {
  990. color: #333333;
  991. font-size: 28rpx;
  992. font-weight: 700;
  993. }
  994. .chartBox {
  995. position: relative;
  996. margin-top: 32rpx;
  997. height: 800rpx;
  998. overflow: hidden;
  999. #canvasColumnA {
  1000. width: 100%;
  1001. height: 800rpx;
  1002. }
  1003. }
  1004. }
  1005. .readmoreHIs {
  1006. position: absolute;
  1007. bottom: 60rpx;
  1008. left: 50%;
  1009. transform: translate(-50%);
  1010. color: #14A478;
  1011. z-index: 5;
  1012. }
  1013. }
  1014. .devicePhoto {
  1015. padding: 32rpx;
  1016. .titleBox {
  1017. display: flex;
  1018. align-items: center;
  1019. justify-content: space-between;
  1020. .btn {
  1021. padding: 10rpx 14rpx;
  1022. border-radius: 8rpx;
  1023. background: #14A478;
  1024. color: #fff;
  1025. font-size: 28rpx;
  1026. }
  1027. }
  1028. .main {
  1029. position: relative;
  1030. width: 678rpx;
  1031. height: 612rpx;
  1032. margin-top: 10px;
  1033. .mainContent {
  1034. position: absolute;
  1035. left: 50%;
  1036. transform: translateX(-50%);
  1037. width: 678rpx;
  1038. top: 10rpx;
  1039. height: 602rpx;
  1040. z-index: 1;
  1041. }
  1042. .sourceBox {
  1043. position: absolute;
  1044. left: 20rpx;
  1045. z-index: 2;
  1046. display: flex;
  1047. align-items: center;
  1048. justify-content: center;
  1049. width: 112rpx;
  1050. height: 112rpx;
  1051. background: #E3FDFF;
  1052. border-radius: 112rpx;
  1053. color: #fff;
  1054. view {
  1055. width: 85rpx;
  1056. height: 85rpx;
  1057. background: #1890FF;
  1058. border-radius: 85rpx;
  1059. text-align: center;
  1060. line-height: 85rpx;
  1061. font-size: 28rpx;
  1062. }
  1063. }
  1064. .colList {
  1065. position: absolute;
  1066. z-index: 2;
  1067. top: 44rpx;
  1068. left: 154rpx;
  1069. width: 528rpx;
  1070. display: flex;
  1071. justify-content: center;
  1072. overflow: hidden;
  1073. .preClo {
  1074. position: relative;
  1075. float: left;
  1076. width: 88rpx;
  1077. // margin-left: 40rpx;
  1078. view {
  1079. text-align: center;
  1080. color: #333333;
  1081. font-size: 28rpx;
  1082. margin-bottom: 20rpx;
  1083. }
  1084. image {
  1085. width: 88rpx;
  1086. height: 272rpx;
  1087. }
  1088. .shanBox {
  1089. position: absolute;
  1090. width: 64rpx;
  1091. height: 64rpx;
  1092. top: 116rpx;
  1093. left: 50%;
  1094. transform: translateX(-50%);
  1095. z-index: 2;
  1096. image {
  1097. width: 64rpx;
  1098. height: 64rpx;
  1099. }
  1100. }
  1101. .jiaoBtn {
  1102. position: absolute;
  1103. width: 64rpx;
  1104. height: 32rpx;
  1105. top: 72rpx;
  1106. left: 50%;
  1107. transform: translateX(-50%);
  1108. z-index: 2;
  1109. /deep/ .u-switch__node {
  1110. width: 28rpx !important;
  1111. height: 28rpx !important;
  1112. top: 2rpx !important;
  1113. }
  1114. /deep/ .u-switch__loading {
  1115. height: 20rpx !important;
  1116. }
  1117. /deep/ .u-switch {
  1118. width: 64rpx;
  1119. height: 32rpx;
  1120. }
  1121. /deep/ .u-switch--on .u-switch__node {
  1122. transform: translateX(36rpx) !important;
  1123. }
  1124. }
  1125. .btnBox {
  1126. position: absolute;
  1127. width: 66rpx;
  1128. height: 72rpx;
  1129. bottom: 40rpx;
  1130. left: 22rpx;
  1131. z-index: 2;
  1132. image {
  1133. width: 66rpx;
  1134. height: 72rpx;
  1135. }
  1136. }
  1137. }
  1138. }
  1139. .benList {
  1140. position: absolute;
  1141. width: 678rpx;
  1142. left: 50%;
  1143. transform: translateX(-50%);
  1144. top: 610rpx;
  1145. .preBen {
  1146. float: left;
  1147. text-align: center;
  1148. width: 20%;
  1149. .daoguan {
  1150. width: 20rpx;
  1151. height: 40rpx;
  1152. }
  1153. .info {
  1154. color: #333333;
  1155. font-size: 12px;
  1156. font-weight: 400;
  1157. }
  1158. .status {
  1159. width: 76rpx;
  1160. height: 100rpx;
  1161. margin-top: 10rpx;
  1162. }
  1163. }
  1164. }
  1165. .lineExit {}
  1166. .exit {
  1167. position: absolute;
  1168. width: 22rpx;
  1169. height: 20rpx;
  1170. top: 360rpx;
  1171. right: 251rpx;
  1172. z-index: 2;
  1173. image {
  1174. width: 22rpx;
  1175. height: 20rpx;
  1176. }
  1177. }
  1178. .warterIn {
  1179. position: absolute;
  1180. width: 66rpx;
  1181. height: 72rpx;
  1182. top: 190rpx;
  1183. left: 52rpx;
  1184. z-index: 3;
  1185. image {
  1186. width: 66rpx;
  1187. height: 72rpx;
  1188. }
  1189. }
  1190. .warterLight {
  1191. position: absolute;
  1192. width: 72rpx;
  1193. height: 48rpx;
  1194. top: 506rpx;
  1195. left: 110rpx;
  1196. z-index: 3;
  1197. image {
  1198. width: 72rpx;
  1199. height: 48rpx;
  1200. }
  1201. }
  1202. .feiLight {
  1203. position: absolute;
  1204. width: 72rpx;
  1205. height: 66rpx;
  1206. top: 424rpx;
  1207. right: 140rpx;
  1208. z-index: 3;
  1209. image {
  1210. width: 72rpx;
  1211. height: 66rpx;
  1212. }
  1213. }
  1214. .kongBox {
  1215. position: absolute;
  1216. width: 84rpx;
  1217. height: 108rpx;
  1218. top: 390rpx;
  1219. right: 228rpx;
  1220. z-index: 3;
  1221. image {
  1222. width: 84rpx;
  1223. height: 108rpx;
  1224. }
  1225. }
  1226. .fengBox {
  1227. position: absolute;
  1228. right: 12rpx;
  1229. top: 270rpx;
  1230. width: 55rpx;
  1231. height: 44rpx;
  1232. z-index: 2;
  1233. .relativeBox {
  1234. position: relative;
  1235. width: 100%;
  1236. height: 100%;
  1237. image:nth-child(1) {
  1238. width: 16rpx;
  1239. height: 32rpx;
  1240. }
  1241. image:nth-child(2) {
  1242. position: absolute;
  1243. right: 0;
  1244. top: -6rpx;
  1245. width: 44rpx;
  1246. height: 44rpx;
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. .consoleList {
  1253. padding: 0 32rpx;
  1254. .histimeBox {
  1255. margin: 32rpx 0;
  1256. }
  1257. .tableTitle {
  1258. background: #E8F3F0;
  1259. color: #333;
  1260. font-weight: 600;
  1261. }
  1262. .tableList {
  1263. font-size: 28rpx;
  1264. height: 78rpx;
  1265. color: #666666;
  1266. display: flex;
  1267. justify-content: space-between;
  1268. align-items: center;
  1269. border-bottom: 2rpx solid var(--neutral-color-border-base, #DCE6E3);
  1270. view {
  1271. text-align: center;
  1272. }
  1273. .success {
  1274. color: #14A478;
  1275. }
  1276. .error {
  1277. color: #FF5951;
  1278. }
  1279. view:nth-child(1) {
  1280. width: 120rpx;
  1281. text-align: left;
  1282. }
  1283. view:nth-child(2) {
  1284. width: 280rpx;
  1285. }
  1286. view:nth-child(3) {
  1287. width: 280rpx;
  1288. }
  1289. }
  1290. }
  1291. </style>