photoImage.vue 4.9 KB

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