whychdw
2021-05-25 a93d9216fe46403a7b2ccde0f875ecd3c43aa800
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<template>
    <div class="el-dialog-wrapper">
        <el-dialog :visible.sync="dialogVisible" class="position-absolute dialog-center dialog-no-header" width="840px"
            top="0" :modal="false" :destroy-on-close="true" :close-on-press-escape="false" :close-on-click-modal="false"
            :modal-append-to-body="false" v-loading="loading" element-loading-text="拼命加载中"
            element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0)">
            <mw-step v-model="step"></mw-step>
            <div class="step-list">
                <div class="step-item" v-show="step == 0">
                    <new-test @nextStep="newTest"></new-test>
                </div>
                <div class="step-item" v-show="step == 1" v-if="step>0">
                    <test-data-input :type="params.type" @nextStep="dataInput"></test-data-input>
                </div>
                <div class="step-item" v-show="step == 2" v-if="step>1">
                    <test-step-confirm v-if="type=='fz'" @nextStep="completeTest"></test-step-confirm>
                    <test-step-confirm-kz v-else-if="type=='kz'" @nextStep="completeTest"></test-step-confirm-kz>
                </div>
            </div>
        </el-dialog>
        <el-dialog :visible.sync="testStepCheck" class="position-absolute dialog-center dialog-no-header" width="840px"
            top="0" :modal="false" :destroy-on-close="true" :close-on-press-escape="false" :close-on-click-modal="false"
            :modal-append-to-body="false">
            <test-start :type="type" @startTest="startTest" v-if="testStepCheck"></test-start>
        </el-dialog>
        <el-dialog :visible.sync="startResult" class="position-absolute dialog-center dialog-no-header" width="840px"
            top="0" :modal="false" :destroy-on-close="true" :close-on-press-escape="false" :close-on-click-modal="false"
            :modal-append-to-body="false">
            <heating-up-rs :list="heatingUpList" @updatePoint="updatePoint"></heating-up-rs>
        </el-dialog>
        <test-step-dialog :type="type" :step="testStepKey" :list="list" :end="endStep" :progress="progressStep">
        </test-step-dialog>
    </div>
</template>
 
