<template>
	<view class="container qualifications" :style="{paddingBottom :isIphoneX ? (218+68)+'rpx' : '218rpx'}">
		<view class="qualifications-content">
			<view class="list" v-for="(item,index) in qualificationsList" :key="index">
				<view class="list-view-title">
					<view class="title-left">商品{{ index+1 }}</view>
					<view class="title-right" v-if="(index+1) > 1" @click="deleteLogistItemFn(item,index)">
						删除商品
					</view>
				</view>
				<view class="list-view">
					<view class="list-view-label">商品</view>
					<view class="list-view-text">
						<picker @change="bindPickerChange(item,$event)" :value="index" :range="productActions" range-key="name">
							<input class="input" type="text" v-model="item.name" placeholder="请选择商品" disabled="true">
							<text class="iconfont icon-xiayibu"></text>
						</picker>
					</view>
				</view>
				<view class="list-view">
					<view class="list-view-label">SN码</view>
					<view class="list-view-text">
						<input class="input" type="text" v-model="item.code" placeholder="请输入商品SN码">
					</view>
				</view>
				<view class="list-view" v-for="(file,fileIndex) in item.fileList" :key="fileIndex">
					<view class="list-view-label">资质文件</view>
					<view class="list-view-text">
						<view class="input">{{ file.fileName }}</view>
						<text class="iconfont icon-iconfontguanbi" @click.stop="deleteFileFn(item.fileList,index)"></text>
					</view>
				</view>	
				<view class="list-view" >
					<view class="list-view-label">资质文件</view>
					<view class="list-view-text">
						<view class="list-view-file" @click="uploadFile(item.fileList)">上传</view>
					</view>
				</view>	
				<view class="list-view-title none">图片<text class="none">(若不方便上传文件，可用图片代替)</text></view>
				<view class="list-view-upload clearfix">
					<view class="photo-item" v-for="(image, index) in item.imageList" :key="index">
						<image :src="image" mode="aspectFill" @click.stop="previewImg(item.imageList,index)"></image>
						<text class="iconfont icon-iconfontguanbi" @click.stop="deletePhotoFn(item.imageList,index)"></text>
					</view>
					<view class="photo-item add" @click.stop="uploadPhotoFn(item.imageList)" v-if="item.imageList.length<10 || item.imageList.length == 0">
						<text class="iconfont icon-jiahao"></text>
					</view>
				</view>
			</view>
			<view class="list-btn" v-if="qualificationsList.length < productActions.length">
				<view class="btn add-btn" @click="addListFn">
					<text class="iconfont icon-jiahao"></text>
					<text>添加商品</text>
				</view>
			</view>
		</view>
		<view class="qualifications-btn" :style="{paddingBottom :isIphoneX ? '68rpx' : '0'}">
			<view class="edit-button-canel">暂不填写</view>
			<view class="edit-button">确定</view>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	import authorize from '@/common/config/authorize.js' 
	import { uploadFileImage , uploadFilePdf } from "@/services/public.js"
	
	var isPreviewImg;
	export default{
		data() {
			return{
				isIphoneX:this.$store.state.isIphoneX,
				productActions:[
					{
						id:1,
						name:'asdasdasM22'
					},
					{
						id:2,
						name:'奥术大师大所打M22'
					},
					{
						id:3,
						name:'美国第六代光子多功能智能平台M22'
					},
				],
				qualificationsList:[
					{
						name:'美国第六代光子多功能智能平台M22',
						code:'SN2562659874565',
						fileList:[
							{
								fileName:'深圳市和创元文件.pdf',
								ossName:'深圳市和创元文件.pdf'
							}
						],
						imageList:[
							'https://dss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2306696130,3636777462&fm=26&gp=0.jpg'
						]
					}
				]
			}
		},
		onLoad(option) {
			
		},
		methods:{
			...mapMutations(['login']),
			initGetLogisticsInfo(){
				this.ShopService.GetLogisticsInfo({ logisticsBatchId : this.logisticsBatchId, shopOrderId:this.info.shopOrderId }).then(response =>{
					const data = response.data.logisticsBatch
					if(data.remarkImages!=null){
						this.photoLists = data.remarkImages
					}else{
						this.photoLists =[]
					}
					this.info.note = data.remark
				}).catch(error =>{
					this.$util.msg(error.msg,2000);
				})
			},
			bindPickerChange: function(item,e) {//选择筛选条件
				item.name = this.productActions[e.target.value].name
			},
			addListFn(){//添加
				let obj ={
					name:'',
					code:'',
					fileList:[],
					imageList:[],
				};
				this.qualificationsList.push(obj)
			},
			deleteLogistItemFn(item,index){
				this.$util.modal('提示','确认删除物流信息吗？','确定','取消',true,() =>{
					this.qualificationsList.splice(index, 1);
				})
			},
			uploadFile(array){//上传资质文件
				console.log(array)
				uploadFilePdf().then(res =>{
					let data =  JSON.parse(res.data).data
					let obj = {
							fileName:uni.getStorageSync('fileName'),
							ossName:data.ossName
						}
					array.push(obj)
					console.log('array',array)
				})
			},
			uploadPhotoFn(array){//添加图片
				uploadFileImage().then(res =>{
					array.push(JSON.parse(res.data).data)
				})
			},
			deleteFileFn(array,index){//删除文件
				this.UploadService.PostFileDelete(
					{
						ossName:array[index].ossName,
					}
				)
				.then(res=>{
					array.splice(index, 1);
				})
				.catch(error =>{
					console.log('删除文件异常提示===>',error.msg)
				})
				
			},
			deletePhotoFn(array,index){//删除图片
				array.splice(index, 1);
			},
			previewImg (image,index) {//顶部商品图片预览
				isPreviewImg = true
				let previewUrls = image
				uni.previewImage({
					current: index, 	//图片索引
					urls: previewUrls, //必须是http图片，本地图片无效
					longPressActions:''
				})
			},
		},
		onShow() {
			
		}
	}
