<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">

                <table class="printTable" border="1">
                    <tr>
                        <td>序号</td>
                        <td>名称</td>
                        <td>规格</td>
                        <td>批号</td>
                        <td>生产日期</td>
                        <td>有效日期</td>
                        <td>生产企业</td>
                        <td>国药准字</td>
                        <td>单位</td>
                        <td>库存量</td>
                    </tr>
                    <tr v-for="(item,index) in tableData" :key="index">
                        <td>{{index+1}}</td>
                        <td>{{item.good_name}}</td>
                        <td>{{item.specification_name}}</td>
                        <td>{{item.number}}</td>
                        <td>{{getTime(item.product_date)}}</td>
                        <td>{{getTime(item.expiry_date)}}</td>
                        <td>{{getManufacturerName(item.manufacturer)}}</td>
                        <td>{{item.remark}}</td>
                        <td>{{item.packing_unit}}</td>
                        <td></td>
                    </tr>
                </table>

            </div>
        </div>
    </div>
</template>

<script>
import BreadCrumb from '@/xt_pages/components/bread-crumb'
const moment = require('moment');
import { uParseTime } from '@/utils/tools'
import { getInventoryExportList } from "@/api/stock"
export default {
    components:{
        BreadCrumb
    },
    data(){
        return{
          crumbs: [
            { path: false, name: '库存管理' },
            { path: false, name: '耗材管理' },
            { path: false, name: '耗材盘点打印' },
          ],
          ids:"",
          tableData:[],
          manufacturerList:[],
        }
    },
    methods:{
        printAction: function() {
            const style = '@media print { .printTitle{font-size: 22px;text-align: center;}.flex{display: flex;justify-content: space-between;}.tableTitle{display: flex;border-top:1px solid #000;border-bottom: 1px solid #000;padding: 10px 0;}.tableTr{display: flex;border-bottom: 1px dashed #000;padding: 10px 0;}.tableBottom{display: flex;border-bottom: 1px solid #000;padding: 10px 0;}.printTable td{padding:5px;} }';
            printJS({
            printable: 'print_content',
            type: 'html',
            documentTitle: '  ',
            style: style,
            scanStyles: false
            })
        },
        getTime(val) {
         if(val < 0){
            return ""
          }
         if(val == ""){
            return ""
          }else {
            return uParseTime(val, '{y}-{m}-{d}')
         }
        },
        getlist(){
         getInventoryExportList().then(response=>{
           if(response.data.state == 1){
             var list =  response.data.data.list
             console.log("list233233232323",list)
             this.tableData = list
             this.manufacturerList = response.data.data.manufacturerList
           }
         })
        },
        getManufacturerName(id){

           var name = ""
           for(let i=0;i<this.manufacturerList.length;i++){
              if(id == this.manufacturerList[i].id){
                  name = this.manufacturerList[i].manufacturer_name
              }
           }
           return name
        }
    },
    created(){
      this.getlist()
    }
}
</script>


<style rel="stylesheet/scss" lang="scss" scoped>
.printTitle{font-size: 22px;text-align: center;}
.flex{display: flex;justify-content: space-between;}
.tableTitle{display: flex;border-top:1px solid #000;border-bottom: 1px solid #000;padding: 10px 0;}
.tableTr{display: flex;border-bottom: 1px dashed #000;padding: 10px 0;}
.tableBottom{display: flex;border-bottom: 1px solid #000;padding: 10px 0;}
.printTable{width:100%;border-collapse: collapse;}
.printTable td{padding:5px;}
</style>
