<!-- 移入公海 -->
<template>
    <el-dialog title="移入公海" v-model="visible" width="850px">
        <el-form ref="formRef" :model="form" label-width="90px">
            <el-form-item label="置公原因：" prop="reasonPublicCustomerDictValue">
                <SelectDict v-model="form.reasonPublicCustomerDictValue" placeholder="请选择置公原因" dictCode="reason_public_customer"></SelectDict>
                <p style="margin-top: 10px;">* 转移到公海后此客户数据将属于公共资源，原归属人员不能再维护跟进和更新此客户数据。</p>
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="cancel">取消</el-button>
                <el-button :loading="buttonLoading" type="primary" @click="submitForm">提交</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
    import { movePublicSea, movePublicSeaTypes } from '@/api/customer'
    import { useDictCache } from '@/hooks/web/useDict'

    const { queryDictDetailByCodes } = useDictCache(['reason_public_customer'])
    queryDictDetailByCodes()

    const emits = defineEmits(['refresh'])
    const visible = ref(false)
    const buttonLoading = ref(false)

    const open = (idList: (string | number)[]) => {
        form.value.idList = idList
        visible.value = true
    }

    const form = ref<movePublicSeaTypes>({
        reasonPublicCustomerDictValue: '',
        hasPublicCustomer: true,
        idList: [],
    })

    const submitForm = () => {
        if(!form.value.reasonPublicCustomerDictValue) {
            ElMessage.error("请选择置公原因")
            return false
        }
        movePublicSea(form.value).then(res => {
            if(res.success) {
                ElMessage.success("移入公海成功")
                emits('refresh')
                cancel()
            }
        })
    }

    const cancel = () => {
        visible.value = false
    }

    defineExpose({
        open
    })
</script>

<style lang="scss" scoped>

</style>
