<template>
	<view>
		<view class="row image-box">
			<view class="image-item m-r20 m-t20" mode="aspectFill" v-for="(item,index) in imgList">
				<image class="image r-10 " :src="item.type === 1?item.url:getVideoImg(item.url)" :style="[{width},{height}]" @click.stop="onPreviewImage(item)">
				</image>
				<image class="wh-45 video-icon" src="/static/img/task/play.png" mode="aspectFill"  @click.stop="showVideoImg(item.url)" v-if="item.type === 2">
				</image>
			</view>
		</view>
    <uni-popup ref="videoPopup" @change="closeVideoImg">
      <view class="video-box" v-if="videoUrl">
        <video class="myVideo" :src="videoUrl" :autoplay="true"></video>
      </view>
    </uni-popup>
	</view>
</template>

<script>
	import tools from "@/service/tools";

  export default {
		props: {
			is_both: {
				type: Boolean,
				default: false
			},
			width: {
				type: String,
				default: '130rpx'
			},
			height: {
				type: String,
				default: '130rpx'
			},
      imgList: {
				default: []
			},
			previewImage: {
				default: []
			}
		},
		data() {
			return {
        videoUrl:''
      }
		},
		mounted() {},
		methods: {
      onPreviewImage(item) {
        if(item.type===1){
          this.$emit('onShowImg',item.url)
        }else {
          this.showVideoImg(item.url)
        }


      },
      closeVideoImg(e) {
        if (!e.show) {
          console.log('关闭视频了')
          this.videoUrl = ''
        }
      },
      showVideoImg(url) {
        console.log(url)
        this.videoUrl = url
        this.$refs.videoPopup.open('center')
      },
      getVideoImg(url) {
        return tools.getOssVideo(url)
      },
		}
	}
</script>

<style lang="scss" scoped>
.video-box {
  height: 70vh;
  width: 100vw;

  .myVideo {
    height: 70vh;
    width: 100vw;
  }
}
	.image-box {
		flex-wrap: wrap;
	}

	.image-item {
		position: relative;

		.image {
			display: block;
		}

		.video-icon {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
		}
	}
  .video-box {
    height: 70vh;
    width: 100vw;

    .myVideo {
      height: 70vh;
      width: 100vw;
    }
  }
</style>