<!--归还登记-->
<template>
    <view id="gasRecycle">
		<view class="title">{{form.airName}}-{{form.configName}}</view>
		<view class="register_li">
			<view class="register_li_min">
				<view>实验地点：</view>
				<input v-model="form.location" disabled  type="text" >
			</view>
			<view class="register_li_min" style="border: none;">
				<view>编号：</view>
				<input v-model="form.airNumber" disabled  type="text" >
			</view>
		</view>
		<view class="register_li2" v-if="pageType==0 || pageType==1">
			<view class="register_li_min">
				<view>*</view>
				<view>当前气压：</view>
				<input v-model="form.afterUse"   type="text" >
			</view>
			<view class="up-img-box">
				<view class="asterisk">*</view>
			    <view class="title-view">气表图片：</view>
			    <view class="img-max-box">
			        <view class="img-box" v-for="(item,index) in imgList" :key="index">
			            <img class="img-data" :src="baseUrl+item">
			            <img class="position-img" src="@/images/icon_ssp_closure.png" @click="delImg(index)">
			        </view>
			        <img class="add-button" src="@/images/icon_07.png" @click="selectImage" v-if="imgList.length<1">
			        <img class="add-button" src="@/images/Version3.0/img_sydj_sltp.png" >
			    </view>
			</view>
		</view>
		<view  class="sub_btn" @click="submitForm()">确认归还</view>

	</view>
</template>

<script>
	import { useRegisterDetail,giveRegisterAdd } from '@/api/index.js'
	import { config } from '@/api/request/config.js'
    export default {

        name: "gasRecycle",
        data() {
            return {
				baseUrl:config.base_url,
				pageType:0,
				//列表请求参数
				getData:{
				    pageNum:1,
					pageSize:20,
					isCg:0,
					zgStatus:"",
				    getType:true,
				    nullDataType:true,
				},
				form:{
					afterUse:null,
					afterUsePic:'',
					storageId:'',
				},
                dataList:[],
				imgList:[],
				electronicTag:'',
				specificationName:{},
            }
        },
       onLoad(option) {
       	this.electronicTag=option.code;
       },
        onShow() {

        },
		mounted(){
			this.getInfo()
		},
        methods: {
			// 图片上传
			selectImage(index) {
			    let self = this;
			    if(self.imgList.length>1){
			        uni.showToast({
			            title: '最多上传1张图片',
			            icon:"none",
			            mask:true,
			            duration: 2000
			        });
			        return
			    }
			    wx.chooseImage({
			        count: 1,
			        sizeType: ["original", "compressed"],
			        sourceType: ["album", "camera"],
			        success: function(res) {
			            let tempFilePaths = res.tempFilePaths[0];
			            self.uploadImg(tempFilePaths,index);
			        }
			    });
			},
			async uploadImg(tempFilePaths,index){
			    var self = this;
			    uni.showLoading({
			        title: '上传中',
			        mask: true
			    });
			    uni.uploadFile({
			        url: config.base_url+'/base/file/upload', //仅为示例，非真实的接口地址
			        header:{'Authorization':uni.getStorageSync('token')},
			        filePath: tempFilePaths,
			        name: 'file',
			        formData: {
			            'user': 'test'
			        },
			        success: (uploadFileRes) => {
			            let res = JSON.parse(uploadFileRes.data);
						if(res.code == 200){

							self.imgList.push(res.data.url);

						}else{
							uni.showToast({
								title: res.msg,
								icon:"none",
								mask:true,
								duration: 2000
							});
						}
			        },
			        fail: err => {},
			        complete: () => {
			            uni.hideLoading()
			        }
			    });
			},
			//删除图片
			delImg(index){
			    this.imgList.splice(index,1);
			},
			async getInfo(){
				let _this=this;
				const {data} = await useRegisterDetail({electronicTag:_this.electronicTag});
				if(data.code==200){
					let res = data.data;
					_this.form=res;
					_this.specificationName=JSON.parse(res.specificationName)
				}
			},
			//提交
			async submitForm(){
				let _this = this;
				if(!_this.form.afterUse){
					uni.showToast({
						title: '请输入当前气压!',
						icon:"none",
						mask:true,
						duration: 2000
					});
					return
				}
				if(_this.imgList.length<=0){
					uni.showToast({
						title: '请选择气表图片!',
						icon:"none",
						mask:true,
						duration: 2000
					});
					return
				}
				_this.form.afterUse=Number( _this.form.afterUse)
				_this.form.storageId=_this.form.id
				_this.form.afterUsePic=_this.imgList.join(',')
				const {data} = await giveRegisterAdd(_this.form);
				if(data.code == 200){
				    uni.showToast({
				        title: '提交成功',
				        icon:"none",
				        mask:true,
				        duration: 2000
				    });
				    setTimeout(function(){
				       uni.redirectTo({
				            url: '/pages_student/gasManage/gasManage'
				        });
				    },2000);
				}

			},
        }
    }
