pengwei
2025-04-21 7bbf1a9df53f5fe1c6c419304460ceec5b7a3629
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<template>
  <div id="goods-template" style="max-width: 800px" class="print-hide">
    <div v-for="item in goods" :key="item.id" style="height: 297mm">
      <div style="margin-top: 20px">
        <div style="display: flex; border: 1px solid #f5f5f5">
          <div
            style="
              display: flex;
              justify-content: center;
              width: 200px;
              border: 1px solid #f5f5f5;
              padding: 10px 0;
            "
          >
            <qrcode-vue
              :size="120"
              :margin="0"
              :auto-color="true"
              :dot-scale="1"
              :text="item.assembleCode"
            />
          </div>
          <div style="flex: 1">
            <div style="text-align: center; font-size: 30px; font-weight: bold">
              {{ item.assembleName }}
            </div>
            <div
              style="
                margin-top: 10px;
                display: flex;
                justify-content: center;
                color: #999999;
              "
            >
              <div>创建人:{{ item.creater }}</div>
              <div>创建时间:{{ item.createDate }}</div>
            </div>
            <div style="color: #205fee; font-size: 22px; text-align: center">
              {{ item.assembleCode }}
            </div>
          </div>
        </div>
        <div
          style="
            text-align: center;
            font-weight: bold;
            line-height: 20px;
            line-height: 40px;
          "
        >
          装配组件清单
        </div>
        <el-table
          :header-row-style="{
            fontSize: '0.75rem',
            color: '#101010',
            fontWeight: '400',
            height: '2.5rem',
          }"
          :header-cell-style="{ background: '#F4F4F4', textAlign: 'center' }"
          :row-style="{
            fontSize: '0.75rem',
            color: '#101010',
            fontWeight: '400',
            height: '2.5rem',
          }"
          :cell-style="{ textAlign: 'center', padding: '0' }"
          :data="item.assembleDetailBomList"
          style="width: 100%; margin-top: 0.88rem"
        >
          <el-table-column prop="bindName" label="清单名称" />
          <el-table-column prop="bindCode" label="清单编号" />
          <el-table-column prop="goodsName" label="物料名称">
            <template #default="scope">
              {{ scope.row.goodsName }}
            </template>
          </el-table-column>
          <el-table-column prop="goodsCode" label="物料编号">
            <template #default="scope">
              {{ scope.row.goodsCode }}
              <!-- <div
                :class="
                  index == scope.row.details.length - 1 ? '' : 'bottomClass'
                "
                v-for="(i, index) in scope.row.details"
                :key="i.id"
                class="cell-item"
              >
                {{ i.goodsCode }}
              </div> -->
            </template>
          </el-table-column>
          <el-table-column prop="goodsSpec" label="规格型号">
            <!-- <template #default="scope">
              <div
                :class="
                  index == scope.row.details.length - 1 ? '' : 'bottomClass'
                "
                v-for="(i, index) in scope.row.details"
                :key="i.id"
                class="cell-item"
              >
                {{ i.goodsSpec || "-" }}
              </div>
            </template> -->
          </el-table-column>
          <el-table-column prop="goodsType" label="物料类型">
            <!-- <template #default="scope">
              <div
                :class="
                  index == scope.row.details.length - 1 ? '' : 'bottomClass'
                "
                v-for="(i, index) in scope.row.details"
                :key="i.id"
                class="cell-item"
              >
                {{ i.goodsType || "-" }}
              </div>
            </template> -->
          </el-table-column>
          <el-table-column prop="goodsSource" label="物料来源">
            <!-- <template #default="scope">
              <div
                :class="
                  index == scope.row.details.length - 1 ? '' : 'bottomClass'
                "
                v-for="(i, index) in scope.row.details"
                :key="i.id"
                class="cell-item"
              >
                {{ i.goodsSource || "-" }}
              </div>
            </template> -->
          </el-table-column>
          <el-table-column prop="goodsNum" label="清单数量">
            <!-- <template #default="scope">
              <div
                :class="
                  index == scope.row.details.length - 1 ? '' : 'bottomClass'
                "
                v-for="(i, index) in scope.row.details"
                :key="i.id"
                class="cell-item"
              >
                {{ i.goodsNum }}
              </div>
            </template> -->
          </el-table-column>
        </el-table>
        <div style="margin-top: 10px">备注:{{ item.remark }}</div>
      </div>
    </div>
  </div>
</template>
  
  <script>
import printJS from "print-js";
import QrcodeVue from "vue-qr/src/packages/vue-qr.vue";
 
export default {
  data() {
    return {
      //定义物料类型
      gType: [
        { label: "物料", value: 1 },
        { label: "工具", value: 2 },
        { label: "辅料", value: 3 },
        { label: "耗材", value: 4 },
      ],
      //定义物料来源
      gSource: [
        { label: "外购", value: 1 },
        { label: "外协", value: 2 },
        { label: "自制", value: 3 },
        { label: "组件", value: 4 },
      ],
    };
  },
  components: {
    QrcodeVue,
  },
  props: {
    goods: {
      type: Object,
      default: () => [],
    },
  },
  created() {
    console.log("created", this.goods);
 
    // this.item.assembleDetailBomList.forEach((item) => {
    //   item.goodsType = this.gType.find((i) => i.value == item.goodsType).label;
    //   item.goodsSource = this.gSource.find(
    //     (i) => i.value == item.goodsSource
    //   ).label;
    // });
    // console.log(this.goods);
  },
  mounted() {
    setTimeout(() => {
      this.handlePrint();
    }, 500);
  },
  beforeUnmount() {
    clearTimeout();
  },
  methods: {
    handlePrint() {
      // 获取打印模板的DOM元素
      const printElement = document.getElementById("goods-template");
      if (printElement) {
        // 显示打印模板,以便能够打印
        printElement.classList.remove("print-hide");
        // 使用vue-printjs打印模板内容
        printJS({
          printable: printElement,
          type: "html",
          scanStyles: false,
          error: (err) => {
            console.log("err", err);
          },
        });
        // 打印完成后隐藏打印模板
        printElement.classList.add("print-hide");
        //向父组件发送打印完成事件
        this.$emit("print-complete");
      }
    },
  },
};
</script>
  <style lang="less" scoped>
.print-hide {
  display: block;
  /* 在屏幕上隐藏打印模板 */
}
</style>