feat(ID1000928): 【领取色卡】新增色卡只能购买5种色卡

【【领取色卡】新增色卡只能购买5种色卡】 https://www.tapd.cn/53459131/prong/stories/view/1153459131001000928
This commit is contained in:
xuan 2023-02-28 10:18:01 +08:00
parent 1bfd170696
commit 5e7af08483
5 changed files with 52 additions and 14 deletions

View File

@ -51,6 +51,13 @@
"query": "", "query": "",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
},
{
"name": "",
"pathName": "pages/getColorCard/colorCardList/index",
"query": "",
"launchMode": "default",
"scene": null
} }
] ]
} }

View File

@ -142,7 +142,7 @@ const AddColorCard = () => {
} }
const handleCountChange = (value: number, id: number) => { const handleCountChange = (value: number, id: number) => {
console.log('value', value) console.log('value', value, order)
if (order.length === 1 && value === 0) { if (order.length === 1 && value === 0) {
Taro.showToast({ Taro.showToast({
title: '最后一个色卡不能删除', title: '最后一个色卡不能删除',
@ -156,8 +156,8 @@ const AddColorCard = () => {
content: '确认删除所选色卡?', content: '确认删除所选色卡?',
confirmText: '删除', confirmText: '删除',
confirmColor: '#337fff', confirmColor: '#337fff',
success(res) { success: ({ confirm }) => {
if (res.confirm) { if (confirm) {
deleteColorCard(id) deleteColorCard(id)
} }
}, },
@ -354,7 +354,7 @@ const AddColorCard = () => {
onClickBtn={getInputValue} onClickBtn={getInputValue}
unit="本" unit="本"
minNum={0} minNum={0}
maxNum={999} maxNum={2}
/> />
</View> </View>
</View> </View>

View File

@ -12,6 +12,8 @@ import { dataLoadingStatus, debounce, getFilterData } from '@/common/util'
import { alert, goLink } from '@/common/common' import { alert, goLink } from '@/common/common'
import { GetCanAddCardList } from '@/api/colorCard' import { GetCanAddCardList } from '@/api/colorCard'
import { formatRemoveHashTag } from '@/common/format' import { formatRemoveHashTag } from '@/common/format'
// 限制5种色卡
const limit = 5
const ColorCardList = () => { const ColorCardList = () => {
const { fetchData, state } = GetCanAddCardList() const { fetchData, state } = GetCanAddCardList()
@ -79,10 +81,14 @@ const ColorCardList = () => {
getData() getData()
}, [searchField]) }, [searchField])
const selectedList = useRef<number[]>([])
useDidShow(() => { useDidShow(() => {
const cache = Taro.getStorageSync('colorCardCache') const cache = Taro.getStorageSync('colorCardCache')
if (cache) { if (cache) {
setSearchField(val => ({ ...val, color_card_ids: JSON.parse(cache).map(item => item.id) })) // 已选的列入 selectedList
selectedList.current = JSON.parse(cache).map(item => item.id)
setSearchField(val => ({ ...val, color_card_ids: selectedList.current }))
} }
}) })
@ -110,12 +116,13 @@ const ColorCardList = () => {
}, [orderList]) }, [orderList])
// 选择 // 选择
const onSelect = (item: any) => { const onSelect = (item: any) => {
console.log('item==>', item) console.log('item==>', item, selectedList.current)
setOrderList((prev: any) => { setOrderList((prev: any) => {
prev.list?.forEach((val) => { prev.list?.forEach((val) => {
if (val.id === item.id) { if (val.id === item.id) {
val.status = true val.status = true
multipleSelection.current = [...multipleSelection.current, val] multipleSelection.current = [...multipleSelection.current, val]
selectedList.current = [...selectedList.current, item.id]
} }
}) })
return { list: prev.list, total: prev.total } return { list: prev.list, total: prev.total }
@ -128,6 +135,7 @@ const ColorCardList = () => {
if (val.id === item.id) { if (val.id === item.id) {
val.status = false val.status = false
multipleSelection.current = multipleSelection.current.filter(mul => mul.id !== val.id) multipleSelection.current = multipleSelection.current.filter(mul => mul.id !== val.id)
selectedList.current = selectedList.current.filter(mul => mul !== val.id)
} }
}) })
return { list: prev.list, total: prev.total } return { list: prev.list, total: prev.total }
@ -137,13 +145,15 @@ const ColorCardList = () => {
const handleClickCheckBox = (item: any) => { const handleClickCheckBox = (item: any) => {
console.log('item', item) console.log('item', item)
if (!item.is_add) { if (isDisabled(item.id)) {
if (item.status) { return alert.none(`最多选择${limit}种色卡`)
onUnSelect(item) }
} if (item.is_add) { return }
else { if (item.status) {
onSelect(item) onUnSelect(item)
} }
else {
onSelect(item)
} }
} }
const noop = (e) => { const noop = (e) => {
@ -157,6 +167,14 @@ const ColorCardList = () => {
} }
}) })
const isDisabled = (currentId: number) => {
console.log('selectedList', selectedList.current)
if (selectedList.current.includes(currentId)) {
return false
}
return selectedList.current.length >= limit
}
return <View className={styles.main}> return <View className={styles.main}>
<View className={styles.search}> <View className={styles.search}>
<Search placeholder="请输入搜索面料/色卡" showBtn={false} changeOnSearch={getSearchData} > <Search placeholder="请输入搜索面料/色卡" showBtn={false} changeOnSearch={getSearchData} >
@ -197,7 +215,7 @@ const ColorCardList = () => {
<View className={styles.addButton} onClick={noop}> <View className={styles.addButton} onClick={noop}>
{/* multipleSelection.current.some(mul => mul.id === item.id) 确保加载新数据时保持选中状态 */} {/* multipleSelection.current.some(mul => mul.id === item.id) 确保加载新数据时保持选中状态 */}
<MCheckbox <MCheckbox
disabled={item.is_add} disabled={item.is_add || isDisabled(item.id)}
status={item.is_add || item.status || multipleSelection.current.some(mul => mul.id === item.id)} status={item.is_add || item.status || multipleSelection.current.some(mul => mul.id === item.id)}
onSelect={() => onSelect(item)} onSelect={() => onSelect(item)}
onClose={() => onUnSelect(item)} onClose={() => onUnSelect(item)}

View File

@ -74,6 +74,10 @@
text-align: right; text-align: right;
} }
} }
&Tags{
display: flex;
flex-flow: row wrap;
}
.colorsBox { .colorsBox {
display: flex; display: flex;

View File

@ -8,6 +8,7 @@ import Divider from '@/components/divider'
import Tag from '@/components/tag' import Tag from '@/components/tag'
import LayoutBlock from '@/components/layoutBlock' import LayoutBlock from '@/components/layoutBlock'
import { goLink } from '@/common/common' import { goLink } from '@/common/common'
import { formatRemoveHashTag } from '@/common/format'
interface PropsType { interface PropsType {
data?: any data?: any
@ -52,6 +53,14 @@ const ItemList = (props: PropsType) => {
<View className={styles.productName}>{data.color_card_info?.[0]?.name}</View> <View className={styles.productName}>{data.color_card_info?.[0]?.name}</View>
<View className={styles.shipMode}>{data.shipment_mode_name}</View> <View className={styles.shipMode}>{data.shipment_mode_name}</View>
</View> </View>
<View className={styles.rightContTags}>
{
data.color_card_info?.[0]?.affiliation_product?.map((item, index) => {
return <Tag customStyle={{ marginRight: '5px', marginBottom: '2px', padding: '5px', background: '#e3ecff', color: '#558cff', borderColor: '#e3ecff' }} key={index} size="small" circle>{formatRemoveHashTag(item.code)}</Tag>
})
}
</View>
<View className={styles.colorsBox}> <View className={styles.colorsBox}>
<View className={styles.colorName}>x{data.color_card_info?.[0]?.count || 0}</View> <View className={styles.colorName}>x{data.color_card_info?.[0]?.count || 0}</View>
</View> </View>