</script>

<style lang="stylus" scoped>
    #gasRecycle {
        height: auto;
        width: 100%;
		flex :1;
        display flex;
        flex-direction column;
        overflow hidden;
		padding-bottom: 220rpx;
		.title{
			width: 750rpx;
			height: 100rpx;
			background: #FFFFFF;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			line-height: 100rpx;
			padding-left: 40rpx;
		}
		.register_li{
			background #fff;
			border-radius:20rpx;
			margin:20rpx 20rpx 0;
			padding:20rpx 0;
			box-sizing: border-box;
			.register_li_min{
				margin:0 26rpx;
				display flex;
				align-items center;
				border-bottom: 1px solid #F5F5F5;
				.icon_img{
					width: 30rpx;
					height: 30rpx;
					margin-right: 12rpx;
				}
				view{
					//width:140rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 100rpx;
				}
				>input{
					flex:1;
					text-align: right;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}
			}

		}
		.register_li2{
			background #fff;
			border-radius:20rpx;
			margin:20rpx 20rpx 0;
			padding:20rpx 0;
			box-sizing: border-box;
			.register_li_min{
				margin:0 26rpx;
				display flex;
				align-items center;
				border-bottom: 1px solid #F5F5F5;
				.icon_img{
					width: 30rpx;
					height: 30rpx;
					margin-right: 12rpx;
				}
				view:nth-child(1){
					color:red;
					line-height:28rpx;
					margin-right: 12rpx;
				}
				view{
					//width:140rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
					line-height: 100rpx;
				}
				>input{
					flex:1;
					text-align: right;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
			}
			/* 照片 */
			.up-img-box{
			    display flex
			    margin:34rpx 26rpx;
				.asterisk{
					padding-top:30rpx;
					color:red;
					line-height:28rpx;
					margin-right: 12rpx;
				}
			    .title-view{
			        width:150rpx;
			        line-height:80rpx;
			        font-size: 30rpx;
			        color:#333;
			    }
			    .img-max-box{
			        width:480rpx;
					display: flex;
			        .img-box{
			            display inline-block
			            height:150rpx;
			            width:150rpx;
			            position relative
			            margin:0 20rpx 20rpx 0;
			            .img-data{
			                height:150rpx;
			                width:150rpx;
			            }
			            .position-img{
			                position absolute
			                right:0;
			                top:0;
			                width:36rpx;
			                height:36rpx;
			            }
			        }
			        .add-button{
			            display inline-block
			            height:150rpx;
			            width:150rpx;
						margin-right: 20rpx;
			        }
			    }
			}

		}
		/* 按钮 */
		.sub_btn{
			width: 650rpx;
			height: 100rpx;
			background: #0183FA;
			border-radius: 20rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 100rpx;
			text-align: center;
			margin-left: 50rpx;
			position: fixed;
			bottom:30rpx;
			z-index: 1000;
		}

	}
</style>
