photoImage.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. {{ formatDate(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. },
  62. data() {
  63. return {
  64. activeIndexList:[],
  65. activePest:[],
  66. activeTab: 0,
  67. tabs: ['全部', '稻飞虱', '水龟虫', '蝼蛄', '系统','全部', '稻飞虱', '水龟虫', '蝼蛄', '系统'],
  68. };
  69. },
  70. methods: {
  71. changeTab(index) {
  72. if(this.activeIndexList.includes(index)){
  73. this.activePest = this.activePest.filter(item => item !== this.pestList[index])
  74. this.activeIndexList = this.activeIndexList.filter(item => item !== index)
  75. }else{
  76. this.activeIndexList.push(index)
  77. this.activePest.push(this.pestList[index])
  78. }
  79. this.$emit('changeTab', this.activePest)
  80. },
  81. // 格式化时间
  82. formatDate(dateString) {
  83. const date = new Date(dateString*1000);
  84. const year = date.getFullYear();
  85. const month = String(date.getMonth() + 1).padStart(2, '0');
  86. const day = String(date.getDate()).padStart(2, '0');
  87. const hour = String(date.getHours()).padStart(2, '0');
  88. const minute = String(date.getMinutes()).padStart(2, '0');
  89. const second = String(date.getSeconds()).padStart(2, '0');
  90. return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  91. },
  92. handleClick(item) {
  93. uni.navigateTo({
  94. url: '/pages/bzy/devicePhoto?device_id=' + item?.device_id + '&addtime=' + item?.addtime + '&img_id=' + item?.id + '&id=' + this.deviceInfo.id + '&currentYear=' + this.currentYear
  95. })
  96. }
  97. },
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. .photo-image {
  102. width: 100%;
  103. box-sizing: border-box;
  104. &__header {
  105. margin-bottom: 32rpx;
  106. white-space: nowrap;
  107. &::-webkit-scrollbar {
  108. display: none;
  109. }
  110. }
  111. &__tabs {
  112. box-sizing: border-box;
  113. width: 100%;
  114. overflow-x: auto;
  115. overflow-y: hidden;
  116. white-space: nowrap;
  117. // 去掉滚动条
  118. -ms-overflow-style: none;
  119. scrollbar-width: none;
  120. }
  121. .photo-image__content{
  122. padding: 30rpx;
  123. background: #ffffff;
  124. border-radius: 16rpx;
  125. .photo-image__grid{
  126. display: grid;
  127. grid-template-columns: repeat(3, 1fr);
  128. gap: 20rpx;
  129. }
  130. }
  131. &__tab {
  132. position: relative;
  133. display: inline-block;
  134. box-sizing: border-box;
  135. margin-right: 16rpx;
  136. background: #ffffff;
  137. color: #999999;
  138. font-family: "Source Han Sans CN VF";
  139. font-size: 28rpx;
  140. padding: 10rpx 32rpx;
  141. border-radius: 8rpx;
  142. &:last-child {
  143. margin-right: 0;
  144. }
  145. .tab-text {
  146. margin-right: 8rpx;
  147. }
  148. .tab-check {
  149. color: #4CAF50;
  150. font-weight: bold;
  151. }
  152. &.active {
  153. color: #0bbc58;
  154. }
  155. .tab-underline {
  156. position: absolute;
  157. bottom: 0;
  158. left: 0;
  159. right: 0;
  160. height: 4rpx;
  161. background: #4CAF50;
  162. border-radius: 2rpx;
  163. }
  164. }
  165. &__item {
  166. position: relative;
  167. width: 100%;
  168. padding: 0rpx;
  169. box-sizing: border-box;
  170. display: inline-block;
  171. overflow: hidden;
  172. border:2rpx solid #e4e7ed;
  173. border-radius: 16rpx;
  174. &-img-container {
  175. width: 100%;
  176. padding-bottom: 100%;
  177. position: relative;
  178. border-radius: 16rpx;
  179. overflow: hidden;
  180. background-color: #f5f5f5;
  181. }
  182. &-img {
  183. position: absolute;
  184. top: 0;
  185. left: 0;
  186. width: 100%;
  187. height: 100%;
  188. }
  189. &-time {
  190. position: absolute;
  191. bottom: 0rpx;
  192. width: 100%;
  193. text-align: center;
  194. padding: 0;
  195. overflow: hidden;
  196. text-overflow: ellipsis;
  197. white-space: nowrap;
  198. margin-top: 12rpx;
  199. font-size: 22rpx;
  200. color: #fff;
  201. text-align: center;
  202. background-color: rgba(0, 0, 0, 0.5);
  203. }
  204. }
  205. }
  206. </style>