</script>

<style lang="scss">
	page {
		height: auto;
		background:#F7F7F7;
	}
	.qualifications-content{
		width: 100%;
		height: auto;
		.list{
			width: 100%;
			height: auto;
			background-color: #FFFFFF;
			box-sizing: border-box;
			margin-bottom: 20rpx;
			padding: 0 24rpx;
			.list-view-title{
				width: 100%;
				height: 92rpx;
				border-bottom: 1px solid #E1E1E1;
				line-height: 92rpx;
				font-size: $font-size-30;
				color: #333333;
				text-align: left;
				.title-left{
					float: left;
				}
				.title-right{
					float: right;
					color: $color-system;
					font-size: $font-size-24;
				}
				&.none{
					border-bottom: none;
				}
				.none{
					color: #666666;
				}
			}
			.list-view{
				width: 100%;
				height: 92rpx;
				border-bottom: 1px solid #E1E1E1;
				line-height: 92rpx;
				font-size: $font-size-30;
				.list-view-label{
					width: 192rpx;
					color: #666666;
					float: left;
				}
				.list-view-text{
					width: 510rpx;
					float: right;
					position: relative;
					.input{
						width: 510rpx;
						height: 92rpx;
						box-sizing: border-box;
						line-height: 92rpx;
						color: #333333;
						text-overflow: ellipsis;
						overflow: hidden;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						line-clamp: 1;
						-webkit-box-orient: vertical;
						padding-right: 40rpx;
					}
					.icon-xiayibu{
						width: 40rpx;
						height: 80rpx;
						display: block;
						position: absolute;
						right: 0;
						top: 0;
						font-size: $font-size-32;
						color: #B2B2B2;
						text-align: center;
					}
					.icon-iconfontguanbi{
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
						background-color: #f94b4b;
						display: block;
						position: absolute;
						right: 0;
						top: 28rpx;
						font-size: $font-size-24;
						color: #FFFFFF;
						line-height: 40rpx;
						text-align: center;
					}
					.list-view-file{
						width: 88rpx;
						height: 44rpx;
						line-height: 44rpx;
						font-size: $font-size-20;
						text-align: center;
						color: #FFFFFF;
						background-color: $color-system;
						border-radius: 4rpx;
						position: absolute;
						right: 0;
						top: 25rpx;
					}
				}
			}
			.list-view-upload{
				width: 100%;
				height: auto;	
				padding: 10rpx 0;
				.photo-item{
					display: inline-block;
					width: 112rpx;
					height: 112rpx;
					margin: 10rpx 0;
					margin-right: 25rpx;
					border-radius: 10rpx;
					border:1px solid #F5F5F5;
					position: relative;
					float: left;
					&.add{
						width: 112rpx;
						height: 112rpx;
						border-color: #b2b2b2;
						text-align: center;
						line-height: 112rpx;
						margin-right: 0rpx;
						.icon-jiahao{
							font-size: $font-size-44;
							color:#b2b2b2 ;
							font-weight: bold;
						}
					}
					.icon-iconfontguanbi{
						width: 30rpx;
						height: 30rpx;
						border-radius:50%;
						display: block;
						position: absolute;
						right: -10rpx;
						top: -10rpx;
						background: #f94b4b;
						text-align: center;
						line-height: 30rpx;
						color: #FFFFFF;
						font-size: $font-size-22;
					}
					image{
						width: 112rpx;
						height: 112rpx;
						border-radius: 10rpx;
					}
				}	
				.photo-list{
					width: 100%;
					height: 116rpx;
					overflow: hidden;
					white-space: nowrap;
					display: flex;
					align-items: flex-start;
				}
				.scoll-wrapper{
					display:flex;
					align-items: flex-start;
				}
			}
		}
		.list-btn{
			width: 702rpx;
			height: 56rpx;
			margin: 0 auto;
			.btn{
				width: 236rpx;
				height: 56rpx;
				background-color: #FFF;
				border-radius: 28rpx;
				border: 1px solid $color-system;
				line-height: 56rpx;
				text-align: center;
				color: $color-system;
				margin: 0 auto;
			}
		}
	}
	.qualifications-btn{
		width: 100%;
		padding-top: 20rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: #FFFFFF;
		.edit-button-canel{
			width: 100%;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			color: #e15616;
			font-size: $font-size-24;
		}
		.edit-button{
			width: 600rpx;
			height: 90rpx;
			background: $btn-confirm;
			line-height: 90rpx;
			text-align: center;
			color: #FFFFFF;
			font-size: $font-size-30;
			margin: 0 auto;
			border-radius: 45rpx;
		}
	}
</style>
