From 404bb00dbfa2b0647ef0c725c3848a81776d68f3 Mon Sep 17 00:00:00 2001 From: owen Date: Wed, 30 Aug 2023 11:50:21 +0800 Subject: [PATCH] =?UTF-8?q?mall=EF=BC=9A=E4=BC=98=E6=83=A0=E5=88=B8=20?= =?UTF-8?q?=E5=95=86=E5=93=81=E9=80=89=E6=8B=A9=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 60d2e3114b4e6d41e0790c06ad02f93ce5f9eec9) --- .../product/spu/components/SpuTableSelect.vue | 270 ++++++++++++------ .../coupon/template/CouponTemplateForm.vue | 102 +++++-- 2 files changed, 253 insertions(+), 119 deletions(-) diff --git a/src/views/mall/product/spu/components/SpuTableSelect.vue b/src/views/mall/product/spu/components/SpuTableSelect.vue index f8560aa3..d7d15439 100644 --- a/src/views/mall/product/spu/components/SpuTableSelect.vue +++ b/src/views/mall/product/spu/components/SpuTableSelect.vue @@ -1,81 +1,103 @@ @@ -85,12 +107,19 @@ import { defaultProps, handleTree } from '@/utils/tree' import * as ProductCategoryApi from '@/api/mall/product/category' import * as ProductSpuApi from '@/api/mall/product/spu' +import { propTypes } from '@/utils/propTypes' + +type Spu = Required defineOptions({ name: 'SpuTableSelect' }) -const message = useMessage() // 消息弹窗 +const props = defineProps({ + // 多选 + multiple: propTypes.bool.def(false) +}) + const total = ref(0) // 列表的总页数 -const list = ref([]) // 列表的数据 +const list = ref([]) // 列表的数据 const loading = ref(false) // 列表的加载中 const dialogVisible = ref(false) // 弹窗的是否展示 const queryParams = ref({ @@ -101,26 +130,24 @@ const queryParams = ref({ categoryId: null, createTime: [] }) // 查询参数 -const spuListRef = ref>() const selectedSpuId = ref() // 选中的商品 spuId -/** 选中时触发 */ -const handleSelected = (row: ProductSpuApi.Spu) => { - emits('change', row) - // 关闭弹窗 - dialogVisible.value = false - selectedSpuId.value = undefined -} - -// 确认选择时的触发事件 -const emits = defineEmits<{ - (e: 'change', spu: ProductSpuApi.Spu): void -}>() - /** 打开弹窗 */ -const open = () => { +const open = (spus?: Spu[]) => { + if (spus && spus.length > 0) { + // todo check-box不显示选中? + checkedSpus.value = [...spus] + checkedSpuIds.value = spus.map((spu) => spu.id) + } else { + checkedSpus.value = [] + checkedSpuIds.value = [] + } + allChecked.value = false + checkedPageNos.value = [] + dialogVisible.value = true + resetQuery() } defineExpose({ open }) // 提供 open 方法,用于打开弹窗 @@ -138,6 +165,7 @@ const getList = async () => { /** 搜索按钮操作 */ const handleQuery = () => { + queryParams.value.pageNo = 1 getList() } @@ -154,9 +182,65 @@ const resetQuery = () => { getList() } +const allChecked = ref(false) //是否全选 +const checkedPageNos = ref([]) //选中的页码 +const checkedSpuIds = ref([]) //选中的商品ID +const checkedSpus = ref([]) //选中的商品 + +/** 单选中时触发 */ +const handleSingleSelected = (row: Spu) => { + emits('change', row) + // 关闭弹窗 + dialogVisible.value = false + // 记住上次选择的ID + selectedSpuId.value = row.id +} + +/** 多选完成 */ +const handleEmitChange = () => { + // 关闭弹窗 + dialogVisible.value = false + emits('change', [...checkedSpus.value]) +} + +/** 确认选择时的触发事件 */ +const emits = defineEmits<{ + (e: 'change', spu: Spu | Spu[] | any): void +}>() + +/** 全选 */ +const handleCheckAll = (checked: boolean) => { + //todo 不触发? + console.log('checkAll', checked) + allChecked.value = checked + const index = checkedPageNos.value.indexOf(queryParams.value.pageNo) + checkedPageNos.value.push(queryParams.value.pageNo) + if (index > -1) { + checkedPageNos.value.splice(index, 1) + } + + list.value.forEach((item) => handleCheckOne(checked, item)) +} + +/** 选中一行 */ +const handleCheckOne = (checked: boolean, spu: Spu) => { + if (checked) { + const index = checkedSpuIds.value.indexOf(spu.id) + if (index === -1) { + checkedSpuIds.value.push(spu.id) + checkedSpus.value.push(spu) + } + } else { + const index = checkedSpuIds.value.indexOf(spu.id) + if (index > -1) { + checkedSpuIds.value.splice(index, 1) + checkedSpus.value.splice(index, 1) + } + } +} + const categoryList = ref() // 分类列表 const categoryTreeList = ref() // 分类树 - /** 初始化 **/ onMounted(async () => { await getList() diff --git a/src/views/mall/promotion/coupon/template/CouponTemplateForm.vue b/src/views/mall/promotion/coupon/template/CouponTemplateForm.vue index e0173c00..69132fbb 100644 --- a/src/views/mall/promotion/coupon/template/CouponTemplateForm.vue +++ b/src/views/mall/promotion/coupon/template/CouponTemplateForm.vue @@ -29,7 +29,7 @@ @@ -43,7 +43,7 @@ @@ -68,7 +68,7 @@ @@ -84,7 +84,7 @@ @@ -94,7 +94,7 @@ @@ -133,7 +133,7 @@ @@ -141,7 +141,7 @@ @@ -162,21 +162,15 @@ v-if="formData.productScope === PromotionProductScopeEnum.SPU.scope" prop="productSpuIds" > - - - {{ item.name }} - - ¥{{ (item.minPrice / 100.0).toFixed(2) }} - - - +
+
+ + +
+
+ +
+
+ + +