<template>
	<view>
		<!-- <uni-data-picker placeholder="请选择单位" popup-title="请选择单位" collection="ngTools_depart"
			field="_id as value, depart_name as text" orderby="value asc" :step-searh="true" self-field="_id"
			parent-field="parent_id" @change="onchange" @nodeclick="onnodeclick">
		</uni-data-picker> -->
		<!-- <uni-easyinput @focus="open" v-model="selectText" placeholder="选择用户"></uni-easyinput> -->
		<uni-data-picker placeholder="请选择用户" popup-title="请选择用户" :localdata="userData" v-model="userID"
			@change="onchange" :map="{text : 'username', value:'_id'}">
		</uni-data-picker>

		<!-- <next-tree ref="nextTreeRef" funcMode="radio" uiMode="popup" :selectParent="true" labelKey="username"
			valueKey="_id" :multiple="false" :treeData="userData" @confirm="onnodeclick" @change="onchange">
		</next-tree> -->


	</view>
</template>
<script>
	const db = uniCloud.database()
	import {
		getJsonTree,
		groupBy
	} from "@/js_sdk/util/jsonData";
	import {
		saveDepartStore,
		saveDictItemStore,
		getDictItemStore,
		getDepartStore
	} from '@/js_sdk/util/dictTools.js';
	export default {
		data() {
			return {
				collectionList: "uni-id-users",
				userData: [],
				selectText: "",
				userID: "",

			}
		},
		props: {
			value: {
				type: String,
				default: ""
			},
		},
		watch: {
			value: {
				immediate: true,
				deep: true,
				handler(val) {
					console.log(val)
					this.userID = val

				}
			}
		},
		mounted() {
			this.userData = this.getUser()
		},
		onShow() {

		},
		methods: {
			open() {
				// this.departTreeData = getDepartStore();
				setTimeout(() => {
					this.$refs.nextTreeRef.showTree = true;
				}, 500)

			},
			onchange(e) {
				console.log(e)
				this.$emit('input', e.detail.value[0].value)
			},

			getUser() {
				db.collection('uni-id-users').field(
						"_id,username,mobile,status"
					).orderBy('username')
					.get().then((res) => {
						console.log(res.result.data)
						if (res.result.data) {
							this.userData = res.result.data;

						}
					}).catch((err) => {
						uni.showModal({
							content: err.message || '请求服务失败',
							showCancel: false
						})

					}).finally(() => {

						uni.hideLoading()
					})

			}

		}
	}
</script>