<template>
	<view class="admin-jiazheng-page">
		<view class="icon-title-navBar-box">
			<view @click="goUpPage" class="nav-bar-icon"></view>
			<text class="nav-bar-title">家政人员</text>
		</view>
		<v-tabs v-model="current" :tabs="tabs" :scroll="false" @change="changeTab" field="name"
			class="admin-tab-box"></v-tabs>
		<gerenZiliao ref="gerenZiliao" :status='status' @finishDom='finishDom' @editSave="editSaveGerenziliao"
			@goNext="gerenziliaoNext" v-show="current ==0"></gerenZiliao>
		<qiuzhiXinxi ref="qiuzhiXinxi" :status='status' @editSave="editSaveQiuzhixinxi" @goNext="goNextQiuzhixinxi"
			v-show="current ==1">
		</qiuzhiXinxi>
		<zhaopianZiliao ref="zhaopianZiliao" :status='status' @editSave="editSaveZhaopianziliao"
			@goNext="goNextZhaopianZiliao" v-show="current ==2"></zhaopianZiliao>
		<banzhengXinxi ref="banzhengXinxi" :status='status' @addSave="addSave" v-show="current ==3">
		</banzhengXinxi>
		<banzhengXinxiList :list="editInfo.kaozhengList" v-show="banzhengXinxiFlag" @editBanzheng="editBanzheng"
			ref="banzhengXinxiList"></banzhengXinxiList>
	</view>
</template>

