history.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="timeandtype">
  5. <view class="timebox">
  6. <view class="firsttime" @click="timeshow = true">
  7. <view class="" v-if="start_time != ''">
  8. {{
  9. ((start_time == '' ? '请选择开始时间' : start_time) / 1000)
  10. | timeFormat()
  11. }}
  12. </view>
  13. <view class="" v-else>
  14. {{ start_time == '' ? '请选择开始时间' : start_time }}
  15. </view>
  16. </view>
  17. <view class="jiange"> - </view>
  18. <view class="endtime" @click="timeshow = true">
  19. <view class="" v-if="end_time != ''">
  20. {{
  21. ((end_time == '' ? '请选择结束时间' : end_time) / 1000)
  22. | timeFormat()
  23. }}
  24. </view>
  25. <view class="" v-else>
  26. {{ end_time == '' ? '请选择结束时间' : end_time }}
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="refresh" @click="refresh"> 刷 新 </view>
  32. <view class="condition">
  33. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  34. <table class="table">
  35. <tr class="tr">
  36. <th class="th" v-for="(item, index) in thdata" :key="'a' + index">
  37. {{ item }}
  38. </th>
  39. </tr>
  40. <tr
  41. class="tr"
  42. v-for="(items, indexs) in historylistdata"
  43. :key="'b' + indexs"
  44. v-if="!forbidden"
  45. >
  46. <td class="td">{{ items.addtime | timeFormat() }}</td>
  47. <td class="td">{{ items.at == '' ? '--' : items.ah / 10 }}</td>
  48. <td class="td">{{ items.ah == '' ? '--' : items.at / 10 }}</td>
  49. <td class="td">{{ items.ds == 1 ? '开机' : '关机' }}</td>
  50. </tr>
  51. <tr class="tr" v-if="forbidden">
  52. <td class="td" v-for="item in 8">暂无数据</td>
  53. </tr>
  54. </table>
  55. </scroll-view>
  56. <view class="pagenumber">
  57. <button @click="prev">上一页</button>
  58. <view class="pagenumber_page"> 第 {{ page }} 页 </view>
  59. <view class="pagenumber_page"> 共 {{ pagesum }} 页 </view>
  60. <button @click="next" :disabled="forbidden">下一页</button>
  61. </view>
  62. </view>
  63. </view>
  64. <u-calendar
  65. v-model="timeshow"
  66. :mode="mode"
  67. @change="timechange"
  68. ></u-calendar>
  69. </view>
  70. </template>
  71. <script>
  72. import uCharts from '../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  73. var canvaColumnA = null;
  74. export default {
  75. data() {
  76. return {
  77. styles: {
  78. // width: "650rpx",
  79. height: '400rpx',
  80. },
  81. d_id: '',
  82. start_time: '',
  83. end_time: '',
  84. historydatas: [],
  85. titletext: ['24小时', '近一个月', '近半年', '近一年'],
  86. titleidnex: 0,
  87. device_id: '',
  88. page: 1,
  89. historylistdata: [],
  90. thdata: ['上报时间', '空气湿度(%RH)', '空气温度(°C)', '开机状态'],
  91. forbidden: false,
  92. pixelRatio: 1,
  93. canvastishiTF: false, //暂无数据提示
  94. dataloadingtf: true, //加载中提示
  95. pagesum: 1,
  96. worms: [],
  97. timeshow: false,
  98. mode: 'range',
  99. };
  100. },
  101. methods: {
  102. //forecast.worm_lamp.device_history_data历史数据列表
  103. async historylist() {
  104. //历史数据列表
  105. const res = await this.$myRequest({
  106. url: '/api/api_gateway?method=forecast.worm_lamp.color_attract_list',
  107. data: {
  108. d_id: this.d_id,
  109. start_time: parseInt(this.start_time / 1000),
  110. end_time: parseInt(this.end_time / 1000),
  111. page: this.page,
  112. page_size: 10,
  113. },
  114. });
  115. this.historylistdata = res.data;
  116. console.log(res.data);
  117. this.pagesum = Math.ceil(res.counts / 10) || 1;
  118. if (res.data.length == 0) {
  119. this.forbidden = true;
  120. } else {
  121. this.forbidden = false;
  122. }
  123. console.log(this.historylistdata);
  124. },
  125. // forecast.send_control.get_device_config 获取当前时间的数据
  126. // async newdata() {
  127. // const res = await this.$myRequest({
  128. // url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_mqtt',
  129. // data: {
  130. // d_id: this.d_id
  131. // }
  132. // })
  133. // if (res) {
  134. // uni.showToast({
  135. // title: '刷新成功',
  136. // duration: 2000,
  137. // icon: "none"
  138. // });
  139. // } else {
  140. // uni.showToast({
  141. // title: '刷新失败',
  142. // duration: 2000,
  143. // icon: "none"
  144. // });
  145. // }
  146. // },
  147. refresh() {
  148. //获取当前时间的数据
  149. this.historylist();
  150. },
  151. prev() {
  152. //上一页
  153. if (this.page > 1) {
  154. this.page--;
  155. this.historylist();
  156. }
  157. },
  158. next() {
  159. //下一页
  160. if (this.page < this.pagesum) {
  161. this.page++;
  162. this.historylist();
  163. }
  164. },
  165. clickLeft() {
  166. uni.navigateBack({
  167. delta: 1,
  168. });
  169. },
  170. closetime() {
  171. this.start_time = '';
  172. this.end_time = '';
  173. this.listpage = 1;
  174. this.historylist();
  175. },
  176. timechange(e) {
  177. console.log(e);
  178. this.start_time = +new Date(e.startDate);
  179. this.end_time = +new Date(e.endDate);
  180. this.listpage = 1;
  181. this.historylist();
  182. },
  183. },
  184. onLoad(option) {
  185. console.log(option);
  186. this.d_id = option.d_id;
  187. this.device_id = option.device_id;
  188. },
  189. onShow() {
  190. this.end_time = +new Date() + 1000;
  191. this.start_time = this.end_time - 24 * 60 * 60 * 1000;
  192. console.log(new Date(this.end_time), new Date(this.start_time));
  193. this.historylist();
  194. },
  195. onPullDownRefresh() {
  196. console.log('refresh');
  197. this.historylist();
  198. setTimeout(function () {
  199. uni.stopPullDownRefresh();
  200. }, 1000);
  201. },
  202. };
  203. </script>
  204. <style lang="less">
  205. .timeandtype {
  206. // background-color: #F6F6FB;
  207. // padding: 20rpx;
  208. box-sizing: border-box;
  209. width: 90%;
  210. margin: 40rpx auto 0;
  211. .timebox {
  212. box-shadow: 0 0 10rpx #bcb9ca;
  213. display: flex;
  214. background-color: #fff;
  215. padding: 10px;
  216. border-top-right-radius: 5px;
  217. border-top-left-radius: 5px;
  218. .jiange {
  219. width: 5%;
  220. text-align: center;
  221. }
  222. .firsttime,
  223. .endtime {
  224. width: 45%;
  225. text-align: center;
  226. }
  227. }
  228. .warntypebox {
  229. display: flex;
  230. justify-content: space-between;
  231. background-color: #fff;
  232. padding: 10px;
  233. border-top: 1px solid #f6f6fb;
  234. border-bottom-right-radius: 5px;
  235. border-bottom-left-radius: 5px;
  236. }
  237. }
  238. .shuju_one,
  239. .shuju_two {
  240. // position: absolute;
  241. // top: 100px;
  242. // width: 90%;
  243. // left: 5%;
  244. width: 90%;
  245. margin: 40rpx auto;
  246. box-shadow: 0 0 10rpx #bcb9ca;
  247. padding-top: 20rpx;
  248. height: 550rpx;
  249. .canvastishi {
  250. font-size: 32rpx;
  251. position: absolute;
  252. top: 50%;
  253. left: 50%;
  254. margin-left: -64rpx;
  255. margin-top: -21rpx;
  256. .dataloading:after {
  257. overflow: hidden;
  258. display: inline-block;
  259. vertical-align: bottom;
  260. animation: ellipsis 2s infinite;
  261. content: '\2026';
  262. }
  263. @keyframes ellipsis {
  264. from {
  265. width: 2px;
  266. }
  267. to {
  268. width: 15px;
  269. }
  270. }
  271. }
  272. .shuju_one_title {
  273. width: 70%;
  274. margin: 0 auto;
  275. display: flex;
  276. .tltle_text {
  277. width: 25%;
  278. border: 2rpx solid #b2b2b2;
  279. color: #57c878;
  280. text-align: center;
  281. font-size: 24rpx;
  282. height: 50rpx;
  283. line-height: 50rpx;
  284. }
  285. .title_text_color {
  286. width: 25%;
  287. border: 2rpx solid #57c878;
  288. background-color: #57c878;
  289. color: #fff;
  290. text-align: center;
  291. font-size: 24rpx;
  292. height: 50rpx;
  293. line-height: 50rpx;
  294. }
  295. }
  296. }
  297. .refresh {
  298. width: 90%;
  299. // margin: 40rpx auto;
  300. margin-left: 5%;
  301. margin-top: 20rpx;
  302. width: 160rpx;
  303. height: 50rpx;
  304. background-color: #57c878;
  305. color: #ffffff;
  306. line-height: 50rpx;
  307. text-align: center;
  308. }
  309. .condition {
  310. width: 90%;
  311. margin: 40rpx auto;
  312. display: flex;
  313. flex-wrap: wrap;
  314. width: 90%;
  315. box-shadow: 0 0 10rpx #bcb9ca;
  316. margin-bottom: 30rpx;
  317. .scroll-X {
  318. width: 95%;
  319. margin: 20rpx auto;
  320. .table {
  321. width: 100%;
  322. }
  323. .tr {
  324. width: 1070rpx;
  325. display: flex;
  326. overflow: hidden;
  327. .th,
  328. .td {
  329. display: inline-block;
  330. padding: 5rpx;
  331. width: 240rpx;
  332. text-align: center;
  333. height: 52rpx;
  334. line-height: 52rpx;
  335. }
  336. .th:first-child,
  337. .td:first-child {
  338. width: 350rpx;
  339. }
  340. }
  341. .tr:nth-child(2n-1) {
  342. background-color: #f5fff8;
  343. }
  344. .tr:first-child {
  345. background-color: #57c878;
  346. color: #fff;
  347. }
  348. }
  349. .pagenumber {
  350. display: flex;
  351. margin: 20rpx auto;
  352. width: 100%;
  353. justify-content: space-around;
  354. button {
  355. width: 150rpx;
  356. height: 50rpx;
  357. line-height: 50rpx;
  358. font-size: 26rpx;
  359. text-align: center;
  360. background-color: #57c878;
  361. color: #ffffff;
  362. }
  363. .pagenumber_page {
  364. // width: 100rpx;
  365. height: 50rpx;
  366. line-height: 50rpx;
  367. font-size: 26rpx;
  368. text-align: center;
  369. }
  370. }
  371. }
  372. ::v-deep .u-calendar__action {
  373. display: flex;
  374. justify-content: space-around;
  375. .u-calendar__action__text {
  376. line-height: 25px;
  377. }
  378. }
  379. </style>