<template>
    <div class="main-contain">
        <div class="position">
        <bread-crumb :crumbs="crumbs"></bread-crumb>
        <el-row style="float:right;">
            <el-col :span="24">
            <el-button size="small" icon="el-icon-printer" type="primary" @click="printAction">打印</el-button>
            </el-col>
        </el-row>
        </div>
        <div class="app-container" style="background-color: white;">
            <div id="print_content">
                <div class="print_main_content">
                    <div class="order_title_panl">
                        <span class="main_title">汇总统计表</span>
                    </div>
                    <div style="display:flex;justify-content: space-between;margin-bottom:10px;">
                        <p>统计时间：{{start_time}}-{{end_time}}</p>
                        <p>印单日期：{{print_date}}</p>
                    </div>
                    <div class="table_panel">
                        <table class="table">
                            <thead>
                                <tr>
                                    <td width="120">商品类型</td>
                                    <td width="120">规格名称</td>
                                    <td width="120">数量</td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr v-for='(item,index) in tableData' :key="index">
                                    <td>
                                      <span v-if="item.stage == 1">{{item.type_name}}</span>
                                      <span v-if="item.stage == 2">抗凝剂</span>
                                    </td>
                                    <td>
                                       <span v-if="item.stage == 1">{{item.specification_name}}</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 1">无肝素</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 2">普通肝素</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 3">低分子肝素</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 4">阿加曲班</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 5">枸橼酸钠</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 6">低分子肝素钙</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 7">低分子肝素钠</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 8">依诺肝素</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 9">达肝素</span>
                                      <span v-if="item.stage == 2 && item.anticoagulant == 10">体外抗凝</span>
                                    </td>
                                    <td>{{item.count}}</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import print from 'print-js'
import {getGatherList} from "@/api/consumable"
const moment = require('moment')
export default {
    components:{
        BreadCrumb
    },
    data(){
        return{
            crumbs: [
                { path: false, name: '耗材药品' },
                { path: false, name: '打印' }
            ],
            tableData:[],
            start_time:"",
            end_time:"",
            print_date:"",
        }
    },
    methods:{
        printAction: function() {
            const style = '@media print { .print_main_content { background-color: white; width:960px;  margin:0 auto; padding: 0 0 20px 0; } .order_title_panl { text-align: center; } .main_title { font-size: 18px; line-height: 40px; font-weight: 500; } .table_panel { } .table { width: 100%; border: 1px solid; border-collapse: collapse; padding: 2px; } thead tr td { border: 1px solid; text-align: center; font-size: 20px; padding: 15px 5px; } tbody tr td { border: 1px solid; text-align: center; font-size: 18px; padding: 10px 5px; } .proj { padding: 5px 0; text-align: left; } .proj_title { font-size: 16px; font-weight: 500; line-height: 25px; } .proj_item { font-size: 15px; line-height: 20px; } .zone_name { font-weight: 500; } }'

            printJS({
            printable: 'print_content',
            type: 'html',
            documentTitle: '  ',
            style: style,
            scanStyles: false
            })
        },
        getlist(startime,endtime){
            const params = {
              start_time:startime,
              end_time:endtime
            }
           getGatherList(params).then(response=>{
             if(response.data.state == 1){
                var arr = []
                var warehouselist = response.data.data.warehouselist
                for(let i=0;i<warehouselist.length;i++){
                  warehouselist[i].stage = 1
                }
              console.log("warehouselist",warehouselist)
                arr.push(...warehouselist)
                var consumables =  response.data.data.consumables

                var count = response.data.data.count
                for(let j=0;j<count.length;j++){
                  count[j].stage = 2
                }
              arr.push(...count)
              console.log("arr344444",arr)
              this.tableData = arr
             }
           })   
        }
    },
    created(){
       var startime  = moment(new Date()).add('year',0).format("YYYY-MM-DD")
      this.print_date = startime
      var startime =  this.$route.query.startime
      this.start_time = startime
      var endtime =  this.$route.query.endtime
      this.end_time = endtime
      this.getlist(startime,endtime)
    }
}
</script>


<style rel="stylesheet/scss" lang="scss" scoped>
.print_main_content {
  background-color: white;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 0 20px 0;

  .order_title_panl {
    text-align: center;

    .main_title {
      font-size: 18px;
      line-height: 40px;
      font-weight: 500;
    }
  }
  .table_panel {
    .table {
      width: 100%;
      border: 1px solid;
      border-collapse: collapse;
      padding: 2px;

      thead {
        tr {
          td {
            border: 1px solid;
            text-align: center;
            font-size: 20px;
            padding: 15px 5px;
          }
        }
      }
      tbody {
        tr {
          td {
            border: 1px solid;
            text-align: center;
            font-size: 18px;
            padding: 10px 5px;

            .proj {
              padding: 5px 0;
              text-align: left;

              .proj_title {
                font-size: 16px;
                font-weight: 500;
                line-height: 25px;
              }

              .proj_item {
                font-size: 15px;
                line-height: 20px;

                .zone_name {
                  font-weight: 500;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
