he wei
2024-09-21 70edda3b00f2528a473c28ec5a50b739ed160f0f
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
<script>
import {getParamsByStationIdApi, setParamsApi} from "@/views/dataTest/js/regularTestRes";
 
export default {
  name: "RegularTestResParams",
  props: {
    batt: {
      type: Object,
      default() {
        return {};
      },
    },
    visible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isCanSet: false,
      layout: {
        span: 12,
        gutter: 16,
      },
      params: {
        lastStartTime: "",    // 测试开始时间
        stationid: 0,         // 机房ID
        timeInterval: 720,    // 启动时间间隔
        enable: 1,            // 是否启用
      },
      rules: {
 
      }
    }
  },
  methods: {
    async getParams() {
      let batt = this.batt;
      this.isCanSet = false;
      let loading = this.$layer.loading();
      try {
        let res = await getParamsByStationIdApi(batt.stationId);
        this.$layer.close(loading);
        let rs = res.data;
        if(rs.code === 1 && rs.data) {
          this.isCanSet = true;
          this.$message.success("读取成功");
          this.params = rs.data2;
        }else {
          this.isCanSet = false;
          this.$message.warning("读取异常");
        }
      }catch (e) {
        this.$layer.close(loading);
        this.isCanSet = false;
        console.log(e);
        this.$message.error(e);
      }
    },
    async setParams() {
      let params = {...this.params};
      params.lastStartTime = new Date(params.lastStartTime).format("yyyy-MM-dd hh:mm:ss");
      let loading = this.$layer.loading();
      try {
        let res = await setParamsApi(params);
        this.$layer.close(loading);
        let rs = res.data;
        if(rs.code ===1 && rs.data) {
          this.$message.success("设置成功");
        }else {
          this.$message.warning("设置失败");
        }
      }catch (e) {
        this.$layer.close(loading);
        console.log(e);
        this.$message.error(e);
      }
    },
    close() {
      this.$emit('update:visible', false);
    }
  },
  mounted() {
    this.getParams();
  }
}
</script>
 
<template>
  <div class="regular-test-res-container">
    <el-form
      ref="ruleForm"
      size="mini"
      label-position="top"
      :model="params"
      :rules="rules"
      class="params-dialog">
      <el-form-item label="机房名称" prop="stationName">
        <el-input
          placeholder="请输入机房名称"
          v-model="batt.stationName"
          readonly="readonly">
        </el-input>
      </el-form-item>
      <el-row :gutter="layout.gutter">
        <el-col :span="layout.span">
          <el-form-item label="周期开始时间" prop="lastStartTime">
            <el-date-picker
              v-model="params.lastStartTime"
              type="datetime"
              placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="layout.span">
          <el-form-item label="启动时间间隔(小时)" prop="timeInterval">
            <el-input
              placeholder="请输入启动时间间隔"
              v-model="params.timeInterval">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="layout.span">
          <el-form-item label="是否启用" prop="enable">
            <el-select v-model="params.enable">
              <el-option :value="0" label="不启用" />
              <el-option :value="1" label="启用" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="form-footer">
        <el-button
          type="primary"
          size="mini"
          @click="getParams">读取</el-button>
        <el-button
          type="success"
          size="mini"
          :disabled="!isCanSet"
          @click="setParams">设定</el-button>
      </div>
    </el-form>
  </div>
</template>
 
<style scoped>
.regular-test-res-container {
  width: 500px;
  background-color: #FFFFFF;
  padding: 8px;
}
.form-footer {
  text-align: right;
  margin-bottom: 0;
}
</style>