details.vue 34 KB

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