<template>
	<view v-if="show">
		<u-popup :show="show" round="15" mode="center" :closeable="true" :customStyle="{ width: '90%' }" @close="show = false">
			<view class="popup">
				<u-divider text="上传任务日志" class="mt20 mb0"></u-divider>
				<view class="bbg">
					<images v-model="item.pic"></images>
				</view>
				<textarea rows="3" placeholder="请输入说明" v-model="item.contents"></textarea>
				<view class="contents"></view>
				<button class="btn" @click="add()">立即提交</button>
			</view>
		</u-popup>
	</view>
</template>

<script>
export default {
	name: 'task',
	data() {
		return {
			show: false,
			item: { pic: [] }
		};
	},
	methods: {
		init(taskId) {
			this.show = true;
			this.item = { pic: [], taskId: taskId };
		},
		add() {
			let rule = [
				{ name: 'pic', checkType: 'notnull', errorMsg: '请上传照片' },
				{ name: 'contents', checkType: 'notnull', errorMsg: '请输入说明' }
			];
			if (!this.verify.check(this.item, rule)) {
				uni.showModal({ content: this.verify.error, showCancel: false });
				return false;
			}
			this.http.request({
				url: '/app/task/add',
				data: { taskId: this.item.taskId, pic: this.item.pic.toString(), contents: this.item.contents },
				method: 'POST',
				success: (res) => {
					uni.showModal({
						title: '提示',
						content: '上传成功',
						showCancel: false,
						success: (res) => {
							this.$emit('confirm');
							this.show = false;
						}
					});
				}
			});
		}
	}
};
</script>

<style lang="scss">
textarea {
	height: 130px;
	width: 93%;
	padding: 10px;
	margin-top: 10px;
	background-color: #f1f1f1;
	border-radius: 5px;
}
</style>
