photoImage.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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/cbd/devicePhoto?device_id=' + item?.device_id + '&addtime=' + item?.addtime + '&img_id=' + item?.ids + '&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. margin-top: 30rpx;
  126. .photo-image__grid{
  127. display: grid;
  128. grid-template-columns: repeat(3, 1fr);
  129. gap: 20rpx;
  130. }
  131. }
  132. &__tab {
  133. position: relative;
  134. display: inline-block;
  135. box-sizing: border-box;
  136. margin-right: 16rpx;
  137. background: #ffffff;
  138. color: #999999;
  139. font-family: "Source Han Sans CN VF";
  140. font-size: 28rpx;
  141. padding: 10rpx 32rpx;
  142. border-radius: 8rpx;
  143. &:last-child {
  144. margin-right: 0;
  145. }
  146. .tab-text {
  147. margin-right: 8rpx;
  148. }
  149. .tab-check {
  150. color: #4CAF50;
  151. font-weight: bold;
  152. }
  153. &.active {
  154. color: #0BBC58;
  155. }
  156. .tab-underline {
  157. position: absolute;
  158. bottom: 0;
  159. left: 0;
  160. right: 0;
  161. height: 4rpx;
  162. background: #4CAF50;
  163. border-radius: 2rpx;
  164. }
  165. }
  166. &__item {
  167. position: relative;
  168. width: 100%;
  169. padding: 0rpx;
  170. box-sizing: border-box;
  171. display: inline-block;
  172. overflow: hidden;
  173. border:2rpx solid #000;
  174. border-radius: 16rpx;
  175. &-img-container {
  176. width: 100%;
  177. padding-bottom: 100%;
  178. position: relative;
  179. border-radius: 16rpx;
  180. overflow: hidden;
  181. background-color: #f5f5f5;
  182. }
  183. &-img {
  184. position: absolute;
  185. top: 0;
  186. left: 0;
  187. width: 100%;
  188. height: 100%;
  189. }
  190. &-time {
  191. position: absolute;
  192. bottom: 0rpx;
  193. width: 100%;
  194. text-align: center;
  195. padding: 0;
  196. border-radius: 16rpx;
  197. overflow: hidden;
  198. text-overflow: ellipsis;
  199. white-space: nowrap;
  200. margin-top: 12rpx;
  201. font-size: 22rpx;
  202. color: #fff;
  203. text-align: center;
  204. background-color: rgba(0, 0, 0, 0.5);
  205. }
  206. }
  207. }
  208. </style>