<template>
	<view class="u-page">
		<view class="u-demo-block">
			<view class="u-demo-block__content">
				<u--form labelPosition="left" :model="form" ref="form">
					<u-form-item label="姓名" prop="userName" labelWidth="80" borderBottom>
						<view class="content">
							<u--input placeholder="姓名" v-model="form.userName" count></u--input>
						</view>
					</u-form-item>
					<u-form-item label="手机号" prop="phone" labelWidth="80" borderBottom>
						<view class="content">
							<u--input placeholder="手机号" v-model="form.phone" count></u--input>
						</view>
					</u-form-item>
					<u-form-item label="省市区" prop="provinces" labelWidth="80" borderBottom>
						<view class="content">
							<pickerAddress @change="change">
								<view v-if="form.provinces">
									{{form.provinces}}
								</view>
								<view v-else style="color: #c4c4c4;">
									选择地址
								</view>
							</pickerAddress>
						</view>
					</u-form-item>
					<u-form-item label="详细地址" prop="detailedAddress" labelWidth="80" borderBottom>
						<u--textarea v-model="form.detailedAddress"></u--textarea>
					</u-form-item>
				</u--form>
				<u-button :disabled="isDisabled" color="rgb(55,186,189)" text="提交" shape="circle" size="large"
					@click="submit" customStyle="margin-top: 50px">
				</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import pickerAddress from '../address/pickerAddress.vue'
	export default {
		components: {
			pickerAddress
		},
		data() {
			return {
				isDisabled: false,
				form: {
					userCode: uni.getStorageSync("setUserName"),
					userName: '',
					phone: '',
					detailedAddress: '',
					provinces: ''
				}
			}
		},
		onLoad() {},
		onShow() {
			if (uni.getStorageSync("addressData")) {
				this.form = uni.getStorageSync("addressData")
			}
		},
		methods: {
			change(data) {
				this.form.provinces = data.data.join('')
			},
			async submit() {
				if (!this.form.userName) {
					this.$showModal('请输入姓名')
					 return
				}
				if (!this.form.phone) {
					this.$showModal('请输入手机号') 
					return
				}
				if (!this.form.provinces) {

					this.$showModal('选择省市区')
					 return
				}
				if (!this.form.detailedAddress) {

					this.$showModal('请输入详细地址')
					 return
				}
				const {
					data: res
				} = await this.$httpRequest({
					url: '/app/saveAds',
					method: 'post',
					urlType: 2,
					data: this.form
				});
				if (res.code === 200) {
					uni.showModal({
						content: "保存成功",
						showCancel: false,
						success() {
							uni.navigateBack()
						}
					})
				} else {
					uni.showToast({
						duration: 2500,
						title: res.msg,
						icon: 'error',
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
