doum
2025-09-25 c5675caab8392bfafd217d06529c2547edaa6aa8
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
<template>
  <GlobalWindow :title="title" :visible.sync="visible" width="900px" :confirm-working="isWorking" @confirm="confirm">
    <p class="tip-warn"><i class="el-icon-warning"></i>提醒:<br>
      1.门禁权限配置成功后,授权任务即进入权限下发队列,可前往【人员授权记录】查看下发进度;<br>
      2.如果需要清空当前选中人员下发权限,以下【已选门禁点分组】为空提交即可。
    </p>
    <p class="tip" v-if="form.names != null">正在为<em>【{{ form.names.map(item => `${item}`).join(',') }}】</em> 配置门禁权限</p>
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="门禁有效期:" prop="timeType">
        <el-radio-group v-model="form.timeType">
          <el-radio :label="0">长期有效</el-radio>
          <el-radio :label="1">自定义时间</el-radio>
          <el-radio :label="2" v-if="companyType === 0">培训有效期</el-radio>
        </el-radio-group>
        <div v-if="form.timeType == 1" style="margin-top: 10px">
          <el-date-picker @change="seleTime" v-model="time" type="datetimerange" format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-form-item label="门禁点分组:" prop="roleIds">
        <el-transfer style="margin-top: 15px;font-size: 12px" :titles="['未选门禁点分组', '已选门禁点分组']" filterable
          :filter-method="filterMethod" filter-placeholder="请输入门禁点分组名称" v-model="form.roleIds" class="transfer"
          :data="roles">
        </el-transfer>
      </el-form-item>
 
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import { getDeviceRoleList } from '@/api/business/device'
export default {
  name: 'OperaDeviceRoleWindow',
  extends: BaseOpera,
  components: { GlobalWindow },
  data() {
    var validateTime = (rule, value, callback) => {
      if (this.form.timeType == null) {
        callback(new Error('请填写正确的门禁有效期时间'))
        return
      }
      if (this.form.timeType === 1 && (this.form.startTime == null || this.form.endTime == null)) {
        callback(new Error('请填写正确的门禁有效期时间'))
        return
      }
      callback()
    }
    return {
      // 表单数据
      time: null,
      companyType: 1,
      form: {
        ids: [],
        names: [],
        timeType: 0,
        roleIds: [],
        status: 1,
        startTime: null,
        endTime: null,
        radio: 0
      },
      roles: [],
      rules: {
        // 验证规则
        timeType: [
          { required: true, validator: validateTime, message: '请选中门禁有效期' }
        ],
        startTime: [
          { validator: validateTime, trigger: 'blur' }
        ],
        endTime: [
          { validator: validateTime, trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.config({
      api: '/business/member',
      'field.id': 'id'
    })
  },
  methods: {
    filterMethod(query, item) {
      if (!query) return item
      return item.label.indexOf(query) > -1
    },
    seleTime(e) {
      if (e && e.length >= 2) {
        this.form.startTime = e[0]
        this.form.endTime = e[1]
      } else {
        this.form.startTime = null
        this.form.endTime = null
      }
    },
    confirm() {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return
        }
        if (this.form.roleIds == null || this.form.roleIds.length == 0) {
          this.$dialog.actionConfirm('权限为空,提交后即清除所选人员已分配权限!请谨慎操作', '您确认进行该操作吗?')
            .then(() => {
              this.confirmDo()
            })
            .catch(() => { })
        } else {
          this.confirmDo()
        }
      })
    },
    confirmDo() {
      // 调用新建接口
      this.isWorking = true
      this.api.batchRoleAuth({
        ids: this.form.ids,
        timeType: this.form.timeType,
        startTime: this.form.startTime,
        endTime: this.form.endTime,
        roleIds: this.form.roleIds
      })
        .then(() => {
          this.visible = false
          this.$tip.apiSuccess('授权成功,可前往【人员授权记录】查看下发进度')
          this.$emit('success')
        })
        .catch(e => {
          //  this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.isWorking = false
        })
    },
    // 获取设备
    getLists() {
      getDeviceRoleList({ type: 2 })
        .then(res => {
          this.roles = res.map(item => {
            return {
              label: item.name,
              area: item.name,
              key: item.id
            }
          })
        })
    },
    open(title, ids, names, companyType) {
      this.roles = []
      this.getLists()
      this.title = title
      this.visible = true
      this.companyType = companyType
      // 新建
      this.$nextTick(() => {
        this.$refs.form.resetFields()
        this.form[this.configData['field.id']] = null
        this.form.ids = ids
        this.form.names = names
 
        console.log(names)
      })
    }
  }
}
</script>
 
<style scoped lang="scss">
@import "@/assets/style/variables.scss";
 
// 角色配置
.global-window {
  .tip {
    em {
      font-style: normal;
      color: $primary-color;
      font-weight: bold;
    }
  }
 
  .tip-warn {
    margin: 4px 0 12px 0;
    font-size: 12px;
    color: #999;
 
    i {
      color: orange;
      margin-right: 4px;
      font-size: 14px;
      position: relative;
      top: 1px;
    }
  }
}
 
.transfer {
  height: 600px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
 
  ::v-deep .el-transfer-panel {
    flex: 1;
    height: 100%;
  }
 
  ::v-deep .el-transfer-panel__body {
    height: 500px;
  }
 
  ::v-deep .el-transfer-panel__list.is-filterable {
    height: 480px;
  }
}
</style>