<template>
  <div class="main-contain">
    <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>
      <div>
       <el-button
          size="small"
          icon="el-icon-printer"
          :disabled="selecting_schs.length == 0"
          @click="signPrintAction"
          type="primary"
          style="margin-right:10"
        >标签打印
      </el-button>
      <el-button
          size="small"
          icon="el-icon-printer"
          :disabled="selecting_schs.length == 0"
          @click="batchPrintAction"
          type="primary"
          >医嘱打印
      </el-button>
    </div>
    </div>
    <div class="app-container">
      <!-- <div class="filter-container">
        <el-input style="width: 400px;" v-model="searchKey" class="filter-item"/>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </div>-->
      <div class="cell clearfix">
        <label class="title">
          <span class="name">日期查询:</span>
        </label>
        <el-date-picker
          v-model="time"
          prefix-icon="el-icon-date"
          @change="changeTime"
          :editable="false"
          style="width: 250px;"
          type="date"
          placeholder="选择日期时间"
          align="right"
          format="yyyy-MM-dd"
          value-format="timestamp"
        ></el-date-picker>

        <!-- <el-button type="primary" :disabled="selecting_schs.length == 0" @click="batchPrintAction">打印</el-button> -->
      </div>
      <div class="cell clearfix">
        <label class="title"> <span class="name">排班班次</span> : </label>
        <div class="time">
          <ul class>
            <li
              :class="item.value == schedulType ? 'active' : ''"
              @click="selectSchedulType(item.value)"
              v-for="item in schedulArr"
              :key="item.value"
            >
              {{ item.label }}
            </li>
          </ul>
        </div>
      </div>
      <div class="cell clearfix">
        <label class="title"> <span class="name">分区</span> : </label>
        <div class="time">
          <ul class>
            <li
              :class="item.id == partitionType ? 'active' : ''"
              @click="selectPartitionType(item.id)"
              v-for="item in partitionArr"
              :key="item.id"
            >
              {{ item.name }}
            </li>
          </ul>
        </div>
      </div>
     
     <div class="cell clearfix">
        <label class="title"> <span class="name">给药途径</span> : </label>
        <div class="time">
          <ul class>
            <li
              :class="item.id == delivery_way ? 'active' : ''"
              @click="selectDeliveryWay(item.id)"
              v-for="item in deliveryWay"
              :key="item.id"
            >
              {{ item.name }}
            </li>
          </ul>
        </div>
      </div>
    
      <el-table :data="scheduleMap" border :row-style="{ color: '#303133' }" :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}" 
        @selection-change="handleSelectionChange"
        :row-class-name="tableRowClassName"
        :span-method="objectSpanMethod"
        :cell-class-name="adviceNameShow"
        :modal-append-to-body="false"
        v-show="show">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column prop="date" label="姓名" align="center" min-width="26px">
          <template slot-scope="scope">
            <span>{{ scope.row.name }}</span>
            <br>
            ({{ scope.row.parent_id == 0 ? scope.row.dialysis_no : ""}})
            <br>
            <span v-if="scope.row.mode_id == 1">(HD)</span>
            <span v-if="scope.row.mode_id == 2">(HDF)</span>
            <span v-if="scope.row.mode_id == 3">(HD+HP)</span>
            <span v-if="scope.row.mode_id == 4">(HP)</span>
            <span v-if="scope.row.mode_id == 5">(HF)</span>
            <span v-if="scope.row.mode_id == 6">(SCUF)</span>
            <span v-if="scope.row.mode_id == 7">(IUF)</span>
            <span v-if="scope.row.mode_id == 8">(HFHD)</span>
            <span v-if="scope.row.mode_id == 9">(HFHD+HP)</span>
            <span v-if="scope.row.mode_id == 10">(PHF)</span>
            <span v-if="scope.row.mode_id == 11">(HFR)</span>
            <span v-if="scope.row.mode_id == 12">(HDF+HP)</span>
            <span v-if="scope.row.mode_id == 13">(CRRT)</span>
            <span v-if="scope.row.mode_id == 14">(腹水回输)</span>
            <span v-if="scope.row.mode_id == 24">I-HDF</span>
          </template>
        </el-table-column>
        <el-table-column  label="分区床位" width="100">
          <template slot-scope="scope" >
              {{scope.row.zone_name}}/{{scope.row.number}}
          </template>
        </el-table-column>
        <el-table-column prop="date" label="透析器" align="center" min-width="26px">
          <template slot-scope="scope">
            <span>{{ scope.row.dialyzer_perfusion_apparatus }}</span>
            <span v-if="scope.row.dialysis_dialyszers!=''">{{scope.row.dialysis_dialyszers}}</span>
            <span v-if="scope.row.dialysis_irrigation!=''">{{scope.row.dialysis_irrigation}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="start_time" label="开始时间" align="center" min-width="35px">
          <template slot-scope="scope">
            <span>
              {{scope.row.start_time | parseTime('{m}-{d} {h}:{i}')}}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="advice_name" min-width="50px" label="医嘱内容" align="center">
          <template slot-scope="scope">
            <el-dropdown trigger="click" v-if="scope.row.parent_id == 0">
              <span class="el-dropdown-link" v-if="scope.row.parent_id == 0">
                {{ getAdviceContent(scope.row, 1)}}
              </span>
            </el-dropdown>

            <el-dropdown trigger="click" v-if="scope.row.parent_id > 0">
              <span class="el-dropdown-link">
                &emsp;{{ getAdviceContent(scope.row, 2)}}
              </span>
            </el-dropdown>
          </template>
        </el-table-column>
        <el-table-column
          prop="start_time"
          align="center"
          min-width="30px"
          label="执行时间"
          sortable
        >
          <template slot-scope="scope">
            <span v-if="scope.row.execution_time != 0">
              {{scope.row.execution_time | parseTime('{m}-{d} {h}:{i}')}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column prop="execution_staff" align="center" min-width="30px" label="执行护士">
          <template slot-scope="scope">
            <span v-if="scope.row.parent_id == 0">
              {{getXuserName(scope.row.execution_staff)}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column prop="checker" align="center" min-width="30px" label="校对护士">
          <template slot-scope="scope">
            <span v-if="scope.row.parent_id == 0">
              {{getXuserName(scope.row.checker)}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column
          prop="check_time"
          align="center"
          min-width="30px"
          label="校对时间"
          sortable
        >
          <template slot-scope="scope">
            <span v-if="scope.row.check_time != 0">
              {{scope.row.check_time | parseTime('{m}-{d} {h}:{i}')}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column prop="date" label="开嘱医生" align="center" min-width="26px">
          <template slot-scope="scope">
            <span>{{ getXuserName(scope.row.advice_doctor) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="created_time"
          align="center"
          min-width="30px"
          label="校对时间"
          sortable
        >
          <template slot-scope="scope">
            <span v-if="scope.row.created_time != 0">
              {{scope.row.created_time | parseTime('{m}-{d} {h}:{i}')}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
      </el-table>
         <el-table :data="scheduleMap" border :row-style="{ color: '#303133' }" :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}" 
        @selection-change="handleSelectionChange"
        :row-class-name="tableRowClassName"
        :span-method="objectSpanMethod"
        :cell-class-name="adviceNameShow"
        :modal-append-to-body="false"
        v-show="showOne">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column prop="date" label="姓名" align="center" min-width="26px">
          <template slot-scope="scope">
            <span>{{ scope.row.name }}</span>
            <br>
            ({{ scope.row.parent_id == 0 ? scope.row.dialysis_no : ""}})
            <br>
            <span v-if="scope.row.mode_id == 1">(HD)</span>
            <span v-if="scope.row.mode_id == 2">(HDF)</span>
            <span v-if="scope.row.mode_id == 3">(HD+HP)</span>
            <span v-if="scope.row.mode_id == 4">(HP)</span>
            <span v-if="scope.row.mode_id == 5">(HF)</span>
            <span v-if="scope.row.mode_id == 6">(SCUF)</span>
            <span v-if="scope.row.mode_id == 7">(IUF)</span>
            <span v-if="scope.row.mode_id == 8">(HFHD)</span>
            <span v-if="scope.row.mode_id == 9">(HFHD+HP)</span>
            <span v-if="scope.row.mode_id == 10">(PHF)</span>
            <span v-if="scope.row.mode_id == 11">(HFR)</span>
            <span v-if="scope.row.mode_id == 12">(HDF+HP)</span>
            <span v-if="scope.row.mode_id == 13">(CRRT)</span>
            <span v-if="scope.row.mode_id == 14">(腹水回输)</span>
            <span v-if="scope.row.mode_id == 24">I-HDF</span>
          </template>
        </el-table-column>
        <el-table-column prop="date" label="透析器" align="center" min-width="26px">
          <template slot-scope="scope">
            <span>
              {{ scope.row.dialyzer_perfusion_apparatus }}
              <span v-if="scope.row.dialysis_dialyszers!=''">{{scope.row.dialysis_dialyszers}}</span>
              <span v-if="scope.row.dialysis_irrigation!=''">{{scope.row.dialysis_irrigation}}</span>
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="start_time" label="开始时间" align="center" min-width="35px">
          <template slot-scope="scope">
            <span>
              {{scope.row.start_time | parseTime('{m}-{d} {h}:{i}')}}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="advice_name" min-width="50px" label="医嘱内容" align="center">
          <template slot-scope="scope">
            <el-dropdown trigger="click" v-if="scope.row.parent_id == 0">
              <span class="el-dropdown-link" v-if="scope.row.parent_id == 0">
                {{ getAdviceContent(scope.row, 1)}}
              </span>
            </el-dropdown>

            <el-dropdown trigger="click" v-if="scope.row.parent_id > 0">
              <span class="el-dropdown-link">
                &emsp;{{ getAdviceContent(scope.row, 2)}}
              </span>
            </el-dropdown>
          </template>
        </el-table-column>
        <el-table-column
          prop="start_time"
          align="center"
          min-width="30px"
          label="执行时间"
          sortable
        >
          <template slot-scope="scope">
            <span v-if="scope.row.execution_time != 0">
              {{scope.row.start_time | parseTime('{m}-{d} {h}:{i}')}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column prop="execution_staff" align="center" min-width="30px" label="执行护士">
          <template slot-scope="scope">
            <span v-if="scope.row.parent_id == 0">
              {{getXuserName(scope.row.execution_staff)}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column prop="checker" align="center" min-width="30px" label="校对护士">
          <template slot-scope="scope">
            <span v-if="scope.row.parent_id == 0">
              {{getXuserName(scope.row.checker)}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column
          prop="check_time"
          align="center"
          min-width="30px"
          label="校对时间"
          sortable
        >
          <template slot-scope="scope">
            <span v-if="scope.row.check_time != 0">
              {{scope.row.check_time | parseTime('{m}-{d} {h}:{i}')}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column prop="date" label="开嘱医生" align="center" min-width="26px">
          <template slot-scope="scope">
            <span>{{ getXuserName(scope.row.advice_doctor) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="created_time"
          align="center"
          min-width="30px"
          label="校对时间"
          sortable
        >
          <template slot-scope="scope">
            <span v-if="scope.row.created_time != 0">
              {{scope.row.created_time | parseTime('{m}-{d} {h}:{i}')}}
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
const moment = require('moment')
import { getSchedualPatient, GetAllZone } from "@/api/dialysis";
import { parseTime } from "@/utils";
import BreadCrumb from "@/xt_pages/components/bread-crumb";
import { getPrintTemplate } from "@/api/data";
import { getSchedualDoctors } from '@/api/advice'

export default {
  name: "Patient",
  data() {
    return {
      crumbs: [
        { path: false, name: "透析管理" },
        { path: false, name: "透析监测" }
      ],
      loading: false,
      time: "",

      search_mode: 1, // 搜索模式 1.日期搜索 2.病人搜索
      patient_search_keyword: "",

      SchedualPatientsTableData: [],
      active: true,
      schedulType: 0,
      schedulArr: [
        { value: 0, label: "全部" },
        { value: 1, label: "上午" },
        { value: 2, label: "下午" },
        { value: 3, label: "晚上" }
      ],
      template_id: 0,

      partitionType: 0,

      total: 0,
      listQuery: {
        page: 1,
        limit: 10,
        schedul_type: 0,
        partition_type: 0,
        schedul_time: "",
        keywords: "",
      },
      selecting_schs: [],
      partitionArr: [],

      scheduleMap:[],
      show:true,
      showOne:false,
      deliveryWay:[],
      delivery_way:0,
    };
  },
  created() {
    var date = new Date();
    this.time = date;
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    if (month < 10) {
      month = "0" + month;
    }
    if (day < 10) {
      day = "0" + day;
    }
    var nowDate = year + "-" + month + "-" + day;
    var date = new Date(nowDate + " 00:00:00");
    this.listQuery.schedul_time = date.getTime();
    this.getAllZone();
    this.getTemplateInfo();
    this.requestSchedualDoctors(this.time)
    // this.template_id = this.$store.getters.xt_user.template_info.template_id;
  },
  methods: {
    getTemplateInfo() {
      getPrintTemplate().then(response => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          return false;
        } else {
          var template = response.data.data.template;
          this.template_id = template.template_id;
        }
      });
    },
    clickCurrent(val) {
      console.log(val);
      this.$router.push({
        path: "/dialysis/details",
        query: { patient_id: val.patient_id, date: val.sch_time_int,mode_id:val.mode_id }
      });
    },
    handleSelectionChange(val) {
      this.selecting_schs = val;
    },

    selectSchedulType(scheduleType) {
     
      this.schedulType = scheduleType;
      this.listQuery.schedul_type = scheduleType;
      console.log("班次",this.listQuery.schedul_type)
      this.requestSchedualDoctors(this.time);
    },
    selectPartitionType(partitionType) {
      this.partitionType = partitionType;
      this.listQuery.partition_type = partitionType;
      console.log("分区",this.listQuery.partition_type)
      this.requestSchedualDoctors(this.time);
    },
    
    selectDeliveryWay(val){
       this.delivery_way = val
       this.requestSchedualDoctors(this.time)
    },


    changeTime() {
      this.listQuery.schedul_time = this.time;
      this.requestSchedualDoctors(this.time)
    },
    getAllZone: function() {
      GetAllZone().then(response => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          return false;
        } else {
          this.partitionArr = response.data.data.zone;
          this.partitionArr.unshift({ id: 0, name: "全部" });
          var dics  =  response.data.data.dics
          var obj = {id:0,name:"全部"}
          this.deliveryWay.push(obj)
          this.deliveryWay.push(...dics)
        }
      });
    },
    requestSchedualDoctors (time) {
        
        var name = ""
        for(let i=0;i<this.deliveryWay.length;i++){
            if(this.delivery_way == this.deliveryWay[i].id){
              name = this.deliveryWay[i].name
            }
        }
        if(name == '全部'){
          name = ""
        }

        let newTime =  moment(time).format('YYYY-MM-DD')
       
         var schedule_type = this.listQuery.schedul_type
         var partition_type = this.listQuery.partition_type
        
        console.log("班次",schedule_type,"分区",partition_type)
        getSchedualDoctors({date: newTime,patient_type: 0,advice_type: 2,delivery_way:name,schedule_type:schedule_type,partition_type:partition_type}).then(rs => {
        var resp = rs.data
        if (resp.state == 1) {
            this.admin_users = resp.data.adminUser
            var schedules = resp.data.scheduals
            console.log("列表数据",schedules)
            var config = resp.data.config
            console.log("config222222",config.is_open)
            let project_config = resp.data.project_config
            console.log('project_config',)
            if(project_config.is_open == 1){
              this.project = resp.data.project
              resp.data.hisAdvices.map((item,index) => {
                if(this.project[index].project.length > 0){
                  this.project[index].project.map(it => {
                    let obj = {
                      advice_doctor: it.doctor,
                      start_time:it.start_time,
                      advice_name: it.type == 2 ? it.project.project_name : it.good_info.good_name,
                      execution_time:it.execution_time,
                      execution_state:it.execution_state,
                      execution_staff:it.execution_staff,
                      check_time:it.check_time,
                      check_state:it.check_state,
                      checker:it.checker,
                      created_time:it.ctime,
                      delivery_way:'',
                      execution_frequency:'',
                      remark:'',
                      id:it.id,
                      patient_id:it.patient_id,
                      parent_id:0,
                      groupno:0
                    }
                    // let advice = []
                    // advice.push(obj)
                    // let advices = {
                    //   advices: advice,
                    //   group_no: 123
                    // }

                //     // console.log(11111,item.new_advice)
                    item.doctor_advice.push(obj)
                  })
                }
              })
            }
            console.log('resp.data.hisAdvices',resp.data.hisAdvices)
           if(config.is_open == 0 || config.is_open == 2){
            this.show = true
            this.showOne = false
            let arr = []
            let newArr = []
            let newSchedules = []
            schedules.map(item => {
             item.doctor_advice.map(it =>{
                it.name = item.patient.name
                    if(item.prescription != null){
                       it.dialyzer_perfusion_apparatus = item.prescription.dialyzer_perfusion_apparatus
                       it.dialysis_dialyszers = item.prescription.dialysis_dialyszers
                       it.dialysis_irrigation = item.prescription.dialysis_irrigation
                    }
                    it.schedule_type = item.schedule_type
                    it.zoneId = item.device_number.zone.id
                    it.dialysis_no = item.patient.dialysis_no
                    it.mode_id = item.mode_id
                    it.number = item.device_number.number
                    it.zone_name = item.device_number.zone.name
                    arr.push(it)
                })
            })
            console.log("班次3333333",this.schedulType)
            if(this.schedulType == 0){
                newSchedules = arr
            }else{
                arr.map(item => {
                    if (item.schedule_type == this.schedulType) {
                        newSchedules.push(item)
                    }
                })
            }
            
            console.log("分区",this.partitionType)
            if(this.partitionType == 0){
                this.scheduleMap = newSchedules
            }else {
                let a = []
                arr.map(item => {
                    if(this.partitionType == item.zoneId){
                        a.push(item)
                    }
                })
                this.scheduleMap = a
            }
            console.log("列表22222",this.scheduleMap)
            this.scheduleMap.map(ele => {
                let firstIndex = this.scheduleMap.findIndex(item => {
                  return item.patient_id === ele.patient_id   // 当category相同的时候，返回第一个相同的Index 赋值给 firstIndex
                })
                if (this.scheduleMap.findIndex(item => { return item.patient_id === firstIndex}) === -1) {
                    newArr.push({
                    length: this.scheduleMap.filter(item => {
                        return item.patient_id === ele.patient_id    //利用数组的filter方法，过滤出相同category的数组的长度。数组长度-即为跨多少行
                    }).length,
                    firstIndex: firstIndex    // firstIndex 返回的是第一个catergory就满足的第一个Index,即为rowIndex开始于第几行。
                    })
                }
            })
            this.indexInfoList = newArr
           }
           if(config.is_open == 1){
             this.show = false
             this.showOne  = true
            var schedules =  resp.data.hisAdvices
            console.log("hhhhhhhh22323232323232",schedules)
            let arr = []
            let newArr = []
            let newSchedules = []
            schedules.map(item => {
             item.doctor_advice.map(it =>{
                it.name = item.patient.name
                    if(item.prescription != null){
                       it.dialyzer_perfusion_apparatus = item.prescription.dialyzer_perfusion_apparatus
                       it.dialysis_dialyszers = item.prescription.dialysis_dialyszers
                       it.dialysis_irrigation = item.prescription.dialysis_irrigation
                    }
                    it.schedule_type = item.schedule_type
                    it.zoneId = item.device_number.zone.id
                    it.dialysis_no = item.patient.dialysis_no
                    it.mode_id = item.mode_id
                    it.number = item.device_number.number
                    it.zone_name = item.device_number.zone.name
                    arr.push(it)
                })
            })
            if(this.schedulType == 0){
                newSchedules = arr
            }else{
                arr.map(item => {
                    if (item.schedule_type == this.schedulType) {
                        newSchedules.push(item)
                    }
                })
            }
            
            
            if(this.partitionType == 0){
                this.scheduleMap = newSchedules
            }else {
                let a = []
                arr.map(item => {
                    if(this.partitionType == item.zoneId){
                        a.push(item)
                    }
                })
                this.scheduleMap = a
            }
            console.log('333333344444',this.scheduleMap)
            this.scheduleMap.map(ele => {
                let firstIndex = this.scheduleMap.findIndex(item => {
                  return item.patient_id === ele.patient_id   // 当category相同的时候，返回第一个相同的Index 赋值给 firstIndex
                })
                if (this.scheduleMap.findIndex(item => { return item.patient_id === firstIndex}) === -1) {
                    newArr.push({
                    length: this.scheduleMap.filter(item => {
                        return item.patient_id === ele.patient_id    //利用数组的filter方法，过滤出相同category的数组的长度。数组长度-即为跨多少行
                    }).length,
                    firstIndex: firstIndex    // firstIndex 返回的是第一个catergory就满足的第一个Index,即为rowIndex开始于第几行。
                    })
                }
            })
            this.indexInfoList = newArr
           }
         }
         console.log("列表22222",this.indexInfoList)
        })
    },
    getValue: function(val) {
      if (val != undefined) {
        return val.value;
      } else {
        return "";
      }
    },

    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getSchedualPatientList();
    },
    changeSearchMode: function() {
      if (this.search_mode == 1) {
        this.search_mode = 2;
      } else {
        this.search_mode = 1;
      }
    },
    searchPatientAction: function() {
      this.listQuery.keywords = this.patient_search_keyword;
      console.log(this.patient_search_keyword);
      if (this.patient_search_keyword.length == 0) {
        return;
      }
      this.getSchedualPatientList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getSchedualPatientList();
    },
    batchPrintAction: function() {
      if (this.selecting_schs.length === 0) {
        this.$message.error("请至少选择一条需要打印的内容");
        return false;
      }
      // 模板ID为6
      var sch_ids = [];

      for (let index = 0; index < this.selecting_schs.length; index++) {
        sch_ids.push(this.selecting_schs[index].patient_id);
      }
  
      this.$store.dispatch("SetAdviceIDs", sch_ids);
       var name = ""
        for(let i=0;i<this.deliveryWay.length;i++){
            if(this.delivery_way == this.deliveryWay[i].id){
              name = this.deliveryWay[i].name
            }
        }
        if(name == '全部'){
          name = ""
       }
      this.$router.push({ path: "/dialysis/doctorAdvicePrint",query:{time: new Date(this.time).getTime(),delivery_way:name} });

    },
    signPrintAction:function(){
      if (this.selecting_schs.length === 0) {
        this.$message.error("请至少选择一条需要打印的内容");
        return false;
      }
      // 模板ID为6
      var sch_ids = [];

      for (let index = 0; index < this.selecting_schs.length; index++) {
        sch_ids.push(this.selecting_schs[index].patient_id);
      }
  
      this.$store.dispatch("SetAdviceIDs", sch_ids);
       var name = ""
        for(let i=0;i<this.deliveryWay.length;i++){
            if(this.delivery_way == this.deliveryWay[i].id){
              name = this.deliveryWay[i].name
            }
        }
        if(name == '全部'){
          name = ""
       }
      this.$router.push({ path: "/dialysis/signPrint",query:{time: new Date(this.time).getTime(),delivery_way:name} });

    },
    batchPrintActionOne: function() {
      if (this.selecting_schs.length === 0) {
        this.$message.error("请至少选择一条需要打印的内容");
        return false;
      }
      var sch_ids = [];
      for (let index = 0; index < this.selecting_schs.length; index++) {
        sch_ids.push(this.selecting_schs[index].sch_id);
      }
      this.$store.dispatch("SetBatchPrintDialysisRecordIDs", sch_ids);
      if (this.template_id == 2 || this.template_id == 0) {
        this.$router.push({ path: "/dialysis/print/batch/otherone" });
      } else if (this.template_id == 1) {
        this.$router.push({ path: "/dialysis/print/batch" });
      } else if (this.template_id == 5) {
        this.$router.push({ path: "/dialysis/print/batch/fiveone" });
      } else if (this.template_id == 22) {
        this.$router.push({ path: "/dialysis/print/batch/twentyTwo_one" });
      }
    },
    batchPrintActionTwo: function() {
      if (this.selecting_schs.length === 0) {
        this.$message.error("请至少选择一条需要打印的内容");
        return false;
      }
      var sch_ids = [];
      for (let index = 0; index < this.selecting_schs.length; index++) {
        sch_ids.push(this.selecting_schs[index].sch_id);
      }
      this.$store.dispatch("SetBatchPrintDialysisRecordIDs", sch_ids);
      if (this.template_id == 2 || this.template_id == 0) {
        this.$router.push({ path: "/dialysis/print/batch/othertwo" });
      } else if (this.template_id == 1) {
        this.$router.push({ path: "/dialysis/print/batch" });
      } else if (this.template_id == 5) {
        this.$router.push({ path: "/dialysis/print/batch/fivetwo" });
      } else if (this.template_id == 22) {
        this.$router.push({ path: "/dialysis/print/batch/twentyTwo_two" });
      }
    },
    compare (property) {
      return function (a, b) {
        var value1 = a[property]
        var value2 = b[property]
        return value1 - value2
      }
    },
    tableRowClassName({ row, rowIndex }) {
        // if (row.stop_state == 1 || row.execution_state == 1) {
        //     return 'stoped-row';
        // }
        // return 'success-rows'
        // row.index = rowIndex
        // const arr = this.hoverOrderArr
        // for (let i = 0; i < arr.length; i++) {
        //   if (rowIndex == arr[i]) {
        //     return 'success-row'
        //   }
        // }
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
        if (columnIndex === 0) {
            let index = this.indexInfoList.findIndex(item => {  //遍历数组
                return item.firstIndex === rowIndex
            })
            if (index > -1) {
                return {
                    rowspan: this.indexInfoList[index].length,
                    colspan: 1
                }
            } else {
                return {
                    rowspan: 0,
                    colspan: 0
                }
            }
        }
        
        if (columnIndex === 1) {
            let index = this.indexInfoList.findIndex(item => {  //遍历数组
                return item.firstIndex === rowIndex
            })
            if (index > -1) {
                return {
                    rowspan: this.indexInfoList[index].length,
                    colspan: 1
                }
            } else {
                return {
                    rowspan: 0,
                    colspan: 0
                }
            }
        }
        if (columnIndex === 2) {
            let index = this.indexInfoList.findIndex(item => {  //遍历数组
                return item.firstIndex === rowIndex
            })
            if (index > -1) {
                return {
                    rowspan: this.indexInfoList[index].length,
                    colspan: 1
                }
            } else {
                return {
                    rowspan: 0,
                    colspan: 0
                }
            }
        }
    },
    adviceNameShow({ row, column, rowIndex, columnIndex }) {
        if (columnIndex == 2) {
          return 'dialysisadvicenamedisplay'
        } else {
          return ''
        }
    },
    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
    },
    getAdviceContent(row, isChild) {
        let tempSingleDoseDesc = ''
        let tempDrugSpecDesc = ''
        let tempPrescribingNumberDesc = ''

        if (row.prescribing_number) {
          tempPrescribingNumberDesc =
            row.prescribing_number + '' + row.prescribing_number_unit
        }

        if (row.single_dose) {
          if (this.template_id != 6) {
            tempSingleDoseDesc =
              ' 单次用量 ' + '  ' + row.single_dose + '' + row.single_dose_unit
          } else {
            tempSingleDoseDesc = row.single_dose ? row.single_dose : '' + '' + row.single_dose_unit ? row.single_dose_unit : ''
          }
        }

        if (row.advice_desc) {
          tempDrugSpecDesc = '(' + row.advice_desc + row.drug_spec_unit + ')'
        }

        if (isChild == 1) {
          // 不是子药 
          console.log(tempDrugSpecDesc)
          console.log(tempPrescribingNumberDesc)
          console.log(tempSingleDoseDesc)
          console.log(11,row.delivery_way)
          console.log(22,row.execution_frequency)

          return (
            row.advice_name +
            tempDrugSpecDesc +
            ' ' +
            tempPrescribingNumberDesc +
            tempSingleDoseDesc +
            ' ' +
            row.delivery_way +
            ' ' +
            row.execution_frequency
          )
        } else {
          // 是子药
          return (
            row.advice_name +
            tempDrugSpecDesc +
            ' ' +
            tempPrescribingNumberDesc +
            tempSingleDoseDesc
          )
        }
    },
    handleSelectionChange(val){
        // console.log('val',val)
        this.selecting_schs = val;
    },
    
  },
  components: {
    BreadCrumb
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.app-container {
  //   margin: 20px;
  font-size: 15px;
  .filter-container {
    padding-bottom: 5px;
  }
  .cqd-dataTitle {
    color: #303133;
    font-size: 14px;
    border-bottom: 2px #e4e7ed solid;
    height: 36px;
    line-height: 36px;
    margin: 0 0 25px 0;
    position: relative;
  }
  .cqd-dataTitle::before {
    position: absolute;
    left: 0;
    bottom: -2px;
    content: "";
    width: 42px;
    height: 2px;
    background: #409eff;
  }
  .search-component {
    width: 500px;
    .searchBox {
      width: 300px;
      height: 36px;
      line-height: 36px;
      padding-left: 15px;
      border: 1px #dcdfe6 solid;
      border-right: none;
      outline: none;
      float: left;
      border-radius: 6px 0 0 6px;
      font-size: 14px;
      color: #333;
      background: #fff;
      box-shadow: 3px 3px 4px rgba(135, 135, 135, 0.05);
    }
    .searchBtn {
      background-color: #409eff;
      color: #fff;
      font-size: 15px;
      text-align: center;
      height: 36px;
      line-height: 36px;
      float: left;
      outline: none;
      width: 70px;
      border: none;
      border-radius: 0 6px 6px 0;
      font-family: "Microsoft Yahei";
      cursor: pointer;
    }
  }
  .amount {
    font-weight: normal;
    padding: 10px 0 0 0;
    color: #606266;
    font-size: 14px;
    span {
      color: #ef2525;
      font-family: "Arial";
      padding: 0 2px;
    }
  }
}
.el-table td,
.el-table th.is-leaf,
.el-table--border,
.el-table--group {
  border-color: #d0d3da;
}
.el-table--border::after,
.el-table--group::after,
.el-table::before {
  background-color: #d0d3da;
}
.el-checkbox__inner::after {
  height: 10px;
  left: 7px;
}
.el-checkbox__inner {
  width: 20px;
  height: 20px;
}
</style>
