<template>
    <div class="main-contain">
     <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>
    </div>
    <div class="app-container">
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="未审核" name="first">
              <el-table
                :data="list"
                border
                style="width: 100%">
                <el-table-column  prop="date" label="序号" min-width="50"  align="center">
                   <template slot-scope="scope" >
                       {{scope.$index + 1 }}
                   </template>
                </el-table-column>
                <el-table-column prop="name"  label="信息模块" min-width="120"  align="center">
                  <template slot-scope="scope" >
                      <span v-if="scope.row.module == 1">透析处方</span> 
                      <span v-if="scope.row.module == 2">接诊评估</span> 
                      <span v-if="scope.row.module == 3">透前评估</span> 
                      <span v-if="scope.row.module == 4">临时医嘱</span> 
                      <span v-if="scope.row.module == 5">双人核对</span> 
                      <span v-if="scope.row.module == 6">透析上机</span> 
                      <span v-if="scope.row.module == 7">透析监测</span> 
                      <span v-if="scope.row.module == 8">透析下机</span> 
                      <span v-if="scope.row.module == 9">透后评估</span> 
                      <span v-if="scope.row.module == 10">治疗小结</span> 
                      <span v-if="scope.row.module == 11">耗材出库</span> 
                   </template>
                </el-table-column>
                <el-table-column  prop="address" label="患者姓名" min-width="100" align="center">
                  <template slot-scope="scope">
                     {{getPatientName(scope.row.patient_id) }}
                   </template>
                </el-table-column>
                <el-table-column prop="date" label="治疗日期"  min-width="100" align="center">
                   <template  slot-scope="scope" >
                      {{getTimeOne(scope.row.record_date)  }}
                   </template>
                </el-table-column>
                <el-table-column prop="name"  label="申请人"  min-width="100"  align="center">
                  <template  slot-scope="scope">
                      {{getUserName(scope.row.creater)  }}
                   </template>
                </el-table-column>
                <el-table-column  prop="address" label="申请时间"   min-width="150" align="center">
                  <template  slot-scope="scope" >
                      {{getTimeTwo(scope.row.application_date)  }}
                   </template>

                </el-table-column>

                <el-table-column  prop="date" label="状态" align="center"  min-width="100">
                  <template  slot-scope="scope" >
                     <span v-if="scope.row.application_status == 1">已审核</span>
                     <span v-if="scope.row.application_status == 2">未审核</span>
                     <span v-if="scope.row.application_status == 3">拒绝</span>
                  </template>
                </el-table-column>
               
                <el-table-column  prop="address" label="备注"   min-width="100" align="center">
                  <template  slot-scope="scope">
                      {{scope.row.remark }}
                   </template>
                </el-table-column>
                <el-table-column prop="address" label="操作"   min-width="150" align="center">
                  <template slot-scope="scope">
                    <el-tooltip
                      class="item"
                      effect="dark"
                      content="审核"
                      placement="top"
                    >
                      <el-button
                        size="small"
                        type="primary"
                        icon="el-icon-edit-outline"
                        @click="handleEdit(scope.$index, scope.row)"
                      >
                      </el-button>
                    </el-tooltip>

                    <el-tooltip
                      class="item"
                      effect="dark"
                      content="拒绝"
                      placement="top"
                    >
                      <el-button
                        size="small"
                        type="danger"
                        icon="el-icon-delete"
                        @click="handleDelete(scope.$index, scope.row)"
                      >
                      </el-button>
                    </el-tooltip>
                   </template>
                </el-table-column>
                
              </el-table>
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :page-size="10"
                background
                style="margin-top:20px;float: right"
                :total="total"
            ></el-pagination>
            </el-tab-pane>

            <el-tab-pane label="全部" name="second">
              <el-table
                :data="inforList"
                border
                style="width: 100%">
                <el-table-column  prop="date" label="序号"  min-width="50" align="center">
                   <template slot-scope="scope" >
                       {{scope.$index + 1 }}
                   </template>
                </el-table-column>
                <el-table-column prop="name"  label="信息模块"  min-width="100" align="center">
                  <template slot-scope="scope" >
                      <span v-if="scope.row.module == 1">透析处方</span> 
                      <span v-if="scope.row.module == 2">接诊评估</span> 
                      <span v-if="scope.row.module == 3">透前评估</span> 
                      <span v-if="scope.row.module == 4">临时医嘱</span> 
                      <span v-if="scope.row.module == 5">双人核对</span> 
                      <span v-if="scope.row.module == 6">透析上机</span> 
                      <span v-if="scope.row.module == 7">透析监测</span> 
                      <span v-if="scope.row.module == 8">透析下机</span> 
                      <span v-if="scope.row.module == 9">透后评估</span> 
                      <span v-if="scope.row.module == 10">治疗小结</span> 
                      <span v-if="scope.row.module == 11">耗材出库</span> 
                   </template>
                </el-table-column>
                <el-table-column  prop="address" label="患者姓名" min-width="100" align="center">
                  <template slot-scope="scope">
                     {{getPatientName(scope.row.patient_id) }}
                   </template>
                </el-table-column>
                <el-table-column prop="date" label="治疗日期"  min-width="100" align="center">
                   <template  slot-scope="scope" >
                      {{getTimeOne(scope.row.record_date)  }}
                   </template>
                </el-table-column>
                <el-table-column prop="name"  label="申请人"  min-width="100" align="center">
                  <template  slot-scope="scope">
                      {{getUserName(scope.row.creater)  }}
                   </template>
                </el-table-column>
                <el-table-column  prop="address" label="申请时间" min-width="180" align="center">
                  <template  slot-scope="scope" >
                      {{getTimeTwo(scope.row.application_date)  }}
                   </template>

                </el-table-column>

                <el-table-column  prop="date" label="状态" min-width="100" align="center">
                  <template  slot-scope="scope" >
                     <span v-if="scope.row.application_status == 1">已审核</span>
                     <span v-if="scope.row.application_status == 2">未审核</span>
                     <span v-if="scope.row.application_status == 3">拒绝</span>
                  </template>
                </el-table-column>
                <el-table-column prop="name" label="审批人" min-width="100" align="center">
                  <template  slot-scope="scope" >
                      {{getUserName(scope.row.checker)  }}
                   </template>
                </el-table-column>
                <el-table-column prop="address" label="审批时间" min-width="180" align="center">
                  <template  slot-scope="scope">
                      {{getTimeOne(scope.row.check_time)  }}
                   </template>
                </el-table-column>
                <el-table-column  prop="address" label="备注" min-width="260" align="center">
                  <template  slot-scope="scope">
                      {{scope.row.remark }}
                   </template>
                </el-table-column>
              
                
              </el-table>
              <el-pagination
                @size-change="handleSizeChangeOne"
                @current-change="handleCurrentChangeOne"
                :page-size="10"
                background
                style="margin-top:20px;float: right"
                :total="totalOne"
            ></el-pagination>

            </el-tab-pane>

            <el-tab-pane label="信息归档设置" name="third">
               <el-button type="primary" size="small" style="margin-bottom:20px" @click="toSeeting">设置</el-button>
              <el-table
                  :data="tableData"
                  style="width: 350px"
                  border
                  lazy>
                  <el-table-column prop="date" label="序号" width="180" align="center">
                     <template slot-scope="scope" >
                        {{scope.$index + 1 }}
                     </template>
                  </el-table-column>
                  <el-table-column
                    prop="name"
                    label="归档天数"
                    width="180"
                    align="center">
                    <template slot-scope="scope" >
                        {{scope.row.week_day }}
                     </template>
                  </el-table-column>
                
                </el-table>
            </el-tab-pane>
          
        </el-tabs>
     </div>

     <el-dialog
        title="信息归档设置"
        :visible.sync="dialogVisible"
        width="30%">
        <span>
          <span>归档天数:</span> <el-input v-model="week_day" style="width:200px"></el-input>   
        </span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="SaveDialysisInformationSetting">保 存</el-button>
       </span>
     </el-dialog>
    </div>
