<template>
	<view class="">
		<view class="navbar">
			<view class="back">
				<text class="iconfont icon-fanhui " @click="backLast()"></text>
			</view>
			<text>上传文件</text>
		</view>
		<view class="upload-home">

			<view class="imgList">
						<view class="img-title">请拍摄并上传图片<text class="down-tmp"> <a :href="url">点击下载模板</a></text></view>
				<!-- <view class="img-title">请拍摄并上传图片<text class="down-tmp" @click="downLoad()">点击下载模板</text></view> -->
				<view class="img-box">
					<htz-image-upload :max="9" v-model="ceshiData1" :uploadSuccess="zidingyiSuccess" :action="baseUrl+'/upload'"></htz-image-upload>
				</view>
				<view class="remark">
					拍摄时确保文件照片<text style="color: red;">边缘完整，字体完整，亮度均匀。</text>
				</view>
			</view>

			<view class="table">
				<view class="title">请确定文件信息</view>
				<view class="text-box">
					<text class="input-key">文件名称：</text><input type="text" v-model="steps.name" class="input-val" placeholder="请输入文件名称" />
				</view>
			</view>

			<view class="submit" @click="saveSubmit()">
				保存
			</view>
			<view class="tips" v-if="tips">
				<view class="title">注意事项：</view>
				<view class="content">{{tips}}</view>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	import navBar from '../../components/navBar/navbar.vue';
	var app = getApp()
		import configData from '../../config.js'
	import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
	export default {
		data() {
			return {
				uploadLists: [],
				max: 1,
				chooseNum: 9,
				ceshiData: [],
				ceshiData1: [],
				file_type: {
					file_type: 'img'
				},
				steps: {
					name: ""
				},
				url:"",
				resource_ids: [],
				staff_id: '',
				isShow: false,
				tips: '',
				baseUrl:configData.data.baseUrl
			}
		},
		components: {
			htzImageUpload,
			navBar
		},
		onLoad() {
			//#ifdef H5
			console.log('ceshi-------h5')
			//#endif
			//#ifdef APP-PLUS
			console.log('ceshi-------app')
			//#endif
			let steps = uni.getStorageSync('steps')
			this.steps = uni.getStorageSync('steps')
			this.name = steps.name
			app.request('/authorization', '', 'get').then(res => {
				this.staff_id = res.data.data.staff_id
				console.log(res, '------------------')
			})
			// this.getTips()
			let params = {
				key: uni.getStorageSync('steps').key,
			}
			app.request('/templates', params, 'get').then(res => {
				console.log(res.data.data.data[0].resource, "---------------------模板")
				this.url = res.data.data.data[0].resource
				this.tips = res.data.data.data[0].remark
			})
		},
		methods: {
			backLast:function(){
				console.log(this.url)
				uni.reLaunch({
					url:'./fileList'
				})
			},
			downLoad() {
			
					let url = this.url
					let dload = document.createElement("a");
					dload.download = ''; // 设置下载的文件名，默认是'下载'

					dload.href = url;

					document.body.appendChild(dload);

					dload.click();

					dload.remove(); // 下载之后把创建的元素删除

					uni.showToast({

						title: "正在下载",

						icon: "success"

					});
			},
			tiaozhuan: function() {


			},

			//上传保存图片
			saveSubmit: function() {
				console.log(this.resource_ids, "________")
				if (!this.steps.name) {
					uni.showToast({
						title: '文件名称不能为空~',
						icon: 'none'
					})
				} else if (!this.resource_ids) {
					uni.showToast({
						title: '请选择图片~',
						icon: 'none'
					})
				} else {
					let ids = JSON.stringify()
					let data = {
						name: this.steps.name,
						key: this.steps.key,
						resource_type: 1,
						resource_ids: this.resource_ids,
						staff_id: this.staff_id,
						user_id: uni.getStorageSync('userInfo').id,
						organization_id: uni.getStorageSync('userInfo').organization_id
					}
					console.log(data.resource_ids, 'llllllllllllllllllllll')
					app.request('/archives', data, 'post').then(res => {
						console.log(res, "上传成功")
						if (res.data.code == 200) {
							uni.showToast({
								title: "上传成功",
								icon: 'none'
							})
							setTimeout(function() {
								uni.navigateBack({

								})
							}, 500)
						}
						else{
							uni.showToast({
								title: res.data.message,
								icon: 'none'
							})
						}
					})
				}
			},
			zidingyiSuccess(res) {
				var _res = JSON.parse(res.data);
				if (_res.code == 200) {
					let imgId = _res.data.id
					// idList.map(item=>{
					this.resource_ids.push(imgId)
					console.log(this.resource_ids)
					return {
						success: true,
						url: _res.data.url
					}
				} else {
					return {
						success: false,
						url: ''
					}
				}
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #EFF1F6;
	}
.navbar {
		font-size: 32upx;
		height: 100upx;
		line-height: 100upx;
		color: #888888;
		position: relative;
		position: fixed;
		top: 0;
		z-index: 9999999;
		width: 100%;
		 background-color: #FFFFFF;
		text-align: center;
		border-bottom: solid 2upx #EFF1F6;
	
		.back {
			height: 100upx;
			width: 100upx;
			text-align: center;
			// background-color: #007AFF;
			position: absolute;
			float: left;
			left: 0upx;
			font-size: 32upx;
		}
	}
	.upload-home {
		background-color: #EFF1F6;
		width: 100%;
		height: 100%;
		padding-top: 100upx;

		.table {
			background-color: #FFFFFF;
			font-size: 28upx;
			margin-top: 30upx;
			padding: 30upx;

			.title {
				color: #666;
				font-size: 30upx;
				display: block;
				padding-bottom: 30upx;
				border-bottom: 1px solid #EFF1F6;
			}

			.text-box {
				margin-top: 20upx;

				.input-key {
					display: inline-block;
					height: 80upx;
					line-height: 80upx;
					width: 160upx;
					vertical-align: top;
					color: #555;
					font-size: 32upx;
				}

				.input-val {
					display: inline-block;
					height: 80upx;
					line-height: 80upx;
					vertical-align: top;
					width: calc(100% - 160upx);
					text-align: right;
					color: #333;
					font-size: 32upx;
				}
			}

			// .left {
			// 	flex: 0 0 150upx;
			// }

			// .right {
			// 	flex: 1;
			// 	height: 80upx;
			// 	// border-bottom: solid 2upx #fabeb9;
			// 	line-height: 80upx;
			// }
		}

		.imgList {
			background-color: #fff;
			padding: 30upx;

			.remark {
				font-size: 26upx;
				padding-top: 20upx;
				color: #555;
			}

			.img-title {
				color: #666;
				font-size: 30upx;
				display: block;
				position: relative;

				.down-tmp {
					color: red;
					position: absolute;
					right: 0;
					a{
						text-decoration: none;
						color: red;
					}
				}
			}

			.img-box {
				margin-top: 20upx;
				background-color: #F3F3F3;
				border-radius: 10upx;
				padding: 15upx;

				.list-img {}
			}
		}

		.submit {
			padding: 25upx 0;
			width: 90%;
			margin: 0 auto;
			margin-top: 100upx;
			margin-bottom: 50upx;
			text-align: center;
			font-size: 32upx;
			color: #FFFFFF;
			background-color: #e61916;
			border-radius: 10upx;
		}



		.htz-image-upload-list {
			display: flex;
			flex-wrap: wrap;
		}

		.htz-image-upload-Item {
			width: 160rpx;
			height: 160rpx;
			margin: 13rpx;
			border-radius: 10rpx;
			position: relative;
		}

		.htz-image-upload-Item image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}

		.htz-image-upload-Item-add {
			font-size: 105rpx;
			/* line-height: 160rpx; */
			text-align: center;
			border: 1px dashed #d9d9d9;
			color: #d9d9d9;
		}

		.htz-image-upload-Item-del {
			background-color: #f5222d;
			font-size: 24rpx;
			position: absolute;
			width: 35rpx;
			height: 35rpx;
			line-height: 35rpx;
			text-align: center;
			top: 0;
			right: 0;
			z-index: 100;
			color: #fff;
		}

		.tips {
			margin: 90upx auto 0;
			border: 1px dashed red;
			padding: 20upx;
			width: 85%;
			border-radius: 15upx;
			font-size: 28upx;
			color: #555;

		}
	}
</style>
