增加商户归属的增加和修改。
This commit is contained in:
parent
d602175913
commit
a7b25fd7f3
@ -65,6 +65,25 @@
|
|||||||
:label-col="{ span: 6 }"
|
:label-col="{ span: 6 }"
|
||||||
:wrapper-col="{ span: 16 }"
|
:wrapper-col="{ span: 16 }"
|
||||||
>
|
>
|
||||||
|
<a-form-item label="选择用户" name="user_id" required>
|
||||||
|
<a-select
|
||||||
|
v-model:value="formState.user_id"
|
||||||
|
placeholder="请选择用户"
|
||||||
|
:loading="userLoading"
|
||||||
|
:filter-option="false"
|
||||||
|
:show-search="true"
|
||||||
|
@search="handleUserSearch"
|
||||||
|
>
|
||||||
|
<a-select-option
|
||||||
|
v-for="user in userOptions"
|
||||||
|
:key="user.userid"
|
||||||
|
:value="user.userid"
|
||||||
|
>
|
||||||
|
{{ user.phone }} ({{ user.username || '未设置昵称' }})
|
||||||
|
</a-select-option>
|
||||||
|
</a-select>
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item label="商家分类" name="category_id" required>
|
<a-form-item label="商家分类" name="category_id" required>
|
||||||
<a-select
|
<a-select
|
||||||
v-model:value="formState.category_id"
|
v-model:value="formState.category_id"
|
||||||
@ -195,6 +214,25 @@
|
|||||||
:label-col="{ span: 6 }"
|
:label-col="{ span: 6 }"
|
||||||
:wrapper-col="{ span: 16 }"
|
:wrapper-col="{ span: 16 }"
|
||||||
>
|
>
|
||||||
|
<a-form-item label="选择用户" name="user_id" required>
|
||||||
|
<a-select
|
||||||
|
v-model:value="editFormState.user_id"
|
||||||
|
placeholder="请选择用户"
|
||||||
|
:loading="userLoading"
|
||||||
|
:filter-option="false"
|
||||||
|
:show-search="true"
|
||||||
|
@search="handleUserSearch"
|
||||||
|
>
|
||||||
|
<a-select-option
|
||||||
|
v-for="user in userOptions"
|
||||||
|
:key="user.userid"
|
||||||
|
:value="user.userid"
|
||||||
|
>
|
||||||
|
{{ user.phone }} ({{ user.username || '未设置昵称' }})
|
||||||
|
</a-select-option>
|
||||||
|
</a-select>
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item label="商家分类" name="category_id" required>
|
<a-form-item label="商家分类" name="category_id" required>
|
||||||
<a-select
|
<a-select
|
||||||
v-model:value="editFormState.category_id"
|
v-model:value="editFormState.category_id"
|
||||||
@ -305,6 +343,16 @@ export default defineComponent({
|
|||||||
width: 80,
|
width: 80,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '商户归属',
|
||||||
|
dataIndex: 'user_info',
|
||||||
|
key: 'user_info',
|
||||||
|
width: 200,
|
||||||
|
customRender: ({ record }) => {
|
||||||
|
if (!record.user_username && !record.user_phone) return '-'
|
||||||
|
return `${record.user_username || '未设置昵称'} (${record.user_phone})`
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '商家分类',
|
title: '商家分类',
|
||||||
dataIndex: 'category_name',
|
dataIndex: 'category_name',
|
||||||
@ -315,7 +363,7 @@ export default defineComponent({
|
|||||||
title: '商家名称',
|
title: '商家名称',
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
width: 150,
|
width: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '营业时间',
|
title: '营业时间',
|
||||||
@ -327,7 +375,8 @@ export default defineComponent({
|
|||||||
title: '地址',
|
title: '地址',
|
||||||
dataIndex: 'address',
|
dataIndex: 'address',
|
||||||
key: 'address',
|
key: 'address',
|
||||||
width: 200,
|
ellipsis: true,
|
||||||
|
width: 300,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '位置',
|
title: '位置',
|
||||||
@ -339,7 +388,7 @@ export default defineComponent({
|
|||||||
title: '联系电话',
|
title: '联系电话',
|
||||||
dataIndex: 'phone',
|
dataIndex: 'phone',
|
||||||
key: 'phone',
|
key: 'phone',
|
||||||
width: 120,
|
width: 150,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '创建时间',
|
title: '创建时间',
|
||||||
@ -350,9 +399,9 @@ export default defineComponent({
|
|||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
width: 120,
|
width: 200,
|
||||||
|
fixed: 'right',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
fixed: 'right'
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -439,9 +488,13 @@ export default defineComponent({
|
|||||||
const addMap = ref(null)
|
const addMap = ref(null)
|
||||||
const addMarker = ref(null)
|
const addMarker = ref(null)
|
||||||
|
|
||||||
|
const userLoading = ref(false)
|
||||||
|
const userOptions = ref([])
|
||||||
|
|
||||||
const formState = ref({
|
const formState = ref({
|
||||||
name: '',
|
user_id: undefined,
|
||||||
category_id: undefined,
|
category_id: undefined,
|
||||||
|
name: '',
|
||||||
business_hours: '',
|
business_hours: '',
|
||||||
address: '',
|
address: '',
|
||||||
longitude: null,
|
longitude: null,
|
||||||
@ -450,8 +503,9 @@ export default defineComponent({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const rules = {
|
const rules = {
|
||||||
name: [{ required: true, message: '请输入商家名称' }],
|
user_id: [{ required: true, message: '请选择用户' }],
|
||||||
category_id: [{ required: true, message: '请选择商家分类' }],
|
category_id: [{ required: true, message: '请选择商家分类' }],
|
||||||
|
name: [{ required: true, message: '请输入商家名称' }],
|
||||||
business_hours: [{ required: true, message: '请输入营业时间' }],
|
business_hours: [{ required: true, message: '请输入营业时间' }],
|
||||||
address: [{ required: true, message: '请输入详细地址' }],
|
address: [{ required: true, message: '请输入详细地址' }],
|
||||||
phone: [{ required: true, message: '请输入联系电话' }],
|
phone: [{ required: true, message: '请输入联系电话' }],
|
||||||
@ -610,31 +664,24 @@ export default defineComponent({
|
|||||||
|
|
||||||
// 取消添加
|
// 取消添加
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
// 重置表单数据
|
|
||||||
formRef.value?.resetFields()
|
formRef.value?.resetFields()
|
||||||
|
|
||||||
// 重置表单状态
|
|
||||||
formState.value = {
|
formState.value = {
|
||||||
name: '',
|
user_id: undefined,
|
||||||
category_id: undefined,
|
category_id: undefined,
|
||||||
|
name: '',
|
||||||
business_hours: '',
|
business_hours: '',
|
||||||
address: '',
|
address: '',
|
||||||
longitude: null,
|
longitude: null,
|
||||||
latitude: null,
|
latitude: null,
|
||||||
phone: ''
|
phone: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置搜索相关数据
|
|
||||||
searchAddress.value = ''
|
searchAddress.value = ''
|
||||||
searchOptions.value = []
|
searchOptions.value = []
|
||||||
|
userOptions.value = []
|
||||||
// 清除地图标记
|
|
||||||
if (addMarker.value) {
|
if (addMarker.value) {
|
||||||
addMarker.value.setMap(null)
|
addMarker.value.setMap(null)
|
||||||
addMarker.value = null
|
addMarker.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关闭模态框
|
|
||||||
addModalVisible.value = false
|
addModalVisible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -778,6 +825,7 @@ export default defineComponent({
|
|||||||
const editLoading = ref(false)
|
const editLoading = ref(false)
|
||||||
const editFormRef = ref(null)
|
const editFormRef = ref(null)
|
||||||
const editFormState = ref({
|
const editFormState = ref({
|
||||||
|
user_id: undefined,
|
||||||
name: '',
|
name: '',
|
||||||
category_id: undefined,
|
category_id: undefined,
|
||||||
business_hours: '',
|
business_hours: '',
|
||||||
@ -795,6 +843,7 @@ export default defineComponent({
|
|||||||
const handleEdit = async (record) => {
|
const handleEdit = async (record) => {
|
||||||
currentEditId.value = record.id
|
currentEditId.value = record.id
|
||||||
editFormState.value = {
|
editFormState.value = {
|
||||||
|
user_id: record.user_id,
|
||||||
name: record.name,
|
name: record.name,
|
||||||
category_id: record.category_id,
|
category_id: record.category_id,
|
||||||
business_hours: record.business_hours,
|
business_hours: record.business_hours,
|
||||||
@ -808,6 +857,15 @@ export default defineComponent({
|
|||||||
if (categories.value.length === 0) {
|
if (categories.value.length === 0) {
|
||||||
await fetchCategories()
|
await fetchCategories()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 加载当前用户信息到选项中
|
||||||
|
if (record.user_id && record.user_phone) {
|
||||||
|
userOptions.value = [{
|
||||||
|
userid: record.user_id,
|
||||||
|
phone: record.user_phone,
|
||||||
|
username: record.user_username
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
editModalVisible.value = true
|
editModalVisible.value = true
|
||||||
await nextTick()
|
await nextTick()
|
||||||
@ -893,13 +951,25 @@ export default defineComponent({
|
|||||||
editFormRef.value.validate().then(async () => {
|
editFormRef.value.validate().then(async () => {
|
||||||
try {
|
try {
|
||||||
editLoading.value = true
|
editLoading.value = true
|
||||||
await request.put(`/api/merchant/${currentEditId.value}`, editFormState.value)
|
|
||||||
message.success('修改成功')
|
// 确保包含 user_id 在请求数据中
|
||||||
editModalVisible.value = false
|
const updateData = {
|
||||||
fetchData()
|
...editFormState.value,
|
||||||
|
user_id: editFormState.value.user_id
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await request.put(`/api/merchant/${currentEditId.value}`, updateData)
|
||||||
|
|
||||||
|
if (res.code === 200) {
|
||||||
|
message.success('修改成功')
|
||||||
|
editModalVisible.value = false
|
||||||
|
fetchData()
|
||||||
|
} else {
|
||||||
|
throw new Error(res.message || '修改失败')
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('修改商家失败:', error)
|
console.error('修改商家失败:', error)
|
||||||
message.error('修改失败')
|
message.error(error.message || '修改失败')
|
||||||
} finally {
|
} finally {
|
||||||
editLoading.value = false
|
editLoading.value = false
|
||||||
}
|
}
|
||||||
@ -909,7 +979,18 @@ export default defineComponent({
|
|||||||
// 取消修改
|
// 取消修改
|
||||||
const handleEditCancel = () => {
|
const handleEditCancel = () => {
|
||||||
editFormRef.value?.resetFields()
|
editFormRef.value?.resetFields()
|
||||||
|
editFormState.value = {
|
||||||
|
user_id: undefined,
|
||||||
|
name: '',
|
||||||
|
category_id: undefined,
|
||||||
|
business_hours: '',
|
||||||
|
address: '',
|
||||||
|
longitude: null,
|
||||||
|
latitude: null,
|
||||||
|
phone: ''
|
||||||
|
}
|
||||||
editSearchAddress.value = ''
|
editSearchAddress.value = ''
|
||||||
|
userOptions.value = []
|
||||||
if (editMarker.value) {
|
if (editMarker.value) {
|
||||||
editMarker.value.setMap(null)
|
editMarker.value.setMap(null)
|
||||||
editMarker.value = null
|
editMarker.value = null
|
||||||
@ -917,6 +998,33 @@ export default defineComponent({
|
|||||||
editModalVisible.value = false
|
editModalVisible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 搜索用户
|
||||||
|
const handleUserSearch = async (value) => {
|
||||||
|
if (!value || value.length < 3) {
|
||||||
|
userOptions.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
userLoading.value = true
|
||||||
|
const res = await request.get('/api/user/list', {
|
||||||
|
params: {
|
||||||
|
phone: value,
|
||||||
|
limit: 10
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.code === 200) {
|
||||||
|
userOptions.value = res.data.items || []
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('搜索用户失败:', error)
|
||||||
|
message.error('搜索用户失败')
|
||||||
|
} finally {
|
||||||
|
userLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchData()
|
fetchData()
|
||||||
})
|
})
|
||||||
@ -966,7 +1074,10 @@ export default defineComponent({
|
|||||||
handleEdit,
|
handleEdit,
|
||||||
handleEditSubmit,
|
handleEditSubmit,
|
||||||
handleEditCancel,
|
handleEditCancel,
|
||||||
handleEditSelect
|
handleEditSelect,
|
||||||
|
userLoading,
|
||||||
|
userOptions,
|
||||||
|
handleUserSearch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -1035,4 +1146,10 @@ export default defineComponent({
|
|||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:deep(.ant-select-item-option-content) {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Loading…
Reference in New Issue
Block a user