<template>
	<view class="app">
		<view class="items">
			<view class="item"
				:style="disease.find(e => e.id == item.id)?'background-color: #4C7BC9;color: #ffffff;':''"
				v-for='(item,index) in diseaselist' :key="index" @tap='choicedisease(item)'>
				{{item.diseaseName}}
			</view>
			<view class="other">
				<span>其他:</span>
				<u-input type="text" placeholder='请填写' />
			</view>
			<view class="btn" @tap='goinformation'>
				提交
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getDiseaseInfo
	} from '@/api/disease/index.js'
	export default {
		data() {
			return {
				diseaselist: [], //疾病列表
				disease: [],
			};
		},
		methods: {
			//选择疾病
			choicedisease(item) {
				if (this.disease.findIndex(e => e.id == item.id) == -1) {
					this.disease.push(item)
				} else {
					this.disease = this.disease.filter(e => e.id != item.id)
				}
				if (this.disease.length > 1) {
					this.disease = this.disease.filter(e => e.id != 9999)
				}
			},
			//获取疾病列表
			diseaseinfo() {
				getDiseaseInfo().then(res => {
					this.diseaselist = res.data;
					// this.diseaselist.unshift({
					// 	id: 9999,
					// 	diseaseName: '无'
					// })
				})
			},
			//跳转回信息完善页面
			goinformation() {
				uni.$emit('disease', {
					disease: JSON.stringify(this.disease)
				})
				uni.navigateBack({
					delta: 1
				});
			}
		},
		onLoad(options) { //开局方法和传参接受
			this.diseaseinfo()
			//传参相等
			this.disease = JSON.parse(options.diseaseInfoList)
			console.log(JSON.parse(options.diseaseInfoList))
		},
	}
</script>

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