<template>
    <div class="p-3 grow cont-box">
        <div class="p-3 h-full cont-inner">
            <div class="flex justify-between collapse-head mt-2">
                <span class="text-16 font-semibold">全部内容</span>
                <span @click="toggleAll">
                    <span v-if="!collapseAll">展开全部</span>
                    <span v-else>收起全部</span>
                    <span :class="['ml-2 icon-down', { 'icon-down-expanded': collapseAll }]">
                        <doc-icon type="doc-down" />
                    </span>
                </span>
            </div>

            <van-collapse :model-value="activeCollapse" ref="collapse" class="doc-collapse" @change="collapseChange">
                <van-collapse-item key="1" title="居民信息" name="1">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div v-for="item in columnsBase" :key="item.key">
                            <div class="flex justify-between py-1 border-bottom item">
                                <span class="shrink-0 mr-2 label">{{ item.title }}</span>
                                <span v-if="item.key === 'idCard'">{{ $idCardHide(residentInfo.idCard) || '-' }}</span>
                                <span class="text-end" v-else>
                                    <span>{{ residentInfo[item.key] || '-' }}</span>
                                    <span v-if="item.unit" class="ml-1">{{ item.unit }}</span>
                                </span>
                            </div>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="2" title="随访方式" name="2">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">随访方式</span>
                            <span class="text-end">
                                {{ visitInfo.visitWayName || '-' }}
                            </span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="3" title="症状" name="3">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">症状</span>
                            <span class="text-end">
                                {{ visitInfo.symptomName || '-' }}
                            </span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="4" title="体征" name="4">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div v-for="item in columnsPhysical" :key="item.key">
                            <div class="flex justify-between py-1 border-bottom item">
                                <span class="shrink-0 mr-2 label">{{ item.title }}</span>
                                <span class="text-end">
                                    <span>{{ visitInfo[item.key] || '-' }}</span>
                                    <span v-if="item.unit" class="ml-1">{{ item.unit }}</span>
                                </span>
                            </div>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="5" title="生活方式指导" name="5">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div style="color: #262626">吸烟</div>
                    <div class="gray-box mt-2">
                        <div>
                            <span>是否正在吸烟：</span>
                            <span>{{ visitInfo.isSmokingName }}</span>
                        </div>
                        <div v-if="visitInfo.isSmoking === 1">
                            <span>您大约从几岁起开始养成每天或基本每天都吸烟的习惯：</span>
                            <span>{{ visitInfo.startSmokeAge || '-' }}岁</span>
                        </div>
                        <div v-if="visitInfo.isSmoking === 1 || visitInfo.isSmoking === 2">
                            <span>您最近7天是否吸烟：</span>
                            <span>{{ visitInfo.lastSevenSmokeName }}</span>
                        </div>
                        <div v-if="visitInfo.isSmoking === 1 || visitInfo.isSmoking === 2">
                            <span>日吸烟量：</span>
                            <span>{{ visitInfo.daySmoking || '-' }}支</span>
                            <!-- <span class="ml-4">目标日吸烟量：</span>
                            <span>{{ visitInfo.goalDaySmoking || '-' }}支</span> -->
                        </div>
                        <div v-if="visitInfo.isSmoking === 1 || visitInfo.isSmoking === 2">
                            <span>目标日吸烟量：</span>
                            <span>{{ visitInfo.goalDaySmoking || '-' }}支</span>
                        </div>
                    </div>
                    <div style="color: #262626" class="mt-2">饮酒</div>
                    <div class="gray-box mt-2">
                        <div>
                            <span>是否正在饮酒：</span>
                            <span>{{ visitInfo.isDrinkName }}</span>
                        </div>
                        <div v-if="visitInfo.isDrink === 1 || visitInfo.isDrink === 2">
                            <span>日饮酒量：</span>
                            <span>{{ visitInfo.dayDrink || '-' }}ml</span>
                            <span class="ml-4">目标日饮酒量：</span>
                            <span>{{ visitInfo.goalDayDrink || '-' }}ml</span>
                        </div>
                        <div v-if="visitInfo.isDrink === 1 || visitInfo.isDrink === 2">
                            <span>白酒：</span>
                            <span>{{ visitInfo.drinkLiquor || '-' }}ml/日</span>
                            <span class="ml-2">啤酒：</span>
                            <span>{{ visitInfo.drinkBeer || '-' }}ml/日</span>
                            <span class="ml-2">红酒：</span>
                            <span>{{ visitInfo.drinkRed || '-' }}ml/日</span>
                            
                        </div>
                        <div v-if="visitInfo.isDrink === 1 || visitInfo.isDrink === 2">
                            <span>黄酒：</span>
                            <span>{{ visitInfo.drinkYellow || '-' }}ml/日</span>
                            <span class="ml-2">其他：</span>
                            <span>{{ visitInfo.drinkOther || '-' }}ml/日</span>
                        </div>
                    </div>
                    <div style="color: #262626" class="mt-2">运动</div>
                    <div class="gray-box mt-2">
                        <div>
                            <span>有无规律活动：</span>
                            <span>{{ visitInfo.regularExerciseName }}</span>
                        </div>
                        <div v-if="visitInfo.regularExercise === 1">
                            <span>运动强度：</span>
                            <span>{{ visitInfo.exerciseStrengthName }}</span>
                        </div>
                        <div>
                            <span>目前运动情况：</span>
                            <span>{{ visitInfo.nowExerciseWeek || '-' }}次/周、</span>
                            <span>{{ visitInfo.nowExerciseMinute || '-' }}分钟/次</span>
                        </div>
                        <div>
                            <span>目标运动情况：</span>
                            <span>{{ visitInfo.targetExerciseWeek || '-' }}次/周、</span>
                            <span>{{ visitInfo.targetExerciseMinute || '-' }}分钟/次</span>
                        </div>
                    </div>
                    <div class="list mt-2">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">主食</span>
                            <span class="text-end">{{ visitInfo.staplFood || '-' }} 克/天</span>
                        </div>
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">目标主食</span>
                            <span class="text-end">{{ visitInfo.targetStaplFood || '-' }} 克/天</span>
                        </div>
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">心理调整</span>
                            <span class="text-end">{{ visitInfo.psychologicalRecoveryName || '-' }}</span>
                        </div>
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">遵医行为</span>
                            <span class="text-end">{{ visitInfo.doctorAdviceName || '-' }}</span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="6" title="辅助检查" name="6">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                </van-collapse-item>
                <van-collapse-item key="7" title="服药依从性" name="7">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">服药依从性</span>
                            <span class="text-end">{{ visitInfo.medicationComplianceName }}</span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="8" title="药物不良反应" name="8">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">药物不良反应</span>
                            <span class="text-end">{{ visitInfo.drugsAdverseName }}</span>
                        </div>
                        <div v-if="visitInfo.drugsAdverse === 1" class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">不良反应</span>
                            <span class="text-end">{{ visitInfo.drugsAdverseOther || '-' }}</span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="9" title="低血糖反应" name="9">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">低血糖反应</span>
                            <span class="text-end">{{ visitInfo.glycopeniaReactionName }}</span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="10" title="此次随访分类" name="10">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">此次随访分类</span>
                            <span class="text-end">{{ visitInfo.visitTypeName }}</span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="11" title="目前诊断" name="11">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">目前诊断</span>
                            <span class="text-end">{{ visitInfo.currentDiagnosisName }}</span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="12" title="用药情况" name="12">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                </van-collapse-item>
                <van-collapse-item key="13" title="转诊" name="13">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">转诊</span>
                            <span class="text-end">{{ visitInfo.isReferralName }}</span>
                        </div>
                        <div v-if="visitInfo.isReferral === 1" class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">转诊原因</span>
                            <span class="text-end">{{ visitInfo.referralReason }}</span>
                        </div>
                        <div v-if="visitInfo.isReferral === 1" class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">转诊机构</span>
                            <span class="text-end">{{ visitInfo.referralUnitName }}</span>
                        </div>
                        <div v-if="visitInfo.isReferral === 1" class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">转诊科室</span>
                            <span class="text-end">{{ visitInfo.referralOfficeName }}</span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="14" title="现场随访照片" name="14">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <ImagePreview :img-list="visitInfo.visitImageList"></ImagePreview>
                </van-collapse-item>
                <van-collapse-item key="15" title="下次随访日期" name="15">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div class="flex justify-between py-1 border-bottom item">
                            <span class="shrink-0 mr-2 label">下次随访日期</span>
                            <span class="text-end">{{ visitInfo.nextVisitDate }}</span>
                        </div>
                    </div>
                </van-collapse-item>
                <van-collapse-item key="16" title="随访机构" name="16">
                    <template #right-icon>
                        <doc-icon type="doc-down" />
                    </template>
                    <div class="list">
                        <div v-for="item in columnsOrg" :key="item.key">
                            <div class="flex justify-between py-1 border-bottom item">
                                <span class="shrink-0 mr-2 label">{{ item.title }}</span>
                                <span class="text-end">{{ visitInfo[item.key] }}</span>
                            </div>
                        </div>
                    </div>
                </van-collapse-item>
            </van-collapse>
        </div>
    </div>
