<template>
	<view>
		<view v-if="customReturnValue === 'orgCode'">
			<uni-data-picker :openSearch="true" placeholder="请选择单位" popup-title="请选择单位" :localdata="dataList"
				@nodeclick="onNodeClick" @popupclosed="onPopupClosed" v-model="ID"
				:map="{ text: 'title', value: 'orgCode' }"></uni-data-picker>
		</view>
		<view v-else>
			<uni-data-picker :openSearch="true" placeholder="请选择单位" popup-title="请选择单位" :localdata="dataList"
				@nodeclick="onNodeClick" @popupclosed="onPopupClosed" v-model="ID"
				:map="{ text: 'title', value: 'id' }"></uni-data-picker>
		</view>
	</view>
</template>

<script setup>
	import {
		queryDepByCode,
		queryZbDepByLdhth
	} from '@/api/depart.js'
	import {
		useStore
	} from '@/store';

	const store = useStore()

	const props = defineProps([{
			value: {
				type: String,
				default: ''
			},

			customReturnValue: {
				require: true,
				type: String,
				default: 'orgCode'
			}
		}]),
		
		watch(value,(newValue,oldValue)=>{
		  console.log("新值是"+newValue, "旧址是"+oldValue);
		  	this.ID = val;
		}),
		watch(value,(newValue,oldValue)=>{
		  console.log("新值是"+newValue, "旧址是"+oldValue);
		  	this.ID = val;
		}),
		
		 
		data() {
			return {
				reset: true,
				url: {
					list: '/sys/sysDepart/queryTreeList'
				},
				pageNo: 1,
				pageSize: 3000,

				params: {
					pageNo: this.pageNo,
					pageSize: this.pageSize
				},
				dataList: [],
				ID: '',
				bmText: '',
				tempID: '',
				field: ''
			};
		},
		onReady() {
			this.getData();
		},
		mounted() {
			this.getData();
		},
		methods: {
			onNodeClick(e) {
				console.log(JSON.stringify(e));
				console.log(e.orgCode, e.title, e.id, this.customReturnValue);
				this.$nextTick(() => {
					if (this.customReturnValue == 'orgCode') {
						this.tempID = e.orgCode;
					}
					if (this.customReturnValue == 'id') {
						this.tempID = e.id;
					}

					this.bmText = e.title;
				})
			},
			onPopupClosed() {
				this.$nextTick(() => {
					this.ID = this.tempID;
					console.log(this.ID, this.bmText);
					this.$emit('input', this.ID);
					this.$emit('change', this.ID, this.bmText);
				});
			},
			onchange(e) {
				this.$nextTick(() => {
					this.ID = this.tempID;
					console.log(this.ID, this.bmText);
					this.$emit('input', this.ID);
					this.$emit('change', this.ID, e.detail.value);
				})
			},
			getData() {
				// console.log(111)
				let that = this;
				queryDepByCode(store.userinfo.workNo).then((res) => { //获取工作单位
					console.log(res)
					depart.value = res.departName
					orgCode.value = res.orgCode
				})
			}
		}
</script>

<style></style>