<template>
	<uni-data-picker class="uni_item" placeholder="请选择工单类别" :showSearch= "showSearch" :readonly="readonly" :localdata="dataOrderType" v-model="WorkOrderCategory" @change="changeType"  @nodeclick="nodeclick" @popupclosed="popupclosed"  @searchTrue="searchTrue">
	</uni-data-picker>
</template>

<script>
	import pageData from "@/pages/myTask/repairList/addRepair/pageData.js"
	import {filterTreeDatas} from '@/utils/dataTreating.js'
	export default {
		data() {
			return {
				order: '',
				WorkOrderCategory: '',
				orderList: [],
				identification: '',
				dataOrderType: [],
				autoData:[],
				showSearch:true
			}
		},
		props: {
			orderType: {},
			typeid: {},
			readonly:false
		},
		created() {
			this.getDpartment()
		},
		methods: {
			getDpartment() {
				pageData.getGongDanType(this.typeid,(res, data) => {
					this.orderList = data
					this.dataOrderType = res 
					if(this.orderType) {
						this.getOrder(res, data, this.orderType)
					}
				})
			},
			getOrder(data, tree, id) {
				let newtext = ''
				for (const i in tree) {
					if (tree[i].id == id) {
						this.getTree(data, tree[i].text)
					} else if (tree[i].children) {
						this.getOrder(data, tree[i].children, id)
					}
				}
			
			},
			getTree(tree, text) {
				for (const i in tree) {
					if (tree[i].text == text) {
						this.WorkOrderCategory = tree[i].value
					} else if (tree[i].children) {
						this.getTree(tree[i].children, text)
					}
				}
			},
			changeType(e,f,g){
				const valueData = e.detail.value
				this.WorkOrderCategory = valueData[valueData.length-1].value
			},
			searchTrue(e){
				this.WorkOrderCategory = e.value
			},
			nodeclick(data) {
				// this.WorkOrderCategory = data.value
				this.order = data.value
				this.identification = this.$mHelper.getIdentification(this.orderList,data.value)
				this.$emit('post-select-data',data.value,data.id,data.orderType,this.identification, data.text)
				// this.$http.get("GongDanType/GetModule", {mId:data.value}).then((response) => {
				// 	if (response.state.toLowerCase() === "success") {
				// 		if(response.data.autodept!=''){
				// 			this.autoData = JSON.parse(response.data.autodept)
				//             this.$emit('post-select-data',data.value,data.id,data.orderType,identification, data.text,this.autoData)
				// 		}
				// 	}
				// })
			},
			popupclosed() {}
		}
	}
</script>

<style>

</style>
