<template>
    <div class="doctorAdvices">
        <div>
            <div style="padding:0 1rem;height:1.875rem;line-height:1.875rem;color: #323233;font-size:0.875rem;">
                上机时间:{{getTimes(dialysis_order.start_time)}}
                透析时长:{{prescription_prop.dialysis_duration_hour}}时<span v-if="prescription_prop.dialysis_duration_minute>0">{{prescription_prop.dialysis_duration_minute}}分</span>
                <!-- 下机时间:{{getTimes(dialysis_order.end_time)}} -->
            </div>
            <table class="table doctorTable">
              <tr @click="cancelAdviceSelect">
                <th width="50">开嘱医生</th>
                <th width="60">开始时间</th>
                <th width="60">医嘱内容</th>
                <th width="60">执行时间</th>
                <th width="50">执行护士</th>
                <th v-if="org_id!=10445 && org_id!=10597&&org_id!=10599 && org_id!=10624" width="50">核对人员</th>
              </tr>
              <template v-for="(group, group_index) in advice_groups">
                <tr
                  v-for="(advice, advice_index) in group.advices"
                  :key="'No' + advice.id + advice_index + group_index"
                  :class="{ 'row-class-active': current_group_index == group_index && current_advice_index < 0 }"
                >
                  <td
                    v-if="advice_index == 0"
                    :rowspan="group.advices.length"
                    @click="selectGroupAdviceAction(group_index, -1, null,group)"
                  >
                    <span v-if="advice.parent_id==0">{{getXuserName(advice.advice_doctor)}}</span>
                    <span v-else></span>
                  </td>

                  <td
                    v-if="advice_index == 0"
                    :rowspan="group.advices.length"
                    @click="selectGroupAdviceAction(group_index, -1, null,group)"
                  >
                    <span>{{uParseTime(advice.start_time, '{m}-{d} {h}:{i}')}}</span>
                  </td>

                  <td
                    :class="{ 'advice_content': advice.parent_id == 0, 'subadvice_content': advice.parent_id > 0, 'td-active':current_group_index == group_index  && advice.is_selected == 1 }"
                    @click="selectAdviceAction(group_index, advice_index, advice)"
                  >
                    <div class="txt">
                      <span>{{advice.advice_name }}</span>
                      <span v-if="advice.advice_desc">({{ advice.advice_desc }}{{advice.drug_spec_unit}})</span>
                      <span v-if="advice.prescribing_number">&nbsp;&nbsp;{{advice.prescribing_number}}{{advice.prescribing_number_unit}}</span>
                      <span v-if="advice.single_dose && template_id == 6">{{advice.single_dose}}{{advice.single_dose_unit}}</span>
                      <span v-if="advice.single_dose && template_id != 6">单次用量{{advice.single_dose}}{{advice.single_dose_unit}}</span>

                      <span v-if="advice.parent_id == 0">{{advice.delivery_way}}</span>
                      <span v-if="advice.parent_id == 0 && org_id!=10599">{{advice.execution_frequency}}</span>
                      <span
                        v-if="advice.parent_id == 0 && advice.remark.length > 0 && org_id!=10644"
                      >({{advice.remark}})</span>

                      <span v-if="org_id==10644 && advice.remark!=''">({{advice.remark}})</span>
                      <!-- 药品剩余数 -->
                      <!-- <van-badge :content="5"></van-badge> -->
                    </div>
                  </td>

                  <td
                    :class="{'td-active':current_group_index == group_index  && advice.is_selected == 1}"
                    @click="selectAdviceAction(group_index,advice_index, advice)"
                  >{{uParseTime(advice.execution_time, '{m}-{d} {h}:{i}')}}
                  </td>

                  <td
                    :class="{'td-active':current_group_index == group_index  && advice.is_selected == 1}"
                    @click="selectAdviceAction(group_index,advice_index, advice)"

                  > {{getXuserName(advice.execution_staff)}}
                  </td>
                  <td v-if="org_id!=10445 && org_id!=10597 && org_id!=10599 && org_id!=10624"
                      :class="{'td-active':current_group_index == group_index  && advice.is_selected == 1}"
                      @click="selectAdviceAction(group_index,advice_index, advice)"
                  >{{getXuserName(advice.checker)}}
                  </td>
                </tr>
              </template>
            </table>

            <van-popup v-model="doctorAdviceshow" get-container="#app" class="doctorAdvicePopup" style="z-index:3200;" position="top" :style="{ height: '100%' }">
                <newAddOrder :patient_id="patient.id" :predialysis='predialysis'
                :drug_spec_unit_options="unitsOption"
                :delivery_way_options="deliveryWayOptions"
                :execution_frequency_options="executionFrequencyOptions"
                :single_dose_unit_options="unitsOption"
                :prescribing_number_unit_options="unitsOption"
                :advice_templates="adviceTemplates"
                :all_drug="all_drug"
                :medicals="medicals"
                :base_drug_list="base_drug_list"
                :base_drug_config="base_drug_config"
                :private_drug_config="private_drug_config"
                :schedulePatient="schedulePatient"
                @close="closeDoctorAdviceshow"
                @did-create-advices="didCreateAdvices"></newAddOrder>
            </van-popup>
            <van-popup v-model="modifyDoctorAdviceshow" get-container="#app" class="doctorAdvicePopup" style="z-index:3200;" position="top" :style="{ height: '100%' }">
                <modifyOrder ref="modify_advice_form"
                @did-modify="didModifyAdvice"
                :drug_spec_unit_options="unitsOption"
                :delivery_way_options="deliveryWayOptions"
                :execution_frequency_options="executionFrequencyOptions"
                :single_dose_unit_options="unitsOption"
                :prescribing_number_unit_options="unitsOption"
                :all_drug="all_drug"
                :medicals="medicals"
                :base_drug_list="base_drug_list"
                :base_drug_config="base_drug_config"
                :private_drug_config="private_drug_config"
                @close="closeModifyDoctorAdviceshow"></modifyOrder>
            </van-popup>
            <van-popup v-model="subDrugshow" get-container="#app" class="doctorAdvicePopup" style="z-index:3200;" position="top" :style="{ height: '100%' }">
                <subDrugOrder ref="subdrug_form"
                @back="subDrugshow = false"
                @did-create-subdrug="didAddSubdrug"
                :single_dose_unit_options="unitsOption"
                :prescribing_number_unit_options="unitsOption"
                :drug_spec_unit_options="unitsOption"
                :all_drug="all_drug"
                :medicals="medicals"
                :base_drug_list="base_drug_list"
                :base_drug_config="base_drug_config"
                :private_drug_config="private_drug_config"></subDrugOrder>
            </van-popup>
            <van-popup v-model="modifySubDrugshow" get-container="#app" class="doctorAdvicePopup" style="z-index:3200;" position="top" :style="{ height: '100%' }">
                <modifySubDrugOrder ref="sub_modify_advice_form"
                @back="modifySubDrugshow = false"
                @did-modify="didModifyAdvice"
                :drug_spec_unit_options="unitsOption"
                :delivery_way_options="deliveryWayOptions"
                :execution_frequency_options="executionFrequencyOptions"
                :single_dose_unit_options="unitsOption"
                :prescribing_number_unit_options="unitsOption"
                :all_drug="all_drug"
                :medicals="medicals"
                :base_drug_list="base_drug_list"
                :base_drug_config="base_drug_config"
                :private_drug_config="private_drug_config"></modifySubDrugOrder>
            </van-popup>
            <van-popup v-model="adviceTemplateShow" get-container="#app" class="doctorAdvicePopup" style="z-index:3200;" position="top" :style="{ height: '100%' }">
                <adviceTemplate
                @back="adviceTemplateShow = false"
                @finish="didSelectTemplateAdvice"
                :predialysis='predialysis'
                :templates="adviceTemplates"
                :schedulePatient="schedulePatient"></adviceTemplate>
            </van-popup>
            <van-popup v-model="lastOrNextAdviceShow" get-container="#app" class="doctorAdvicePopup" style="z-index:3200;" position="top" :style="{ height: '100%' }">
                <lastOrNextAdvice  :schedulePatient="schedulePatient" @back='lastOrNextAdviceShow = false' @finish="didLastOrNext"></lastOrNextAdvice>
            </van-popup>
        </div>
        <div>
            <div class="preserveBox" v-if="currentSubAdvices.length > 0">
              <div style="margin: 0 auto;">
                <span @click="modifySubdviceAction">修改子医嘱</span>
                <span @click="deleteSubAdviceAction">删除子医嘱</span>
              </div>
            </div>
            <div class="preserveBox">
              <div style="display: flex;justify-content: space-between;width: 100%;">
                  <span v-if="his_is_open != 1 || org_id == 10721" :class="{ forbid: is_has_create != true }" @click="showNew">新增</span>

                  <mu-date-input v-if="isShowExce && (org_id == 10215 || org_id == 4 || org_id == 9671 || org_id == 10340)" type="dateTime" class="dateInput" label="执行" v-model="newExecTime" @focus="onFocusExecTime" @change="execTimeFunc" container="dialog" :clock-type="'24hr'" actions></mu-date-input>
                  <span v-if="isShowExce && (org_id != 10215  && org_id != 4 && org_id!=9671 && org_id !=10340)" :class="{ forbid: is_has_exce != true || allForbidShow != true }" @click="execAdvice">执行</span>
                  <!-- <span v-if="isShowExce && (org_id ==10164 || org_id==10480)" :class="{ forbid: is_has_exce != true || allForbidShow != true }" @click="BatchExecAdvice">全部执行</span> -->
                  <!-- <span v-if="org_id ==10164 || org_id ==10480" :class="{ forbid: (current_advice&& current_advice.parent_id > 0) || is_has_check != true || allForbidShow != true }" @click="checkAdviceTwo">全部核对</span> -->
                  <mu-date-input v-if="isShowMofifyExce && (org_id == 10215  || org_id == 4 || org_id == 10340 || org_id == 9671)" type="dateTime" class="dateInput2" label="修改执行" v-model="newModifyExecTime" @focus="onFocusModifyExecTime" @change="modifyExecTimeFunc" container="dialog" :clock-type="'24hr'" actions></mu-date-input>
                  <span v-if="isShowMofifyExce && (org_id != 10215  && org_id != 4 && org_id!=10340 && org_id!=9671)" :class="{ forbid: (current_advice&& current_advice.parent_id > 0) || is_has_modify_exce != true || allForbidShow != true }" @click="modifyExecAdvice">修改执行</span>
                  <span v-if="org_id!=10445 && org_id!=3877  && org_id !=10344 && org_id!=10597 && org_id!=10599 && org_id!=10624" :class="{ forbid: (current_advice&& current_advice.parent_id > 0) || is_has_check != true || allForbidShow != true }" @click="checkAdvice">核对</span>

                  <span v-if="org_id ==3877  || org_id ==10344" :class="{ forbid: (current_advice&& current_advice.parent_id > 0) || is_has_check != true || allForbidShow != true }" @click="checkAdviceOne">核对</span>
                  <span v-if="his_is_open != 1 || org_id == 10721" :class="{ forbid: current_advice == null || current_advice.parent_id > 0 ||  currentAdvices.length != 1 || is_has_create != true || allForbidShow != true }" @click="openNewChild">添加子药</span>
                  <span v-if="his_is_open != 1 || org_id == 10721" :class="{ forbid: current_group_index < 0 ||  currentAdvices.length != 1  || current_select_object== 2 || (is_has_modify != true && is_has_modify_other != true) || allForbidShow != true || modifyOrDelete != true }" @click="modifyAdviceAction">修改</span>
                  <span v-if="(his_is_open != 1 || org_id == 10721) && user_type !=3 " :class="{ forbid: current_group_index < 0 || currentAdvices.length <= 0 || (is_has_del != true && is_has_del_other != true) || allForbidShow != true || modifyOrDelete != true , deleteColor : true }" @click="deleteAdviceAction">删除</span>
                  <!-- <span v-if="his_is_open != 1 && user_type ==3" @click="checkAllAdvice">全部核对</span> -->
              </div>
            </div>
        </div>
        <!-- 执行 -->
        <!-- <div style="overflow-y: auto;height: 300px;"> -->
          <mt-datetime-picker
            class="datetimePicker"
            ref="exec_time"
            type="datetime"
            @confirm="handleExecTime"
            v-model="nowExecTime"
            ></mt-datetime-picker>
        <!-- </div> -->
       <mt-datetime-picker
        class="datetimePicker"
        ref="batch_exec_time"
        type="datetime"
        @confirm="BatchHandleExecTime"
        v-model="nowExecTime"
        ></mt-datetime-picker>
        <!-- 修改执行 -->
        <div style="overflow-y: auto;">
          <mt-datetime-picker
          class="datetimePicker"
          ref="mofify_exec_time"
          type="datetime"
          @confirm="handleModifyExecTime"
          v-model="nowExecTime"
          style="height: 300px;"
          ></mt-datetime-picker>
        </div>
        <mt-datetime-picker
        class="datetimePicker"
        ref="check_time"
        type="datetime"
        @confirm="handleCheckTime"
        v-model="newCheckTime"
        ></mt-datetime-picker>

       <mt-datetime-picker
        class="datetimePicker"
        ref="batch_check_time"
        type="datetime"
        @confirm="BatchHandleCheckTime"
        v-model="newCheckTime"
        ></mt-datetime-picker>

        <van-action-sheet
        class="actionSheet"
        v-model="sheetShow"
        :actions="actions"
        cancel-text="取消"
        close-on-click-action
        @select="onCancelSheet"
        />

      <van-popup
        v-model="infor_visibility"
        class="advicePopup"
        get-container="#today_panel"
      >
        <infor-sub-menu
        :visibility="infor_visibility"
        v-on:menu-cancle-three="menuCancleFour"
        v-on:menu-comfirm-three="menuComfirmFour"
        >
      </infor-sub-menu>
      </van-popup>
      <!-- <div class="checkBox4"  @click="tiaozhuan" ref="moveBtn2">
        <img src="../../../assets/images/check2.png" @mousedown="down2" @touchstart="down2"
        @mousemove="move2"
        @touchmove="move2"
        @mouseup="end2"
        @touchend="end2"
        @touchcancel="end2" alt="">
      </div> -->
    </div>
