<template>
   <div class="plate-box">
    <h2 class="title border"><span class="line"></span><p>{{title}}</p><span class="line"></span> </h2> 
    <table class="table">
      <tr>
        <th width="12%">开嘱医生</th>
        <th width="18%">开始时间</th>
        <th width="31%">医嘱内容</th>
        <th width="18.6%">执行时间</th>
        <th width="10.5%">执行护士</th>
        <th width="9.4%">核对护士</th>
      </tr>
      <tr v-for="(item,index) in tableDate" :key="index" :value="item.value">
        <td>{{item.advice_doctor}}</td>
        <td>{{parseTime(item.start_time, "{y}-{m}-{d}")}}</td>
        <td>{{item.advice_desc}}</td>
        <td>{{parseTime(item.execution_time, "{y}-{m}-{d}")}}</td>
        <td>{{item.execution_staff}}</td>
        <td>{{item.checker}}</td>
      </tr>
      <tr v-if="tableDate.length == 0">
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
    </table>
  </div>    
</template>

<script>
import {parseTime} from "@/utils"

export default {
  name: "statOrder",
  data() {
    return {
      title: "临时医嘱 ",
      tableDate: []
    };
  },
  methods: {
    setAdvices(advices) {
      if (advices == null) {
        advices = []
      }
      this.tableDate.splice(0, this.tableDate.length)
      this.tableDate.push(...advices)
    },
    parseTime(time, layout) {
      return parseTime(time, layout)
    },
    createMedicalOrder(row) {
      if (row.parent_id > 0) {
          var spliceIndex = -1;
          for (let index = this.tableDate.length-1; ; index--) {
              if(this.tableDate[index].parent_id ===  row.parent_id) {
                  spliceIndex = index;
                  break;
              }else if (this.tableDate[index].id === row.parent_id) {
                  spliceIndex = index;
                  break; 
              }
          }
          if (spliceIndex > -1) {
              spliceIndex += 1;
              if (spliceIndex === this.tableDate.length) {
                  this.tableDate.push(row);
              }else {
                  var swapData = this.tableDate.splice(spliceIndex);
                  this.tableDate.push(row);
                  this.tableDate = this.tableDate.concat(swapData);
              }
          } 
      }else {
          this.tableDate.unshift(row);
      }
    },
    delMedicalOrder(row){
      if (row.parent_id>0) {
        var rslen = this.tableDate.length;
        for (let i = 0; i < rslen; i++) {
          if (this.tableDate[i].id == row.id ) {
              this.tableDate.splice(i,1);
              break;
          }
        }
      }else {
          var resetTableData = this.tableDate;
          this.tableDate = [];
          var that = this;
          var rslen = resetTableData.length;
          for (let i = 0; i < rslen; i++) {
            if (resetTableData[i].id != row.id && resetTableData[i].parent_id != row.id) {
                that.tableDate.push(resetTableData[i]);
            }
          }
      }
    },
    executionMedicalOrder(row) {
      var alen = this.tableDate.length;
      for (let index = 0; index < alen; index++) {
        if (this.tableDate[index].id== row.id) {
          this.tableDate[index].execution_state = 1;
          this.tableDate[index].execution_staff = row.execution_staff;
          this.tableDate[index].execution_time = 	row.execution_time;
          this.tableDate[index].checker = row.checker;
          break;
        }
      }
      
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.table {
  width: 100%;
  overflow: hidden;
  font-size: 0.3rem;
  text-align: center;
  border: $border-color;
  tr {
    padding: 0;
    margin: 0;
    padding: 0.1rem 0;
    th {
      background: $main-color;
      border: none;
      color: #fff;
      padding: 0;
      margin: 0;
      height: 0.88rem;
      line-height: 0.88rem;
      font-weight: normal;
    }
    td {
      background: #f0f5fa;
      border: none;
      padding: 0.18rem 0;
    }
  }
}
</style>



