ipms-sjy-ui/src/views/crm/business/components/BusinessListModal.vue

157 lines
4.7 KiB
Vue
Raw Normal View History

2023-12-03 19:56:46 +08:00
<template>
2024-01-02 18:48:47 +08:00
<Dialog title="关联商机" v-model="dialogVisible">
<!-- 搜索工作栏 -->
2023-12-03 19:56:46 +08:00
<ContentWrap>
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="商机名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入商机名称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button type="primary" @click="openForm()" v-hasPermi="['crm:business:create']">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
2023-12-03 19:56:46 +08:00
<!-- 列表 -->
<ContentWrap class="mt-10px">
<el-table
v-loading="loading"
ref="businessRef"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
>
2023-12-03 19:56:46 +08:00
<el-table-column type="selection" width="55" />
<el-table-column label="商机名称" fixed="left" align="center" prop="name">
<template #default="scope">
<el-link type="primary" :underline="false" @click="openDetail(scope.row.id)">
{{ scope.row.name }}
</el-link>
</template>
</el-table-column>
<el-table-column
label="商机金额"
align="center"
prop="totalPrice"
:formatter="erpPriceTableColumnFormatter"
/>
2023-12-03 19:56:46 +08:00
<el-table-column label="客户名称" align="center" prop="customerName" />
<el-table-column label="商机组" align="center" prop="statusTypeName" />
<el-table-column label="商机阶段" align="center" prop="statusName" />
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
2023-12-03 19:56:46 +08:00
<!-- 表单弹窗添加 -->
<BusinessForm ref="formRef" @success="getList" />
</Dialog>
</template>
<script setup lang="ts">
import * as BusinessApi from '@/api/crm/business'
2023-12-17 17:34:32 +08:00
import BusinessForm from '../BusinessForm.vue'
import { erpPriceTableColumnFormatter } from '@/utils'
2023-12-17 17:34:32 +08:00
const message = useMessage() // 消息弹窗
const props = defineProps<{
customerId: number
}>()
2024-01-02 18:48:47 +08:00
defineOptions({ name: 'BusinessListModal' })
2023-12-03 19:56:46 +08:00
const dialogVisible = ref(false) // 弹窗的是否展示
const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryFormRef = ref() // 搜索的表单
const formLoading = ref(false) // 表单的加载中1修改时的数据加载2提交的按钮禁用
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
2023-12-17 17:34:32 +08:00
name: undefined,
customerId: props.customerId
2023-12-03 19:56:46 +08:00
})
2023-12-03 19:56:46 +08:00
/** 打开弹窗 */
2024-01-02 18:48:47 +08:00
const open = async () => {
2023-12-03 19:56:46 +08:00
dialogVisible.value = true
queryParams.customerId = props.customerId // 解决 props.customerId 没更新到 queryParams 上的问题
2023-12-17 17:34:32 +08:00
await getList()
2023-12-03 19:56:46 +08:00
}
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
2023-12-03 19:56:46 +08:00
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
2023-12-17 17:34:32 +08:00
const data = await BusinessApi.getBusinessPageByCustomer(queryParams)
2023-12-03 19:56:46 +08:00
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
2023-12-03 19:56:46 +08:00
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
2023-12-03 19:56:46 +08:00
/** 添加操作 */
const formRef = ref()
const openForm = () => {
formRef.value.open('create')
}
/** 关联商机提交 */
2023-12-03 19:56:46 +08:00
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
const businessRef = ref()
const submitForm = async () => {
2024-01-02 18:48:47 +08:00
const businessIds = businessRef.value
.getSelectionRows()
.map((row: BusinessApi.BusinessVO) => row.id)
if (businessIds.length === 0) {
return message.error('未选择商机')
2023-12-03 19:56:46 +08:00
}
2023-12-17 17:34:32 +08:00
dialogVisible.value = false
emit('success', businessIds, businessRef.value.getSelectionRows())
2023-12-03 19:56:46 +08:00
}
/** 打开联系人详情 */
const { push } = useRouter()
const openDetail = (id: number) => {
push({ name: 'CrmBusinessDetail', params: { id } })
}
</script>