<template>
	<view class="content">
		<view class="nav">
			<view class="uni-page-head-btnBox">
				<view class="uni-page-head-btn" @click="goback"><i class="uni-btn-icon" ></i></view>
			</view>
			
			<view class="Navtitle">选择素材</view>
			<view class="uni-page-head-btnBox"></view>
		</view>
		<view class="zhidingyiBox">
			<view class="zhidingyi" @click="upimg">
				<view class="zdyLeft">
					<view class="zdyTitle">自定义图片</view>
					<view class="zdyms">建议尺寸：宽度750*390px</view>
					<view class="zdyms" style="padding-top: 24rpx;">请先上传自定义活动图片 后编辑活动内容</view>
				</view>
				<view class="zdyRight">
					<image src="../../static/img/bg_sucai@2x.png" mode="" class="zdyRightImg"></image>
				</view>
			</view>
		</view>
		<view class="listBox">
			<view class="listLine" v-for="(item,i) in list">
				<view class="listTitle">{{item.Name}}</view>
				<view class="listSm">{{item.collectingComment}}</view>
				<scroll-view scroll-x="true" class="scroll-X" >
					<view class="listLineImgBox" >
						<view class="" v-for="(img,index) in item.imgList" @click="goAdd(img)">
							<image  class="listLineImg" :src="img.Img" mode=""></image>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<w-compress ref='wCompress' />
	</view>
</template>

<script>
	import WCompress from '@/components/w-compress/w-compress.vue'
	//https://ext.dcloud.net.cn/plugin?id=1718
	export default {
		 components: {
		        WCompress
		},
		data() {
			return {
				list:'',
				imgurl:'',
				type:'',
			}
		},
		onLoad(opt) {
          this.getSetTheGuestList();
		  this.type=opt.type;
		  //?token=1BAD122A96BA41E49200322381DC5D34&uid=DC0B84EA-A67B-4A4B-8EAE-F55A13CF8217
		},
		// onBackPress(e){
		// 	console.log(e)
		// 	console.log("返回")
		// 	return true; 
		// },
		
		methods: {
		   goback(){
			   if(this.type==2){
				   uni.navigateBack()
			   }else{
				   var standalone = window.navigator.standalone
				   var userAgent = window.navigator.userAgent.toLowerCase()
				   var safari = /safari/.test(userAgent)
				   var ios = /iphone|ipod|ipad|mac/.test(userAgent)
				   var android = /android/.test(userAgent)
				   if (ios) {
				     if ( true) {//!standalone&& !safari
				       window.webkit.messageHandlers.goMyNav.postMessage(null)
				     }
				   } else if (android) {
				     window.android.postMessage()
				   }
			   }
			   
			   
		   },
		   goAdd(item){
			   uni.removeStorageSync('ckmusic');
				uni.navigateTo({
					url:'addActivity?img='+item.Img
				})
		   },
		   goAddzdy(img){
			   uni.navigateTo({
			   	url:'addActivity?img='+img
			   })
		   },
           getSetTheGuestList(){
			   uni.showLoading({
			   	title: '加载中'
			   })
			   this.$http('openH5SetTheGuest/getSetTheGuestList', {
			     
			    },'GET').then(res => {
			   		uni.hideLoading();
			   		this.list=res.data
			    })
		   },
		   upimg(){
			   var that = this;
			    uni.chooseImage({
			    	sourceType: ['album','camera'],
			    	count:1, 
				 sizeType:['compressed'],
			   	success: (chooseImageRes) => {
			   		const tempFilePaths = chooseImageRes.tempFilePaths;
					console.log(tempFilePaths[0])
					//that.getImageInfo(tempFilePaths[0])
			   		 that.file=tempFilePaths[0];
					 that.$refs.wCompress.start(that.file, {
					             pixels: 600000,  // 最大分辨率，默认二百万
					             quality: 0.9,     // 压缩质量，默认0.8
					             type: 'png',      // 图片类型，默认jpg
					             base64: true,     // 是否返回base64，默认false，非H5有效
					           }).then(resxx => {
					                 uni.uploadFile({
					                        url: that.$request.baseUrl+'accompany/SuperCheckSheet/uploadFile', //仅为示例，非真实的接口地址
					                        filePath: resxx,
					                        name: 'file',
					                        formData: {
					                            'user': 'test'
					                        },
					                        success: (uploadFileRes) => {
					                            console.log(JSON.parse(uploadFileRes.data).data );
													//that.imgArr=that.imgArr.concat(JSON.parse(uploadFileRes.data).data) ;
													that.imgurl=JSON.parse(uploadFileRes.data).data[0];
													that.goAddzdy(that.imgurl)
					                        }
					                    });           
					                           
					            }).catch(e => {
					                           
					            })
					      //  }
			   		 /* uni.uploadFile({
			   	            url: that.$request.baseUrl+'accompany/SuperCheckSheet/uploadFile', //仅为示例，非真实的接口地址
			   	            filePath: tempFilePaths[0],
			   	            name: 'file',
			   	            formData: {
			   	                'user': 'test'
			   	            },
			   	            success: (uploadFileRes) => {
			   	                console.log(JSON.parse(uploadFileRes.data).data );
			   					//that.imgArr=that.imgArr.concat(JSON.parse(uploadFileRes.data).data) ;
			   					that.imgurl=JSON.parse(uploadFileRes.data).data[0];
								that.goAddzdy(that.imgurl)
			   	            }
			   	        }); 
			   */
			   		
			   	}
			   });
			 
		   },
		   getImageInfo(src){
			    let _this = this
			                   uni.getImageInfo({
			                       src,
			                       success(res) {
			                           let canvasWidth = res.width //图片原始长宽
			                           let canvasHeight = res.height
			                           let ratio = canvasWidth / canvasHeight;
			                           if (canvasWidth > 500) {
			                               canvasWidth = 500;
			                               canvasHeight = Math.floor(canvasWidth / ratio);
			                           }
			               
			                           let img = new Image()
			                           img.src = res.path
									 
			                           let canvas = document.createElement('canvas');
			                           let ctx = canvas.getContext('2d')
			                           canvas.width = canvasWidth
			                           canvas.height = canvasHeight
			                           ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight)
			                           canvas.toBlob(function(fileSrc) {
										   
			                               let imgSrc = window.URL.createObjectURL(fileSrc)
			                               _this.upimgfwq(imgSrc)
			                           })
			                       }
			                   })
		   },
		   upimgfwq(imgSrc){
			   console.log(imgSrc)
			   //let file = new File([imgSrc], '122.png')
			  //  var renameFile =new File([imgSrc], this.time(new Date()) + '.png' );
			   
			  //   var formdata = new FormData();
			  //   formdata.append('file', renameFile);
			  // console.log(formdata)
			   var that=this;
			   uni.uploadFile({
			          url: that.$request.baseUrl+'accompany/SuperCheckSheet/uploadFile', //仅为示例，非真实的接口地址
			          filePath:  imgSrc,
			          name: 'file',
			          formData: {
			              'user': 'test'
			          },
			          success: (uploadFileRes) => {
			              console.log(JSON.parse(uploadFileRes.data).data );
							//that.imgArr=that.imgArr.concat(JSON.parse(uploadFileRes.data).data) ;
							that.imgurl=JSON.parse(uploadFileRes.data).data[0];
							that.goAddzdy(that.imgurl)
			          }
			      });
		   },
		   time(time) {
		             let month = time.getMonth() + 1;  // 月
		             let date = time.getDate();  // 日
		             let hh = time.getHours();  // 时
		             let mm = time.getMinutes();  // 分
		             let ss = time.getSeconds();  // 秒
		             if (hh >=0 && hh<10){hh= '0' + hh;}
		             if (mm >=0 && mm<10){mm= '0' + mm;}
		             if (ss >=0 && ss<10){ss= '0' + ss;}
		             if (month < 10){month= '0' + month;}
		             if (date < 10){date= '0' + date;}
		             return time.getFullYear().toString() + month.toString() + date.toString() + hh.toString() + mm.toString() + ss.toString();
	       },
		  
		}
	}
