generated from Leo_Ding/web-template
产品中心
This commit is contained in:
parent
f48342bba2
commit
a880d98f88
14
src/apis/modules/categorys.js
Normal file
14
src/apis/modules/categorys.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* 海邻动态接口
|
||||||
|
*/
|
||||||
|
import request from '@/utils/request'
|
||||||
|
// 获取公司动态列表
|
||||||
|
export const getDataList = (params) => request.basic.get('/api/v1/products/categorys', params)
|
||||||
|
// 获取单条数据
|
||||||
|
export const getItem = (id) => request.basic.get(`/api/v1/products/categorys/${id}`)
|
||||||
|
// 添加动态
|
||||||
|
export const createProductsItem = (params) => request.basic.post('/api/v1/products/categorys', params)
|
||||||
|
// 更新动态
|
||||||
|
export const updateItem = (id, params) => request.basic.put(`/api/v1/products/categorys/${id}`, params)
|
||||||
|
// 删除动态
|
||||||
|
export const delProductsItem = (id) => request.basic.delete(`/api/v1/products/categorys/${id}`)
|
||||||
@ -121,6 +121,7 @@ async function getPageList() {
|
|||||||
.getDataList({
|
.getDataList({
|
||||||
pageSize,
|
pageSize,
|
||||||
page: current,
|
page: current,
|
||||||
|
type:120,
|
||||||
...searchFormData.value,
|
...searchFormData.value,
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
@ -129,7 +130,7 @@ async function getPageList() {
|
|||||||
hideLoading()
|
hideLoading()
|
||||||
if (config('http.code.success') === success) {
|
if (config('http.code.success') === success) {
|
||||||
//筛选type的值80对应about
|
//筛选type的值80对应about
|
||||||
listData.value = data.filter(item => item.type === 120)
|
listData.value = data
|
||||||
paginationState.total = total
|
paginationState.total = total
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -120,6 +120,7 @@ async function getPageList() {
|
|||||||
.getDataList({
|
.getDataList({
|
||||||
pageSize,
|
pageSize,
|
||||||
page: current,
|
page: current,
|
||||||
|
type:110,
|
||||||
...searchFormData.value,
|
...searchFormData.value,
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
@ -128,7 +129,7 @@ async function getPageList() {
|
|||||||
hideLoading()
|
hideLoading()
|
||||||
if (config('http.code.success') === success) {
|
if (config('http.code.success') === success) {
|
||||||
//筛选type的值110对应researchHonor
|
//筛选type的值110对应researchHonor
|
||||||
listData.value = data.filter(item => item.type===110)
|
// listData.value = data.filter(item => item.type===110)
|
||||||
paginationState.total = total
|
paginationState.total = total
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -1,169 +0,0 @@
|
|||||||
<template>
|
|
||||||
<a-card
|
|
||||||
:body-style="{ height: 'calc(100% - 56px - 47px)', padding: 0 }"
|
|
||||||
:style="{
|
|
||||||
position: 'sticky',
|
|
||||||
top: appStore.mainOffsetTop,
|
|
||||||
height: appStore.mainHeight,
|
|
||||||
}">
|
|
||||||
<template #title>
|
|
||||||
<a-input-search placeholder="搜索部门"></a-input-search>
|
|
||||||
</template>
|
|
||||||
<x-scrollbar class="pa-8-2">
|
|
||||||
<a-spin :spinning="loading">
|
|
||||||
<a-tree
|
|
||||||
block-node
|
|
||||||
:selected-keys="selectedKeys"
|
|
||||||
:tree-data="listData"
|
|
||||||
:field-names="{ key: 'id', children: 'children' }"
|
|
||||||
@select="onSelect">
|
|
||||||
<template #title="{ title }">
|
|
||||||
<span class="ant-tree-title__name">{{ title }}</span>
|
|
||||||
<span class="ant-tree-title__actions">
|
|
||||||
<a-dropdown
|
|
||||||
:trigger="['click']"
|
|
||||||
@click.stop>
|
|
||||||
<x-action-button>
|
|
||||||
<more-outlined></more-outlined>
|
|
||||||
</x-action-button>
|
|
||||||
<template #overlay>
|
|
||||||
<a-menu>
|
|
||||||
<a-menu-item @click="$refs.editDepartmentDialogRef.handleEdit()">
|
|
||||||
添加子部门
|
|
||||||
</a-menu-item>
|
|
||||||
<a-menu-item @click="$refs.editDepartmentDialogRef.handleEdit()">
|
|
||||||
编辑
|
|
||||||
</a-menu-item>
|
|
||||||
<a-menu-item @click="handleDelete">删除</a-menu-item>
|
|
||||||
</a-menu>
|
|
||||||
</template>
|
|
||||||
</a-dropdown>
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
</a-tree>
|
|
||||||
<empty
|
|
||||||
v-if="!listData.length"
|
|
||||||
:image="Empty.PRESENTED_IMAGE_SIMPLE"></empty>
|
|
||||||
</a-spin>
|
|
||||||
</x-scrollbar>
|
|
||||||
<template #actions>
|
|
||||||
<span @click="$refs.editDepartmentDialogRef.handleCreate()">
|
|
||||||
<plus-outlined></plus-outlined>
|
|
||||||
新建部门
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
</a-card>
|
|
||||||
|
|
||||||
<edit-department-dialog
|
|
||||||
ref="editDepartmentDialogRef"
|
|
||||||
@ok="onOk"></edit-department-dialog>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { useAppStore } from '@/store'
|
|
||||||
import { ref, watch } from 'vue'
|
|
||||||
import { usePagination } from '@/hooks'
|
|
||||||
import apis from '@/apis'
|
|
||||||
import { Empty, Modal, message } from 'ant-design-vue'
|
|
||||||
import { config } from '@/config'
|
|
||||||
import { head, get, find } from 'lodash-es'
|
|
||||||
import { MoreOutlined, PlusOutlined } from '@ant-design/icons-vue'
|
|
||||||
import EditDepartmentDialog from './EditDepartmentDialog.vue'
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
value: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const emit = defineEmits(['change', 'update:value'])
|
|
||||||
|
|
||||||
const appStore = useAppStore()
|
|
||||||
const { listData, loading, showLoading, hideLoading } = usePagination()
|
|
||||||
|
|
||||||
const editDepartmentDialogRef = ref()
|
|
||||||
const selectedKeys = ref([props.value])
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.value,
|
|
||||||
(val) => {
|
|
||||||
if (val === selectedKeys.value?.[0]) return
|
|
||||||
selectedKeys.value = [val]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
getList()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取列表
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async function getList() {
|
|
||||||
try {
|
|
||||||
showLoading()
|
|
||||||
const { code, data } = await apis.common.getPageList().catch(() => {
|
|
||||||
throw new Error()
|
|
||||||
})
|
|
||||||
hideLoading()
|
|
||||||
if (config('http.code.success') === code) {
|
|
||||||
const { records } = data
|
|
||||||
listData.value = records
|
|
||||||
if (listData.value.length) {
|
|
||||||
selectedKeys.value = [get(head(listData.value), 'id')]
|
|
||||||
trigger()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
hideLoading()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除
|
|
||||||
*/
|
|
||||||
function handleDelete({ id }) {
|
|
||||||
Modal.confirm({
|
|
||||||
title: '删除提示',
|
|
||||||
content: '确认删除?',
|
|
||||||
okText: '确认',
|
|
||||||
onOk: () => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
;(async () => {
|
|
||||||
try {
|
|
||||||
const { code } = await apis.common.del(id).catch(() => {
|
|
||||||
throw new Error()
|
|
||||||
})
|
|
||||||
if (config('http.code.success') === code) {
|
|
||||||
resolve()
|
|
||||||
message.success('删除成功')
|
|
||||||
await getList()
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
reject()
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSelect(keys) {
|
|
||||||
if (!keys.length) return
|
|
||||||
selectedKeys.value = keys
|
|
||||||
trigger()
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onOk() {
|
|
||||||
await getList()
|
|
||||||
}
|
|
||||||
|
|
||||||
function trigger() {
|
|
||||||
const value = head(selectedKeys.value)
|
|
||||||
const record = find(listData.value, { id: value })
|
|
||||||
emit('update:value', value)
|
|
||||||
emit('change', record)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="less" scoped></style>
|
|
||||||
@ -1,131 +0,0 @@
|
|||||||
<template>
|
|
||||||
<a-modal
|
|
||||||
:open="modal.open"
|
|
||||||
:title="modal.title"
|
|
||||||
:width="480"
|
|
||||||
:confirm-loading="modal.confirmLoading"
|
|
||||||
:after-close="onAfterClose"
|
|
||||||
:cancel-text="cancelText"
|
|
||||||
@ok="handleOk"
|
|
||||||
@cancel="handleCancel">
|
|
||||||
<a-form
|
|
||||||
ref="formRef"
|
|
||||||
:model="formData"
|
|
||||||
:rules="formRules"
|
|
||||||
:label-col="{ style: { width: '90px' } }">
|
|
||||||
<a-form-item
|
|
||||||
label="部门名称"
|
|
||||||
name="name">
|
|
||||||
<a-input v-model:value="formData.name"></a-input>
|
|
||||||
</a-form-item>
|
|
||||||
<a-form-item
|
|
||||||
label="上级部门"
|
|
||||||
name="parent_id">
|
|
||||||
<a-tree-select v-model:value="formData.parent_id"></a-tree-select>
|
|
||||||
</a-form-item>
|
|
||||||
<a-form-item
|
|
||||||
label="部门负责人"
|
|
||||||
name="name">
|
|
||||||
<a-input v-model:value="formData.name"></a-input>
|
|
||||||
</a-form-item>
|
|
||||||
</a-form>
|
|
||||||
</a-modal>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { cloneDeep } from 'lodash-es'
|
|
||||||
import { ref } from 'vue'
|
|
||||||
import { config } from '@/config'
|
|
||||||
import apis from '@/apis'
|
|
||||||
import { useForm, useModal } from '@/hooks'
|
|
||||||
|
|
||||||
const emit = defineEmits(['ok'])
|
|
||||||
|
|
||||||
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
|
|
||||||
const { formRecord, formData, formRef, formRules, resetForm } = useForm()
|
|
||||||
const cancelText = ref('取消')
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新建
|
|
||||||
*/
|
|
||||||
function handleCreate() {
|
|
||||||
showModal({
|
|
||||||
type: 'create',
|
|
||||||
title: '新建部门',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编辑
|
|
||||||
*/
|
|
||||||
function handleEdit(record = {}) {
|
|
||||||
showModal({
|
|
||||||
type: 'edit',
|
|
||||||
title: '编辑部门',
|
|
||||||
})
|
|
||||||
formRecord.value = record
|
|
||||||
formData.value = cloneDeep(record)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 确定
|
|
||||||
*/
|
|
||||||
function handleOk() {
|
|
||||||
formRef.value
|
|
||||||
.validateFields()
|
|
||||||
.then(async (values) => {
|
|
||||||
try {
|
|
||||||
showLoading()
|
|
||||||
const params = {
|
|
||||||
...values,
|
|
||||||
}
|
|
||||||
let result = null
|
|
||||||
switch (modal.value.type) {
|
|
||||||
case 'create':
|
|
||||||
result = await apis.common.create(params).catch(() => {
|
|
||||||
throw new Error()
|
|
||||||
})
|
|
||||||
break
|
|
||||||
case 'edit':
|
|
||||||
result = await apis.common.update(params).catch(() => {
|
|
||||||
throw new Error()
|
|
||||||
})
|
|
||||||
break
|
|
||||||
}
|
|
||||||
hideLoading()
|
|
||||||
if (config('http.code.success') === result?.code) {
|
|
||||||
hideModal()
|
|
||||||
emit('ok')
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
hideLoading()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
hideLoading()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消
|
|
||||||
*/
|
|
||||||
function handleCancel() {
|
|
||||||
hideModal()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关闭后
|
|
||||||
*/
|
|
||||||
function onAfterClose() {
|
|
||||||
resetForm()
|
|
||||||
cancelText.value = '取消'
|
|
||||||
hideLoading()
|
|
||||||
}
|
|
||||||
|
|
||||||
defineExpose({
|
|
||||||
handleCreate,
|
|
||||||
handleEdit,
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="less" scoped></style>
|
|
||||||
@ -13,13 +13,10 @@
|
|||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col :span="24">
|
<a-col :span="24">
|
||||||
<a-form-item :label="'产品类别'" name="categoryID">
|
<a-form-item :label="'产品类别'" name="categoryIDs">
|
||||||
<div style="display: flex;justify-content: space-between;">
|
<a-tree-select v-model:value="formData.categoryIDs" :tree-data="categoryList"
|
||||||
<a-select v-model:value="formData.categoryID" allowClear>
|
@change="handleTreeSelectChange" placeholder="请选择(只能选最后一级)"
|
||||||
<a-select-option v-for="item in areaList" :value="item.value">{{
|
style="width: 100%" tree-default-expand-all/>
|
||||||
item.categoryIDName }}</a-select-option>
|
|
||||||
</a-select>
|
|
||||||
</div>
|
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col :span="24">
|
<a-col :span="24">
|
||||||
@ -140,15 +137,14 @@ const imgUrl = ref('')
|
|||||||
const categoryList = ref([])
|
const categoryList = ref([])
|
||||||
const targetList = ref([])
|
const targetList = ref([])
|
||||||
const images = ref([])
|
const images = ref([])
|
||||||
const mainImage = ref([])
|
|
||||||
const contentImage = ref([])
|
const contentImage = ref([])
|
||||||
const childOpen = ref(false)
|
const childOpen = ref(false)
|
||||||
const formArea = ref({ name: '', status: 'enabled' })
|
|
||||||
const activeKey = ref('1')
|
const activeKey = ref('1')
|
||||||
formRules.value = {
|
formRules.value = {
|
||||||
title: { required: true, message: '请输入产品类别名称' },
|
title: { required: true, message: '请输入产品类别名称' },
|
||||||
code: { required: true, message: '请输入产品名称' },
|
code: { required: true, message: '请输入产品名称' },
|
||||||
categoryID: { required: true, message: '请选择产品类别', trigger: 'change' },
|
categoryIDs: { required: true, message: '请选择产品类别', trigger: 'change' },
|
||||||
compose: { required: true, message: '请选择产品适用对象', trigger: 'change' },
|
compose: { required: true, message: '请选择产品适用对象', trigger: 'change' },
|
||||||
feature: [{ required: true, message: '请输入产品功能特点', trigger: 'change' }],
|
feature: [{ required: true, message: '请输入产品功能特点', trigger: 'change' }],
|
||||||
// feature: [{ required: true, message: '请输入产品功能特点' }],
|
// feature: [{ required: true, message: '请输入产品功能特点' }],
|
||||||
@ -160,19 +156,13 @@ formRules.value = {
|
|||||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||||
|
|
||||||
}
|
}
|
||||||
const areaFormRules = {
|
|
||||||
categoryIDName: [{ required: true, message: '请输入产品类别' }],
|
|
||||||
targetName: [{ required: true, message: '请输入产品适用对象' }],
|
|
||||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
|
||||||
}
|
|
||||||
const initData = async () => {
|
const initData = async () => {
|
||||||
try {
|
try {
|
||||||
showSpining();
|
showSpining();
|
||||||
const { success: prodSuccess, data: prodData } = await apis.products.getProductObj({ pageSize: 999, page: 1 });
|
const { success: prodSuccess, data: prodData } = await apis.categorys.getDataList({ pageSize: 999, page: 1 });
|
||||||
if (config('http.code.success') === prodSuccess) {
|
if (config('http.code.success') === prodSuccess) {
|
||||||
targetList.value = prodData
|
categoryList.value = prodData
|
||||||
.filter(item => item.status === 'enabled')
|
|
||||||
.map(item => ({ code: item.id, name: item.name }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -193,7 +183,7 @@ function handleCreate() {
|
|||||||
// 初始化所有字段
|
// 初始化所有字段
|
||||||
formData.value = {
|
formData.value = {
|
||||||
title: '',
|
title: '',
|
||||||
categoryID: '',
|
categoryIDs:'',
|
||||||
compose: '',
|
compose: '',
|
||||||
target: '',
|
target: '',
|
||||||
feature: [{
|
feature: [{
|
||||||
@ -206,39 +196,13 @@ function handleCreate() {
|
|||||||
fu_hoao: '',
|
fu_hoao: '',
|
||||||
prx: '',
|
prx: '',
|
||||||
}],
|
}],
|
||||||
images: [
|
images: [''],
|
||||||
...(Array.isArray(formData.value.mainImage)
|
|
||||||
? formData.value.mainImage
|
|
||||||
: [formData.value.mainImage]
|
|
||||||
).filter(Boolean).map(item => String(item)),
|
|
||||||
|
|
||||||
...(Array.isArray(formData.value.contentImage)
|
|
||||||
? formData.value.contentImage
|
|
||||||
: [formData.value.contentImage]
|
|
||||||
).filter(Boolean).map(item => String(item))
|
|
||||||
],
|
|
||||||
|
|
||||||
sequence: null,
|
sequence: null,
|
||||||
status: 'enabled',
|
status: 'enabled',
|
||||||
}
|
}
|
||||||
initData()
|
initData()
|
||||||
}
|
}
|
||||||
|
|
||||||
//新建产品类别
|
|
||||||
const childHandleOk = async () => {
|
|
||||||
areaFormRef.value.validateFields().then(async (values) => {
|
|
||||||
try {
|
|
||||||
const params = { ...categoryForm.value }
|
|
||||||
const { success } = await apis.products.createProductCategory(params)
|
|
||||||
if (success) message.success('新增成功')
|
|
||||||
childOpen.value = false
|
|
||||||
categoryForm.value = { categoryIDName: '', status: 'enabled' }
|
|
||||||
initData()
|
|
||||||
} catch (error) {
|
|
||||||
message.error(error.message)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
//新建产品适用对象
|
//新建产品适用对象
|
||||||
const childHandleObjOk = async () => {
|
const childHandleObjOk = async () => {
|
||||||
areaFormRef.value.validateFields().then(async (values) => {
|
areaFormRef.value.validateFields().then(async (values) => {
|
||||||
@ -262,6 +226,7 @@ const handleCombinedOk = () => {
|
|||||||
* 编辑
|
* 编辑
|
||||||
*/
|
*/
|
||||||
async function handleEdit(record = {}) {
|
async function handleEdit(record = {}) {
|
||||||
|
initData()
|
||||||
showModal({
|
showModal({
|
||||||
type: 'edit',
|
type: 'edit',
|
||||||
title: t('pages.system.user.edit'),
|
title: t('pages.system.user.edit'),
|
||||||
@ -273,6 +238,7 @@ async function handleEdit(record = {}) {
|
|||||||
}
|
}
|
||||||
formData.value = {
|
formData.value = {
|
||||||
...data,
|
...data,
|
||||||
|
categoryIDs:data.categoryID,
|
||||||
standard: data.standard || [{
|
standard: data.standard || [{
|
||||||
label: '',
|
label: '',
|
||||||
val: '',
|
val: '',
|
||||||
@ -284,13 +250,8 @@ async function handleEdit(record = {}) {
|
|||||||
data: []
|
data: []
|
||||||
}],
|
}],
|
||||||
// images:data.images || [''],
|
// images:data.images || [''],
|
||||||
mainImage: data.images ? [config('http.apiBasic') + data.images[0]] : [''],
|
mainImage: data.images ? data.images.map(item=>config('http.apiBasic')+item):[''],
|
||||||
contentImage: data.images ? [config('http.apiBasic') + data.images[1]] : [''],
|
|
||||||
}
|
}
|
||||||
// imgUrl.value = config('http.apiBasic') + data.img
|
|
||||||
mainImage.value = config('http.apiBasic') + data.images?.[0],
|
|
||||||
contentImage.value = config('http.apiBasic') + data.images?.[1],
|
|
||||||
console.log('编辑产品数据:', formData.value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -303,6 +264,8 @@ function handleOk() {
|
|||||||
showLoading()
|
showLoading()
|
||||||
const params = {
|
const params = {
|
||||||
...values,
|
...values,
|
||||||
|
categoryID:formData.value.categoryID,
|
||||||
|
categoryRootID:formData.value.categoryRootID,
|
||||||
standard: formData.value.standard ||
|
standard: formData.value.standard ||
|
||||||
[{
|
[{
|
||||||
label: '',
|
label: '',
|
||||||
@ -311,17 +274,7 @@ function handleOk() {
|
|||||||
prx: '',
|
prx: '',
|
||||||
}],
|
}],
|
||||||
feature: formData.value.feature,
|
feature: formData.value.feature,
|
||||||
images: [
|
images: formData.value.mainImage?formData.value.mainImage.map(item=>spliceUrl(item)):[''],
|
||||||
...(Array.isArray(formData.value.mainImage)
|
|
||||||
? formData.value.mainImage
|
|
||||||
: [formData.value.mainImage]
|
|
||||||
).filter(Boolean).map(item => spliceUrl(item)),
|
|
||||||
|
|
||||||
...(Array.isArray(formData.value.contentImage)
|
|
||||||
? formData.value.contentImage
|
|
||||||
: [formData.value.contentImage]
|
|
||||||
).filter(Boolean).map(item => spliceUrl(item))
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
let result = null
|
let result = null
|
||||||
switch (modal.value.type) {
|
switch (modal.value.type) {
|
||||||
@ -396,6 +349,52 @@ function removeFeature(index) {
|
|||||||
formData.value.feature.splice(index, 1)
|
formData.value.feature.splice(index, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 递归查找节点路径
|
||||||
|
const findNodePath = (tree, value, path = []) => {
|
||||||
|
for (const node of tree) {
|
||||||
|
const currentPath = [...path, node.value];
|
||||||
|
if (node.value === value) return currentPath;
|
||||||
|
if (node.children) {
|
||||||
|
const found = findNodePath(node.children, value, currentPath);
|
||||||
|
if (found) return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
// 获取节点是否是叶子节点
|
||||||
|
const isLeafNode = (id) => {
|
||||||
|
const node = findNodeById(categoryList.value, id);
|
||||||
|
if(node.children.length>0) return false;
|
||||||
|
else return true
|
||||||
|
};
|
||||||
|
// 根据ID查找节点
|
||||||
|
const findNodeById = (tree, value) => {
|
||||||
|
for (const node of tree) {
|
||||||
|
if (node.value === value) return node;
|
||||||
|
if(node.children){
|
||||||
|
const found=findNodeById(node.children,value)
|
||||||
|
if(found) return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
// 处理选择事件
|
||||||
|
const handleTreeSelectChange = (value) => {
|
||||||
|
// 验证是否叶子节点
|
||||||
|
if (!isLeafNode(value)) {
|
||||||
|
message.warning('只能选择最后一级节点');
|
||||||
|
formData.value.categoryID = null; // 清除非叶子选择
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!value) return;
|
||||||
|
const pathIds = findNodePath(categoryList.value, value);
|
||||||
|
if (pathIds) {
|
||||||
|
console.log('选中的路径ID数组:', pathIds);
|
||||||
|
// 实际使用中,此处可提交 pathIds 到后端或进行其他操作
|
||||||
|
formData.value.categoryID=pathIds[1]
|
||||||
|
formData.value.categoryRootID=pathIds[0]
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped></style>
|
<style lang="less" scoped></style>
|
||||||
|
|||||||
@ -49,7 +49,6 @@
|
|||||||
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
|
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
|
||||||
:pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange">
|
:pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange">
|
||||||
<template #bodyCell="{ column, record }">
|
<template #bodyCell="{ column, record }">
|
||||||
|
|
||||||
<template v-if="column.dataIndex === 'title'">
|
<template v-if="column.dataIndex === 'title'">
|
||||||
<a-tooltip :title="record.title">
|
<a-tooltip :title="record.title">
|
||||||
<div class="text-ellipsis">{{ record.title }}</div>
|
<div class="text-ellipsis">{{ record.title }}</div>
|
||||||
@ -123,40 +122,31 @@ defineOptions({
|
|||||||
})
|
})
|
||||||
const { t } = useI18n() // 解构出t方法
|
const { t } = useI18n() // 解构出t方法
|
||||||
const columns = [
|
const columns = [
|
||||||
{ title: '产品名称', dataIndex: 'code', width: 120 },
|
{ title: '产品名称', dataIndex: 'code', width: 120, ellipsis:true},
|
||||||
{ title: '产品类别名称', dataIndex: 'title', width: 120 },
|
{ title: '产品类别', dataIndex: 'categoryID', key: 'categoryID', width: 120 },
|
||||||
{ title: '产品类别ID', dataIndex: 'categoryID', key: 'categoryID', width: 120 },
|
|
||||||
{ title: '适用对象', dataIndex: 'target', width: 120 },
|
{ title: '适用对象', dataIndex: 'target', width: 120 },
|
||||||
{ title: '产品适用类别ID', dataIndex: 'CategoryRootID', key: 'CategoryRootID', width: 120 },
|
|
||||||
{ title: '原料组成', dataIndex: 'compose', key: 'compose', width: 120 },
|
{ title: '原料组成', dataIndex: 'compose', key: 'compose', width: 120 },
|
||||||
{
|
// {
|
||||||
title: '功能特点',
|
// title: '产品标准',
|
||||||
dataIndex: 'feature',
|
// dataIndex: 'standard',
|
||||||
width: 120,
|
// width: 120,
|
||||||
align: 'center',
|
// align: 'center',
|
||||||
customRender: ({ text }) => Array.isArray(text) ? text.join(', ') : ''
|
// customRender: ({ text }) => Array.isArray(text)
|
||||||
},
|
// ? text.map(item => `${item.label}: ${item.fu_hoao}${item.val}${item.prx}`).join(', ')
|
||||||
{
|
// : ''
|
||||||
title: '产品标准',
|
// },
|
||||||
dataIndex: 'standard',
|
// {
|
||||||
width: 120,
|
// title: '产品图片',
|
||||||
align: 'center',
|
// dataIndex: 'mainImage',
|
||||||
customRender: ({ text }) => Array.isArray(text)
|
// width: 120,
|
||||||
? text.map(item => `${item.label}: ${item.fu_hoao}${item.val}${item.prx}`).join(', ')
|
// align: 'center',
|
||||||
: ''
|
// },
|
||||||
},
|
// {
|
||||||
{
|
// title: '产品内容图片',
|
||||||
title: '产品图片',
|
// dataIndex: 'contentImage',
|
||||||
dataIndex: 'mainImage',
|
// width: 120,
|
||||||
width: 120,
|
// align: 'center',
|
||||||
align: 'center',
|
// },
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '产品内容图片',
|
|
||||||
dataIndex: 'contentImage',
|
|
||||||
width: 120,
|
|
||||||
align: 'center',
|
|
||||||
},
|
|
||||||
|
|
||||||
{ title: '产品排序', dataIndex: 'sequence', width: 120, align: 'center' },
|
{ title: '产品排序', dataIndex: 'sequence', width: 120, align: 'center' },
|
||||||
{ title: '产品状态', dataIndex: 'status', width: 120, align: 'center' },
|
{ title: '产品状态', dataIndex: 'status', width: 120, align: 'center' },
|
||||||
@ -188,12 +178,7 @@ async function getPageList() {
|
|||||||
if (config('http.code.success') === success) {
|
if (config('http.code.success') === success) {
|
||||||
listData.value = data.map(item => ({
|
listData.value = data.map(item => ({
|
||||||
...item,
|
...item,
|
||||||
mainImage: item.images?.[0] || '',
|
|
||||||
contentImage: item.images?.[1] || '',
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
console.log('接口数据', data)
|
|
||||||
console.log('接口过滤数据', listData.value)
|
|
||||||
paginationState.total = total
|
paginationState.total = total
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -258,7 +243,6 @@ function handleResetSearch() {
|
|||||||
* 编辑完成
|
* 编辑完成
|
||||||
*/
|
*/
|
||||||
async function onOk() {
|
async function onOk() {
|
||||||
message.success(t('component.message.success.delete'))
|
|
||||||
await getPageList()
|
await getPageList()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -4,103 +4,23 @@
|
|||||||
<a-spin :spinning="spining">
|
<a-spin :spinning="spining">
|
||||||
<a-form ref="formRef" :model="formData" :rules="formRules">
|
<a-form ref="formRef" :model="formData" :rules="formRules">
|
||||||
<a-card class="mb-8-2">
|
<a-card class="mb-8-2">
|
||||||
<a-tabs v-model:activeKey="activeKey">
|
|
||||||
<a-tab-pane key="1" tab="基本信息">
|
|
||||||
<a-row :gutter="12">
|
<a-row :gutter="12">
|
||||||
<a-col :span="24">
|
<a-col :span="24">
|
||||||
<a-form-item :label="'产品名称'" name="code">
|
<a-form-item :label="'父级分类'" name="parentID">
|
||||||
<a-input :placeholder="'请输入产品名称'" v-model:value="formData.code"></a-input>
|
<a-tree-select v-model:value="formData.parentID" show-search style="width: 100%"
|
||||||
|
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }" placeholder="请选择"
|
||||||
|
allow-clear tree-default-expand-all :tree-data="treeData"
|
||||||
|
tree-node-filter-prop="label">
|
||||||
|
</a-tree-select>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col :span="24">
|
<a-col :span="24">
|
||||||
<a-form-item :label="'产品类别'" name="categoryID">
|
<a-form-item :label="'产品分类'" name="label">
|
||||||
<div style="display: flex;justify-content: space-between;">
|
<a-input :placeholder="'请输入产品分类名称'" v-model:value="formData.label"></a-input>
|
||||||
<a-select v-model:value="formData.categoryID" allowClear>
|
|
||||||
<a-select-option v-for="item in areaList" :value="item.value">{{
|
|
||||||
item.categoryIDName }}</a-select-option>
|
|
||||||
</a-select>
|
|
||||||
</div>
|
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col :span="24">
|
|
||||||
<a-form-item :label="'原料组成'" name="compose">
|
|
||||||
<a-textarea :placeholder="'请输入原料组成'"
|
|
||||||
v-model:value="formData.compose"></a-textarea>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
<a-col :span="24">
|
|
||||||
<a-form-item :label="'适用对象'" name="target">
|
|
||||||
<a-input :placeholder="'请输入适用对象'" v-model:value="formData.target"></a-input>
|
|
||||||
</a-form-item>
|
|
||||||
|
|
||||||
</a-col>
|
|
||||||
|
|
||||||
<a-col :span="12">
|
|
||||||
<a-form-item :label="'产品排序'" name="sequence">
|
|
||||||
<a-input-number v-model:value="formData.sequence" :placeholder="'请输入排序'"
|
|
||||||
style="width: 100%;" />
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
<a-col :span="12">
|
|
||||||
<a-form-item :label="'状态'" name="status">
|
|
||||||
<a-radio-group v-model:value="formData.status" :options="[
|
|
||||||
{ label: '启用', value: 'enabled' },
|
|
||||||
{ label: '停用', value: 'disabled' },]"></a-radio-group>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
<a-form-item :label="'产品图片'">
|
|
||||||
<gx-upload v-model="formData.mainImage" :fileNumber="2" />
|
|
||||||
</a-form-item>
|
|
||||||
|
|
||||||
</a-row>
|
</a-row>
|
||||||
</a-tab-pane>
|
|
||||||
<a-tab-pane key="2" tab="产品功能">
|
|
||||||
<a-col :span="24">
|
|
||||||
<a-form-item v-for="(item, index) in formData.feature" :key="index"
|
|
||||||
:label="`产品功能特点 ${index + 1}`">
|
|
||||||
<a-input v-model:value="item.label" placeholder="请输入功能特点标题" class="inputPhone" />
|
|
||||||
<a-select v-model:value="item.data" mode="tags" :placeholder="'请输入功能特点,按回车区分不同特点'"
|
|
||||||
:token-separators="[',']" style="width: 100%;" />
|
|
||||||
<a-button danger @click="removeFeature(index)" size="small" style="margin-top: 8px">
|
|
||||||
删除
|
|
||||||
</a-button>
|
|
||||||
</a-form-item>
|
|
||||||
|
|
||||||
<a-form-item>
|
|
||||||
<a-button type="dashed" block @click="addFeature">
|
|
||||||
新增产品功能特点
|
|
||||||
</a-button>
|
|
||||||
</a-form-item>
|
|
||||||
|
|
||||||
</a-col>
|
|
||||||
</a-tab-pane>
|
|
||||||
<a-tab-pane key="3" tab="产品标准">
|
|
||||||
<a-col :span="24">
|
|
||||||
<a-form-item v-for="(item, index) in formData.standard" :key="index"
|
|
||||||
:label="`产品标准 ${index + 1}`">
|
|
||||||
<a-input v-model:value="item.label" placeholder="请输入标准名称" class="inputPhone" />
|
|
||||||
<a-input v-model:value="item.fu_hoao" placeholder="请输入符号" class="inputPhone"
|
|
||||||
style="margin-top: 8px" />
|
|
||||||
<a-input v-model:value="item.val" placeholder="请输入标准值" class="inputPhone"
|
|
||||||
style="margin-top: 8px" />
|
|
||||||
<a-input v-model:value="item.prx" placeholder="请输入标准值单位" class="inputPhone"
|
|
||||||
style="margin-top: 8px" />
|
|
||||||
<a-button danger @click="removeStandard(index)" size="small"
|
|
||||||
style="margin-top: 8px">
|
|
||||||
删除
|
|
||||||
</a-button>
|
|
||||||
</a-form-item>
|
|
||||||
|
|
||||||
<a-form-item>
|
|
||||||
<a-button type="dashed" block @click="addStandard">
|
|
||||||
新增产品标准
|
|
||||||
</a-button>
|
|
||||||
</a-form-item>
|
|
||||||
|
|
||||||
</a-col>
|
|
||||||
</a-tab-pane>
|
|
||||||
</a-tabs>
|
|
||||||
|
|
||||||
</a-card>
|
</a-card>
|
||||||
</a-form>
|
</a-form>
|
||||||
</a-spin>
|
</a-spin>
|
||||||
@ -117,14 +37,6 @@ import { useForm, useModal, useSpining } from '@/hooks'
|
|||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
import dayjs from 'dayjs'
|
|
||||||
import {
|
|
||||||
createProductCategory,
|
|
||||||
createProductObj, createProductsItem,
|
|
||||||
getProductCategory,
|
|
||||||
getProductObj,
|
|
||||||
getProductsItem, updateProductsItem,
|
|
||||||
} from '@/apis/modules/products'
|
|
||||||
import { spliceUrl } from '@/utils/util'
|
import { spliceUrl } from '@/utils/util'
|
||||||
const areaFormRef = ref()
|
const areaFormRef = ref()
|
||||||
const emit = defineEmits(['ok'])
|
const emit = defineEmits(['ok'])
|
||||||
@ -134,224 +46,55 @@ const { formRecord, formData, formRef, formRules, resetForm } = useForm()
|
|||||||
const { spining, showSpining, hideSpining } = useSpining()
|
const { spining, showSpining, hideSpining } = useSpining()
|
||||||
const cancelText = ref(t('button.cancel'))
|
const cancelText = ref(t('button.cancel'))
|
||||||
const okText = ref(t('button.confirm'))
|
const okText = ref(t('button.confirm'))
|
||||||
const rolesValue = ref([])
|
const treeData=ref([])
|
||||||
const roles = ref([])
|
|
||||||
const imgUrl = ref('')
|
|
||||||
const areaList = ref([])
|
|
||||||
const images = ref([])
|
|
||||||
const mainImage = ref([])
|
|
||||||
const contentImage = ref([])
|
|
||||||
const childOpen = ref(false)
|
|
||||||
const formArea = ref({ name: '', status: 'enabled' })
|
|
||||||
const activeKey=ref('1')
|
|
||||||
formRules.value = {
|
formRules.value = {
|
||||||
title: { required: true, message: '请输入产品类别名称' },
|
label: { required: true, message: '请输入产品类别名称' },
|
||||||
code: { required: true, message: '请输入产品名称' },
|
|
||||||
categoryID: { required: true, message: '请选择产品类别', trigger: 'change' },
|
|
||||||
compose: { required: true, message: '请选择产品适用对象', trigger: 'change' },
|
|
||||||
feature: [{ required: true, message: '请输入产品功能特点', trigger: 'change' }],
|
|
||||||
// feature: [{ required: true, message: '请输入产品功能特点' }],
|
|
||||||
standard: [{ required: true, message: '请输入产品标准' }],
|
|
||||||
images: [{ required: true, message: '请上传产品图片' }],
|
|
||||||
mainImage: { required: true, message: '请上传产品图片' },
|
|
||||||
contentImage: { required: false, message: '请上传产品内容图片' },
|
|
||||||
sequence: [{ required: true, message: '请输入产品排序' }],
|
|
||||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
|
||||||
|
|
||||||
}
|
}
|
||||||
const areaFormRules = {
|
|
||||||
categoryIDName: [{ required: true, message: '请输入产品类别' }],
|
|
||||||
// targetName: [{ required: true, message: '请输入产品适用对象' }],
|
|
||||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
|
||||||
}
|
|
||||||
const initDataBatch = async (configs) => {
|
|
||||||
try {
|
|
||||||
showSpining()
|
|
||||||
const responses = await Promise.all(
|
|
||||||
configs.map(({ apiFunc }) => apiFunc({ pageSize: 999, page: 1 }))
|
|
||||||
)
|
|
||||||
configs.forEach(({ nameKey, resultKey }, index) => {
|
|
||||||
const { success, data } = responses[index]
|
|
||||||
|
|
||||||
|
|
||||||
|
const initData = async () => {
|
||||||
|
const { success, data, total } = await apis.categorys
|
||||||
|
.getDataList({
|
||||||
|
pageSize:99,
|
||||||
|
page: 1,
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
throw new Error()
|
||||||
|
})
|
||||||
if (config('http.code.success') === success) {
|
if (config('http.code.success') === success) {
|
||||||
const mapped = data.map(item => {
|
treeData.value = data.map(item => ({
|
||||||
return {
|
...item
|
||||||
value: item.value,
|
}))
|
||||||
children: item.children,
|
|
||||||
[resultKey]: item.label,// e.g. item['label']
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
areaList.value = [...areaList.value, ...mapped]
|
|
||||||
console.log(areaList.value)
|
|
||||||
console.log('after merge:', areaList.value)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
message.error({ content: error.message })
|
|
||||||
} finally {
|
|
||||||
hideSpining()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initDataBatch([
|
|
||||||
{
|
|
||||||
apiFunc: apis.products.getProductCategory,
|
|
||||||
nameKey: 'name',
|
|
||||||
resultKey: 'categoryIDName'
|
|
||||||
},
|
|
||||||
// {
|
|
||||||
// apiFunc: apis.products.getProductObj,
|
|
||||||
// nameKey: 'name',
|
|
||||||
// resultKey: 'targetName'
|
|
||||||
// }
|
|
||||||
])
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建
|
* 新建
|
||||||
*/
|
*/
|
||||||
function handleCreate() {
|
function handleCreate() {
|
||||||
showModal({
|
showModal({
|
||||||
type: 'create',
|
type: 'create',
|
||||||
title: '产品中心',
|
title: '产品分类',
|
||||||
})
|
})
|
||||||
// 初始化所有字段
|
// 初始化所有字段
|
||||||
formData.value = {
|
|
||||||
title: '',
|
|
||||||
categoryID: '',
|
|
||||||
compose: '',
|
|
||||||
target: '',
|
|
||||||
feature: [{
|
|
||||||
label: '功能特点',
|
|
||||||
data: []
|
|
||||||
}],
|
|
||||||
standard: [{
|
|
||||||
label: '',
|
|
||||||
val: '',
|
|
||||||
fu_hoao: '',
|
|
||||||
prx: '',
|
|
||||||
}],
|
|
||||||
images: [
|
|
||||||
...(Array.isArray(formData.value.mainImage)
|
|
||||||
? formData.value.mainImage
|
|
||||||
: [formData.value.mainImage]
|
|
||||||
).filter(Boolean).map(item => String(item)),
|
|
||||||
|
|
||||||
...(Array.isArray(formData.value.contentImage)
|
|
||||||
? formData.value.contentImage
|
|
||||||
: [formData.value.contentImage]
|
|
||||||
).filter(Boolean).map(item => String(item))
|
|
||||||
],
|
|
||||||
|
|
||||||
sequence: null,
|
|
||||||
status: 'enabled',
|
|
||||||
}
|
|
||||||
initData()
|
initData()
|
||||||
}
|
}
|
||||||
|
|
||||||
//新建产品类别
|
|
||||||
const childHandleOk = async () => {
|
|
||||||
areaFormRef.value.validateFields().then(async (values) => {
|
|
||||||
try {
|
|
||||||
const params = { ...formArea.value }
|
|
||||||
const { success } = await apis.products.createProductCategory(params)
|
|
||||||
if (success) message.success('新增成功')
|
|
||||||
childOpen.value = false
|
|
||||||
formArea.value = { categoryIDName: '', status: 'enabled' }
|
|
||||||
initData()
|
|
||||||
} catch (error) {
|
|
||||||
message.error(error.message)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
//新建产品适用对象
|
|
||||||
const childHandleObjOk = async () => {
|
|
||||||
areaFormRef.value.validateFields().then(async (values) => {
|
|
||||||
try {
|
|
||||||
const params = { ...formArea.value }
|
|
||||||
const { success } = await apis.products.createProductObj(params)
|
|
||||||
if (success) message.success('新增成功')
|
|
||||||
childOpen.value = false
|
|
||||||
formArea.value = { targetName: '', status: 'enabled' }
|
|
||||||
initData()
|
|
||||||
} catch (error) {
|
|
||||||
message.error(error.message)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const handleCombinedOk = () => {
|
|
||||||
childHandleOk();
|
|
||||||
childHandleObjOk();
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 编辑
|
|
||||||
*/
|
|
||||||
async function handleEdit(record = {}) {
|
|
||||||
showModal({
|
|
||||||
type: 'edit',
|
|
||||||
title: t('pages.system.user.edit'),
|
|
||||||
})
|
|
||||||
const { data, success } = await apis.products.getProductsItem(record.id).catch()
|
|
||||||
if (!success) {
|
|
||||||
hideModal()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
formData.value = {
|
|
||||||
...data,
|
|
||||||
standard: data.standard || [{
|
|
||||||
label: '',
|
|
||||||
val: '',
|
|
||||||
fu_hoao: '',
|
|
||||||
prx: '',
|
|
||||||
}],
|
|
||||||
feature: data.feature || [{
|
|
||||||
label: '功能特点',
|
|
||||||
data: []
|
|
||||||
}],
|
|
||||||
// images:data.images || [''],
|
|
||||||
mainImage: data.images ? [config('http.apiBasic') + data.images[0]] : [''],
|
|
||||||
contentImage: data.images ? [config('http.apiBasic') + data.images[1]] : [''],
|
|
||||||
}
|
|
||||||
// imgUrl.value = config('http.apiBasic') + data.img
|
|
||||||
mainImage.value = config('http.apiBasic') + data.images?.[0],
|
|
||||||
contentImage.value = config('http.apiBasic') + data.images?.[1],
|
|
||||||
console.log('编辑产品数据:', formData.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 确定
|
* 确定
|
||||||
*/
|
*/
|
||||||
function handleOk() {
|
function handleOk() {
|
||||||
console.log('编辑产品列表', formData.value)
|
|
||||||
formRef.value.validateFields().then(async (values) => {
|
formRef.value.validateFields().then(async (values) => {
|
||||||
try {
|
try {
|
||||||
showLoading()
|
showLoading()
|
||||||
const params = {
|
const params = {
|
||||||
...values,
|
...values,
|
||||||
standard: formData.value.standard ||
|
parentID:formData.value.parentID?formData.value.parentID:0
|
||||||
[{
|
|
||||||
label: '',
|
|
||||||
val: '',
|
|
||||||
fu_hoao: '',
|
|
||||||
prx: '',
|
|
||||||
}],
|
|
||||||
feature: formData.value.feature,
|
|
||||||
images: [
|
|
||||||
...(Array.isArray(formData.value.mainImage)
|
|
||||||
? formData.value.mainImage
|
|
||||||
: [formData.value.mainImage]
|
|
||||||
).filter(Boolean).map(item => spliceUrl(item)),
|
|
||||||
|
|
||||||
...(Array.isArray(formData.value.contentImage)
|
|
||||||
? formData.value.contentImage
|
|
||||||
: [formData.value.contentImage]
|
|
||||||
).filter(Boolean).map(item => spliceUrl(item))
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
let result = null
|
let result = null
|
||||||
switch (modal.value.type) {
|
switch (modal.value.type) {
|
||||||
case 'create':
|
case 'create':
|
||||||
result = await apis.products.createProductsItem(params).catch((error) => {
|
result = await apis.categorys.createProductsItem(params).catch((error) => {
|
||||||
throw new Error(error)
|
throw new Error(error)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
@ -382,7 +125,6 @@ function handleOk() {
|
|||||||
* 取消
|
* 取消
|
||||||
*/
|
*/
|
||||||
function handleCancel() {
|
function handleCancel() {
|
||||||
imgUrl.value = ''
|
|
||||||
hideModal()
|
hideModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,31 +138,9 @@ function onAfterClose() {
|
|||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
handleCreate,
|
handleCreate,
|
||||||
handleEdit,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 添加标准
|
|
||||||
function addStandard() {
|
|
||||||
formData.value.standard.push({ label: '', value: '' })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除标准
|
|
||||||
function removeStandard(index) {
|
|
||||||
if (formData.value.standard.length > 1) {
|
|
||||||
formData.value.standard.splice(index, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 添加标准
|
|
||||||
function addFeature() {
|
|
||||||
formData.value.feature.push({ label: '', value: '' })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除标准
|
|
||||||
function removeFeature(index) {
|
|
||||||
if (formData.value.feature.length > 1) {
|
|
||||||
formData.value.feature.splice(index, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped></style>
|
<style lang="less" scoped></style>
|
||||||
|
|||||||
@ -1,40 +1,4 @@
|
|||||||
<template>
|
<template>
|
||||||
<x-search-bar class="mb-8-2">
|
|
||||||
<template #default="{ gutter, colSpan }">
|
|
||||||
<a-form :model="searchFormData" layout="inline">
|
|
||||||
<a-row :gutter="gutter">
|
|
||||||
<a-col v-bind="colSpan">
|
|
||||||
<a-form-item label="产品类别名称" name="title">
|
|
||||||
<a-input placeholder="请输入产品名称" v-model:value="searchFormData.title"></a-input>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
<a-col v-bind="colSpan">
|
|
||||||
<a-form-item label="产品名称" name="code">
|
|
||||||
<a-input placeholder="请输入产品名称" v-model:value="searchFormData.code"></a-input>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
|
|
||||||
<a-col v-bind="colSpan">
|
|
||||||
<a-form-item label="状态" name="status">
|
|
||||||
<a-select v-model:value="searchFormData.status" allowClear>
|
|
||||||
<a-select-option value="">全部</a-select-option>
|
|
||||||
<a-select-option value="enabled">启用</a-select-option>
|
|
||||||
<a-select-option value="disabled">停用</a-select-option>
|
|
||||||
</a-select>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
<a-col class="align-right" v-bind="colSpan">
|
|
||||||
<a-space>
|
|
||||||
<a-button @click="handleResetSearch">{{ $t('button.reset') }}</a-button>
|
|
||||||
<a-button ghost type="primary" @click="handleSearch">
|
|
||||||
{{ $t('button.search') }}
|
|
||||||
</a-button>
|
|
||||||
</a-space>
|
|
||||||
</a-col>
|
|
||||||
</a-row>
|
|
||||||
</a-form>
|
|
||||||
</template>
|
|
||||||
</x-search-bar>
|
|
||||||
<a-row :gutter="8" :wrap="false">
|
<a-row :gutter="8" :wrap="false">
|
||||||
<a-col flex="auto">
|
<a-col flex="auto">
|
||||||
<a-card type="flex">
|
<a-card type="flex">
|
||||||
@ -43,53 +7,20 @@
|
|||||||
<template #icon>
|
<template #icon>
|
||||||
<plus-outlined></plus-outlined>
|
<plus-outlined></plus-outlined>
|
||||||
</template>
|
</template>
|
||||||
新增产品
|
新增分类
|
||||||
</a-button>
|
</a-button>
|
||||||
</x-action-bar>
|
</x-action-bar>
|
||||||
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
|
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
|
||||||
:pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange">
|
:pagination="paginationState" @change="onTableChange">
|
||||||
<template #bodyCell="{ column, record }">
|
<template #bodyCell="{ column, record }">
|
||||||
|
|
||||||
<template v-if="column.dataIndex === 'title'">
|
|
||||||
<a-tooltip :title="record.title">
|
|
||||||
<div class="text-ellipsis">{{ record.title }}</div>
|
|
||||||
</a-tooltip>
|
|
||||||
</template>
|
|
||||||
<template v-if="column.dataIndex === 'categoryID'">
|
|
||||||
<a-tooltip :title="record.categoryID">
|
|
||||||
<div class="text-ellipsis">{{ record.categoryID }}</div>
|
|
||||||
</a-tooltip>
|
|
||||||
</template>
|
|
||||||
<template v-if="column.dataIndex === 'compose'">
|
|
||||||
<a-tooltip :title="record.compose">
|
|
||||||
<div class="text-ellipsis">{{ record.compose }}</div>
|
|
||||||
</a-tooltip>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template v-if="column.dataIndex === 'target'">
|
|
||||||
<a-tooltip :title="record.target">
|
|
||||||
<div class="text-ellipsis">{{ record.target }}</div>
|
|
||||||
</a-tooltip>
|
|
||||||
</template>
|
|
||||||
<template v-if="'mainImage' === column.dataIndex">
|
|
||||||
<a-image :width="60" :alt="column.title"
|
|
||||||
:src="config('http.apiBasic') + record.mainImage || $imageErr.imgErr" />
|
|
||||||
</template>
|
|
||||||
<template v-if="'contentImage' === column.dataIndex">
|
|
||||||
<a-image :width="60" :alt="column.title"
|
|
||||||
:src="config('http.apiBasic') + record.contentImage || $imageErr.imgErr" />
|
|
||||||
</template>
|
|
||||||
<template v-if="'status' === column.dataIndex">
|
<template v-if="'status' === column.dataIndex">
|
||||||
<a-tag v-if="record.status === 'enabled'" :color="'green'">启用</a-tag>
|
<a-tag v-if="record.status === 'enabled'" :color="'green'">启用</a-tag>
|
||||||
<a-tag v-if="record.status === 'disabled'" :color="'red'">停用</a-tag>
|
<a-tag v-if="record.status === 'disabled'" :color="'red'">停用</a-tag>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="'action' === column.key">
|
<template v-if="'action' === column.key">
|
||||||
<x-action-button @click="$refs.editDialogRef.handleEdit(record)">
|
|
||||||
<a-tooltip>
|
<x-action-button @click="handleDelete(record.value)">
|
||||||
<template #title> {{ $t('pages.system.user.edit') }}</template>
|
|
||||||
<edit-outlined /> </a-tooltip></x-action-button>
|
|
||||||
<x-action-button @click="handleDelete(record)">
|
|
||||||
<a-tooltip>
|
<a-tooltip>
|
||||||
<template #title>{{ $t('pages.system.delete') }}</template>
|
<template #title>{{ $t('pages.system.delete') }}</template>
|
||||||
<delete-outlined style="color: #ff4d4f" /> </a-tooltip></x-action-button>
|
<delete-outlined style="color: #ff4d4f" /> </a-tooltip></x-action-button>
|
||||||
@ -117,46 +48,12 @@ import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vu
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { delProductsItem, getProductsList } from '@/apis/modules/products'
|
import { delProductsItem, getProductsList } from '@/apis/modules/products'
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'components',
|
name: 'productType',
|
||||||
})
|
})
|
||||||
const { t } = useI18n() // 解构出t方法
|
const { t } = useI18n() // 解构出t方法
|
||||||
const columns = [
|
const columns = [
|
||||||
{ title: '产品名称', dataIndex: 'code', width: 120 },
|
{ title: '分类名称', dataIndex: 'label' },
|
||||||
{ title: '产品类别名称', dataIndex: 'title', width: 120 },
|
// { title: '状态', dataIndex: 'status', width: 120, align: 'center' },
|
||||||
{ title: '产品类别', dataIndex: 'categoryID', key: 'categoryID', width: 120 },
|
|
||||||
{ title: '原料组成', dataIndex: 'compose', key: 'compose', width: 120 },
|
|
||||||
{ title: '适用对象', dataIndex: 'target', width: 120 },
|
|
||||||
{
|
|
||||||
title: '功能特点',
|
|
||||||
dataIndex: 'feature',
|
|
||||||
width: 120,
|
|
||||||
align: 'center',
|
|
||||||
customRender: ({ text }) => Array.isArray(text) ? text.join(', ') : ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '产品标准',
|
|
||||||
dataIndex: 'standard',
|
|
||||||
width: 120,
|
|
||||||
align: 'center',
|
|
||||||
customRender: ({ text }) => Array.isArray(text)
|
|
||||||
? text.map(item => `${item.label}: ${item.fu_hoao}${item.val}${item.prx}`).join(', ')
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '产品图片',
|
|
||||||
dataIndex: 'mainImage',
|
|
||||||
width: 120,
|
|
||||||
align: 'center',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '产品内容图片',
|
|
||||||
dataIndex: 'contentImage',
|
|
||||||
width: 120,
|
|
||||||
align: 'center',
|
|
||||||
},
|
|
||||||
|
|
||||||
{ title: '产品排序', dataIndex: 'sequence', width: 120, align: 'center' },
|
|
||||||
{ title: '产品状态', dataIndex: 'status', width: 120, align: 'center' },
|
|
||||||
{ title: t('button.action'), key: 'action', fixed: 'right', width: 100, align: 'center' },
|
{ title: t('button.action'), key: 'action', fixed: 'right', width: 100, align: 'center' },
|
||||||
]
|
]
|
||||||
const { listData, loading, showLoading, hideLoading, paginationState, resetPagination, searchFormData } =
|
const { listData, loading, showLoading, hideLoading, paginationState, resetPagination, searchFormData } =
|
||||||
@ -172,11 +69,10 @@ async function getPageList() {
|
|||||||
try {
|
try {
|
||||||
showLoading()
|
showLoading()
|
||||||
const { pageSize, current } = paginationState
|
const { pageSize, current } = paginationState
|
||||||
const { success, data, total } = await apis.products
|
const { success, data, total } = await apis.categorys
|
||||||
.getProductsList({
|
.getDataList({
|
||||||
pageSize,
|
pageSize,
|
||||||
page: current,
|
page: current,
|
||||||
...searchFormData.value,
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
@ -185,12 +81,8 @@ async function getPageList() {
|
|||||||
if (config('http.code.success') === success) {
|
if (config('http.code.success') === success) {
|
||||||
listData.value = data.map(item => ({
|
listData.value = data.map(item => ({
|
||||||
...item,
|
...item,
|
||||||
mainImage: item.images?.[0] || '',
|
key:item.value
|
||||||
contentImage: item.images?.[1] || '',
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
console.log('接口数据', data)
|
|
||||||
console.log('接口过滤数据', listData.value)
|
|
||||||
paginationState.total = total
|
paginationState.total = total
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -201,16 +93,16 @@ async function getPageList() {
|
|||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
*/
|
*/
|
||||||
function handleDelete({ id }) {
|
function handleDelete(value) {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: t('pages.system.user.delTip'),
|
title: '确定删除该分类吗',
|
||||||
content: t('button.confirm'),
|
content: t('button.confirm'),
|
||||||
okText: t('button.confirm'),
|
okText: t('button.confirm'),
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
; (async () => {
|
; (async () => {
|
||||||
try {
|
try {
|
||||||
const { success } = await apis.products.delProductsItem(id).catch(() => {
|
const { success } = await apis.categorys.delProductsItem(value).catch(() => {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
})
|
})
|
||||||
if (config('http.code.success') === success) {
|
if (config('http.code.success') === success) {
|
||||||
@ -255,7 +147,6 @@ function handleResetSearch() {
|
|||||||
* 编辑完成
|
* 编辑完成
|
||||||
*/
|
*/
|
||||||
async function onOk() {
|
async function onOk() {
|
||||||
message.success(t('component.message.success.delete'))
|
|
||||||
await getPageList()
|
await getPageList()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user