<!--
 * @Title: 
 * @Description: 维修任务填报提交页
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
	<view class="container">
		<uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
			@clickLeft="toBack">
			<view style="width: 100%;display: flex;flex-direction: row;justify-content: center;align-items: center;">
				<text style="color: white;font-size: 1rem;">{{title}}</text>
			</view>
		</uni-nav-bar>
		<uni-forms ref="baseForm" :model="formData" :rules="rules">
			<uni-group>
<!-- 				<uni-forms-item name="postCode" label="岗位" label-width="130px" required>
					<uni-data-checkbox v-model="formData.postCode" :localdata="postCodeOption.items">
					</uni-data-checkbox>
				</uni-forms-item> -->
				<uni-forms-item name='personName' label="姓名" label-width="130px" required>
					<uni-easyinput :styles="styles" v-model="formData.personName" placeholder="请录入姓名" />
				</uni-forms-item>
				<uni-forms-item name='contactPhone' label="联系电话" label-width="130px">
					<uni-easyinput :styles="styles" v-model="formData.contactPhone" placeholder="请录入联系电话" />
				</uni-forms-item>
				<uni-forms-item name='mail' label="邮箱" label-width="130px">
					<uni-easyinput :styles="styles" v-model="formData.mail" placeholder="请录入邮箱" />
				</uni-forms-item>
			</uni-group>
		</uni-forms>
		<view class="footer">
			<view class="control">
				<view class="view-flex-rc">
					<view class="block"
						style="width: 120px;height:28px;margin-left: 10px;margin-right: 10px;border-radius:7px;background-color:lightpink"
						@click="toSubmit()">
						<view class="view-flex-cc">
							<uni-icons class="input-uni-icon" type="checkmarkempty" size="18" color="#999" />
						</view>
						<view class="view-flex-cc" style="padding-left:5px;">
							<text style="color:black;font-size:0.7rem">立即提交</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import http from '@/http/api.js';
	import {
		oss,
		devUrl,
		prodUrl
	} from '@/common/setting';
	export default {
		components: {},
		data() {
			return {
				title: '人员信息修改',
				desc: '',
				styles: {
					color: '#333',
					borderColor: '#e5e5e5',
					disableColor: '#FFFFFF'
				},
				formData: {
					id: '',
					personName: '',
					contactPhone: '',
					mail: '',
					// postCode: '',
				},
				rules: {
					// 手机网络信号选择
					postCode: {
						rules: [{
							required: true,
							errorMessage: '必填项',
						}]
					},
					personName: {
						rules: [{
							required: true,
							errorMessage: '必填项',
						}, ]
					},
				},
				baseURL: '',
				baseOSS: '',
				postCodeOption: {
					items: [{
						'value': 1,
						'text': '工程师'
					}, {
						'value': 2,
						'text': '服务员'
					}],
					current: 0,
				},
				id: '',
			}
		},
		computed: {

		},
		onLoad(options) {
			this.baseURL = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
			this.baseOSS = oss;
			this.id = options.id;
			this.getDetail(this.id);
		},
		onReady() {
			console.log("onReady++++++++++++++")
			// 需要在onReady中设置规则
			this.$refs.baseForm.setRules(this.rules)
		},
		onShow() {},
		methods: {
			toOss(path) {
				let url = this.baseOSS + path;
				console.log("tooss " + url)
				return url;
			},
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			getDetail(id){
				let that = this;
				let postData = {};
				postData['id'] = this.id;
				http.request({
					url: '/galaxy-business/serviceperson/detail',
					method: 'GET',
					data: postData
				}).then(res => {
					console.log(JSON.stringify(res))
					if (res.data != null) {
						that.formData = res.data;
						// that.formData['personName'] ==res.data.
						
						// personName: '',
						// contactPhone: '',
						// mail: '',
					}
				}).catch(err => {
					console.log(err)
				})
			},
			toSubmit() {
				console.log('表单提交');
				let that = this;
				this.$refs.baseForm.validate().then(res => {
					that.submitData();
				}).catch(err => {
					console.log('表单错误信息：', err);
					uni.showModal({
						content: "内容填报错误，请根据提示信息检查录入内容!",
						showCancel: false,
						success(res) {
							if (res.confirm) {
								//that.$refs.baseForm.clearValidate();
							}
						}
					});
				})
			},
			submitData() {
				let formdata = this.formData;
				formdata['id'] = this.id;
				let that = this;
				http.request({
					url: '/galaxy-business/serviceperson/update',
					method: 'POST',
					data: formdata
				}).then(res => {
					if (res.success) {
						uni.showModal({
							content: '已成功提交',
							showCancel: false,
							success(res) {
								that.toBack();
							}
						});
					} else {
						uni.showModal({
							content: '' + res.msg,
							showCancel: false
						});
					}
				}).catch(err => {
					console.log(err)
				})
			},

		}
	}
