<template>
    <div class="department">
        <div class="departmentView">
            <div class="content">
                <div class="list" v-for="(item,index) in departmentLis" @click="goStart(index,item.recordTime)" :key="item.recordTime">
                    <div class="top">
                        <p>挂号科室：{{item.hospitalDeptName}} <img src="../images/right.png" alt=""></p>
                    </div>
                    <div class="main">
                        <p>预约时间：{{item.recordTime}}</p>
                        <p>姓名：{{item.patientName}}</p>
                        <p>病历号：{{item.recordId}}</p>
                        <p>挂号信息：{{item.registerNum}}</p>
                        <p v-if="item.dided">您已完成过一次预问诊，是否再次录入</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
  import {setScroll,compare} from '@utils/tools.js';
  import BScroll from 'better-scroll';
    export default {
        name: "Department",
        data(){
            return {
                scroll:null,
                departmentLis:[]
            }
        },
        created(){
            let tmpList = JSON.parse(localStorage.getItem('loginData'))
            let tmpTime = JSON.parse(localStorage.getItem('recordTime'))
            let sortArr = tmpList.sort(compare("recordTime"));
            if(tmpTime){
                for(let j = 0;j < tmpTime.length;j++){
                    for(let i = 0;i < sortArr.length;i++){
                        if(tmpTime[j] == (new Date((sortArr[i].recordTime).replace(/\-/g, "/"))).getTime()){
                            sortArr[i].dided = 1
                        }
                    }
                }
            }
            this.departmentLis = sortArr
        },
        mounted(){
            this.$nextTick(()=>{
                let scroll = setScroll(BScroll,true,'.departmentView')
                this.scroll = scroll
            })
        },
        methods:{
            goStart(num,time){
                let msg = this.departmentLis[num]
                let params = {
                    hospitalCode:msg.hospitalCode,
                    hospitalDeptCode:msg.hospitalDeptCode,
                    doctorCode:msg.doctorCode,
                    patientCode:msg.patientCode,
                    recordId:msg.recordId,
                    time:(new Date(time.replace(/\-/g, "/"))).getTime()
                }

                localStorage.setItem('loginParam',JSON.stringify(params))//保存登陆信息，扫码进入徐删除该参数

                this.$router.push({
                    path:'/home',
                    query:params
                })
            }
        }
    }
</script>
<style lang="less" scoped>
    .department {
        font-size: .3rem;
        padding: .3rem 0 1rem 0;
        .departmentView {
            position: absolute;
            width: 100%;
            height: 100%;
            overflow: hidden;
            padding: 0 .3rem 1rem .3rem;
            box-sizing: border-box;
            .content {
                padding-bottom: 1rem;
            }
            .list {
                background:rgba(255,255,255,1);
                box-shadow:0px 3px 15px 0px rgba(217,217,217,0.5);
                border-radius:.1rem;
                overflow: hidden;
                margin-bottom: .3rem;
            }
            .top {
                height: 1rem;
                line-height: 1rem;
                background: url('../images/bg-title.png') 100% 100% no-repeat;
                padding: 0 .3rem;
                box-sizing: border-box;
                p {
                    position: relative;
                    color: #fff;
                    img {
                        position: absolute;
                        right: 0;
                        top: 50%;
                        width: .4rem;
                        height: .4rem;
                        margin-top: -0.2rem;
                    }
                }
            }
            .main {
                font-size: .28rem;
                padding: .3rem;
                p {
                    line-height: .5rem;
                }
            }
        }
    }
</style>