yangpeixing
6 小时以前 027b75833ae1bc3bd1bb597b18c65c9177fa62d4
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
<!--
*Author:jxx
 *Contact:283591387@qq.com
 *代码由框架生成,任何更改都可能导致被代码生成器覆盖
 *业务请在@/extension/widesea_wms/taskinfo/Dt_Task.js此处编写
 -->
<template>
    <div class="switch">
        <span class="switchTitle">自动打印</span>
        <el-switch v-model="value1" @change="handleSwitchChange" />
    </div>
    <view-grid ref="grid" :columns="columns" :detail="detail" :editFormFields="editFormFields"
        :editFormOptions="editFormOptions" :searchFormFields="searchFormFields" :searchFormOptions="searchFormOptions"
        :table="table" :extend="extend" />
</template>
<script>
import http from "@/api/http";
import extend from "@/extension/widesea_wms/Order/InboundOrder.js";
import { ref, defineComponent, onMounted } from "vue"; // 新增 onMounted
 
export default defineComponent({
    setup() {
        const table = ref({
            key: "id",
            footer: "Foots",
            cnName: '入库单据',
            name: '',
            url: "/InboundOrder/",
            sortName: "upperOrderNo"
        });
        const editFormFields = ref({
            orderNo: "",
            upperOrderNo: "",
            materialNo: "",
            materialName: "",
            demandClassification: "",
            orderType: "",
            datetime: "",
            lineNumber: "",
            productDrawingNumber: "",
            weight: "",
            unit: "",
            texture: "",
            orderStatus: ""
        });
        const editFormOptions = ref([
            [
                { "title": "仓库", "field": "wareHouseId", "type": "select", dataKey: "WareAreaTypeEnable", data: [] },
                { "title": "数量", "field": "quantity", "type": "text" },
            ],
        ]);
        const searchFormFields = ref({});
        const searchFormOptions = ref([
            [
                { "title": "订单编号", "field": "orderNo", "type": "text" },
                { "title": "上游单号", "field": "upperOrderNo", "type": "text" },
                { "title": "需求分类", "field": "demandClassification", "type": "text" },
                { "title": "单据类型", "field": "orderType", "type": "select", dataKey: "orderTypeEmun", data: [] },
            ],
            [
                { "title": "物料编码", "field": "materialNo", type: "text" },
                { "title": "物料名称", "field": "materialName", type: "text" },
                { "title": "行号", "field": "lineNumber", type: "text" },
                { "title": "时间", "field": "datetime", type: "text" },
            ],
            [
                { "title": "仓库名称", "field": "wareHouseId", type: "select", dataKey: "WareAreaTypeEnable", data: [] },
                { "title": "单重", "field": "weight", type: "text", },
                { "title": "规格", "field": "specs", type: "text" },
                { "title": "数量", "field": "quantity", type: "text" },
            ],
        ]);
        const columns = ref([
            { field: 'orderNo', title: '订单编号', type: 'string', width: 180, readonly: true, require: true, align: 'left' },
            { field: 'upperOrderNo', title: '上游单号', type: 'string', width: 180, align: 'left' },
            { field: 'materialNo', title: '物料编码', type: 'string', width: 180, align: 'left' },
            { field: 'materialName', title: '物料名称', type: 'string', width: 180, align: 'left' },
            { field: 'quantity', title: '数量', type: 'string', width: 90, align: 'left' },
            { field: 'demandClassification', title: '需求分类', type: 'string', width: 180, align: 'left' },
            { field: 'orderType', title: '单据类型', type: 'string', width: 110, align: 'left', bind: { key: "orderTypeEmun", data: [] } },
            { field: 'wareHouseId', title: '仓库', type: 'string', width: 120, align: 'left', bind: { key: "WareAreaTypeEnable", data: [] } },
            { field: 'datetime', title: '时间', type: 'string', width: 180, align: 'left' },
            { field: 'lineNumber', title: '行号', type: 'string', width: 90, align: 'left' },
            { field: 'productDrawingNumber', title: '图号', type: 'string', width: 180, align: 'left' },
            { field: 'weight', title: '单重', type: 'string', width: 90, align: 'left' },
            { field: 'specs', title: '规格', type: 'string', width: 180, align: 'left' },
            { field: 'unit', title: '单位', type: 'string', width: 90, align: 'left' },
            { field: 'texture', title: '材质', type: 'string', width: 180, align: 'left' },
            { field: 'orderStatus', title: '订单状态', type: 'string', width: 90, align: 'left' },
            { field: 'creater', title: '创建人', type: 'string', width: 120, align: 'left' },
            { field: 'createDate', title: '创建时间', type: 'datetime', sort: true, width: 150, align: 'left', sort: true },
            { field: 'modifier', title: '修改人', type: 'string', width: 120, align: 'left' },
            { field: 'modifyDate', title: '修改时间', type: 'datetime', sort: true, width: 150, align: 'left', sort: true },
        ]);
        const detail = ref({
            cnName: "#detailCnName",
            table: "#detailTable",
            columns: [],
            sortName: "",
            key: ""
        });
 
        // 定义开关状态
        const value1 = ref(false);
 
        const getAutomaticPrintStatus = async () => {
            try {
                // 请求后端接口获取当前状态
                const res = await http.get(`/api/InboundOrder/GetAutomaticPrint`);
                // 初始化开关值
                if (res !== undefined) {
                    value1.value = res;
                }
                console.log("自动打印状态初始化完成:", value1.value);
            } catch (error) {
                console.error("获取自动打印状态失败:", error);
                // 异常时默认关闭
                value1.value = false;
            }
        };
 
        onMounted(() => {
            getAutomaticPrintStatus(); 
        });
 
        const handleSwitchChange = async (val) => {
            try {
                await http.get(`/api/InboundOrder/AutomaticPrint?AutomaticPrintStatus=${val}`);
                console.log("自动打印状态已修改为:", val);
            } catch (error) {
                console.error("修改自动打印状态失败:", error);
                // 失败时回滚开关状态
                value1.value = !val;
            }
        };
 
        return {
            table,
            extend,
            editFormFields,
            editFormOptions,
            searchFormFields,
            searchFormOptions,
            columns,
            detail,
            value1, // 暴露开关状态
            handleSwitchChange // 暴露方法
        };
    }
});
</script>
<style>
.switch {
    text-align: center;
    position: fixed;
    top: 7.1rem;
    left: 54rem;
    z-index: 9999;
}
 
.switchTitle {
    font-size: 15px;
    margin-left: 20px;
}
</style>