photoImage.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="photo-image">
  3. <view
  4. class="photo-image__tabs"
  5. v-if="disableShow"
  6. >
  7. <view
  8. class="photo-image__tab"
  9. v-for="(pest, index) in pestList"
  10. :key="index"
  11. :class="{ active: activeIndexList.includes(index) }"
  12. @click="changeTab(index)"
  13. >
  14. <text class="tab-text">{{ pest.pest_name }}({{ pest.pest_num }})</text>
  15. </view>
  16. </view>
  17. <view class="photo-image__content" v-if="images.length">
  18. <view class="photo-image__grid">
  19. <view class="photo-image__item" v-for="(item, index) in images" :key="index" @click="handleClick(item)">
  20. <view class="photo-image__item-img-container">
  21. <image
  22. class="photo-image__item-img"
  23. :src="item.addr"
  24. mode="aspectFill"
  25. />
  26. </view>
  27. <view class="photo-image__item-time">
  28. {{ item.addtime }}
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view v-else>
  34. <u-empty text="暂无图片"></u-empty>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. props:{
  41. disableShow:{
  42. type: Boolean,
  43. default: true
  44. },
  45. pestList:{
  46. type: Array,
  47. default: () => []
  48. },
  49. images:{
  50. type: Array,
  51. default: () => []
  52. },
  53. deviceInfo:{
  54. type: Object,
  55. default: () => ({})
  56. },
  57. currentYear:{
  58. type: String | Number,
  59. default: ''
  60. },
  61. device_type_id:{
  62. type: String | Number,
  63. default: ''
  64. },
  65. },
  66. data() {
  67. return {
  68. activeIndexList:[],
  69. activePest:[],
  70. activeTab: 0,
  71. tabs: ['全部', '稻飞虱', '水龟虫', '蝼蛄', '系统','全部', '稻飞虱', '水龟虫', '蝼蛄', '系统'],
  72. };
  73. },
  74. methods: {
  75. changeTab(index) {
  76. if(this.activeIndexList.includes(index)){
  77. this.activePest = this.activePest.filter(item => item !== this.pestList[index])
  78. this.activeIndexList = this.activeIndexList.filter(item => item !== index)
  79. }else{
  80. this.activeIndexList.push(index)
  81. this.activePest.push(this.pestList[index])
  82. }
  83. this.$emit('changeTab', this.activePest)
  84. },
  85. // 格式化时间
  86. formatDate(dateString) {
  87. const date = new Date(dateString*1000);
  88. const year = date.getFullYear();
  89. const month = String(date.getMonth() + 1).padStart(2, '0');
  90. const day = String(date.getDate()).padStart(2, '0');
  91. const hour = String(date.getHours()).padStart(2, '0');
  92. const minute = String(date.getMinutes()).padStart(2, '0');
  93. const second = String(date.getSeconds()).padStart(2, '0');
  94. return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  95. },
  96. handleClick(item) {
  97. uni.navigateTo({
  98. url: '/pages/sy/devicePhoto?device_id=' + item?.device_id + '&addtime=' + item?.addtime + '&img_id=' + item?.ids + '&id=' + this.deviceInfo.id + '&currentYear=' + this.currentYear+'&device_type_id='+this.device_type_id+'&cmd=sy1'
  99. })
  100. }
  101. },
  102. };
  103. </script>
  104. <style lang="scss" scoped>
  105. .photo-image {
  106. width: 100%;
  107. box-sizing: border-box;
  108. &__header {
  109. margin-bottom: 32rpx;
  110. white-space: nowrap;
  111. &::-webkit-scrollbar {
  112. display: none;
  113. }
  114. }
  115. &__tabs {
  116. box-sizing: border-box;
  117. width: 100%;
  118. overflow-x: auto;
  119. overflow-y: hidden;
  120. white-space: nowrap;
  121. // 去掉滚动条
  122. -ms-overflow-style: none;
  123. scrollbar-width: none;
  124. }
  125. .photo-image__content{
  126. padding: 30rpx;
  127. background: #ffffff;
  128. border-radius: 16rpx;
  129. margin-top: 30rpx;
  130. .photo-image__grid{
  131. display: grid;
  132. grid-template-columns: repeat(3, 1fr);
  133. gap: 20rpx;
  134. }
  135. }
  136. &__tab {
  137. position: relative;
  138. display: inline-block;
  139. box-sizing: border-box;
  140. margin-right: 16rpx;
  141. background: #ffffff;
  142. color: #999999;
  143. font-family: "Source Han Sans CN VF";
  144. font-size: 28rpx;
  145. padding: 10rpx 32rpx;
  146. border-radius: 8rpx;
  147. &:last-child {
  148. margin-right: 0;
  149. }
  150. .tab-text {
  151. margin-right: 8rpx;
  152. }
  153. .tab-check {
  154. color: #4CAF50;
  155. font-weight: bold;
  156. }
  157. &.active {
  158. color: #0BBC58;
  159. }
  160. .tab-underline {
  161. position: absolute;
  162. bottom: 0;
  163. left: 0;
  164. right: 0;
  165. height: 4rpx;
  166. background: #4CAF50;
  167. border-radius: 2rpx;
  168. }
  169. }
  170. &__item {
  171. position: relative;
  172. width: 100%;
  173. padding: 0rpx;
  174. box-sizing: border-box;
  175. display: inline-block;
  176. overflow: hidden;
  177. border:2rpx solid #e4e7ed;
  178. border-radius: 16rpx;
  179. &-img-container {
  180. width: 100%;
  181. padding-bottom: 100%;
  182. position: relative;
  183. border-radius: 16rpx;
  184. overflow: hidden;
  185. background-color: #f5f5f5;
  186. }
  187. &-img {
  188. position: absolute;
  189. top: 0;
  190. left: 0;
  191. width: 100%;
  192. height: 100%;
  193. }
  194. &-time {
  195. position: absolute;
  196. bottom: 0rpx;
  197. width: 100%;
  198. text-align: center;
  199. padding: 0;
  200. overflow: hidden;
  201. text-overflow: ellipsis;
  202. white-space: nowrap;
  203. margin-top: 12rpx;
  204. font-size: 22rpx;
  205. color: #fff;
  206. text-align: center;
  207. background-color: rgba(0, 0, 0, 0.5);
  208. }
  209. }
  210. }
  211. </style>