🌈 style(eslint): 新增eslint规则
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { CustomWrapper, View } from '@tarojs/components'
|
||||
import { memo, useCallback, useMemo } from 'react'
|
||||
import classnames from 'classnames'
|
||||
import Big from 'big.js'
|
||||
import styles from './index.module.scss'
|
||||
import MCheckbox from '@/components/checkbox'
|
||||
import Counter from '@/components/counter'
|
||||
import LabAndImg from '@/components/LabAndImg'
|
||||
import { formatHashTag, formatImgUrl, formatPriceDiv } from '@/common/fotmat'
|
||||
import Big from 'big.js'
|
||||
import { saleModeType } from '@/common/enum'
|
||||
type param = {
|
||||
import type { saleModeType } from '@/common/enum'
|
||||
|
||||
interface param {
|
||||
sale_model: saleModeType
|
||||
onChangeSelect: (val: any) => any
|
||||
onChangeCount: (val: any) => any
|
||||
@@ -16,7 +17,7 @@ type param = {
|
||||
}
|
||||
|
||||
export default memo((props: param) => {
|
||||
let { onChangeCount, onChangeSelect, item, sale_model } = props
|
||||
const { onChangeCount, onChangeSelect, item, sale_model } = props
|
||||
|
||||
const selectCallBack = useCallback(() => {
|
||||
onChangeSelect({ ...item, selected: true })
|
||||
@@ -27,8 +28,8 @@ export default memo((props: param) => {
|
||||
const getLabAndImg = useCallback(() => {}, [])
|
||||
const getInputValue = useCallback(
|
||||
(e) => {
|
||||
let roll = item.sale_mode == 0 ? parseFloat(e) : 0
|
||||
let length = item.sale_mode != 0 ? parseFloat(new Big(parseFloat(e)).times(100)) : 0
|
||||
const roll = item.sale_mode == 0 ? parseFloat(e) : 0
|
||||
const length = item.sale_mode != 0 ? parseFloat(new Big(parseFloat(e)).times(100)) : 0
|
||||
onChangeCount({ ...item, roll, length })
|
||||
},
|
||||
[item],
|
||||
@@ -38,20 +39,20 @@ export default memo((props: param) => {
|
||||
}, [item])
|
||||
|
||||
const clickProduct = useCallback(() => {
|
||||
if (sale_model == item.sale_mode) onChangeSelect({ ...item, selected: !item.selected })
|
||||
if (sale_model == item.sale_mode) { onChangeSelect({ ...item, selected: !item.selected }) }
|
||||
}, [item])
|
||||
|
||||
console.log('刷新2::', item)
|
||||
|
||||
//格式化金额
|
||||
// 格式化金额
|
||||
const formatPirce = useCallback((price) => {
|
||||
return Number(formatPriceDiv(price))
|
||||
}, [])
|
||||
//格式化数量
|
||||
// 格式化数量
|
||||
const formatCount = useCallback((item) => {
|
||||
return item.sale_mode == 0 ? item.roll : item.length / 100
|
||||
}, [])
|
||||
//格式化单位
|
||||
// 格式化单位
|
||||
const formatUnit = useCallback((item) => {
|
||||
return item.sale_mode == 0 ? '条' : '米'
|
||||
}, [])
|
||||
@@ -78,7 +79,7 @@ export default memo((props: param) => {
|
||||
</View>
|
||||
<View className={styles.count}>
|
||||
<View className={styles.des}>
|
||||
<View className={styles.subtitle}>{item.product_color_code + ' ' + item.product_color_name}</View>
|
||||
<View className={styles.subtitle}>{`${item.product_color_code} ${item.product_color_name}`}</View>
|
||||
<View className={styles.tag}>{item.sale_mode_name}</View>
|
||||
</View>
|
||||
<View className={styles.btn_count}>
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { Image, ScrollView, View } from '@tarojs/components'
|
||||
import Popup from '@/components/popup'
|
||||
import classnames from 'classnames'
|
||||
import MCheckbox from '@/components/checkbox'
|
||||
import LoadingCard from '@/components/loadingCard'
|
||||
import InfiniteScroll from '@/components/infiniteScroll'
|
||||
import styles from './index.module.scss'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { alert, goLink } from '@/common/common'
|
||||
import { GetShoppingCartApi, DelShoppingCartApi, UpdateShoppingCartApi } from '@/api/shopCart'
|
||||
import { formatHashTag, formatImgUrl, formatPriceDiv } from '@/common/fotmat'
|
||||
import { setParam } from '@/common/system'
|
||||
import { debounce, throttle } from '@/common/util'
|
||||
import classnames from 'classnames'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import Counter from '../counter'
|
||||
import { ApplyOrderAccessApi, GetAdminUserInfoApi, SubscriptionMessageApi } from '@/api/user'
|
||||
import useCommonData from '@/use/useCommonData'
|
||||
import BindSalesmanPopup from '../bindSalesmanPopup'
|
||||
import LabAndImgShow from '../LabAndImgShow'
|
||||
import LabAndImg from '../LabAndImg'
|
||||
import styles from './index.module.scss'
|
||||
import Popup from '@/components/popup'
|
||||
import MCheckbox from '@/components/checkbox'
|
||||
import LoadingCard from '@/components/loadingCard'
|
||||
import InfiniteScroll from '@/components/infiniteScroll'
|
||||
import { alert, goLink } from '@/common/common'
|
||||
import { DelShoppingCartApi, GetShoppingCartApi, UpdateShoppingCartApi } from '@/api/shopCart'
|
||||
import { formatHashTag, formatImgUrl, formatPriceDiv } from '@/common/fotmat'
|
||||
import { setParam } from '@/common/system'
|
||||
import { debounce, throttle } from '@/common/util'
|
||||
import { ApplyOrderAccessApi, GetAdminUserInfoApi, SubscriptionMessageApi } from '@/api/user'
|
||||
import useCommonData from '@/use/useCommonData'
|
||||
|
||||
type param = {
|
||||
interface param {
|
||||
show?: true | false
|
||||
onClose?: () => void
|
||||
intoStatus?: 'again' | 'shop'
|
||||
default_sale_mode?: number //面料类型(0:大货, 1:剪版,2:散剪
|
||||
default_sale_mode?: number // 面料类型(0:大货, 1:剪版,2:散剪
|
||||
}
|
||||
export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode }: param) => {
|
||||
const selectList = [
|
||||
@@ -32,7 +32,7 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
{ value: 2, title: '散剪', unit: '米', eunit: 'kg', step: 1, digits: 2, minNum: 3, maxNum: 100000, defaultNum: 3 },
|
||||
]
|
||||
|
||||
//切换面料类型
|
||||
// 切换面料类型
|
||||
const [selectIndex, setSelectIndex] = useState(default_sale_mode || 0)
|
||||
const selectProduct = (index: number) => {
|
||||
setSelectIndex(index)
|
||||
@@ -48,53 +48,55 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
|
||||
const MCheckboxRef = useRef(null)
|
||||
|
||||
//获取购物车数据数量
|
||||
// 获取购物车数据数量
|
||||
const { setShopCount } = useCommonData()
|
||||
|
||||
//重置勾选数据
|
||||
// 重置勾选数据
|
||||
const resetList = () => {
|
||||
list?.map((item) => {
|
||||
if (selectIndex == item.sale_mode || selectIndex == -1) {
|
||||
checkboxData[item.id] = true
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
checkboxData[item.id] = false
|
||||
}
|
||||
})
|
||||
setCheckboxData(() => ({ ...checkboxData }))
|
||||
}
|
||||
|
||||
//获取数据
|
||||
// 获取数据
|
||||
const [list, setList] = useState<any[]>([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
const { fetchData } = GetShoppingCartApi()
|
||||
const getShoppingCart = async () => {
|
||||
const getShoppingCart = async() => {
|
||||
const { data } = await fetchData()
|
||||
let color_list = data.color_list || []
|
||||
const color_list = data.color_list || []
|
||||
setShopCount(color_list.length)
|
||||
initList(color_list)
|
||||
setList(color_list)
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
//初始化全部数据默认勾选
|
||||
const [checkboxData, setCheckboxData] = useState<{ [index: number]: true | false }>({})
|
||||
// 初始化全部数据默认勾选
|
||||
const [checkboxData, setCheckboxData] = useState<Record<number, true | false>>({})
|
||||
const initStatus = useRef(false)
|
||||
const initList = (color_list) => {
|
||||
if (initStatus.current) {
|
||||
color_list?.map((item) => {
|
||||
if (selectIndex == item.sale_mode) checkboxData[item.id] = true
|
||||
if (selectIndex == item.sale_mode) { checkboxData[item.id] = true }
|
||||
})
|
||||
initStatus.current = false
|
||||
}
|
||||
setCheckboxData(() => checkboxData)
|
||||
}
|
||||
|
||||
//显示是展示数据
|
||||
// 显示是展示数据
|
||||
useEffect(() => {
|
||||
if (!show) {
|
||||
setList([])
|
||||
setSelectIndex(default_sale_mode || 0)
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
setLoading(true)
|
||||
initStatus.current = true
|
||||
getShoppingCart()
|
||||
@@ -113,57 +115,57 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
setShowPopup(show)
|
||||
}, [show])
|
||||
|
||||
//全选反选
|
||||
// 全选反选
|
||||
const [selectStatus, setSelectStatus] = useState(false)
|
||||
const selectAll = () => {
|
||||
list.map((item) => {
|
||||
if (selectIndex == item.sale_mode || selectIndex == -1) checkboxData[item.id] = !selectStatus
|
||||
if (selectIndex == item.sale_mode || selectIndex == -1) { checkboxData[item.id] = !selectStatus }
|
||||
})
|
||||
setSelectStatus(!selectStatus)
|
||||
setCheckboxData(() => ({ ...checkboxData }))
|
||||
}
|
||||
|
||||
//checkbox选中回调
|
||||
// checkbox选中回调
|
||||
const selectCallBack = useCallback((item) => {
|
||||
checkboxData[item.id] = true
|
||||
checkSelect()
|
||||
setCheckboxData((e) => ({ ...e, ...checkboxData }))
|
||||
setCheckboxData(e => ({ ...e, ...checkboxData }))
|
||||
}, [])
|
||||
|
||||
//checkbox选中判断是否全部选中,全部选中后是全选,否则反选
|
||||
// checkbox选中判断是否全部选中,全部选中后是全选,否则反选
|
||||
const checkSelect = () => {
|
||||
let list_count = 0
|
||||
let select_count = 0
|
||||
list?.map((item) => {
|
||||
if (selectIndex == -1 || selectIndex == item.sale_mode) {
|
||||
list_count++
|
||||
if (checkboxData[item.id]) select_count++
|
||||
if (checkboxData[item.id]) { select_count++ }
|
||||
}
|
||||
})
|
||||
setSelectStatus(select_count == list_count)
|
||||
}
|
||||
|
||||
//checkbox关闭回调
|
||||
// checkbox关闭回调
|
||||
const colseCallBack = useCallback((item) => {
|
||||
checkboxData[item.id] = false
|
||||
checkSelect()
|
||||
setCheckboxData((e) => ({ ...e, ...checkboxData }))
|
||||
setCheckboxData(e => ({ ...e, ...checkboxData }))
|
||||
}, [])
|
||||
|
||||
//popup关闭
|
||||
// popup关闭
|
||||
const closePopup = () => {
|
||||
onClose?.()
|
||||
setShowPopup(false)
|
||||
}
|
||||
|
||||
//删除购物车内容
|
||||
// 删除购物车内容
|
||||
const { fetchData: delShopFetchData } = DelShoppingCartApi()
|
||||
const delSelect = () => {
|
||||
getSelectId()
|
||||
if (selectIds.current.length <= 0) return alert.none('请选择要删除的面料!')
|
||||
if (selectIds.current.length <= 0) { return alert.none('请选择要删除的面料!') }
|
||||
Taro.showModal({
|
||||
content: '删除所选商品?',
|
||||
success: async function (res) {
|
||||
async success(res) {
|
||||
if (res.confirm) {
|
||||
const res = await delShopFetchData({ id: selectIds.current })
|
||||
if (res.success) {
|
||||
@@ -172,20 +174,22 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
title: '成功',
|
||||
icon: 'success',
|
||||
})
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Taro.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} else if (res.cancel) {
|
||||
}
|
||||
else if (res.cancel) {
|
||||
console.log('用户点击取消')
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//获取面料选中的id
|
||||
// 获取面料选中的id
|
||||
const selectIds = useRef<number[]>([])
|
||||
const getSelectId = () => {
|
||||
selectIds.current = []
|
||||
@@ -196,27 +200,27 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
})
|
||||
}
|
||||
|
||||
//格式化金额
|
||||
// 格式化金额
|
||||
const formatPirce = useCallback((price) => {
|
||||
return Number(formatPriceDiv(price))
|
||||
}, [])
|
||||
|
||||
//格式化数量
|
||||
// 格式化数量
|
||||
const formatCount = useCallback((item) => {
|
||||
return item.sale_mode == 0 ? item.roll : item.length / 100
|
||||
}, [])
|
||||
|
||||
//格式化单位
|
||||
// 格式化单位
|
||||
const formatUnit = useCallback((item) => {
|
||||
return item.sale_mode == 0 ? '条' : '米'
|
||||
}, [])
|
||||
|
||||
//预估金额和总条数
|
||||
// 预估金额和总条数
|
||||
const estimatePrice = useMemo(() => {
|
||||
let estimate_amount = 0
|
||||
let product_list = new Set() //面料
|
||||
let color_count = 0 //颜色数量
|
||||
let all_count = 0 //总数量
|
||||
const product_list = new Set() // 面料
|
||||
let color_count = 0 // 颜色数量
|
||||
let all_count = 0 // 总数量
|
||||
list.map((item) => {
|
||||
if (checkboxData[item.id]) {
|
||||
estimate_amount += item.estimate_amount
|
||||
@@ -225,7 +229,7 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
all_count += item.sale_mode == 0 ? item.roll : item.length
|
||||
}
|
||||
})
|
||||
let all_count_text = selectIndex == 0 ? all_count + ' 条' : all_count / 100 + ' 米'
|
||||
const all_count_text = selectIndex == 0 ? `${all_count} 条` : `${all_count / 100} 米`
|
||||
return {
|
||||
price: Number(formatPriceDiv(estimate_amount)).toFixed(2),
|
||||
countText: `已选 ${product_list.size} 种面料,${color_count} 个颜色,共 ${all_count_text}`,
|
||||
@@ -233,13 +237,13 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
}
|
||||
}, [list, checkboxData])
|
||||
|
||||
//去结算
|
||||
// 去结算
|
||||
const { fetchData: useFetchData } = GetAdminUserInfoApi()
|
||||
const { fetchData: applyOrderAccessFetchData } = ApplyOrderAccessApi()
|
||||
const orderDetail = throttle(async () => {
|
||||
let res = await useFetchData()
|
||||
const orderDetail = throttle(async() => {
|
||||
const res = await useFetchData()
|
||||
if (res.data.order_access_status !== 3) {
|
||||
if (res.data.order_access_status == 1) applyOrderAccessFetchData()
|
||||
if (res.data.order_access_status == 1) { applyOrderAccessFetchData() }
|
||||
setShowBindSalesman(() => true)
|
||||
onClose?.()
|
||||
return false
|
||||
@@ -247,36 +251,38 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
getSelectId()
|
||||
if (selectIds.current.length == 0) {
|
||||
alert.error('请选择面料')
|
||||
} else {
|
||||
let ids = selectIds.current.join('-')
|
||||
setParam({ ids, sale_mode: selectIndex }) //临时存储
|
||||
}
|
||||
else {
|
||||
const ids = selectIds.current.join('-')
|
||||
setParam({ ids, sale_mode: selectIndex }) // 临时存储
|
||||
closePopup()
|
||||
if (intoStatus == 'again') {
|
||||
goLink('/pages/order/comfirm', {}, 'redirectTo')
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
goLink('/pages/order/comfirm')
|
||||
}
|
||||
}
|
||||
}, 500)
|
||||
|
||||
//计数组件-当后端修改完成才修改前端显示
|
||||
// 计数组件-当后端修改完成才修改前端显示
|
||||
const { fetchData: fetchDataUpdateShoppingCart } = UpdateShoppingCartApi()
|
||||
const [UpdateShoppingCartLoading, setUpdateShoppingCartLoading] = useState(false)
|
||||
const getInputValue = debounce(async (num, item) => {
|
||||
let roll = item.sale_mode == 0 ? parseFloat(num) : 0
|
||||
let length = item.sale_mode != 0 ? parseFloat(num) * 100 : 0
|
||||
const getInputValue = debounce(async(num, item) => {
|
||||
const roll = item.sale_mode == 0 ? parseFloat(num) : 0
|
||||
const length = item.sale_mode != 0 ? parseFloat(num) * 100 : 0
|
||||
setUpdateShoppingCartLoading(() => true)
|
||||
let res = await fetchDataUpdateShoppingCart({ id: item.id, roll, length })
|
||||
const res = await fetchDataUpdateShoppingCart({ id: item.id, roll, length })
|
||||
setUpdateShoppingCartLoading(() => false)
|
||||
if (res.success) {
|
||||
getShoppingCart()
|
||||
}
|
||||
}, 300)
|
||||
|
||||
//绑定业务员和电话号码
|
||||
// 绑定业务员和电话号码
|
||||
const [showBindSalesman, setShowBindSalesman] = useState(false)
|
||||
|
||||
//显示图片弹窗
|
||||
// 显示图片弹窗
|
||||
const [showLabImage, setShowLabImage] = useState(false)
|
||||
const [labImageValue, setLabImageValue] = useState()
|
||||
const getLabAndImg = useCallback((val) => {
|
||||
@@ -305,7 +311,8 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
<View
|
||||
key={item.value}
|
||||
onClick={() => selectProduct(item.value)}
|
||||
className={classnames(styles.search_item, selectIndex == item.value && styles.search_item_select)}>
|
||||
className={classnames(styles.search_item, selectIndex == item.value && styles.search_item_select)}
|
||||
>
|
||||
{item.title}
|
||||
</View>
|
||||
)
|
||||
@@ -320,7 +327,8 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
return (
|
||||
<View
|
||||
key={item}
|
||||
className={classnames(styles.product_item, selectIndex != -1 && selectIndex != item.sale_mode && styles.no_product_item_select)}>
|
||||
className={classnames(styles.product_item, selectIndex != -1 && selectIndex != item.sale_mode && styles.no_product_item_select)}
|
||||
>
|
||||
<View className={styles.checkbox}>
|
||||
<MCheckbox
|
||||
disabled={selectIndex != -1 && selectIndex != item.sale_mode}
|
||||
@@ -347,16 +355,16 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
</View>
|
||||
<View className={styles.count}>
|
||||
<View className={styles.des}>
|
||||
<View className={styles.subtitle}>{item.product_color_code + ' ' + item.product_color_name}</View>
|
||||
<View className={styles.subtitle}>{`${item.product_color_code} ${item.product_color_name}`}</View>
|
||||
<View className={styles.tag}>{item.sale_mode_name}</View>
|
||||
</View>
|
||||
<View className={styles.btn_count}>
|
||||
<Counter
|
||||
onBlue={(e) => getInputValue(e, item)}
|
||||
onBlue={e => getInputValue(e, item)}
|
||||
defaultNum={formatCount(item)}
|
||||
step={selectList[selectIndex].step}
|
||||
digits={selectList[selectIndex].digits}
|
||||
onClickBtn={(e) => getInputValue(e, item)}
|
||||
onClickBtn={e => getInputValue(e, item)}
|
||||
unit={formatUnit(item)}
|
||||
minNum={selectList[selectIndex].minNum}
|
||||
maxNum={selectList[selectIndex].maxNum}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
import { Image, ScrollView, View } from '@tarojs/components'
|
||||
import Popup from '@/components/popup'
|
||||
import classnames from 'classnames'
|
||||
import MCheckbox from '@/components/checkbox'
|
||||
import LoadingCard from '@/components/loadingCard'
|
||||
import InfiniteScroll from '@/components/infiniteScroll'
|
||||
import styles from './index.module.scss'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, useTransition } from 'react'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { alert, goLink } from '@/common/common'
|
||||
import { GetShoppingCartApi, DelShoppingCartApi, UpdateShoppingCartApi } from '@/api/shopCart'
|
||||
import { formatHashTag, formatImgUrl, formatPriceDiv } from '@/common/fotmat'
|
||||
import { setParam } from '@/common/system'
|
||||
import { debounce, throttle } from '@/common/util'
|
||||
import classnames from 'classnames'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, useTransition } from 'react'
|
||||
import Counter from '../counter'
|
||||
import { ApplyOrderAccessApi, GetAdminUserInfoApi, SubscriptionMessageApi } from '@/api/user'
|
||||
import useCommonData from '@/use/useCommonData'
|
||||
import BindSalesmanPopup from '../bindSalesmanPopup'
|
||||
import LabAndImgShow from '../LabAndImgShow'
|
||||
import LabAndImg from '../LabAndImg'
|
||||
import styles from './index.module.scss'
|
||||
import ProductItem from './components/productItem'
|
||||
import { saleModeType } from '@/common/enum'
|
||||
import Popup from '@/components/popup'
|
||||
import MCheckbox from '@/components/checkbox'
|
||||
import LoadingCard from '@/components/loadingCard'
|
||||
import InfiniteScroll from '@/components/infiniteScroll'
|
||||
import { alert, goLink } from '@/common/common'
|
||||
import { DelShoppingCartApi, GetShoppingCartApi, UpdateShoppingCartApi } from '@/api/shopCart'
|
||||
import { formatHashTag, formatImgUrl, formatPriceDiv } from '@/common/fotmat'
|
||||
import { setParam } from '@/common/system'
|
||||
import { debounce, throttle } from '@/common/util'
|
||||
import { ApplyOrderAccessApi, GetAdminUserInfoApi, SubscriptionMessageApi } from '@/api/user'
|
||||
import useCommonData from '@/use/useCommonData'
|
||||
import type { saleModeType } from '@/common/enum'
|
||||
|
||||
type param = {
|
||||
interface param {
|
||||
show?: true | false
|
||||
onClose?: () => void
|
||||
intoStatus?: 'again' | 'shop'
|
||||
default_sale_mode?: saleModeType //面料类型(0:大货, 1:剪版,2:散剪
|
||||
default_sale_mode?: saleModeType // 面料类型(0:大货, 1:剪版,2:散剪
|
||||
}
|
||||
type modelClassType = {
|
||||
interface modelClassType {
|
||||
value: saleModeType
|
||||
title: string
|
||||
unit: string
|
||||
@@ -47,7 +47,7 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
|
||||
const [isPending, startTransition] = useTransition()
|
||||
|
||||
//切换面料类型
|
||||
// 切换面料类型
|
||||
const [selectIndex, setSelectIndex] = useState<saleModeType>(default_sale_mode || 0)
|
||||
const selectProduct = (index: 0 | 1 | 2) => {
|
||||
setSelectIndex(index)
|
||||
@@ -65,26 +65,26 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
})
|
||||
}, [selectIndex])
|
||||
|
||||
//获取购物车数据数量
|
||||
// 获取购物车数据数量
|
||||
const { getShopCount } = useCommonData()
|
||||
|
||||
//获取所有数据数据
|
||||
const [list, setList] = useState<{ [id: number]: any }>({})
|
||||
// 获取所有数据数据
|
||||
const [list, setList] = useState<Record<number, any>>({})
|
||||
const [loading, setLoading] = useState(false)
|
||||
const { fetchData: getShoppingFetchData } = GetShoppingCartApi()
|
||||
const getShoppingCart = async () => {
|
||||
const getShoppingCart = async() => {
|
||||
const { data } = await getShoppingFetchData()
|
||||
let color_list = data.color_list || []
|
||||
const color_list = data.color_list || []
|
||||
initList(color_list)
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
//更新单条数据
|
||||
const getShoppingCartInfo = async (item) => {
|
||||
// 更新单条数据
|
||||
const getShoppingCartInfo = async(item) => {
|
||||
const res = await getShoppingFetchData({ id: item.id })
|
||||
if (res.success) {
|
||||
let info = res.data.color_list[0]
|
||||
let newInfo = {
|
||||
const info = res.data.color_list[0]
|
||||
const newInfo = {
|
||||
...item,
|
||||
estimate_amount: info.estimate_amount,
|
||||
estimate_weight: info.estimate_weight,
|
||||
@@ -95,7 +95,7 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
sale_price: info.sale_price,
|
||||
standard_price: info.standard_price,
|
||||
}
|
||||
setList((e) => ({ ...e, [item['id']]: newInfo }))
|
||||
setList(e => ({ ...e, [item.id]: newInfo }))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +103,9 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
return Object.values(list)
|
||||
}, [list])
|
||||
|
||||
//初始化全部数据默认勾选
|
||||
// 初始化全部数据默认勾选
|
||||
const initList = (color_list) => {
|
||||
let obj = {}
|
||||
const obj = {}
|
||||
color_list?.map((item) => {
|
||||
item.selected = selectIndex == item.sale_mode
|
||||
const { unit, eunit, step, digits, minNum, maxNum } = selectList[item.sale_mode]
|
||||
@@ -115,25 +115,27 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
setList(() => ({ ...obj }))
|
||||
}
|
||||
|
||||
//重置勾选数据
|
||||
// 重置勾选数据
|
||||
const resetList = () => {
|
||||
Object.values(list)?.map((item) => {
|
||||
if (selectIndex == item.sale_mode) {
|
||||
item.selected = true
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
item.selected = false
|
||||
}
|
||||
list[item['id']] = { ...item }
|
||||
list[item.id] = { ...item }
|
||||
})
|
||||
setList(() => ({ ...list }))
|
||||
}
|
||||
|
||||
//显示时展示数据
|
||||
// 显示时展示数据
|
||||
useEffect(() => {
|
||||
if (!show) {
|
||||
setList({})
|
||||
setSelectIndex(default_sale_mode || 0)
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
setLoading(true)
|
||||
getShoppingCart()
|
||||
setShowBindSalesman(() => false)
|
||||
@@ -145,56 +147,56 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
setShowPopup(show)
|
||||
}, [show])
|
||||
|
||||
//全选反选
|
||||
// 全选反选
|
||||
const [selectStatus, setSelectStatus] = useState(false)
|
||||
const selectAll = () => {
|
||||
Object.values(list)?.map((item) => {
|
||||
if (selectIndex == item.sale_mode) {
|
||||
item.selected = !selectStatus
|
||||
list[item['id']] = { ...item }
|
||||
list[item.id] = { ...item }
|
||||
}
|
||||
})
|
||||
setList(() => ({ ...list }))
|
||||
setSelectStatus(!selectStatus)
|
||||
}
|
||||
|
||||
//checkbox选中判断是否全部选中,全部选中后是全选,否则反选
|
||||
// checkbox选中判断是否全部选中,全部选中后是全选,否则反选
|
||||
useEffect(() => {
|
||||
let list_count = 0
|
||||
let select_count = 0
|
||||
Object.values(list)?.map((item) => {
|
||||
if (selectIndex == item.sale_mode) {
|
||||
list_count++
|
||||
if (item.selected) select_count++
|
||||
if (item.selected) { select_count++ }
|
||||
}
|
||||
})
|
||||
setSelectStatus(select_count == list_count)
|
||||
}, [list])
|
||||
|
||||
//修改数量
|
||||
// 修改数量
|
||||
const onChangeCount = useCallback((item) => {
|
||||
getInputValue(item)
|
||||
}, [])
|
||||
|
||||
//修改选择
|
||||
// 修改选择
|
||||
const onChangeSelect = useCallback((item) => {
|
||||
setList((e) => ({ ...e, [item.id]: { ...item } }))
|
||||
setList(e => ({ ...e, [item.id]: { ...item } }))
|
||||
}, [])
|
||||
|
||||
//popup关闭
|
||||
// popup关闭
|
||||
const closePopup = () => {
|
||||
onClose?.()
|
||||
setShowPopup(false)
|
||||
}
|
||||
|
||||
//删除购物车内容
|
||||
// 删除购物车内容
|
||||
const { fetchData: delShopFetchData } = DelShoppingCartApi()
|
||||
const delSelect = () => {
|
||||
getSelectId()
|
||||
if (selectIds.current.length <= 0) return alert.none('请选择要删除的面料!')
|
||||
if (selectIds.current.length <= 0) { return alert.none('请选择要删除的面料!') }
|
||||
Taro.showModal({
|
||||
content: '删除所选商品?',
|
||||
success: async function (res) {
|
||||
async success(res) {
|
||||
if (res.confirm) {
|
||||
const res = await delShopFetchData({ id: selectIds.current })
|
||||
if (res.success) {
|
||||
@@ -204,20 +206,22 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
title: '成功',
|
||||
icon: 'success',
|
||||
})
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Taro.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} else if (res.cancel) {
|
||||
}
|
||||
else if (res.cancel) {
|
||||
console.log('用户点击取消')
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//获取面料选中的id
|
||||
// 获取面料选中的id
|
||||
const selectIds = useRef<number[]>([])
|
||||
const getSelectId = () => {
|
||||
selectIds.current = []
|
||||
@@ -228,12 +232,12 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
})
|
||||
}
|
||||
|
||||
//预估金额和总条数
|
||||
// 预估金额和总条数
|
||||
const estimatePrice = useMemo(() => {
|
||||
let estimate_amount = 0
|
||||
let product_list = new Set() //面料
|
||||
let color_count = 0 //颜色数量
|
||||
let all_count = 0 //总数量
|
||||
const product_list = new Set() // 面料
|
||||
let color_count = 0 // 颜色数量
|
||||
let all_count = 0 // 总数量
|
||||
Object.values(list)?.map((item) => {
|
||||
if (item.selected) {
|
||||
estimate_amount += item.estimate_amount
|
||||
@@ -242,7 +246,7 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
all_count += item.sale_mode == 0 ? parseFloat(item.roll) : parseFloat(item.length)
|
||||
}
|
||||
})
|
||||
let all_count_text = selectIndex == 0 ? all_count + ' 条' : all_count / 100 + ' 米'
|
||||
const all_count_text = selectIndex == 0 ? `${all_count} 条` : `${all_count / 100} 米`
|
||||
console.log('text::', list)
|
||||
return {
|
||||
price: Number(formatPriceDiv(estimate_amount)).toFixed(2),
|
||||
@@ -251,13 +255,13 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
}
|
||||
}, [list])
|
||||
|
||||
//去结算
|
||||
// 去结算
|
||||
const { fetchData: useFetchData } = GetAdminUserInfoApi()
|
||||
const { fetchData: applyOrderAccessFetchData } = ApplyOrderAccessApi()
|
||||
const orderDetail = throttle(async () => {
|
||||
let res = await useFetchData()
|
||||
const orderDetail = throttle(async() => {
|
||||
const res = await useFetchData()
|
||||
if (res.data.order_access_status !== 3) {
|
||||
if (res.data.order_access_status == 1) applyOrderAccessFetchData()
|
||||
if (res.data.order_access_status == 1) { applyOrderAccessFetchData() }
|
||||
setShowBindSalesman(() => true)
|
||||
onClose?.()
|
||||
return false
|
||||
@@ -265,34 +269,37 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
getSelectId()
|
||||
if (selectIds.current.length == 0) {
|
||||
alert.error('请选择面料')
|
||||
} else {
|
||||
let ids = selectIds.current.join('-')
|
||||
setParam({ ids, sale_mode: selectIndex }) //临时存储
|
||||
}
|
||||
else {
|
||||
const ids = selectIds.current.join('-')
|
||||
setParam({ ids, sale_mode: selectIndex }) // 临时存储
|
||||
closePopup()
|
||||
if (intoStatus == 'again') {
|
||||
goLink('/pages/order/comfirm', null, 'redirectTo')
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
goLink('/pages/order/comfirm')
|
||||
}
|
||||
}
|
||||
}, 500)
|
||||
|
||||
//计数组件-当后端修改完成才修改前端显示
|
||||
// 计数组件-当后端修改完成才修改前端显示
|
||||
const { fetchData: fetchDataUpdateShoppingCart } = UpdateShoppingCartApi()
|
||||
const getInputValue = debounce(async (item) => {
|
||||
let res = await fetchDataUpdateShoppingCart({ id: item.id, roll: item.roll, length: item.length })
|
||||
const getInputValue = debounce(async(item) => {
|
||||
const res = await fetchDataUpdateShoppingCart({ id: item.id, roll: item.roll, length: item.length })
|
||||
if (res.success) {
|
||||
console.log('item修改::', item)
|
||||
getShoppingCartInfo(item)
|
||||
} else {
|
||||
setList((e) => ({ ...e }))
|
||||
}
|
||||
else {
|
||||
setList(e => ({ ...e }))
|
||||
}
|
||||
}, 300)
|
||||
|
||||
//绑定业务员和电话号码
|
||||
// 绑定业务员和电话号码
|
||||
const [showBindSalesman, setShowBindSalesman] = useState(false)
|
||||
|
||||
//显示图片弹窗
|
||||
// 显示图片弹窗
|
||||
const [showLabImage, setShowLabImage] = useState(false)
|
||||
const [labImageValue, setLabImageValue] = useState()
|
||||
const getLabAndImg = useCallback((val) => {
|
||||
@@ -326,7 +333,8 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
<View
|
||||
key={item.value}
|
||||
onClick={() => selectProduct(item.value)}
|
||||
className={classnames(styles.search_item, selectIndex == item.value && styles.search_item_select)}>
|
||||
className={classnames(styles.search_item, selectIndex == item.value && styles.search_item_select)}
|
||||
>
|
||||
{item.title}
|
||||
</View>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user