</template>

<script>
import {Dialog, Toast,Badge } from 'vant'
import {parseTime} from '@/utils'
import {uParseTime} from '@/utils/tools'
import newAddOrder from './components/newAddOrder'
import modifyOrder from './components/modifyOrder'
import subDrugOrder from './components/subDrugOrder'
import modifySubDrugOrder from './components/modifySubDrugOrder'
import adviceTemplate from './components/adviceTemplate'
import lastOrNextAdvice from './components/lastOrNextAdvice'
import {GetAllDrug} from '@/api/drug/drug'
import {
  batchCreateAdvices,
  CheckDoctorAdvice,
  checkMobileDoctorAdvice,
  CreateDoctorAdvice,
  DeleteDoctorAdviceNew,
  DeleteSubDoctorAdvice,
  EditDoctorAdvice,
  ExecDoctorAdvice,
  getAdviceConfig,
  GetLastOrNextDoctorAdvice,
  ModifyExecDoctorAdvice,
  batchAdviceExecution,
  batchAdviceCheck,
  batchDeleteAdvice,
  execProject,
  checkProject,
  getScheduleByPatient,
  BatchHandleExecTime,
  batchCheckAdvice
} from '@/api/advice'
import { saveMobileInformation } from '@/api/dialysis'
import {getDataConfig} from '@/utils/data'
import request from '@/utils/request'
import InforSubMenu from "../dialog/subMenu/InforSubMenu.vue"
import { HTML5_FMT } from 'moment'
export default {
  components: {
    newAddOrder,
    modifyOrder,
    subDrugOrder,
    modifySubDrugOrder,
    adviceTemplate,
    lastOrNextAdvice,
    InforSubMenu
  },
  props: {
    advice_groups: {
      type: Array,
      default: () => {
        return []
      }
    },
    patient_prop: {
      type: Object
    },
    advice_list_prop: {
      type: Array
    },
    admin_users_prop: {
      type: Array
    },
    dialysis_order: {
      type: Object
    },
    his_is_open: {
      type: Number,
      default: () => {
        return 0
      }
    },
    is_advice_open: {
      type: Number,
      default: () => {
        return 0
      }
    },
    predialysis: {
      type: Object
    },
    prescription_prop:{
      type: Object,
    },
    // tableIndex:Number
  },
  data () {
    return {
      newModifyExecTime: '',
      newExecTime: '',
      result: [],
      template_id: 0,
      allChecked: false,
      sheetShow: false,
      actions: [{ name: '选择模板' }, { name: '新增医嘱' }, { name: '上一方' }],
      doctorAdviceshow: false,
      current_select_object: -1,
      current_group_index: -1,
      current_advice_index: -1,
      current_advice: null,
      currentAdviceIdsStr: '',
      currentAdvices: [],
      currentSubAdvices: [],
      private_drug_config: null,
      base_drug_config: null,
      base_drug_list: [],
      all_drug: [],
      medicals: [],
      adviceTemplates: [],
      drugOptions: {},
      deliveryWayOptions: [],
      executionFrequencyOptions: [],
      unitsOption: [],
      unitsObj: [],
      nowExecTime: new Date(),
      newCheckTime:new Date(),
      isShowExce: true,
      isShowMofifyExce: false,
      modifyDoctorAdviceshow: false,
      subDrugshow: false,
      modifySubDrugshow: false,
      adviceTemplateShow: false,
      lastOrNextAdviceShow: false,

      is_has_create: true,
      is_has_exce: true,
      is_has_check: true,
      is_has_modify_exce: true,
      is_has_modify: true,
      is_has_modify_other: true,
      is_has_del: true,
      is_has_del_other: true,
      isShowDialog: true,
      isShowExce: true,
      isShowMofifyExce: false,

      allForbidShow: true,
      modifyOrDelete: true,
      curerentAdvice: {},
      schedulePatient: {},
      infor_visibility:false,
      user_type:0,

      nx2: '',
      ny2: '',
      dx2: '',
      dy2: '',
      xPum2: '',
      yPum2: '',
      position2:{
        x: 0,
        y: 0
      },
      moveBtn2:{},
      
    }
  },
  created () {
    console.log("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",this.advice_groups)
    var user_type =  this.$store.getters.user.user.user_type
    this.user_type =user_type

    this.getPermission()
    this.template_id = this.$store.getters.user.template_info.template_id
    this.org_id = this.$store.getters.user.template_info.org_id
    var date = this.$route.query && this.$route.query.date
    date *= 1000
    var newDate = new Date(date)

    var otherDate = new Date()

    var y = newDate.getFullYear()
    var m = newDate.getMonth() + 1
    var d = newDate.getDate()

    var h = otherDate.getHours()
    var mm = otherDate.getMinutes()

    if (isNaN(y) || isNaN(m) || isNaN(d)) {
      newDate = new Date()
      y = newDate.getFullYear()
      m = newDate.getMonth() + 1
      d = newDate.getDate()
    }
    this.record_date =
            y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d)
    this.request_record_date = this.record_date
    this.patient = this.patient_prop

    this.adviceList = this.advice_list_prop
    this.admin_users = this.admin_users_prop
    this.doctor = this.$store.getters.user.user.user_name
    this.getAdviceConfig()

    this.unitsOption = getDataConfig('hemodialysis', 'units')
    for (var index in this.unitsOption) {
      this.unitsObj[this.unitsOption[index].id] = this.unitsOption[index]
    }

    var start_time = y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d) + ' ' +
            (h < 10 ? '0' + h : h) + ':' + (mm < 10 ? '0' + mm : mm) + ':00'
    this.start_time = start_time
    this.start_time_str = start_time

    var patient_id = this.$route.query.patient_id
    var date = this.$route.query.date

    this.GetAllDrug(patient_id)

    // 获取今日排班数据
    this.getScheduleByPatient(patient_id, date)
  },
  mounted(){
    // this.moveBtn2 = this.$refs.moveBtn2
    // if (sessionStorage.getItem('checkBtnTop2')) {
    //   this.moveBtn2.style.top = sessionStorage.getItem('checkBtnTop2')
    //   this.moveBtn2.style.bottom = 'initial'
    // }
    // if (sessionStorage.getItem('checkBtnLeft2')) {
    //   this.moveBtn2.style.left = sessionStorage.getItem('checkBtnLeft2')
    // }
  },
  methods: {
    // tiaozhuan(){
    //   this.tableIndex = 1
    //   this.$emit('tiaozhuan',this.tableIndex)
    //   console.log('this.index',this.tableIndex);
    // },
    menuComfirmFour:function(start_time,remark){
       var params = {
         patient_id:this.$route.query.patient_id,
         record_date:parseInt(this.$route.query.date),
         start_time:start_time,
         module:4,
         remark:remark,
       }

      saveMobileInformation(params).then(response=>{
        if(response.data.state == 1){
           this.infor_visibility = false
           Toast.success('申请成功')
        }
      })
    },
    menuCancleFour:function(){
     this.infor_visibility = false

    },
    onFocusExecTime () {
      this.newExecTime = new Date()
    },
    onFocusModifyExecTime () {
      this.newModifyExecTime = new Date(this.currentAdvices[0].execution_time * 1000)
    },
    modifyExecTimeFunc (time) {
      if (this.is_has_modify_exce == false) {
        Toast.fail('你没有修改执行医嘱的权限')
        return false
      }
      var exceTime = this.handleTime(time)
      var currentAdviceIdArr = []
      var exceParams = null
      for (let i = 0; i < this.currentAdvices.length; i++) {
        if (this.currentAdvices[i].execution_state == 1) {
          currentAdviceIdArr.push(this.currentAdvices[i].id)
        }
      }
      this.currentAdviceIdsStr = currentAdviceIdArr.join(',')
      if (this.current_select_object == 1) {
        exceParams = {
          groupno: 0,
          advice_id: this.currentAdviceIdsStr,
          execution_time: exceTime,
          patient_id:this.$route.query.patient_id,
        }
      } else {
        var group = this.advice_groups[this.current_group_index]
        exceParams = {
          groupno: group.group_no <= 0 ? 0 : group.group_no,
          advice_id: group.group_no <= 0 ? group.advices[0].id : 0,
          execution_time: exceTime,
          patient_id:this.$route.query.patient_id,
          record_date:this.$route.query.date,
        }
      }
      exceParams['mode'] = 8
      ModifyExecDoctorAdvice(exceParams)
        .then(response => {
          if (response.data.state == 0) {
            Toast.fail(response.data.msg)
            if(response.data.code == 600000008){
                this.infor_visibility = true
            }
            return false
          } else {
            // 新版医嘱
            Toast.success('修改成功！')
            var advice = response.data.data.advice
            if (this.current_select_object == 1) {
              var ids = this.currentAdviceIdsStr.split(',')
              var adviceArr = this.advice_groups[this.current_group_index]
                .advices
              for (let i = 0; i < adviceArr.length; i++) {
                for (let a = 0; a < ids.length; a++) {
                  if (
                    (adviceArr[i].execution_state == 1 &&
                                            adviceArr[i].id == ids[a]) ||
                                        (adviceArr[i].execution_state == 1 &&
                                            adviceArr[i].parent_id == ids[a])
                  ) {
                    adviceArr[i].execution_time = advice.execution_time
                  }
                }
              }
            } else {
              for (let index = 0; index < group.advices.length; index++) {
                const adv = group.advices[index]
                if (adv.execution_state == 1) {
                  adv.execution_time = advice.execution_time
                }
              }
            }
          }
        })
        .catch(err => {
          Toast.fail(err)
          return false
        })
    },
    // 执行弹窗
    execTimeFunc (time) {

      if (this.is_has_exce == false) {
        Toast.fail('你没有执行医嘱的权限')
        return false
      }

      if (this.currentAdvices.length <= 0) {
        return
      }
      if (this.current_select_object == 1) {
        var isExecution = true
        var adviceArr = this.advice_groups[this.current_group_index].advices
        for (let i = 0; i < adviceArr.length; i++) {
          if (
            (adviceArr[i].execution_state == 2 &&
                    adviceArr[i].is_selected == 1) || (adviceArr[i].execution_state == 0 &&
                    adviceArr[i].is_selected == 1)
          ) {
            isExecution = false
          }
        }
        if (isExecution) {
          Toast.fail('所选医嘱已停止或执行')
          return false
        }

        for (let i = 0; i < adviceArr.length; i++) {
          if (
            adviceArr[i].is_selected == 1 &&
                    adviceArr[i].checker > 0 &&
                    adviceArr[i].checker == this.$store.getters.user.admin.id
          ) {
            Toast.fail('核对与执行不能是同一人')
            return false
          }
        }
        var currentAdviceIdArr = []
        for (let i = 0; i < adviceArr.length; i++) {
          if (adviceArr[i].is_selected == 1) {
            currentAdviceIdArr.push(adviceArr[i].id)
          }
        }
        this.currentAdviceIdsStr = currentAdviceIdArr.join(',')
        this.nowExecTime = new Date(adviceArr[0].start_time * 1000)

      } else {
        if (!(this.current_group_index >= 0 && this.current_advice_index < 0)) {
          return
        }
        var isExecution = true
        var group_top_advice = this.advice_groups[this.current_group_index]
          .advices[0]

        var adviceArr = this.advice_groups[this.current_group_index].advices
        for (let i = 0; i < adviceArr.length; i++) {
          if (
            adviceArr[i].is_selected == 1 &&
                    adviceArr[i].execution_state == 2
          ) {
            isExecution = false
          }
        }
        if (isExecution) {
          Toast.fail('所选医嘱已停止或执行')
          return false
        }

        for (let i = 0; i < adviceArr.length; i++) {
          if (
            adviceArr[i].is_selected == 1 &&
                    adviceArr[i].checker > 0 &&
                    adviceArr[i].checker == this.$store.getters.user.admin.id
          ) {
            Toast.fail('核对与执行不能是同一人')
            return false
          }
        }

        this.nowExecTime = new Date(group_top_advice.start_time * 1000)

      }

      var exceTime = this.handleTime(time)
      var exceParams = null
      if (this.advice_groups[this.current_group_index].advices[0].origin == 2) {
        var group = this.advice_groups[this.current_group_index]
        if (this.current_select_object == 1) {
          exceParams = {
            origin: 2,
            groupno: 0,
            advice_id: this.currentAdviceIdsStr,
            execution_time: exceTime,
            record_date:this.$route.query.date,
            patient_id:this.$route.query.patient_id,
          }
          exceParams['mode'] = '6'
        } else {
          let arr = []
          group.advices.map(item => {
            arr.push(item.id)
          })
          let str = arr.join(',')
          exceParams = {
            origin: 2,
            groupno: group.group_no <= 0 ? 0 : group.group_no,
            advice_id: str,
            execution_time: exceTime,
            record_date:this.$route.query.date,
            patient_id:this.$route.query.patient_id,
          }
          exceParams['mode'] = '6'
        }
      } else {
        if (this.current_select_object == 1) {
          exceParams = {
            origin: 1,
            groupno: 0,
            advice_id: this.currentAdviceIdsStr,
            execution_time: exceTime,
            record_date:this.$route.query.date,
            patient_id:this.$route.query.patient_id,
          }
        } else {
          var group = this.advice_groups[this.current_group_index]
          exceParams = {
            origin: 1,

            groupno: group.group_no <= 0 ? 0 : group.group_no,
            advice_id: group.group_no <= 0 ? group.advices[0].id : 0,
            execution_time: exceTime,
            record_date:this.$route.query.date,
            patient_id:this.$route.query.patient_id,
          }
        }
        Toast.loading({forbidClick: true, duration: 0})
        exceParams['mode'] = '6'
      }

      if (this.advice_groups[this.current_group_index].advices[0].projectType == 2) {
        let data = {
          execution_time: exceTime,
          project_id: this.advice_groups[this.current_group_index].advices[0].id,
          record_date:this.$route.query.date,
          patient_id:this.$route.query.patient_id,
        }
        execProject(data).then(response => {
          if (response.data.state == 0) {
            Toast.fail(response.data.msg)
            if(response.data.code == 600000008){
                this.infor_visibility = true
            }
            return false
          } else {
            Toast.success('执行成功！')
            var advice = response.data.data.project
            // if (this.current_select_object == 1) {
            var ids = this.currentAdviceIdsStr.split(',')
            var adviceArr = this.advice_groups[this.current_group_index]
              .advices
            for (let i = 0; i < adviceArr.length; i++) {
              for (let a = 0; a < ids.length; a++) {

                if (adviceArr[i].execution_state != 1 && adviceArr[i].id == ids[a]) {
                  adviceArr[i].execution_staff = advice.execution_staff
                  adviceArr[i].execution_time = advice.execution_time
                  adviceArr[i].execution_state = advice.execution_state
                }
              }
            }
            // }
          }
        }).catch(err => {
          Toast.fail(err)
          return false
        })
      } else {
        console.log("执行whwhhwhwhwhw",exceParams)
        ExecDoctorAdvice(exceParams).then(response => {
          if (response.data.state == 0) {
            console.log("hhhhhhhhhhhhhhhwowowoo")
            Toast.fail(response.data.msg)
            if(response.data.code == 600000008){
               this.infor_visibility = true
            }
            return false
          } else {
            console.log("hahhahah",response.data.data.msg)
            if (response.data.data.msg == 1 || response.data.data.msg == 2 || response.data.data.msg == 3 ||  response.data.data.msg == 6  ||  response.data.data.msg == 7 || response.data.data.msg == 'ok' || response.data.data.msg == 12) {
             
              Toast.success('执行成功！')
              var advice = response.data.data.advice
              if(response.data.data.msg == 12){
                Toast.success('请选择正确的自备药!,执行失败!')
                return
              }
              if (this.current_select_object == 1) {
                var ids = this.currentAdviceIdsStr.split(',')
                var adviceArr = this.advice_groups[this.current_group_index].advices

                for (let i = 0; i < adviceArr.length; i++) {
                  for (let a = 0; a < ids.length; a++) {
                    if ((adviceArr[i].execution_state == 2 &&adviceArr[i].id == ids[a]) ||(adviceArr[i].execution_state == 2 &&adviceArr[i].parent_id == ids[a])) {
                      adviceArr[i].execution_staff = advice.execution_staff
                      adviceArr[i].execution_time = advice.execution_time
                      adviceArr[i].execution_state = advice.execution_state
                    }
                  }
                }
              } else {
                var adviceArr = this.advice_groups[this.current_group_index]
                  .advices
                for (let i = 0; i < adviceArr.length; i++) {
                  if (
                    (adviceArr[i].execution_state == 2 &&
                                            adviceArr[i].groupno == exceParams.groupno)
                  ) {
                    adviceArr[i].execution_staff = advice.execution_staff
                    adviceArr[i].execution_time = advice.execution_time
                    adviceArr[i].execution_state = advice.execution_state
                  }
                }
              }

              if (response.data.data.msg == 2) {
                Toast.success('库存数量不足，请入库,执行失败!')
              }
              if (response.data.data.msg == 3) {
                Toast.success('无库存，请入库,执行失败!')
              }
              if (response.data.data.msg == 6) {
                Toast.success('执行失败,请重新执行,执行失败!')
              }

              if (response.data.data.msg == 7) {

                Toast.success('单位不统一,执行失败!')
              }
             
            } else {
              for (let index = 0; index < group.advices.length; index++) {
                const adv = group.advices[index]
                if (adv.execution_state != 1) {
                  adv.execution_staff = advice.execution_staff
                  adv.execution_time = advice.execution_time
                  adv.execution_state = advice.execution_state
                }
              }
            }
          }
        }).catch(err => {
          console.log("hhhhhhhwowoowode122")
          Toast.fail(err)
          return false
        })
      }
    },
    getTimes (time) {
      return parseTime(time, '{h}:{i}')
    },
    getXuserName (id) {
      if (id <= 0) {
        return ''
      }
      var name = ''
      if (
        this.admin_users == null ||
                typeof this.admin_users.length === 'undefined'
      ) {
        return name
      }
      var leng = this.admin_users.length
      if (leng == 0) {
        return name
      }
      for (let index = 0; index < leng; index++) {
        if (this.admin_users[index].id == id) {
          name = this.admin_users[index].name
          break
        }
      }
      return name
    },
    uParseTime (time, format) {
      if (time == 0) {
        return ''
      }
      return uParseTime(time, format)
    },
    toggle () {
      if (this.allChecked) {
        this.result = []
        for (let i = 0; i < this.advice_list_prop.length; i++) {
          this.result.push(this.advice_list_prop[i].id)
        }
      } else {
        this.result = []
      }
    },
    checkGroup (arr) {
      if (arr.length == this.advice_list_prop.length) {
        this.allChecked = true
      } else {
        this.allChecked = false
      }
      let num = 0
      let newNum = 0 // 判断修改和删除显示状态
      this.advice_list_prop.map(item => {
        if (arr.indexOf(item.id) > -1) {
          if ((item.execution_state == 1 && item.check_state == 1)) {
            num++
          }
          if (item.execution_state == 1) {
            newNum++
          }
        }
      })
      if (num == this.advice_list_prop.length) {
        this.allForbidShow = false
      } else {
        this.allForbidShow = true
      }
      if (newNum == this.advice_list_prop.length) {
        this.modifyOrDelete = false
      } else {
        this.modifyOrDelete = true
      }
    },
    onCancelSheet (action, index) {

      if (action.name == '新增医嘱') {
        this.currentAdvices = []
        this.currentSubAdvices = []
        for (let i = 0; i < this.advice_groups.length; i++) {
          for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
            var advices = this.advice_groups[i].advices[y]
            advices.is_selected = 0
          }
        }

        this.index = 1
        this.current_group_index = -1
        this.current_advice_index = -1
        this.current_advice = null

        this.doctorAdviceshow = true
      } else if (action.name == '选择模板') {
        this.adviceTemplateShow = true
      } else if (action.name == '上一方') {
        this.lastOrNextAdviceShow = true
      }
    },
    showNew () {
      if (this.is_has_create != true) {
        Toast.fail('你没有新增医嘱的权限')
        return false
      }
      this.sheetShow = true
    },
    GetAllDrug (id) {
      const params = {
        patient_id: id
      }
      GetAllDrug(params).then(response => {
        if (response.data.state == 1) {
          this.all_drug = []
          var medicalList = response.data.data.private_drug_list
          var base_drug_list = response.data.data.base_drug_list
          var base_drug_cofig = response.data.data.base_drug_config
          var private_drug_cofig = response.data.data.private_drug_config

          if (private_drug_cofig != null && private_drug_cofig.drug_start == 1) {
            for (let i = 0; i < medicalList.length; i++) {
              if (medicalList[i].drug_specs != null) {
                for (let a = 0; a < medicalList[i].drug_specs.length; a++) {
                  medicalList[i].drug_specs[a]['type'] = 2
                }
              }
              let obj = {
                drug_name: '',
                drug_desc: '',
                delivery_way: '',
                execution_frequency: '',
                single_dose: '',
                single_dose_unit: '',
                prescribing_number: '',
                prescribing_number_unit: '',
                type_id: '',
                type: '',
                custom_id: '',
                drug_specs: []
              }

              medicalList[i].drug_name = medicalList[i].drug_name + '(自备药)'
              obj.drug_name = medicalList[i].drug_name
              obj.delivery_way = medicalList[i].delivery_way
              obj.execution_frequency = medicalList[i].execution_frequency
              obj.single_dose = medicalList[i].single_dose
              obj.prescribing_number = medicalList[i].prescribing_number
              obj.type_id = medicalList[i].id
              obj.type = 2
              obj.drug_specs = medicalList[i].drug_specs
              obj.id = medicalList[i].id
              this.all_drug.push(obj)
            }
          }

          for (let i = 0; i < base_drug_list.length; i++) {
            if (base_drug_list[i].drug_specs != null) {
              for (let a = 0; a < base_drug_list[i].drug_specs.length; a++) {
                base_drug_list[i].drug_specs[a]['type'] = 1
              }
            }
            let obj = {
              drug_name: '',
              drug_desc: '',
              delivery_way: '',
              execution_frequency: '',
              single_dose: '',
              single_dose_unit: '',
              prescribing_number: '',
              prescribing_number_unit: '',
              type_id: '',
              type: '',
              custom_id: '',
              drug_specs: []
            }

            obj.drug_name = base_drug_list[i].drug_name
            obj.delivery_way = base_drug_list[i].delivery_way
            obj.execution_frequency = base_drug_list[i].execution_frequency
            obj.single_dose = base_drug_list[i].single_dose
            obj.prescribing_number = base_drug_list[i].prescribing_number
            obj.type_id = base_drug_list[i].id
            obj.type = 1
            obj.drug_specs = base_drug_list[i].drug_specs
            obj.id = base_drug_list[i].id
            this.all_drug.push(obj)
          }
        }

        this.medicals = medicalList
        this.base_drug_list = base_drug_list
        this.private_drug_config = private_drug_cofig
        this.base_drug_cofig = base_drug_cofig
      })
    },
    getAdviceConfig () {
      getAdviceConfig().then(response => {
        if (response.data.state == 1) {
          this.deliveryWayOptions =
                    response.data.data.drugways === null
                      ? []
                      : response.data.data.drugways
          this.executionFrequencyOptions =
                    response.data.data.efs === null ? [] : response.data.data.efs

          this.adviceTemplates =
                    response.data.data.advice_templates === null
                      ? []
                      : response.data.data.advice_templates
        }
      })
    },
    didCreateAdvices: function (advices) {
      if (advices.length == 0) {
        return
      }
      for (let i = 0; i < advices.length; i++) {
        advices[i]['is_selected'] = 0
      }

      var new_group = Object.assign(
        {},
        {
          group_no: 0,
          start_time: 0,
          advices: []
        }
      )
      new_group.group_no = advices[0].groupno
      new_group.start_time = advices[0].start_time
      new_group.advices.push(...advices)

      var insertIndex = -1
      for (let index = 0; index < this.advice_groups.length; index++) {
        const group = this.advice_groups[index]
        group['origin'] = 1
        if (group.start_time < new_group.start_time) {
          insertIndex = index
          break
        }
      }

      if (insertIndex < 0) {
        this.advice_groups.push(new_group)
      } else {
        this.advice_groups.splice(insertIndex, 0, new_group)
      }
      this.index = 0
      this.advice_groups.sort((a, b) => a.start_time - b.start_time)
    },
    closeDoctorAdviceshow () {
      this.doctorAdviceshow = false
    },
    // 执行弹窗
    execAdvice () {
      if (this.is_has_exce == false) {
        Toast.fail('你没有执行医嘱的权限')
        return false
      }
      if (this.currentAdvices.length <= 0) {

      }
      if (this.current_select_object == 1) {
        var isExecution = true
        var adviceArr = this.advice_groups[this.current_group_index].advices
        for (let i = 0; i < adviceArr.length; i++) {
          if ((adviceArr[i].execution_state == 2 && adviceArr[i].is_selected == 1) || (adviceArr[i].execution_state == 0 && adviceArr[i].is_selected == 1)) {
            isExecution = false
          }
        }
        if (isExecution) {
          Toast.fail('所选医嘱已停止或执行')
          return false
        }

        for (let i = 0; i < adviceArr.length; i++) {
          if (adviceArr[i].is_selected == 1 && adviceArr[i].checker > 0 && adviceArr[i].checker == this.$store.getters.user.admin.id) {
            Toast.fail('核对与执行不能是同一人')
            return false
          }
        }
        var currentAdviceIdArr = []
        for (let i = 0; i < adviceArr.length; i++) {
          if (adviceArr[i].is_selected == 1) {
            currentAdviceIdArr.push(adviceArr[i].id)
          }
        }
        this.currentAdviceIdsStr = currentAdviceIdArr.join(',')
        // this.nowExecTime = new Date(adviceArr[0].start_time * 1000)
        this.nowExecTime = new Date()
      } else {
        if (!(this.current_group_index >= 0 && this.current_advice_index < 0)) {

        }
        var isExecution = true
        var group_top_advice = this.advice_groups[this.current_group_index]
          .advices[0]

        var adviceArr = this.advice_groups[this.current_group_index].advices
        for (let i = 0; i < adviceArr.length; i++) {
          if (
            adviceArr[i].is_selected == 1 &&
                    adviceArr[i].execution_state == 2
          ) {
            isExecution = false
          }
        }
        if (isExecution) {
          Toast.fail('所选医嘱已停止或执行')
          return false
        }

        for (let i = 0; i < adviceArr.length; i++) {
          if (
            adviceArr[i].is_selected == 1 &&
                    adviceArr[i].checker > 0 &&
                    adviceArr[i].checker == this.$store.getters.user.admin.id
          ) {
            Toast.fail('核对与执行不能是同一人')
            return false
          }
        }
        // this.nowExecTime = new Date(group_top_advice.start_time * 1000)
        this.nowExecTime = new Date()
      }
      this.$refs.exec_time.open()
    },
    BatchExecAdvice(){
      this.$refs.batch_exec_time.open()
    },
    handleExecTime (time) {
      var exceTime = this.handleTime(time)
      var exceParams = null
      if (this.advice_groups[this.current_group_index].advices[0].origin == 2) {
        var group = this.advice_groups[this.current_group_index]
        if (this.current_select_object == 1) {
          exceParams = {
            origin: 2,
            groupno: 0,
            advice_id: this.currentAdviceIdsStr,
            execution_time: exceTime,
            record_date:this.$route.query.date,
            patient_id:this.$route.query.patient_id,
          }
          exceParams['mode'] = '6'
        } else {
          let arr = []
          group.advices.map(item => {
            arr.push(item.id)
          })
          let str = arr.join(',')
          exceParams = {
            origin: 2,
            groupno: group.group_no <= 0 ? 0 : group.group_no,
            advice_id: str,
            execution_time: exceTime,
            record_date:this.$route.query.date,
            patient_id:this.$route.query.patient_id,
          }
          exceParams['mode'] = '6'
        }
      } else {
        if (this.current_select_object == 1) {
          exceParams = {
            origin: 1,
            groupno: 0,
            advice_id: this.currentAdviceIdsStr,
            execution_time: exceTime,
            record_date:this.$route.query.date,
            patient_id:this.$route.query.patient_id,
          }
        } else {
          var group = this.advice_groups[this.current_group_index]
          exceParams = {
            origin: 1,

            groupno: group.group_no <= 0 ? 0 : group.group_no,
            advice_id: group.group_no <= 0 ? group.advices[0].id : 0,
            execution_time: exceTime,
            record_date:this.$route.query.date,
            patient_id:this.$route.query.patient_id,
          }
        }
        Toast.loading({forbidClick: true, duration: 0})
        exceParams['mode'] = '6'
      }
      if (this.advice_groups[this.current_group_index].advices[0].projectType == 2) {
        let data = {
          execution_time: exceTime,
          project_id: this.advice_groups[this.current_group_index].advices[0].id,
          team_id: this.advice_groups[this.current_group_index].advices[0].team_id,
          is_check_team: this.advice_groups[this.current_group_index].advices[0].is_check_team,
          record_date:this.$route.query.date,
          patient_id:this.$route.query.patient_id,
        }
        execProject(data).then(response => {
          if (response.data.state == 0) {
            Toast.fail(response.data.msg)
            return false
          } else {
            Toast.success('执行成功！')
            var advice = response.data.data.project
            // if (this.current_select_object == 1) {
            var ids = this.currentAdviceIdsStr.split(',')
            var adviceArr = this.advice_groups[this.current_group_index]
              .advices
            for (let i = 0; i < adviceArr.length; i++) {
              for (let a = 0; a < ids.length; a++) {

                if (adviceArr[i].execution_state != 1 && adviceArr[i].id == ids[a]) {
                  adviceArr[i].execution_staff = advice.execution_staff
                  adviceArr[i].execution_time = advice.execution_time
                  adviceArr[i].execution_state = advice.execution_state
                }
              }
            }
            // }
          }
        }).catch(err => {
          Toast.fail(err)
          return false
        })
      } else {

        console.log("执行--------------",exceParams)
        ExecDoctorAdvice(exceParams).then(response => {
          if (response.data.state == 0) {
            Toast.fail(response.data.msg)
            return false
          } else {
            if (response.data.data.msg == 1 || response.data.data.msg == 2 || response.data.data.msg == 3 || response.data.data.msg == 6|| response.data.data.msg == 7 || response.data.data.msg == 12) {
              Toast.success('执行成功！')
              var advice = response.data.data.advice
              if (this.current_select_object == 1) {
                var ids = this.currentAdviceIdsStr.split(',')
                var adviceArr = this.advice_groups[this.current_group_index].advices

                for (let i = 0; i < adviceArr.length; i++) {
                  for (let a = 0; a < ids.length; a++) {
                    if ((adviceArr[i].execution_state == 2 &&adviceArr[i].id == ids[a]) ||(adviceArr[i].execution_state == 2 &&adviceArr[i].parent_id == ids[a])) {
                      adviceArr[i].execution_staff = advice.execution_staff
                      adviceArr[i].execution_time = advice.execution_time
                      adviceArr[i].execution_state = advice.execution_state
                    }
                  }
                }
              } else {
                var adviceArr = this.advice_groups[this.current_group_index].advices
                for (let i = 0; i < adviceArr.length; i++) {
                  if ((adviceArr[i].execution_state == 2 &&adviceArr[i].groupno == exceParams.groupno)) {
                    adviceArr[i].execution_staff = advice.execution_staff
                    adviceArr[i].execution_time = advice.execution_time
                    adviceArr[i].execution_state = advice.execution_state
                  }
                }
              }

              if (response.data.data.msg == 2) {
                Toast.success('库存数量不足，请入库,执行失败!')
              }
              if (response.data.data.msg == 3) {
                Toast.success('无库存，请入库,执行失败!')
              }

              if (response.data.data.msg == 6) {
                Toast.success('执行失败,请重新执行')
              }

              if (response.data.data.msg == 7) {

                Toast.success('单位不匹配,执行失败!')
              }

              if(response.data.data.msg == 12){
                Toast.success(advice.advice_name+'不是正确的自备药,执行失败,请重新开药!')
                return
              }
            } else if (resp.data.data.msg == 'ok') {

              var adviceArr = this.advice_groups[this.current_group_index].advices
              for (let i = 0; i < adviceArr.length; i++) {
                if ((adviceArr[i].execution_state == 2 && adviceArr[i].groupno == exceParams.groupno)) {
                  for (let j = 0; j < advice.length; j++) {
                    adviceArr[i].execution_staff = advice[j].execution_staff
                    adviceArr[i].execution_time = advice[j].execution_time
                    adviceArr[i].execution_state = advice[j].execution_state
                  }
                }
              }
            } else {
              for (let index = 0; index < group.advices.length; index++) {
                const adv = group.advices[index]
                if (adv.execution_state != 1) {
                  adv.execution_staff = advice.execution_staff
                  adv.execution_time = advice.execution_time
                  adv.execution_state = advice.execution_state
                }
              }
            }
          }
        }).catch(err => {
          Toast.fail(err)
          return false
        })
      }
    },
    BatchHandleExecTime(time){
       var exceTime = this.handleTime(time)
       var params = {
        execution_time: exceTime,
        patient_id:parseInt(this.$route.query.patient_id),
        record_date:parseInt(this.$route.query.date)
       }
       console.log("params----",params)
      BatchHandleExecTime(params).then(response=>{

      })
    },
    handleTime (time) {
      var year = time.getFullYear()
      var month = time.getMonth() + 1
      var day = time.getDate()
      var hour = time.getHours()
      var minute = time.getMinutes()
      if (month < 10) {
        month = '0' + month
      }
      if (day < 10) {
        day = '0' + day
      }
      if (hour < 10) {
        hour = '0' + hour
      }
      if (minute < 10) {
        minute = '0' + minute
      }
      return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':00'
    },
    // 修改执行
    modifyExecAdvice: function () {
      if (this.is_has_modify_exce == false) {
        Toast.fail('你没有修改执行医嘱的权限')
        return false
      }
      this.nowExecTime = new Date(this.currentAdvices[0].execution_time * 1000)
      this.$refs.mofify_exec_time.open()
    },
    handleModifyExecTime (time) {
      // 新版医嘱
      var exceTime = this.handleTime(time)
      var currentAdviceIdArr = []
      var exceParams = null
      for (let i = 0; i < this.currentAdvices.length; i++) {
        if (this.currentAdvices[i].execution_state == 1) {
          currentAdviceIdArr.push(this.currentAdvices[i].id)
        }
      }
      this.currentAdviceIdsStr = currentAdviceIdArr.join(',')
      if (this.current_select_object == 1) {
        exceParams = {
          groupno: 0,
          advice_id: this.currentAdviceIdsStr,
          execution_time: exceTime,
          patient_id:this.$route.query.patient_id,
          record_date:this.$route.query.date,
        }
      } else {
        var group = this.advice_groups[this.current_group_index]
        exceParams = {
          groupno: group.group_no <= 0 ? 0 : group.group_no,
          advice_id: group.group_no <= 0 ? group.advices[0].id : 0,
          execution_time: exceTime,
          patient_id:this.$route.query.patient_id,
          record_date:this.$route.query.date,
        }
      }
      exceParams['mode'] = 8
      ModifyExecDoctorAdvice(exceParams)
        .then(response => {
          if (response.data.state == 0) {
            Toast.fail(response.data.msg)
            return false
          } else {
            // 新版医嘱


            Toast.success('修改成功！')
            var advice = response.data.data.advice
            if (this.current_select_object == 1) {
              var ids = this.currentAdviceIdsStr.split(',')
              var adviceArr = this.advice_groups[this.current_group_index]
                .advices
              for (let i = 0; i < adviceArr.length; i++) {
                for (let a = 0; a < ids.length; a++) {
                  if (
                    (adviceArr[i].execution_state == 1 &&
                                            adviceArr[i].id == ids[a]) ||
                                        (adviceArr[i].execution_state == 1 &&
                                            adviceArr[i].parent_id == ids[a])
                  ) {
                    adviceArr[i].execution_time = advice.execution_time
                  }
                }
              }
            } else {
              for (let index = 0; index < group.advices.length; index++) {
                const adv = group.advices[index]
                if (adv.execution_state == 1) {
                  adv.execution_time = advice.execution_time
                }
              }
            }
          }
        })
        .catch(err => {
          Toast.fail(err)
          return false
        })
    },
    checkAdvice () {
      if (this.is_has_check == false) {
        Toast.fail('你没有核对医嘱的权限')
        return false
      }

      if (this.currentAdvices.length <= 0) {
        return
      }

      if (this.current_select_object == 1) {
        var isCheck = true
        var adviceArr = this.advice_groups[this.current_group_index].advices
        for (let i = 0; i < adviceArr.length; i++) {
          if ((adviceArr[i].check_state == 0 && adviceArr[i].is_selected == 1) || (adviceArr[i].check_state == 2 && adviceArr[i].is_selected == 1)) {
            isCheck = false
          }
        }
        if (isCheck) {
          Toast.fail('所选医嘱已核对')
          return false
        }

        for (let i = 0; i < adviceArr.length; i++) {
          if (adviceArr[i].is_selected == 1 &&adviceArr[i].execution_staff > 0 &&adviceArr[i].execution_staff == this.$store.getters.user.admin.id) {
            Toast.fail('核对与执行不能是同一人')
            return false
          }
          if(this.org_id == 10460){
           if (adviceArr[i].is_selected == 1 &&adviceArr[i].execution_staff == 0) {
            Toast.fail('请先执行再核对')
            return false
          }
         }
        }



        var currentAdviceIdArr = []
        for (let i = 0; i < adviceArr.length; i++) {
          if (adviceArr[i].is_selected == 1) {
            currentAdviceIdArr.push(adviceArr[i].id)
          }
        }

        if (currentAdviceIdArr.length <= 0) {
          Toast.fail('请选择想要核对的医嘱')
          return false
        }

        this.currentAdviceIdsStr = currentAdviceIdArr.join(',')
        if (this.currentAdviceIdsStr == '') {
          Toast.fail('请选择想要核对的医嘱')
          return false
        }
      } else {
        if (!(this.current_group_index >= 0 && this.current_advice_index < 0)) {
          return
        }
        var isCheck = true
        var group_top_advice = this.advice_groups[this.current_group_index]
          .advices[0]

        var adviceArr = this.advice_groups[this.current_group_index].advices
        var advice = null
        for (let i = 0; i < adviceArr.length; i++) {
          if (adviceArr[i].check_state == 0) {
            isCheck = false
          }
        }

        if (isCheck) {
          Toast.fail('所选医嘱已核对')
          return false
        }

        for (let i = 0; i < adviceArr.length; i++) {
          if (adviceArr[i].is_selected == 1 &&adviceArr[i].execution_staff > 0 &&adviceArr[i].execution_staff == this.$store.getters.user.admin.id) {
            Toast.fail('核对与执行不能是同一人')
            return false
          }

          if(this.org_id == 10460){
           if (adviceArr[i].is_selected == 1 &&adviceArr[i].execution_staff == 0) {
            Toast.fail('请先执行再核对')
            return false
          }
         }

        }


      }

      Dialog.confirm({
        title: '医嘱核对',
        message: '确认提交核对?'
      }).then(() => {
        var params = null
        Toast.loading({forbidClick: true, duration: 0})
        if (this.advice_groups[this.current_group_index].advices[0].origin == 2) {
          if (this.current_select_object == 1) {
            params = {
              origin: 2,
              advice_id: this.currentAdviceIdsStr,
              record_date:this.$route.query.date,
              patient_id:this.$route.query.patient_id
            }
          } else {
            var group = this.advice_groups[this.current_group_index]
            let arr = []
            group.advices.map(item => {
              arr.push(item.id)
            })
            let str = arr.join(',')
            params = {
              origin: 2,
              advice_id: str
            }
          }
        } else {
          if (this.current_select_object == 1) {
            params = {
              origin: 1,
              groupno: 0,
              advice_id: this.currentAdviceIdsStr,
              record_date:this.$route.query.date,
              patient_id:this.$route.query.patient_id
            }
          } else {
            var group = this.advice_groups[this.current_group_index]
            params = {
              origin: 1,
              groupno: group.group_no <= 0 ? 0 : group.group_no,
              advice_id: group.group_no <= 0 ? group.advices[0].id : 0,
              record_date:this.$route.query.date,
              patient_id:this.$route.query.patient_id
            }
          }
        }

        params['mode'] = '7'
        if (this.advice_groups[this.current_group_index].advices[0].projectType == 2) {
          let data = {
            project_id: this.advice_groups[this.current_group_index].advices[0].id,
            team_id: this.advice_groups[this.current_group_index].advices[0].team_id,
            is_check_team: this.advice_groups[this.current_group_index].advices[0].is_check_team,
            record_date:this.$route.query.date,
            patient_id:this.$route.query.patient_id
          }
          checkProject(data).then(response => {
            if (response.data.state == 0) {
              Toast.fail('你没有权限核对医嘱！')
              if(response.data.code == 600000008){
                this.infor_visibility = true
              }
              return false
            } else {
              Toast.success('核对成功！')
              var advice = response.data.data.project
              var ids = this.currentAdviceIdsStr.split(',')
              var adviceArr = this.advice_groups[this.current_group_index].advices
              for (let i = 0; i < adviceArr.length; i++) {
                for (let a = 0; a < ids.length; a++) {
                  if (adviceArr[i].check_state != 1 && adviceArr[i].id == ids[a]) {
                    adviceArr[i].checker = advice.checker
                    adviceArr[i].check_time = advice.check_time
                    adviceArr[i].check_state = advice.check_state
                  }
                }
              }
            }
          })
        } else {
          CheckDoctorAdvice(params)
            .then(response => {
              if (response.data.state == 0) {
                Toast.fail('你没有权限核对医嘱！')
                if(response.data.code == 600000008){
                  this.infor_visibility = true
                }
                return false
              } else {
                Toast.success('核对成功！')
                if (this.advice_groups[this.current_group_index].advices[0].origin == 2) {
                  if (this.current_select_object == 1) {
                    var advice = response.data.data.advice
                    var ids = this.currentAdviceIdsStr.split(',')
                    var adviceArr = this.advice_groups[this.current_group_index].advices
                    for (let i = 0; i < adviceArr.length; i++) {
                      for (let a = 0; a < advice.length; a++) {
                        if ((adviceArr[i].check_state == 0 &&adviceArr[i].id == advice[a].id) ||(adviceArr[i].check_state == 0 && adviceArr[i].parent_id == advice[a].id)) {
                          adviceArr[i].checker = advice[a].checker
                          adviceArr[i].check_time = advice[a].check_time
                          adviceArr[i].check_state = advice[a].check_state
                        }
                      }
                    }
                  } else {
                    var advice = response.data.data.advice
                    var adviceArr = this.advice_groups[this.current_group_index].advices

                    for (let i = 0; i < adviceArr.length; i++) {
                      for (let a = 0; a < advice.length; a++) {
                        if (
                          (adviceArr[i].check_state == 0 &&adviceArr[i].id == advice[a].id) ||(adviceArr[i].check_state == 0 &&adviceArr[i].parent_id == advice[a].id)) {
                          adviceArr[i].checker = advice[a].checker
                          adviceArr[i].check_time = advice[a].check_time
                          adviceArr[i].check_state = advice[a].check_state
                        }
                      }
                    }
                  }
                } else {
                  var advice = response.data.data.advice
                  if (this.current_select_object == 1) {
                    var ids = this.currentAdviceIdsStr.split(',')

                    var adviceArr = this.advice_groups[this.current_group_index]
                      .advices

                    for (let i = 0; i < adviceArr.length; i++) {
                      for (let a = 0; a < ids.length; a++) {
                        if ((adviceArr[i].check_state == 0 && adviceArr[i].id == ids[a]) ||(adviceArr[i].check_state == 0 &&adviceArr[i].parent_id == ids[a])) {
                          adviceArr[i].checker = advice.checker
                          adviceArr[i].check_time = advice.check_time
                          adviceArr[i].check_state = advice.check_state
                        }
                      }
                    }
                  } else {
                    for (let index = 0; index < group.advices.length; index++) {
                      const adv = group.advices[index]
                      adv.checker = advice.checker
                      adv.check_time = advice.check_time
                      adv.check_state = advice.check_state
                    }
                  }
                }
              }
            }).catch(err => {
              Toast.fail(err)
            })
        }
      })
      // .catch(err => {
      //   Toast.fail(err);
      // });
    },

    checkAdviceOne(){
       this.newCheckTime = new Date()
       this.$refs.check_time.open()
    },
    checkAdviceTwo(){
      this.newCheckTime = new Date()
      this.$refs.batch_check_time.open()
    },

    closeModifyDoctorAdviceshow () {
      this.modifyDoctorAdviceshow = false
    },
    modifyAdviceAction: function () {

      var group = this.advice_groups[this.current_group_index]

      var advice = this.currentAdvices[0]

      if (advice.origin == 2) {
        Toast.fail('所选医嘱属于his医嘱无法修改医嘱')
        return false
      }

      if (this.currentAdvices.length != 1 || this.current_select_object == 2) {
        return
      }
      if (this.current_group_index < 0) {
        return
      }
      var group = this.advice_groups[this.current_group_index]

      var advice = this.currentAdvices[0]

      if (this.base_drug_cofig != null && this.base_drug_cofig.is_open == 1 && advice.execution_state == 1) {
        Toast.fail('医嘱已执行，无法修改')
        return
      }

      if (this.private_drug_config != null && this.private_drug_config.drug_start == 1 && advice.execution_state == 1) {
        Toast.fail('医嘱已执行，无法修改')
        return
      }

      if (this.current_advice_index >= 0) {
        this.modifyDoctorAdviceshow = true
        var advice = this.currentAdvices[0]
        this.$nextTick(() => {
          this.$refs.modify_advice_form.showWithModify({
            id: advice.id,
            parent_id: advice.parent_id,
            title: advice.advice_name,
            advice_desc: advice.advice_desc,
            advice_doctor: advice.advice_doctor,
            remark: advice.remark,
            start_time: advice.start_time,
            drug_spec: advice.drug_spec,
            drug_spec_unit: advice.drug_spec_unit,
            delivery_way: advice.delivery_way,
            execution_frequency: advice.execution_frequency,
            single_dose: advice.single_dose,
            single_dose_unit: advice.single_dose_unit,
            prescribing_number: advice.prescribing_number,
            prescribing_number_unit: advice.prescribing_number_unit,
            drug_id: advice.drug_id,
            way: advice.way,
            drug_name_id: advice.drug_name_id
          })
        })
      } else {
        if (group.group_no <= 0) {
          this.modifyDoctorAdviceshow = true
          var advice = group.advices[0]
          this.$nextTick(() => {
            this.$refs.modify_advice_form.showWithModify({
              id: advice.id,
              parent_id: advice.parent_id,
              title: advice.advice_name,
              advice_desc: advice.advice_desc,
              remark: advice.remark,
              drug_spec: advice.drug_spec,
              drug_spec_unit: advice.drug_spec_unit,
              delivery_way: advice.delivery_way,
              execution_frequency: advice.execution_frequency,
              single_dose: advice.single_dose,
              single_dose_unit: advice.single_dose_unit,
              prescribing_number: advice.prescribing_number,
              prescribing_number_unit: advice.prescribing_number_unit,
              drug_id: advice.drug_id,
              way: advice.way,
              drug_name_id: advice.drug_name_id
            })
          })
        }
      }
    },
    didModifyAdvice: function (advice) {
      let mode = '2'


      if (
        advice.doctor_advice != this.$store.getters.user.admin.id &&
                advice.doctor_advice > 0
      ) {
        mode = '3'
      }
      Toast.loading({forbidClick: true, duration: 0})
      if (advice.drug_name_id == undefined) {
        advice.drug_name_id = 0
      }
      var patient_id = this.$route.query.patient_id
      var advice_date = this.$route.query.date
      EditDoctorAdvice(
        advice.id,
        {
          advice_name: advice.title,
          advice_desc: advice.advice_desc,
          remark: advice.remark,
          start_time: advice.start_time,
          drug_spec: String(advice.drug_spec),
          drug_spec_unit: advice.drug_spec_unit,
          delivery_way: advice.delivery_way,
          execution_frequency: advice.execution_frequency,
          single_dose: String(advice.single_dose),
          single_dose_unit: advice.single_dose_unit,
          prescribing_number: String(advice.prescribing_number),
          prescribing_number_unit: advice.prescribing_number_unit,
          way: advice.way,
          drug_id: advice.drug_id,
          drug_name_id: advice.drug_name_id
        },
        mode,
        advice_date,
        patient_id
      ).then(rs => {
        if (rs.data.state == 1) {
          var resp_advice = rs.data.data.advice
          // 新版医嘱
          if (!rs.data.data.isChange) {
            var group = this.advice_groups[this.current_group_index]
            for (let index = 0; index < group.advices.length; index++) {
              const advice = group.advices[index]
              if (advice.id == resp_advice.id) {
                advice.advice_name = resp_advice.advice_name
                advice.advice_desc = resp_advice.advice_desc
                advice.remark = resp_advice.remark
                advice.start_time = resp_advice.start_time
                advice.drug_spec = resp_advice.drug_spec
                advice.drug_id = resp_advice.drug_id
                advice.way = resp_advice.way
                advice.drug_name_id = resp_advice.drug_name_id;
                (advice.drug_spec_unit = resp_advice.drug_spec_unit),
                (advice.delivery_way = resp_advice.delivery_way),
                (advice.execution_frequency =
                                    resp_advice.execution_frequency),
                (advice.single_dose = resp_advice.single_dose),
                (advice.single_dose_unit = resp_advice.single_dose_unit),
                (advice.prescribing_number =
                                    resp_advice.prescribing_number),
                (advice.prescribing_number_unit =
                                    resp_advice.prescribing_number_unit)
                break
              }
            }
          } else {
            // var group = this.advice_groups[this.current_group_index]
            // 先删除旧数据，再插入新数据
            var adviceArr = this.advice_groups[this.current_group_index]
              .advices
            for (let y = resp_advice.length - 1; y >= 0; y--) {
              for (let i = adviceArr.length - 1; i >= 0; i--) {
                if (
                  adviceArr[i].id == resp_advice[y].id ||
                            adviceArr[i].parent_id == resp_advice[y].id
                ) {
                  adviceArr.splice(i, 1)
                }
              }
            }
            var newAdvice = {}
            newAdvice['advices'] = resp_advice
            newAdvice['group_no'] = resp_advice[0].groupno
            this.advice_groups.push(newAdvice)
          }

          this.currentAdvices = []
          this.currentSubAdvices = []
          for (let i = 0; i < this.advice_groups.length; i++) {
            for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
              var advices = this.advice_groups[i].advices[y]
              advices.is_selected = 0
            }
          }

          Toast.clear()
          this.modifyDoctorAdviceshow = false
          this.modifySubDrugshow = false
          // this.index = 0
        } else {
           if(rs.data.code == 600000008){
            this.infor_visibility = true
           }
          Toast.fail(rs.data.msg)
        }
      })
        .catch(err => {
          Toast.fail(err)
        })
    },
    deleteAdviceAction: function () {
      // 新版医嘱
      if (this.currentAdvices[0].origin == 2) {
        Toast.fail('所选医嘱属于his医嘱无法删除医嘱')
        return false
      }
      if (this.current_select_object == 1) {
        if (this.currentAdvices.length <= 0) {
          return
        }
        var isShow = true
        for (let i = 0; i < this.currentAdvices.length; i++) {
          if (this.currentAdvices[i].execution_state == 1) {
            isShow = false
          }
        }

        if (this.base_drug_cofig != null && this.base_drug_cofig.is_open == 1 && !isShow) {
          Toast.fail('所选医嘱已执行，无法删除')
          return
        }

        if (this.private_drug_config != null && this.private_drug_config.drug_start == 1 && !isShow) {
          Toast.fail('所选医嘱已执行，无法删除')
          return
        }

        Dialog.confirm({
          title: '删除医嘱',
          message: '确认删除医嘱吗?'
        }).then(() => {
          Toast.loading({forbidClick: true, duration: 0})
          var group_no = 0
          var advice_id = this.currentAdvices.join(',')
          var ids = []
          for (let i = 0; i < this.currentAdvices.length; i++) {
            ids.push(this.currentAdvices[i].id)
          }
          advice_id = ids.join(',')

          let mode = '4'
          if (
            this.currentAdvices[0].advice_doctor !=
                    this.$store.getters.user.admin.id &&
                    this.currentAdvices[0].advice_doctor > 0
          ) {
            mode = '5'
          }
          if (
            this.currentAdvices[0].advice_doctor !=
                    this.$store.getters.user.admin.id
          ) {
          }
          let is_sub = 2
          var doc_advice_date = this.$route.query.date
          var patient_id = this.$route.query.patient_id
          DeleteDoctorAdviceNew(group_no, advice_id, mode, is_sub, patient_id, doc_advice_date)
            .then(rs => {
              if (rs.data.state == 1) {
                Toast.success('删除成功')
                var adviceArr = this.advice_groups[this.current_group_index]
                  .advices

                for (let y = ids.length - 1; y >= 0; y--) {
                  for (let i = adviceArr.length - 1; i >= 0; i--) {
                    if (
                      adviceArr[i].id == ids[y] ||
                                adviceArr[i].parent_id == ids[y]
                    ) {
                      adviceArr.splice(i, 1)
                    }
                  }
                }
                this.currentSubAdvices = []
                this.currentAdvices = []
                for (let i = 0; i < this.advice_groups.length; i++) {
                  for (
                    let y = 0;
                    y < this.advice_groups[i].advices.length;
                    y++
                  ) {
                    var advices = this.advice_groups[i].advices[y]
                    advices.is_selected = 0
                  }
                }
              } else {
                if(rs.data.code == 600000008){
                  this.infor_visibility = true
                }
                Toast.fail(rs.data.msg)
              }
            })
            .catch(err => {
              Toast.fail(err)
            })
        })
      } else {
        if (this.current_group_index < 0) {
          return
        }
        var group = this.advice_groups[this.current_group_index]

        Dialog.confirm({
          title: '删除医嘱',
          message: '确认删除这组医嘱吗?'
        }).then(() => {
          Toast.loading({forbidClick: true, duration: 0})
          var group_no = group.group_no <= 0 ? 0 : group.group_no
          var advice_id = 0
          if (group.group_no <= 0) {
            advice_id = group.advices[0].id
          } else if (this.current_advice != null) {
            group_no = 0
            advice_id = this.current_advice.id
          }

          let mode = '4'
          if (
            group.advices[0].advice_doctor !=
                    this.$store.getters.user.admin.id &&
                    group.advices[0].advice_doctor > 0
          ) {
            mode = '5'
          }
          let is_sub = 2
          var doc_advice_date = this.$route.query.date
          var patient_id = this.$route.query.patient_id
          DeleteDoctorAdviceNew(group_no, advice_id, mode, is_sub, patient_id, doc_advice_date)
            .then(rs => {
              if (rs.data.state == 1) {
                Toast.success('删除成功')
                // if (group.group_no <= 0) {
                //   this.advice_groups.splice(this.current_group_index, 1);
                // } else {
                if (this.current_advice_index >= 0) {
                  // if (group.advices.length <= 1) {
                  //   this.advice_groups.splice(this.current_group_index, 1);
                  // } else {
                  var advice = group.advices[this.current_advice_index]
                  if (advice.parent_id > 0) {
                    group.advices.splice(this.current_advice_index, 1)
                  } else {
                    var child_count = 0
                    for (
                      let index = this.current_advice_index + 1;
                      index < group.advices.length;
                      index++
                    ) {
                      const adv = group.advices[index]
                      if (adv.parent_id == advice.id) {
                        child_count++
                      }
                    }
                    group.advices.splice(
                      this.current_advice_index,
                      child_count + 1
                    )
                  }
                  if (group.advices.length == 0) {
                    this.advice_groups.splice(this.current_group_index, 1)
                  }
                  // }
                } else {
                  this.advice_groups.splice(this.current_group_index, 1)
                }
                // }
                this.cancelAdviceSelect()
              } else {
                if(rs.data.code == 600000008){
                  this.infor_visibility = true
                }
                Toast.fail(rs.data.msg)
              }
            })
            .catch(err => {
              Toast.fail(err)
            })
        })
      }
    },
    checkAllAdvice(){
      var patient_id = this.$route.query.patient_id
      var advice_date = this.$route.query.date
      var params = {
        patient_id:patient_id,
        advice_date:advice_date,
      }
      console.log("params--------",params)
      batchCheckAdvice(params).then(response=>{
        if(response.data.state ==1){
          var adviceList = response.data.data.adviceList
          if(adviceList!=null && adviceList.length>0){
            var adviceArr = this.advice_groups[this.current_group_index].adviceList
            for (let i = 0; i < adviceArr.length; i++) {
              for (let a = 0; a < advice.length; a++) {
                if ((adviceArr[i].check_state == 0 &&adviceArr[i].id == advice[a].id) ||(adviceArr[i].check_state == 0 && adviceArr[i].parent_id == advice[a].id)) {
                  adviceArr[i].checker = advice[a].checker
                  adviceArr[i].check_time = advice[a].check_time
                  adviceArr[i].check_state = advice[a].check_state
                }
              }
            }
          }

          var projectList = response.data.data.projectList
          if(projectList!=null && projectList.length>0){
            var adviceArr = this.advice_groups[this.current_group_index].projectList
            for (let i = 0; i < adviceArr.length; i++) {
              for (let a = 0; a < ids.length; a++) {
                if (adviceArr[i].check_state != 1 && adviceArr[i].id == ids[a]) {
                  adviceArr[i].checker = advice.checker
                  adviceArr[i].check_time = advice.check_time
                  adviceArr[i].check_state = advice.check_state
                }
              }
            }
          }

        }
      })
    },
    openNewChild () {
      if (this.current_advice.origin == 2) {
        Toast.fail('所选医嘱属于his医嘱无法添加子药')
        return false
      }
      if (this.current_advice == null) {
        return
      }

      if (this.currentAdvices.length == 0) {
        return false
      }
      this.current_advice = this.currentAdvices[0]
      this.group_no = this.current_advice.groupno

      if (
        this.current_advice.stop_state == 1 ||
                this.current_advice.execution_state == 1 ||
                this.current_advice.check_state == 1
      ) {
        Toast.fail('所选医嘱已停止或执行或核对')
        return false
      }

      this.index = 2
      var start_time = uParseTime(
        this.current_advice.start_time,
        '{y}-{m}-{d} {h}:{i}'
      )
      this.subDrugshow = true
      this.$nextTick(() => {
        this.$refs.subdrug_form.showWithNewSubDrug(
          this.current_advice.id,
          this.record_date,
          start_time,
          this.current_advice.delivery_way,
          this.current_advice.execution_frequency,
          this.group_no
        )
      })
    },

    didAddSubdrug: function (subdrug) {

      Toast.loading({forbidClick: true, duration: 0})
      let mode = '1'
      var is_child = 2
      batchCreateAdvices(
        this.patient.id,
        subdrug.group_no,
        {
          parent_id: subdrug.parent_id,
          advice_type: 2,
          advice_date: subdrug.record_time,
          start_time: subdrug.start_time + ':00',
          advice_name: subdrug.title,
          advice_desc: subdrug.advice_desc,
          drug_spec: String(subdrug.drug_spec),
          drug_spec_unit: subdrug.drug_spec_unit,
          single_dose: String(subdrug.single_dose),
          single_dose_unit: subdrug.single_dose_unit,
          prescribing_number: String(subdrug.prescribing_number),
          prescribing_number_unit: subdrug.prescribing_number_unit,
          way: subdrug.way,
          drug_id: subdrug.drug_id,
          drug_name_id: subdrug.drug_name_id,
          record_date:parseInt(this.$route.query.date),
          // delivery_way: subdrug.delivery_way,
          // execution_frequency: subdrug.execution_frequency
        },
        mode,
        is_child
      ).then(response => {
          if (response.data.state == 0) {
             if(response.data.code == 600000008){
                this.infor_visibility = true
             }
            Toast.fail(response.data.msg)
            return false
          } else {
            Toast.success('添加成功')
            var resp_advice = response.data.data.advice
            var group_index = this.current_group_index

            var adviceArr = this.advice_groups[this.current_group_index]
              .advices
            for (let i = 0; i < adviceArr.length; i++) {
              if (
                adviceArr[i].id == this.currentAdvices[0].id &&
                            adviceArr[i].is_selected == 1
              ) {
                var advice_index = i
              }
            }

            var group = this.advice_groups[group_index]

            var insert_index = -1
            var last_child_index = -1
            for (
              let index = advice_index + 1;
              index < group.advices.length;
              index++
            ) {
              const advice = group.advices[index]
              if (resp_advice.parent_id != advice.parent_id) {
                insert_index = index
                break
              } else {
                last_child_index = index
              }
            }
            if (insert_index < 0) {
              if (last_child_index < 0) {
                group.advices.splice(advice_index + 1, 0, resp_advice)
              } else {
                group.advices.splice(last_child_index + 1, 0, resp_advice)
              }
            } else {
              group.advices.splice(insert_index, 0, resp_advice)
            }

            this.cancelAdviceSelect()
            // this.$refs.subdrug_form.dismiss()
            // this.index = 0
            // this.$emit("new_create", response.data.data.advice);

            this.currentAdvices = []
            this.currentSubAdvices = []
            for (let i = 0; i < this.advice_groups.length; i++) {
              for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
                var advices = this.advice_groups[i].advices[y]
                advices.is_selected = 0
              }
            }
            this.subDrugshow = false
            return false
          }
        })
        .catch(err => {
          Toast.fail(err)
        })
    },

    modifySubdviceAction: function () {
      if (this.currentSubAdvices.length <= 0) {
        return
      }

      var advice = this.currentSubAdvices[0]

      if (this.base_drug_cofig != null && this.base_drug_cofig.is_open == 1 && advice.execution_state == 1) {
        Toast.fail('医嘱已执行，无法修改')
        return
      }

      if (this.private_drug_config != null && this.private_drug_config.drug_start == 1 && advice.execution_state == 1) {
        Toast.fail('医嘱已执行，无法修改')
        return
      }

      if (this.current_advice_index >= 0) {
        this.modifySubDrugshow = true
        var advice = this.currentSubAdvices[0]
        this.$nextTick(() => {
          this.$refs.sub_modify_advice_form.showWithModify({
            id: advice.id,
            parent_id: advice.parent_id,
            title: advice.advice_name,
            advice_desc: advice.advice_desc,
            advice_doctor: advice.advice_doctor,
            remark: advice.remark,
            drug_spec: advice.drug_spec,
            drug_spec_unit: advice.drug_spec_unit,
            delivery_way: advice.delivery_way,
            execution_frequency: advice.execution_frequency,
            single_dose: advice.single_dose,
            single_dose_unit: advice.single_dose_unit,
            prescribing_number: advice.prescribing_number,
            prescribing_number_unit: advice.prescribing_number_unit,
            record_date:parseInt(this.$route.query.date),
          })
        })
      }
    },

    deleteSubAdviceAction: function () {
      if (this.currentSubAdvices.length <= 0) {
        return
      }
      Dialog.confirm({
        title: '删除医嘱',
        message: '确认删除医嘱吗?'
      }).then(() => {
        Toast.loading({forbidClick: true, duration: 0})
        let is_sub = 1
        let mode = '4'
        if (
          this.currentSubAdvices[0].advice_doctor !=
                    this.$store.getters.user.admin.id &&
                    this.currentSubAdvices[0].advice_doctor > 0
        ) {
          mode = '5'
        }
        var doc_advice_date = this.$route.query.date
        var patient_id = this.$route.query.patient_id
        DeleteDoctorAdviceNew(0, this.currentSubAdvices[0].id, mode, is_sub, patient_id, doc_advice_date)
          .then(rs => {
            if (rs.data.state == 1) {
              Toast.success('删除成功')
              var adviceArr = this.advice_groups[this.current_group_index]
                .advices
              for (let i = adviceArr.length - 1; i >= 0; i--) {
                if (adviceArr[i].id == this.currentSubAdvices[0].id) {
                  adviceArr.splice(i, 1)
                }
              }
              this.currentSubAdvices = []
              this.currentAdvices = []
              for (let i = 0; i < this.advice_groups.length; i++) {
                for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
                  var advices = this.advice_groups[i].advices[y]
                  advices.is_selected = 0
                }
              }
            } else {
              Toast.fail(rs.data.msg)
            }
          })
          .catch(err => {
            Toast.fail(err)
          })
      })
    },
    didSelectTemplateAdvice: function (resp_advices, start_time_str) {
      if (this.private_drug_config != null && this.private_drug_config.drug_start == 1) {
        for (let index = 0; index < resp_advices.length; index++) {
          for (let i = 0; i < this.medicals.length; i++) {
            if (resp_advices[index].drug_id == this.medicals[i].drug_name_id) {
              resp_advices[index].way = 2
              resp_advices[index].drug_name_id = this.medicals[i].drug_name_id
            }
          }
        }
      }
      this.show_dialog_key = 0
      var advices = []
      for (let index = 0; index < resp_advices.length; index++) {
        const adv = resp_advices[index]
        if (adv.parent_id == 0) {
          advices.push({
            id: adv.id,
            title: adv.advice_name,
            advice_desc: adv.advice_desc,
            drug_spec: adv.drug_spec,
            drug_spec_unit: adv.drug_spec_unit,
            delivery_way: adv.delivery_way,
            execution_frequency: adv.execution_frequency,
            single_dose: adv.single_dose,
            single_dose_unit: adv.single_dose_unit,
            prescribing_number: adv.prescribing_number,
            prescribing_number_unit: adv.prescribing_number_unit,
            record_date:parseInt(this.$route.query.date),
            way: adv.way,
            drug_id: adv.drug_id,
            drug_name_id: adv.drug_name_id,
            subdrugs: []
          })
        }
      }
      for (let r_a_i = 0; r_a_i < resp_advices.length; r_a_i++) {
        const resp_adv = resp_advices[r_a_i]
        if (resp_adv.parent_id > 0) {
          for (let p_i = 0; p_i < advices.length; p_i++) {
            const p_adv = advices[p_i]
            if (p_adv.id == resp_adv.parent_id) {
              var subdrug = {
                id: resp_adv.id,
                title: resp_adv.advice_name,
                advice_desc: resp_adv.advice_desc,
                drug_spec: resp_adv.drug_spec,
                drug_spec_unit: resp_adv.drug_spec_unit,
                delivery_way: resp_adv.delivery_way,
                execution_frequency: resp_adv.execution_frequency,
                single_dose: resp_adv.single_dose,
                single_dose_unit: resp_adv.single_dose_unit,
                prescribing_number: resp_adv.prescribing_number,
                prescribing_number_unit: resp_adv.prescribing_number_unit,
                record_date:parseInt(this.$route.query.date),
              }
              p_adv.subdrugs.push(subdrug)
              break
            }
          }
        }
      }


      var data = {}
      data.advice_type = 2
      data.advice_date = parseTime(new Date(), '{y}-{m}-{d}')
      data.start_time = start_time_str
      data.record_date =parseInt(this.$route.query.date)
      var adviceJSONs = []

      for (let index = 0; index < advices.length; index++) {
        const advice = advices[index]
        var json = {
          advice_name: advice.title,
          advice_desc: advice.advice_desc,
          drug_spec: String(advice.drug_spec),
          drug_spec_unit: advice.drug_spec_unit,
          single_dose: String(advice.single_dose),
          single_dose_unit: advice.single_dose_unit,
          prescribing_number: String(advice.prescribing_number),
          prescribing_number_unit: advice.prescribing_number_unit,
          delivery_way: advice.delivery_way,
          execution_frequency: advice.execution_frequency,
          remark: advice.remark,
          drug_id: advice.drug_id,
          way: advice.way,
          drug_name_id: advice.drug_name_id,
          subdrugs: []
        }
        for (let s_i = 0; s_i < advice.subdrugs.length; s_i++) {
          const subdrug = advice.subdrugs[s_i]
          json.subdrugs.push({
            advice_name: subdrug.title,
            advice_desc: subdrug.advice_desc,
            drug_spec: String(subdrug.drug_spec),
            drug_spec_unit: subdrug.drug_spec_unit,
            single_dose: String(subdrug.single_dose),
            single_dose_unit: subdrug.single_dose_unit,
            prescribing_number: String(subdrug.prescribing_number),
            prescribing_number_unit: subdrug.prescribing_number_unit,
            record_date:parseInt(this.$route.query.date),
          })
        }
        adviceJSONs.push(json)
      }

      data.adviceNames = adviceJSONs


      this.loading = true
      let mode = '1'
      var is_child = 1
      let group_no = 0
      let patient_id = this.$route.query.patient_id

      batchCreateAdvices(patient_id, group_no, data, mode, is_child)
        .then(rs => {
          this.loading = false
          var resp = rs.data
          if (resp.state == 1) {
            // 返回数组，清空数据，隐藏弹框
            Toast.success('新增成功！')
            this.didCreateAdvices(resp.data.advices)

            // 新版本医嘱
            this.adviceTemplateShow = false
          } else {
            Toast.fail(resp.msg)
            if(resp.code == 600000008){
              this.adviceTemplateShow = false
              this.infor_visibility = true
            }
          }
        })
        .catch(err => {
          this.loading = false
          Toast.fail(err)
        })
    },
    didLastOrNext (resp_advices, start_time_str) {

      var data = {}
      data.advice_type = 2
      data.advice_date = this.record_date
      data.start_time = start_time_str
      data.record_date = parseInt(this.$route.query.date)
      console.log("data---------",data.record_date)
      var adviceJSONs = []
      for (let index = 0; index < resp_advices.length; index++) {
        const advice = resp_advices[index]
        var json = {
          advice_name: advice.advice_name,
          advice_desc: advice.advice_desc,
          drug_spec: String(advice.drug_spec),
          drug_spec_unit: advice.drug_spec_unit,
          single_dose: String(advice.single_dose),
          single_dose_unit: advice.single_dose_unit,
          prescribing_number: String(advice.prescribing_number),
          prescribing_number_unit: advice.prescribing_number_unit,
          delivery_way: advice.delivery_way,
          execution_frequency: advice.execution_frequency,
          remark: advice.remark,
          subdrugs: [],
          drug_id: advice.drug_id,
          way: advice.way,
          drug_name_id: advice.drug_name_id

        }
        for (let s_i = 0; s_i < advice.children.length; s_i++) {
          const subdrug = advice.children[s_i]
          json.subdrugs.push({
            advice_name: subdrug.advice_name,
            advice_desc: subdrug.advice_desc,
            drug_spec: String(subdrug.drug_spec),
            drug_spec_unit: subdrug.drug_spec_unit,
            single_dose: String(subdrug.single_dose),
            single_dose_unit: subdrug.single_dose_unit,
            prescribing_number: String(subdrug.prescribing_number),
            prescribing_number_unit: subdrug.prescribing_number_unit,
            drug_id: advice.drug_id,
            way: advice.way,
            drug_name_id: advice.drug_name_id
          })
        }
        adviceJSONs.push(json)
      }

      data.adviceNames = adviceJSONs
      this.loading = true
      let mode = '1'
      var is_child = 1
      let patient_id = this.$route.query.patient_id
      batchCreateAdvices(patient_id, 0, data, mode, is_child)
        .then(rs => {
          this.loading = false
          var resp = rs.data
          if (resp.state == 1) {
            // 返回数组，清空数据，隐藏弹框
            Toast.success('新增成功！')
            this.didCreateAdvices(resp.data.advices)

            // 新版医嘱
            this.lastOrNextAdviceShow = false
          } else {
            Toast.fail(resp.msg)
             if(resp.code == 600000008){
                this.lastOrNextAdviceShow = false
                this.infor_visibility = true
             }

          }
        })
        .catch(err => {
          this.loading = false
          Toast.fail(err)
        })
    },
    cancelAdviceSelect: function () {
      this.current_group_index = -1
      this.current_advice_index = -1
      this.current_advice = null
      this.currentAdvices = []
      this.currentSubAdvices = []
    },
    selectAdviceAction: function (group_index, advice_index, advice) {

      this.curerentAdvice = advice
      if (
        (this.current_group_index != -1 &&
                    this.current_group_index != group_index) ||
                advice.parent_id > 0
      ) {
        // 选择其他组，将原来的组选择状态清除
        this.currentAdvices = []
        this.currentSubAdvices = []
        for (let i = 0; i < this.advice_groups.length; i++) {
          for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
            var advices = this.advice_groups[i].advices[y]
            advices.is_selected = 0
          }
        }
      }

      for (let i = 0; i < this.advice_groups.length; i++) {
        // 选择子医嘱，将已经选择的医嘱选择状态清除
        for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
          var advices = this.advice_groups[i].advices[y]
          if (advices.parent_id > 0) {
            advices.is_selected = 0
          }
        }
      }

      for (let i = 0; i < this.advice_groups.length; i++) {
        // 设置选择状态
        for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
          var advices = this.advice_groups[i].advices[y]
          if (advices.id == advice.id) {
            if (advice.is_selected == 1) {
              advice.is_selected = 0
              for (let a = this.currentAdvices.length - 1; a >= 0; a--) {
                if (this.currentAdvices[a].id == advice.id) {
                  this.currentAdvices.splice(a, 1)
                }
              }
            } else {
              advice.is_selected = 1
              if (advice.parent_id == 0) {
                this.currentAdvices.push(advice)
              }
            }
          }
        }
      }

      if (advice.parent_id == 0) {
        this.currentSubAdvices = []
      } else {
        this.currentSubAdvices.push(advice)
      }

      this.current_select_object = 1 // 单条医嘱
      this.current_group_index = group_index
      this.current_advice_index = advice_index
      this.current_advice = advice
    },
    selectGroupAdviceAction: function (
      group_index,
      advice_index,
      advice,
      group
    ) {
      if (
        this.current_group_index != -1 &&
                this.current_group_index != group_index
      ) {
        // 选择其他组，将原来的组选择状态清除
        this.currentAdvices = []
        this.currentSubAdvices = []
        for (let i = 0; i < this.advice_groups.length; i++) {
          for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
            var advices = this.advice_groups[i].advices[y]
            advices.is_selected = 0
          }
        }
      }

      for (let i = 0; i < this.advice_groups.length; i++) {
        // 选择子医嘱，将已经选择的医嘱选择状态清除
        for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
          var advices = this.advice_groups[i].advices[y]
          if (advices.parent_id > 0) {
            advices.is_selected = 0
          }
        }
      }
      this.currentAdvices = []
      for (let i = 0; i < this.advice_groups.length; i++) {
        for (let y = 0; y < this.advice_groups[i].advices.length; y++) {
          var advices = this.advice_groups[i].advices[y]
          if (advices.groupno == group.group_no) {
            advices.is_selected = 1
            this.currentAdvices.push(advices)
          }
        }
      }
      this.current_select_object = 2 // 单组医嘱
      this.current_group_index = group_index
      this.current_advice_index = advice_index
      this.current_advice = advice

    },
    getPermission () {
      request
        .get('/m/api/permission/get', {
          params: {
            create_url: '/m/api/advice/creategroup?mode=1',
            modify_url: '/m/api/advice/edit?mode=2',
            modify_other_url: '/m/api/advice/edit?mode=3',
            del_url: '/m/api/newadvice/delete?mode=4',
            del_other_url: '/m/api/newadvice/delete?mode=5',
            exce_url: '/m/api/advice/exec?mode=6',
            check_url: '/m/api/advice/check?mode=7',
            modify_exce_url: '/m/api/advice/exec/modify?mode=8',
            module: 4
          }
        })
        .then(res => {

          if (res.data.state == 0) {
            this.hasPermission = false
          } else if (res.data.state == 1) {
            this.is_has_create = res.data.data.is_has_create
            this.is_has_exce = res.data.data.is_has_exce
            this.is_has_check = res.data.data.is_has_check
            this.is_has_modify = res.data.data.is_has_modify
            this.is_has_modify_other = res.data.data.is_has_modify_other
            this.is_has_modify_exce = res.data.data.is_has_modify_exce
            this.is_has_del = res.data.data.is_has_del
            this.is_has_del_other = res.data.data.is_has_del_other
          }
        })
    },
    // eslint-disable-next-line camelcase
    getScheduleByPatient (patient_id, schedule_date) {
      var params = {
        patient_id: patient_id,
        schedule_date: schedule_date
      }
      getScheduleByPatient(params).then(response => {
        if (response.data.state == 1) {
          var schedule = response.data.data.schedule
          this.schedulePatient = schedule
        }
      })
    },
    handleCheckTime(time){

      var params = null
        Toast.loading({forbidClick: true, duration: 0})
        if (this.advice_groups[this.current_group_index].advices[0].origin == 2) {
          if (this.current_select_object == 1) {
            params = {
              origin: 2,
              advice_id: this.currentAdviceIdsStr,
              record_date:this.$route.query.date,
              patient_id:this.$route.query.patient_id
            }
          } else {
            var group = this.advice_groups[this.current_group_index]
            let arr = []
            group.advices.map(item => {
              arr.push(item.id)
            })
            let str = arr.join(',')
            params = {
              origin: 2,
              advice_id: str
            }
          }
        } else {
          if (this.current_select_object == 1) {
            params = {
              origin: 1,
              groupno: 0,
              advice_id: this.currentAdviceIdsStr,
              record_date:this.$route.query.date,
              patient_id:this.$route.query.patient_id
            }
          } else {
            var group = this.advice_groups[this.current_group_index]
            params = {
              origin: 1,
              groupno: group.group_no <= 0 ? 0 : group.group_no,
              advice_id: group.group_no <= 0 ? group.advices[0].id : 0,
              record_date:this.$route.query.date,
              patient_id:this.$route.query.patient_id
            }
          }
        }
        var checkTime = this.handleTime(time)
       params['mode'] = '7'

       params['check_time'] = checkTime

       checkMobileDoctorAdvice(params).then(response => {
        if (response.data.state == 0) {
          Toast.fail('你没有权限核对医嘱！')
          if(response.data.code == 600000008){
            this.infor_visibility = true
          }
          return false
        } else {
          Toast.success('核对成功！')
          if (this.advice_groups[this.current_group_index].advices[0].origin == 2) {
            if (this.current_select_object == 1) {
              var advice = response.data.data.advice
              var ids = this.currentAdviceIdsStr.split(',')
              var adviceArr = this.advice_groups[this.current_group_index].advices
              for (let i = 0; i < adviceArr.length; i++) {
                for (let a = 0; a < advice.length; a++) {
                  if ((adviceArr[i].check_state == 0 &&adviceArr[i].id == advice[a].id) ||(adviceArr[i].check_state == 0 && adviceArr[i].parent_id == advice[a].id)) {
                    adviceArr[i].checker = advice[a].checker
                    adviceArr[i].check_time = advice[a].check_time
                    adviceArr[i].check_state = advice[a].check_state
                  }
                }
              }
            } else {
              var advice = response.data.data.advice
              var adviceArr = this.advice_groups[this.current_group_index]
                .advices
              for (let i = 0; i < adviceArr.length; i++) {
                for (let a = 0; a < advice.length; a++) {
                  if (
                    (adviceArr[i].check_state == 0 &&adviceArr[i].id == advice[a].id) ||(adviceArr[i].check_state == 0 &&adviceArr[i].parent_id == advice[a].id)) {
                    adviceArr[i].checker = advice[a].checker
                    adviceArr[i].check_time = advice[a].check_time
                    adviceArr[i].check_state = advice[a].check_state
                  }
                }
              }
            }
          } else {
            var advice = response.data.data.advice
            if (this.current_select_object == 1) {
              var ids = this.currentAdviceIdsStr.split(',')

              var adviceArr = this.advice_groups[this.current_group_index]
                .advices

              for (let i = 0; i < adviceArr.length; i++) {
                for (let a = 0; a < ids.length; a++) {
                  if ((adviceArr[i].check_state == 0 && adviceArr[i].id == ids[a]) ||(adviceArr[i].check_state == 0 &&adviceArr[i].parent_id == ids[a])) {
                    adviceArr[i].checker = advice.checker
                    adviceArr[i].check_time = advice.check_time
                    adviceArr[i].check_state = advice.check_state
                  }
                }
              }
            } else {
              for (let index = 0; index < group.advices.length; index++) {
                const adv = group.advices[index]
                adv.checker = advice.checker
                adv.check_time = advice.check_time
                adv.check_state = advice.check_state
              }
            }
          }
        }
      }).catch(err => {
        Toast.fail(err)
      })
    },
    BatchHandleCheckTime(time){
      console.log("time=====",time)
      var params = {
        record_date:this.$route.query.date,
        patient_id:this.$route.query.patient_id,
        exceTime:this.handleTime(time)
      }
      console.log("params",params)
     BatchHandleCheckTime(params).then(response=>{
       if(response.data.state ==1){

       }
     })
    },
     // 长期医嘱
    // down2 (event) {
    //   this.flags = true
    //   var touch
    //   if (event.touches) {
    //     touch = event.touches[0]
    //   } else {
    //     touch = event
    //   }
    //   this.position2.x = touch.clientX
    //   this.position2.y = touch.clientY
    //   this.dx2 = this.moveBtn2.offsetLeft
    //   this.dy2 = this.moveBtn2.offsetTop
    //   console.log('this.moveBtn2.offsetLeft',this.moveBtn2.offsetLeft);
    // },
    // move2 (event) {
    //   if (this.flags) {
    //     var touch
    //     if (event.touches) {
    //       touch = event.touches[0]
    //     } else {
    //       touch = event
    //     }
    //     this.nx2 = touch.clientX - this.position2.x
    //     this.ny2 = touch.clientY - this.position2.y
    //     this.xPum2 = this.dx2 + this.nx2
    //     this.yPum2 = this.dy2 + this.ny2
    //     var clientWidth = document.documentElement.clientWidth
    //     var clientHeight = document.documentElement.clientHeight
    //     if (
    //       this.xPum2 > 0 &&
    //       this.xPum2 < clientWidth - this.moveBtn2.offsetWidth
    //     ) {
    //       this.moveBtn2.style.left = this.xPum2 + 'px'
    //     }
    //     if (
    //       this.yPum2 > 0 &&
    //       this.yPum2 < clientHeight - this.moveBtn2.offsetHeight
    //     ) {
    //       this.moveBtn2.style.top = this.yPum2 + 'px'
    //     }

    //     // 阻止页面的滑动默认事件
    //     document.addEventListener('touchmove', this.handler, {
    //       passive: false
    //     })
    //   }
    // },
    // // 鼠标释放时候的函数
    // end2 () {
    //   this.flags = false
    //   sessionStorage.setItem('checkBtnTop2', this.moveBtn2.style.top)
    //   sessionStorage.setItem('checkBtnLeft2', this.moveBtn2.style.left)
    //   document.addEventListener('touchmove', this.handler, {
    //     passive: false
    //   })
    // },
    // handler () {
    //   if (this.flags) {
    //     event.preventDefault()
    //   } else {
    //     return true
    //   }
    // },

  },
  watch: {
    result: function (result) {
      if (result.length == 0) {
        this.isShowExce = true
        this.isShowMofifyExce = false
      } else if (result.length == 1) {
        let id = result.join(',')
        this.advice_list_prop.map(item => {
          if (item.id == id) {
            if (item.execution_state == 1) {
              this.isShowExce = false
              this.isShowMofifyExce = true
            } else {
              this.isShowExce = true
              this.isShowMofifyExce = false
            }
          }
        })
      } else if (result.length > 1) {
        let num = 0
        this.advice_list_prop.map(item => {
          if (this.result.indexOf(item.id) > -1) {
            if (item.execution_state == 2) {
              num++
            }
          }
        })
        if (num == this.result.length) {
          this.isShowExce = true
          this.isShowMofifyExce = false
        } else {
          this.isShowExce = false
          this.isShowMofifyExce = true
        }
      }
    },
    currentAdvices: function (currentAdvices) {
      if (currentAdvices.length == 0) {
        this.isShowExce = true
        this.isShowMofifyExce = false
      } else {
        let a = 0
        for (let i = 0; i < currentAdvices.length; i++) {
          if (currentAdvices[i].execution_state == 1) {
            a = a + 1
          }
        }

        if (a == currentAdvices.length) {
          this.isShowExce = false
          this.isShowMofifyExce = true
        } else {
          this.isShowExce = true
          this.isShowMofifyExce = false
        }
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.doctorAdvices{
    font-size: .875rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    >:first-child{
        flex: 1;
        overflow-y: auto;
    }
    .adviceTitle{
        display: flex;
        justify-content: space-between;
    }
    .executionBox{
        font-size: .75rem;
        display: flex;
        color: #4bb467;
    }
    .preserveBox{
        height: 3.125rem;
        display: flex;
        justify-content: space-between;
        padding: 0 .625rem;
        align-items: center;
        font-size: 1rem;
        >div>span{
            height: 2.25rem;
            line-height: 2.25rem;
            padding: 0 .375rem;
            font-size: .875rem;
            border-radius: 5px;
            border: 1px solid #409eff;
            color: #409eff;
            display: inline-block;
        }
        // >div>span:last-child{
        //     color: #f56c6c;
        //     border: 1px solid #f56c6c;
        // }
        .forbid {
            color: #c6cdd2 !important;
            border: 1px solid #c6cdd2 !important;
        }
    }
    .actionSheet{
        top:initial;
        transform: translate3d(0, 0, 0);
        border-radius: 1.25rem 1.25rem 0 0;
    }
    .startTimePicker{
        z-index: 4010 !important;
    }
    .van-button--mini {
        height: 1.5rem;
        padding: 0 .25rem;
        font-size: .625rem;
    }
    .forbid{
        color: #c6cdd2;
    }
    .paddingLeft{
        padding-left: 1.6875rem;
    }
    .deleteColor{
        color: #f56c6c !important;
        border: 1px solid #f56c6c !important;
    }
    .doctorTable{
        font-size: .875rem !important;
        tr th{
            height: 2.25rem !important;
        }
        tr td{
            padding: .5rem 0;
        }
    }

}
.td-active {
  background: #badcff !important;
}
.row-class-active {
    td {
    background: #badcff;
    }
}
.table tr td .txt{
    padding: 0 10px;
    text-align: left;
}
.table tr .subadvice_content {
    padding-left: 20px !important;
}
@media only screen and (max-width: 415px){
    .table {
        width: 850px;
    }
}

</style>

<style lang="scss">
.doctorAdvices{
    .datetimePicker{
        z-index: 4010 !important;
        .picker-item{
            font-size: .875rem !important;
            height: 44px;
            line-height: 44px;

        }
        .mint-datetime-action{
            font-size: .9375rem !important;
        }

    }
    @media only screen and (min-width: 415px) and (max-width: 767px){
        .table {
            width: 700px;
        }
    }
    @media only screen and (max-width: 415px){
        .table[data-v-365ae4b7] {
            width: 500px;
        }
    }
    .dateInput .mu-text-field-input{
        height: 2.25rem;
        line-height: 2.25rem;
        padding: 0 0.375rem;
        font-size: .875rem;
        border-radius: 5px;
        border: 1px solid #409eff;
        color: #fff;
        display: inline-block;
        width: 2.625rem;
    }
    .dateInput2 .mu-text-field-input{
        height: 2.25rem;
        line-height: 2.25rem;
        padding: 0 0.375rem;
        font-size: .875rem;
        border-radius: 5px;
        border: 1px solid #409eff;
        color: #fff;
        display: inline-block;
        width: 4.375rem;
    }
    .mu-input{
        width: auto;
        margin-bottom: 0;
    }
    .mu-input.has-label .mu-input-label{
        top: 50%;
        transform: translateY(-50%);
        text-align: center;
        font-size: .875rem;
        color: #409eff;
        text-align: center;
        width: 100%;
    }
    .mu-input.has-label{
        padding: 0;
        min-height:auto;
    }
    .checkBox4 {
      position: fixed;
      left: 0.6rem;
      bottom: 11rem;
      z-index:5000;
      img {
        width: 3.5rem;
        height: 3.5rem;
      }
    }
}
</style>
