<template>
  <div id="allList-print" class="allList-print">
    <div v-for='(i,index) in pageArr.length' :key="index">
      <div class="allListTitle">{{ $store.getters.xt_user.org.org_name }}费用汇总</div>
      <div class="allListInfo">
        <div>患者姓名：{{ patient.name }}</div>
        <div>透析号：{{ patient.dialysis_no }}</div>
        <div>性别：{{ patient.gender == 1 ? '男' : '女' }}</div>
        <div>年龄：{{ patient.age }} 岁</div>
        <div v-if="$store.getters.xt_user.org_id  == 0">日期：{{ hospital.in_hosptial_time }} 至
          {{ hospital.out_hosptial_time }}
        </div>
        <div v-else>日期：{{ getTimes(order.settle_start_time) }} 至 {{ getTimes(order.settle_end_time) }}</div>

      </div>
      <table class="allListTable" border="1">
        <tr>
          <td style="width:10%">类别</td>
          <td style="width:50%">项目名称</td>
          <td style="width:10%">规格</td>
          <td style="width:10%">单价(元)</td>
          <td style="width:10%">数量</td>
          <td style="width:10%">金额(元)</td>
        </tr>
        <template v-for='item in list.slice(index * 13,(index * 13) + pageArr[index])'>
          <tr v-if="item.is_total == 2">
            <td style="width:10%">{{ item.med_chrgitm_type }}</td>
            <td style="width:50%">{{ item.name }}</td>
            <td style="width:10%">{{ item.spec }}</td>
            <td style="width:10%">{{ (item.price).toFixed(2) }}</td>
            <td style="width:10%">{{ item.count }}{{ item.unit }}</td>
            <td style="width:10%">{{ (item.price * item.count).toFixed(2) }}</td>
          </tr>
          <tr>
            <td colspan="6" style="text-align:right;" v-if="item.is_total == 1">合计：{{ item.total }}元</td>
          </tr>
        </template>
      </table>
      <div class="tableBottom">
        <div class="tableBottomOne">制表人：{{ admin.user_name }}</div>
        <div class="tableBottomOne">制表日期：{{ getNowTime() }}</div>
        <div class="tableBottomOne">总费用：{{ order.medfee_sumamt }}元</div>
      </div>
    </div>
  </div>
</template>

<script>
import { uParseTime } from '@/utils/tools'

export default {
  props: {
    list: {
      type: Array,
      default: function() {
        return []
      }
    }, patient: {
      type: Object,
      default: function() {
        return {}
      }
    }, order: {
      type: Object,
      default: function() {
        return {}
      }
    }, admin: {
      type: Object,
      default: function() {
        return {}
      }
    }, hospital: {
      type: Object,
      default: function() {
        return {}
      }

    }
  },
  data() {
    return {
      page: 1,
      pageArr: []
    }
  },
  methods: {
    getNowTime: function() {
      let dateTime
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes()
          :
          new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds()
          :
          new Date().getSeconds()
      dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      return dateTime
    },
    getTimes(time) {
      return uParseTime(time, '{y}-{m}-{d}')
    }, getTotal: function(items) {
      let total = 0
      for (let i = 0; i < items.length; i++) {
        total = total + (items[i].count * items[i].price).toFixed(2)
      }
      return total

    },
    getPage() {
      if (this.list.length <= 13) {
        this.page = 1
        this.pageArr.push(this.list.length)
      } else if (this.list.length > 13) {
        this.page = parseInt(this.list.length / 13)
        let num = this.list.length % 13
        for (var i = 0; i < this.page; i++) {
          this.pageArr.push(13)
        }
        if (num != 0) {
          this.pageArr.push(num)
        }
      }
    }

  },
  watch: {
    list: {
      handler(newVal) {
        this.getPage()
      },
      deep: true
    }
  }
}


</script>

<style lang="scss" scoped>
.allList-print {
  -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 60px rgba(0, 0, 0, 0.06) inset;
  -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset;
  margin-bottom: 20px;
  padding: 20px 10px;
}

.allListTitle {
  font-size: 22px;
  text-align: center;
  font-weight: bold;
  margin-bottom: 10px;
}

.allListInfo {
  display: flex;
  font-size: 14px;
  justify-content: space-between;
  margin: 10px 0;
}

.allListTable {
  width: 100%;
  text-align: center;
  border-collapse: collapse;
  line-height: 20px;
  font-size: 12px;
  border-color: #000;
  text-align: left;
}

.allListTable tr td {
  padding: 0 5px;
}

.tableBottom {
  font-size: 14px;
  display: flex;
  margin-top: 20px;
}

.tableBottomOne {
  margin-right: 40px;
}
</style>
