!294 feat: 客户表的 crud

Merge pull request !294 from wanwan/master
This commit is contained in:
芋道源码 2023-10-27 14:41:47 +00:00 committed by Gitee
commit 32b3c874f5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 484 additions and 0 deletions

View File

@ -0,0 +1,51 @@
import request from '@/config/axios'
export interface CustomerVO {
id: number
name: string
followUpStatus: boolean
lockStatus: boolean
mobile: string
telephone: string
website: string
remark: string
ownerUserId: number
roUserIds: string
rwUserIds: string
areaId: number
detailAddress: string
longitude: string
latitude: string
contactLastTime: Date
contactNextTime: Date
}
// 查询客户列表
export const getCustomerPage = async (params) => {
return await request.get({ url: `/crm/customer/page`, params })
}
// 查询客户详情
export const getCustomer = async (id: number) => {
return await request.get({ url: `/crm/customer/get?id=` + id })
}
// 新增客户
export const createCustomer = async (data: CustomerVO) => {
return await request.post({ url: `/crm/customer/create`, data })
}
// 修改客户
export const updateCustomer = async (data: CustomerVO) => {
return await request.put({ url: `/crm/customer/update`, data })
}
// 删除客户
export const deleteCustomer = async (id: number) => {
return await request.delete({ url: `/crm/customer/delete?id=` + id })
}
// 导出客户 Excel
export const exportCustomer = async (params) => {
return await request.download({ url: `/crm/customer/export-excel`, params })
}

View File