<script>
    import mwStep from "@/components/smallModule/mwStep";
    import newTest from "@/pages/test/dialog/newTest";
    import TestDataInput from "@/pages/test/dialog/testDataInput";
    import TestStepConfirm from "@/pages/test/dialog/testStepConfirm";
    import testStepConfirmKz from "@/pages/test/dialog/testStepConfirmKz";
    import TestStart from "@/pages/test/dialog/testStart";
    import {
        addKzFzTest,
        experimentPoint,
        getExitTest,
        testHeatingUp
    } from "@/pages/test/js/api";
    import HeatingUpRs from "@/pages/test/dialog/heatingUpRs";
    import {
        getLabel
    } from "@/assets/js/tools";
    import {
        constTestType
    } from "@/pages/test/js/const";
    import Timeout from "@/assets/js/tools/Timeout";
    import TestStepDialog from "@/pages/test/dialog/testStepDialog";
 
    export default {
        name: "LoadTestDialog",
        props: {
            visible: {
                type: Boolean,
                default: false,
            },
            type: {
                require: true,
                type: String,
            }
        },
        components: {
            TestStepDialog,
            HeatingUpRs,
            TestStepConfirm,
            TestDataInput,
            mwStep,
            newTest,
            testStepConfirmKz,
            TestStart
        },
        data() {
            return {
                loading: false,
                timer: new Timeout(),
                step: 0,
                dialogVisible: false,
                testStepCheck: false,
                startResult: false,
                experimentId: 0,
                params: {
                    baseData: {
                        experimentId: "", // 试验编号
                        gearSpeedRatio: "", // 齿轮转速比
                        ratedLateralSpeed: 0, // 高速侧转速,单位:r/min
                        ratedPower: 0, // 额定功率,单位KW
                        ratedRotateSpeed: 0, // 额定转速,单位:r/min
                        ratedVol: 0 // 额定电压,单位V
                    },
                    createTime: "", // 创建时间
                    deviceId: "", // 被测设备id
                    deviceSn: "", // 被测设备SN
                    duration: "", // 试验时长
                    endTime: "", // 结束时间
                    id: "", // 试验编号
                    name: "", // 试验名称
                    point: [],
                    projectId: 0, // 对应的项目
                    rz_link: 0, // 各相绕组连接情况 0 引出; 1 内部连接
                    startTime: "", // 启动时间
                    status: 0, // 状态:-1-取消,0-未开始,1-进行中,2-完成
                    type: "", // 试验类型:九大试验
                    userId: sessionStorage.getItem('uid'), // 负责人
                    username: "" // 负责人姓名
                },
                heatingUpList: [],
                list: [],
                testStepKey: -1,
                endStep: false,
                progressStep: false,
            }
        },
        watch: {
            visible(value) {
                this.dialogVisible = value;
            },
        },
        methods: {
            startTimer() {
                this.timer.start(() => {
                    this.$axios.all([
                        this.experimentPoint()
                    ]).then(res => {
                        this.timer.open();
                    }).catch(error => {
                        this.timer.open();
                    });
                }, 2000);
 
            },
            experimentPoint() {
                let postData = {
                    experimentId: this.experimentId
                }
                experimentPoint(postData).then((res) => {
                    let rs = res.data;
                    let data = [];
                    if (rs.code == 1) {
                        data = rs.data.map(item => {
                            let start = item.startTime ? new Date(item.startTime).format("hh:mm:ss") : '';
                            let end = item.endTime ? new Date(item.endTime).format("hh:mm:ss") : '';
                            item.start = item.startTime ? `开始时间&&${start}` : '';
                            item.end = item.endTime ? `完成时间&&${end}` : '';
                            item.endText = item.averagePower ? `平均功率&&${item.averagePower}kW` : '';
                            return item;
                        });
                    }
                    this.list = data;
                    this.$nextTick(() => {
                        // 设置testStepKey
                        let step = -1;
                        this.progressStep = false;
                        for (let i = 0; i < data.length; i++) {
                            let status = data[i].status;
                            if (status == 0) {
                                step = i;
                                this.endStep = false;
                                break;
                            } else if (status == 1) {
                                step = i;
                                this.progressStep = true;
                                break;
                            }
                            step = i;
                            this.endStep = true;
                        }
                        // 设置未激活点
                        this.testStepKey = step;
                    });
                    this.$emit('updateList', this.list);
                }).catch((err) => {
                    console.log(err)
                });
            },
            checkIsTesting() {
                getExitTest().then(res => {
                    let rs = res.data;
                    console.log(rs);
                    if (rs.code == 1) {
                        let data = rs.data;
                        if (data.type != this.type) {
                            let testType = getLabel(data.type, constTestType);
                            this.$alert("当前已开启试验:" + testType + "。如需要进行其他试验需先关闭此试验。", '系统提示', {
                                callback: () => {
                                    this.$router.push('/index/testManager/testing');
                                }
                            });
                        } else {
                            console.log('查询试验步骤');
                            this.experimentId = rs.data.id;
                            this.startTimer();
                        }
                    } else {
                        this.dialogVisible = true;
                    }
                }).catch(error => {
 
                });
            },
            newTest(data) {
                this.params.name = data.name;
                this.params.projectId = data.projectId;
                this.step++;
            },
            dataInput(data) {
                this.params.baseData.experimentId = data.experimentId;
                this.params.id = data.experimentId;
                this.params.deviceSn = data.deviceSn;
                this.params.deviceId = data.deviceId;
                this.params.baseData.ratedPower = data.ratedPower;
                this.params.baseData.ratedVol = data.ratedVol;
                this.params.baseData.gearSpeedRatio = data.gearSpeedRatio;
                this.params.baseData.ratedRotateSpeed = data.ratedRotateSpeed;
                this.params.baseData.ratedLateralSpeed = data.ratedLateralSpeed;
                this.step++;
            },
            completeTest(data) {
                let experimentId = this.params.baseData.experimentId;
                this.params.point = data.point.map(item => {
                    item.experimentId = experimentId;
                    return item;
                });
                this.loading = true;
                addKzFzTest(this.params).then(res => {
                    let rs = res.data;
                    if (rs.code == 1) {
                        this.dialogVisible = false;
                        this.$nextTick(() => {
                            this.$layer.msg("生成试验成功");
                            this.testStepCheck = true;
                        });
                    } else {
                        this.$layer.msg("生成试验失败");
                    }
                    this.loading = false;
                }).catch(error => {
                    this.$layer.msg("请检测网络");
                    this.loading = false;
                });
            },
            startTest() { // 开始试验, 进行升温
                this.testStepCheck = false;
                testHeatingUp(this.params.id).then(res => {
                    let rs = res.data;
                    let data = [];
                    if (rs.code == 1) {
                        data = rs.data;
                    }
                    this.heatingUpList = data;
                    this.startResult = true;
                }).catch(error => {
 
                });
            },
            updatePoint() { // 更新节点数据
                this.$emit('updatePoint');
                this.startResult = false;
                this.experimentId = this.params.id;
                this.startTimer();
            }
        },
        mounted() {
            this.params.type = this.type;
            this.dialogVisible = this.visible;
 
            this.checkIsTesting();
        },
        destroyed() {
            this.timer.stop();
        }
    }
</script>
 
<style scoped>
 
</style>