Newer
Older
iris_temperature_front_gz / src / views / memberManage / updateFace.vue
zhangyingjie on 6 Aug 2020 3 KB 新增人脸识别下发订阅功能
<template>
  <el-dialog :visible.sync="dialogFormVisible" :close-on-click-modal="false" title="人脸识别数据下发"  append-to-body >
    <el-form ref="dataForm" :model="form" :rules="rules" label-width="auto" >
      <el-row type="flex" justify="center">
        <el-col :span="20">
          <el-form-item label="已选人员">
            <el-tag v-for="item in personList" :key="item.id" class="person-span">{{ item.name }}</el-tag>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <el-col :span="20">
          <el-form-item label="下发设备" prop="selectDeivces">
            <el-select v-model="form.selectDeivces" multiple placeholder="请选择" style="width: 100%">
              <el-option
                v-for="item in deviceList"
                :key="item.id"
                :label="item.devCode"
                :value="''+item.id"/>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="loading" type="primary" @click="saveData">保存</el-button>
      <el-button @click="cancel">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getDeviceListAll } from '../../api/device'
import { updatePersonFace } from '../../api/face'

export default {
  name: 'UpdateFace',
  data() {
    return {
      form: {
        personIds: [],
        selectDeivces: [],
        personType: ''
      },
      rules: {
        selectDeivces: [{ required: true, message: '下发设备不能为空', trigger: ['blur', 'change'] }],
      },
      personList: [],
      deviceList: [],
      dialogFormVisible: false,
      loading: false
    }
  },
  methods: {
    initDialog(dialogFormVisible, personList,personType) {
      this.dialogFormVisible = dialogFormVisible
      this.personList = personList
      this.fetchDeviceList()
      this.form.selectDeivces = []
      this.form.personType = personType
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    fetchDeviceList() {
      const params = {
        devType: '5'
      }
      getDeviceListAll(params).then(res => {
        this.deviceList = res.data
      })
    },
    cancel() {
      this.dialogFormVisible = false
    },
    saveData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          this.form.personIds = this.personList.map(item => item.id)
          console.log(this.form.personIds)
          updatePersonFace(this.form.personIds, this.form.selectDeivces, this.form.personType).then(res => {
            if (res.code === 200) {
              this.loading = false
              this.$message.success('数据下发成功')
              this.dialogFormVisible = false
              this.$emit('finishUpdate')
            } else {
              this.loading = false
              this.dialogFormVisible = false
              this.$emit('finishUpdate')
            }
          }).catch((res) => {
            this.loading = false
            // this.dialogFormVisible = false
            // this.$emit('finishUpdate')
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.person-span{
  color: #909399;
  background-color: #f0f2f5;
  margin-right: 10px;
  border-color: #f0f2f5;
  padding: 0 5px;
}
.dialog-footer {
  margin: auto;
}
</style>