<template>
	<view class="content">
		<view class="top">
			<view class="left">
				用户名：
				<!-- <image src="../../static/logo.png" mode="widthFix" class="head-img"></image> -->
			</view>
			<view class="right">
				<view class="">
					{{userInfo.username}}
				</view>
				<!-- <view class="">
					2022-12-2到期
				</view> -->
			</view>
		</view>
		<jobSelect ref="jobSelect" :listData="listData" @confirem="confiremJob" :typeOneData='typeOneData'
			:typeTwoData='typeTwoData'></jobSelect>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import jobSelect from '@/components/yunmiao-jobSelect/yunmiao-jobSelect.vue'
	export default {
		components: {
			jobSelect
		},
		computed: {
			...mapState(['hasLogin'])
		},
		onShow() {
			if (this.hasLogin || uni.getStorageSync("userInfo").username) {
				this.userInfo = uni.getStorageSync("userInfo")
			} else {
				uni.navigateTo({
					url: "/pages/login/login"
				})
				// uni.({
				// 	url: '/pages/index/index'
				// })
			}
		},
		data() {
			return {
				typeOneData: [],
				typeTwoData: [],
				userInfo: {},
				listData: [{
					"id": 1,
					"name": "餐饮",
					"children": [{
							"id": 2,
							"name": "服务员",
						}, {
							"id": 3,
							"name": "送餐员",
						}, {
							"id": 4,
							"name": "传菜员",
						},
						{
							"id": 5,
							"name": "厨师",
						}
					]
				}, {
					"id": 6,
					"name": "家政保洁",
					"children": [{
						"id": 7,
						"name": "保洁",
					}, {
						"id": 8,
						"name": "保姆",
					}, {
						"id": 9,
						"name": "月嫂",
					}]
				}, {
					"id": 10,
					"name": "美容美发",
					"children": [{
						"id": 11,
						"name": "发型师",
					}]
				}],
				title: ''
			}
		},
		onLoad() {
			uni.showLoading({
				title: '数据加载中'
			})
			this.$request.baseRequest('admin.gubi.gubiTypeInfo', 'list', {
					page: 1,
					limit: 1000
				},
				failres => {
					console.log('res+++++', failres.errmsg)
					this.$refs.uToast.show({
						type: 'error',
						message: failres.errmsg,
					})
					uni.hideLoading()
				}).then(res => {
				// if (res.errno == 200) {
				uni.hideLoading()
				console.log(11)
				console.log(res.data.items)
				this.typeOneData = res.data.items
				this.$request.baseRequest('admin.gubi.gubiTypeSecond', 'list', {
						page: 1,
						limit: 1000,
						typeId: this.typeOneData[0].id
					},
					failres => {
						console.log('res+++++', failres.errmsg)
						this.$refs.uToast.show({
							type: 'error',
							message: failres.errmsg,
						})
						uni.hideLoading()
					}).then(res => {
					// if (res.errno == 200) {
					uni.hideLoading()
					console.log(11)
					console.log(res.data.items)
					this.typeTwoData = res.data.items
					// this.makeData(res.data)
					// }

				})
				// this.makeData(res.data)
				// }

			})
			// this.$request.baseRequest('admin.gubi.gubiTypeInfo', 'listInfo', failres => {
			// 	console.log('res+++++', failres.errmsg)
			// 	this.$refs.uToast.show({
			// 		type: 'error',
			// 		message: failres.errmsg,
			// 	})
			// 	uni.hideLoading()
			// }).then(res => {
			// 	// if (res.errno == 200) {
			// 	uni.hideLoading()
			// 	console.log(11)
			// 	console.log(res.data)

			// 	this.makeData(res.data)
			// 	// }

			// })
			// this.$refs.jobSelect.show()
		},
		methods: {
			makeData(val) {
				console.log(val)
				for (let i = 0; i < val.length; i++) {
					if (val[i].children) {
						for (let j = 0; j < val[i].children.length; j++) {
							let _obj = val[i].children[j]
							_obj.typeName = val[i].children[j].secondName
							val[i].children[j] = _obj
							if (val[i].children[j].children) {
								for (let k = 0; k < val[i].children[j].children.length; k++) {
									let _obj1 = val[i].children[j].children[k]
									_obj1.typeName = val[i].children[j].children[k].typeId
									val[i].children[j].children[k] = _obj1
								}
							}
						}
					}
				}
				this.listData = val
				// console.log(this.data)
			},
			// show() {
			// 	this.$refs.jobSelect.show()
			// },
			confiremJob(e) {
				console.log("e", e)
				uni.setStorageSync('selectInfo', e)
				uni.navigateTo({
					url: "/pages/index/price"
				})
			}
		}
	}
</script>

<style>
	.content {}

	.top {
		display: flex;
		background: #ececec;
		padding: 20rpx;
		position: fixed;
		z-index: 999;
		width: 100%;

	}


	.head-img {
		width: 100rpx;
	}
</style>
