<template>
  <div class="patient-container">
    <patient-sidebar :id="patientID" defaultActive="1-6" v-on:tran-patient="onTranPatient"></patient-sidebar>
    <div class="patient-app-container advice-container app-container">
      <div style="display:flex;justify-content: space-between;align-items: center;margin-bottom: 12px;">
         <span style="font-weight:bold;">血管通路列表</span>
         <el-button size="medium" type="primary" @click="dialogVisible =true">新增</el-button>
      </div>
      <el-table class="oictable" :data="tableData" border style="width:100%">
      <el-table-column prop="start_time" label="建立日期" width="100" align="center">
          <template slot-scope="scope">
            <span>{{ getTime(scope.row.start_time, "{y}-{m}-{d}")}}</span>
          </template>
     </el-table-column>
      <el-table-column prop="blood_access_part_opera_id" label="血管通路" align="center" width="120">
        <template slot-scope="scope">
           <router-link
              :to="'/patients/patient/' + scope.row.patient_id+'/vascularAccessDetail/'+scope.row.id"
              style="color:#409eff;width:100%;display:block;"
            >{{ scope.row.blood_access_part_opera_id }}
            </router-link
            >
        </template>
     </el-table-column>
     <el-table-column prop="blood_access_part_id" label="血管通路部位" width="200" align="center">
        <template slot-scope="scope">
           <span>{{scope.row.blood_access_part_id}}</span>  
        </template>
     </el-table-column>
      <el-table-column prop="inflow_pass" label="血管通路部位(其他)" width="100" align="center">
         <template slot-scope="scope">
            <span>{{scope.row.other_vascular}}</span>
         </template>
      </el-table-column>
      <el-table-column prop="date" label="首次启用日期" width="120" align="center">
          <template slot-scope="scope">
            <span>{{ getTime(scope.row.first_start_time, "{y}-{m}-{d}")}}</span>
          </template>
      </el-table-column>
     
       <el-table-column prop="date" label="停用日期" align="center" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.stop_time>0">{{ getTime(scope.row.stop_time, "{y}-{m}-{d}")}}</span>
             <span v-if="scope.row.stop_time<0"></span>
          </template>
      </el-table-column>
       <el-table-column prop="date" label="停用原因" align="center" width="120">
          <template slot-scope="scope">
             <span>{{scope.row.stop_reason}}</span>
          </template>
      </el-table-column>
       <el-table-column prop="date" label="使用寿命(天)" align="center" width="120">
          <template slot-scope="scope">
           <span v-if="scope.row.stop_time>0&&(scope.row.stop_time - scope.row.start_time)/86400 == 0"></span> 
           <span v-if="scope.row.stop_time>0&&(scope.row.stop_time - scope.row.start_time)/86400 != 0">{{(scope.row.stop_time - scope.row.start_time)/86400}}</span>
          </template>
      </el-table-column>
       
      <el-table-column prop="date" label="导管感染转归" align="center" width="120">
          <template slot-scope="scope">
             <span v-if="scope.row.ci_type == 1">拔管</span>
             <span v-if="scope.row.ci_type == 2">治愈</span>
             <span v-if="scope.row.ci_type == 3">死亡</span>
             <span v-if="scope.row.ci_type == 4">放弃</span>
             <span v-if="scope.row.ci_type == 9">其它</span>
          </template>
      </el-table-column>
       
       <el-table-column prop="date" label="血培养检查结果" align="center" width="120">
          <template slot-scope="scope">
             <span v-if="scope.row.blood_cultupe == 0">阴性</span>
             <span v-if="scope.row.blood_cultupe == 1">阳性</span>
             <span v-if="scope.row.blood_cultupe == 9">未查</span>
          </template>
      </el-table-column>
      
     <el-table-column prop="date" label="患者导管转归类型" align="center" width="120">
          <template slot-scope="scope">
             <span v-if="scope.row.sequelae_type == 1">局部感染</span>
             <span v-if="scope.row.sequelae_type == 2">静脉炎</span>
             <span v-if="scope.row.sequelae_type == 3">导管细菌定植</span>
             <span v-if="scope.row.sequelae_type == 4">导管相关血型感染</span>
          </template>
      </el-table-column>
       <el-table-column prop="date" label="备注" align="center" width="180">
          <template slot-scope="scope">
             <span>{{scope.row.remark}}</span>
          </template>
      </el-table-column>
      <el-table-column prop="date" label="创始人" align="center" width="100">
          <template slot-scope="scope">
            <span>{{getDoctor(scope.row.creator)}}</span>
          </template>
      </el-table-column>
       <el-table-column prop="date" fixed="right" label="操作" width="140" align="center">
          <template slot-scope="scope">
             <el-tooltip class="item" effect="dark" content="编辑" placement="top">
               <el-button
                  type="primary"
                  size="small"
                  icon="el-icon-edit-outline"
                 
                  @click="handleUpdateAdviceTemplate(scope.row.id)"
                  >
               </el-button>
             </el-tooltip>
              <el-tooltip class="item" effect="dark" content="删除" placement="top">
                 <el-button
                  size="small"
                  type="danger"
                  icon="el-icon-delete"
                  @click="handleDeleteAdviceTemplate(scope.row.id, scope.$index)"
                  >
                 </el-button>
              </el-tooltip>
           </template>
      </el-table-column>
  </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10,20,50,100]"
        :page-size="10"
        background
        style="margin-top:20px;"
        align="right"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"></el-pagination>

     <el-dialog
         title="新增通路"
         :visible.sync="dialogVisible"
         width="65%"
         center>
      <el-form label-width="150px" :model="form" ref="form" :rules="rules" >
         <el-row :gutter="24">
            <el-col :span="24">
                <el-form-item label="通路项目:" :required="true" prop="access_project"  > 
                    <el-radio-group style="padding: 10px;" v-model="form.access_project" @change="changeRadio">
                        <el-radio  label="1">内瘘</el-radio>
                        <el-radio  label="2">导管</el-radio>
                   </el-radio-group>
                </el-form-item>
            </el-col>
         </el-row>
         <el-row :gutter="24">
            <el-col :span="8">
               <el-form-item label="建立日期:" :required="true" prop="start_time">
                 <el-date-picker
                    type="datetime"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择时间"
                    v-model="form.start_time"
                    style="width:200px">
                 </el-date-picker>
               </el-form-item>
            </el-col>
             <el-col :span="8">
               <el-form-item label="血管通路类型:" :required="true" prop="blood_access_part_opera_id">
                 <el-select v-model="form.blood_access_part_opera_id" placeholder="请选择"  style="width:200px">
                    <el-option
                        v-for="item in blood_access_part_opera"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                        >
                    </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
             <el-col :span="8">
               <el-form-item label="血管通路部位:" :required="true" prop="blood_access_part_id">
                  <el-input v-model="form.blood_access_part_id" readonly @focus="showInnerDialog('17')" style="width:200px"></el-input>
               </el-form-item>
            </el-col>
         </el-row>
          <el-row :gutter="24">
            <el-col :span="8">
               <el-form-item label="血管通路部位(其他):"  prop="inflow_pass">
                 <!-- <el-select v-model="form.inflow_pass" placeholder="请选择" style="width:150px">
                    <el-option
                        v-for="item in optionsPass"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                  </el-select> -->
                  <el-input v-model="form.other_vascular" style="width:200px"></el-input>
               </el-form-item>
            </el-col>
             <el-col :span="8">
               <el-form-item label="首次启用日期:" :required="true" prop="first_start_time">
                  <el-date-picker
                    type="datetime"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择时间"
                    v-model="form.first_start_time"
                    style="width:200px">
                 </el-date-picker>
               </el-form-item>
            </el-col>
             <el-col :span="8">
               <el-form-item label="使用状态:" :required="true" prop="user_status">
                 <el-select v-model="form.user_status" placeholder="请选择" style="width:200px" @change="changeStatus">
                    <el-option
                        v-for="item in options"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
         </el-row>
         <el-row :gutter="24" v-show="showOne">
            <el-col :span="8">
               <el-form-item label="导管感染转归:">
                  <el-select v-model="form.ci_type" placeholder="请选择" style="width:200px" @change="changeStatus">
                     <el-option
                           v-for="item in optionsTwo"
                           :key="item.id"
                           :label="item.name"
                           :value="item.id">
                     </el-option>
                  </el-select>
               </el-form-item>
             </el-col>
             <el-col :span="8">
               <el-form-item label="血培养检查结果:">
                  <el-select v-model="form.blood_cultupe" placeholder="请选择" style="width:200px" @change="changeStatus">
                     <el-option
                           v-for="item in optionsThree"
                           :key="item.id"
                           :label="item.name"
                           :value="item.id">
                     </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
            <el-col :span="8">
               <el-form-item label="患者导管转归类型:">
                  <el-select v-model="form.sequelae_type" placeholder="请选择" style="width:200px" @change="changeStatus">
                     <el-option
                           v-for="item in optionsOne"
                           :key="item.id"
                           :label="item.name"
                           :value="item.id">
                     </el-option>
                  </el-select>
               </el-form-item>
             </el-col>
         </el-row>
         <el-row v-show="show">
            <el-col :span="8">
               <el-form-item label="停用日期:">
                  <el-date-picker
                    type="datetime"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择时间"
                    v-model="form.stop_time"
                    style="width:200px">
                 </el-date-picker>
               </el-form-item>
            </el-col>
         </el-row>
         <el-row v-show="show">
           <el-col>
            <el-form-item label="停用原因:">
               <el-input v-model="form.stop_reason"></el-input>
            </el-form-item>
           </el-col>  
         </el-row>
           <el-row>
            <el-col>
                <el-form-item label="备注:">
                 <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="form.remark"></el-input>
                </el-form-item>
            </el-col>  
         </el-row>
      </el-form>

     <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveVasularAccess('form')">保存</el-button>
     </span>
     </el-dialog>



      <el-dialog
         title="编辑通路"
         :visible.sync="editDialogVisible"
         width="60%"
         center>
      <el-form label-width="120px" :model="form" ref="form" :rules="rules" >
         <el-row :gutter="24">
            <el-col :span="24">
                <el-form-item label="通路项目:" :required="true" prop="access_project">
                  <el-radio-group style="padding: 10px;" v-model="form.access_project" @change="changeRadio">
                        <el-radio  label="1">内瘘</el-radio>
                        <el-radio  label="2">导管</el-radio>
                  </el-radio-group>
                </el-form-item>
            </el-col>
         </el-row>
         <el-row :gutter="24">
            <el-col :span="8">
               <el-form-item label="建立日期:" :required="true" prop="start_time">
                 <el-date-picker
                    type="datetime"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择时间"
                    v-model="form.start_time"
                    style="width:150px">
                 </el-date-picker>
               </el-form-item>
            </el-col>
             <el-col :span="8">
               <el-form-item label="血管通路类型:" :required="true" prop="blood_access_part_opera_id">
                 <el-select v-model="form.blood_access_part_opera_id" placeholder="请选择"  style="width:150px">
                    <el-option
                        v-for="item in blood_access_part_opera"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                        >
                    </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
             <el-col :span="8">
               <el-form-item label="血管通路部位:" :required="true" prop="blood_access_part_id">
                 <!-- <el-select v-model="form.blood_access_part_id" placeholder="请选择" style="width:150px">
                    <el-option
                        v-for="item in blood_access_part"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                  </el-select> -->

                   <el-input v-model="form.blood_access_part_id" readonly @focus="showInnerDialog('17')" style="width:150px"></el-input>
               </el-form-item>
            </el-col>
         </el-row>
          <el-row :gutter="24">
            <el-col :span="8">
               <el-form-item label="血管通路部位(其他):" :required="true" prop="inflow_pass">
                 <!-- <el-select v-model="form.inflow_pass" placeholder="请选择" style="width:150px">
                    <el-option
                        v-for="item in optionsPass"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                  </el-select> -->
                  <el-input v-model="form.other_vascular"></el-input>
               </el-form-item>
            </el-col>
             <el-col :span="8">
               <el-form-item label="首次启用日期:" :required="true" prop="first_start_time">
                  <el-date-picker
                    type="datetime"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择时间"
                    v-model="form.first_start_time"
                    style="width:150px">
                 </el-date-picker>
               </el-form-item>
            </el-col>
             <el-col :span="8">
               <el-form-item label="使用状态:" :required="true" prop="user_status">
                 <el-select v-model="form.user_status" placeholder="请选择" style="width:150px" @change="changeStatus">
                    <el-option
                        v-for="item in options"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
         </el-row>
           <el-row v-show="showOne">
            <el-col :span="8">
               <el-form-item label="导管感染转归:">
                  <el-select v-model="form.ci_type" placeholder="请选择" style="width:150px" @change="changeStatus">
                     <el-option
                           v-for="item in optionsTwo"
                           :key="item.id"
                           :label="item.name"
                           :value="item.id">
                     </el-option>
                  </el-select>
               </el-form-item>
             </el-col>
             <el-col :span="8">
               <el-form-item label="血培养检查结果:">
                  <el-select v-model="form.blood_cultupe" placeholder="请选择" style="width:150px" @change="changeStatus">
                     <el-option
                           v-for="item in optionsThree"
                           :key="item.id"
                           :label="item.name"
                           :value="item.id">
                     </el-option>
                  </el-select>
               </el-form-item>
            </el-col>
            <el-col :span="8">
               <el-form-item label="患者导管转归类型:">
                  <el-select v-model="form.sequelae_type" placeholder="请选择" style="width:150px" @change="changeStatus">
                     <el-option
                           v-for="item in optionsOne"
                           :key="item.id"
                           :label="item.name"
                           :value="item.id">
                     </el-option>
                  </el-select>
               </el-form-item>
             </el-col>
         </el-row>
         <el-row v-show="show">
            <el-col :span="8">
               <el-form-item label="停用日期:">
                  <el-date-picker
                    type="datetime"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择时间"
                    v-model="form.stop_time"
                    style="width:150px">
                 </el-date-picker>
               </el-form-item>
            </el-col>
         </el-row>
         <el-row v-show="show">
           <el-col>
            <el-form-item label="停用原因:">
               <el-input v-model="form.stop_reason"></el-input>
            </el-form-item>
           </el-col>  
         </el-row>
           <el-row>
            <el-col>
                <el-form-item label="备注:">
                 <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="form.remark"></el-input>
                </el-form-item>
            </el-col>  
         </el-row>
      </el-form>

     <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible= false">取 消</el-button>
        <el-button type="primary" @click="updatedVasularAccess('form')">保存</el-button>
     </span>
     </el-dialog>

    </div>

     <multi-select-box
        :propsForm="InnerDialogProps"
        v-on:dialog-comfirm="innerDialogComfirm"
        v-on:dialog-cancle="innerDialogCancle"
      ></multi-select-box>
  </div>
