@ -3,90 +3,38 @@
< div @click ="show" >
< slot >
< el -button > { { t ( 'goodsSelectPopupSelectGoodsButton' ) } } < / e l - b u t t o n >
< div
class = "inline-block ml-[10px] text-[14px]"
v - show = "goodsIds.length"
>
< div class = "inline-block ml-[10px] text-[14px]" v-show ="goodsIds.length" >
< span > { { t ( 'goodsSelectPopupSelect' ) } } < / span >
< span class = "text-primary mx-[2px]" > { { goodsIds . length } } < / span >
< span > { { t ( 'goodsSelectPopupPiece' ) } } < / span >
< / div >
< / slot >
< / div >
< el -dialog
v - model = "showDialog"
: title = "t('goodsSelectPopupSelectGoodsDialog')"
width = "1000px"
: close - on - press - escape = "false"
: destroy - on - close = "true"
: close - on - click - modal = "false"
>
< el -form
: inline = "true"
: model = "goodsTable.searchParam"
ref = "searchFormRef"
>
< el -dialog v-model ="showDialog" :title="t('goodsSelectPopupSelectGoodsDialog')" width="1000px" :close-on-press-escape="false" :destroy-on-close="true" :close-on-click-modal="false" >
< el -form :inline ="true" :model ="goodsTable.searchParam" ref = "searchFormRef" >
< el -form -item prop = "select_type" class = "form-item-wrap" >
< el -select
v - model = "goodsTable.searchParam.select_type"
@ change = "handleSelectTypeChange"
>
< el -select v-model ="goodsTable.searchParam.select_type" @change="handleSelectTypeChange" >
< el -option :label ="t('goodsSelectPopupAllGoods')" value = "all" / >
< el -option
: label = "t('goodsSelectPopupSelectedGoods')"
value = "selected"
/ >
< el -option :label ="t('goodsSelectPopupSelectedGoods')" value = "selected" / >
< / e l - s e l e c t >
< / e l - f o r m - i t e m >
< el -form -item
: label = "t('goodsSelectPopupGoodsName')"
prop = "keyword"
class = "form-item-wrap"
>
< el -input
v - model . trim = "goodsTable.searchParam.keyword"
: placeholder = "t('goodsSelectPopupGoodsNamePlaceholder')"
maxlength = "60"
/ >
< el -form -item :label ="t('goodsSelectPopupGoodsName')" prop = "keyword" class = "form-item-wrap" >
< el -input v -model .trim = " goodsTable.searchParam.keyword " :placeholder ="t('goodsSelectPopupGoodsNamePlaceholder')" maxlength = "60" / >
< / e l - f o r m - i t e m >
< el -form -item
: label = "t('goodsSelectPopupGoodsCategory')"
prop = "goods_category"
class = "form-item-wrap"
>
< el -cascader
v - model = "goodsTable.searchParam.goods_category"
: options = "goodsCategoryOptions"
: placeholder = "t('goodsSelectPopupGoodsCategoryPlaceholder')"
clearable
: props = "{ value: 'value', label: 'label', emitPath: false }"
/ >
< el -form -item :label ="t('goodsSelectPopupGoodsCategory')" prop = "goods_category" class = "form-item-wrap" >
< el -cascader v -model = " goodsTable.searchParam.goods_category "
: options = "goodsCategoryOptions" : placeholder = "t('goodsSelectPopupGoodsCategoryPlaceholder')"
clearable : props = "{ value: 'value', label: 'label', emitPath:false }" / >
< / e l - f o r m - i t e m >
< el -form -item
: label = "t('goodsSelectPopupGoodsType')"
prop = "goods_type"
class = "form-item-wrap"
>
< el -select
v - model = "goodsTable.searchParam.goods_type"
: placeholder = "t('goodsSelectPopupGoodsTypePlaceholder')"
clearable
>
< el -option
v - for = "item in goodsType"
: key = "item.type"
: label = "item.name"
: value = "item.type"
/ >
< el -form -item :label ="t('goodsSelectPopupGoodsType')" prop = "goods_type" class = "form-item-wrap" >
< el -select v -model = " goodsTable.searchParam.goods_type " :placeholder ="t('goodsSelectPopupGoodsTypePlaceholder')" clearable >
< el -option v -for = " item in goodsType " :key ="item.type" :label ="item.name" :value ="item.type" / >
< / e l - s e l e c t >
< / e l - f o r m - i t e m >
< el -form -item class = "form-item-wrap" >
< el -button type = "primary" @click ="loadGoodsList()" > {{
t ( 'search' )
} } < / e l - b u t t o n >
< el -button @click ="resetForm(searchFormRef)" > {{
t ( 'reset' )
} } < / e l - b u t t o n >
< el -button type = "primary" @click ="loadGoodsList()" > {{ t ( ' search ' ) }} < / el -button >
< el -button @click ="resetForm(searchFormRef)" > {{ t ( ' reset ' ) }} < / el -button >
< / e l - f o r m - i t e m >
< / e l - f o r m >
@ -94,87 +42,37 @@
< div class = "table-head flex items-center bg-[#f5f7f9] py-[8px]" >
< div class = "w-[3%]" > < / div >
< div class = "w-[7%]" >
< el -checkbox
v - model = "staircheckAll"
: indeterminate = "isStairIndeterminate"
@ change = "handleCheckAllChange"
/ >
< el -checkbox v -model = " staircheckAll " :indeterminate ="isStairIndeterminate" @change ="handleCheckAllChange" / >
< / div >
< div class = "w-[50%]" > 商品信息 < / div >
< div class = "w-[20%]" > 商品价格 < / div >
< div class = "w-[20%]" > 库存 < / div >
< / div >
< div class = "table-body h-[350px] overflow-y-auto" >
< div
v - for = "(row, rowIndex) in goodsTable.data"
: key = "rowIndex"
class = "flex flex-col"
>
< div v-for ="(row,rowIndex) in goodsTable.data" :key="rowIndex" class="flex flex-col" >
<!-- 内容 -- >
< div
class = "flex items-center border-solid border-[#e5e7eb] py-[8px] border-b-[1px]"
>
< div class = "flex items-center border-solid border-[#e5e7eb] py-[8px] border-b-[1px]" >
< div v-if ="prop.mode == 'spu'" class="w-[3%]" > < / div >
< div
v - if = "prop.mode == 'sku' && row.skuList.length > 1"
class = "w-[3%] cursor-pointer text-center !text-[10px]"
@ click = "secondLevelArrowChange(row)"
: class = " {
'iconfont iconxiangyoujiantou' : row . skuList . length ,
'arrow-show' : row . isShow ,
} "
> < / div >
< div
v - if = "prop.mode == 'sku' && row.skuList.length <= 1"
class = "w-[3%]"
> < / div >
< div v-if ="prop.mode == 'sku' && row.skuList.length > 1" class="w-[3%] cursor-pointer text-center !text-[10px]" @click="secondLevelArrowChange(row)" :class="{'iconfont iconxiangyoujiantou': row.skuList.length, 'arrow-show': row.isShow}" > < / div >
< div v-if ="prop.mode == 'sku' && row.skuList.length <= 1" class="w-[3%]" > < / div >
< div class = "w-[7%]" >
< el -checkbox
v - model = "row.secondLevelCheckAll"
: indeterminate = "row.isSecondLevelIndeterminate"
@ change = "secondLevelHandleCheckAllChange($event, row)"
/ >
< el -checkbox v -model = " row.secondLevelCheckAll " :indeterminate ="row.isSecondLevelIndeterminate" @change ="secondLevelHandleCheckAllChange($event,row)" / >
< / div >
< div class = "flex items-center cursor-pointer w-[50%]" >
< div
class = "min-w-[60px] h-[60px] flex items-center justify-center"
>
< el -image
v - if = "row.goods_cover_thumb_small"
class = "w-[60px] h-[60px]"
: src = "img(row.goods_cover_thumb_small)"
fit = "contain"
>
< div class = "min-w-[60px] h-[60px] flex items-center justify-center" >
< el -image v-if ="row.goods_cover_thumb_small" class="w-[60px] h-[60px]" :src="img(row.goods_cover_thumb_small)" fit="contain" >
< template # error >
< div class = "image-slot" >
< img
class = "w-[60px] h-[60px]"
src = "@/addon/shop/assets/goods_default.png"
/ >
< img class = "w-[60px] h-[60px]" src = "@/addon/shop/assets/goods_default.png" / >
< / div >
< / template >
< / e l - i m a g e >
< img
v - else
class = "w-[60px] h-[60px]"
src = "@/addon/shop/assets/goods_default.png"
fit = "contain"
/ >
< img v -else class = "w-[60px] h-[60px]" src = "@/addon/shop/assets/goods_default.png" fit = "contain" / >
< / div >
< div class = "ml-2 flex flex-col items-start" >
< span
: title = "row.goods_name"
class = "multi-hidden leading-[1.4]"
> { { row . goods_name } } < / s p a n
>
< span class = "text-primary text-[12px]" > { {
row . goods_type_name
} } < / span >
< span
class = "px-[4px] text-[12px] text-[#fff] rounded-[4px] bg-primary leading-[18px]"
v - if = "row.is_gift == 1"
> 赠品 < / s p a n
>
< span :title ="row.goods_name" class = "multi-hidden leading-[1.4]" > { { row . goods_name } } < / span >
< span class = "text-primary text-[12px]" > { { row . goods_type_name } } < / span >
< span class = "px-[4px] text-[12px] text-[#fff] rounded-[4px] bg-primary leading-[18px]" v-if ="row.is_gift == 1" > 赠品 < / span >
< / div >
< / div >
< div class = "w-[20%]" > ¥ { { row . goodsSku . price } } < / div >
@ -183,57 +81,25 @@
< div v-show ="prop.mode == 'sku' && row.skuList.length > 1" >
<!-- 子级 -- >
< div
v - for = "(item, index) in row.skuList"
: key = "index"
class = "flex items-center py-[8px] border-solid border-transparent border-b-[1px]"
: class = " {
hidden : ! row . isShow ,
'border-[#e5e7eb]' : index == row . skuList . length - 1 ,
} "
>
< div v-for ="(item,index) in row.skuList" :key="index" class="flex items-center py-[8px] border-solid border-transparent border-b-[1px]" :class="{'hidden': !row.isShow, 'border-[#e5e7eb]': index == (row.skuList.length-1)}" >
< div class = "w-[6%]" > < / div >
< div class = "w-[4%]" >
< el -checkbox
v - model = "item.threeLevelCheckAll"
@ change = "subChildHandleCheckAllChange($event, row, item)"
/ >
< el -checkbox v -model = " item.threeLevelCheckAll " @change ="subChildHandleCheckAllChange($event,row,item)" / >
< / div >
< div class = "flex items-center cursor-pointer w-[50%]" >
< div
class = "min-w-[60px] h-[60px] flex items-center justify-center"
>
< el -image
v - if = "item.sku_image"
class = "w-[60px] h-[60px]"
: src = "img(item.sku_image)"
fit = "contain"
>
< div class = "min-w-[60px] h-[60px] flex items-center justify-center" >
< el -image v-if ="item.sku_image" class="w-[60px] h-[60px]" :src="img(item.sku_image)" fit="contain" >
< template # error >
< div class = "image-slot" >
< img
class = "w-[60px] h-[60px]"
src = "@/addon/shop/assets/goods_default.png"
/ >
< img class = "w-[60px] h-[60px]" src = "@/addon/shop/assets/goods_default.png" / >
< / div >
< / template >
< / e l - i m a g e >
< img
v - else
class = "w-[60px] h-[60px]"
src = "@/addon/shop/assets/goods_default.png"
fit = "contain"
/ >
< img v -else class = "w-[60px] h-[60px]" src = "@/addon/shop/assets/goods_default.png" fit = "contain" / >
< / div >
< div class = "ml-2" >
< span
: title = "item.sku_name || row.goods_name"
class = "multi-hidden leading-[1.4]"
> { { item . sku_name || row . goods_name } } < / s p a n
>
< span class = "text-primary text-[12px]" > { {
row . goods_type_name
} } < / span >
< span : title = "item.sku_name || row.goods_name" class = "multi-hidden leading-[1.4]" > { { item . sku_name || row . goods_name } } < / span >
< span class = "text-primary text-[12px]" > { { row . goods_type_name } } < / span >
< / div >
< / div >
< div class = "w-[20%] flex" > ¥ { { item . price } } < / div >
@ -242,10 +108,7 @@
< / div >
< / div >
< div
v - if = "!goodsTable.data.length && !goodsTable.loading"
class = "h-[60px] flex items-center justify-center border-solid border-[#e5e7eb] py-[12px] border-b-[1px]"
>
< div v-if ="!goodsTable.data.length && !goodsTable.loading" class="h-[60px] flex items-center justify-center border-solid border-[#e5e7eb] py-[12px] border-b-[1px]" >
暂无数据
< / div >
< / div >
@ -253,30 +116,16 @@
< div class = "mt-[16px] flex" >
< div class = "flex items-center flex-1" >
< div
class = "layui-table-bottom-left-container mr-[10px]"
v - show = "selectGoodsNum"
>
< div class = "layui-table-bottom-left-container mr-[10px]" v-show ="selectGoodsNum" >
< span > { { t ( 'goodsSelectPopupBeforeTip' ) } } < / span >
< span class = "text-primary mx-[2px]" > { { selectGoodsNum } } < / span >
< span > { { t ( 'goodsSelectPopupAfterTip' ) } } < / span >
< / div >
< el -button
type = "primary"
link
@ click = "clear"
v - show = "selectGoodsNum"
> { { t ( 'goodsSelectPopupClearGoods' ) } } < / e l - b u t t o n
>
< el -button type = "primary" link @click ="clear" v-show ="selectGoodsNum" > {{ t ( ' goodsSelectPopupClearGoods ' ) }} < / el -button >
< / div >
< el -pagination
v - model : current - page = "goodsTable.page"
v - model : page - size = "goodsTable.limit"
layout = "total, sizes, prev, pager, next, jumper"
: total = "goodsTable.total"
@ size - change = "loadGoodsList()"
@ current - change = "loadGoodsList"
/ >
< el -pagination v -model :current-page ="goodsTable.page" v -model :page-size ="goodsTable.limit"
layout = "total, sizes, prev, pager, next, jumper" : total = "goodsTable.total"
@ size - change = "loadGoodsList()" @ current - change = "loadGoodsList" / >
< / div >
< template # footer >
@ -295,47 +144,42 @@ import { ref, reactive, computed, nextTick } from 'vue'
import { cloneDeep } from 'lodash-es'
import { img , deepClone } from '@/utils/common'
import { ElMessage } from 'element-plus'
import {
getGoodsSelectPageList ,
getGoodsSkuNoPageList ,
getCategoryTree ,
getGoodsType ,
} from '@/addon/shop/api/goods'
import { getGoodsSelectPageList , getGoodsSkuNoPageList , getCategoryTree , getGoodsType } from '@/addon/shop/api/goods'
const prop = defineProps ( {
modelValue : {
type : String ,
default : '' ,
default : ''
} ,
max : {
type : Number ,
default : 0 ,
default : 0
} ,
min : {
type : Number ,
default : 0 ,
default : 0
} ,
mode : {
type : String ,
default : 'spu' , / / s p u : 按 商 品 , s k u : 按 多 规 格
default : 'spu' / / s p u : 按 商 品 , s k u : 按 多 规 格
} ,
way : {
type : String ,
default : '' , / / 选 择 方 式 , 空 : 代 表 全 部 , s i n g l e : 单 一
default : '' / / 选 择 方 式 , 空 : 代 表 全 部 , s i n g l e : 单 一
} ,
isGift : {
type : [ String , Number ] ,
default : 0 , / / 查 询 是 否 赠 品 , 0 : 不 查 赠 品 , 1 : 查 询 赠 品
default : 0 / / 查 询 是 否 赠 品 , 0 : 不 查 赠 品 , 1 : 查 询 赠 品
} ,
} )
const emit = defineEmits ( [ 'update:modelValue' , 'goodsSelect' ] )
/ / 通 过 p r o p . m o d e 来 决 定 数 据 前 缀 是 s k u _ 还 是 g o o d s _
let replacePrefix = prop . mode == 'sku' ? 'sku_' : 'goods_'
let replacePrefix = prop . mode == "sku" ? 'sku_' : 'goods_' ;
const isStairIndeterminate = ref ( false )
const staircheckAll = ref ( false )
const isStairIndeterminate = ref ( false ) ;
const staircheckAll = ref ( false ) ;
const goodsIds : any = computed ( {
get ( ) {
@ -343,7 +187,7 @@ const goodsIds: any = computed({
} ,
set ( value ) {
emit ( 'update:modelValue' , value )
} ,
}
} )
const showDialog = ref ( false )
@ -373,11 +217,11 @@ const goodsTable = reactive({
verify_goods_ids : '' ,
verify_sku_ids : '' ,
goods_type : '' ,
is_gift : 0 ,
} ,
is_gift : 0
}
} )
goodsTable . searchParam . is_gift = prop . isGift ? prop . isGift : 0
goodsTable . searchParam . is_gift = prop . isGift ? prop . isGift : 0 ;
const searchFormRef = ref ( )
@ -405,21 +249,17 @@ const initData = () => {
item . child_list . forEach ( ( childItem : any ) => {
children . push ( {
value : childItem . category_id ,
label : childItem . category_name ,
label : childItem . category_name
} )
} )
}
goodsCategoryTree . push ( {
value : item . category_id ,
label : item . category_name ,
children ,
children
} )
} )
goodsCategoryOptions . splice (
0 ,
goodsCategoryOptions . length ,
... goodsCategoryTree
)
goodsCategoryOptions . splice ( 0 , goodsCategoryOptions . length , ... goodsCategoryTree )
}
} )
@ -443,18 +283,18 @@ const multipleSelection: any = ref([])
/ / 箭 头 选 择 事 件
const secondLevelArrowChange = ( data ) => {
data . isShow = ! data . isShow
data . isShow = ! data . isShow ;
}
/ / 一 级 复 选 框
const handleCheckAllChange = ( isSelect ) => {
isStairIndeterminate . value = false
isStairIndeterminate . value = false ;
goodsTable . data . forEach ( ( item , index ) => {
item . secondLevelCheckAll = isSelect
item . secondLevelCheckAll = isSelect ;
item . skuList . forEach ( ( subItem , subIndex ) => {
subItem . threeLevelCheckAll = isSelect
} )
} )
subItem . threeLevelCheckAll = isSelect ;
} ) ;
} ) ;
if ( isSelect ) {
goodsTable . data . forEach ( ( item : any ) => {
if ( prop . mode == 'spu' ) {
@ -462,15 +302,13 @@ const handleCheckAllChange = (isSelect) => {
selectGoodsId . push ( item . goods_id )
} else {
item . skuList . forEach ( ( skuItem : any ) => {
selectGoodsId . push ( skuItem . sku_id )
selectGoods [ replacePrefix + skuItem . sku_id ] = deepClone ( skuItem )
selectGoods [ replacePrefix + skuItem . sku_id ] . goods_name =
item . goods_name / / 多 规 格 模 式 , 要 增 加 商 品 名 称 、 商 品 类 型 , 后 续 还 会 增 加 , 满 足 不 同 业 务 场 景
selectGoods [ replacePrefix + skuItem . sku_id ] . goods_type_name =
item . goods_type_name
selectGoods [ replacePrefix + skuItem . sku_id ] . goods_type =
item . goods_type
selectGoodsId . push ( skuItem . sku_id ) ;
selectGoods [ replacePrefix + skuItem . sku_id ] = deepClone ( skuItem ) ;
selectGoods [ replacePrefix + skuItem . sku_id ] . goods_name = item . goods_name ; / / 多 规 格 模 式 , 要 增 加 商 品 名 称 、 商 品 类 型 , 后 续 还 会 增 加 , 满 足 不 同 业 务 场 景
selectGoods [ replacePrefix + skuItem . sku_id ] . goods_type_name = item . goods_type_name ;
selectGoods [ replacePrefix + skuItem . sku_id ] . goods_type = item . goods_type ;
} )
}
} )
} else {
@ -491,10 +329,11 @@ const handleCheckAllChange = (isSelect) => {
/ / 二 级 复 选 框
const secondLevelHandleCheckAllChange = ( isSelect , row ) => {
row . skuList . forEach ( ( item , index ) => {
item . threeLevelCheckAll = isSelect
} )
detectionAllSelect ( )
item . threeLevelCheckAll = isSelect ;
} ) ;
detectionAllSelect ( ) ;
if ( prop . mode == 'spu' ) {
if ( isSelect ) {
selectGoodsId . push ( row . goods_id )
@ -507,19 +346,18 @@ const secondLevelHandleCheckAllChange = (isSelect, row) => {
} else {
if ( isSelect ) {
row . skuList . forEach ( ( item , index ) => {
selectGoodsId . push ( item . sku_id )
selectGoods [ replacePrefix + item . sku_id ] = deepClone ( item )
selectGoods [ replacePrefix + item . sku_id ] . goods_name = row . goods_name / / 多 规 格 模 式 , 要 增 加 商 品 名 称 、 商 品 类 型 , 后 续 还 会 增 加 , 满 足 不 同 业 务 场 景
selectGoods [ replacePrefix + item . sku_id ] . goods_type_name =
row . goods_type_name
selectGoods [ replacePrefix + item . sku_id ] . goods_type = row . goods_type
} )
selectGoodsId . push ( item . sku_id ) ;
selectGoods [ replacePrefix + item . sku_id ] = deepClone ( item ) ;
selectGoods [ replacePrefix + item . sku_id ] . goods_name = row . goods_name ; / / 多 规 格 模 式 , 要 增 加 商 品 名 称 、 商 品 类 型 , 后 续 还 会 增 加 , 满 足 不 同 业 务 场 景
selectGoods [ replacePrefix + item . sku_id ] . goods_type_name = row . goods_type_name ;
selectGoods [ replacePrefix + item . sku_id ] . goods_type = row . goods_type ;
} ) ;
} else {
row . skuList . forEach ( ( item , index ) => {
selectGoodsId . splice ( selectGoodsId . indexOf ( item . sku_id ) , 1 )
/ / 未 选 中 , 删 除 当 前 商 品
delete selectGoods [ replacePrefix + item . sku_id ]
} )
} ) ;
}
}
@ -528,61 +366,52 @@ const secondLevelHandleCheckAllChange = (isSelect, row) => {
/ / g o o d s L i s t T a b l e R e f . v a l u e . t o g g l e R o w E x p a n s i o n ( . . . O b j e c t . v a l u e s ( s p r e a d T a b l e D a t a ) , t r u e )
/ / } , 0 ) ;
/ / 当 所 选 数 量 超 出 限 制 数 量 【 p r o p . m a x 】 时 , 添 加 一 个 就 会 删 除 开 头 的 第 一 个 或 多 个 , 最 终 保 证 所 选 的 数 量 小 于 等 于 p r o p . m a x
if (
prop . max &&
prop . max > 0 &&
Object . keys ( selectGoods ) . length > 0 &&
Object . keys ( selectGoods ) . length > prop . max
) {
let len = Object . keys ( selectGoods ) . length
len = len - prop . max
let goodsIdCopy = cloneDeep ( selectGoodsId )
if ( prop . max && prop . max > 0 && Object . keys ( selectGoods ) . length > 0 && Object . keys ( selectGoods ) . length > prop . max ) {
let len = Object . keys ( selectGoods ) . length ;
len = len - prop . max ;
let goodsIdCopy = cloneDeep ( selectGoodsId ) ;
goodsIdCopy . forEach ( ( item , index , arr ) => {
if ( index < len ) {
let indent = selectGoodsId . indexOf ( item )
delete selectGoods [ replacePrefix + selectGoodsId [ indent ] ]
selectGoodsId . splice ( indent , 1 )
}
} )
setGoodsSelected ( )
} ) ;
setGoodsSelected ( ) ;
}
}
/ / 三 级 复 选 框
const subChildHandleCheckAllChange = (
selected : any ,
parentData : any ,
data : any
) => {
let selectNum = 0
const subChildHandleCheckAllChange = ( selected : any , parentData : any , data : any ) => {
let selectNum = 0 ;
parentData . skuList . forEach ( ( item , index ) => {
if ( item . threeLevelCheckAll ) {
selectNum ++
selectNum ++ ;
}
} )
} ) ;
if ( selectNum > 0 && selectNum != parentData . skuList . length ) {
parentData . secondLevelCheckAll = false
parentData . isSecondLevelIndeterminate = true
parentData . secondLevelCheckAll = false ;
parentData . isSecondLevelIndeterminate = true ;
} else if ( selectNum == parentData . skuList . length ) {
parentData . isSecondLevelIndeterminate = false
parentData . isSecondLevelIndeterminate = false ;
parentData . secondLevelCheckAll = true
} else {
parentData . isSecondLevelIndeterminate = false
parentData . secondLevelCheckAll = false
parentData . isSecondLevelIndeterminate = false ;
parentData . secondLevelCheckAll = false ;
}
detectionAllSelect ( )
detectionAllSelect ( ) ;
let currSku = deepClone ( data )
if ( selected ) {
selectGoodsId . push ( currSku . sku_id )
selectGoodsId . push ( currSku . sku_id ) ;
currSku . goods_name = parentData . goods_name / / 多 规 格 模 式 , 要 增 加 商 品 名 称 、 商 品 类 型 , 后 续 还 会 增 加 , 满 足 不 同 业 务 场 景
currSku . goods_type_name = parentData . goods_type_name
currSku . goods_type = parentData . goods_type
selectGoods [ replacePrefix + currSku . sku_id ] = currSku
currSku . goods_name = parentData . goods_name ; / / 多 规 格 模 式 , 要 增 加 商 品 名 称 、 商 品 类 型 , 后 续 还 会 增 加 , 满 足 不 同 业 务 场 景
currSku . goods_type_name = parentData . goods_type_name ;
currSku . goods_type = parentData . goods_type ;
selectGoods [ replacePrefix + currSku . sku_id ] = currSku ;
} else {
selectGoodsId . splice ( selectGoodsId . indexOf ( currSku . sku_id ) , 1 )
/ / 未 选 中 , 删 除 当 前 商 品
@ -592,22 +421,22 @@ const subChildHandleCheckAllChange = (
/ / 检 测 是 否 选 中
const detectionAllSelect = ( ) => {
let selectNum = 0
let selectNum = 0 ;
goodsTable . data . forEach ( ( item , index ) => {
if ( item . secondLevelCheckAll ) {
selectNum ++
selectNum ++ ;
}
} )
} ) ;
if ( selectNum > 0 && selectNum != goodsTable . data . length ) {
staircheckAll . value = false
isStairIndeterminate . value = true
staircheckAll . value = false ;
isStairIndeterminate . value = true ;
} else if ( selectNum > 0 && selectNum == goodsTable . data . length ) {
isStairIndeterminate . value = false
isStairIndeterminate . value = false ;
staircheckAll . value = true
} else {
isStairIndeterminate . value = false
staircheckAll . value = false
isStairIndeterminate . value = false ;
staircheckAll . value = false ;
}
}
@ -615,13 +444,13 @@ const detectionAllSelect = () => {
* 获取商品列表
* /
const loadGoodsList = ( page : number = 1 , callback : any = null ) => {
isStairIndeterminate . value = false
staircheckAll . value = false
goodsTable . loading = true
goodsTable . data = [ ]
isStairIndeterminate . value = false ;
staircheckAll . value = false ;
goodsTable . loading = true ;
goodsTable . data = [ ] ;
goodsTable . page = page
const searchData = cloneDeep ( goodsTable . searchParam )
const searchData = cloneDeep ( goodsTable . searchParam ) ;
if ( searchData . select_type == 'selected' ) {
const goods_ids = < any > [ ]
@ -630,85 +459,79 @@ const loadGoodsList = (page: number = 1, callback: any = null) => {
}
searchData [ replacePrefix + 'ids' ] = goods_ids
} else {
searchData [ replacePrefix + 'ids' ] = ''
searchData [ replacePrefix + 'ids' ] = '' ;
}
getGoodsSelectPageList ( {
page : goodsTable . page ,
limit : goodsTable . limit ,
... searchData ,
} )
. then ( ( res ) => {
let goodsTableData = cloneDeep ( res . data . data )
... searchData
} ) . then ( res => {
let goodsTableData = cloneDeep ( res . data . data ) ;
goodsTableData . forEach ( ( item : any ) => {
item . isShow = false
item . isSecondLevelIndeterminate = false
item . secondLevelCheckAll = false
item . isShow = false ;
item . isSecondLevelIndeterminate = false ;
item . secondLevelCheckAll = false ;
} )
if ( prop . mode == 'sku' ) {
if ( prop . mode == "sku" ) {
goodsTableData . forEach ( ( item : any ) => {
if ( item . skuList . length ) {
item . skuList . forEach ( ( skuItem : any ) => {
skuItem . threeLevelCheckAll = false
skuItem . goods_type = item . goods_type
skuItem . threeLevelCheckAll = false ;
skuItem . goods_type = item . goods_type ;
} )
}
} )
}
if ( callback )
callback (
prop . mode == 'spu'
? res . data . verify_goods_ids
: res . data . verify_sku_ids ,
res . data . select_goods_list
)
setGoodsSelected ( )
if ( callback ) callback ( prop . mode == "spu" ? res . data . verify_goods_ids : res . data . verify_sku_ids , res . data . select_goods_list )
setGoodsSelected ( ) ;
goodsTable . data = goodsTableData
goodsTable . total = res . data . total
goodsTable . loading = false
} )
. catch ( ( ) => {
} ) . catch ( ( ) => {
goodsTable . loading = false
} )
}
/ / 表 格 设 置 选 中 状 态 s p u
const setGoodsSelected = ( ) => {
nextTick ( ( ) => {
if ( prop . mode == 'spu' ) {
if ( prop . mode == "spu" ) {
for ( let i = 0 ; i < goodsTable . data . length ; i ++ ) {
goodsTable . data [ i ] . secondLevelCheckAll = false
goodsTable . data [ i ] . secondLevelCheckAll = false ;
if ( selectGoods [ replacePrefix + goodsTable . data [ i ] . goods_id ] ) {
goodsTable . data [ i ] . secondLevelCheckAll = true
goodsTable . data [ i ] . secondLevelCheckAll = true ;
}
}
} else {
let isAllSelectSku = true
let isAllSelectSku = true ;
for ( let i = 0 ; i < goodsTable . data . length ; i ++ ) {
goodsTable . data [ i ] . secondLevelCheckAll = false
goodsTable . data [ i ] . secondLevelCheckAll = false ;
isAllSelectSku = true
isAllSelectSku = true ;
goodsTable . data [ i ] . isSecondLevelIndeterminate = false
goodsTable . data [ i ] . isSecondLevelIndeterminate = false ;
goodsTable . data [ i ] . skuList . forEach ( ( item , index ) => {
item . threeLevelCheckAll = false
item . threeLevelCheckAll = false ;
if ( selectGoods [ replacePrefix + item . sku_id ] ) {
goodsTable . data [ i ] . isSecondLevelIndeterminate = true
item . threeLevelCheckAll = true
goodsTable . data [ i ] . isSecondLevelIndeterminate = true ;
item . threeLevelCheckAll = true ;
} else {
isAllSelectSku = false
isAllSelectSku = false ;
}
} )
} ) ;
if ( isAllSelectSku ) {
goodsTable . data [ i ] . isSecondLevelIndeterminate = false
goodsTable . data [ i ] . secondLevelCheckAll = true
goodsTable . data [ i ] . isSecondLevelIndeterminate = false ;
goodsTable . data [ i ] . secondLevelCheckAll = true ;
}
}
}
detectionAllSelect ( )
} )
detectionAllSelect ( ) ;
} ) ;
}
const resetForm = ( formEl : FormInstance | undefined ) => {
@ -720,30 +543,31 @@ const resetForm = (formEl: FormInstance | undefined) => {
const show = ( ) => {
for ( let k in selectGoods ) {
delete selectGoods [ k ]
delete selectGoods [ k ] ;
}
replacePrefix = prop . mode == 'sku' ? 'sku_' : 'goods_'
replacePrefix = prop . mode == "sku" ? 'sku_' : 'goods_' ;
/ / 检 测 商 品 i d 集 合 是 否 存 在 , 移 除 不 存 在 的 商 品 i d , 纠 正 数 据 准 确 性
if ( prop . mode == 'sku' ) {
goodsTable . searchParam . verify_sku_ids = goodsIds . value
goodsTable . searchParam . verify_sku_ids = goodsIds . value ;
} else {
goodsTable . searchParam . verify_goods_ids = goodsIds . value
goodsTable . searchParam . verify_goods_ids = goodsIds . value ;
}
getGoodsSkuNoPageListFn ( )
getGoodsSkuNoPageListFn ( ) ;
loadGoodsList ( 1 , ( verify_ids : any ) => {
/ / 第 一 次 打 开 弹 出 框 时 , 纠 正 数 据 , 并 且 赋 值 已 选 商 品
if ( goodsIds . value && goodsIds . value . length ) {
goodsIds . value . splice ( 0 , goodsIds . value . length , ... verify_ids )
selectGoodsId . splice ( 0 , selectGoodsId . length , ... verify_ids )
if ( Object . keys ( selectGoods ) . length ) {
for ( let key in selectGoods ) {
let num = Number ( key . split ( replacePrefix ) [ 1 ] )
let num = Number ( key . split ( replacePrefix ) [ 1 ] ) ;
if ( goodsIds . value . indexOf ( num ) == - 1 ) {
delete selectGoods [ key ]
delete selectGoods [ key ] ;
}
}
}
@ -754,49 +578,49 @@ const show = () => {
}
const getGoodsSkuNoPageListFn = ( ) => {
const searchData = cloneDeep ( goodsTable . searchParam )
const searchData = cloneDeep ( goodsTable . searchParam ) ;
getGoodsSkuNoPageList ( { ... searchData } ) . then ( ( res : any ) => {
const selectGoodsData = res . data
const selectGoodsData = res . data ;
/ / 赋 值 已 选 择 的 商 品
if ( prop . mode == 'sku' ) {
for ( let i = 0 ; i < selectGoodsData . length ; i ++ ) {
selectGoodsData [ i ] . skuList . forEach ( ( item : any ) => {
if ( goodsIds . value . indexOf ( item . sku_id ) != - 1 ) {
item . goods_name = selectGoodsData [ i ] . goods_name / / 多 规 格 模 式 , 要 增 加 商 品 名 称 、 商 品 类 型 , 后 续 还 会 增 加 , 满 足 不 同 业 务 场 景
item . goods_type_name = selectGoodsData [ i ] . goods_type_name
item . goods_type = selectGoodsData [ i ] . goods_type
selectGoods [ replacePrefix + item . sku_id ] = item
item . goods_name = selectGoodsData [ i ] . goods_name ; / / 多 规 格 模 式 , 要 增 加 商 品 名 称 、 商 品 类 型 , 后 续 还 会 增 加 , 满 足 不 同 业 务 场 景
item . goods_type_name = selectGoodsData [ i ] . goods_type_name ;
item . goods_type = selectGoodsData [ i ] . goods_type ;
selectGoods [ replacePrefix + item . sku_id ] = item ;
}
} )
} ) ;
}
} else {
for ( let i = 0 ; i < selectGoodsData . length ; i ++ ) {
if ( goodsIds . value . indexOf ( selectGoodsData [ i ] . goods_id ) != - 1 ) {
selectGoods [ replacePrefix + selectGoodsData [ i ] . goods_id ] =
selectGoodsData [ i ]
selectGoods [ replacePrefix + selectGoodsData [ i ] . goods_id ] = selectGoodsData [ i ] ;
}
}
}
if ( Object . keys ( selectGoods ) . length && goodsIds . value . length ) {
for ( let key in selectGoods ) {
let num = Number ( key . split ( replacePrefix ) [ 1 ] )
let num = Number ( key . split ( replacePrefix ) [ 1 ] ) ;
if ( goodsIds . value . indexOf ( num ) == - 1 ) {
delete selectGoods [ key ]
delete selectGoods [ key ] ;
}
}
}
setGoodsSelected ( )
setGoodsSelected ( ) ;
} )
}
/ / 清 空 已 选 商 品
const clear = ( ) => {
for ( let k in selectGoods ) {
delete selectGoods [ k ]
delete selectGoods [ k ] ;
}
setGoodsSelected ( )
setGoodsSelected ( ) ;
}
const save = ( ) => {
@ -804,72 +628,64 @@ const save = () => {
ElMessage ( {
type : 'warning' ,
message : ` ${ t ( 'goodsSelectPopupGoodsMinTip' ) } ${ prop . min } ${ t ( 'goodsSelectPopupPiece' ) } ` ,
} )
return
} ) ;
return ;
}
if (
prop . max &&
prop . max > 0 &&
selectGoodsNum . value &&
selectGoodsNum . value > prop . max
) {
if ( prop . max && prop . max > 0 && selectGoodsNum . value && selectGoodsNum . value > prop . max ) {
ElMessage ( {
type : 'warning' ,
message : ` ${ t ( 'goodsSelectPopupGoodsMaxTip' ) } ${ prop . max } ${ t ( 'goodsSelectPopupPiece' ) } ` ,
} )
return
} ) ;
return ;
}
if ( prop . way == 'single' ) {
let realTypeNum = 0
let virtualTypeNum = 0
let realTypeNum = 0 ;
let virtualTypeNum = 0 ;
for ( let k in selectGoods ) {
if ( selectGoods [ k ] . goods_type == 'virtual' ) {
virtualTypeNum ++
} else if ( selectGoods [ k ] . goods_type == 'real' ) {
realTypeNum ++
if ( selectGoods [ k ] . goods_type == "virtual" ) {
virtualTypeNum ++ ;
} else if ( selectGoods [ k ] . goods_type == "real" ) {
realTypeNum ++ ;
}
}
if (
realTypeNum != Object . keys ( selectGoods ) . length &&
virtualTypeNum != Object . keys ( selectGoods ) . length
) {
if ( realTypeNum != Object . keys ( selectGoods ) . length && virtualTypeNum != Object . keys ( selectGoods ) . length ) {
ElMessage ( {
type : 'warning' ,
message : ` ${ t ( 'wayPlaceholder' ) } ` ,
} )
return
} ) ;
return ;
}
}
let ids : any = [ ]
let ids : any = [ ] ;
for ( let k in selectGoods ) {
ids . push ( parseInt ( k . replace ( replacePrefix , '' ) ) )
ids . push ( parseInt ( k . replace ( replacePrefix , '' ) ) ) ;
}
goodsIds . value . splice ( 0 , goodsIds . value . length , ... ids )
emit ( 'goodsSelect' , selectGoods )
initSearchParam ( )
initSearchParam ( ) ;
showDialog . value = false
}
/ / 重 置 表 单 搜 索
const initSearchParam = ( ) => {
goodsTable . searchParam . keyword = ''
goodsTable . searchParam . goods_category = [ ]
goodsTable . searchParam . select_type = 'all'
goodsTable . searchParam . goods_ids = ''
goodsTable . searchParam . verify_goods_ids = ''
goodsTable . searchParam . verify_sku_ids = ''
goodsTable . searchParam . goods_type = ''
goodsTable . searchParam . keyword = '' ;
goodsTable . searchParam . goods_category = [ ] ;
goodsTable . searchParam . select_type = 'all' ;
goodsTable . searchParam . goods_ids = '' ;
goodsTable . searchParam . verify_goods_ids = '' ;
goodsTable . searchParam . verify_sku_ids = '' ;
goodsTable . searchParam . goods_type = '' ;
}
defineExpose ( {
showDialog ,
selectGoods ,
selectGoodsNum ,
selectGoodsNum
} )
< / script >