image.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <!-- 虫情监测查看图片 -->
  3. <view class="ui-card px-13">
  4. <!-- 选择时间 -->
  5. <uni-datetime-picker v-model="searchTime" type="daterange" rangeSeparator="-" @change="changeSearchTime" />
  6. <!-- 选择时间end -->
  7. <!-- 图片列表 -->
  8. <view class="row wrap">
  9. <block v-for="(item,index) in imageList" :key="index">
  10. <view class="worm-img" @click="previewImage(index)">
  11. <image class="pic" mode="aspectFill" :src="item.indentify_photo"></image>
  12. <view class="time">{{item.addtime | timeFrom}}</view>
  13. </view>
  14. </block>
  15. </view>
  16. <!-- 图片列表end -->
  17. <ui-empty v-if="imageList.length==0"></ui-empty>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. getWormImageList
  23. } from '@/api/worm.js'
  24. import {
  25. timeFrame,
  26. dateToUnix
  27. } from '@/utils/utils.js'
  28. // 虫情监测查看图片逻辑
  29. export default {
  30. data() {
  31. return {
  32. // 搜索条件
  33. params: {
  34. time_begin: timeFrame('start'), // 开始时间
  35. time_end: timeFrame('end'), // 结束时间
  36. device_id: '', //设备号
  37. page: 1,
  38. page_number: 20,
  39. },
  40. searchTime: ['', ''],
  41. imageList: [], // 图片列表
  42. }
  43. },
  44. onLoad(options) {
  45. this.params.device_id = options.id;
  46. this.getImageList();
  47. },
  48. // 触底请求
  49. onReachBottom(e) {
  50. if (this.imageList.length >= this.total) {
  51. return;
  52. }
  53. this.params.page += 1;
  54. this.getImageList();
  55. },
  56. methods: {
  57. // 加载图片列表
  58. async getImageList() {
  59. const {
  60. data,
  61. num
  62. } = await getWormImageList(this.params);
  63. this.imageList = [...this.imageList, ...data];
  64. this.total = num ?? 0;
  65. },
  66. // 选择时间
  67. changeSearchTime(time) {
  68. this.params.time_begin = time[0] ? dateToUnix(time[0]) : timeFrame('start');
  69. this.params.time_end = time[0] ? dateToUnix(time[1]) : timeFrame('end');
  70. this.searchTime = time;
  71. this.params.page = 1;
  72. this.imageList=[];
  73. this.getImageList();
  74. },
  75. // 预览图片
  76. previewImage(index) {
  77. let imgList = this.imageList.map(item => item.indentify_photo);
  78. uni.previewImage({
  79. current: index,
  80. urls: imgList
  81. });
  82. },
  83. }
  84. }
  85. </script>
  86. <style lang="scss">
  87. .worm-img {
  88. width: 313rpx;
  89. height: 280rpx;
  90. margin-top: 24rpx;
  91. margin-right: 24rpx;
  92. &:nth-child(2n) {
  93. margin-right: 0;
  94. }
  95. .pic {
  96. display: block;
  97. width: 314rpx;
  98. height: 236rpx;
  99. background-color: #f3f5f9;
  100. border-radius: 4rpx;
  101. }
  102. .time {
  103. height: 28rpx;
  104. margin-top: 18rpx;
  105. font-size: 20rpx;
  106. font-weight: normal;
  107. color: #999999;
  108. line-height: 28rpx;
  109. }
  110. }
  111. </style>