<template>
	<mobile-frame>
		<view class="info">
			<view class="one">
				<uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
					<uni-forms-item label="维护快递单号" name="customer_transport_no">
						<uni-easyinput type="text" v-model="form.customer_transport_no" placeholder="请输入快递单号" />
					</uni-forms-item>
				</uni-forms>
				<view class="btn">
					<button type="primary" @click="onSubmit('form')" size="small">提交</button>
				</view>
			</view>
		</view>
	</mobile-frame>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				form: {},
				rules: {
					customer_transport_no: {
						rules: [{
							required: true,
							errorMessage: '请输入快递单号',
						}]
					}
				},
			};
		},
		onLoad: function(e) {
			const that = this;
			that.$set(that, `id`, e.id || '');
			that.watchLogin();
		},
		onShow: function() {},
		methods: {
			// 提交保存
			async onSubmit(ref) {
				const that = this;
				that.$refs[ref].validate().then(async params => {
					let form = that.form;
					form.customer_transport_no = params.customer_transport_no;
					const arr = await that.$api(`/afterSale/${that.id}`, 'POST', form);
					if (arr.errcode == '0') {
						uni.showToast({
							title: `维护信息成功`,
							icon: 'success',
						});
						uni.navigateBack({
							detail: 1
						})
					} else {
						uni.showToast({
							title: arr.errmsg,
							icon: 'none',
						})
					}
				})
			},
			watchLogin() {
				const that = this;
				uni.getStorage({
					key: 'token',
					success: async (res) => {},
					fail: (err) => {
						uni.navigateTo({
							url: `/pages/login/index`
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.info {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;

		.one {
			padding: 2vw;

			.uni-input {
				border: #f1f1ff 1px solid;
				padding: 2vw 2vw;
				border-radius: 1vw;
			}

			.btn {
				text-align: center;

				button {
					margin: 0 2vw 2vw 2vw;
					background-color: var(--ff0Color);
					color: var(--fffColor);
				}

				.name {
					color: var(--f85Color);
					font-size: var(--font14Size);
				}
			}
		}
	}

	.uni-forms-item {
		margin-bottom: 6vw !important;
		display: flex;
		flex-direction: row;
	}
</style>
