🌈 style(eslint): add eslint rules
This commit is contained in:
@@ -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/format'
|
||||
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/format'
|
||||
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)
|
||||
@@ -46,53 +46,55 @@ export default ({ show = false, onClose, intoStatus = 'shop', default_sale_mode
|
||||
setSelectStatus(true)
|
||||
}, [selectIndex])
|
||||
|
||||
//获取购物车数据数量
|
||||
// 获取购物车数据数量
|
||||
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()
|
||||
@@ -111,57 +113,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 = (item) => {
|
||||
checkboxData[item.id] = true
|
||||
checkSelect()
|
||||
setCheckboxData(() => ({ ...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 = (item) => {
|
||||
checkboxData[item.id] = false
|
||||
checkSelect()
|
||||
setCheckboxData(() => ({ ...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) {
|
||||
@@ -170,20 +172,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 = []
|
||||
@@ -194,27 +198,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
|
||||
@@ -223,7 +227,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}`,
|
||||
@@ -231,13 +235,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
|
||||
@@ -245,36 +249,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) => {
|
||||
@@ -303,7 +309,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>
|
||||
)
|
||||
@@ -318,7 +325,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}
|
||||
@@ -345,16 +353,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}
|
||||
|
||||
Reference in New Issue
Block a user