<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="0" cellspacing="0" align="center">
                    <thead class="print_head">
                        <tr><td colspan="11">{{org_name}}</td></tr>
                        <tr><td colspan="11">耗材盘点</td></tr>
                    </thead>
                    <tbody class="print_body">
                    <tr>
                        <td>耗材名称</td>
                        <td>规格</td>
                        <td>单位</td>
                        <td>批号</td>
                        <td>生产厂商</td>
                        <td>仓库名称</td>
                        <td>盘点前数量</td> 
                        <td>盘点后数量</td>
                        <td>盈亏类型</td>
                        <td>进货单价</td>
                        <td width="60">总额</td>
                        
                    </tr>
                    <tr v-for="(item,index) in tableData" :key="index">
                        <td>{{item.good_name}}</td>
                        <td>{{item.specification_name}}</td>
                        <td>{{item.packing_unit}}</td>
                        <td>{{item.number}}</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</template>

<script>
import BreadCrumb from '@/xt_pages/components/bread-crumb'
const moment = require('moment');
import { uParseTime } from '@/utils/tools'
import { getPrintList } from "@/api/stock"
import print from "print-js";
export default {
    components:{
        BreadCrumb
    },
    data(){
        return{
          crumbs: [
            { path: false, name: '库存管理' },
            { path: false, name: '耗材管理' },
            { path: false, name: '耗材盘点打印' },
          ],
          org_name:"",
          ids:"",
          tableData:[],
          manufacturerList:[],
          houseList:[],
        }
    },
    methods:{
        printAction: function() {
            const style = '@page{size:landscape;margin: 10mm;} @media print { print_content{width:960px;margin:0} .flex{display: flex;justify-content: space-between;} .printTable{width:100%;border-collapse: collapse;border:0px;margin:10px 0;} .printTable thead{text-align:center}.printTable td{padding:5px;} .print_body tr td{border: 1px solid;font-size:12px;border-collapse:collapse;} }';
            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(){
          var params = {
            storehouse_id:this.$route.query.storehouse_id,
            good_name:this.$route.query.good_name,
            limit:this.$route.query.limit,
            page:this.$route.query.page,
          }
         getPrintList(params).then(response=>{
           if(response.data.state == 1){
             var list =  response.data.data.list
             console.log("list233233232323",list)
             this.tableData = list
             this.houseList = response.data.data.houseList
           }
         })
        },
        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;}
.print_head{border: none;display: table-header-group;}
.print_head tr td{text-align: center;border: none;}
.print_body tr td{border:1px solid}
</style>
