<template>
  <el-dialog v-model="modelValue" title="等级切换" width="500px" @close="handleClose">
    <el-form :model="listQuery" ref="formValidate" :rules="rules">
        <el-form-item prop="fxDj" label="风险等级" v-if="props.type == '级别变更'">
            <MOSTY.Select filterable v-model="listQuery.fxDj" :dictEnum="props.dic.D_GS_RQFJ_FXDJ" width="100%" clearable placeholder="请选择风险等级"/>
        </el-form-item>
        <el-form-item prop="ssbmdm" label="所属部门" v-if="props.type == '警种变更'">
            <MOSTY.Department filterable v-model="listQuery.ssbmdm" width="100%" clearable placeholder="请选择所属部门"/>
        </el-form-item>
        <el-form-item prop="uid" label="选择民警" v-if="props.type == '指定分配'">
            <MOSTY.Other @click="chooseUserVisible = true" readonly v-model="listQuery.uidMc" width="100%" clearable placeholder="请选择选择民警"/>
        </el-form-item>
    </el-form>
    <template #footer>
        <div class="tc">
            <el-button @click="handleClose">取消</el-button>
            <el-button type="primary" @click="submitForm">确定</el-button>
        </div>
    </template>
</el-dialog>
<ChooseUser v-model="chooseUserVisible" @choosedUsers="handleUserSelected" :roleIds="roleIds" />

</template>

<script setup>
import ChooseUser from "@/components/MyComponents/ChooseUser/index.vue";
import { ElMessage } from "element-plus";
import { qcckPost } from "@/api/qcckApi.js";
import * as MOSTY from "@/components/MyComponents/index";
import { ref ,defineProps,defineEmits, reactive} from 'vue';
const props = defineProps({
    modelValue:{
        type:Boolean,
        default:false
    },
    ids:{
        type:Array,
        default:[]
    },
    type:String,
    dic:Object
})
const chooseUserVisible = ref(false)
const roleIds = ref([])
const emits = defineEmits(["update:modelValue",'getDepValue']);
const formValidate = ref()
const rules = reactive({
    fxDj: [{ required: true, message: "请选择风险等级", trigger: "change" }],
    ssbmdm: [{ required: true, message: "请选择所属部门", trigger: "change" }],
    uid: [{ required: true, message: "请选择民警", trigger: "change" }],
})
const listQuery = ref({});

const handleUserSelected = (val) => {
    listQuery.value.uid = val[0].id;
    listQuery.value.uidMc = val[0].userName;
    roleIds.value = [val[0].id]
}

const submitForm  = () =>{
    formValidate.value.validate((valid) => {
        if (!valid) return false;
        let params = { ids:props.ids, ...listQuery.value  }
        let url = props.type == '指定分配' ? '/mosty-gsxt/tbGsxtRqfjRy/updateByMj':'/mosty-gsxt/tbGsxtRqfjRy/updateByFxDj'
        qcckPost(params,url).then(res=>{
            ElMessage.success("修改成功");
            emits('update:modelValue',false)
            emits('change')
        })
    })
}

const handleClose = () =>{
    emits('update:modelValue',false)
    formValidate.value.resetFields();
}
</script>

<style lang="scss" scoped>

</style>