photoImage.vue 5.2 KB

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