<!--通用随访详情-->
<template>
    <div class='flex flex-col' style='height: 100vh'>
        <div class='p-3 text-black text-center shrink-0 doc-nav-bar'>
            <span @click='onBack' class='text-12 back-bt'>
                <doc-icon type='doc-left2' />
            </span>
            <span>随访详情</span>
        </div>
        <div class='px-4 py-3 flex shrink-0 base-info'>
            <div class='flex w-full'>
                <div class='grow flex flex-col justify-between'>
                    <div class='flex justify-between'>
                        <span class='name'>{{ residentInfo.residentName }}</span>
                    </div>
                    <div class='top-label'>
                        <div class='mt-3 flex'>
                            <div><span>随访方式：</span><span class='color-b'>{{ info.visitWayName }}</span></div>
                            <div class='ml-4'>随访日期：<span class='color-b'>{{ info.visitDate }}</span></div>
                        </div>
                        <div><span>下次随访日期：</span><span class='color-b'>{{ info.nextVisitDate }}</span></div>
                    </div>
                </div>
            </div>
        </div>
        <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'>
                                                            <span>{{ info.groupsArraysName || '-' }}</span>
                                                        </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'>
                                                            <span>{{ info.visitWayName || '-' }}</span>
                                                        </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 class='flex justify-between py-1 border-bottom item'>
                                <span class='shrink-0 mr-2 label'>随访类型</span>
                                <span class='text-end'>
                                                            <span>{{ info.visitWayRulesName || '-' }}</span>
                                                        </span>
                            </div>
                        </div>
                    </van-collapse-item>
                    <van-collapse-item key='5' title='随访内容' name='5' v-if='showOne'>
                        <template #right-icon>
                            <doc-icon type='doc-down' />
                        </template>
                        <div class='list'>
                            <div class='py-1 border-bottom item card'
                                 :style="{textIndent: info.visitContent ? '2em' : '0'}">
                                <span>{{ info.visitContent || '-' }}</span>
                            </div>
                        </div>
                    </van-collapse-item>
                    <van-collapse-item key='6' title='处置意见' name='6' v-if='showOne'>
                        <template #right-icon>
                            <doc-icon type='doc-down' />
                        </template>
                        <div class='list'>
                            <div class='py-1 border-bottom item card'
                                 :style="{textIndent: info.disposalOpinion ? '2em' : '0'}">
                                <span>{{ info.disposalOpinion || '-' }}</span>
                            </div>
                        </div>
                    </van-collapse-item>
                    <van-collapse-item key='7' title='健康指导' name='7' v-if='showTwo'>
                        <template #right-icon>
                            <doc-icon type='doc-down' />
                        </template>
                        <div>
                            <div v-if='guideContentList.length' class='flex flex-col card'>
                                <!-- 文本 -->
                                <div v-for='item in guideContentList' :key='item.templateMode' class='mb-1 flex'
                                     :style='`order: ${item.templateMode}`'>
                                    <span class='shrink-0 mr-1'
                                          v-if="item.templateModeTrans != '无'">{{ item.templateModeTrans }} :</span>
                                    <span> {{ item.templateContent }}</span>
                                </div>
                            </div>
                        </div>
                    </van-collapse-item>
                    <van-collapse-item key='8' title='宣教内容' name='8' v-if='showThree'>
                        <template #right-icon>
                            <doc-icon type='doc-down' />
                        </template>
                        <div>
                            <div class='flex flex-col card' v-if='detailInfo?.publicizeType?.includes(1)'>
                                <!-- 文本 -->
                                <div v-for='item in contentList' :key='item.templateMode' class='mb-1 flex'
                                     :style='`order: ${item.templateMode}`'>
                                    <span class='shrink-0 mr-1'
                                          v-if="item.templateModeTrans != '无'">{{ item.templateModeTrans }} :</span>
                                    <span> {{ item.templateContent }}</span>
                                </div>
                            </div>
                            <div class='card mt-2' v-if='detailInfo?.publicizeType?.includes(3)'>
                                <Mp4 :files='mp4List' :activeMediaUrl='activeMediaUrl'
                                     @play='e => activeMediaUrl = e.annexUrl' />
                            </div>
                            <div class='card flex flex-col mt-2' style='row-gap: .06rem;'
                                 v-if='detailInfo?.publicizeType?.includes(2)'>
                                <Mp3 :file='item' v-for='item in mp3List' :key='item.annexId'
                                     :activeMediaUrl='activeMediaUrl'
                                     @play='e => activeMediaUrl = e.annexUrl' />
                            </div>
                        </div>
                    </van-collapse-item>
                    <van-collapse-item key='9' title='催检内容' name='9' v-if='showFour'>
                        <template #right-icon>
                            <doc-icon type='doc-down' />
                        </template>
                        <div class='list'>
                            <div class='py-1 border-bottom item card'
                                 :style="{textIndent: info.urgentInsContent ? '2em' : '0'}">
                                <span>{{ info.urgentInsContent || '-' }}</span>
                            </div>
                        </div>
                    </van-collapse-item>
                    <van-collapse-item key='10' title='上传随访记录' name='10' v-if='showOne'>
                        <template #right-icon>
                            <doc-icon type='doc-down' />
                        </template>
                        <div>
                            <image-preview :img-list='info.uploadVisitRecordImageList'></image-preview>
                        </div>
                    </van-collapse-item>
                    <van-collapse-item key='11' title='现场随访照片' name='11'>
                        <template #right-icon>
                            <doc-icon type='doc-down' />
                        </template>
                        <!--                        <div class='list gap-x-2.5 gap-y-1 flex items-center flex-wrap'>
                                                    <div v-for="(url, index) in info.sceneVisitImageList" :key="index" >
                                                        <img style='width: 1.47rem;height: 2.04rem'  :src="url.trueDownloadUrl" />
                                                    </div>
                                                </div>-->
                        <div>
                            <image-preview :img-list='info.sceneVisitImageList'></image-preview>
                        </div>
                    </van-collapse-item>
                    <van-collapse-item key='12' title='推送渠道' name='12'
                                       v-if='info?.visitWayRules?.includes(2) || info?.visitWayRules?.includes(3) || info?.visitWayRules?.includes(4)'>
                        <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'>
                                    <span v-if='info.isSms == 1'>短信</span><span
                                    v-if='info.isSms == 1 && info.isWx == 1'>；</span>
                                    <span v-if='info.isWx == 1'>微信</span>
                                    <span v-if='info.isSms != 1 && info.isWx != 1'>-</span>
                                </span>
                            </div>
                            <div class='flex justify-between py-1 border-bottom item'
                                 v-if='info.isSms == 1 && (info?.visitWayRules?.includes(2) || info?.visitWayRules?.includes(3) || info?.visitWayRules?.includes(4))'>
                                <span class='shrink-0 mr-2 label'>短信推送情况</span>
                                <span class='text-end'>
                                   <span>{{ info?.serviceResidents?.messageStateName || '-' }}</span>
                                   <span class='ml-4' v-if='info?.serviceResidents?.messageState == 3' style='font-size: 12px'>
                                   <van-button ghost type='primary' size='small' @click='toReSend'>重发</van-button>
                                   </span>
                                </span>
                            </div>
                        </div>
                    </van-collapse-item>
                    <van-collapse-item key='13' title='随访机构' name='13'>
                        <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'>
                                        <span>{{ info[item.key] || '-' }}</span>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </van-collapse-item>
                </van-collapse>
            </div>
        </div>
    </div>
