details.vue 33 KB

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