3636 </div >
3737 </div >
3838 </el-form-item >
39- <!-- TODO 疯狂:要不把 productSpuIds 改成 productScopeValues,更通用?另外,改完后,涉及到优惠劵的匹配逻辑,要补充分类相关的逻辑,例如说获得匹配的优惠劵列表之类的,包括使用卷的时候; -->
4039 <el-form-item
4140 label =" 分类"
4241 v-if =" formData.productScope === PromotionProductScopeEnum.CATEGORY.scope"
153152 <el-date-picker
154153 v-model =" formData.validTimes"
155154 style =" width : 240px "
156- value-format =" YYYY-MM-DD HH:mm:ss "
155+ value-format =" x "
157156 type =" datetimerange"
158157 :default-time =" [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]"
159158 />
@@ -228,8 +227,9 @@ const formData = ref({
228227 fixedStartTerm: undefined ,
229228 fixedEndTerm: undefined ,
230229 productScope: PromotionProductScopeEnum .ALL .scope ,
231- productSpuIds: [],
232- productCategoryIds: []
230+ productScopeValues: [], // 商品范围:值为 品类编号列表 或 商品编号列表 ,用于提交
231+ productCategoryIds: [], // 仅用于表单,不提交
232+ productSpuIds: [] // 仅用于表单,不提交
233233})
234234const formRules = reactive ({
235235 name: [{ required: true , message: ' 优惠券名称不能为空' , trigger: ' blur' }],
@@ -246,8 +246,8 @@ const formRules = reactive({
246246 fixedStartTerm: [{ required: true , message: ' 开始领取天数不能为空' , trigger: ' blur' }],
247247 fixedEndTerm: [{ required: true , message: ' 开始领取天数不能为空' , trigger: ' blur' }],
248248 productScope: [{ required: true , message: ' 商品范围不能为空' , trigger: ' blur' }],
249- productSpuIds: [{ required: true , message: ' 商品范围不能为空 ' , trigger: ' blur' }],
250- productCategoryIds: [{ required: true , message: ' 分类范围不能为空 ' , trigger: ' blur' }]
249+ productSpuIds: [{ required: true , message: ' 商品不能为空 ' , trigger: ' blur' }],
250+ productCategoryIds: [{ required: true , message: ' 分类不能为空 ' , trigger: ' blur' }]
251251})
252252const formRef = ref () // 表单 Ref
253253const productSpus = ref <ProductSpuApi .Spu []>([]) // 商品列表
@@ -313,12 +313,10 @@ const submitForm = async () => {
313313 formData .value .validTimes && formData .value .validTimes .length === 2
314314 ? formData .value .validTimes [1 ]
315315 : undefined
316- } as CouponTemplateApi .CouponTemplateVO
316+ } as unknown as CouponTemplateApi .CouponTemplateVO
317317
318- if (formData .value .productCategoryIds ?.length > 0 ) {
319- // 改个名字?加个字段?
320- data .productSpuIds = formData .value .productCategoryIds
321- }
318+ // 设置商品范围
319+ setProductScopeValues (data )
322320
323321 if (formType .value === ' create' ) {
324322 await CouponTemplateApi .createCouponTemplate (data )
@@ -355,6 +353,7 @@ const resetForm = () => {
355353 fixedStartTerm: undefined ,
356354 fixedEndTerm: undefined ,
357355 productScope: PromotionProductScopeEnum .ALL .scope ,
356+ productScopeValues: [],
358357 productSpuIds: [],
359358 productCategoryIds: []
360359 }
@@ -366,13 +365,36 @@ const resetForm = () => {
366365const getProductScope = async () => {
367366 switch (formData .value .productScope ) {
368367 case PromotionProductScopeEnum .SPU .scope :
368+ // 设置商品编号
369+ formData .value .productSpuIds = formData .value .productScopeValues
369370 // 获得商品列表
370- productSpus .value = await ProductSpuApi .getSpuDetailList (formData .value .productSpuIds )
371+ productSpus .value = await ProductSpuApi .getSpuDetailList (formData .value .productScopeValues )
372+ break
373+ case PromotionProductScopeEnum .CATEGORY .scope :
374+ await nextTick (() => {
375+ let productCategoryIds = formData .value .productScopeValues
376+ if (Array .isArray (productCategoryIds ) && productCategoryIds .length > 0 ) {
377+ // 单选时使用数组不能反显
378+ productCategoryIds = productCategoryIds [0 ]
379+ }
380+ // 设置品类编号
381+ formData .value .productCategoryIds = productCategoryIds
382+ })
383+ break
384+ default :
385+ break
386+ }
387+ }
388+ /** 设置商品范围 */
389+ function setProductScopeValues(data : CouponTemplateApi .CouponTemplateVO ) {
390+ switch (formData .value .productScope ) {
391+ case PromotionProductScopeEnum .SPU .scope :
392+ data .productScopeValues = formData .value .productSpuIds
371393 break
372394 case PromotionProductScopeEnum .CATEGORY .scope :
373- // TODO @疯狂:貌似分类不会选中。
374- formData . value . productCategoryIds = formData .value .productSpuIds
375- formData .value .productSpuIds = [ ]
395+ data . productScopeValues = Array . isArray ( formData . value . productCategoryIds )
396+ ? formData .value .productCategoryIds
397+ : [ formData .value .productCategoryIds ]
376398 break
377399 default :
378400 break
0 commit comments