<template>
	<view class="app">
		<view class="inputs" v-if="show==true">
			<i class="icon"></i>
			<input type="text" name="" id="" class="input" placeholder="请输入医生姓名" v-model="realname">
		</view>
		<view class="list" v-if="doctorlist">
			<view class="item" v-for="item in doctorlist" @tap='emitdata(item)'>
				<image src="../../static/docHead.png" mode=""></image>
				<view class="name">
					{{item.realname?item.realname:''}}
				</view>
				<view class="address">
					{{item.teamName?item.teamName:''}}
				</view>
				<view class="title">
					{{item.teamMemberTypeName?item.teamMemberTypeName:''}}
				</view>
				<view class="zixunbtn" v-if="item.userNo==userNo">
					已选择
				</view>
				<view class="zixunbtn  nobtn" v-else>
					选TA
				</view>
			</view>
		</view>
		<view class="list" v-if="list">
			<view class="item"  @tap='emitdata(item)'>
				<image src="../../static/docHead.png" mode=""></image>
				<view class="name">
					{{list.personName}}
				</view>
				<view class="address">
					{{list.personPhone}}
				</view>
				<!-- <view class="title">
					{{list.personPhone}}
				</view> -->
				<view class="zixunbtn" v-if="list.userNo==userNo">
					已选择
				</view>
				<view class="zixunbtn  nobtn" v-else>
					选TA
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getDoctorList
	} from '@/api/pagesC/choosedoctor/index.js'
	import {
		getDoctorListtwo
	} from '@/api/pagesB/myfamilydoctorteam/index.js'
	export default {
		data() {
			return {
				show:"",
				orgNo: null,
				userNo: null,
				teamNo: null,
				realname: '',
				doctorlist: [],
				doctortotal: 0,
				list:[{
					personPhone:'',
					personName:'',
				}],
				pageNum: 1,
			};
		},
		watch: {
			realname: {
				handler(newval, oldval) {
					this.getDoctorListinfo();
				}
			}
		},
		methods: {
			getDoctorListinfo() {
				if (this.orgNo) {
					getDoctorList(this.pageNum, this.orgNo, this.realname).then(res => {
						this.doctorlist = res.rows
						this.doctortotal = res.total
					})
				} else {
					// getDoctorListtwo(this.pageNum, 10, this.teamNo, this.realname).then(res => {
					// 	this.doctorlist = res.rows
					// 	this.doctortotal = res.total
					// })
				}
			},
			emitdata(item) {
				console.log(this.list,'474')
				if(item){
					uni.$emit('doctordata', {
						data: JSON.stringify(item),
					})
					uni.navigateBack({
						delta: 1
					});
				}else{
					uni.$emit('doctordata', {
						data: JSON.stringify(this.list),
					})
					uni.navigateBack({
						delta: 1
					});
				}

			},
		},
		onLoad(options) {
			console.log(options,'888')
			if(options.static=="1"){
				this.show=true

			}
			if (options.item) {
				this.list = JSON.parse(options.item)
				console.log(this.list, '58')
			}
			if (options.orgNo) {
				this.orgNo = options.orgNo
				this.userNo = options.userNo
				this.getDoctorListinfo();
			} else {
				// this.teamNo = uni.getStorageSync('userinfo').teamNo
				this.teamNo = "00bf7f5a02f3460aa975721ff9f5e533"
			}
		},
		onReachBottom() { //上滑加载
			if (this.doctorlist.length >= this.doctortotal) {} else {
				this.pageNum++;
				if (this.orgNo) {
					getDoctorList(this.pageNum, this.orgNo, this.realname).then(res => {
						res.rows.forEach(e => {
							this.doctorlist.push(e)
						})
						this.doctortotal = res.total
					})
				} else {
					getDoctorListtwo(this.pageNum, 10, this.teamNo, this.realname).then(res => {
						res.rows.forEach(e => {
							this.doctorlist.push(e)
						})
						this.doctortotal = res.total
					})
				}
			}
		},
		onPullDownRefresh() { //下拉刷新
			this.pageNum = 1;
			this.getDoctorListinfo()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
	}
</script>

<style lang="scss">
	@import './choosedoctor.scss';
</style>
