<template>
	<view>
		<z-text style="min-width: 300rpx;" arrow v-model="dicName" :placeholder="placeholder" @click="visible=true"></z-text>
		<z-select-popup :visible.sync="visible">
			<view v-for="(item,index) in list" :key="index" @click="changeData(item)" v-if="item.dicCode!='01'">
				<view>{{item.dicName}}</view>
				<view class="line" v-if="index!=(list.length-1)"></view>
			</view>
		</z-select-popup>
	</view>
</template>

<script>
	export default{
		props:{
			placeholder:String,
			value: String,
		},
		model: {
			prop: 'value',
		},
		data(){
			return{
				dicName:'',
				visible:false,
				list:[]
			}
		},
		watch: {
			value(newval, oldval) {
				// var code = this.type == 'object' ? newval.dicCode : newval;
				console.log('yx',newval)
				var list = this.list.filter((item) => item.dicCode == newval);
				//数据不存在时
				if (list.length == 0) {
					this.$store.state.dicChange = true;
					this.getData();
				}else{
					this.changeData(list[0]);
				}
			}
		},
		mounted() {
			this.getData();
		},
		methods:{
			getData(){
				uni.getStorage({
					key:'dic',
					success: (res) => {
						this.list=res.data.followState;
							var list = this.list.filter((item) => item.dicCode == this.value);
							if(list.length>0){
								this.changeData(list[0]);
							}
					},fail: (err) => {
						this.$store.state.dicChange = true;
						this.getData();
					}
				})
				// this.$axios.post('app/dic/followStateCode', {
				// 	"parentId": "1001",
				// 	 "dicType": " follow_state"
				// }).then(res => {
				// 	console.log(res)
				// 	this.list = res.data.list;
				// 	var list = this.list.filter((item) => item.dicCode == this.value);
				// 	if(list.length>0){
				// 		this.changeData(list[0]);
				// 	}
				// }).catch(err => {
				// 	console.log(res)
				// })
			},
			changeData(data){
				this.dicName=data.dicName;
				this.$emit('input',data.dicCode);
				this.$emit('change',data);
				this.visible=false;
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>