@ -0,0 +1,195 @@
<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="name">
<el-input v-model="formData.name" placeholder="请输入客户名称" />
</el-form-item>
<el-form-item label="跟进状态" prop="followUpStatus">
<el-radio-group v-model="formData.followUpStatus">
<el-radio
v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="锁定状态" prop="lockStatus">
<el-radio-group v-model="formData.lockStatus">
<el-radio
v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="手机" prop="mobile">
<el-input v-model="formData.mobile" placeholder="请输入手机" />
</el-form-item>
<el-form-item label="电话" prop="telephone">
<el-input v-model="formData.telephone" placeholder="请输入电话" />
</el-form-item>
<el-form-item label="网址" prop="website">
<el-input v-model="formData.website" placeholder="请输入网址" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="formData.remark" placeholder="请输入备注" />
</el-form-item>
<el-form-item label="负责人的用户编号" prop="ownerUserId">
<el-input v-model="formData.ownerUserId" placeholder="请输入负责人的用户编号" />
</el-form-item>
<el-form-item label="只读权限的用户编号数组" prop="roUserIds">
<el-input v-model="formData.roUserIds" placeholder="请输入只读权限的用户编号数组" />
</el-form-item>
<el-form-item label="读写权限的用户编号数组" prop="rwUserIds">
<el-input v-model="formData.rwUserIds" placeholder="请输入读写权限的用户编号数组" />
</el-form-item>
<el-form-item label="地区编号" prop="areaId">
<el-input v-model="formData.areaId" placeholder="请输入地区编号" />
</el-form-item>
<el-form-item label="详细地址" prop="detailAddress">
<el-input v-model="formData.detailAddress" placeholder="请输入详细地址" />
</el-form-item>
<el-form-item label="地理位置经度" prop="longitude">
<el-input v-model="formData.longitude" placeholder="请输入地理位置经度" />
</el-form-item>
<el-form-item label="地理位置维度" prop="latitude">
<el-input v-model="formData.latitude" placeholder="请输入地理位置维度" />
</el-form-item>
<el-form-item label="最后跟进时间" prop="contactLastTime">
<el-date-picker
v-model="formData.contactLastTime"
type="date"
value-format="x"
placeholder="选择最后跟进时间"
/>
</el-form-item>
<el-form-item label="下次联系时间" prop="contactNextTime">
<el-date-picker
v-model="formData.contactNextTime"
type="date"
value-format="x"
placeholder="选择下次联系时间"
/>
</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 { DICT_TYPE, getBoolDictOptions } from '@/utils/dict'
import * as CustomerApi from '@/api/crm/customer'
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
name: undefined,
followUpStatus: undefined,
lockStatus: undefined,
mobile: undefined,
telephone: undefined,
website: undefined,
remark: undefined,
ownerUserId: undefined,
roUserIds: undefined,
rwUserIds: undefined,
areaId: undefined,
detailAddress: undefined,
longitude: undefined,
latitude: undefined,
contactLastTime: undefined,
contactNextTime: undefined
})
const formRules = reactive({
name: [{ require: true, message: '跟进状态不能为空', trigger: 'blur' }],
followUpStatus: [{ required: true, message: '跟进状态不能为空', trigger: 'blur' }],
lockStatus: [{ required: true, message: '锁定状态不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
formLoading.value = true
try {
formData.value = await CustomerApi.getCustomer(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as unknown as CustomerApi.CustomerVO
if (formType.value === 'create') {
await CustomerApi.createCustomer(data)
message.success(t('common.createSuccess'))
} else {
await CustomerApi.updateCustomer(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
name: undefined,
followUpStatus: undefined,
lockStatus: undefined,
mobile: undefined,
telephone: undefined,
website: undefined,
remark: undefined,
ownerUserId: undefined,
roUserIds: undefined,
rwUserIds: undefined,
areaId: undefined,
detailAddress: undefined,
longitude: undefined,
latitude: undefined,
contactLastTime: undefined,
contactNextTime: undefined
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,238 @@
<template>
<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 label="手机" prop="mobile">
<el-input
v-model="queryParams.mobile"
placeholder="请输入手机"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="电话" prop="telephone">
<el-input
v-model="queryParams.telephone"
placeholder="请输入电话"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="网址" prop="website">
<el-input
v-model="queryParams.website"
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('create')" v-hasPermi="['crm:customer:create']">
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['crm:customer:export']"
>
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="客户名称" align="center" prop="name" />
<el-table-column label="跟进状态" align="center" prop="followUpStatus">
<template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.followUpStatus" />
</template>
</el-table-column>
<el-table-column label="锁定状态" align="center" prop="lockStatus">
<template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.lockStatus" />
</template>
</el-table-column>
<el-table-column label="成交状态" align="center" prop="dealStatus">
<template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.dealStatus" />
</template>
</el-table-column>
<el-table-column label="手机" align="center" prop="mobile" />
<el-table-column label="电话" align="center" prop="telephone" />
<el-table-column label="网址" align="center" prop="website" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="负责人的用户编号" align="center" prop="ownerUserId" />
<el-table-column label="地区编号" align="center" prop="areaId" />
<el-table-column label="详细地址" align="center" prop="detailAddress" />
<el-table-column label="地理位置经度" align="center" prop="longitude" />
<el-table-column label="地理位置维度" align="center" prop="latitude" />
<el-table-column
label="最后跟进时间"
align="center"
prop="contactLastTime"
:formatter="dateFormatter"
width="180px"
/>
<el-table-column
label="下次联系时间"
align="center"
prop="contactNextTime"
:formatter="dateFormatter"
width="180px"
/>
<el-table-column
label="创建时间"
align="center"
prop="createTime"
:formatter="dateFormatter"
width="180px"
/>
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['crm:customer:update']"
>
编辑
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['crm:customer:delete']"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<CustomerForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import { DICT_TYPE, getBoolDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import * as CustomerApi from '@/api/crm/customer'
import CustomerForm from './CustomerForm.vue'
defineOptions({ name: 'CrmCustomer' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const total = ref(0) //
const list = ref([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: null,
mobile: null,
telephone: null,
website: null
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await CustomerApi.getCustomerPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await CustomerApi.deleteCustomer(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await CustomerApi.exportCustomer(queryParams)
download.excel(data, '客户.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>