</script>

<style scoped>
	.nav{
		height: 44px;
		background: #ffffff;
		display: flex;
		justify-content: space-between;
		line-height: 44px;
		font-size: 16px;
		font-weight: 700;
		position: fixed;
		width: 750rpx;
		left: 0;
		top: 0;
		z-index: 11;
	}
	.uni-page-head-btnBox{
		width: 40px;
		padding-top: 5px;
	}
	.uni-btn-icon{
		color: #000000;
		font-size: 27px;
	}
	.content{
		min-height: 100vh;
		background:#F4F5F7 ;
	}
	.zhidingyiBox{
		padding: 20rpx 24rpx;
		margin-top: 44px;
	}
	.zhidingyi{
		background: #ffffff;
		border-radius: 10rpx;
		display: flex;
		justify-content: space-between;
	}
	.zdyRightImg{
		width: 217rpx;
		height: 210rpx;
	}
	.zdyLeft{
		padding-top: 50rpx;
		padding-left: 20rpx;
		width: 300rpx;
	}
 .zdyTitle{
	 color: #333333;
	 line-height: 42rpx;
	 font-size: 30rpx;
	 font-weight: 500;
	 padding-bottom: 16rpx;
 }
.zdyms{
	font-weight: 400;
	color: #999999;
	line-height: 33rpx;
	font-size: 24rpx;
}
.zdyRight{
	padding: 35rpx 30rpx;
}
.listBox{
	background: #ffffff;
}
.listLine{
	padding-left: 24rpx;
	padding-top: 30rpx;
}
.listLineImg{
	width: 630rpx;
	height: 252rpx;
	margin-right: 30rpx;
	border-radius: 10rpx;
}
.listLineImgBox{
	display: flex;
}
.listTitle{
	font-weight: 500;
	color: #333333;
	font-size: 30rpx;
}
.listSm{
	font-weight: 400;
	color: #999999;
	line-height: 33px;
	font-size: 24rpx;
	width: 702rpx;
	height: 33rpx;
}
</style>
