114 lines
3.1 KiB
Vue
114 lines
3.1 KiB
Vue
<template>
|
|
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
|
<el-form
|
|
ref="formRef"
|
|
:model="formData"
|
|
:rules="formRules"
|
|
label-width="100px"
|
|
v-loading="formLoading"
|
|
>
|
|
<el-form-item label="选择公海" prop="openSeaId">
|
|
<el-select
|
|
v-model="formData.openSeaId"
|
|
placeholder="请选择"
|
|
clearable
|
|
class="!w-240px"
|
|
>
|
|
<el-option
|
|
v-for="item in openSeaList"
|
|
:key="item.id"
|
|
:value="item.id"
|
|
:label="item.name"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-form>
|
|
<template #footer>
|
|
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
</template>
|
|
</Dialog>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { CustomerInforApi } from '@/api/crm/customer/customer'
|
|
import { OpenSeaApi, OpenSeaVO } from '@/api/crm/opensea'
|
|
import { reactive, ref } from 'vue'
|
|
|
|
defineOptions({ name: 'TransferForm' })
|
|
|
|
const message = useMessage() // 消息弹窗
|
|
const { t } = useI18n() // 国际化
|
|
|
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
|
const dialogTitle = ref('转移到公海') // 弹窗的标题
|
|
const formLoading = ref(false) // 表单的加载中
|
|
const openSeaList = ref<OpenSeaVO[]>([]) // 公海列表
|
|
|
|
const formData = ref({
|
|
openSeaId: undefined as number | undefined,
|
|
customerIds: [] as number[] // 选中的客户ID列表
|
|
})
|
|
|
|
const formRules = reactive({
|
|
openSeaId: [{ required: true, message: '请选择公海', trigger: 'change' }]
|
|
})
|
|
|
|
const formRef = ref() // 表单 Ref
|
|
|
|
/** 打开弹窗 */
|
|
const open = async (customerIds: number[], type?: number) => {
|
|
dialogVisible.value = true
|
|
formData.value.customerIds = customerIds
|
|
resetForm()
|
|
// 根据type加载不同的公海列表
|
|
if (type === 1) {
|
|
// 获取自己适配的公海
|
|
openSeaList.value = await OpenSeaApi.getOpenSeaListByCurUser()
|
|
} else {
|
|
// 获取全部公海
|
|
openSeaList.value = await OpenSeaApi.getOpenSeaList(null)
|
|
}
|
|
}
|
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
|
|
|
/** 提交表单 */
|
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
|
const submitForm = async () => {
|
|
// 校验表单
|
|
await formRef.value.validate()
|
|
if (!formData.value.openSeaId) {
|
|
message.error('请选择公海')
|
|
return
|
|
}
|
|
if (formData.value.customerIds.length === 0) {
|
|
message.error('请选择要转移的客户')
|
|
return
|
|
}
|
|
|
|
formLoading.value = true
|
|
try {
|
|
const data = {
|
|
openSeaId: formData.value.openSeaId,
|
|
customerIds: formData.value.customerIds
|
|
}
|
|
await CustomerInforApi.transfer(data)
|
|
message.success('转移成功')
|
|
dialogVisible.value = false
|
|
emit('success')
|
|
} catch (error) {
|
|
message.error('转移失败')
|
|
} finally {
|
|
formLoading.value = false
|
|
}
|
|
}
|
|
|
|
/** 重置表单 */
|
|
const resetForm = () => {
|
|
formData.value = {
|
|
openSeaId: undefined,
|
|
customerIds: formData.value.customerIds
|
|
}
|
|
formRef.value?.resetFields()
|
|
}
|
|
</script> |