提交 892e2dcf authored 作者: lidongxu's avatar lidongxu

refactor(bi/prd_tag): 修复新增编辑删除功能

同上
上级 b8d3aaa7
...@@ -14,5 +14,5 @@ VITE_APP_ENV = 'development' ...@@ -14,5 +14,5 @@ VITE_APP_ENV = 'development'
VITE_APP_PUBLIC_PATH = '/' VITE_APP_PUBLIC_PATH = '/'
# 第三方服务回调地址 # 第三方服务回调地址
VITE_APP_REDIRECT_URL = 'http://localhost:81/' VITE_APP_REDIRECT_URL = 'http://localhost:8080/'
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
<div class="buttons_wrap"> <div class="buttons_wrap">
<!-- 扩展的按钮 --> <!-- 扩展的按钮 -->
<slot name="buttons"></slot> <slot name="buttons"></slot>
<el-input v-model="searchValue" <el-input v-model="queryParams.searchKey"
:placeholder="placeholder" :placeholder="placeholder"
clearable clearable
prefix-icon="Search" /> prefix-icon="Search"
@click.stop />
</div> </div>
<div class="scroll" <div class="scroll"
:class="{ 'row_gap': customOptions.rowGap }"> :class="{ 'row_gap': customOptions.rowGap }">
...@@ -129,28 +130,28 @@ const props = defineProps({ ...@@ -129,28 +130,28 @@ const props = defineProps({
// 隐藏左侧分类框 // 隐藏左侧分类框
const hideSideBar = ref(false) const hideSideBar = ref(false)
// 搜索关键字 // 上次点击的行对象
const searchValue = ref('')
// 上次点击的行对象-唯一值
const lastRowId = ref(null)
const lastRow = ref(null) const lastRow = ref(null)
// 分页参数 // 分页参数
const queryParams = reactive({ const queryParams = reactive({
pageNum: 1, pageNum: 1,
pageSize: 10 pageSize: 10,
searchKey: ''
}) })
const treeRef = ref(null) const treeRef = ref(null)
const emits = defineEmits(['update:modelValue', 'search', 'pageChange']) // search:让外部触发业务的搜索
// listChange: 让外部重新搜索本分类列表数据
const emits = defineEmits(['update:modelValue', 'search', 'listChange', 'flodEdit', 'flodDel'])
watch(searchValue, (val) => { watch(() => queryParams.searchKey, (val) => {
if (!props.customOptions.showPagination) { if (!props.customOptions.showPagination) {
// 没有分页,用本地列表搜索 // 没有分页,用本地列表搜索
treeRef.value.filter(val); treeRef.value.filter(val);
} else { } else {
// 有分页,走外面接口搜索 // 有分页,走外面接口搜索
queryParams.searchKey = val queryParams.searchKey = val
// emits('search', queryParams) emits('listChange', queryParams)
} }
}) })
...@@ -159,7 +160,7 @@ watch(() => props.modelValue, (val) => { ...@@ -159,7 +160,7 @@ watch(() => props.modelValue, (val) => {
if (val) { if (val) {
nextTick(() => { nextTick(() => {
treeRef.value.setCurrentKey(val) treeRef.value.setCurrentKey(val)
lastRowId.value = val lastRow[props.nodeKey] = val
}) })
} }
}) })
...@@ -167,7 +168,6 @@ watch(() => props.modelValue, (val) => { ...@@ -167,7 +168,6 @@ watch(() => props.modelValue, (val) => {
// 点击空白位置-取消选中效果 // 点击空白位置-取消选中效果
const cancelSel = () => { const cancelSel = () => {
// 刚才有过点击的某行 // 刚才有过点击的某行
console.log(666, lastRow.value)
if (lastRow.value) { if (lastRow.value) {
treeRef.value.setCurrentKey(null) treeRef.value.setCurrentKey(null)
lastRow.value = null lastRow.value = null
...@@ -179,15 +179,13 @@ const cancelSel = () => { ...@@ -179,15 +179,13 @@ const cancelSel = () => {
// 点击某行 // 点击某行
const handleNodeClick = (row) => { const handleNodeClick = (row) => {
// 当前点击和上次点击一样->取消 // 当前点击和上次点击一样->取消
if (lastRowId.value === row[props.nodeKey]) { if (lastRow[props.nodeKey] === row[props.nodeKey]) {
treeRef.value.setCurrentKey(null) treeRef.value.setCurrentKey(null)
lastRowId.value = null
lastRow.value = null lastRow.value = null
} else { } else {
lastRowId.value = row[props.nodeKey]
lastRow.value = row lastRow.value = row
} }
emits('update:modelValue', lastRowId.value ? row[props.nodeKey] : '') emits('update:modelValue', lastRow.value ? row[props.nodeKey] : '')
emits('search', row) emits('search', row)
} }
...@@ -199,11 +197,11 @@ const filterNode = (value, data) => { ...@@ -199,11 +197,11 @@ const filterNode = (value, data) => {
// 分页逻辑触发 // 分页逻辑触发
const getPageList = () => { const getPageList = () => {
emits('pageChange', queryParams) emits('listChange', queryParams)
} }
const handleClick = () => { const handleClick = () => {
hideSideBar.value =!hideSideBar.value hideSideBar.value = !hideSideBar.value
} }
</script> </script>
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</el-date-picker> </el-date-picker>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div :class="{chart_wrap : showType === 'charts', table_wrap : showType === 'table'}" <div :class="{ chart_wrap: showType === 'charts', table_wrap: showType === 'table' }"
v-loading="loading"> v-loading="loading">
<template v-if="queryParams.brandList.length > 0 && queryParams.typeList.length > 0 && !loading"> <template v-if="queryParams.brandList.length > 0 && queryParams.typeList.length > 0 && !loading">
<template v-if="showType === 'charts'"> <template v-if="showType === 'charts'">
...@@ -387,10 +387,11 @@ const reset = async () => { ...@@ -387,10 +387,11 @@ const reset = async () => {
} }
</script> </script>
<style scoped lang="scss"> <style scoped
.table_wrap{ lang="scss">
display: flex; .table_wrap {
flex-direction: column; display: flex;
justify-content: flex-start; flex-direction: column;
} justify-content: flex-start;
}
</style> </style>
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<div class="app-container"> <div class="app-container">
<el-row :gutter="20" <el-row :gutter="20"
class="client-fix-height container"> class="client-fix-height container">
<!--商品分类--> <!-- 商品标签列表 -->
<category-tree :options="tagsOptions" <category-tree :options="tagsOptions"
:defaultProps="defaultProps" :defaultProps="defaultProps"
:nodeKey="nodeKey" :nodeKey="nodeKey"
...@@ -21,13 +21,14 @@ ...@@ -21,13 +21,14 @@
@flodEdit="handleFlodEdit" @flodEdit="handleFlodEdit"
@flodDel="handleFlodDel" @flodDel="handleFlodDel"
@search="handleQuery" @search="handleQuery"
@pageChange="getSeriesGoodsTagList"> @listChange="getSeriesGoodsTagList">
<template #buttons> <template #buttons>
<el-button type="primary" <el-button type="primary"
icon="Plus" icon="Plus"
@click="handleAdd">新增</el-button> @click="handleAdd">新增</el-button>
</template> </template>
</category-tree> </category-tree>
<!-- 标签下属商品 -->
<el-col :span="10" <el-col :span="10"
:xs="24" :xs="24"
class="right_col"> class="right_col">
...@@ -43,9 +44,9 @@ ...@@ -43,9 +44,9 @@
</el-table> </el-table>
</el-col> </el-col>
</el-row> </el-row>
<!-- 添加或修改商品-标签详情对话框 --> <!-- 添加/修改-商品标签 -->
<el-dialog :title="title" <el-dialog :title="title"
v-model="open"> v-model="visible">
<el-form ref="formRef" <el-form ref="formRef"
:model="form" :model="form"
:rules="rules" :rules="rules"
...@@ -58,10 +59,12 @@ ...@@ -58,10 +59,12 @@
<el-form-item label="系列和商品" <el-form-item label="系列和商品"
prop="seriesPrdMap"> prop="seriesPrdMap">
<el-cascader v-model="form.seriesPrdMap" <el-cascader v-model="form.seriesPrdMap"
v-if="open" v-if="visible"
:options="seriesPrdOptions" :options="seriesPrdOptions"
:props="props" :props="props"
:show-all-levels="false"
collapse-tags collapse-tags
collapse-tags-tooltip
clearable clearable
filterable filterable
popper-class="my_popper"></el-cascader> popper-class="my_popper"></el-cascader>
...@@ -81,32 +84,24 @@ import { getSeriesListAPI, getProductListAPI, createSeriesGoodsTagAPI, getSeries ...@@ -81,32 +84,24 @@ import { getSeriesListAPI, getProductListAPI, createSeriesGoodsTagAPI, getSeries
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
// 左侧-商品集合标签相关数据 const tagsOptions = ref([]); // 标签列表
const formRef = ref(null)
const tagsOptions = ref([]);
const defaultProps = reactive({ const defaultProps = reactive({
children: 'children', children: 'children',
label: 'prdTagName' label: 'prdTagName'
}); });
const nodeKey = 'prdTagId'; const nodeKey = 'prdTagId';
// 查询参数 const queryParams = reactive({ // 标签列表查询参数
const queryParams = reactive({ tagNameLike: null,
prdTagId: null pageNum: 1,
pageSize: 10
}); });
// 右侧-商品列表 const prdList = ref([]); // 右侧-商品列表
const prdList = ref([]); const flodLoading = ref(false); // 左侧-商品集合标签-刷新状态
// 左侧-商品集合标签-刷新状态 const title = ref(''); // 弹出层标题
const flodLoading = ref(false); const visible = ref(false); // 是否显示弹出层
// 弹出层标题 const loading = ref(true); // 表格数据遮罩层
const title = ref(''); const form = ref({}); // 商品集合标签-表单参数
// 是否显示弹出层 const rules = reactive({ // 商品集合标签-表单校验
const open = ref(false);
// 表格数据遮罩层
const loading = ref(true);
// 商品集合标签-表单参数
const form = ref({});
// 商品集合标签-表单校验
const rules = reactive({
prdTagName: [ prdTagName: [
{ required: true, message: "标签名称不能为空", trigger: "blur" }, { required: true, message: "标签名称不能为空", trigger: "blur" },
{ min: 1, max: 7, message: '长度在 1 到 7 个字符', trigger: 'blur' } { min: 1, max: 7, message: '长度在 1 到 7 个字符', trigger: 'blur' }
...@@ -115,38 +110,25 @@ const rules = reactive({ ...@@ -115,38 +110,25 @@ const rules = reactive({
{ required: true, message: "系列和商品不能为空", trigger: "blur" } { required: true, message: "系列和商品不能为空", trigger: "blur" }
] ]
}); });
// 左侧商品标签总数 const tagTotal = ref(0); // 左侧商品标签总数
const tagTotal = ref(0);
// 级联选择器配置 const props = reactive({ // 级联选择器配置
const props = reactive({
multiple: true, multiple: true,
lazy: true, lazy: true,
async lazyLoad(node, resolve) { async lazyLoad(node, resolve) {
const { level } = node;
if (node.children?.length > 0) {
return resolve();
}
// 隐藏第二级列叶子节点没子菜单点击还加载的效果
if (level === 2) {
node.loading = false;
return resolve([]);
}
const { data: { total } } = await getProductListAPI({ seriesId: node.value }); const { data: { total } } = await getProductListAPI({ seriesId: node.value });
const { data: { rows } } = await getProductListAPI({ seriesId: node.value, pageNum: 1, pageSize: total }); const { data: { rows } } = await getProductListAPI({ seriesId: node.value, pageNum: 1, pageSize: total });
const nodes = rows.map(item => ({ const nodes = rows.map(item => ({
value: item.prdCode, value: item.prdCode,
label: item.prdName, label: item.prdName,
leaf: true leaf: true // 指定叶子节点
})); }));
// 通过调用resolve将子节点数据返回,通知组件数据加载完成 // 通过调用resolve将子节点数据返回,通知组件数据加载完成
resolve(nodes); resolve(nodes);
} }
}); });
// 系列和商品-级联数据 // 级联数据-系列和商品
const seriesPrdOptions = ref([]); const seriesPrdOptions = ref([]);
// 获取系列数据列表
const getSeriesList = async () => { const getSeriesList = async () => {
const response = await getSeriesListAPI(); const response = await getSeriesListAPI();
seriesPrdOptions.value = response.data.map(obj => { seriesPrdOptions.value = response.data.map(obj => {
...@@ -156,22 +138,23 @@ const getSeriesList = async () => { ...@@ -156,22 +138,23 @@ const getSeriesList = async () => {
}; };
}); });
}; };
getSeriesList();
// 获取商品-标签集合列表 // 商品标签-列表
const getSeriesGoodsTagList = async (params = { pageNum: 1, pageSize: 10 }) => { const getSeriesGoodsTagList = async (params) => {
const { data: { total, rows } } = await getSeriesGoodsTagListAPI({ Object.assign(queryParams, params)
...params, queryParams.tagNameLike = params?.searchKey;
tagNameLike: params.searchKey const { data: { total, rows } } = await getSeriesGoodsTagListAPI(queryParams);
});
tagTotal.value = total; tagTotal.value = total;
tagsOptions.value = rows; tagsOptions.value = rows;
// 获取商品-标签指定第一个详情 // 获取商品-标签指定第一个详情
queryParams.prdTagId = rows[0].prdTagId; queryParams.prdTagId = rows[0]?.prdTagId;
getTagDetailsList(); getTagDetailsList();
}; };
getSeriesGoodsTagList()
/** 查询商品-标签详情列表 */ /** 商品标签-详情 */
const getTagDetailsList = async () => { const getTagDetailsList = async () => {
loading.value = true; loading.value = true;
const response = await getPrdTagDetailAPI({ const response = await getPrdTagDetailAPI({
...@@ -180,8 +163,9 @@ const getTagDetailsList = async () => { ...@@ -180,8 +163,9 @@ const getTagDetailsList = async () => {
prdList.value = response.data; prdList.value = response.data;
loading.value = false; loading.value = false;
}; };
// 商品标签-编辑
const handleFlodEdit = async (row) => { const handleFlodEdit = async (row) => {
reset();
// 获取标签详情数据 // 获取标签详情数据
const res = await getPrdTagDetailAPI({ const res = await getPrdTagDetailAPI({
prdTagId: row.prdTagId prdTagId: row.prdTagId
...@@ -207,18 +191,15 @@ const handleFlodEdit = async (row) => { ...@@ -207,18 +191,15 @@ const handleFlodEdit = async (row) => {
obj.children = childrenRows obj.children = childrenRows
} }
}) })
open.value = true;
title.value = "修改商品-标签详情";
// ===== 回显数据 ===== // ===== 回显数据 =====
nextTick(() => { form.value.prdTagId = row.prdTagId
form.value.prdTagId = row.prdTagId form.value.prdTagName = row.prdTagName
form.value.prdTagName = row.prdTagName // 回显给数据绑定 v-model 的值
// 回显给数据绑定 v-model 的值 form.value.seriesPrdMap = res.data.map(obj => {
form.value.seriesPrdMap = res.data.map(obj => { return [obj.seriesId, obj.prdCode]
return [obj.seriesId, obj.prdCode]
})
form.value.seriesPrdMap = seriesPrdMap
}) })
visible.value = true;
title.value = "修改商品-标签详情";
} }
// 商品集合标签点击-删除 // 商品集合标签点击-删除
const handleFlodDel = async (row) => { const handleFlodDel = async (row) => {
...@@ -232,7 +213,7 @@ const handleFlodDel = async (row) => { ...@@ -232,7 +213,7 @@ const handleFlodDel = async (row) => {
} }
// 取消按钮 // 取消按钮
const cancel = () => { const cancel = () => {
open.value = false; visible.value = false;
reset(); reset();
} }
// 表单重置 // 表单重置
...@@ -242,22 +223,24 @@ const reset = () => { ...@@ -242,22 +223,24 @@ const reset = () => {
prdTagName: null, prdTagName: null,
seriesPrdMap: null seriesPrdMap: null
}; };
resetForm("form"); proxy.$refs.formRef.resetForm();
} }
/** 商品集合标签点击-搜索右侧商品列表 */ /** 商品标签点击 */
const handleQuery = () => { const handleQuery = () => {
queryParams.pageNum = 1; queryParams.pageNum = 1;
getTagDetailsList(); getTagDetailsList();
} }
/** 新增按钮操作 */ /** 新增商品标签 */
const handleAdd = () => { const handleAdd = () => {
form.prdTagId && reset(); visible.value = true;
open.value = true; nextTick(() => {
title.value = "添加商品-标签详情"; form.value.prdTagId && reset();
title.value = "添加商品-标签详情";
})
} }
/** 提交按钮 */ /** 提交按钮 */
const submitForm = () => { const submitForm = () => {
formRef.value.validate(valid => { proxy.$refs.formRef.validate(valid => {
if (valid) { if (valid) {
// 数据结构要处理成后端需要的 // 数据结构要处理成后端需要的
const uploadData = { const uploadData = {
...@@ -273,14 +256,14 @@ const submitForm = () => { ...@@ -273,14 +256,14 @@ const submitForm = () => {
deleteSeriesGoodsTagAPI(form.value.prdTagId).then(response => { deleteSeriesGoodsTagAPI(form.value.prdTagId).then(response => {
createSeriesGoodsTagAPI(uploadData).then(response => { createSeriesGoodsTagAPI(uploadData).then(response => {
proxy.$modal.msgSuccess("修改成功"); proxy.$modal.msgSuccess("修改成功");
open.value = false; visible.value = false;
getSeriesGoodsTagList(); getSeriesGoodsTagList();
}); });
}); });
} else { } else {
createSeriesGoodsTagAPI(uploadData).then(response => { createSeriesGoodsTagAPI(uploadData).then(response => {
proxy.$modal.msgSuccess("新增成功"); proxy.$modal.msgSuccess("新增成功");
open.value = false; visible.value = false;
getSeriesGoodsTagList(); getSeriesGoodsTagList();
reset(); reset();
}); });
...@@ -288,9 +271,6 @@ const submitForm = () => { ...@@ -288,9 +271,6 @@ const submitForm = () => {
} }
}); });
} }
getSeriesList();
getSeriesGoodsTagList()
</script> </script>
<style scoped <style scoped
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论