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