history.vue 8.2 KB

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