<template>
    <div>
        <dg-row>
            <el-col>
                <dg-button type="primary" icon="el-icon-plus" size="middle" @click="handleAddUser()"
                    >添加关联用户</dg-button
                >
            </el-col>
        </dg-row>
        <dg-tag style="margin-top: 10px" effect="plain" type="primary"> 已关联用户 </dg-tag>

        <dg-row style="margin-top: 10px">
            <new-table
                ref="table"
                :tableUrl="relUserTableUrl"
                :tableHeader="tableHeader"
                :condition="condition"
                :tableOptList="tableOptList"
                @submitTableOpt="handleRemove"
            >
            </new-table>
        </dg-row>
        <div v-footer>
            <dg-button @click="$emit('close')">关闭</dg-button>
        </div>
    </div>
</template>

<script>
import { relUserTableUrl, deleteUserRel } from "@/api/environment-manage"
import newTable from "@/components/new-table"
export default {
    props: {
        elementId: String
    },
    components: { newTable },
    data() {
        return {
            relUserTableUrl,
            tableHeader: [
                { label: "姓名", prop: "userName" },
                { label: "警号", prop: "policeNumber" },
                { label: "身份证号码", prop: "idcard" },
                { label: "单位名称", prop: "orgName" }
            ],
            tableOptList: ["删除"],
            condition: {
                elementId: {
                    value: this.elementId,
                    op: "="
                }
            }
        }
    },
    methods: {
        // 添加关联用户
        handleAddUser() {
            const vm = this
            const layer = this.$dgLayer({
                title: "添加关联用户",
                content: require("./add-user-form.vue"),
                props: {
                    elementId: this.elementId
                },
                on: {
                    success() {
                        vm.$refs.table.handleSearch()
                        layer.close(layer.dialogIndex)
                    }
                },
                area: ["1100px", "700px"]
            })
        },
        // 移除用户
        handleRemove(opt, row) {
            this.$dgConfirm("是否确定移除这条数据!", "提示").then(() => {
                deleteUserRel(row.id).then(res => {
                    this.$refs.table.handleSearch()
                })
            })
        }
    }
}
</script>

<style lang="scss"></style>
