<template>
	<view class="fs-p30">
		<tui-form ref="form" :showMessage="false">
			<tui-textarea :radius="20" placeholder="请输入巡检描述" isCounter :size="28" :maxlength="100" v-model="formData.remark"></tui-textarea>
			<tui-white-space></tui-white-space>
			<tui-upload background="#fff" :width="210" :radius="10" :height="210" delColor="#333" custom :serverUrl="serverURL" :header="{'Authorization': userToken}" :limit="3" @complete="complete">
				<text class="fs-size__28 fs-color__subtitle fs-weight__400">上传图片</text>
			</tui-upload>
		</tui-form>
		<view class="fs-mt60 fs-flex__center">
			<tui-button shape="circle" width="600rpx" height="80rpx" shadow :loading="isLoading" :disabled="isLoading" @click="onSubmit">提 交</tui-button>
		</view>
	</view>
</template>

<script>
import { uploadURL } from '@/config/app'
import { apiInspectionAdd } from '@/api/work'
const rules = [
	{
		name: "remark",
		rule: ["required"],
		msg: ["请输入描述"]
	}
]
export default {
	data() {
		return {
			formData: {
				type: 1,
				remark: '',
				imgs: [],
				planNo: ''
			},
			isLoading: false,
			serverURL: uploadURL,
			id: 0
		}
	},
	onLoad(options) {
		this.id = options.id
		this.formData.planNo = options.planno
	},
	methods: {
		// 上传完成
		complete(e) {
			if (e.status == 1) this.formData.imgs = e.imgArr
		},
		// 提交记录
		onSubmit() {
			this.$refs.form.validate(this.formData, rules).then(res => {
				if (!res.isPass) {
					uni.$tui.toast(res.errorMsg)
					return
				}
				if (!this.formData.imgs.length) {
					uni.$tui.toast('请上传图片')
					return
				}
				this.isLoading = true
				apiInspectionAdd({data:{...this.formData}}).then(res => {
					uni.$tui.toast('提交成功')
					const pages = getCurrentPages()
					const beforePage = pages[pages.length - 2]
					const id = this.id
					setTimeout(() => {
						uni.navigateBack({
							success () {
								// 刷新页面数据
								beforePage.$vm.getInspectionInfo(id)
						    }
						}) 
					}, 1500)
				}).finally(() => {
					this.isLoading = false
				})
			})
		}
	}
}
</script>

<style lang="scss" scoped>

</style>