</template>

<script>
import { showToast } from 'vant'
import Mp3 from '@/residentWX/components/mediaPlay/Mp3.vue'
import Mp4 from '@/residentWX/components/mediaPlay/Mp4'
import ImagePreview from '@/residentWX/components/imagePreview/imagePreview'
import { fetchCurrencyById, messageResend } from '@/api/doctor/generalFU'
import { getTemplateDetail } from '@/api/doctor/workbench'

export default {
    name: 'CurrencyFUDetail.vue',
    components: { ImagePreview, Mp4, Mp3 },
    data() {
        return {
            activeCollapse: [],
            detailInfo: {
                publicizeType: [],
                visitWayRules: []
            },
            collapseList: [
                { title: '居民信息', name: '1' },
                { title: '随访人群', name: '2' },
                { title: '随访方式', name: '3' },
                { title: '随访类型', name: '4' },
                { title: '随访内容', name: '5' },
                { title: '处置意见', name: '6' },
                { title: '健康指导', name: '7' },
                { title: '宣教内容', name: '8' },
                { title: '催检内容', name: '9' },
                { title: '上传随访记录', name: '10' },
                { title: '现场随访照片', name: '11' },
                { title: '推送渠道', name: '12' },
                { title: '下次随访日期', name: '13' },
                { title: '随访机构', name: '14' }
            ],
            // 全部展开、收起
            collapseAll: false,
            info: {},
            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' }
            ],
            columnsOrg: [
                { title: '随访单位', key: 'visitUnitName' },
                { title: '随访科室', key: 'visitOfficeName' },
                { title: '随访医生', key: 'visitDoctorName' }
            ],
            activeMediaUrl: ''
        }
    },
    computed: {
        routerDetail() {
            return this.$route.query
        },
        residentInfo() {
            return this.info.residentsRecord || {}
        },
        //复检
        showOne() {
            const { visitWayRules = [] } = this.info
            let res = false
            if (visitWayRules.includes(1)) {
                res = true
            }
            return res
        },
        //指导
        showTwo() {
            const { visitWayRules = [] } = this.info
            let res = false
            if (visitWayRules.includes(2)) {
                res = true
            }
            return res
        },
        //宣教
        showThree() {
            const { visitWayRules = [] } = this.info
            let res = false
            if (visitWayRules.includes(3)) {
                res = true
            }
            return res
        },
        //催检
        showFour() {
            const { visitWayRules = [] } = this.info
            let res = false
            if (visitWayRules.includes(4)) {
                res = true
            }
            return res
        },
        // 文本内容
        guideContentList() {
            return this.info?.guide?.contentList || []
        },
        // 文本内容
        contentList() {
            return this.info?.publicize?.contentList || []
        },
        // 文件内容
        annexList() {
            return this.info?.publicize?.annexList || []
        },
        mp3List() {
            return this.annexList.filter(e => e.type == 2)
        },
        mp4List() {
            return this.annexList.filter(e => e.type == 3)
        }
    },
    created() {
        document.title = '通用随访详情'
        this.load()
    },
    methods: {
        async load() {
            if (!this.routerDetail.relationId) {
                showToast('未获取到信息')
                return
            }
            let par = {
                id: this.routerDetail.relationId
            }
            fetchCurrencyById(par).then(res => {
                let result = res.data || {}
                this.info = result
                this.dataHandle()
            }).finally(() => {
            })
        },
        //数据处理
        dataHandle() {
            const { visitWayRules, publicizeType } = this.info
                if (publicizeType) {
                    this.detailInfo.publicizeType = publicizeType.split(',').map(item => Number(item))
                }
                if (visitWayRules) {
                    this.detailInfo.visitWayRules = visitWayRules.split(',').map(item => Number(item))
                }
        },
        //重新发送
        toReSend() {
            let par = {
                id: this.routerDetail.relationId
            }
            messageResend(par).then(() => {
                this.load()
            })
        },
        // 折叠面板切换
        collapseChange(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 && val.length === this.collapseList.length) {
                this.collapseAll = true
            } else {
                this.collapseAll = false
            }
        },
        // 全部展开、收起
        toggleAll() {
            if (this.collapseAll) {
                this.activeCollapse = []
            } else {
                this.activeCollapse = this.collapseList.map(e => e.name)
            }
            this.collapseAll = !this.collapseAll
        },
        onBack() {
            this.$router.back()
        }
    }
}
</script>

<style lang='less' scoped>
@import url('../../../utils/common.less');

.base-info {
    background: linear-gradient(to bottom, #F0F6FF, #fff 50%);
    color: #8c8c8c;

    .name {
        font-weight: 600;
        color: #000;
        font-size: 18px;
    }

    .top-label {
        font-size: 13px;
        line-height: 22px;
    }

    .color-b {
        color: #262626;
    }
}

.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);
        }
    }
}


table {
    text-align: left;
    border-bottom: 1px solid var(--van-cell-border-color);

    > tr {
        > td {
            padding-left: 14px;
            padding-bottom: 12px;

            &:first-child {
                text-align: right;
                padding-left: 0;
            }
        }
    }
}

.list {
    .label {
        min-width: 5em;
    }
}

.card {
    background-color: #F8FAFC;
    padding: 4px 10px;
    border-radius: 4px;
    color: #4D5665;
}
</style>
