<template>
    <div class="system-add-blackList-container">
        <el-dialog v-model="state.isShowDialog" width="500px" draggable title="新增黑名单">
            <el-form :model="state.ruleForm" ref="blacklistFormRef" label-width="80px" label-position="left">
                <el-row :gutter="35">
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="电话号码" prop="phoneNo" :rules="[{ required: true, message: '请输入电话号码', trigger: 'blur' }
                        ]">
                            <el-input v-model="state.ruleForm.phoneNo" placeholder="请输入电话号码" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="级别" prop="level" :rules="[{ required: true, message: '请选择级别', trigger: 'change' }]">
                            <template #label>
                                <p class="flex-center-align">级别
                                    <el-popover :width="500" trigger="hover">
                                        <template #reference>
                                            <SvgIcon name="ele-QuestionFilled" color="var(--el-color-info)" class="ml5"/>
                                        </template>
                                        <div>
                                            <p>呼入限制：接通后直接挂断</p>
                                            <p>坐席限制：可进入IVR，可使用语音导航功能以及智能机器人（如有），不支持转人工服务，语音导航中屏蔽转人工选项</p>
                                            <p>友情提示：接通后，播放礼貌性提示语后挂断（提示语在呼叫中心配置），提示语内容由业务设定</p>
                                        </div>
                                    </el-popover>
                                </p>
                            </template>
                            <el-select v-model="state.ruleForm.level" placeholder="请选择级别" class="w100">
                                <el-option v-for="item in state.levelList" :key="item.value" :label="item.label"
                                    :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="黑名单时长(秒)" prop="duration"
                            :rules="[{ required: true, message: '请输入时间(秒)', trigger: 'blur' }]">
                            <el-input-number v-model="state.ruleForm.duration" :precision="0" :min="1" class="w100" />
                        </el-form-item>
                    </el-col> -->
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="时间" prop="time"
                            :rules="[{ required: true, message: '请选择时间', trigger: 'change' }]">
                            <el-date-picker
                                v-model="state.ruleForm.time"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间"
                                value-format="YYYY-MM-DD[T]HH:mm:ss.sss[Z]"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="24" :lg="24" :xl="24">
						<el-form-item label="情况说明" prop="remark" :rules="[{ required: true, message: '请输入情况说明', trigger: 'blur' }]">
							<el-input v-model="state.ruleForm.remark" type="textarea" :autosize="{ minRows: 4, maxRows: 6 }" placeholder="请输入情况说明" clearable></el-input>
						</el-form-item>
					</el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="closeDialog" class="default-button">取 消</el-button>
                    <el-button type="primary" @click="onSubmit">保 存</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts" setup name="addBlacklist">
import { ref, reactive} from 'vue';
import { ElMessage } from 'element-plus';
import { addBlacklist } from '/@/api/tels/blacklist';

// 定义接口来定义对象的类型
interface StateBacklist {
    ruleForm: {
        phoneNo: string; //电话号码
        level: string; //级别
        time:Array<any>; // 时间
        remark:string; //清空说明
    }
    isShowDialog: boolean;
    levelList: Array<any>; // 级别列表
}

// 定义子组件向父组件传值/事件
const emit = defineEmits(['updateList', 'openDialog', 'closeDialog'])

// 定义变量内容
const blacklistFormRef = ref();
const state = reactive<StateBacklist>({
    ruleForm: {
        phoneNo: "",
        level:'',
        time:[],
        remark:''
    },
    isShowDialog: false,
    levelList: [
		{
			label: '呼入限制',
			value: 0
		},
		{
			label: '坐席限制',
			value: 1
		},{
			label: '友情提示',
			value: 2
		},
	],
})
// 打开弹窗
const openDialog = () => {
    blacklistFormRef.value?.resetFields();
    state.isShowDialog = true;
    emit('openDialog')
}
// 关闭弹窗
const closeDialog = () => {
    state.isShowDialog = false;
    emit('closeDialog')
};
// 新增保存
const onSubmit = () => {
    blacklistFormRef.value.validate((valid: boolean) => {
        if (valid) {
            addBlacklist(state.ruleForm).then(() => {
                ElMessage.success("新增成功")
                emit("updateList");
                state.isShowDialog = false;
            })
        } else {
            return false;
        }
    });
}
//暴漏变量和方法
defineExpose({ closeDialog, openDialog })
</script>
