zhouwx
2024-08-14 60e36c367ccfb6382b29f02df97bebca76351235
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<template>
  <div class="notice">
    <el-dialog
        v-model="dialogVisible"
        :title="title == 'pro' ? '成品二维码打印' : '危化品二维码打印'"
        width="600px"
        :before-close="handleClose"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
    >
      <el-table v-loading="state.loading" :data="state.dataList" :border="true" :show-header="false" height="550"  @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"  align="center" />
        <el-table-column align="center" >
          <template #default="scope">
            <div :id="scope.row.code">
              <div style="display: flex;flex-direction: column;align-items: center;justify-content: center">
                <div style="font-size:14px;margin-top:10px;">{{scope.row.name}}—{{scope.row.productSn}}</div>
                <vue-qr :size="80" :margin="0" :auto-color="true" :dot-scale="1" :text="scope.row.code" style="margin-top:10px;"></vue-qr>
                <div style="font-size:10px;margin-top:10px;">{{scope.row.code}}</div>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
          v-show="state.total > 0"
          :total="state.total"
          v-model:page="state.queryParams.pageNum"
          v-model:limit="state.queryParams.pageSize"
          @pagination="getList"
      />
      <template #footer>
        <span class="dialog-footer">
            <el-button @click="handleClose" size="default">取 消</el-button>
            <el-button type="primary"  @click="printEvent" size="default" v-preReClick>打印</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import {reactive, ref, toRefs} from 'vue'
import VueQr from 'vue-qr/src/packages/vue-qr.vue'
import {ElMessage} from "element-plus";
import {addWarehouse, checkName, editWarehouse} from "@/api/hazardousChemicals/warehouse";
import {verifyPhone} from "@/utils/validate";
import {checkBasicName} from "@/api/hazardousChemicals/basicInfo";
import {getProDetail, getProductRecord} from "@/api/hazardousChemicals/productRecord";
import {getRawDetail} from "@/api/hazardousChemicals/rawRecord";
 
const dialogVisible = ref(false);
const title = ref("");
const busRef = ref();
const length = ref()
const emit = defineEmits(["getList"]);
 
const state = reactive({
  loading: false,
  dataList: [],
  total: 0,
  queryParams:{
    pageNum: 1,
    pageSize: 5,
    warehouseId: null,
    basicId: null,
  },
  chooseList: []
 
})
 
const originalList = ref([])
const openDialog = async (type,value) => {
  state.queryParams.warehouseId =value.warehouseId
  state.queryParams.basicId =value.basicId
  title.value = type;
  await getList()
 
  console.log('state.dataList',state.dataList)
  dialogVisible.value = true;
}
const getRowKey = (row) => {
  return row.id
}
 
const onSubmit = async () => {
 
}
const handleSelectionChange = (val) => {
  // state.form.studentIds = val.map(item => item.id)
  state.chooseList = val
  console.log("选中的行", val)
}
 
const handleClose = () => {
  reset();
  dialogVisible.value = false;
  emit("getList")
}
const reset = () => {
  state.dataList = [];
  state.queryParams = {
    pageNum: 1,
    pageSize: 5,
    warehouseId: null,
    basicId: null,
  }
  state.total = 0
  state.chooseList = []
}
const getList = async () => {
  if(title.value == 'pro'){
    const res = await getProDetail(state.queryParams)
    if(res.code == 200){
      state.dataList = res.data.list.map(item => {
       return{
         ...item,
         name: item.productBasic.name,
         productSn: item.productBasic.productSn
       }
      })
      state.total = res.data.total
      originalList.value = state.dataList
    }else{
      ElMessage.warning(res.message)
    }
  }else {
    const res = await getRawDetail(state.queryParams)
    if(res.code == 200){
      state.dataList = res.data.list.map(item => {
        return{
          ...item,
          name: item.hazmatBasic.name,
          productSn: item.hazmatBasic.productSn
        }
      })
      state.total = res.data.total
      originalList.value = state.dataList
    }else{
      ElMessage.warning(res.message)
    }
  }
 
 
 
}
 
const printEvent=() => {
  let data = []
  if(state.chooseList && state.chooseList.length>0){
    data = state.chooseList
  }else {
    data = state.dataList
  }
  let qrCodes=''
  for(let index in data){
    console.log(index,'index')
    qrCodes+=`<div class="my-list-col"><div class="centered-content">${document.getElementById(data[index].code).innerHTML}</div></div>`
  }
  const printContent=document.createElement('div')
  printContent.innerHTML=qrCodes
  //创建一个新的隐藏的iframe元素
  const printFrame =document.createElement('iframe')
  printFrame.style.display='none'
  document.body.appendChild(printFrame)
 
  const printDocument=printFrame.contentWindow.document
  printDocument.open()
  printDocument.write(`
  <html>
  <head>
    <title>Print</title>
    <style>
      @media print {
        .page-break { page-break-after:always;} /* 定义分页符格式*/
        .centered-content { text-align:center;} /* 居中对齐内容*/
        @page { size:50mm 40mm;margin:0mm; }
      }
    </style>
  </head>
  <body style='margin:0;padding:0;'>${printContent.innerHTML}</body>
  </html>
  `)
  printDocument.close()
  //在打印窗口中调用打印功能
  printFrame.contentWindow.print()
  //移除隐藏的iframe元素
  document.body.removeChild(printFrame)
  // handleClose()
}
 
 
defineExpose({
  openDialog
});
 
</script>
 
<style scoped lang="scss">
.notice{
  :deep(.el-form .el-form-item__label) {
    font-size: 15px;
  }
  .file {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
}
</style>