history.vue 9.3 KB

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