<script>
	import {
		ref
	} from "vue";
	import banzhengXinxi from './banzhengXinxi.vue';
	import banzhengXinxiList from './banzhengXinxiList.vue';
	import qiuzhiXinxi from './qiuzhiXinxi.vue';
	import zhaopianZiliao from './zhaopianZiliao.vue';
	import gerenZiliao from './gerenZiliao.vue';
	import {
		getJiazhengInfo
	} from "@/api/jiazheng.js";
	export default {
		data() {
			return {
				current: 0,
				//	tabs: ['个人资料', '求职信息', '照片资料', '办证信息']
				tabs: [],
				allData: {
					"birthday": "",
					"gender": '',
					"hujiDizhi": "",
					"hunyin": '',
					"icon": "",
					"idcard": "",
					"idcardUrl1": "",
					"idcardUrl2": "",
					"idtype": '',
					"jiankangDate": "",
					"jibiexinzi": "",
					"jiguanShengId": '',
					"jiguanShiId": '',
					"jineng": "",
					"jingli": "",
					"jingyan": "",
					"juzhuDizhi": "",
					"kaozhengList": [],
					"leixing": "",
					"minzu": '',
					"qiwangxinzi": "",
					"realName": "",
					"shenghuoUrls": "",
					"shuxiang": '',
					"tijianDate": "",
					"tijianUrl": "",
					"userId": '',
					"userName": "",
					"xingzuo": '',
					"xingzuoFlag": false,
					"xueli": '',
					"zhengshuUrls": "",
					"zhuangtai": ''
				},
				status: '',
				id: '',
				userId: '',
				banzhengXinxiFlag: false,
				editInfo: {}
			}
		},
		components: {
			banzhengXinxi,
			banzhengXinxiList,
			qiuzhiXinxi,
			gerenZiliao,
			zhaopianZiliao,
		},
		onLoad(options) {
			let pageInfo = JSON.parse(options.pageInfo)
			this.status = pageInfo.status
			this.dataHandle(pageInfo)
		},
		methods: {
			dataHandle(pageInfo) {
				if (this.status == 'add') {
					this.tabs = [{
							id: 1,
							name: '个人资料',
							disabled: false
						},
						{
							id: 2,
							name: '求职信息',
							disabled: true
						},
						{
							id: 3,
							name: '照片资料',
							disabled: true
						},
						{
							id: 4,
							name: '办证信息',
							disabled: true
						},
					]
				} else {
					this.id = pageInfo.id
					this.userId = pageInfo.userId
					this.tabs = [{
							id: 1,
							name: '个人资料',
							disabled: false
						},
						{
							id: 2,
							name: '求职信息',
							disabled: false
						},
						{
							id: 3,
							name: '照片资料',
							disabled: false
						},
						{
							id: 4,
							name: '办证信息',
							disabled: false
						},
					]

				}
			},
			finishDom() {
				let req = {
					id: this.id,
					userId: this.userId
				}
				getJiazhengInfo(req).then(res => {
					if (res.code == 0) {
						this.$refs.gerenZiliao.editinfo(res.data)
						this.editInfo = res.data
					} else {
						uni.showToast({
							icon: 'none',
							title: '获取详情失败'
						})
						return false
					}
				})
			},
			changeTab(data) {
				console.log('data', data);
				if (this.status == 'edit' && data == 3 && this.editInfo.kaozhengList.length > 0) {
					this.banzhengXinxiFlag = true
					return false
				}
				this.current = data
				if (this.status != 'edit') {
					return false
				}
				switch (Number(data)) {
					case 0:
						this.$refs.gerenZiliao.editinfo(this.editInfo)
						break;
					case 1:
						this.$refs.qiuzhiXinxi.editinfo(this.editInfo)
						break;
					case 2:
						this.$refs.zhaopianZiliao.editinfo(this.editInfo)
						break;
					case 3:
						this.$refs.banzhengXinxi.editinfo(this.editInfo)
						break;
					default:
						break;
				}


			},
			gerenZiliaoDataHandle(data) {
				this.allData.userName = data.userName
				this.allData.realName = data.realName
				this.allData.idcard = data.idcard
				this.allData.idtype = data.idtype
				this.allData.jiguanShengId = data.jiguanObj.jiguanShengId
				this.allData.jiguanShiId = data.jiguanObj.jiguanShiId
				this.allData.juzhuDizhi = data.juzhuDizhi
				this.allData.birthday = data.birthday
				this.allData.minzu = data.minzu.id
				this.allData.gender = data.gender
				this.allData.xueli = data.xueli.id
				this.allData.hunyin = data.hunyin.id
				this.allData.hujiDizhi = data.hujiDizhi
				this.allData.xingzuo = data.xingzuo.id
				this.allData.shuxiang = data.shuxiang.id
				this.allData.xingzuoFlag = data.xingzuoFlag
			},
			gerenziliaoNext(data, num) {
				this.gerenZiliaoDataHandle(data)
				this.current = num + 1
				this.tabs = this.tabs.map((item, i) => {
					if (i == this.current) item.disabled = false
					return item
				})
			},
			editSaveGerenziliao(data) {
				this.gerenZiliaoDataHandle(data)
			},
			qiuzhiXinxiDataHandle(data) {
				this.allData.leixing = data.leixing
				this.allData.jingyan = data.jingyan
				this.allData.jineng = data.jineng
				this.allData.zhuangtai = data.zhuangtai
				this.allData.jibiexinzi = data.jibiexinzi
				this.allData.qiwangxinzi = data.qiwangxinzi
				this.allData.jingli = data.jingli
			},
			goNextQiuzhixinxi(data, num) {
				this.qiuzhiXinxiDataHandle(data)
				this.current = num + 1
				this.tabs = this.tabs.map((item, i) => {
					if (i == this.current) item.disabled = false
					return item
				})
			},
			editSaveQiuzhixinxi(data) {
				this.qiuzhiXinxiDataHandle(data)
			},

			goNextZhaopianZiliao(data, num) {
				this.zhaopianziliaoDataHandle(data)
				this.current = num + 1
				this.tabs = this.tabs.map((item, i) => {
					if (i == this.current) item.disabled = false
					return item
				})
			},
			zhaopianziliaoDataHandle(data) {
				this.allData.icon = data.icon
				this.allData.idcardUrl1 = data.idcardUrl1
				this.allData.idcardUrl2 = data.idcardUrl2
				this.allData.shenghuoUrls = data.shenghuoUrls
				this.allData.zhengshuUrls = data.zhengshuUrls
				this.allData.tijianDate = data.tijianDate
				this.allData.jiankangDate = data.jiankangDate
				this.allData.tijianUrl = data.tijianUrl
			},
			editSaveZhaopianziliao(data) {
				this.zhaopianziliaoDataHandle(data)
			},
			addSave(data) {
				this.allData.kaozhengList.push(data)
				this.submitJiazheng()
			},
			submitJiazheng() {
				console.log('this.allData', this.allData);
			},
			editBanzheng(data, index) {
				this.current = 3
				this.banzhengXinxiFlag = false
				this.$refs.banzhengXinxi.editinfo(data, index)


			},
			goUpPage() {
				uni.navigateTo({
					url: `/pages/admin/Jiazheng/index`
				})
			}

		}
	}
</script>