<template>
    <el-dialog
        title="病历调用"
        width="1000px"
        :visible.sync="visible"
        :before-close="_close"
        class="recordDialog"
    >
        <div>
            <el-tabs v-model="activeName">
                <el-tab-pane label="病历模板" name="first">
                    <div style="display:flex;align-items: center;margin-bottom:10px;">
                        <el-input size="small"  v-model.trim="search_input" class="filter-item" style="width:140px;"/>
                        <el-button size="small" style="margin:0 10px;" class="filter-item" type="primary"  @click="searchAction">搜索</el-button>
                        <span>日期：</span>
                        <el-date-picker
                        size="small"
                        style="width:140px;margin:0 10px;"
                        v-model="start_time"
                        type="date"
                        placeholder="选择日期"
                        @change="changeStarTime">
                        </el-date-picker>
                        <el-date-picker
                        style="width:140px;"
                        size="small"
                        v-model="end_time"
                        type="date"
                        placeholder="选择日期"
                        @change="changeEndTime">
                        </el-date-picker>
                    </div>
                    <el-table :data="tempalateData" border height="300" :row-style="{ color: '#303133' }" :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}" highlight-current-row>
                        <el-table-column align="center" type="index" width="60" label="序号"></el-table-column>
                        <el-table-column align="center" prop="name" width="60" label="病历编号">
                            <template slot-scope="scope">{{ scope.row.id }}</template>
                        </el-table-column>
                        <el-table-column align="center" prop="name" label="名称">
                            <template slot-scope="scope">{{ scope.row.template_name }}</template>
                        </el-table-column>
                        <el-table-column align="center" prop="name" label="创建人">
                            <template slot-scope="scope">{{ scope.row.user_name }}</template>
                        </el-table-column>
                        <el-table-column align="center" prop="name" label="创建日期">
                            <template slot-scope="scope">{{getTimes(scope.row.record_date) }}</template>
                        </el-table-column>
                        <el-table-column align="center" prop="name" label="模板说明">
                            <template slot-scope="scope">{{ scope.row.template_remark }}</template>
                        </el-table-column>
                        <el-table-column align="center" prop="name" label="操作" width='200'>
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="totemplateDetailTwo(scope.row.id)">调用</el-button>
                                <el-button type="primary" size="mini" @click="totemplateDetail(scope.row.id)">详情</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-tab-pane>
            </el-tabs>
        </div>
        <record-history-detail ref="recordHistoryDetail"></record-history-detail>
        <record-template-detail ref="recordTemplateDetail"></record-template-detail>
        <div slot="footer" class="dialog-footer">
            <el-button @click="hide">取 消</el-button>
            <el-button type="primary"  @click="submitAction()">保 存</el-button>
        </div>
    </el-dialog>
</template>

<script>
import recordHistoryDetail from './recordHistoryDetail'
import recordTemplateDetail from './recordTemplateDetail'
import { getHistoryTemplate } from "@/api/project/project"
import { uParseTime } from '@/utils/tools'
export default {
    components:{
        recordHistoryDetail,
        recordTemplateDetail
    },
    data(){
        return{
            visible:false,
            activeName:'first',
            form:{
                name:''
            },
            tableData: [],
            tempalateData:[],
            value1:"",
            search_input:"",
            start_time:"",
            end_time:"",
            mode_status:0,
        }
    },
    methods:{
        _close: function(done) {
            // this.clear()
            done()
        },
        clear: function() {
            this.form.id = 0;
            this.form.name = "";
            this.form.intro = "";
        },
        show(id) {
            this.mode_status = id;
            this.getlist();
            this.visible = true
        },
        hide() {
            // this.clear()
            this.visible = false
        },
        toHistoryDetail(){
            this.$refs.recordHistoryDetail.show()
        },
        totemplateDetail(id){
            this.$refs.recordTemplateDetail.show(id)
        },
        totemplateDetailTwo(id){
         this.$emit('func',id);
         this.visible = false
        },
        //获取历史数据历史模板
        getlist(){

            const params = {
               keyword:this.search_input,
               start_time:this.start_time,
               end_time:this.end_time
            };

          getHistoryTemplate(params).then(response=>{
            if(response.data.state == 1){
              var template =  response.data.data.template;
              console.log("templagte",template);
              this.tempalateData = template
            }
          })
        },
        searchAction(){
          this.getlist()
        },
        changeStarTime(){
           this.getlist()
        },
        changeEndTime(){
          this.getlist()
        },
        getTimes(time) {
        return uParseTime(time, "{y}-{m}-{d} {h}:{i}:{s}");
      },
    },
    created(){
       this.getlist()
    },


}
</script>

<style lang="scss">
.recordDialog{
    .el-dialog__body{
        padding-top:0;
    }
}
</style>