</template>
<script>
  const moment = require('moment')
  import PatientSidebar from './components/PatientSidebar'
  import { fetchAllAdminUsers, fetchAllDoctorAndNurse } from '@/api/doctor'
  import { saveVasularAccess,getAllVascularAccessList,getVascularAccessByDetail,updatedVasularAccess,DeleteVascularAccess,getAccessList } from '@/api/patient'

  import { jsGetAge, uParseTime } from '@/utils/tools'
  import { getDataConfig } from '@/utils/data'
  import multiSelectBox from '../dialysis/details/dialog/MultiSelectBox'
    
  export default {
    name: 'doctorAdvice',
    components: {
      PatientSidebar,
      multiSelectBox
    },
    data() {
      return {
        tableData: [],
        nowtime: moment(new Date()).format('YYYY-MM-DD'),
        page: 1,
        limit: 10,
        total: 0,
        rules: {
          start_time: [{ required: true, message: '请输入建立日期' }],
          access_project: [{ required: true, message: '请选择通路项目' }],
          blood_access_part_opera_id:[{required:true,message:'请选择血管通路类型'}],
          blood_access_part_id:[{required:true,message:"请选择血管通路"}],
          first_start_time:[{required:true,message:"请选择首次启用日期"}],
          user_status:[{required:true,message:"请选择使用状态"}]
        },
        dialogVisible:false,
        editDialogVisible:false,
        form:{
         id:0,
         access_project:"1",
         blood_access_part_id:"",
         blood_access_part_opera_id:"",
         inflow_pass:"",
         start_time:moment(new Date()).format('YYYY-MM-DD'),
         first_start_time:moment(new Date()).format('YYYY-MM-DD'),
         stop_reason:"",
         user_status:1,
         remark:"",
         stop_time:"",
         other_vascular:"",
         ci_type:"",//导管感染转归
         blood_cultupe:"", //血培养检查结果
         sequelae_type:"",//患者导管转归类型
        },
        options:[
         {id:1,name:"启用"},
         {id:2,name:"停用"}
        ],
        optionsPass:[
          {id:1,name:"流入-动脉"},
          {id:2,name:"流出-静脉"},
        ],

        blood_access_part_opera:[],
        blood_access_part:[],
        show:false,
        doctorList:[],
        InnerDialogProps: {
          values: [],
          visibility: false,
          isShowTextArea: true,
          customContent: '',
          titles: '',
          type: '' // 不同弹框类型，用来匹配数据
        },
        new_blood_access_part_opera:[],
        new_blood_access_part:[],
       // 导管感染类型
        optionsOne:[
           {id:1,name:"局部感染"},
           {id:2,name:"静脉炎"},
           {id:3,name:"导管细菌定植"},
           {id:4,name:"导管相关血型感染"},
        ],
      //   导管转归类型
        optionsTwo:[
           {id:1,name:"拔管"},
           {id:2,name:"治愈"},
           {id:3,name:"死亡"},
           {id:4,name:"放弃"},
           {id:9,name:"其它"},
        ],
      //  血培养检查结果
        optionsThree:[
           {id:0,name:"阴性"},
           {id:1,name:"阳性"},
           {id:9,name:"未查"}
        ],
        showOne:false
      }
    },
    methods: {
      clickuseradvicecell(row, column, cell, event) {
      },
      onTranPatient: function(tranPatient) {
        this.currentPatient = tranPatient
      },
      CreateTime(time) {
        return uParseTime(time, '{y}-{m}-{d} {h}:{i}:{s}')
      },
   
     
    
     
      handleSizeChange(limit) {
        this.limit = limit
        this.getlist()
      },
      handleCurrentChange(page) {
        this.page = page
      
        this.getlist()
      },
      changeStatus(val){
        if(val == 1 ){
          this.show = false
        }
        if(val == 2){
          this.show = true
        }
      },
      saveVasularAccess(formName){
         this.$refs[formName].validate((valid)=>{
           if(valid){
              var blood_name = ""
              for(let i=0;i<this.blood_access_part_opera.length;i++){
                 if(this.blood_access_part_opera[i].id == this.form.blood_access_part_opera_id){
                     blood_name = this.blood_access_part_opera[i].name
                 }
              }
              var inflow_pass = ""
              for(let i=0;i<this.optionsPass.length;i++){
                 if(this.optionsPass[i].id == this.form.inflow_pass){
                     inflow_pass = this.optionsPass[i].name
                 }
              }
              console.log("params",this.form.blood_access_part_id)
              
              var params = {
                patient_id:this.patientID,
                access_project:parseInt(this.form.access_project),
                start_time:this.form.start_time,
                blood_access_part_opera_id:blood_name,
                blood_access_part_id:this.form.blood_access_part_id,
                inflow_pass:inflow_pass,
                first_start_time:this.form.first_start_time,
                user_status:this.form.user_status,
                stop_reason:this.form.stop_reason,
                remark:this.form.remark,
                stop_time:this.form.stop_time,
                other_vascular:this.form.other_vascular,
                ci_type:this.form.ci_type,
                blood_cultupe:this.form.blood_cultupe,
                sequelae_type:this.form.sequelae_type,
              }
              console.log("params",params)
            
             saveVasularAccess(params).then(response=>{
                if(response.data.state == 1){
                   var access =  response.data.data.access
                   console.log("access",access)
                   this.$message.success("保存成功")
                   this.dialogVisible = false
                   this.getlist()
                   this.form.blood_access_part_opera_id=""
                   this.form.blood_access_part_id = ""
                   this.inflow_pass = ""
                   this.user_status = ""
                   this.stop_reason = ""
                   this.remark = ""
                }else{
                   this.$message.error("该日期数据已存在!")
                }
             })
           }  
         })
      },
      getlist(){
         var params = {
               page:this.page,
               limit:this.limit,
               patient_id:this.patientID,
           }
        getAllVascularAccessList(params).then(response=>{
           if(response.data.state == 1){
             var list =  response.data.data.list
             console.log("list",list)
             this.tableData = list
             var total = response.data.data.total
             console.log("total",total)
             this.total = total
             var doctor = response.data.data.doctor
             console.log("doctor",doctor)
             this.doctorList = doctor
           }  
        })   
      },
     getTime(value, temp) {
        if (value != undefined) {
            return uParseTime(value, temp);
        }
        return "";
     },
     handleUpdateAdviceTemplate(id){
        getVascularAccessByDetail(id).then(response=>{
           if(response.data.state ==1){
             var accessDetail =  response.data.data.accessDetail
             console.log("accessDetail",accessDetail)
             this.form.id = accessDetail.id
             this.form.access_project = accessDetail.access_project.toString()
             var arr = []
             var arrOne = []
             var arrThree = []
             var arrFour = []

              if(accessDetail.access_project == "1"){
               for(let i=0;i<this.new_blood_access_part_opera.length;i++){ 
                 if(this.new_blood_access_part_opera[i].field_type == 1){
                     arr.push(this.new_blood_access_part_opera[i])     
                 }
                }
                this.blood_access_part_opera = arr


              for(let j=0;j<this.new_blood_access_part.length;j++){
                 if(this.new_blood_access_part[j].field_type == 1){
                     arrThree.push(this.new_blood_access_part[j])
                 }
                 
                }
                this.blood_access_part = arrThree
              }

              if(accessDetail.access_project == "2"){
               this.showOne = true
               for(let i=0;i<this.new_blood_access_part_opera.length;i++){ 
                  if(this.new_blood_access_part_opera[i].field_type == 2){
                     arrOne.push(this.new_blood_access_part_opera[i])  
                  }
                
                }
                this.blood_access_part_opera = arrOne

                for(let j=0;j<this.new_blood_access_part.length;j++){
                   if(this.new_blood_access_part[j].field_type == 2){
                     arrFour.push(this.new_blood_access_part[j])
                   }    
                }
                this.blood_access_part = arrFour
              } 
            
           
             this.form.blood_access_part_id = accessDetail.blood_access_part_id
             

              var blood_part = 0
              for(let i=0;i<this.blood_access_part_opera.length;i++){
                 if(accessDetail.blood_access_part_opera_id == this.blood_access_part_opera[i].name){
                    blood_part = this.blood_access_part_opera[i].id
                 }
              }
             this.form.blood_access_part_opera_id = blood_part

             this.form.first_start_time = this.getTime(accessDetail.first_start_time,"{y}-{m}-{d}")

             var inflow_id = 0
             for(let i=0;i<this.optionsPass.length;i++){
               if(this.optionsPass[i].name == accessDetail.inflow_pass){
                  inflow_id = this.optionsPass[i].id
               }
             }
             this.form.inflow_pass = inflow_id
             this.form.remark = accessDetail.remark
             this.form.start_time = this.getTime(accessDetail.start_time,"{y}-{m}-{d}")
             this.form.stop_reason = accessDetail.stop_reason
             this.form.stop_time = this.getTime(accessDetail.stop_time,"{y}-{m}-{d}")
 
             this.form.user_status = accessDetail.user_status
             this.form.other_vascular = accessDetail.other_vascular
             this.form.ci_type = accessDetail.ci_type
             this.form.blood_cultupe = accessDetail.blood_cultupe
             this.form.sequelae_type = accessDetail.sequelae_type
             if(accessDetail.user_status == 1){
               this.show = false
             }
             if(accessDetail.user_status == 2){
               this.show = true
             }
             this.editDialogVisible = true
           }
        }) 
     },
     getDoctor(id){
       var name = ""
       for(let i=0;i<this.doctorList.length;i++){
          if(id == this.doctorList[i].admin_user_id){
             name = this.doctorList[i].user_name
          }
       }
       return name
     },
     handleDeleteAdviceTemplate(id,index){
       this.$confirm("确认删除吗?", "删除", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning"
      })
        .then(() => {
          DeleteVascularAccess(id).then(response => {
            if(response.data.state == 1){
              var msg = response.data.data.msg
              this.tableData.splice(index, 1);
              this.$message.success("删除成功!")
            }
             
            
          });
        })
        .catch(() => {});
     },
     updatedVasularAccess(formName){
        this.$refs[formName].validate((valid)=>{
           if(valid){
              var blood_name = ""
              for(let i=0;i<this.blood_access_part_opera.length;i++){
                 if(this.blood_access_part_opera[i].id == this.form.blood_access_part_opera_id){
                     blood_name = this.blood_access_part_opera[i].name
                 }
              }
            //   var blood_part = ""
            //   for(let i=0;i<this.blood_access_part.length;i++){
            //      if(this.form.blood_access_part_id == this.blood_access_part[i].id){
            //         blood_part = this.blood_access_part[i].name
            //      }
            //   }
              var inflow_pass = ""
              for(let i=0;i<this.optionsPass.length;i++){
                 if(this.optionsPass[i].id == this.form.inflow_pass){
                     inflow_pass = this.optionsPass[i].name
                 }
              }
              var params = {
                id:this.form.id,
                patient_id:this.patientID,
                access_project:parseInt(this.form.access_project),
                start_time:this.form.start_time,
                blood_access_part_opera_id:blood_name,
                blood_access_part_id:this.form.blood_access_part_id,
                inflow_pass:inflow_pass,
                first_start_time:this.form.first_start_time,
                user_status:this.form.user_status,
                stop_reason:this.form.stop_reason,
                remark:this.form.remark,
                stop_time:this.form.stop_time,
                patient_id:this.patientID,
                other_vascular:this.form.other_vascular,
                ci_type:this.form.ci_type,
                blood_cultupe:this.form.blood_cultupe,
                sequelae_type:this.form.sequelae_type
              }
            
              updatedVasularAccess(params).then(response=>{
                if(response.data.state == 1){
                  var access =  response.data.data.access
                  console.log("access",access)
                  this.$message.success("保存成功")
                  this.editDialogVisible = false
                  this.getlist()
                }else{
                   this.$message.error("该日期数据已存在!")
                }
              })
           }
        })
     },
     rowClick(row){
       console.log("row",row)
       this.$router.push({path:'/patients/patient/'+this.patientID+'/vascularAccessDetail/'+row.id})
     },
       showInnerDialog: function(val) {
        this.InnerDialogProps.visibility = true
        switch (val) {
        
          case '17': // 血管通路
            this.InnerDialogProps.values = this.blood_access_part
            this.InnerDialogProps.titles = '血管通路部位'
            this.InnerDialogProps.type = 'blood_access_part_id'
            this.InnerDialogProps.selected = this.form.blood_access_part_id
            this.InnerDialogProps.isShowTextArea = false
            break

        
        }
      },
       innerDialogComfirm: function(val) {
         this.InnerDialogProps.visibility = false
         switch (val.type) {
           case 'blood_access_part_id':
           this.form.blood_access_part_id = val.value.join(',')
           break
        }
      },
      innerDialogCancle: function() {
        this.InnerDialogProps.visibility = false
      },
      getAccessList(){
        getAccessList().then(response=>{
           if(response.data.state == 1){
             var blood_access_part_opera = response.data.data.blood_access_part_opera
             console.log("blood_access_part_operahhahs",blood_access_part_opera)
             this.new_blood_access_part_opera = blood_access_part_opera
             var blood_access_part = response.data.data.blood_access_part
             console.log("blood_access",blood_access_part)
             this.new_blood_access_part = blood_access_part

             console.log("通路项目",this.form.access_project)
             
             var arr = []
             var arrOne = []
             if(this.form.access_project == 1 ){
               for(let i=0;i<this.new_blood_access_part_opera.length;i++){
                  if(this.new_blood_access_part_opera[i].field_type == 1){
                     arr.push(this.new_blood_access_part_opera[i])
                  }

               }
  
               for(let i=0;i<this.new_blood_access_part.length;i++){
                  if(this.new_blood_access_part[i].field_type == 1){
                     arrOne.push(this.new_blood_access_part[i])
                  }
               }
             }
            this.blood_access_part_opera = arr
            this.blood_access_part = arrOne
           }
        })
      },
      changeRadio(val){
        console.log("val",val)
        var arr = []
        var arrOne = []
        var arrTwo = []
        var arrThree = []
        for(let i=0;i<this.new_blood_access_part_opera.length;i++){
           if(this.new_blood_access_part_opera[i].field_type == 1){
              arr.push(this.new_blood_access_part_opera[i])
           }
           if(this.new_blood_access_part_opera[i].field_type == 2){
             arrOne.push(this.new_blood_access_part_opera[i])
           }
        } 

        for(let i=0;i<this.new_blood_access_part.length;i++){
          if(this.new_blood_access_part[i].field_type == 1){
             arrTwo.push(this.new_blood_access_part[i])
          }
          if(this.new_blood_access_part[i].field_type == 2){
             arrThree.push(this.new_blood_access_part[i])
          }
        }

        if(val == 1){
           this.blood_access_part_opera = arr
           this.blood_access_part = arrTwo
           this.showOne = false
          
        }
        if(val == 2){
          this.blood_access_part_opera = arrOne
          this.blood_access_part = arrThree
          this.showOne = true
        }
        
        console.log("arr",arr)
        console.log("arrOne",arrOne)
      }
    },
    created() {
      const id = this.$route.params && this.$route.params.id
      this.patientID = parseInt(id)
      this.getlist()
      //获取血管通路
      this.getAccessList()
    },
   
  }
</script>

<style>
  .oictable ::-webkit-scrollbar {
    height: 15px;
  }
</style>

<style rel="stylesheet/scss" lang="scss">
   ::-webkit-scrollbar{
      height:15px;
   }

</style>

