photoImage.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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">
  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>
  31. </template>
  32. <script>
  33. export default {
  34. props:{
  35. pestList:{
  36. type: Array,
  37. default: () => []
  38. },
  39. images:{
  40. type: Array,
  41. default: () => []
  42. },
  43. },
  44. data() {
  45. return {
  46. activeIndexList:[],
  47. activePest:[],
  48. activeTab: 0,
  49. tabs: ['全部', '稻飞虱', '水龟虫', '蝼蛄', '系统','全部', '稻飞虱', '水龟虫', '蝼蛄', '系统'],
  50. };
  51. },
  52. methods: {
  53. changeTab(index) {
  54. if(this.activeIndexList.includes(index)){
  55. this.activePest = this.activePest.filter(item => item !== this.pestList[index])
  56. this.activeIndexList = this.activeIndexList.filter(item => item !== index)
  57. }else{
  58. this.activeIndexList.push(index)
  59. this.activePest.push(this.pestList[index])
  60. }
  61. this.$emit('changeTab', this.activePest)
  62. },
  63. // 格式化时间
  64. formatDate(dateString) {
  65. const date = new Date(dateString*1000);
  66. const year = date.getFullYear();
  67. const month = String(date.getMonth() + 1).padStart(2, '0');
  68. const day = String(date.getDate()).padStart(2, '0');
  69. const hour = String(date.getHours()).padStart(2, '0');
  70. const minute = String(date.getMinutes()).padStart(2, '0');
  71. const second = String(date.getSeconds()).padStart(2, '0');
  72. return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  73. },
  74. handleClick(item) {
  75. uni.navigateTo({
  76. url: '/pages/cbd/devicePhoto?devicePhoto=' + item
  77. })
  78. }
  79. },
  80. };
  81. </script>
  82. <style lang="scss" scoped>
  83. .photo-image {
  84. width: 100%;
  85. box-sizing: border-box;
  86. &__header {
  87. margin-bottom: 32rpx;
  88. white-space: nowrap;
  89. &::-webkit-scrollbar {
  90. display: none;
  91. }
  92. }
  93. &__tabs {
  94. box-sizing: border-box;
  95. width: 100%;
  96. overflow-x: auto;
  97. overflow-y: hidden;
  98. white-space: nowrap;
  99. // 去掉滚动条
  100. -ms-overflow-style: none;
  101. scrollbar-width: none;
  102. }
  103. .photo-image__content{
  104. padding: 30rpx;
  105. background: #ffffff;
  106. border-radius: 16rpx;
  107. margin-top: 30rpx;
  108. }
  109. &__tab {
  110. position: relative;
  111. display: inline-block;
  112. box-sizing: border-box;
  113. margin-right: 16rpx;
  114. background: #ffffff;
  115. color: #999999;
  116. font-family: "Source Han Sans CN VF";
  117. font-size: 28rpx;
  118. padding: 10rpx 32rpx;
  119. border-radius: 8rpx;
  120. &:last-child {
  121. margin-right: 0;
  122. }
  123. .tab-text {
  124. margin-right: 8rpx;
  125. }
  126. .tab-check {
  127. color: #4CAF50;
  128. font-weight: bold;
  129. }
  130. &.active {
  131. color: #0BBC58;
  132. }
  133. .tab-underline {
  134. position: absolute;
  135. bottom: 0;
  136. left: 0;
  137. right: 0;
  138. height: 4rpx;
  139. background: #4CAF50;
  140. border-radius: 2rpx;
  141. }
  142. }
  143. &__item {
  144. position: relative;
  145. width: 33.33%;
  146. padding: 0 10rpx;
  147. box-sizing: border-box;
  148. display: inline-block;
  149. margin-bottom: 24rpx;
  150. &-img-container {
  151. width: 100%;
  152. padding-bottom: 100%;
  153. position: relative;
  154. border-radius: 8rpx;
  155. overflow: hidden;
  156. background-color: #f5f5f5;
  157. border: 2rpx solid #333;
  158. }
  159. &-img {
  160. position: absolute;
  161. top: 0;
  162. left: 0;
  163. width: 100%;
  164. height: 100%;
  165. }
  166. &-time {
  167. position: absolute;
  168. bottom: 10rpx;
  169. margin-top: 12rpx;
  170. font-size: 22rpx;
  171. color: #fff;
  172. text-align: center;
  173. background-color: rgba(0, 0, 0, 0.5);
  174. }
  175. }
  176. }
  177. </style>