</script>

<style>
	/* page {
		background-color: rgb(240, 242, 244);
	} */
</style>

<style lang="scss" scoped>
	.cell-hover-class {
		background-color: rgb(235, 237, 238);
	}

	.view-flex-rs {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
	}

	.view-flex-rc {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}

	.view-flex-re {
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		align-items: center;
	}

	.view-flex-cs {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
	}

	.view-flex-cc {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.view-flex-ce {
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
	}

	.line-body {
		padding-left: 10px;
		padding-right: 10px;
	}

	.required-star {
		color: #FF0000;
		font-size: 15px;
		width: 20px;
		text-align: center;
		padding-left: 0px;
		padding-right: 2px;
	}

	.item-title {
		color: #909399;
		font-size: 15px;
	}

	.mline-text {
		padding-left: 2px;
		width: 100%;
		/* background-color:#909399; */
		height: 70px;
		border: 1px solid #FF5A5F;
		border-radius: 5px;
	}

	.footer {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 1;
		height: 100rpx;
		padding: 20rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		background-color: whitesmoke;

		.ipt {
			width: 380rpx;
			height: 77rpx;
			background: #f7f7f7;
			border-radius: 38px;
			padding: 0 37rpx;
			box-sizing: border-box;
			margin-right: 20rpx;
		}

		.control {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: flex-end;

			.block {
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
			}

			.icon {
				height: auto;
			}

			.c {
				width: 41rpx;
				margin-right: 10rpx;
			}

			.s {
				width: 36rpx;
			}

			.t {
				width: 31rpx;
			}
		}
	}

	.container {
		padding: 0 0 100rpx;
	}

	.img-container {
		margin-bottom: 0px;
		width: 80px;
		height: 80px;

		.note-image-box {
			margin-top: 5px;
			display: flex;
			flex-wrap: wrap;
			padding: 0px;

			.note-image-item {
				position: relative;
				width: 100%;
				height: 0;
				padding-top: 100%;
				box-sizing: border-box;
				// background-color: #18B566;

				.close-icon {
					display: flex;
					justify-content: center;
					align-items: center;
					position: absolute;
					right: 0px;
					top: 0px;
					width: 22px;
					height: 22px;
					border-radius: 50%;
					background-color: #d5d5d5;
					z-index: 2;
				}

				.image-box {
					display: flex;
					justify-content: center;

					align-items: center;
					position: absolute;
					top: 0px;
					right: 0px;
					border: 0px;
					left: 0px;
					border: 1px #eee solid;
					border-radius: 5px;
					overflow: hidden;
					width: 98%;
					height: 98%;

				}


			}
		}
	}

	.input-body {
		background-color: #fff;
		padding: 10px;
	}

	.mb-10 {
		margin-top: 0px;
		margin-bottom: 0px;
	}

	.decoration {
		width: 6px;
		height: 6px;
		margin-right: 4px;
		border-radius: 50%;
		background-color: cadetblue;
	}
</style>