<template>
	<view>
		<view style="padding:5rpx 20rpx 45rpx 20rpx;">
			<view class="desc">
				<uni-row>
					<uni-col :span="5">
						<view class="desc" style="font-size: 25rpx;">
							文件名称
						</view>
					</uni-col>
					<uni-col :span="19">
						<view>
							<uni-easyinput primaryColor="#37babd" v-model="form.totalTime">
							</uni-easyinput>
						</view>
					</uni-col>
				</uni-row>
			</view>
			<view class="desc">
				<uni-row>
					<uni-col :span="5">
						<view class="desc" style="font-size: 25rpx;">
							文件类型
						</view>
					</uni-col>
					<uni-col :span="19">
						<view>
							<uni-easyinput primaryColor="#37babd" v-model="form.totalTime">
							</uni-easyinput>
						</view>
					</uni-col>
				</uni-row>
			</view>
			<view class="desc">
				<view class="desc" style="font-size: 25rpx;">
					文件审批事由:
				</view>
				<view>
					<uni-easyinput type="textarea" primaryColor="#37babd" v-model="form.totalTime">
					</uni-easyinput>
				</view>
			</view>
			<view class="desc">
				<view>
					请上传文件照片
				</view>
				<view style="width: 100%;overflow-x: scroll;white-space: nowrap">
					<u-upload style="margin: 0;" :fileList="fileList" @afterRead="afterRead" @delete="deletePic"
						name="1" multiple :maxCount="6" width="120" height="120" uploadIcon="plus-circle">
					</u-upload>
				</view>
			</view>
		</view>
		<u-gap height="70" bgColor="#ffffff"></u-gap>
		<view class="bottim_view">
			<view>
				<u-row>
					<u-col span="11">
						<u-button :disabled="isDisabled" class="btnDoPay" shape="circle" @click="submit"
							color="rgb(55,186,189)" text="提交"></u-button>
					</u-col>
				</u-row>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isDisabled: false,
				index: 0,
				fileList: [],
				wpTypes: ['办公用品', '固定资产', '低值易耗品', '广告印刷品', '其他']
			}
		},
		methods: {
			submit() {

			},
			onchange(e) {
				setTimeout(() => {

				}, 200)
			},
			maskClick(e) {},
			bindPickerChange: function(e) {
				this.index = e.detail.value
			},
			// 删除图片
			deletePic(event) {
				this.fileList.splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen
				if (this.fileList) {
					fileListLen = this.fileList.length
				} else {
					this.fileList = []
					fileListLen = 0
				}
				lists.map((item) => {
					this.fileList.push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this.fileList[fileListLen]
					this.fileList.splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
				// uni.setStorageSync("listImg", this.fileList)
				// console.log(this.fileList)
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.$BASE_URL + '/common/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						header: this.header,
						success: (res) => {
							// console.log(JSON.parse(res.data).url);
							setTimeout(() => {
								resolve(JSON.parse(res.data).url)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.desc {
		padding: 15rpx 5rpx;
	}

	.bottim_view {
		padding: 5px 20px 30px;
		position: fixed;
		left: 0px;
		bottom: 0px;
		width: 100%;
		height: 40px;
		background-color: #ffffff;
	}
</style>
