gaoshp
2024-06-23 fbee7228e2f6e43b417d4c3f03020704831261cd
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
<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="570" destroy-on-close @closed="$emit('closed')">
        <div v-if="isShow">历史反馈</div>
        <el-row v-if="isShow" class="history-feedback">
                <el-col :span="24"><span>开始反馈时间</span><span>{{latestData.feedbackTime}}</span></el-col>
                <el-col :span="24"><span>状态</span><span>{{latestData.wcsDesc}}</span></el-col>
                <el-col :span="24"><span>描述</span><span>{{latestData.feedbackDesc}}</span></el-col>
                <el-col :span="24"><span>状态持续时间</span><span>{{latestData.diffTime}}</span></el-col>
        </el-row>
        <div v-if="isShow" class="modal-title">最新反馈</div>
        <el-form :model="addDictForm" :rules="addDictRules" :disabled="mode=='show'" ref="dialogForm" label-width="120px" label-position="center">
            <el-row>
                <el-col :span="24">
                    <el-form-item label="状态时间">
                        <el-date-picker v-model="addDictForm.date" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right" value-format="YYYY-MM-DD HH:mm:ss" @change="dateChange">
                    </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="状态" prop="wcs">
                        <el-select v-model="addDictForm.wcs" style="width: 100%">
                            <el-option v-for="item in feedBackStatusList" :key="item.code" :label="item.name" :value="item.code"/>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="描述">
                        <el-input v-model="addDictForm.description" placeholder="描述" clearable></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <el-button @click="visible=false" >取 消</el-button>
            <el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="dictSubmit">提交反馈</el-button>
        </template>
    </el-dialog>
</template>
 
<script>
    export default {
        emits: ['success', 'closed'],
        props: ['workstationId'],
        data() {
            return {
                feedBackStatusList: [],
                latestData: {
                    latestData: "",
                    wcsDesc: "",
                    feedbackDesc: "",
                    diffTime: ""
                },
                isShow: false,
                value1: true,
                mode: "add",
                titleMap: {
                    add: '状态反馈',
                    edit: '状态反馈',
                    show: '状态反馈'
                },
                visible: false,
                isSaveing: false,
                //表单数据
                addDictForm: {
                    description: "",
                    date: [],
                    endTime: "",
                    startTime: "",
                    wcs: ""
                },
                //验证规则
                addDictRules: {
                    wcs:[{required: true, message: '请选择状态', trigger: 'change'}]
                }
            }
        },
        mounted() {
            
        },
        methods: {
            sumTime(startTime,endTime) {
                // 将字符串转换为Date对象  
                var startDate = new Date(startTime);  
                var endDate = new Date(endTime);  
                
                // 计算时间差(毫秒)  
                var timeDiff = endDate - startDate;  
                
                // 将时间差转换为天数、小时数、分钟数和秒数  
                var diffDays = Math.floor(timeDiff / (1000 * 60 * 60 * 24)); // 天  
                timeDiff %= 1000 * 60 * 60 * 24; // 剩余毫秒数  
                var diffHours = Math.floor(timeDiff / (1000 * 60 * 60)); // 小时  
                timeDiff %= 1000 * 60 * 60; // 剩余毫秒数  
                var diffMinutes = Math.floor(timeDiff / (1000 * 60)); // 分钟  
                timeDiff %= 1000 * 60; // 剩余毫秒数  
                var diffSeconds = Math.floor(timeDiff / 1000); // 秒
                var d = diffDays == 0?"":diffDays + "天";
                return d + diffHours + "小时 " + diffMinutes + "分钟 " + diffSeconds + "秒"
            },
            dateChange(val) {
                this.addDictForm.startTime = val[0];
                this.addDictForm.endTime = val[1];
            },
            //显示
            open(mode='add'){
                this.mode = mode;
                this.visible = true;
                return this
            },
            getfeedBackStatusList() {
                this.$HTTP.get("/api/blade-cps/global_wcs/wcs-achievements").then(res=> {
                    if(res.code == 200) {
                        res.data.forEach(item=> {
                            if(item.type == "4") {
                                this.feedBackStatusList.push(item);
                            }
                        })
                    }
                })
            },
            //表单提交方法
            dictSubmit(){
                var obj = Object.assign({},this.addDictForm);
                obj.workstationIds = [this.workstationId];
                var that = this;
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = true;
                        this.$HTTP.post("/api/blade-cps/workstation-wcs-feedback/overwrite-feedback-check",obj).then(res=> {
                            that.isSaveing = false;
                            if(res.code == 200) {
                                if(res.data) {
                                    that.$confirm(`反馈的时间与已有反馈重叠,是否覆盖`, '', {
                                        type: 'warning'
                                    }).then(() => {
                                        that.$HTTP.post("/api/blade-cps/workstation-wcs-feedback/start-feedback-by-no-immediate",obj).then(res=> {
                                            if(res.code == 200) {
                                                that.$message.success("操作成功");
                                                that.$emit('success', this.addDictForm, this.mode);
                                                that.visible = false;
                                            }
                                        })
                                    }).catch(() => {})
                                }else {
                                    that.$HTTP.post("/api/blade-cps/workstation-wcs-feedback/start-feedback-by-no-immediate",obj).then(res=> {
                                        if(res.code == 200) {
                                            that.$message.success("操作成功");
                                            that.$emit('success', this.addDictForm, this.mode);
                                            that.visible = false;
                                        }
                                    })
                                }
                            }else {
                                this.$alert(res.message, "提示", {type: 'error'});
                            }
                        })
                    }else{
                        return false;
                    }
                })
            },
            //表单注入数据
            setData(lastLevelId){
                this.getfeedBackStatusList();  //获取状态list
                this.$HTTP.get(`/api/blade-cps/workstation-wcs-feedback/latest?workstationId=${lastLevelId}`).then(res=> {
                    if(res.code == 200) {
                        if(res.data == null) {
                            this.isShow = false;
                        }else {
                            res.data.diffTime = this.sumTime(res.data.startTime,res.data.endTime);
                            this.latestData = res.data;
                            this.isShow = true;
                        }
                    }
                })
            }
        }
    }
</script>
 
<style scoped>
.history-feedback {
    background: #f5f5f5;
    padding: 12px 0;
    padding-bottom: 24px;
    margin: 16px 0 24px 0;
}
.history-feedback .el-col.el-col-24 {
    margin: 24px 0 0px 40px;
    font-size: 14px;
}
.history-feedback .el-col.el-col-24 span:nth-child(1) {
    display: inline-block;
    min-width: 100px;
}
.modal-title {
    margin-bottom: 20px;
}
</style>