zhangwencui
4 天以前 d85e1b4cce3e137a02f08515cd78c601fcf325b0
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
<template>
  <div class="app-container">
    <div class="search_form">
      <div>
        <span class="search_title">工单编号:</span>
        <el-input v-model="searchForm.workOrderNo"
                  style="width: 240px"
                  placeholder="请输入"
                  @change="handleQuery"
                  clearable
                  prefix-icon="Search" />
        <el-button type="primary"
                   @click="handleQuery"
                   style="margin-left: 10px">搜索</el-button>
      </div>
      <div>
      </div>
    </div>
    <div class="table_list">
      <PIMTable rowKey="id"
                :column="tableColumn"
                :tableData="tableData"
                :page="page"
                :tableLoading="tableLoading"
                @pagination="pagination"></PIMTable>
    </div>
    <el-dialog v-model="qrDialogVisible"
               title="二维码"
               width="300px">
      <div style="text-align:center;">
        <img :src="qrCodeUrl"
             alt="二维码"
             style="width:200px;height:200px;" />
        <div style="margin:10px 0;">
          <el-button type="primary"
                     @click="downloadQRCode">下载二维码图片</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
 
<script setup>
  import { onMounted, ref } from "vue";
  import { ElMessageBox } from "element-plus";
  import dayjs from "dayjs";
  import { productWorkOrderPage } from "@/api/productionManagement/workOrder.js";
  import QRCode from "qrcode";
  import { getCurrentInstance, reactive, toRefs } from "vue";
  const { proxy } = getCurrentInstance();
 
  const tableColumn = ref([
    {
      label: "工单编号",
      prop: "workOrderNo",
    },
    {
      label: "产品名称",
      prop: "productName",
    },
    {
      label: "规格",
      prop: "model",
    },
    {
      label: "单位",
      prop: "unit",
    },
    {
      label: "工序名称",
      prop: "processName",
    },
    {
      label: "计划开始时间",
      prop: "planStartTime",
    },
    {
      label: "计划结束时间",
      prop: "planEndTime",
    },
    {
      label: "实际开始时间",
      prop: "actualStartTime",
    },
    {
      label: "实际结束时间",
      prop: "actualEndTime",
    },
  ]);
  const tableData = ref([]);
  const tableLoading = ref(false);
  const qrDialogVisible = ref(false);
  const qrCodeUrl = ref("");
  const qrRowData = ref(null);
  const page = reactive({
    current: 1,
    size: 100,
    total: 0,
  });
 
  const data = reactive({
    searchForm: {
      workOrderNo: "",
    },
  });
  const { searchForm } = toRefs(data);
 
  // 查询列表
  /** 搜索按钮操作 */
  const handleQuery = () => {
    page.current = 1;
    getList();
  };
  const pagination = obj => {
    page.current = obj.page;
    page.size = obj.limit;
    getList();
  };
  const getList = () => {
    tableLoading.value = true;
    const params = { ...searchForm.value, ...page };
    productWorkOrderPage(params)
      .then(res => {
        tableLoading.value = false;
        tableData.value = res.data.records;
        page.total = res.data.total;
      })
      .catch(() => {
        tableLoading.value = false;
      });
  };
  const showQRCode = async row => {
    // 直接使用URL,不要用JSON.stringify包装
    const qrContent = proxy.javaApi + "/device-info?deviceId=" + row.id;
    qrCodeUrl.value = await QRCode.toDataURL(qrContent);
    qrRowData.value = row;
    qrDialogVisible.value = true;
  };
  const downloadQRCode = () => {
    const link = document.createElement("a");
    link.href = qrCodeUrl.value;
    link.download = `二维码_${qrRowData.value.id}.png`;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
  };
 
  onMounted(() => {
    getList();
  });
</script>
 
<style scoped lang="scss"></style>