diff --git a/src/api/supermarket/mallCategory.ts b/src/api/supermarket/mallCategory.ts index b993d34..53fdc4c 100644 --- a/src/api/supermarket/mallCategory.ts +++ b/src/api/supermarket/mallCategory.ts @@ -39,10 +39,10 @@ export function putObj(obj?: Object) { }) } -export function tree(obj?: Object) { +export function tree(params?: Object) { return request({ url: '/supermarket/mallCategory/tree', method: 'get', - data: obj + params: params }) } diff --git a/src/views/supermarket/mallCategory/form.vue b/src/views/supermarket/mallCategory/form.vue index 4192b8c..bc37ff7 100644 --- a/src/views/supermarket/mallCategory/form.vue +++ b/src/views/supermarket/mallCategory/form.vue @@ -3,6 +3,19 @@ :close-on-click-modal="false" draggable> + + + + + + + + @@ -58,6 +71,7 @@ import { useDict } from '/@/hooks/dict'; import { useMessage } from "/@/hooks/message"; import { getObj, addObj, putObj, fetchList } from '/@/api/supermarket/mallCategory' +import { selectOption as fetchMerchantSelect } from '/@/api/supermarket/mallMerchant'; import { rule } from '/@/utils/validate'; import { ref, reactive, nextTick, onMounted } from 'vue'; const emit = defineEmits(['refresh']); @@ -72,6 +86,7 @@ const { status } = useDict('status') // 提交表单数据 const form = reactive({ id:'', + merchantId: '', parentId: '', name: '', sort: 0, @@ -81,12 +96,16 @@ const form = reactive({ // 定义校验规则 const dataRules = ref({ + merchantId: [{ required: true, message: '商户不能为空', trigger: 'change' }], name: [{required: true, message: '分类名称不能为空', trigger: 'blur'}], }) // 分类选项 const categoryOptions = ref([]); +// 商户选项 +const merchantOptions = ref([]); + // 获取所有分类(排除自身) const loadCategories = async () => { const res = await fetchList({ size: 9999 }); @@ -96,8 +115,15 @@ const loadCategories = async () => { } }; +// 加载商户选项 +const loadMerchantOptions = async () => { + const res = await fetchMerchantSelect(); + merchantOptions.value = res.data || []; +}; + onMounted(() => { loadCategories(); + loadMerchantOptions(); }); // 打开弹窗 @@ -108,6 +134,7 @@ const openDialog = (id: string) => { // 重置表单数据 nextTick(() => { dataFormRef.value?.resetFields(); + form.merchantId = ''; form.status = '0'; }); @@ -116,8 +143,9 @@ const openDialog = (id: string) => { form.id = id getmallCategoryData(id) } else { - // 新增时直接加载分类 + // 新增时直接加载分类和商户 loadCategories(); + loadMerchantOptions(); } }; @@ -146,8 +174,9 @@ const getmallCategoryData = (id: string) => { loading.value = true getObj(id).then((res: any) => { Object.assign(form, res.data) - // 编辑时加载分类并排除自己 + // 编辑时加载分类和商户并排除自己 loadCategories(); + loadMerchantOptions(); }).finally(() => { loading.value = false }) diff --git a/src/views/supermarket/mallMerchant/form.vue b/src/views/supermarket/mallMerchant/form.vue index f64978e..0e3b567 100644 --- a/src/views/supermarket/mallMerchant/form.vue +++ b/src/views/supermarket/mallMerchant/form.vue @@ -33,6 +33,21 @@ + + + + + + @@ -82,6 +97,7 @@ import { useDict } from '/@/hooks/dict'; import { useMessage } from "/@/hooks/message"; import { getObj, addObj, putObj } from '/@/api/supermarket/mallMerchant' import { rule } from '/@/utils/validate'; +import { ref, reactive, nextTick, watch } from 'vue'; const emit = defineEmits(['refresh']); // 定义变量内容 @@ -99,6 +115,7 @@ const form = reactive({ contactName: '', contactPhone: '', email: '', + businessHours: '', // 营业时间 status: 1, // 默认正常状态 licenseNo: '', address: '', @@ -107,11 +124,24 @@ const form = reactive({ deptId: '', }); +// 营业时间范围选择器 +const businessHoursRange = ref<[string, string] | null>(null); + +// 监听营业时间范围变化,转换为数据库格式 +watch(businessHoursRange, (newRange) => { + if (newRange && newRange.length === 2) { + form.businessHours = `${newRange[0]}-${newRange[1]}`; + } else { + form.businessHours = ''; + } +}, { immediate: true }); + // 定义校验规则 const dataRules = ref({ name: [{required: true, message: '商户名称不能为空', trigger: 'blur'}], contactName: [{required: true, message: '联系人不能为空', trigger: 'blur'}], contactPhone: [{required: true, message: '联系电话不能为空', trigger: 'blur'}, { validator: rule.mobilePhone, trigger: 'blur' }], + businessHours: [{required: true, message: '营业时间不能为空', trigger: 'change'}], }) // 打开弹窗 @@ -126,6 +156,8 @@ const openDialog = (id: string) => { if (!id) { form.status = 1; } + // 重置营业时间 + businessHoursRange.value = null; }); // 获取mallMerchant信息 @@ -160,6 +192,14 @@ const getmallMerchantData = (id: string) => { loading.value = true getObj(id).then((res: any) => { Object.assign(form, res.data) + + // 处理营业时间回显 + if (res.data.businessHours) { + const timeRange = res.data.businessHours.split('-'); + if (timeRange.length === 2) { + businessHoursRange.value = [timeRange[0], timeRange[1]]; + } + } }).finally(() => { loading.value = false }) diff --git a/src/views/supermarket/mallMerchant/index.vue b/src/views/supermarket/mallMerchant/index.vue index e5f4858..cfe3c1d 100644 --- a/src/views/supermarket/mallMerchant/index.vue +++ b/src/views/supermarket/mallMerchant/index.vue @@ -45,6 +45,7 @@ +