<!-- 添加协作 -->
<template>
    <el-dialog title="添加协作" v-model="visible" width="850px">
        <el-form ref="formRef" :model="form" label-width="120px">
            <el-form-item label="接收对象：" prop="newOwnerBy"  :rule="{required: true, message: '请选择接收对象', trigger: 'change'}">
                <SelectUser v-model="form.newOwnerBy"></SelectUser>
            </el-form-item>
<!--            <el-form-item label="选择类型：" prop="typeList" >-->
<!--                <el-checkbox-group v-model="form.typeList">-->
<!--                    <el-checkbox value="1">订单</el-checkbox>-->
<!--                    <el-checkbox value="2">费用</el-checkbox>-->
<!--                    <el-checkbox value="3">发票</el-checkbox>-->
<!--                </el-checkbox-group>-->
<!--            </el-form-item>-->
            <el-form-item label="备注：" >
                <el-input type="textarea" v-model="form.remark"></el-input>
            </el-form-item>
            <p class="tips">*如需变更客户相关记录归属人员请勾选相关选项</p>

        </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 SelectUser from '@/components/SelectOrg/SelectUser.vue';

    import {transferBusiness} from '@/api/business/allBusiness'

    const emit = defineEmits(['onOk'])

    const visible = ref(false)
    const formRef = ref()
    const buttonLoading = ref(false)
    const radio1 = ref('1')

    const open = (businessIdList) => {
        form.businessIdList = businessIdList
        visible.value = true
    }

    const form = reactive({
        businessIdList: [],
        newOwnerBy: undefined,
        remark: undefined,
        typeList: []
    })

    const submitForm = async () => {
        formRef.value.validate(async (valid: boolean) => {
            if (valid) {
               let res = await transferBusiness(form)
                reset()
                visible.value = false
                emit('onOk', 'turnBussnese')
            }
        })

    }

    const cancel = () => {
        visible.value = false
    }
/** 表单重置 */
const reset = () => {
    Object.assign(form, {
        businessIdList: [],
        newOwnerBy: undefined,
        remark: undefined,
        typeList: []
    })
    formRef.value?.resetFields();
}

    defineExpose({
        open
    })
</script>

<style lang="scss" scoped>
.tips{
    padding-left: 120px;
    margin-bottom: 2px;
}
</style>
