photoImage.vue 4.5 KB

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