<template>
        <div class="page_rescueRecord">
            <div class="cell clearfix" style="margin-top:10px;">
                <!-- <label class="title">
                    <span class="name">治疗日期</span> :
                </label>
                <div class="time">
                    <ul class>
                    <li
                        :class="item.state == dayType ? 'active' : ''"
                        @click="chooseDay(item.state)"
                        v-for="item in day"
                        :key="item.value"
                    >{{ item.label }}</li>
                    </ul>
                </div>
                <el-date-picker
                    v-model="time"
                    prefix-icon="el-icon-date"
                    @change="changeTime"
                    :editable="false"
                    style="width: 150px;"
                    type="date"
                    placeholder="选择日期时间"
                    align="right"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                ></el-date-picker> -->
                <label class="title" style="margin-left:10px;">
                    <span class="name">患者信息</span> :
                </label>
                <div class="infoBox">
                    <span>姓名：{{ patient.name }}</span>&nbsp;|&nbsp;<span>透析编号：{{ patient.dialysis_no }}</span>
                </div>
            </div>
            <div>
                <el-input type="textarea" :disabled="true" :rows="4" placeholder="请输入内容" v-model="textarea"></el-input>
                <el-button type="primary" v-clipboard:copy="textarea" v-clipboard:success="onCopy" v-clipboard:error="onError" style="margin-top:10px;float:right;">复制</el-button>
            </div>
        </div>
</template>

<script>
export default {
    props:{
        doctor_advices:Array,
        patient:Object,
        prescription:Object,
    },
    data(){
      return{
        day: [
            { value: 0, label: "今天", state: 0 },
            { value: 1, label: "昨天", state: 1 },
            { value: 2, label: "前天", state: 2 },
        ],
        dayType: 0,
        time:'',
        advices:[],
        textarea:'',
        modeId:''
      }
    },
    created(){
        console.log('patient',this.prescription)
        if(this.prescription.mode_id){
            this.modeId = this.getMode(this.prescription.mode_id)
        }
        
        if(this.doctor_advices.length > 0){
            let str = ''
            let arr = []
            this.advices = this.doctor_advices
            this.advices.map(item => {
                str = item.advice_name + (item.advice_desc ? ('(' +  item.advice_desc + item.drug_spec_unit + ')') : '' )  + '  ' + item.prescribing_number + item.prescribing_number_unit + '  ' + 
                item.single_dose + item.single_dose_unit + '  ' + item.delivery_way + item.execution_frequency + item.remark
                arr.push(str)
            })
            this.textarea = ''
            arr.map(item => {
                this.textarea += item + "\n"
            })
        }else if(this.doctor_advices.length == 0){
            this.textarea = ''
            this.textarea = '1.开始' + this.modeId + '治疗' + '\n' +
                            '2.结束' + this.modeId + '治疗' + '\n' +
                            '3.患者离开血透室'
        }
        
        
    },
    methods:{
        chooseDay(day) {
            this.dayType = day;
        },
        getMode(id){
            let name = ''
            this.treatment_mode = Object.values(this.$store.getters.treatment_mode)
            this.treatment_mode.map(item => {
                if(item.id == id){
                    name = item.name
                }
            })
            return name
        },
        onCopy() {
            this.$message.success("复制成功");
        },
        onError() {
            this.$message.success("复制失败,请重试");
        }
    },
    watch:{
        doctor_advices:{
            handler:function(val) {
                if(this.doctor_advices.length > 0){
                    let str = ''
                    let arr = []
                    this.advices = this.doctor_advices
                    this.advices.map(item => {
                        str = item.advice_name + (item.advice_desc ? ('(' +  item.advice_desc + item.drug_spec_unit + ')') : '' )  + '  ' + item.prescribing_number + item.prescribing_number_unit + '  ' + 
                        item.single_dose + item.single_dose_unit + '  ' + item.delivery_way + item.execution_frequency + item.remark
                        arr.push(str)
                    })
                    this.textarea = ''
                    arr.map(item => {
                        this.textarea += item + "\n"
                    })
                }else if(this.doctor_advices.length == 0){
                    this.textarea = ''
                    this.textarea = '1.开始' + this.modeId + '治疗' + '\n' +
                                    '2.结束' + this.modeId + '治疗' + '\n' +
                                    '3.患者离开血透室'
                }
            }
        },
        patient:{
            handler:function(val) {
            }
        },
        prescription:{
          handler:function(val) {
                if(this.prescription.mode_id){
                    this.modeId = this.getMode(this.prescription.mode_id)
                }
            }  
        },
        deep:true,
    }
}
</script>

<style lang="scss" scoped>
.tableTitle {
    font-size: 16px;
    color: #000;
    font-weight: bold;
    line-height: 40px;
}
.page_rescueRecord{
    width: 100%;
    padding-right: 10px;
    .infoBox{
        padding: 10px 20px;
        border-radius: 20px;
        border:1px solid #DCDFE6;
        font-size: 14px;
        color: #606266;
        display: flex;
        align-items: center;
    }
}
</style>