</template>
<script>
 import { SaveDialysisInformationSetting,getDialysisInformationSetting,checkDialysisInformation } from "@/api/dialysis"
 import { uParseTime } from '@/utils/tools'
  export default {
    data() {
      return {
        activeName: 'first',
        dialogVisible:false,
        id:0,
        week_day:"",
        crumbs: [
        { path: false, name: "信息归档" },      
        ],
        tableData:[],
        limit:10,
        page:1,
        list:[],
        total:0,
        totalOne:0,
        inforList:0,
        patients:[],
        adminList:[],
        id:0,
      };
    },
    methods: {
        handleClick(val){
           this.getlist()
        },
        toSeeting(){
          var params = {
             limit:this.limit,
             page:this.page
           }
          getDialysisInformationSetting(params).then(response=>{
            if(response.data.state == 1){
              this.dialogVisible = true
              var informaitonSetting =  response.data.data.informaitonSetting
              if (informaitonSetting!=null && informaitonSetting.length > 0) {
                 this.week_day = informaitonSetting[0].week_day
              }
            }
          })
         
        },
        SaveDialysisInformationSetting(){
            var params = {
              week_day:parseInt(this.week_day),
              id:parseInt(this.id),
            }
            SaveDialysisInformationSetting(params).then(response=>{
             if(response.data.state == 1){
               var informaitonSetting = response.data.data.informaitonSetting
               this.$message.success("保存成功!")
               this.dialogVisible = false
               this.toSeetingOne()
             }
          })
        },
        getlist(){
           var params = {
             limit:this.limit,
             page:this.page
           }
           console.log("params23433232wo",params)
          getDialysisInformationSetting(params).then(response=>{
            if(response.data.state == 1){
              var informaitonSetting =  response.data.data.informaitonSetting
              this.tableData = informaitonSetting
              //未审核
              this.list = response.data.data.infor
              this.total = response.data.data.total
              //已审核
              this.totalOne = response.data.data.totalOne
              this.inforList = response.data.data.inforList
              this.patients = response.data.data.patients

              this.adminList= response.data.data.adminList
            }
          }) 
      },
      handleSizeChange(val){
        this.limit = val;
        this.getList();
      },
      handleCurrentChange(val){
        this.page =val
        this.getlist()
      },
      handleSizeChangeOne(val){
        this.limit=val
        this.getlist()
      },
      handleCurrentChangeOne(val){
        this.page =val
        this.getlist()
      },
      getPatientName(patient_id){
       
        var name = ""
        for(let i=0;i<this.patients.length;i++){
           if(patient_id == this.patients[i].id){
              name = this.patients[i].name
           }
        }
        return name
      },
      getTimeOne(val) {
        if(val == ""){
        return ""
        }else {
        return uParseTime(val, '{y}-{m}-{d}')
        }
     },
     getTimeTwo(val) {
        if(val == ""){
        return ""
        }else {
        return uParseTime(val, '{y}-{m}-{d} {h}:{i}')
        }
     },
      getUserName(admin_user_id){
        var user_name = ""
        for(let i=0;i<this.adminList.length;i++){
          if(admin_user_id == this.adminList[i].admin_user_id){
              user_name = this.adminList[i].user_name
          }
        }
        return user_name
      },
      handleEdit(index,row) {
        this.$confirm("确认审核吗?", "审核", {
          confirmButtonText: "确 定",
          cancelButtonText: "取 消",
          type: "warning"
        }).then(() => {
            var params = {
              id:row.id,
              application_status:1,
            }
            checkDialysisInformation(params).then(response => {
              if (response.data.state == 0) {
                this.$message.error(response.data.msg);
                return false;
              } else {
                this.$notify({
                  title: "成功",
                  message: "审核成功",
                  type: "success",
                  duration: 2000
                });
                this.getlist()
              }
            });
          })
          .catch(() => {});
      },
      handleDelete(index,row){
        this.$confirm("确认审核吗?", "审核", {
          confirmButtonText: "确 定",
          cancelButtonText: "取 消",
          type: "warning"
        }).then(() => {
            var params = {
              id:row.id,
              application_status:3,
            }
            checkDialysisInformation(params).then(response => {
              if (response.data.state == 0) {
                this.$message.error(response.data.msg);
                return false;
              } else {
                this.$notify({
                  title: "成功",
                  message: "拒绝成功",
                  type: "success",
                  duration: 2000
                });
                this.getlist()
              }
            });
          }).catch(() => {});
      },

         toSeetingOne(){
           var params = {
             limit:this.limit,
             page:this.page
           }
          getDialysisInformationSetting(params).then(response=>{
            if(response.data.state == 1){
              var informaitonSetting =  response.data.data.informaitonSetting
              this.tableData = []
              this.tableData = informaitonSetting
            }
          }) 
      },

    
    },
   
    created(){
      this.getlist()
     
    }
  };
</script>