【代码优化】代码格式化
parent
40fe63a3fb
commit
4870231b61
|
@ -3,7 +3,7 @@ import {ComponentStyle, DiyComponent} from '@/components/DiyEditor/util'
|
||||||
/** 拼团属性 */
|
/** 拼团属性 */
|
||||||
export interface PromotionCombinationProperty {
|
export interface PromotionCombinationProperty {
|
||||||
// 布局类型:单列 | 三列
|
// 布局类型:单列 | 三列
|
||||||
layoutType: 'oneColBigImg' | 'oneColSmallImg' | 'twoCol';
|
layoutType: 'oneColBigImg' | 'oneColSmallImg' | 'twoCol'
|
||||||
// 商品字段
|
// 商品字段
|
||||||
fields: {
|
fields: {
|
||||||
// 商品名称
|
// 商品名称
|
||||||
|
|
|
@ -118,64 +118,67 @@
|
||||||
import { PromotionCombinationProperty } from './config'
|
import { PromotionCombinationProperty } from './config'
|
||||||
import * as ProductSpuApi from '@/api/mall/product/spu'
|
import * as ProductSpuApi from '@/api/mall/product/spu'
|
||||||
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
|
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
|
||||||
import {fenToYuan} from "@/utils";
|
import { fenToYuan } from '@/utils'
|
||||||
|
|
||||||
/** 拼团卡片 */
|
/** 拼团卡片 */
|
||||||
defineOptions({ name: 'PromotionCombination' })
|
defineOptions({ name: 'PromotionCombination' })
|
||||||
// 定义属性
|
// 定义属性
|
||||||
const props = defineProps<{ property: PromotionCombinationProperty }>();
|
const props = defineProps<{ property: PromotionCombinationProperty }>()
|
||||||
// 商品列表
|
// 商品列表
|
||||||
const spuList = ref<ProductSpuApi.Spu[]>([]);
|
const spuList = ref<ProductSpuApi.Spu[]>([])
|
||||||
const spuIdList = ref<number[]>([]);
|
const spuIdList = ref<number[]>([])
|
||||||
const combinationActivityList = ref<CombinationActivityApi.CombinationActivityVO[]>([]);
|
const combinationActivityList = ref<CombinationActivityApi.CombinationActivityVO[]>([])
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.property.activityIds,
|
() => props.property.activityIds,
|
||||||
async () => {
|
async () => {
|
||||||
try {
|
try {
|
||||||
// 新添加的拼团组件,是没有活动ID的
|
// 新添加的拼团组件,是没有活动ID的
|
||||||
const activityIds = props.property.activityIds;
|
const activityIds = props.property.activityIds
|
||||||
// 检查活动ID的有效性
|
// 检查活动ID的有效性
|
||||||
if (Array.isArray(activityIds) && activityIds.length > 0 && activityIds.every(item => item != null)) {
|
if (
|
||||||
|
Array.isArray(activityIds) &&
|
||||||
|
activityIds.length > 0 &&
|
||||||
|
activityIds.every((item) => item != null)
|
||||||
|
) {
|
||||||
// 获取拼团活动详情列表
|
// 获取拼团活动详情列表
|
||||||
combinationActivityList.value = await CombinationActivityApi.getCombinationActivityDetailList(activityIds);
|
combinationActivityList.value =
|
||||||
|
await CombinationActivityApi.getCombinationActivityDetailList(activityIds)
|
||||||
|
|
||||||
// 清空之前的数据,防止有重复
|
// 清空之前的数据,防止有重复
|
||||||
spuIdList.value = [];
|
spuIdList.value = []
|
||||||
spuList.value = [];
|
spuList.value = []
|
||||||
|
|
||||||
// 生成有效的 spuId 列表
|
// 生成有效的 spuId 列表
|
||||||
spuIdList.value = combinationActivityList.value
|
spuIdList.value = combinationActivityList.value
|
||||||
.map(activity => activity.spuId)
|
.map((activity) => activity.spuId)
|
||||||
.filter((spuId): spuId is number => typeof spuId === 'number');
|
.filter((spuId): spuId is number => typeof spuId === 'number')
|
||||||
|
|
||||||
// 如果存在有效的 spuId,调用 API 获取详细信息
|
// 如果存在有效的 spuId,调用 API 获取详细信息
|
||||||
if (spuIdList.value.length > 0) {
|
if (spuIdList.value.length > 0) {
|
||||||
spuList.value = await ProductSpuApi.getSpuDetailList(spuIdList.value);
|
spuList.value = await ProductSpuApi.getSpuDetailList(spuIdList.value)
|
||||||
} else {
|
} else {
|
||||||
console.warn('没有用于获取详细信息的有效 spuId。');
|
console.warn('没有用于获取详细信息的有效 spuId。')
|
||||||
}
|
}
|
||||||
// 更新 SPU 的最低价格
|
// 更新 SPU 的最低价格
|
||||||
combinationActivityList.value.forEach(activity => {
|
combinationActivityList.value.forEach((activity) => {
|
||||||
activity.products.forEach(product => {
|
activity.products.forEach((product) => {
|
||||||
const spu = spuList.value.find(spu => spu.id === product.spuId);
|
const spu = spuList.value.find((spu) => spu.id === product.spuId)
|
||||||
if (spu) {
|
if (spu) {
|
||||||
spu.price = Math.min(product.combinationPrice || Infinity, spu.price || Infinity);
|
spu.price = Math.min(product.combinationPrice || Infinity, spu.price || Infinity)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取拼团活动细节或 SPU 细节时出错:', error);
|
console.error('获取拼团活动细节或 SPU 细节时出错:', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
immediate: true,
|
immediate: true,
|
||||||
deep: true
|
deep: true
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算商品的间距
|
* 计算商品的间距
|
||||||
|
|
|
@ -143,7 +143,7 @@ import {PromotionCombinationProperty} from './config'
|
||||||
import { usePropertyForm } from '@/components/DiyEditor/util'
|
import { usePropertyForm } from '@/components/DiyEditor/util'
|
||||||
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
|
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
|
||||||
import { CommonStatusEnum } from '@/utils/constants'
|
import { CommonStatusEnum } from '@/utils/constants'
|
||||||
import CombinationShowcase from "@/views/mall/promotion/combination/components/CombinationShowcase.vue";
|
import CombinationShowcase from '@/views/mall/promotion/combination/components/CombinationShowcase.vue'
|
||||||
|
|
||||||
// 拼团属性面板
|
// 拼团属性面板
|
||||||
defineOptions({ name: 'PromotionCombinationProperty' })
|
defineOptions({ name: 'PromotionCombinationProperty' })
|
||||||
|
@ -158,7 +158,7 @@ onMounted(async () => {
|
||||||
status: CommonStatusEnum.ENABLE
|
status: CommonStatusEnum.ENABLE
|
||||||
})
|
})
|
||||||
activityList.value = list
|
activityList.value = list
|
||||||
console.log("formDa", props);
|
console.log('formDa', props)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,11 @@
|
||||||
>
|
>
|
||||||
<!--这里的 key 使用时间戳是为了保证每次点击组件都进行刷新-->
|
<!--这里的 key 使用时间戳是为了保证每次点击组件都进行刷新-->
|
||||||
<component
|
<component
|
||||||
:key="selectedComponent?.uid || selectedComponent?.id + new Date().getTime() || new Date().getTime().toString()"
|
:key="
|
||||||
|
selectedComponent?.uid ||
|
||||||
|
selectedComponent?.id + new Date().getTime() ||
|
||||||
|
new Date().getTime().toString()
|
||||||
|
"
|
||||||
:is="selectedComponent?.id + 'Property'"
|
:is="selectedComponent?.id + 'Property'"
|
||||||
v-model="selectedComponent.property"
|
v-model="selectedComponent.property"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
<div
|
<div
|
||||||
v-for="(combinationActivity, index) in Activitys"
|
v-for="(combinationActivity, index) in Activitys"
|
||||||
:key="combinationActivity.id"
|
:key="combinationActivity.id"
|
||||||
class="select-box spu-pic">
|
class="select-box spu-pic"
|
||||||
|
>
|
||||||
<el-tooltip :content="combinationActivity.name">
|
<el-tooltip :content="combinationActivity.name">
|
||||||
<div class="relative h-full w-full">
|
<div class="relative h-full w-full">
|
||||||
<el-image :src="combinationActivity.picUrl" class="h-full w-full" />
|
<el-image :src="combinationActivity.picUrl" class="h-full w-full" />
|
||||||
|
@ -23,15 +24,18 @@
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</div>
|
</div>
|
||||||
<!-- 拼团活动选择对话框(表格形式) -->
|
<!-- 拼团活动选择对话框(表格形式) -->
|
||||||
<CombinationTableSelect ref="combinationActivityTableSelectRef" :multiple="limit != 1"
|
<CombinationTableSelect
|
||||||
@change="handleActivitySelected"/>
|
ref="combinationActivityTableSelectRef"
|
||||||
|
:multiple="limit != 1"
|
||||||
|
@change="handleActivitySelected"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
|
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
|
||||||
import { propTypes } from '@/utils/propTypes'
|
import { propTypes } from '@/utils/propTypes'
|
||||||
import { oneOfType } from 'vue-types'
|
import { oneOfType } from 'vue-types'
|
||||||
import { isArray } from '@/utils/is'
|
import { isArray } from '@/utils/is'
|
||||||
import CombinationTableSelect from "@/views/mall/promotion/combination/components/CombinationTableSelect.vue";
|
import CombinationTableSelect from '@/views/mall/promotion/combination/components/CombinationTableSelect.vue'
|
||||||
|
|
||||||
// 活动橱窗,一般用于装修时使用
|
// 活动橱窗,一般用于装修时使用
|
||||||
// 提供功能:展示活动列表、添加活动、删除活动
|
// 提供功能:展示活动列表、添加活动、删除活动
|
||||||
|
@ -73,7 +77,10 @@ watch(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 只有活动发生变化之后,才会查询活动
|
// 只有活动发生变化之后,才会查询活动
|
||||||
if (Activitys.value.length === 0 || Activitys.value.some((combinationActivity) => !ids.includes(combinationActivity.id!))) {
|
if (
|
||||||
|
Activitys.value.length === 0 ||
|
||||||
|
Activitys.value.some((combinationActivity) => !ids.includes(combinationActivity.id!))
|
||||||
|
) {
|
||||||
Activitys.value = await CombinationActivityApi.getCombinationActivityDetailList(ids)
|
Activitys.value = await CombinationActivityApi.getCombinationActivityDetailList(ids)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -91,7 +98,11 @@ const openCombinationActivityTableSelect = () => {
|
||||||
* 选择活动后触发
|
* 选择活动后触发
|
||||||
* @param activityVOs 选中的活动列表
|
* @param activityVOs 选中的活动列表
|
||||||
*/
|
*/
|
||||||
const handleActivitySelected = (activityVOs: CombinationActivityApi.CombinationActivityVO | CombinationActivityApi.CombinationActivityVO[]) => {
|
const handleActivitySelected = (
|
||||||
|
activityVOs:
|
||||||
|
| CombinationActivityApi.CombinationActivityVO
|
||||||
|
| CombinationActivityApi.CombinationActivityVO[]
|
||||||
|
) => {
|
||||||
Activitys.value = isArray(activityVOs) ? activityVOs : [activityVOs]
|
Activitys.value = isArray(activityVOs) ? activityVOs : [activityVOs]
|
||||||
emitActivityChange()
|
emitActivityChange()
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,11 @@
|
||||||
<!-- 2. 单选模式 -->
|
<!-- 2. 单选模式 -->
|
||||||
<el-table-column label="#" width="55" v-else>
|
<el-table-column label="#" width="55" v-else>
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-radio :value="row.id" v-model="selectedActivityId" @change="handleSingleSelected(row)">
|
<el-radio
|
||||||
|
:value="row.id"
|
||||||
|
v-model="selectedActivityId"
|
||||||
|
@change="handleSingleSelected(row)"
|
||||||
|
>
|
||||||
<!-- 空格不能省略,是为了让单选框不显示label,如果不指定label不会有选中的效果 -->
|
<!-- 空格不能省略,是为了让单选框不显示label,如果不指定label不会有选中的效果 -->
|
||||||
|
|
||||||
</el-radio>
|
</el-radio>
|
||||||
|
@ -137,11 +141,11 @@ import {handleTree} from '@/utils/tree'
|
||||||
import * as ProductCategoryApi from '@/api/mall/product/category'
|
import * as ProductCategoryApi from '@/api/mall/product/category'
|
||||||
import { propTypes } from '@/utils/propTypes'
|
import { propTypes } from '@/utils/propTypes'
|
||||||
import { CHANGE_EVENT } from 'element-plus'
|
import { CHANGE_EVENT } from 'element-plus'
|
||||||
import * as CombinationActivityApi from "@/api/mall/promotion/combination/combinationActivity";
|
import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationActivity'
|
||||||
import {fenToYuanFormat} from "@/utils/formatter";
|
import { fenToYuanFormat } from '@/utils/formatter'
|
||||||
import {DICT_TYPE, getIntDictOptions} from "@/utils/dict";
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||||
import {dateFormatter, formatDate} from "@/utils/formatTime";
|
import { dateFormatter, formatDate } from '@/utils/formatTime'
|
||||||
import {fenToYuan} from "@/utils";
|
import { fenToYuan } from '@/utils'
|
||||||
|
|
||||||
type CombinationActivityVO = Required<CombinationActivityApi.CombinationActivityVO>
|
type CombinationActivityVO = Required<CombinationActivityApi.CombinationActivityVO>
|
||||||
|
|
||||||
|
@ -190,7 +194,9 @@ const open = (CombinationList?: CombinationActivityVO[]) => {
|
||||||
// 处理已选中
|
// 处理已选中
|
||||||
if (CombinationList && CombinationList.length > 0) {
|
if (CombinationList && CombinationList.length > 0) {
|
||||||
checkedActivitys.value = [...CombinationList]
|
checkedActivitys.value = [...CombinationList]
|
||||||
checkedStatus.value = Object.fromEntries(CombinationList.map((activityVO) => [activityVO.id, true]))
|
checkedStatus.value = Object.fromEntries(
|
||||||
|
CombinationList.map((activityVO) => [activityVO.id, true])
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
|
@ -208,7 +214,8 @@ const getList = async () => {
|
||||||
total.value = data.total
|
total.value = data.total
|
||||||
// checkbox绑定undefined会有问题,需要给一个bool值
|
// checkbox绑定undefined会有问题,需要给一个bool值
|
||||||
list.value.forEach(
|
list.value.forEach(
|
||||||
(activityVO) => (checkedStatus.value[activityVO.id] = checkedStatus.value[activityVO.id] || false)
|
(activityVO) =>
|
||||||
|
(checkedStatus.value[activityVO.id] = checkedStatus.value[activityVO.id] || false)
|
||||||
)
|
)
|
||||||
// 计算全选框状态
|
// 计算全选框状态
|
||||||
calculateIsCheckAll()
|
calculateIsCheckAll()
|
||||||
|
@ -289,7 +296,11 @@ const handleCheckAll = (checked: boolean) => {
|
||||||
* @param combinationActivity 活动
|
* @param combinationActivity 活动
|
||||||
* @param isCalcCheckAll 是否计算全选
|
* @param isCalcCheckAll 是否计算全选
|
||||||
*/
|
*/
|
||||||
const handleCheckOne = (checked: boolean, combinationActivity: CombinationActivityVO, isCalcCheckAll: boolean) => {
|
const handleCheckOne = (
|
||||||
|
checked: boolean,
|
||||||
|
combinationActivity: CombinationActivityVO,
|
||||||
|
isCalcCheckAll: boolean
|
||||||
|
) => {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
checkedActivitys.value.push(combinationActivity)
|
checkedActivitys.value.push(combinationActivity)
|
||||||
checkedStatus.value[combinationActivity.id] = true
|
checkedStatus.value[combinationActivity.id] = true
|
||||||
|
@ -309,13 +320,15 @@ const handleCheckOne = (checked: boolean, combinationActivity: CombinationActivi
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找活动在已选中活动列表中的索引
|
// 查找活动在已选中活动列表中的索引
|
||||||
const findCheckedIndex = (activityVO: CombinationActivityVO) => checkedActivitys.value.findIndex((item) => item.id === activityVO.id)
|
const findCheckedIndex = (activityVO: CombinationActivityVO) =>
|
||||||
|
checkedActivitys.value.findIndex((item) => item.id === activityVO.id)
|
||||||
|
|
||||||
// 计算全选框状态
|
// 计算全选框状态
|
||||||
const calculateIsCheckAll = () => {
|
const calculateIsCheckAll = () => {
|
||||||
isCheckAll.value = list.value.every((activityVO) => checkedStatus.value[activityVO.id])
|
isCheckAll.value = list.value.every((activityVO) => checkedStatus.value[activityVO.id])
|
||||||
// 计算中间状态:不是全部选中 && 任意一个选中
|
// 计算中间状态:不是全部选中 && 任意一个选中
|
||||||
isIndeterminate.value = !isCheckAll.value && list.value.some((activityVO) => checkedStatus.value[activityVO.id])
|
isIndeterminate.value =
|
||||||
|
!isCheckAll.value && list.value.some((activityVO) => checkedStatus.value[activityVO.id])
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分类列表
|
// 分类列表
|
||||||
|
|
Loading…
Reference in New Issue