history.vue 8.4 KB

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