<template>
	<view class='container'>
		<view>
			<u-form :model="dataobj" ref="uForm">
				<u-form-item class='typeform'  :border-bottom='false' label="类型"><view style='color:#000;width:100%;text-align:right;' @click='typeselect'>{{dataobj.businessType?dataobj.businessType+" >":'请选择类型 >'}}</view></u-form-item>
			</u-form>
			<u-form :model="dataobj"  ref="uForm">
				<u-form-item :border-bottom='false' :label-position='"top"' label="备注">
					<view class="u-textarea-style">
						<view class="right-bottom">
							{{dataobj.remark.length}}/2000个字
						</view>
						<!-- <u-input class="" v-model='auditMind' placeholder="请在此输入审核意见" type="textarea" height="414"
							maxlength="100" /> -->
							<textarea style='font-size:12px;' maxlength="2000" v-model='dataobj.remark' placeholder="请输入备注信息" name="" id="" cols="30" rows="11"></textarea>
					</view>
				</u-form-item>
			</u-form>
			<view class='wrap'>
				<view class="c-row">
				<view class="title">
					<view>附件</view><view><text style='color:#617AE0;'>{{imglist2.length}}</text>/20</view></view>
				</view>
				<view style="display: flex;flex-wrap: wrap;">
					<view v-for='(item,index) in imglist2' v-if="imglist2 && imglist2.length > 0"
						style="position: relative;margin:20rpx 0 20rpx 20rpx;">
						<view class="delete_img" @click="deleteImg(index)">X</view>
						<image :src="item.appendixPath" mode="" style="width: 100px;height: 100px;"></image>
					</view>
					<view class="biankuang" @click="uploadClick" v-if="imglist2.length < 20">
						<view class="tubiao">
								上传附件
						</view>
					</view>
				</view>
			</view>
			<u-picker @confirm='typeconfirm' :range="xialaList"  mode="selector" v-model="show" range-key="constValue" :default-selector="[0]"></u-picker>
		</view>
		<u-toast ref="uToast" />
		<view class="bottom-btn">
			<view @click="submit()" class="btn">提交</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import * as config from '../../config'
	export default {
		data() {
			return {
				xialaList:[],
				show:false,
				dataobj:{remark:''},
				imglist:[],
				imglist2:[]
			}
		},
		onShow(){
			this.getList()
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		watch: {
			imglist: {
				handler: function() {
					this.$api.doRequest('get', 'appendix/query/getFileList', {
						appendixIds: this.imglist.toString()
					}).then(res => {
						this.imglist2 = res.data.data
					})
				},
				deep: true
			}
		},
		methods: {
			async uploadClick() {
				let baseUrlNew = config.def().baseUrlNew
				console.log('baseUrlNew',baseUrlNew)
				let pcUserInfo = uni.getStorageSync('pcUserInfo')
				if(!pcUserInfo){
					uni.showToast({
						title:"登录已失效，请重新登录"
					})
					return 
				}
				uni.chooseImage({
					count:10,
					success: (chooseImageRes) => {
						console.log('chooseImageRes',chooseImageRes)
						let files = []
						for (let item of chooseImageRes.tempFiles) {
							files.push({
								name: 'fileName',
								url : item.path
							});
						}
							for (let i = 0; i < files.length; i++) {
						uni.uploadFile({
							url: baseUrlNew + 'appendix/api/uploadFiles',
							// url: baseUrlNew+'appendix/api/uploadFiles', //仅为示例，非真实的接口地址
							filePath: files[i].url,
							name: files[i].name,
							formData: {
								// fileName: chooseImageRes.tempFiles[0],
								companyId: pcUserInfo.compId,
								modelId: '',
								vesselId: '',
							},
							success: (uploadFileRes) => {
								console.log(JSON.parse(uploadFileRes.data))
								var data = JSON.parse(uploadFileRes.data).data
								data.compId = pcUserInfo.compId
								this.$api.doRequest('post', '/appendix/api/saveFilesApp', {
									newAppendixs: [data],
									oldAppendixIds: ""
								}).then(res => {
									this.imglist.push(res.data.data[0])
									console.log(res)
								})
								console.log(uploadFileRes.data);
							},
							fail(res) {
								
								console.log(res);
							}
						});
						}
					}
				});
			},
			deleteImg(index) {
				this.imglist.splice(index, 1)
			},
			getList(){
				this.$api.doRequest('get', '/commonSysParameter/getInfo', {
					constId:'EXA1'
				}).then(res => {
					this.xialaList=res.data.data
				})
			},
			typeselect(){
				this.show=true
			},
			typeconfirm(e){
				console.log(this.xialaList[e[0]])
				this.dataobj.businessType=this.xialaList[e[0]].constValue
			},
			submit() {
				if (!this.dataobj.businessType) {
					this.$api.msg('类型不能为空')
					return
				}
				
				var that = this
				this.dataobj.compId=uni.getStorageSync('pcUserInfo').compId
				this.dataobj.sponsor=this.userInfo.userName
				
				uni.showModal({
					content: '确定发起申请？',
					showCancel: true,
					confirmText: '提交',
					success: function(res) {
						if (res.confirm) {
							if (that.imglist.length > 0) {
								that.dataobj.addressUrl = that.imglist.toString()
							}
							uni.showLoading({
								title: "加载中",
								mask: true
							})
							that.$api.doRequest('post', '/generalAuditInfo/api/insertGeneralAuditInfo', that.dataobj)
								.then(res => {
									if (res.data.code == 200) {
										uni.hideLoading()
										that.$api.msg('提交成功')
										uni.navigateBack({
											delta: 1
										});
									} else {
										that.$api.msg('提交失败')
									}
								})
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		padding-bottom: 20rpx;
	}
page {
		background: #F5F6FA;
	}
.u-form {
		margin: 20rpx;
		background: #fff;
		border-radius: 10px;
		padding: 30rpx 10px;
	
		.u-form-item {
			line-height: 30px;
			padding: 0px 0;
			font-size: 26rpx;
			color: #878C9C;
		}
	}
	.delete_img {
		position: absolute;
		z-index: 100;
		left: 84px;
		color: #ffffff;
		font-size: 24rpx;
		border: 1px;
		border-radius: 5rpx 5rpx 5rpx 20rpx;
		width: 32rpx;
		height: 32rpx;
		background-color: rgba(17, 26, 52, 0.5000);
		padding:0 3px 0 5px;
		text-align: center;
	}

	.title_b {
		margin: 20rpx 20rpx 0rpx 20rpx;
		padding: 20rpx 10rpx 20rpx 10rpx;
		font-size: 18px;
		font-weight: 550;
	}

	.xinxi {
		padding: 20rpx 30rpx;
	}

	.tubiao {
		margin: 0 auto;
		text-align: center;
		margin-top: 35rpx;
	}

	.biankuang {

		width: 100%;
		height: 120rpx;
		border-radius: 30px;
		margin:0 20rpx;
		background:#F5F9FC;
		color:#617AE0;
	}

	.upload {
		width: 80rpx;
		height: 80rpx;
	}

	.c-row {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		padding: 20rpx 30rpx;
		position: relative;
	}

	.con-list {
		-webkit-box-flex: 1;
		flex: 1;
		display: flex;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		flex-direction: column;
		color: #303133;
		line-height: 20px;
		text-align: right;
		padding-right: 10px;
		justify-content: space-between;
	}

	.title {
		width:100%;
		display:flex;
		justify-content: space-between;
	}

	.buns_item {
		display: flex;
		padding: 80rpx 0 50rpx 0;
		justify-content: space-around;
	}

	.but_css {
		background: #22C572;
		width: 40%;
		padding: 20rpx;
		color: #fff;
		text-align: center;
		border-radius: 20rpx;
	}

	/deep/.u-radio-group {
		flex-direction: row-reverse;
	}

	.no-boder {
		border: 0;
	}

	.textarea {
		background: #F9F9FA;
		border: 1px solid #EEEEEE;
	}

	.remark {
		position: absolute;
		right: 10px;
		bottom: 20px;
		color: #AFB3BF;
	}

	.submit {
		width: 100%;
		background: #2c8ac5;
		border-radius: 10rpx;
	}

	.bottom-btn {
		padding: 30rpx;
		background: #FFFFFF;
		width: 100%;
		position: fixed;
		bottom: 0rpx;
		display: flex;
		z-index: 9999;
	}

	.content {
		overflow: hidden;
	}

	.btn {
		border-radius: 50rpx;
		padding: 20rpx 0;
		background: #22C572;
		color: #fff;
		font-size: 32rpx;
		width: 100%;
		box-sizing: border-box;
		display: flex;
		justify-content: center;
	}
	.margin-bottom{
		margin-bottom:84px;
	}
	.u-textarea-style {
		margin: 20rpx;
		background: #F9F9FA;
		border-radius: 10px;
		border: 1px solid #EEEEEE;
		padding: 10rpx 20rpx;
		position: relative;
		height:240px;
		/deep/.uni-textarea-textarea{
			width: 80%;
		}
		.right-bottom {
			position: absolute;
			right: 20rpx;
			bottom: 20rpx;
			color: #AFB3BF;
		}
	}
	.wrap{
		border-radius:10px;
		background:#fff;
		margin:10px 10px 80px 10px;
		padding:0 0 10px 0;
	}
</style>
