<template>
	<view class="container qualifications" :style="{ paddingBottom: isIphoneX ? '68rpx' : '0' }">
		<view class="remarks-content">
			<view class="list-view-title"> <view class="list-view-h1">文字备注</view> </view>
			<view class="remarks-textarea"> {{ remarksParams.note }} </view>
			<view class="list-view-title"> <view class="list-view-h1">上传图片</view> </view>
			<view class="list-view-upload clearfix">
				<view class="photo-item" v-for="(image, imageIndex) in remarksParams.imageList" :key="imageIndex">
					<image
						:src="image"
						mode="aspectFill"
						@click.stop="previewImg(remarksParams.imageList, imageIndex)"
					></image>
				</view>
			</view>
			<view class="list-view-title"> <view class="list-view-h1">上传文件</view> </view>
			<view class="list-view" v-for="(file, fileIndex) in remarksParams.fileList" :key="fileIndex">
				<view class="list-view-text">
					<view class="input">{{ file.name }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import authorize from '@/common/config/authorize.js'
import { uploadFileImage, uploadFilePdfDocDocx } from '@/services/public.js'

var isPreviewImg
export default {
	data() {
		return {
			isIphoneX: this.$store.state.isIphoneX,
			shopOrderId: 0,
			logisticsBatchId: 0,
			productActions: [],
			remarksParams: {
				note:
					'本期采美网给大家带来重磅消息：中国医美知名上游品牌半岛医疗正式入驻采美啦！！！本期采美网给大家带来重磅消息：中国医美知名上游品牌半岛医疗正式入驻采美啦！！！本期采美网给大家带来重磅消息：中国医美知名上游品牌半岛医疗正式入驻采美啦！！！本期采美网给大家带来重磅消息：中国医美知名上游品牌半岛医疗正式入驻采美啦！！！本期采美网给大家带来重磅消息：中国医美知名上游品牌半岛医疗正式入驻采美啦！！！本期采美网给大家带来重磅消息：中国医美知名上游品牌半岛医疗正式入驻采美啦！！！本期采美网给大家带来重磅消息：中国医美知名上游品牌半岛医疗正式入驻采美啦！！！本期采美网给大家带来重磅消息本期采美网给大家带来重磅消息本期采美网给大家带来重磅消息本期采美网给大家带来重磅消息本期采美网给大家带来重磅消息本期采美网给大家带来重磅消息：中国医美知名上游品牌半岛医疗正式入驻采美啦！！！',
				fileList: [
					{
						name: '任正非：除了胜利，我们已无路可走.pdf',
					},
					{
						name: '任正非：除了胜利，我们已无路可走.pdf',
					},
					{
						name: '任正非：除了胜利，我们已无路可走.pdf',
					},
					{
						name: '任正非：除了胜利，我们已无路可走.pdf',
					},
				],
				imageList: [
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png',
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png',
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png',
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png',
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png',
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png',
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png',
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png',
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png',
					'https://img.caimei365.com/group1/M00/00/10/rB-lGGCHqP-AIE9-AAEQHiqWjQY981.png'
				]
			},
			min: 0,
			max: 500
		}
	},
	onLoad(option) {
		console.log(option)
		if (option.type == 'add') {
			this.logisticsBatchId = option.logisticsBatchId
			this.shopOrderId = option.shopOrderId
			this.GetSupplierLogisticsRecord()
		} else {
			this.logisticsBatchId = option.logisticsBatchId
			this.shopOrderId = option.shopOrderId
			this.GetSupplierLogisticsRecord()
			this.GetSupplierQualificationData()
		}
	},
	methods: {
		...mapMutations(['login']),
		GetSupplierQualificationData() {
			//编辑回显商品资质信息
			this.ShopService.GetSupplierQualificationData({
				logisticsBatchId: this.logisticsBatchId
			})
				.then(response => {
					const data = response.data
					if (data && data.length > 0) {
						this.qualificationsList = data
						this.isEmpty = false
					} else {
						this.isEmpty = true
					}
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		GetSupplierLogisticsRecord() {
			//添加商品资质初始化查询商品信息
			this.ShopService.GetSupplierLogisticsRecord({
				logisticsBatchId: this.logisticsBatchId
			})
				.then(response => {
					const data = response.data
					data.forEach((el, index) => {
						let obj = {
							value: el.id,
							name: el.productName
						}
						this.productActions.push(obj)
					})
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		editButtonConfim() {
			//确定
			// 校验物流公司不能为空
			let isRecordId = false
			let isSnCode = false
			let isFileList = false
			let isImageList = false
			let params = [] //参数
			this.qualificationsList.forEach((el, index) => {
				if (el.recordId == '') {
					isRecordId = true
				}
				if (el.sn == '') {
					isSnCode = true
				}
				if (el.fileList == '') {
					isFileList = true
				}
				if (el.imageList == '') {
					isImageList = true
				}
				let paramsObject = {
					recordId: el.recordId,
					sn: el.sn,
					files: el.fileList,
					images: el.imageList
				}
				params.push(paramsObject)
			})
			if (isRecordId) {
				this.$util.msg('请选择商品', 2000)
				return
			}
			if (isSnCode) {
				this.$util.msg('请输入商品SN码', 2000)
				return
			}
			if (isFileList && isImageList) {
				this.$util.msg('请上传商品资质文件', 2000)
				return
			}
			console.log('params========>', params)
			this.ShopService.GetSupplierQualificationUpdata({
				params: JSON.stringify(params)
			})
				.then(response => {
					this.$util.msg('保存成功', 3000, true, 'success')
					setTimeout(() => {
						this.$api.navigateTo(`/pages/supplier/deliver/deliver-record?shopOrderId=${this.shopOrderId}`)
					}, 2000)
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		bindPickerChange: function(item, e) {
			//选择筛选条件
			item.recordId = this.productActions[e.target.value].value
			item.productName = this.productActions[e.target.value].name
		},
		addListFn() {
			//添加
			let obj = {
				productName: '',
				recordId: '',
				sn: '',
				fileList: [],
				imageList: []
			}
			this.qualificationsList.push(obj)
		},
		deleteLogistItemFn(item, index) {
			this.$util.modal('提示', '确认删除物流信息吗？', '确定', '取消', true, () => {
				this.qualificationsList.splice(index, 1)
			})
		},
		uploadFile(array) {
			//上传资质文件
			console.log(array)
			uploadFilePdfDocDocx().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: ''
			})
		},
		conInput(e) {
			//备注文字字数限制
			let value = e.detail.value
			let len = parseInt(value.length)
			if (len > this.max) return
			this.min = len
			if (this.min == 200) {
				this.$util.msg('您输入的字数已达上限', 2000)
			}
		}
	},
	onShow() {}
}
</script>

<style lang="scss">
page {
	height: auto;
	background: #ffffff;
}
.remarks-content {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	padding: 0 24rpx;
	.list-view-title {
		width: 100%;
		height: auto;
		margin-bottom: 16rpx;
		margin-top: 40rpx;
		.list-view-h1 {
			line-height: 40rpx;
			font-size: $font-size-28;
			color: #333333;
			text-align: left;
		}
	}
	.remarks-textarea {
		width: 100%;
		height: 340rpx;
		padding: 16rpx;
		margin: 20rpx 0 0 0;
		border-radius: 6rpx;
		position: relative;
		border: 1px solid #b2b2b2;
		box-sizing: border-box;
		overflow-y: scroll;
		line-height: 38rpx;
		font-size: $font-size-26;
		color: #333333;
	}
	.list-view {
		width: 100%;
		height: auto;
		margin-top: 20rpx;
		.list-view-text {
			width: 100%;
			float: left;
			.input {
				width: 560rpx;
				height: 50rpx;
				box-sizing: border-box;
				line-height: 50rpx;
				color: #333333;
				text-overflow: ellipsis;
				overflow: hidden;
				display: -webkit-box;
				-webkit-line-clamp: 1;
				line-clamp: 1;
				-webkit-box-orient: vertical;
				float: left;
				font-size: 26rpx;
			}
		}
	}
	.list-view-upload {
		width: 100%;
		height: auto;
		.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;
			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;
		}
	}
}
</style>
