Xxxu
2020-07-03 1ac6ef52a03f25f9def9f6a2594d2a8196aa77f6
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
<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    append-to-body
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="定时名称" prop="name">
        <el-input v-model="dataForm.name" placeholder="定时名称"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <!-- 取消按钮 -->
      <button class="btn-cancel" @click="visible = false"></button>
      <!-- 确定按钮 -->
      <button class="btn-config" type="primary" @click="dataFormSubmit()"></button>
    </span>
  </el-dialog>
</template>
 
<script>
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        timeId: 0,
        parentId: '',
        name: '',
        type: '',
        beanName: '',
        value: '',
        cron: '',
        createUserId: '',
        createTime: '',
        groupId: []
      },
      dataRule: {
        name: [
          { required: true, message: '定时名称不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init (id) {
      this.dataForm.timeId = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        this.$http({
          url: this.$http.adornUrl(`/pole/poletime/info/${this.dataForm.timeId}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataForm.parentId = data.poleTime.parentId
            this.dataForm.name = data.poleTime.name
            this.dataForm.type = data.poleTime.type
            this.dataForm.beanName = data.poleTime.beanName
            this.dataForm.value = data.poleTime.value
            this.dataForm.cron = data.poleTime.cron
            this.dataForm.groupId = data.poleTime.groupId || []
          } else {
            this.dataForm.parentId = ''
            this.dataForm.name = ''
            this.dataForm.type = 0
            this.dataForm.beanName = ''
            this.dataForm.value = ''
            this.dataForm.cron = ''
            this.dataForm.groupId = []
          }
        })
      })
    },
    // 表单提交
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/pole/poletime/${!this.dataForm.timeId ? 'save' : 'update'}`),
            method: 'post',
            data: this.$http.adornData({
              'timeId': this.dataForm.timeId || undefined,
              'parentId': this.dataForm.parentId,
              'name': this.dataForm.name,
              'type': this.dataForm.type,
              'beanName': this.dataForm.beanName,
              'value': this.dataForm.value,
              'cron': this.dataForm.cron,
              'groupId': this.dataForm.groupId
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    },
    // 类型改变
    typeChange () {
    },
    // 编辑cron
    editCron () {
      this.scheduleVisible = true
      this.$nextTick(() => {
        this.$refs.schedule.init(this.dataForm.cron)
      })
    },
    // 更改cron回调方法
    changeCron (val) {
      this.dataForm.cron = val
    }
  }
}
</script>
 
<style lang="scss" scoped>
div {
  /deep/ .el-dialog__header {
    background: url(~@/assets/img/streetlight/dialog-title.png);
    background-size:100% 100%;
  };
  /deep/ .el-dialog{
    background: #143251;
    border:3px solid #458aad;
    /deep/ .el-form-item__label {
      color: #fff
    }
    /deep/ .el-input__inner {
      background-color: transparent;
      color: #fff
    }
  };
}
</style>