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
<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    append-to-body
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="名称" prop="groupName">
      <el-input v-model="dataForm.groupName" placeholder="名称"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    <!-- <el-form-item label="" prop="createUserId">
      <el-input v-model="dataForm.createUserId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="createTime">
      <el-input v-model="dataForm.createTime" 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: {
          nbDeviceGroupId: 0,
          groupName: '',
          remark: '',
          createUserId: '',
          createTime: ''
        },
        dataRule: {
          groupName: [
            { required: true, message: '名称不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
          // createUserId: [
          //   { required: true, message: '不能为空', trigger: 'blur' }
          // ],
          // createTime: [
          //   { required: true, message: '不能为空', trigger: 'blur' }
          // ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.nbDeviceGroupId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.nbDeviceGroupId) {
            this.$http({
              url: this.$http.adornUrl(`/nbiot/nbdevicegroup/info/${this.dataForm.nbDeviceGroupId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.groupName = data.nbDeviceGroup.groupName
                this.dataForm.remark = data.nbDeviceGroup.remark
                // this.dataForm.createUserId = data.nbdevicegroup.createUserId
                // this.dataForm.createTime = data.nbdevicegroup.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/nbiot/nbdevicegroup/${!this.dataForm.nbDeviceGroupId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'nbDeviceGroupId': this.dataForm.nbDeviceGroupId || undefined,
                'groupName': this.dataForm.groupName,
                'remark': this.dataForm.remark
                // 'createUserId': this.dataForm.createUserId,
                // 'createTime': this.dataForm.createTime
              })
            }).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)
              }
            })
          }
        })
      }
    }
  }
</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>