generated from Leo_Ding/web-template
产品中心
This commit is contained in:
parent
c514f7a1c0
commit
b9048006a1
@ -51,4 +51,5 @@ export default {
|
||||
friendlyLinks:'友情链接',
|
||||
websiteStatement:'网站声明',
|
||||
contactUs:'联系我们',
|
||||
productType:'产品分类'
|
||||
}
|
||||
|
||||
@ -13,4 +13,16 @@ export default [
|
||||
permission: '*',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'productType',
|
||||
name: 'productType',
|
||||
component: 'productType/index.vue',
|
||||
meta: {
|
||||
icon: ShoppingOutlined,
|
||||
title: '产品分类',
|
||||
isMenu: true,
|
||||
keepAlive: true,
|
||||
permission: '*',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
@ -4,79 +4,64 @@
|
||||
<a-spin :spinning="spining">
|
||||
<a-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<a-card class="mb-8-2">
|
||||
<a-tabs v-model:activeKey="activeKey">
|
||||
<a-tab-pane key="1" tab="基本信息">
|
||||
<a-row :gutter="12">
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'产品名称'" name="code">
|
||||
<a-input :placeholder="'请输入产品名称'" v-model:value="formData.code"></a-input>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'产品类别名称'" name="title">
|
||||
<a-input :placeholder="'请输入产品类别名称'" v-model:value="formData.title"></a-input>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'产品类别'" name="categoryID">
|
||||
<!-- <a-input :placeholder="'请输入产品类别名称'" v-model:value="formData.categoryID"></a-input>-->
|
||||
<div style="display: flex;justify-content: space-between;">
|
||||
<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-option v-for="item in areaList" :value="item.value">{{
|
||||
item.categoryIDName }}</a-select-option>
|
||||
</a-select>
|
||||
<!-- <a-button type="primary" @click="childOpen = true">新增产品类别</a-button>-->
|
||||
</div>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'原料组成'" name="compose">
|
||||
<a-textarea :placeholder="'请输入原料组成'" v-model:value="formData.compose"></a-textarea>
|
||||
<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>
|
||||
<!-- <div style="display: flex;justify-content: space-between;">-->
|
||||
<!-- <a-select v-model:value="formData.target" allowClear>-->
|
||||
<!-- <a-select-option v-for="item in areaList" :value="item.code">{{ item.targetName }}</a-select-option>-->
|
||||
<!-- </a-select>-->
|
||||
<!--<!– <a-button type="primary" @click="childOpen = true">新增适用对象</a-button>–>-->
|
||||
<!-- </div>-->
|
||||
</a-form-item>
|
||||
<!-- <a-form-item :label="'适用对象'" name="target">-->
|
||||
<!-- <a-textarea :placeholder="'请输入岗位职责'" v-model:value="formData.target"></a-textarea>-->
|
||||
<!-- </a-form-item>-->
|
||||
|
||||
</a-col>
|
||||
<!-- <a-col :span="24">-->
|
||||
<!-- <a-form-item :label="'原料组成'" name="feature">-->
|
||||
<!-- <a-textarea :placeholder="'请输入原料组成'" v-model:value="formData.feature"></a-textarea>-->
|
||||
<!-- </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-tab-pane>
|
||||
<a-tab-pane key="2" tab="产品功能">
|
||||
<a-col :span="24">
|
||||
<a-form-item
|
||||
v-for="(item, index) in formData.feature"
|
||||
:key="index"
|
||||
<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-input-->
|
||||
<!-- v-model:value="item.data"-->
|
||||
<!-- 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-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>
|
||||
@ -88,50 +73,19 @@
|
||||
</a-form-item>
|
||||
|
||||
</a-col>
|
||||
<!-- <a-col :span="24">-->
|
||||
<!-- <a-form-item :label="'功能特点'" name="feature">-->
|
||||
<!-- <a-select-->
|
||||
<!-- v-model:value="formData.feature"-->
|
||||
<!-- mode="tags"-->
|
||||
<!-- :placeholder="'请输入功能特点,按回车分隔'"-->
|
||||
<!-- :token-separators="[',']"-->
|
||||
<!-- style="width: 100%;"-->
|
||||
<!-- />-->
|
||||
<!-- </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"
|
||||
<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"
|
||||
<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>
|
||||
@ -144,76 +98,14 @@
|
||||
</a-form-item>
|
||||
|
||||
</a-col>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
|
||||
<!-- <a-col :span="24">-->
|
||||
<!-- <a-form-item :label="'产品图片'" name="images">-->
|
||||
<!-- <gx-upload v-model="formData.images" accept-types=".jpg,.png,.webp" :fileNumber="2" />-->
|
||||
<!-- </a-form-item>-->
|
||||
|
||||
<!-- </a-col>-->
|
||||
<a-form-item :label="'产品主图'" >
|
||||
<gx-upload v-model="formData.mainImage" :fileNumber="1" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item :label="'内容物图'" >
|
||||
<gx-upload v-model="formData.contentImage" :fileNumber="1" />
|
||||
</a-form-item>
|
||||
<!-- <a-col :span="24">-->
|
||||
<!-- <a-form-item :label="'产品图片'" name="images">-->
|
||||
<!-- <gx-upload v-model="formData.images[0]" accept-types=".jpg,.png,.webp" :fileNumber="1" />-->
|
||||
<!-- </a-form-item>-->
|
||||
|
||||
<!-- </a-col>-->
|
||||
<!-- <a-col :span="24">-->
|
||||
<!-- <a-form-item :label="'产品内容物图片'" name="images">-->
|
||||
<!-- <gx-upload v-model="formData.images[1]" accept-types=".jpg,.png,.webp" :fileNumber="1" />-->
|
||||
<!-- </a-form-item>-->
|
||||
|
||||
<!-- </a-col>-->
|
||||
|
||||
|
||||
<a-col :span="24">
|
||||
<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="24">
|
||||
<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-row>
|
||||
</a-card>
|
||||
</a-form>
|
||||
</a-spin>
|
||||
<a-modal ref="modalRef" v-model:open="childOpen" :wrap-style="{ overflow: 'hidden' }" @ok="handleCombinedOk">
|
||||
<a-card class="mb-8-2">
|
||||
<a-form ref="areaFormRef" :model="formArea" :rules="areaFormRules">
|
||||
<a-row :gutter="12">
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'产品类别名称'" name="name">
|
||||
<a-input v-model:value="formArea.name" :placeholder="'请输入产品类别名称'" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'状态'" name="status" style="width: 100%;">
|
||||
<a-radio-group v-model:value="formArea.status" :options="[
|
||||
{ label: '启用', value: 'enabled' },
|
||||
{ label: '停用', value: 'disabled' },
|
||||
]"></a-radio-group>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
</a-card>
|
||||
<template #title>
|
||||
<div ref="modalTitleRef" style="width: 100%; cursor: move">新增产品类别</div>
|
||||
</template>
|
||||
|
||||
</a-modal>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@ -251,6 +143,7 @@ const mainImage = ref([])
|
||||
const contentImage = ref([])
|
||||
const childOpen = ref(false)
|
||||
const formArea = ref({ name: '', status: 'enabled' })
|
||||
const activeKey=ref('1')
|
||||
formRules.value = {
|
||||
title: { required: true, message: '请输入产品类别名称' },
|
||||
code: { required: true, message: '请输入产品名称' },
|
||||
@ -264,6 +157,7 @@ formRules.value = {
|
||||
contentImage: { required: false, message: '请上传产品内容图片' },
|
||||
sequence: [{ required: true, message: '请输入产品排序' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||
|
||||
}
|
||||
const areaFormRules = {
|
||||
categoryIDName: [{ required: true, message: '请输入产品类别' }],
|
||||
@ -329,9 +223,7 @@ function handleCreate() {
|
||||
target: '',
|
||||
feature: [{
|
||||
label: '功能特点',
|
||||
data:[{
|
||||
msg:[''],
|
||||
}]
|
||||
data: []
|
||||
}],
|
||||
standard: [{
|
||||
label: '',
|
||||
@ -414,9 +306,7 @@ async function handleEdit(record = {}) {
|
||||
}],
|
||||
feature: data.feature || [{
|
||||
label: '功能特点',
|
||||
data:[{
|
||||
msg:[''],
|
||||
}]
|
||||
data: []
|
||||
}],
|
||||
// images:data.images || [''],
|
||||
mainImage: data.images ? [config('http.apiBasic') + data.images[0]] : [''],
|
||||
@ -445,12 +335,7 @@ function handleOk() {
|
||||
fu_hoao: '',
|
||||
prx: '',
|
||||
}],
|
||||
feature:formData.value.feature|| [{
|
||||
label:'功能特点',
|
||||
data:[{
|
||||
msg:[''],
|
||||
}]
|
||||
}],
|
||||
feature: formData.value.feature,
|
||||
images: [
|
||||
...(Array.isArray(formData.value.mainImage)
|
||||
? formData.value.mainImage
|
||||
@ -538,6 +423,4 @@ function removeFeature(index) {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
</style>
|
||||
<style lang="less" scoped></style>
|
||||
|
||||
426
src/views/productType/components/EditDialog.vue
Normal file
426
src/views/productType/components/EditDialog.vue
Normal file
@ -0,0 +1,426 @@
|
||||
<template>
|
||||
<a-modal :open="modal.open" :title="modal.title" :width="640" :confirm-loading="modal.confirmLoading"
|
||||
:after-close="onAfterClose" :cancel-text="cancelText" :ok-text="okText" @ok="handleOk" @cancel="handleCancel">
|
||||
<a-spin :spinning="spining">
|
||||
<a-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<a-card class="mb-8-2">
|
||||
<a-tabs v-model:activeKey="activeKey">
|
||||
<a-tab-pane key="1" tab="基本信息">
|
||||
<a-row :gutter="12">
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'产品名称'" name="code">
|
||||
<a-input :placeholder="'请输入产品名称'" v-model:value="formData.code"></a-input>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24">
|
||||
<a-form-item :label="'产品类别'" name="categoryID">
|
||||
<div style="display: flex;justify-content: space-between;">
|
||||
<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-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-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-form>
|
||||
</a-spin>
|
||||
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
import { ref, onBeforeMount } from 'vue'
|
||||
import { config } from '@/config'
|
||||
import apis from '@/apis'
|
||||
import { useForm, useModal, useSpining } from '@/hooks'
|
||||
import { message } from 'ant-design-vue'
|
||||
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'
|
||||
const areaFormRef = ref()
|
||||
const emit = defineEmits(['ok'])
|
||||
const { t } = useI18n() // 解构出t方法
|
||||
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
|
||||
const { formRecord, formData, formRef, formRules, resetForm } = useForm()
|
||||
const { spining, showSpining, hideSpining } = useSpining()
|
||||
const cancelText = ref(t('button.cancel'))
|
||||
const okText = ref(t('button.confirm'))
|
||||
const rolesValue = 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 = {
|
||||
title: { 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]
|
||||
|
||||
if (config('http.code.success') === success) {
|
||||
const mapped = data.map(item => {
|
||||
return {
|
||||
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() {
|
||||
showModal({
|
||||
type: 'create',
|
||||
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()
|
||||
}
|
||||
|
||||
//新建产品类别
|
||||
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() {
|
||||
console.log('编辑产品列表', formData.value)
|
||||
formRef.value.validateFields().then(async (values) => {
|
||||
try {
|
||||
showLoading()
|
||||
const params = {
|
||||
...values,
|
||||
standard: formData.value.standard ||
|
||||
[{
|
||||
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
|
||||
switch (modal.value.type) {
|
||||
case 'create':
|
||||
result = await apis.products.createProductsItem(params).catch((error) => {
|
||||
throw new Error(error)
|
||||
})
|
||||
break
|
||||
case 'edit':
|
||||
result = await apis.products.updateProductsItem(formData.value.id, params).catch(() => {
|
||||
throw new Error(error)
|
||||
})
|
||||
break
|
||||
}
|
||||
hideLoading()
|
||||
if (config('http.code.success') === result?.success) {
|
||||
hideModal()
|
||||
emit('ok')
|
||||
}
|
||||
} catch (error) {
|
||||
message.error({ content: error.message })
|
||||
hideLoading()
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
hideLoading()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消
|
||||
*/
|
||||
function handleCancel() {
|
||||
imgUrl.value = ''
|
||||
hideModal()
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭后
|
||||
*/
|
||||
function onAfterClose() {
|
||||
resetForm()
|
||||
hideLoading()
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
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>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
263
src/views/productType/index.vue
Normal file
263
src/views/productType/index.vue
Normal file
@ -0,0 +1,263 @@
|
||||
<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-col flex="auto">
|
||||
<a-card type="flex">
|
||||
<x-action-bar class="mb-8-2">
|
||||
<a-button type="primary" @click="$refs.editDialogRef.handleCreate()">
|
||||
<template #icon>
|
||||
<plus-outlined></plus-outlined>
|
||||
</template>
|
||||
新增产品
|
||||
</a-button>
|
||||
</x-action-bar>
|
||||
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
|
||||
:pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange">
|
||||
<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">
|
||||
<a-tag v-if="record.status === 'enabled'" :color="'green'">启用</a-tag>
|
||||
<a-tag v-if="record.status === 'disabled'" :color="'red'">停用</a-tag>
|
||||
</template>
|
||||
|
||||
<template v-if="'action' === column.key">
|
||||
<x-action-button @click="$refs.editDialogRef.handleEdit(record)">
|
||||
<a-tooltip>
|
||||
<template #title> {{ $t('pages.system.user.edit') }}</template>
|
||||
<edit-outlined /> </a-tooltip></x-action-button>
|
||||
<x-action-button @click="handleDelete(record)">
|
||||
<a-tooltip>
|
||||
<template #title>{{ $t('pages.system.delete') }}</template>
|
||||
<delete-outlined style="color: #ff4d4f" /> </a-tooltip></x-action-button>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<edit-dialog ref="editDialogRef" @ok="onOk"></edit-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { ref } from 'vue'
|
||||
import apis from '@/apis'
|
||||
import { formatUtcDateTime } from '@/utils/util'
|
||||
import { config } from '@/config'
|
||||
import { statusUserTypeEnum } from '@/enums/system'
|
||||
import { usePagination } from '@/hooks'
|
||||
|
||||
import EditDialog from './components/EditDialog.vue'
|
||||
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { delProductsItem, getProductsList } from '@/apis/modules/products'
|
||||
defineOptions({
|
||||
name: 'components',
|
||||
})
|
||||
const { t } = useI18n() // 解构出t方法
|
||||
const columns = [
|
||||
{ title: '产品名称', dataIndex: 'code', width: 120 },
|
||||
{ title: '产品类别名称', dataIndex: 'title', width: 120 },
|
||||
{ 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' },
|
||||
]
|
||||
const { listData, loading, showLoading, hideLoading, paginationState, resetPagination, searchFormData } =
|
||||
usePagination()
|
||||
|
||||
const editDialogRef = ref()
|
||||
getPageList()
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function getPageList() {
|
||||
try {
|
||||
showLoading()
|
||||
const { pageSize, current } = paginationState
|
||||
const { success, data, total } = await apis.products
|
||||
.getProductsList({
|
||||
pageSize,
|
||||
page: current,
|
||||
...searchFormData.value,
|
||||
})
|
||||
.catch(() => {
|
||||
throw new Error()
|
||||
})
|
||||
hideLoading()
|
||||
if (config('http.code.success') === success) {
|
||||
listData.value = data.map(item => ({
|
||||
...item,
|
||||
mainImage: item.images?.[0] || '',
|
||||
contentImage: item.images?.[1] || '',
|
||||
}))
|
||||
|
||||
console.log('接口数据', data)
|
||||
console.log('接口过滤数据', listData.value)
|
||||
paginationState.total = total
|
||||
}
|
||||
} catch (error) {
|
||||
hideLoading()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
function handleDelete({ id }) {
|
||||
Modal.confirm({
|
||||
title: t('pages.system.user.delTip'),
|
||||
content: t('button.confirm'),
|
||||
okText: t('button.confirm'),
|
||||
onOk: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
; (async () => {
|
||||
try {
|
||||
const { success } = await apis.products.delProductsItem(id).catch(() => {
|
||||
throw new Error()
|
||||
})
|
||||
if (config('http.code.success') === success) {
|
||||
resolve()
|
||||
message.success(t('component.message.success.delete'))
|
||||
await getPageList()
|
||||
}
|
||||
} catch (error) {
|
||||
reject()
|
||||
}
|
||||
})()
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
function onTableChange({ current, pageSize }) {
|
||||
paginationState.current = current
|
||||
paginationState.pageSize = pageSize
|
||||
getPageList()
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
*/
|
||||
function handleSearch() {
|
||||
resetPagination()
|
||||
getPageList()
|
||||
}
|
||||
/**
|
||||
* 重置
|
||||
*/
|
||||
function handleResetSearch() {
|
||||
searchFormData.value = {}
|
||||
resetPagination()
|
||||
getPageList()
|
||||
}
|
||||
/**
|
||||
* 编辑完成
|
||||
*/
|
||||
async function onOk() {
|
||||
message.success(t('component.message.success.delete'))
|
||||
await getPageList()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
@ -67,7 +67,7 @@ import { useForm, useModal } from '@/hooks'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import dayjs from 'dayjs'
|
||||
import { createMenu, getMenu, updateMenu } from '@/apis/modules/webSite'
|
||||
|
||||
const emit = defineEmits(['ok'])
|
||||
const { t } = useI18n() // 解构出t方法
|
||||
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user