</template>
<script>
import ImagePreview from '@/doctor/components/imagePreview/imagePreview.vue'
export default {
    components: { ImagePreview },
    props: {
        visitInfo: {
            type: Object,
            default: () => {}
        }
    },
    data() {
        return {
            collapseAll: false,
            activeCollapse: [],
            columnsBase: [
                { title: '姓名', key: 'residentName' },
                { title: '证件号码', key: 'idCard' },
                { title: '性别', key: 'genderName' },
                { title: '出生日期', key: 'dataBirth' },
                { title: '年龄', key: 'currentAge' },
                { title: '民族', key: 'nationalName' },
                { title: '本人电话', key: 'telephone' },
                { title: '现住址', key: 'presentCodeName' },
                { title: '详细地址', key: 'nowAddress' },
                { title: '户籍地址', key: 'registeredCodeName' },
                { title: '详细地址', key: 'permanentAddress' }
            ],
            columnsPhysical: [
                { title: '收缩压SBP', key: 'signSystolicPressure', unit: 'mmHg' },
                { title: '舒张压DBP', key: 'signDiastolicPressure', unit: 'mmHg' },
                { title: '身高', key: 'signHeight', unit: 'cm' },
                { title: '体重', key: 'signWeight', unit: 'kg' },
                { title: 'BMI', key: 'signBmi', unit: 'kg/m²' },
                { title: '腰围', key: 'signWaistline', unit: 'cm' },
                // { title: '心率', key: 'signHeartRate', unit: '次/分' },
                { title: '足背动脉搏动', key: 'signArteryPulsationName' },
                { title: '其他', key: 'signOther' }
            ],
            columnsOrg: [
                { title: '随访日期', key: 'visitDate' },
                { title: '随访单位', key: 'visitUnitName' },
                { title: '随访科室', key: 'visitOfficeName' },
                { title: '随访医生', key: 'visitDoctorName' }
            ]
        }
    },
    computed: {
        residentInfo() {
            return this.visitInfo.residentsRecord || {}
        }
    },
    methods: {
        // 全部展开、收起
        toggleAll() {
            if (this.collapseAll) {
                this.activeCollapse = []
            } else {
                let list = []
                for (let i = 1; i < 17; i++) {
                    list.push(i.toString())
                }
                this.activeCollapse = list
            }
            this.collapseAll = !this.collapseAll
        },
        // 折叠面板切换
        collapseChange(val) {
            console.log(val)
            if (val && val.length <= 2) {
                this.activeCollapse = val.slice(val.length - 1)
            } else {
                if (this.activeCollapse.length > val.length) {
                    this.activeCollapse = val
                }
                if (this.activeCollapse.length < val.length) {
                    this.activeCollapse = val.slice(val.length - 1)
                }
            }
            if (val.length === 16) {
                this.collapseAll = true
            } else {
                this.collapseAll = false
            }
        }
    }
}
</script>
<style lang="less" scoped>
@import url('@/doctor/utils/common.less');

.cont-box {
    background-color: #f9f9f9;
    .cont-inner {
        background: linear-gradient(to bottom, #F0F6FF, #fff .6rem);
        border-top-left-radius: .08rem;
        border-top-right-radius: .08rem;
    }
}
.collapse-head {
    .icon-down {
        vertical-align: middle;
        font-size: .12rem;

        .svg-icon {
            transition: all .2s;
        }
    }

    .icon-down-expanded {
        .svg-icon {
            transform: rotate(-180deg);
        }
    }
}
.list {
    color: #262626;
    .label {
        min-width: 5em;
    }
}
.gray-box {
    background: #F8FAFC;
    padding: 8px;
    color: #4D5665;
    font-size: 13px;
}
</style>