details.vue 33 KB

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