<template>
	<view class="content">
		<view class="head">
			<!-- <u-avatar src="/static/head.jpg"></u-avatar> -->
		</view>
		<!-- <uni-transition ref="ani" custom-class="transition" mode-class="fade"  :duration="5000" :show="show"><text class="text">示例元素</text></uni-transition> -->
		<form-step :fromdata="data" v-if="num==1" :fshow="fshow" :num="num" @next="next"></form-step>
		<form-step :fromdata="data" v-if="num==2" :fshow="fshow" :num="num" @next="next"></form-step>
		<form-step :fromdata="data" v-if="num==3" :fshow="fshow" :num="num" @next="next"></form-step>
		<form-step :fromdata="data" v-if="num==4" :fshow="fshow" :num="num" @next="next"></form-step>
		<form-step :fromdata="data" v-if="num==5" :fshow="fshow" :num="num" @next="next"></form-step>
		<form-step :fromdata="data" v-if="num==6" :fshow="fshow" :num="num" @next="next" @res="res"></form-step>
	</view>
</template>

<script>
	import classifyData from '@/common/data.js'
	import dataVersion from '@/common/dataVersion.js'
	export default {
		data() {
			return {
				sdata: {},
				data: classifyData,
				num: 1,
				title: 'Hello',
				fshow: false,
			}
		},
		onLoad(e) {
			// 判断 数据版本
			if (uni.getStorageSync("data_version") == '') {
				uni.setStorageSync("data_version", dataVersion)
			} else {
				if (uni.getStorageSync("data_version") != dataVersion) {
					console.log("数据版本不一致：", dataVersion)
					// 数据版本不一致，移除之前缓存数据
					uni.setStorageSync("data_version", dataVersion)
					uni.removeStorageSync("data")
				} else {
					console.log("数据版本相同：", uni.getStorageSync("data_version"))
				}
			}
			//uni.removeStorageSync("data")
			uni.setStorageSync("tempdata", this.data)
			if (uni.getStorageSync("data").length > 0) {
				this.data = uni.getStorageSync("data")
			}
			if (e.clear == 1) {
				this.next(0);
			}
		},
		methods: {
			res(data, indexnum) {
				this.data[indexnum - 1] = data
				uni.setStorageSync("data", this.data)
				// 基本用法，注意：post的第三个参数才为配置项
				uni.$u.http.post('/diacrisis/add', this.data).then(res => {
					this.jump("/pages/res/res?id=" + res)
				}).catch(err => {})
			},
			next(e, data, indexnum) {
				if (e == 0) {
					//重写
					uni.removeStorageSync("data")
					this.num = 1;
					this.data = uni.getStorageSync("tempdata")
					// uni.reLaunch({
					//     url: '/pages/index/index'
					// });
					return
				}
				if (e == 999) {
					this.num = 1;
					return
				}
				if (this.num > e) {
					this.fshow = true
				} else {
					this.fshow = false
				}
				this.num = e
				this.data[indexnum - 1] = data
				uni.setStorageSync("data", this.data)
			}
		}
	}
</script>

<style>
	@import url("index.css");
</style>
