<template>
	<view class="content">

		<view class="banner"></view>

		<view class="b-relative" style="width: 710rpx;height: 310rpx; margin: -174rpx auto 0;">
			<image src="/static/ms/settled.png" style="width: 710rpx;height: 310rpx;"></image>
			<view class="banner-font">
				<image style="width: 380rpx;height: 98rpx;" src="/static/ms/fontjszm.png"></image>
			</view>
			<view class="font-3">打造专业的技术服务</view>
			<view class="banner-button">立即联系我们>></view>
		</view>

		<view>
			<view class="item-card">
				<view class="serrled-title">
					<view class="before"></view>
					店铺信息
				</view>
				<view class="item-line flex">
					<view class="label">店铺名称</view>
					<input placeholder="请输入店铺名称" v-model="technician.name" />
				</view>
				<view class="item-line flex">
					<view class="label">你的姓名</view>
					<input placeholder="请输入姓名" v-model.number="technician.username" />
				</view>
				<view class="item-line flex">
					<view class="label">联系方式</view>
					<input placeholder="请输入联系方式" v-model="technician.phone" />
				</view>
				<view class="item-line flex">
					<view class="label">所在地区</view>
					<input placeholder="请输入所在地区" v-model="technician.city" />
				</view>
				<view class="item-line flex">
					<view class="label">详细地址</view>
					<textarea v-model="technician.detailAddress" placeholder="请输入详细地址" class="textarea"></textarea>
				</view>
			</view>
		</view>

		<view class="b-fiexd">
			<view @click="addOrUpdateMsgTer" class="button-submit">提交</view>
		</view>

	</view>
</template>

<script>
	import OSS from "ali-oss"
	import {
		v4 as uuidv4
	} from 'uuid';
	import {
		showDialog
	} from 'vant';

	export default {
		data() {
			return {
				technician: {
					id: '',
					name: '',
					phone: '',
					username: '',
					city: '',
					phone: '',
					detailAddress : ''
				}
			}
		},
		onShow() {
			this.getTenFans()
		},
		methods: {
			getUserInfo() { //获取用户信息
				this.$api('getUserInfo', {}, res => {
					if (res.code == 200) {
						this.userInfo = res.result;
					}
				})
			},
			addOrUpdateMsgTer() { //新增修改技师入驻信息
				let isOk = this.parameterVerification()
				if (!isOk.auth) {
					return uni.showToast({
						title: isOk.title,
						icon: 'none'
					})
				}
				this.$api('addOrUpdateMsgTer', this.technician, res => {
					if (res.code == 200) {
						showDialog({
							title: this.technician.id ? '修改入驻' : '技师入驻',
							message: this.technician.id ? '技师入驻修改成功' : '技师入驻提交成功',
						}).then(() => {
							uni.switchTab({
								url: '/pages/index/index'
							})
						});
					}
				})
			},
			parameterVerification() { //验证用户参数合法性
				let { name, sex, phone, age, city, image } = this.technician
				if (name.trim() == '') {
					return { title: '请填写技师姓名', auth: false }
				} else if (sex.trim() == '') {
					return { title: '请选择性别', auth: false }
				} else if (phone.trim() == '') {
					return { title: '请填写手机号', auth: false }
				} else if (!age) {
					return { title: '请填写年龄', auth: false }
				} else if (city.trim() == '') {
					return { title: '请填写意向城市', auth: false }
				} else if (image.trim() == '') {
					return { title: '请上传近期照片', auth: false }
				} else if (phone.trim() != '') {
					if (!this.$utils.verificationPhone(phone)) {
						return { title: '手机号格式不合法', auth: false }
					}
				}
				return {
					title: '验证通过',
					auth: true
				}
			},
			getTenFans() { //获取我推荐的技师记录
				this.$api('getTenFans', {}, res => {
					if (res.code == 200) {
						if (res.result.length > 0) {
							let { id, name, sex, age, city, image, phone } = res.result[0];
							this.technician = { id , name, sex, age, city, image, phone }
						}
					}
				})
			}
		}
	}
</script>

<style>
	body {
		background-color: #f5f5f5;
	}

	.banner {
		width: 100vw;
		height: calc(392rpx - 160rpx);
	}


	.banner-font {
		width: 292rpx;
		height: 142rpx;
		font-size: 72rpx;
		line-height: 66rpx;
		font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
		font-weight: 400;
		text-align: left;
		color: #ffffff;
		letter-spacing: -1;
		text-shadow: 0px 6px 6px 0px rgba(0, 165, 141, 0.70);

		position: absolute;
		left: 52rpx;
		top: 34rpx;
	}

	.font-3 {
		height: 28rpx;
		line-height: 28rpx;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: 400;
		text-align: left;
		color: #ffffff;

		text-shadow: 0 4rpx 6rpx 0 rgba(0, 165, 141, 0.70);
		position: absolute;
		left: 52rpx;
		top: 138rpx;
	}

	.banner-button {
		width: 240rpx;
		height: 56rpx;
		line-height: 56rpx;
		background: #ffdb75;
		border-radius: 24rpx;
		box-shadow: 0 6rpx 6rpx 0 rgba(17, 106, 93, 0.23);

		position: absolute;
		left: 52rpx;
		top: 220rpx;

		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC-Bold;
		font-weight: 700;
		text-align: center;
		color: #EF7683;
	}


	.item-card {
		width: calc(710rpx - 40rpx);
		height: 840rpx;
		background: #ffffff;
		border-radius: 16rpx;

		margin: 40rpx auto 20rpx;
		padding: 1rpx 20rpx;
	}

	.serrled-title {
		display: flex;
		align-items: center;
		margin: 20rpx 0rpx;
		font-size: 30rpx;
		font-weight: bold;
	}

	.serrled-title .before {
		content: '';
		width: 8rpx;
		height: 32rpx;
		background: #FAA8B0;
		border-radius: 4rpx;
		margin-right: 10rpx;
	}

	.item-line {
		height: 60rpx;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC-Bold;
		font-weight: 700;
		text-align: left;
		color: #333333;
		margin-top: 40rpx;
	}

	.item-line .label {
		display: flex;
		align-items: center;
		width: 152rpx;
		height: 60rpx;
	}

	.item-line input {
		width: 456rpx;
		height: 60rpx;
		line-height: 60rpx;
		background: #f5f5f5;
		border-radius: 12rpx;

		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC-Medium;
		font-weight: 500;
		text-align: left;
		color: #939393;

		padding: 0 20rpx;
	}
	
	.item-line textarea{
		background: #F5F5F5;
		border-radius: 10rpx;
		padding: 20rpx;
		height: 150rpx;
	}

	.upload {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 200rpx;
		height: 200rpx;
		background: rgba(245, 245, 245, 0.82);
		border: 2rpx dashed #99dcd0;
		border-radius: 16rpx;

		margin: 10rpx 12rpx;
	}

	.upload-img {
		width: calc(100% - 4rpx);
		height: calc(100% - 4rpx);
		border: 2rpx dashed #ccc;
		margin: 2rpx;
	}

	.button-submit {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 596rpx;
		height: 90rpx;
		background: #F7AEB6;
		border-radius: 46rpx;

		margin: 20rpx auto;

		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: 400;
		text-align: center;
		color: #ffffff;
	}
</style>