From 639112c038259eb18f60b2374570944ab0d08b39 Mon Sep 17 00:00:00 2001 From: xuan Date: Mon, 5 Dec 2022 16:30:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=88=20style(eslint):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Deslint=E7=9A=84=E6=8A=A5=E9=94=99=E2=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- global.d.ts | 3 + src/app.tsx | 6 +- src/common/common.ts | 50 +-- src/common/{constant.js => constant.ts} | 4 +- src/common/fotmat.js | 83 ++--- src/common/util.ts | 18 +- src/components/AddressList/index.tsx | 21 +- src/components/FromList/index.tsx | 17 +- .../FromListCertification/index.tsx | 17 +- src/components/InfiniteScrollPaging/index.tsx | 65 ++-- src/components/LabAndImg/index.tsx | 9 +- src/components/LabAndImgShow/index.tsx | 18 +- src/components/Message/index.tsx | 6 +- src/components/addCollection/index.tsx | 9 +- src/components/address/index.tsx | 126 ++++--- src/components/afterOrderBtns/index.tsx | 36 +- src/components/amountShow/index.tsx | 5 +- src/components/banner/index.tsx | 14 +- src/components/bindSalesmanPopup/index.tsx | 8 +- src/components/bluetooth/LinkBlueTooth.tsx | 27 +- src/components/bluetooth/Popup.tsx | 66 ++-- src/components/checkbox/index.tsx | 7 +- src/components/closeBtn/index.tsx | 6 +- src/components/counter/index.tsx | 65 ++-- src/components/dotLoading/index.tsx | 5 +- src/components/estimatedAmount/index.tsx | 21 +- src/components/filter/index.tsx | 5 +- src/components/filterV2/index.tsx | 12 +- src/components/infiniteScroll/index.tsx | 47 +-- src/components/loading/index.tsx | 11 +- src/components/loadingCard/index.tsx | 5 +- src/components/moveBtn/index.tsx | 8 +- src/components/orderBtns/index.tsx | 64 ++-- src/components/popup/index.tsx | 11 +- src/components/product/index.tsx | 6 +- src/components/search/index.tsx | 178 +++++----- src/components/searchInput/index.tsx | 8 +- .../shopCart/components/productItem/index.tsx | 8 +- src/components/shopCart/index copy.tsx | 20 +- src/components/shopCart/index.tsx | 113 +++--- src/components/sideBar/index.tsx | 245 +++++++------ src/components/sortBtn/index.tsx | 9 +- src/components/tabs/index.tsx | 8 +- src/components/textareaEnhance/index.tsx | 10 +- src/pages/addressManager/index.tsx | 9 +- .../components/cutKindList/index.tsx | 12 +- .../components/kindList/index.tsx | 12 +- .../components/otherReason/index.tsx | 10 +- .../components/reasonPopup/index.tsx | 5 +- src/pages/applyAfterSales/index.tsx | 38 +- .../component/successBind/index.tsx | 10 +- src/pages/bindSalesman/index.tsx | 12 +- .../components/SelectEnterpriseType.tsx | 8 +- src/pages/certification/index.tsx | 35 +- .../collection/collectionClass/index.tsx | 31 +- .../components/createPopup/index.tsx | 7 +- .../collection/components/product/index.tsx | 32 +- .../components/updatePopup/index.tsx | 9 +- src/pages/collection/index.tsx | 43 +-- src/pages/company/index.tsx | 35 +- src/pages/creditLine/index.tsx | 216 +++++------ src/pages/creditUsed/index.tsx | 8 +- src/pages/depositBeforehand/index.tsx | 4 +- src/pages/depositBeforehandDetail/index.tsx | 58 +-- src/pages/depositList/index.tsx | 4 +- .../details/components/counter/index.tsx | 44 +-- .../details/components/orderCount/index.tsx | 81 +++-- .../details/components/preview/index.tsx | 6 +- .../details/components/productItem/index.tsx | 7 +- src/pages/details/components/swiper/index.tsx | 9 +- src/pages/details/index.tsx | 72 ++-- .../components/shipmentMode/index.tsx | 9 +- src/pages/editOrder/index.tsx | 4 +- src/pages/index/components/product/index.tsx | 8 +- .../index/components/productClass/index.tsx | 11 +- src/pages/index/index.tsx | 54 +-- src/pages/order/comfirm.tsx | 55 ++- .../order/components/addressInfo/index.tsx | 41 ++- .../components/addressInfoDetail/index.tsx | 336 +++++++++--------- .../components/advanceOrderState/index.tsx | 6 +- .../order/components/amountShow/index.tsx | 5 +- .../order/components/applyRefund/index.tsx | 36 +- .../components/estimatedAmount/index.tsx | 21 +- src/pages/order/components/kindList/index.tsx | 10 +- .../order/components/movableAreaBtn/index.tsx | 8 +- .../order/components/offlinePay/index.tsx | 5 +- .../order/components/orderState/index.tsx | 10 +- .../order/components/orderStatusTag/index.tsx | 5 +- src/pages/order/components/payment/index.tsx | 11 +- .../order/components/reasonPopup/index.tsx | 5 +- src/pages/order/components/remark/index.tsx | 12 +- .../order/components/returnRecord/index.tsx | 21 +- src/pages/order/components/scanPay/index.tsx | 56 ++- .../order/components/scanPayCheck/index.tsx | 155 ++++---- .../order/components/shipmentMode/index.tsx | 9 +- .../order/components/submitOrderBtn/index.tsx | 7 +- .../order/components/weightMemo/index.tsx | 5 +- src/pages/order/index.tsx | 113 +++--- .../orderList/components/order/index.tsx | 7 +- .../components/orderStatusList/index.tsx | 7 +- src/pages/order/orderList/index.tsx | 97 +++-- src/pages/salesAfter/index.tsx | 245 +++++++------ src/pages/salesAfter/salesAfterList/index.tsx | 72 ++-- src/pages/search/index.tsx | 4 +- .../subjectList/components/filter/index.tsx | 10 +- src/pages/user/index.tsx | 214 +++++------ src/store/index.ts | 5 +- src/use/BlueToothCopy.tsx | 82 ++--- src/use/contextBlueTooth.tsx | 133 +++---- src/use/useCheckAuthorize.tsx | 16 +- src/use/useCommon.ts | 24 +- src/use/useLogin.ts | 116 +++--- src/use/useLoginRequest.ts | 22 +- src/use/useUploadImage.ts | 1 + 114 files changed, 2209 insertions(+), 2161 deletions(-) rename src/common/{constant.js => constant.ts} (94%) diff --git a/global.d.ts b/global.d.ts index 78b17be..38be54d 100644 --- a/global.d.ts +++ b/global.d.ts @@ -20,3 +20,6 @@ declare namespace NodeJS { declare const CURRENT_VERSION: string declare const CURRENT_GITHASH: string declare const CURRENT_ENV: string +declare const CURRENT_BASE_URL: string +declare const CURRENT_CAP_HTML_TO_IMAGE_BASE_URL: string +declare const CURRENT_PAY_H5_CODE_URL: string diff --git a/src/app.tsx b/src/app.tsx index 13e9a38..ae59bbe 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,13 +1,13 @@ +import Taro, { onAppShow, useDidShow } from '@tarojs/taro' import type { FC } from 'react' import { Provider } from 'react-redux' import configStore from './store' +import { shareShop } from './common/util' import ContextBlueTooth from '@/use/contextBlueTooth' import './app.scss' -import Taro, { onAppShow, useDidShow } from '@tarojs/taro' -import { shareShop } from './common/util' const store = configStore() -const App: FC = (params) => { +const App: FC = (params: { children?: React.ReactNode }) => { Taro.showShareMenu({ withShareTicket: true, }) diff --git a/src/common/common.ts b/src/common/common.ts index c9e63d2..38c5a7c 100644 --- a/src/common/common.ts +++ b/src/common/common.ts @@ -1,6 +1,25 @@ import Taro from '@tarojs/taro' import Qs from 'qs' +const setUrlQuery = (options: { url: string; query: object | null }) => { + let { url, query } = options + if (!url) { return '' } + if (query) { + const queryArr: any[] = [] + for (const key in query) { + if (query.hasOwnProperty(key)) { + queryArr.push(`${key}=${query[key]}`) + } + } + if (url.includes('?')) { + url = `${url}&${queryArr.join('&')}` + } + else { + url = `${url}?${queryArr.join('&')}` + } + } + return url +} /** * 跳转 * @param path @@ -16,25 +35,6 @@ export const goLink = (path = '', params: object | null = null, way: ParamLink = Taro[way]({ url: path }) } } -const setUrlQuery = (options: { url: string; query: object | null }) => { - let { url, query } = options - if (!url) { return '' } - if (query) { - const queryArr: any[] = [] - for (const key in query) { - if (query.hasOwnProperty(key)) { - queryArr.push(`${key}=${query[key]}`) - } - } - if (url.includes('?')) { - url = `${url}&${queryArr.join('&')}` - } - else { - url = `${url}?${queryArr.join('&')}` - } - } - return url -} /** * 判断对象为空 * @param object @@ -43,14 +43,14 @@ const setUrlQuery = (options: { url: string; query: object | null }) => { export const isEmptyObject = (object: any) => { if (object == undefined || object == null || Number.isNaN(object)) { return true - } + } else { if (object.constructor == Object) { return Reflect.ownKeys(object).length == 0 - } + } else if (object.constructor == Array) { return object.length == 0 - } + } else if (object.constructor == String) { return object == '' } @@ -88,12 +88,12 @@ export const retrieval = (data: any, rules?: Object, message = '请填写完信 if (item.validator(data[key], item)) { _res = true } - } + } else if (item.regex) { if (!item.regex.test(data[key])) { _res = true } - } + } else { if (isEmptyObject(data[key])) { _res = true @@ -106,7 +106,7 @@ export const retrieval = (data: any, rules?: Object, message = '请填写完信 if (result) { reject(message) } - } + } else { const keys = Reflect.ownKeys(data) if (keys.some((key: any) => isEmptyObject(data[key]))) { diff --git a/src/common/constant.js b/src/common/constant.ts similarity index 94% rename from src/common/constant.js rename to src/common/constant.ts index 2e26ffb..74c1972 100644 --- a/src/common/constant.js +++ b/src/common/constant.ts @@ -1,4 +1,4 @@ -export const BASE_URL = CURRENT_BASE_URL +// export const BASE_URL = CURRENT_BASE_URL // export const BASE_URL = `http://192.168.0.75:50001/lymarket` // export const BASE_URL = `http://192.168.0.89:50001/lymarket` // export const BASE_URL = `http://10.0.0.5:50001/lymarket` @@ -13,7 +13,7 @@ export const BASE_URL = CURRENT_BASE_URL // export const BASE_URL = `https://www.zzfzyc.com/lymarket` // 正式环境 // export const BASE_URL = `http://192.168.1.5:40001/lymarket` // 王霞 // export const BASE_URL = `http://192.168.1.7:50002/lymarket` // 添 -// export const BASE_URL = `http://192.168.1.28:50002/lymarket` // 婷 +export const BASE_URL = 'http://192.168.1.28:50002/lymarket' // 婷 // export const BASE_URL = `http://192.168.1.42:50002/lymarket` // 杰 // CDN diff --git a/src/common/fotmat.js b/src/common/fotmat.js index 05ece51..ccd0a7b 100644 --- a/src/common/fotmat.js +++ b/src/common/fotmat.js @@ -20,14 +20,36 @@ export const formatRemoveHashTag = (val = '') => { export const formatHashTag = (code = '', name = '', mode = 'both') => { if (mode == 'both') { return `${formatRemoveHashTag(code)}# ${name}` - } + } else if (mode == 'name') { return `${name}` } } const Digit = 10 * 10 - +/** + * 精度 + * @param {*} num + * @param {*} precision + * @returns + */ +export const strip = (num, precision = 12) => { + return +parseFloat(num.toPrecision(precision)) +} +/** + * + * @param {千位分割付} number + * @returns + */ +export const numberWithCommas = ({ number = 0, digit = 2 }) => { + if (!Number.isNaN(Number(number))) { + // return parseFloat(number).toFixed(digit).replace(/^\B(? { .replace('ss', s.toString().padStart(2, '0')) return fmt - } + } else { return val } } -/** - * 精度 - * @param {*} num - * @param {*} precision - * @returns - */ -export const strip = (num, precision = 12) => { - return +parseFloat(num.toPrecision(precision)) -} - -/** - * 转换金额单位 - * @param {*} num 金额 / 数值 - * @param {*} digit 转换单位 - * @returns - */ -export const formatMillionYuan = (num, digit = 10000) => { - return num / digit > 1 ? { num: toDecimal2(num / digit), million: true } : { num, million: false } -} - /** * 数值保留两位小数 * @param {*} x @@ -123,7 +125,7 @@ export const formatMillionYuan = (num, digit = 10000) => { */ export const toDecimal2 = (x) => { let f = parseFloat(x) - if (isNaN(f)) { + if (Number.isNaN(f)) { return 0 } f = `${f}` @@ -132,14 +134,22 @@ export const toDecimal2 = (x) => { const decimal = f.substring(index + 1) if (decimal.length == 1) { f = `${f.substring(0, index + 1) + decimal}0` - } + } else { f = f.substring(0, index + 1) + decimal.substring(0, 2) } } return f } - +/** + * 转换金额单位 + * @param {*} num 金额 / 数值 + * @param {*} digit 转换单位 + * @returns + */ +export const formatMillionYuan = (num, digit = 10000) => { + return num / digit > 1 ? { num: toDecimal2(num / digit), million: true } : { num, million: false } +} /** * 格式化图片路径 * @param {*} url @@ -149,7 +159,7 @@ export const toDecimal2 = (x) => { export const formatImgUrl = (url, suffix = '!w200') => { if (url) { return url.includes('http') ? url + suffix : IMG_CND_Prefix + url + suffix - } + } else { return `${IMG_CND_Prefix}/mall/no_img.png` } @@ -165,26 +175,11 @@ export const formatImgUrl = (url, suffix = '!w200') => { export const isLabImage = (imgurl, rgb, suffix = '!w200') => { if (imgurl) { return { status: 1, value: `${IMG_CND_Prefix}/${imgurl}${suffix}` } - } + } else if (rgb.r != 0 || rgb.g != 0 || rgb.b != 0) { return { status: 2, value: rgb } - } + } else { return { status: 3, value: `${IMG_CND_Prefix}/mall/no_img.png` } } } - -/** - * - * @param {千位分割付} number - * @returns - */ -export const numberWithCommas = ({ number = 0, digit = 2 }) => { - if (!isNaN(Number(number))) { - // return parseFloat(number).toFixed(digit).replace(/^\B(? { for (const key in val) { if (val[key] !== undefined && val[key] !== null && val[key] !== '' && !arr.includes(key)) { if (typeof val[key] == 'number') { - if (!isNaN(val[key])) { + if (!Number.isNaN(val[key])) { res[key] = val[key] } - } + } else { res[key] = val[key] } @@ -66,16 +66,16 @@ export const copyObject = (object) => { if (object.constructor == Object) { const keys = Object.keys(object) const newObject = {} - keys.map((key) => { + keys.forEach((key) => { newObject[key] = copyObject(object[key]) }) return newObject - } + } else if (object.constructor == Array) { return object.map((item) => { return copyObject(item) }) - } + } else { return object } @@ -101,13 +101,13 @@ export const screenshot = (url, suffix = '!w200') => { export const dataLoadingStatus = ({ list = [], total = 0, status = false }: { list: any[]; total: number; status: true | false }) => { if (list.length == 0 && status) { return 0 - } + } else if (list.length == 0 && !status) { return 1 - } + } else if (list.length < total) { return 2 - } + } else { return 3 } @@ -132,7 +132,7 @@ export const shareShop = () => { path = `/pages/details/index?share=${sortCode.shareShortDetail.code}` title = sortCode.shareShortDetail.title imageUrl = sortCode.shareShortDetail.img - } + } else { path = pageInfo.route === 'pages/user/index' diff --git a/src/components/AddressList/index.tsx b/src/components/AddressList/index.tsx index e060cb6..5be6c9b 100644 --- a/src/components/AddressList/index.tsx +++ b/src/components/AddressList/index.tsx @@ -1,10 +1,10 @@ import { Button, Navigator, ScrollView, Text, View } from '@tarojs/components' +import Taro, { showModal } from '@tarojs/taro' import { memo, useEffect, useState } from 'react' import './index.scss' import { addressDeleteApi, addressListApi } from '@/api/addressManager' import { alert } from '@/common/common' -import Taro, { showModal } from '@tarojs/taro' interface Params{ refresherEnabled?: boolean// 是否开启刷新 @@ -15,15 +15,18 @@ interface Params{ } // 地址列表 -const AddressList = memo((props: Params) => { +const AddressList = (props: Params) => { const { addButtonEnabled = true, focusBorderEnabled = false } = props const { fetchData, state } = addressListApi() + + // 焦点 + const [focusId, setFocusId] = useState() // 获取数据 const getData = async() => { const result = await fetchData() if (props.id) { setFocusId(props.id as any) - } + } else { result.data.list?.every((item) => { if (item.is_default) { @@ -50,8 +53,6 @@ const AddressList = memo((props: Params) => { setRefreshState(false) } const data = Array.from({ length: 15 }) - // 焦点 - const [focusId, setFocusId] = useState() // 列表选择 const handleSelect = (item: any, index: number) => { props.onSelect && props.onSelect(item, index) @@ -71,7 +72,7 @@ const AddressList = memo((props: Params) => { if (result.success) { alert.success('删除成功') getData() - } + } else { alert.success(result.msg) } @@ -90,11 +91,11 @@ const AddressList = memo((props: Params) => { // data.length>0? // data.map((item,index)=>{ return ( - handleDelete(item)} onClick={() => handleSelect(item, index)} className={`address-list ${focusId == item.id && 'address-active'}`}> + handleDelete(item)} onClick={() => handleSelect(item, index)} className={`address-list ${focusId == item.id && 'address-active'}`}> {item.name} { - item.is_default + item.is_default ? 默认 : {item.phone.replace(item.phone.substring(3, 7), '****')} } @@ -122,6 +123,6 @@ const AddressList = memo((props: Params) => { {addButtonEnabled && 添加收货地址} ) -}) +} -export default AddressList +export default memo(AddressList) diff --git a/src/components/FromList/index.tsx b/src/components/FromList/index.tsx index ee4839d..e9afd21 100644 --- a/src/components/FromList/index.tsx +++ b/src/components/FromList/index.tsx @@ -16,9 +16,7 @@ interface ListParams { contentStyle?: object required?: boolean } - -// 表单列表 -const FromList = memo((props: ListParams) => { +const FromList = (props: ListParams) => { const { type = 'input', value = '', style = {}, labelStyle = {}, contentStyle = {}, required = false } = props return ( @@ -29,7 +27,7 @@ const FromList = memo((props: ListParams) => { {props.children ?? ( - {type == 'input' + {type == 'input' ? ( { )} - ) - : type == 'textarea' + ) + : type == 'textarea' ? ( - || toggleShowRealTextarea(true)}>{descData.value || placeholder} + {(descData.show && !onlyRead) + ? + : toggleShowRealTextarea(true)}>{descData.value || placeholder} } {`${descData.number}/${descData.count}`} ) -}) +} +export default memo(TextareaEnhance) diff --git a/src/pages/addressManager/index.tsx b/src/pages/addressManager/index.tsx index 0d32548..4c08f27 100644 --- a/src/pages/addressManager/index.tsx +++ b/src/pages/addressManager/index.tsx @@ -1,16 +1,15 @@ -import { Button, ScrollView, Text, View } from '@tarojs/components' -import { stopPullDownRefresh, usePullDownRefresh } from '@tarojs/taro' -import { useState } from 'react' +import { View } from '@tarojs/components' import useLogin from '@/use/useLogin' import AddressList from '@/components/AddressList' import './index.scss' -export default () => { +const AddressManager = () => { useLogin() return ( ) -} +} +export default AddressManager diff --git a/src/pages/applyAfterSales/components/cutKindList/index.tsx b/src/pages/applyAfterSales/components/cutKindList/index.tsx index b97cf66..556c2fa 100644 --- a/src/pages/applyAfterSales/components/cutKindList/index.tsx +++ b/src/pages/applyAfterSales/components/cutKindList/index.tsx @@ -1,5 +1,5 @@ import { Image, Text, View } from '@tarojs/components' -import type { FC } from 'react' +import type { FC } from 'react' import { memo, useCallback } from 'react' import styles from './index.module.scss' import { formatHashTag, formatImgUrl } from '@/common/fotmat' @@ -23,7 +23,7 @@ interface Param { onSelectChange?: (val: { color_id: number; length: number; status: true|false; sale_order_detail_id: number }) => void } -const kindeList: FC = memo(({ order, onSelectChange }) => { +const KindeList: FC = ({ order, onSelectChange }) => { // checkbox选中回调 const selectCallBack = (colorItem) => { onSelectChange?.({ color_id: colorItem.product_color_id, length: colorItem.length, sale_order_detail_id: colorItem.sale_order_detail_id, status: true }) @@ -36,13 +36,13 @@ const kindeList: FC = memo(({ order, onSelectChange }) => { return ( - {order?.av_return_product?.map(item => + {order?.av_return_product?.map((item, index) => {order.sale_mode_name} {formatHashTag(item.product_code, item.product_name)} - {item?.av_product_color?.map(colorItem => + {item?.av_product_color?.map((colorItem, key) => {`${colorItem.product_color_code} ${colorItem.product_color_name}`}x {colorItem.length / 100} m selectCallBack(colorItem)} onClose={() => colseCallBack(colorItem)} /> @@ -51,6 +51,6 @@ const kindeList: FC = memo(({ order, onSelectChange }) => { )} ) -}) +} -export default kindeList +export default memo(KindeList) diff --git a/src/pages/applyAfterSales/components/kindList/index.tsx b/src/pages/applyAfterSales/components/kindList/index.tsx index 85b7d98..ab3d25a 100644 --- a/src/pages/applyAfterSales/components/kindList/index.tsx +++ b/src/pages/applyAfterSales/components/kindList/index.tsx @@ -1,5 +1,5 @@ import { Image, Text, View } from '@tarojs/components' -import type { FC } from 'react' +import type { FC } from 'react' import { memo, useCallback } from 'react' import styles from './index.module.scss' import { formatHashTag, formatImgUrl } from '@/common/fotmat' @@ -23,7 +23,7 @@ interface Param { onNumChange?: (val: any) => void } -const kindeList: FC = memo(({ order, onNumChange }) => { +const KindeList: FC = ({ order, onNumChange }) => { // 计步器返回值 const getCounterChange = useCallback((colorItem) => { return (number) => { @@ -33,13 +33,13 @@ const kindeList: FC = memo(({ order, onNumChange }) => { return ( - {order?.av_return_product?.map(item => + {order?.av_return_product?.map((item, index) => {order.sale_mode_name} {formatHashTag(item.product_code, item.product_name)} - {item?.av_product_color?.map(colorItem => + {item?.av_product_color?.map((colorItem, key) => {`${colorItem.product_color_code} ${colorItem.product_color_name}`}x {colorItem.roll} @@ -50,6 +50,6 @@ const kindeList: FC = memo(({ order, onNumChange }) => { )} ) -}) +} -export default kindeList +export default memo(KindeList) diff --git a/src/pages/applyAfterSales/components/otherReason/index.tsx b/src/pages/applyAfterSales/components/otherReason/index.tsx index 0f48e08..6af670c 100644 --- a/src/pages/applyAfterSales/components/otherReason/index.tsx +++ b/src/pages/applyAfterSales/components/otherReason/index.tsx @@ -7,7 +7,7 @@ import styles from './index.module.scss' interface Param { onChange: (val: string) => void } -export default memo(({ onChange }: Param) => { +const OtherReason = ({ onChange }: Param) => { const [descData, setDescData] = useState({ number: 0, value: '', @@ -31,11 +31,13 @@ export default memo(({ onChange }: Param) => { 其他说明 - {descData.show && - || toggleShowRealTextarea(true)}>{descData.value || '一般情况下选填,当退货说明=“其它问题”时,必填'} + {descData.show + ? + : toggleShowRealTextarea(true)}>{descData.value || '一般情况下选填,当退货说明=“其它问题”时,必填'} } {`${descData.number}/${descData.count}`} ) -}) +} +export default memo(OtherReason) diff --git a/src/pages/applyAfterSales/components/reasonPopup/index.tsx b/src/pages/applyAfterSales/components/reasonPopup/index.tsx index 610f300..04062c7 100644 --- a/src/pages/applyAfterSales/components/reasonPopup/index.tsx +++ b/src/pages/applyAfterSales/components/reasonPopup/index.tsx @@ -17,7 +17,7 @@ interface ReasonInfoParam { defaultValue?: number // 默认选中 dataLength?: number // 可显示的数据列数 } -export default memo(({ show = false, onClose, title = '', list = [], onSelect, onHeaderSelect, defaultValue, dataLength = 1 }: ReasonInfoParam) => { +const ReasonPopup = ({ show = false, onClose, title = '', list = [], onSelect, onHeaderSelect, defaultValue, dataLength = 1 }: ReasonInfoParam) => { const [initList, setInitList] = useState([]) useEffect(() => { @@ -59,4 +59,5 @@ export default memo(({ show = false, onClose, title = '', list = [], onSelect, o ) -}) +} +export default memo(ReasonPopup) diff --git a/src/pages/applyAfterSales/index.tsx b/src/pages/applyAfterSales/index.tsx index 174e036..dbbc501 100644 --- a/src/pages/applyAfterSales/index.tsx +++ b/src/pages/applyAfterSales/index.tsx @@ -19,11 +19,8 @@ enum returnStatus { goods_status = 2, // 状况 return_explain = 3, // 说明 } -export default () => { +const ApplyAfterSales = () => { useLogin() - useDidShow(() => { - getSaleOrderPreView() - }) const router = useRouter() const orderId = useRef(Number(router.params.id)) @@ -50,13 +47,9 @@ export default () => { } } - // 监听获取到的数据 - useEffect(() => { - if (orderDetail) { - formatData() - } - }, [orderDetail]) - + useDidShow(() => { + getSaleOrderPreView() + }) // 格式化数据格式 const [formatDetailOrder, setFormatDetailOrder] = useState() // 格式化后的数据 const formatData = () => { @@ -82,18 +75,23 @@ export default () => { const getNumChange = useCallback((val) => { if (parseInt(val.number) > 0) { roll_list.current[val.color_id] = { product_roll: val.number, sale_order_detail_id: val.sale_order_detail_id } - } + } else { delete roll_list.current[val.color_id] } setSubmitData(e => ({ ...e, roll_list: Object.values(roll_list.current) })) }, []) - + // 监听获取到的数据 + useEffect(() => { + if (orderDetail) { + formatData() + } + }, [orderDetail]) // 散剪和剪板 const getSelectChange = useCallback((val) => { if (val.status) { roll_list.current[val.sale_order_detail_id] = { product_roll: val.length, sale_order_detail_id: val.sale_order_detail_id } - } + } else { delete roll_list.current[val.sale_order_detail_id] } @@ -119,7 +117,7 @@ export default () => { if (res.success) { alert.success('申请成功') goLink('/pages/salesAfter/salesAfterList/index', {}, 'reLaunch') - } + } else { alert.error(res.msg) } @@ -132,7 +130,7 @@ export default () => { if (submitData.return_explain === '') { return alert.error('请选择退货原因') } if (!submitData.return_explain && !submitData.reason_describe) { return alert.error('请填写其他说明') } onSubmitData() - } + } else { Taro.navigateBack() } @@ -144,9 +142,6 @@ export default () => { const onShowReason = () => { setShowReason(true) } - useEffect(() => { - getReturnReason() - }, []) // 请求获取到的数据 const [returnGoodsInfo, setReturnGoodsInfo] = useState([]) @@ -157,6 +152,9 @@ export default () => { const res = await fetchDataReturnReason() setReturnGoodsInfo(e => res.data?.list) } + useEffect(() => { + getReturnReason() + }, []) // 售后退货说明 const { fetchData: fetchDataReturnExplain } = ReturnExplainApi() const getReturnExplain = async(id) => { @@ -273,3 +271,5 @@ export default () => { ) } + +export default ApplyAfterSales diff --git a/src/pages/bindSalesman/component/successBind/index.tsx b/src/pages/bindSalesman/component/successBind/index.tsx index 60ec1c7..c74c8ee 100644 --- a/src/pages/bindSalesman/component/successBind/index.tsx +++ b/src/pages/bindSalesman/component/successBind/index.tsx @@ -11,10 +11,10 @@ interface params { onClose?: () => void saleMan?: string } -export default ({ show = false, saleMan = '', onClose }: params) => { +const SuccessBind = ({ show = false, saleMan = '', onClose }: params) => { const onClick = async() => { onClose?.() - goLink('/pages/index/index', {}, 'switchTab') + goLink('/pages/index/index', {}, 'switchTab') } const onCloseEven = () => { onClose?.() @@ -35,5 +35,7 @@ export default ({ show = false, saleMan = '', onClose }: params) => { } - ) -} + ) +} + +export default SuccessBind diff --git a/src/pages/bindSalesman/index.tsx b/src/pages/bindSalesman/index.tsx index 411516d..1a20bf7 100644 --- a/src/pages/bindSalesman/index.tsx +++ b/src/pages/bindSalesman/index.tsx @@ -11,13 +11,9 @@ import CloseBtn from '@/components/closeBtn' import { BindInvitationInfoApi, GetInvitationInfoApi } from '@/api/user' import { debounce, getFilterData, throttle } from '@/common/util' -export default () => { +const BindSalesman = () => { useLogin() - useEffect(() => { - onClipboardData() - }, []) - const [submitData, setSubmitData] = useState({ invitation_code: '', }) @@ -71,7 +67,9 @@ export default () => { }, }) } - + useEffect(() => { + onClipboardData() + }, []) return ( @@ -113,3 +111,5 @@ export default () => { ) } + +export default BindSalesman diff --git a/src/pages/certification/components/SelectEnterpriseType.tsx b/src/pages/certification/components/SelectEnterpriseType.tsx index 0e8cef3..0945711 100644 --- a/src/pages/certification/components/SelectEnterpriseType.tsx +++ b/src/pages/certification/components/SelectEnterpriseType.tsx @@ -1,14 +1,13 @@ import { Text, View } from '@tarojs/components' +import { forwardRef, useEffect, useImperativeHandle, useState } from 'react' import Popup from '@/components/popup' import './SelectEnterpriseType.scss' -import { forwardRef, useEffect, useImperativeHandle, useState } from 'react' import { certificationTypeListApi } from '@/api/certification' interface Params{ confirm?: (selected: any) => void // 确定 } - -export default forwardRef((props: Params, ref) => { +const SelectEnterpriseType = (props: Params, ref) => { const [modalShow, setModalShow] = useState(false) // 获取认证信息 const { fetchData, state } = certificationTypeListApi() @@ -53,4 +52,5 @@ export default forwardRef((props: Params, ref) => { ) -}) +} +export default forwardRef(SelectEnterpriseType) diff --git a/src/pages/certification/index.tsx b/src/pages/certification/index.tsx index e9fb037..05ae725 100644 --- a/src/pages/certification/index.tsx +++ b/src/pages/certification/index.tsx @@ -13,22 +13,9 @@ import { IMG_CND_Prefix } from '@/common/constant' import { useSelector } from '@/reducers/hooks' import useLogin from '@/use/useLogin' -export default () => { +const Certification = () => { const { getAdminUserInfo } = useLogin() const { adminUserInfo } = useSelector(state => state.userInfo) - useEffect(() => { - initalFormData() - }, []) - // 获取认证信息 - const { fetchData: getFromData } = certificationDetailApi() - const initalFormData = async() => { - const detail = await getFromData() - setFormData({ - ...detail.data ?? {}, - legal_person_identity_url: detail?.data?.legal_person_identity_url ?? [], - // business_license_url: "https://test.cdn.zzfzyc.com/mall/827082e888860dd9da10f0fbb0ac3cf023081456.png" - } as any) - } // 保存 const [formData, setFormData] = useState({ authentication_type: 0, @@ -40,6 +27,20 @@ export default () => { legal_person_identity_url: [], name: '', }) + // 获取认证信息 + const { fetchData: getFromData } = certificationDetailApi() + const initalFormData = async() => { + const detail = await getFromData() + setFormData({ + ...detail.data ?? {}, + legal_person_identity_url: detail?.data?.legal_person_identity_url ?? [], + // business_license_url: "https://test.cdn.zzfzyc.com/mall/827082e888860dd9da10f0fbb0ac3cf023081456.png" + } as any) + } + useEffect(() => { + initalFormData() + }, []) + const rules = { // authentication_type: [{ // message: "请选择认证类型" @@ -79,7 +80,7 @@ export default () => { getAdminUserInfo() Taro.navigateBack() alert.success('保存成功') - } + } else { alert.error(result.msg) } @@ -113,7 +114,7 @@ export default () => { const result = await getWxPhoto('mall') if (text == 'business_license_url') { formData.business_license_url = IMG_CND_Prefix + (result as any).url - } + } else { formData.legal_person_identity_url[text] = IMG_CND_Prefix + (result as any).url as never } @@ -201,3 +202,5 @@ export default () => { ) } + +export default Certification diff --git a/src/pages/collection/collectionClass/index.tsx b/src/pages/collection/collectionClass/index.tsx index 101d0ef..4890963 100644 --- a/src/pages/collection/collectionClass/index.tsx +++ b/src/pages/collection/collectionClass/index.tsx @@ -11,12 +11,15 @@ import { DelFavoriteProductApi, DetailFavoriteProductApi, MoveFavoriteProductApi import MCheckbox from '@/components/checkbox' import AddCollection from '@/components/addCollection' -export default () => { +const CollectionClass = () => { const router = useRouter() // 获取收藏夹面料 const { fetchData: fetchDataDetailFavoriteProduct } = DetailFavoriteProductApi() const [colorInfo, setColorInfo] = useState({}) + + // 获取搜索数据 + const [searchData, setSearchData] = useState({ id: 0, code_or_name: '' }) const getFavoriteInfo = async() => { const res = await fetchDataDetailFavoriteProduct(searchData) if (res.success) { @@ -27,8 +30,6 @@ export default () => { } } - // 获取搜索数据 - const [searchData, setSearchData] = useState({ id: 0, code_or_name: '' }) const onSearch = useCallback((e) => { setSearchData(val => ({ ...val, code_or_name: e })) }, []) @@ -53,26 +54,17 @@ export default () => { // 全选反选 const [allSelectStatus, setAllSelectStatus] = useState(false) - const selectCallBack = useCallback(() => { - setAllSelectStatus(() => true) - setSelectStatus(1) - }, []) - const colseCallBack = useCallback(() => { - setAllSelectStatus(() => false) - setSelectStatus(3) - }, []) - const [selectStatus, setSelectStatus] = useState<1 | 2 | 3>(3) useEffect(() => { if (colorInfo.product_color_list?.length) { if (ids.length == colorInfo.product_color_list.length) { setSelectStatus(1) setAllSelectStatus(true) - } + } else if (ids.length > 0 && ids.length < colorInfo.product_color_list.length) { setSelectStatus(2) setAllSelectStatus(false) - } + } else { setSelectStatus(3) setAllSelectStatus(false) @@ -84,7 +76,14 @@ export default () => { const closeCollection = useCallback(() => { setCollectionShow(false) }, []) - + const selectCallBack = useCallback(() => { + setAllSelectStatus(() => true) + setSelectStatus(1) + }, []) + const colseCallBack = useCallback(() => { + setAllSelectStatus(() => false) + setSelectStatus(3) + }, []) // 移动面料 const { fetchData: fetchDataMoveFavoriteProduct } = MoveFavoriteProductApi() const onAdd = async(val) => { @@ -145,3 +144,5 @@ export default () => { ) } + +export default CollectionClass diff --git a/src/pages/collection/components/createPopup/index.tsx b/src/pages/collection/components/createPopup/index.tsx index f4111f4..249acdf 100644 --- a/src/pages/collection/components/createPopup/index.tsx +++ b/src/pages/collection/components/createPopup/index.tsx @@ -17,7 +17,7 @@ interface ReasonInfoParam { name: string } // 默认数据 } -export default memo(({ show = false, onClose, onSuccess, defaultValue }: ReasonInfoParam) => { +const CreatePopup = ({ show = false, onClose, onSuccess, defaultValue }: ReasonInfoParam) => { const submitData = useRef({ name: '', remark: '', @@ -36,7 +36,7 @@ export default memo(({ show = false, onClose, onSuccess, defaultValue }: ReasonI } useEffect(() => { - submitData.current = { name: defaultValue?.name!, remark: defaultValue?.remark! } + submitData.current = { name: defaultValue?.name as string, remark: defaultValue?.remark as string } }, [defaultValue]) return ( @@ -71,4 +71,5 @@ export default memo(({ show = false, onClose, onSuccess, defaultValue }: ReasonI ) -}) +} +export default memo(CreatePopup) diff --git a/src/pages/collection/components/product/index.tsx b/src/pages/collection/components/product/index.tsx index c7a6d53..6ae665e 100644 --- a/src/pages/collection/components/product/index.tsx +++ b/src/pages/collection/components/product/index.tsx @@ -13,7 +13,7 @@ interface Params { selectStatus?: 1|2|3 // 1全选,2不做处理,3全清空 openCheckBox?: true|false // 是否开启选择 } -export default ({ productList, onSelectIds, selectStatus = 2, openCheckBox = false }: Params) => { +const Product = ({ productList, onSelectIds, selectStatus = 2, openCheckBox = false }: Params) => { const [list, setList] = useState([]) useEffect(() => { setList(() => productList || []) @@ -21,22 +21,12 @@ export default ({ productList, onSelectIds, selectStatus = 2, openCheckBox = fal useEffect(() => { if (list.length && selectStatus != 2) { - list.map((item) => { + list.forEach((item) => { item.check = (selectStatus == 1) }) setList(() => [...list]) - } - }, [selectStatus]) - - const onChangeSelect = (item) => { - if (item.check) { - onClose(item) - } - else { - onSelect(item) } - } - + }, [selectStatus]) // 选中和取消选中 const onSelect = (item) => { item.check = true @@ -46,11 +36,19 @@ export default ({ productList, onSelectIds, selectStatus = 2, openCheckBox = fal item.check = false setList(() => ([...list])) } + const onChangeSelect = (item) => { + if (item.check) { + onClose(item) + } + else { + onSelect(item) + } + } // 监听数据变化 useEffect(() => { const ids: number[] = [] - list.map((item) => { + list.forEach((item) => { if (item.check) { ids.push(item.product_id) } }) onSelectIds?.(ids) @@ -58,8 +56,8 @@ export default ({ productList, onSelectIds, selectStatus = 2, openCheckBox = fal return ( - {list?.map((item) => { - return openCheckBox ? onChangeSelect(item) : goLink(`/pages/details/index?id=${item.product_id}`)}> + {list?.map((item, index) => { + return openCheckBox ? onChangeSelect(item) : goLink(`/pages/details/index?id=${item.product_id}`)}> {openCheckBox && e.stopPropagation()}> onSelect(item)} onClose={() => onClose(item)} /> } @@ -81,3 +79,5 @@ export default ({ productList, onSelectIds, selectStatus = 2, openCheckBox = fal ) } + +export default Product diff --git a/src/pages/collection/components/updatePopup/index.tsx b/src/pages/collection/components/updatePopup/index.tsx index c47da89..0b59fbe 100644 --- a/src/pages/collection/components/updatePopup/index.tsx +++ b/src/pages/collection/components/updatePopup/index.tsx @@ -16,14 +16,14 @@ interface ReasonInfoParam { onDelete?: () => void // 删除 } -export default memo(({ show = false, onClose, onUpdate, onBatchManagement, onDelete }: ReasonInfoParam) => { +const UpdatePopup = ({ show = false, onClose, onUpdate, onBatchManagement, onDelete }: ReasonInfoParam) => { const onClickEven = (val) => { if (val == 1) { onUpdate?.() - } + } else if (val == 2) { onBatchManagement?.() - } + } else { onDelete?.() } @@ -46,4 +46,5 @@ export default memo(({ show = false, onClose, onUpdate, onBatchManagement, onDel ) -}) +} +export default memo(UpdatePopup) diff --git a/src/pages/collection/index.tsx b/src/pages/collection/index.tsx index 738c309..f5a7ac6 100644 --- a/src/pages/collection/index.tsx +++ b/src/pages/collection/index.tsx @@ -1,4 +1,5 @@ import Taro, { useDidHide, useDidShow } from '@tarojs/taro' +import { Text, View } from '@tarojs/components' import classnames from 'classnames' import { useCallback, useEffect, useRef, useState } from 'react' import Product from './components/product' @@ -10,25 +11,15 @@ import { getFilterData } from '@/common/util' import { alert, goLink } from '@/common/common' import { CreateFavoriteApi, DelFavoriteApi, FavoriteListApi, UpdateFavoriteApi } from '@/api/favorite' import useLogin from '@/use/useLogin' -import { View, Text } from '@tarojs/components' -export default () => { +const Collection = () => { useLogin() - const changeOpenCon = (item) => { - item.openStatus = !item.openStatus - setList(e => [...e]) - } - useDidShow(() => { - getFavoriteList() - }) + // 获取搜索数据 const [searchData, setSearchData] = useState('') const onSearch = useCallback((e) => { setSearchData(() => e) }, []) - useEffect(() => { - getFavoriteList() - }, [searchData]) // 获取列表 const [list, setList] = useState([]) @@ -37,18 +28,32 @@ export default () => { const res = await fetchDataList(getFilterData({ name: searchData })) setList(() => res.data.list) } - + const changeOpenCon = (item) => { + item.openStatus = !item.openStatus + setList(e => [...e]) + } + useDidShow(() => { + getFavoriteList() + }) // 创建收藏夹 const [collectioinShow, setCollectioinShow] = useState(false) const closeCollection = useCallback(() => { setCollectioinShow(false) }, []) + // 更多编辑 + const [initData, setInitData] = useState({ + remark: '', + name: '', + id: 0, + }) const creatShow = () => { setCollectioinShow(true) setInitData(() => ({ remark: '', name: '', id: 0 })) } - + useEffect(() => { + getFavoriteList() + }, [searchData]) // 新增 const { fetchData } = CreateFavoriteApi() const onCreate = async(submitData) => { @@ -63,12 +68,6 @@ export default () => { } } - // 更多编辑 - const [initData, setInitData] = useState({ - remark: '', - name: '', - id: 0, - }) const selectInfo = useRef(null) const [updateShow, setUpdateShow] = useState(false) const closeUpdate = useCallback(() => { @@ -149,7 +148,7 @@ export default () => { - {list?.map((item: any) => + {list?.map((item: any, key) => changeOpenCon(item)}> {item.name} @@ -167,3 +166,5 @@ export default () => { ) } + +export default Collection diff --git a/src/pages/company/index.tsx b/src/pages/company/index.tsx index 955d420..fdd5285 100644 --- a/src/pages/company/index.tsx +++ b/src/pages/company/index.tsx @@ -9,26 +9,12 @@ import { companyDetailApi, companyUpdateApi } from '@/api/company' import './index.scss' import useLogin from '@/use/useLogin' -export default () => { +const Company = () => { useLogin() const [showSiteModal, setShowSiteModal] = useState(false) const handleSelectSite = () => { setShowSiteModal(true) } - // 获取公司信息 - const { fetchData: getFromData } = companyDetailApi() - const getData = async() => { - const result = await getFromData() - console.log(result.data, '===') - - setFormData({ - ...result.data, - - }) - } - useEffect(() => { - getData() - }, []) // 保存 const [formData, setFormData] = useState({ address_detail: '', @@ -46,6 +32,21 @@ export default () => { site: '', siteArray: [], }) + // 获取公司信息 + const { fetchData: getFromData } = companyDetailApi() + const getData = async() => { + const result = await getFromData() + console.log(result.data, '===') + + setFormData({ + ...result.data, + + }) + } + useEffect(() => { + getData() + }, []) + const rules = { company_name: [{ message: '请输入公司名称', @@ -145,7 +146,9 @@ export default () => { {/*
setShowSiteModal(false)} show={showSiteModal}/> */} -
setShowSiteModal(false)} show={showSiteModal} /> +
setShowSiteModal(false)} show={showSiteModal} /> ) } + +export default Company diff --git a/src/pages/creditLine/index.tsx b/src/pages/creditLine/index.tsx index a44a43e..80eabe1 100644 --- a/src/pages/creditLine/index.tsx +++ b/src/pages/creditLine/index.tsx @@ -1,7 +1,7 @@ import { Button, Canvas, Navigator, ScrollView, Text, View } from '@tarojs/components' import Taro, { useReady } from '@tarojs/taro' -import { useEffect, useState } from 'react' +import React, { useEffect, useState } from 'react' import AddressList from '@/components/AddressList' import { creditInfoApi } from '@/api/creditLine' import './index.scss' @@ -10,12 +10,109 @@ import { formatDateTime, formatPriceDiv } from '@/common/fotmat' import Message from '@/components/Message' import useLogin from '@/use/useLogin' -export default () => { +interface ProgressType { + progress: number + style: Record +} +const Progress = (props: ProgressType) => { + const getCanvas = () => { + // const percentage = props.progress??0; + const percentage = props.progress || 0 + const query = Taro.createSelectorQuery() + query.select('#myCanvas').fields({ node: true, size: true }).exec((res) => { + const canvas = res[0]?.node + if (canvas) { + const ctx = canvas.getContext('2d') + const { windowHeight, windowWidth } = Taro.getSystemInfoSync() + const dpr = 750 / windowWidth + canvas.width = res[0].width * dpr + canvas.height = res[0].height * dpr + const r = canvas.width / 2 + ctx.translate(r, r) + + // 白色大圆 + ctx.beginPath() + ctx.fillStyle = 'white' + ctx.shadowBlur = 20 + ctx.shadowColor = '#cde5ff' + ctx.arc(0, 0, 100, 0, 2 * Math.PI, false) + ctx.fill() + + // 刻度 + const my_minute = Math.PI * 2 / 60 + const my_second = Math.PI * 2 / 60 + ctx.strokeStyle = '#F59F5D' + ctx.lineWidth = 2 + ctx.beginPath() + for (let i = 0; i < 15; i++) { + ctx.save() + ctx.rotate(i * 4 * my_minute) + ctx.moveTo(r - 45, 0) + ctx.lineTo(r - 40, 0) + ctx.stroke() + ctx.restore() + } + + // 白色小圆 + ctx.beginPath() + ctx.fillStyle = 'white' + ctx.shadowBlur = 20 + ctx.shadowColor = 'rgba(204,204,204,0.50)' + ctx.arc(0, 0, 74, 0, 2 * Math.PI, false) + ctx.fill() + + // 文字 + ctx.beginPath() + ctx.restore() + + ctx.fillStyle = props.style?.cir?.color// "#007aff"; + ctx.font = '42px Cambria, Cambria-Bold' + ctx.textAlign = 'center' + ctx.textBaseline = 'middle' + ctx.fillText(`${percentage}%`, 0, 0) + + // 蓝色的圆 + if (percentage > 0) { + ctx.beginPath() + ctx.lineWidth = 25 + ctx.lineCap = 'round' + const gad = ctx.createLinearGradient(100, 0, 0, 100) + gad.addColorStop(0, props.style?.cir?.background?.start[0]) + gad.addColorStop(1, props.style?.cir?.background?.start[1]) + ctx.strokeStyle = gad + ctx.arc(0, 0, 104, -Math.PI * 0.5, 2 * Math.PI / 100 * ((percentage < 50 ? percentage : 50) - 25), false) + ctx.stroke() + } + + if (percentage > 50) { + ctx.beginPath() + const gad2 = ctx.createLinearGradient(0, -100, 0, 0) + gad2.addColorStop(0, props.style?.cir?.background?.end[0]) + gad2.addColorStop(1, props.style?.cir?.background?.start[1]) + ctx.strokeStyle = gad2 + ctx.arc(0, 0, 104, Math.PI * 0.4, 2 * Math.PI / 100 * (percentage - 25), false) + ctx.stroke() + } + } + else { + getCanvas() + } + }) + } + useReady(() => { + getCanvas() + }) + useEffect(() => { + if (props.progress != 0) { + getCanvas() + } + }, [props.progress]) + return +} +const CreditLine = () => { useLogin() const userInfo = useSelector(state => state.userInfo) - useEffect(() => { - getData() - }, []) + const { fetchData, state } = creditInfoApi() const [data, setData] = useState({ credit_quota_used_line: [0, '00'], @@ -39,6 +136,11 @@ export default () => { }) // 获取数据 const getData = async() => { + const convertPrice = (data) => { + const t = data.toString().split('.') + t[1] = t[1] ? t[1].padEnd(2, 0) : '00' + return t + } const result = await fetchData() const credit_quota_used_line = convertPrice(formatPriceDiv(result.data.credit_quota_used_line)) const credit_quota_line = convertPrice(formatPriceDiv(result.data.credit_quota_line)) @@ -113,12 +215,10 @@ export default () => { credit_quota_end_time: formatDateTime(result.data?.credit_quota_end_time, 'YYYY-MM-DD'), }) } - const convertPrice = (data) => { - const t = data.toString().split('.') - t[1] = t[1] ? t[1].padEnd(2, 0) : '00' - return t - } + useEffect(() => { + getData() + }, []) return ( @@ -154,98 +254,4 @@ export default () => { ) } -const Progress = (props) => { - useEffect(() => { - if (props.progress != 0) { - getCanvas() - } - }, [props.progress]) - const getCanvas = () => { - // const percentage = props.progress??0; - const percentage = props.progress || 0 - const query = Taro.createSelectorQuery() - query.select('#myCanvas').fields({ node: true, size: true }).exec((res) => { - const canvas = res[0]?.node - if (canvas) { - const ctx = canvas.getContext('2d') - const { windowHeight, windowWidth } = Taro.getSystemInfoSync() - const dpr = 750 / windowWidth - canvas.width = res[0].width * dpr - canvas.height = res[0].height * dpr - const r = canvas.width / 2 - ctx.translate(r, r) - - // 白色大圆 - ctx.beginPath() - ctx.fillStyle = 'white' - ctx.shadowBlur = 20 - ctx.shadowColor = '#cde5ff' - ctx.arc(0, 0, 100, 0, 2 * Math.PI, false) - ctx.fill() - - // 刻度 - const my_minute = Math.PI * 2 / 60 - const my_second = Math.PI * 2 / 60 - ctx.strokeStyle = '#F59F5D' - ctx.lineWidth = 2 - ctx.beginPath() - for (let i = 0; i < 15; i++) { - ctx.save() - ctx.rotate(i * 4 * my_minute) - ctx.moveTo(r - 45, 0) - ctx.lineTo(r - 40, 0) - ctx.stroke() - ctx.restore() - } - - // 白色小圆 - ctx.beginPath() - ctx.fillStyle = 'white' - ctx.shadowBlur = 20 - ctx.shadowColor = 'rgba(204,204,204,0.50)' - ctx.arc(0, 0, 74, 0, 2 * Math.PI, false) - ctx.fill() - - // 文字 - ctx.beginPath() - ctx.restore() - - ctx.fillStyle = props.style?.cir?.color// "#007aff"; - ctx.font = '42px Cambria, Cambria-Bold' - ctx.textAlign = 'center' - ctx.textBaseline = 'middle' - ctx.fillText(`${percentage}%`, 0, 0) - - // 蓝色的圆 - if (percentage > 0) { - ctx.beginPath() - ctx.lineWidth = 25 - ctx.lineCap = 'round' - const gad = ctx.createLinearGradient(100, 0, 0, 100) - gad.addColorStop(0, props.style?.cir?.background?.start[0]) - gad.addColorStop(1, props.style?.cir?.background?.start[1]) - ctx.strokeStyle = gad - ctx.arc(0, 0, 104, -Math.PI * 0.5, 2 * Math.PI / 100 * ((percentage < 50 ? percentage : 50) - 25), false) - ctx.stroke() - } - - if (percentage > 50) { - ctx.beginPath() - const gad2 = ctx.createLinearGradient(0, -100, 0, 0) - gad2.addColorStop(0, props.style?.cir?.background?.end[0]) - gad2.addColorStop(1, props.style?.cir?.background?.start[1]) - ctx.strokeStyle = gad2 - ctx.arc(0, 0, 104, Math.PI * 0.4, 2 * Math.PI / 100 * (percentage - 25), false) - ctx.stroke() - } - } - else { - getCanvas() - } - }) - } - useReady(() => { - getCanvas() - }) - return -} +export default CreditLine diff --git a/src/pages/creditUsed/index.tsx b/src/pages/creditUsed/index.tsx index cf3b2a4..8080927 100644 --- a/src/pages/creditUsed/index.tsx +++ b/src/pages/creditUsed/index.tsx @@ -1,15 +1,15 @@ -import InfiniteScrollPaging from '@/components/InfiniteScrollPaging' import { Button, Canvas, ScrollView, Text, View } from '@tarojs/components' import Taro, { useReady } from '@tarojs/taro' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' -import { creditListApi } from '@/api/creditLine' import './index.scss' import classnames from 'classnames' +import { creditListApi } from '@/api/creditLine' +import InfiniteScrollPaging from '@/components/InfiniteScrollPaging' import { formatDateTime, formatPriceDiv, toDecimal2 } from '@/common/fotmat' import { dataLoadingStatus, getFilterData } from '@/common/util' import useLogin from '@/use/useLogin' -export default () => { +const CreditUsed = () => { useLogin() const { fetchData, state } = creditListApi() // 渲染(数据) @@ -172,3 +172,5 @@ export default () => { // // ) // } + +export default CreditUsed diff --git a/src/pages/depositBeforehand/index.tsx b/src/pages/depositBeforehand/index.tsx index d48eac0..b720552 100644 --- a/src/pages/depositBeforehand/index.tsx +++ b/src/pages/depositBeforehand/index.tsx @@ -8,7 +8,7 @@ import { formatPriceDiv, toDecimal2 } from '@/common/fotmat' import Message from '@/components/Message' import useLogin from '@/use/useLogin' -export default () => { +const DepositBeforehand = () => { useLogin() const { fetchData, state } = depositInfoApi() const getData = async() => { @@ -65,3 +65,5 @@ export default () => { ) } + +export default DepositBeforehand diff --git a/src/pages/depositBeforehandDetail/index.tsx b/src/pages/depositBeforehandDetail/index.tsx index c7bde52..634c577 100644 --- a/src/pages/depositBeforehandDetail/index.tsx +++ b/src/pages/depositBeforehandDetail/index.tsx @@ -8,7 +8,35 @@ import { creditListApi } from '@/api/creditLine' import './index.scss' import useLogin from '@/use/useLogin' -export default () => { +const TimeLine = () => { + return ( + + + + + 申请提交 + 2022-04-24 16:10:11 + + + + + + 申请提交 + + + + + + + + 申请提交 + 2022-04-24 16:10:11 + + + ) +} + +const DepositBeforehandDetail = () => { useLogin() return ( @@ -58,30 +86,4 @@ export default () => { ) } -const TimeLine = () => { - return ( - - - - - 申请提交 - 2022-04-24 16:10:11 - - - - - - 申请提交 - - - - - - - - 申请提交 - 2022-04-24 16:10:11 - - - ) -} +export default DepositBeforehandDetail diff --git a/src/pages/depositList/index.tsx b/src/pages/depositList/index.tsx index e8ed24b..1bf61ec 100644 --- a/src/pages/depositList/index.tsx +++ b/src/pages/depositList/index.tsx @@ -8,7 +8,7 @@ import './index.scss' import { formatDateTime, formatPriceDiv } from '@/common/fotmat' import useLogin from '@/use/useLogin' -export default () => { +const DepositList = () => { useLogin() const { fetchData, state } = depositListApi() // 渲染(数据) @@ -56,3 +56,5 @@ export default () => { ) } + +export default DepositList diff --git a/src/pages/details/components/counter/index.tsx b/src/pages/details/components/counter/index.tsx index 344deb0..1f290b8 100644 --- a/src/pages/details/components/counter/index.tsx +++ b/src/pages/details/components/counter/index.tsx @@ -1,7 +1,7 @@ import { Input, View } from '@tarojs/components' import { useEffect, useMemo, useRef, useState } from 'react' import Big from 'big.js' -import styles from './index.module.scss' +import styles from './index.module.scss' interface params { minNum?: number // 最小值 @@ -15,9 +15,19 @@ interface params { unit?: string otherData?: any } -export default ({ minNum = 0, maxNum = 100, step = 1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = '', otherData }: params) => { +const Counter = ({ minNum = 0, maxNum = 100, step = 1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = '', otherData }: params) => { const [value, setValue] = useState({ count: defaultNum }) - + // 保留小数 + const formatDigits = (num) => { + num = `${num}` + if (num.includes('.') && digits > 0) { + console.log('num::', num.includes('.')) + const res = num.split('.') + const last_num = res[1].substr(0, digits) + return `${res[0]}.${last_num}` + } + return parseFloat(num) + } const onPlus = () => { const { count } = value let num_res = Big(count).add(step).toNumber() @@ -36,18 +46,6 @@ export default ({ minNum = 0, maxNum = 100, step = 1, digits = 0, defaultNum = 0 onClickBtn?.(parseFloat(num_res), otherData) } - // 保留小数 - const formatDigits = (num) => { - num = `${num}` - if (num.includes('.') && digits > 0) { - console.log('num::', num.includes('.')) - const res = num.split('.') - const last_num = res[1].substr(0, digits) - return `${res[0]}.${last_num}` - } - return parseFloat(num) - } - // 检查数据 const checkData = (val) => { const num = parseFloat(val) @@ -61,21 +59,21 @@ export default ({ minNum = 0, maxNum = 100, step = 1, digits = 0, defaultNum = 0 if (res === '') { setValue({ ...value, count: minNum }) onChange?.(minNum, otherData) - } - else if (!isNaN(Number(res))) { + } + else if (!Number.isNaN(Number(res))) { let count = formatDigits(res) count = checkData(count) setValue({ ...value, count }) onChange?.(parseFloat(count as string), otherData) - } + } else { const num = parseFloat(res) - if (!isNaN(num)) { + if (!Number.isNaN(num)) { let count = formatDigits(num) count = checkData(count) setValue({ ...value, count }) onChange?.(count as number, otherData) - } + } else { setValue({ ...value, count: defaultNum }) onChange?.(defaultNum, otherData) @@ -85,12 +83,12 @@ export default ({ minNum = 0, maxNum = 100, step = 1, digits = 0, defaultNum = 0 const onBluerEven = () => { const num = parseFloat(value.count) - if (!isNaN(num)) { + if (!Number.isNaN(num)) { let count = formatDigits(num) count = checkData(count) setValue({ ...value, count }) onBlue?.(count as number, otherData) - } + } else { setValue({ ...value, count: defaultNum }) onBlue?.(defaultNum, otherData) @@ -111,3 +109,5 @@ export default ({ minNum = 0, maxNum = 100, step = 1, digits = 0, defaultNum = 0 ) } + +export default Counter diff --git a/src/pages/details/components/orderCount/index.tsx b/src/pages/details/components/orderCount/index.tsx index 3e49549..6c46d4b 100644 --- a/src/pages/details/components/orderCount/index.tsx +++ b/src/pages/details/components/orderCount/index.tsx @@ -25,7 +25,7 @@ interface param { title?: string productId?: number } -export default memo(({ show = false, onClose, title = '', productId = 0 }: param) => { +const OrderCount = ({ show = false, onClose, title = '', productId = 0 }: param) => { const { adminUserInfo } = useSelector(state => state.userInfo) const [selectList, _] = useState([ @@ -46,39 +46,11 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param }, ]) const [selectIndex, setSelectIndex] = useState(0) - const selectProduct = (index: number) => { - condition.current.code_or_name = null - getColorList() - setSelectIndex(() => index) - } - - // 重置数据 - useEffect(() => { - setSearchShow(false) - }, [selectIndex]) // 获取面料颜色列表 const { fetchData: colorFetchData, state: colorState } = GetColorList() const [list, setList] = useState([]) const condition = useRef({ physical_warehouse: adminUserInfo?.physical_warehouse, sale_mode: selectIndex, product_id: 0, code_or_name: null }) - const getColorList = async() => { - const { data } = await colorFetchData(getFilterData(condition.current)) - const lists = initList(data.list) - setList(() => [...lists]) - } - const [showPopup, setShowPopup] = useState(false) - - // 显示获取 - useEffect(() => { - if (show) { - setSelectIndex(0) - condition.current.code_or_name = null - setSearchShow(false) - condition.current.product_id = productId - getColorList() - } - setShowPopup(show) - }, [show]) // 初始化列表数据 const initList = useCallback((list) => { @@ -89,6 +61,18 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param }) return newList }, []) + const getColorList = async() => { + const { data } = await colorFetchData(getFilterData(condition.current)) + const lists = initList(data.list) + setList(() => [...lists]) + } + const [showPopup, setShowPopup] = useState(false) + + const selectProduct = (index: number) => { + condition.current.code_or_name = null + getColorList() + setSelectIndex(() => index) + } // 卸载数据 useEffect(() => { @@ -115,7 +99,7 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param let kindCount = 0 const color_list: any[] = [] let color_list_info = {} - list.map((item) => { + list.forEach((item) => { if (item.count > 0) { sumCount = Big(sumCount).add(item.count).toNumber() kindCount++ @@ -147,7 +131,21 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param const changeSearchShow = () => { setSearchShow(true) } - + // 显示获取 + useEffect(() => { + if (show) { + setSelectIndex(0) + condition.current.code_or_name = null + setSearchShow(false) + condition.current.product_id = productId + getColorList() + } + setShowPopup(show) + }, [show]) + // 重置数据 + useEffect(() => { + setSearchShow(false) + }, [selectIndex]) // 添加购物车 const { getShopCount } = useCommonData() const { getSelfUserInfo } = UseLogin() @@ -155,7 +153,7 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param const addShopCart = async() => { try { await getSelfUserInfo() - } + } catch (msg) { Taro.showToast({ icon: 'none', @@ -181,7 +179,7 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param }) getShopCount() onClose?.() - } + } else { Taro.showToast({ icon: 'none', @@ -228,9 +226,7 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param const closeLabImgShow = useCallback(() => { setShowLabImage(() => false) }, []) - - // 虚拟滚动 - const Rows = memo(({ id, index, style, data }: any) => { + const Rows = ({ id, index, style, data }: any) => { const item = data[index] return ( <> @@ -269,7 +265,9 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param )) || } ) - }) + } + // 虚拟滚动 + const RowsWithMemo = memo(Rows) const [virtualHeight, setVirtualheight] = useState(400) const getHeight = () => { @@ -305,7 +303,7 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param selectProduct(index)} - className={classnames(styles.search_item, selectIndex == index && styles.search_item_select)} + className={classnames(styles.search_item, selectIndex == index && styles.search_item_select)} > {item.title} @@ -339,9 +337,9 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param itemData={list} /* 渲染列表的数据 */ itemCount={searchShow ? list.length + 1 : list.length} /* 渲染列表的长度 */ itemSize={100} /* 列表单项的高度 */ - overscanCount={1} + overscanCount={1} > - {Rows} + {RowsWithMemo} @@ -367,4 +365,5 @@ export default memo(({ show = false, onClose, title = '', productId = 0 }: param ) -}) +} +export default memo(OrderCount) diff --git a/src/pages/details/components/preview/index.tsx b/src/pages/details/components/preview/index.tsx index 66d8ec5..6d53288 100644 --- a/src/pages/details/components/preview/index.tsx +++ b/src/pages/details/components/preview/index.tsx @@ -7,7 +7,7 @@ export interface colorParams { show?: false|true onClose?: () => void } -export default ({ value, show = false, onClose }: colorParams) => { +const Preview = ({ value, show = false, onClose }: colorParams) => { return ( <> {show && onClose?.()}> @@ -18,4 +18,6 @@ export default ({ value, show = false, onClose }: colorParams) => { } ) -} +} + +export default Preview diff --git a/src/pages/details/components/productItem/index.tsx b/src/pages/details/components/productItem/index.tsx index 7a7cc4c..c2764d6 100644 --- a/src/pages/details/components/productItem/index.tsx +++ b/src/pages/details/components/productItem/index.tsx @@ -1,9 +1,9 @@ import { View } from '@tarojs/components' import { memo } from 'react' import styles from './index.module.scss' -import LabAndImg from '@/components/LabAndImg' +import LabAndImg from '@/components/LabAndImg' -export default memo(() => { +const ProductItem = () => { return ( @@ -43,4 +43,5 @@ export default memo(() => { ) -}) +} +export default memo(ProductItem) diff --git a/src/pages/details/components/swiper/index.tsx b/src/pages/details/components/swiper/index.tsx index 6af2a03..a59ccee 100644 --- a/src/pages/details/components/swiper/index.tsx +++ b/src/pages/details/components/swiper/index.tsx @@ -8,8 +8,7 @@ interface item { title: string; img: string; url: string; id: number } interface params { list?: item[] } - -export default ({ list = [] }: params) => { +const SwiperComp = ({ list = [] }: params) => { const [pageIndex, setPageIndex] = useState(1) const pageRef = useRef(null) @@ -36,9 +35,9 @@ export default ({ list = [] }: params) => { {list.length > 0 && ( swiperChange(e)}> - {list?.map((item) => { + {list?.map((item, key) => { return ( - + @@ -55,3 +54,5 @@ export default ({ list = [] }: params) => { ) } + +export default SwiperComp diff --git a/src/pages/details/index.tsx b/src/pages/details/index.tsx index e4d411a..d965afe 100644 --- a/src/pages/details/index.tsx +++ b/src/pages/details/index.tsx @@ -26,13 +26,19 @@ interface Params { swiperOnClick?: (val: item) => void style?: Object } -export default (props: Params) => { +const Details = (props: Params) => { const { getPhoneNumber, userInfo } = useLogin() // 获取参数(有两种参数:1.商品id, 2.页面分享) const router = useRouter() const [params, setParams] = useState({ id: '', share: null }) + // 解析短码参数 + const { fetchData: fetchDataAnalysisShortCode } = AnalysisShortCodeApi() + const analysisShortCode = async() => { + const res = await fetchDataAnalysisShortCode({ md5_key: router.params.share }) + setParams({ id: res.data.product_id, share: res.data }) + } // 判断是否是分享过来的参数 const judgeParam = async() => { if (router.params.id) { @@ -42,29 +48,9 @@ export default (props: Params) => { analysisShortCode() } } - - // 解析短码参数 - const { fetchData: fetchDataAnalysisShortCode } = AnalysisShortCodeApi() - const analysisShortCode = async() => { - const res = await fetchDataAnalysisShortCode({ md5_key: router.params.share }) - setParams({ id: res.data.product_id, share: res.data }) - } - // 获取购物车数据数量 const { getShopCount, commonData } = useCommonData() - useDidShow(() => { - judgeParam() - setShowCart(false) - getShopCount() - }) - - useEffect(() => { - if (params.id) { - getProductDetail() - } - }, [params]) - // 获取数据 const [productInfo, setProductInfo] = useState({}) const { fetchData } = GetProductDetailApi() @@ -74,13 +60,6 @@ export default (props: Params) => { Taro.stopPullDownRefresh() } - useEffect(() => { - if (productInfo.code) { - getShortCode() - setCollectStatus(() => productInfo.is_favorite) - } - }, [productInfo]) - // 面料名称 const productName = useMemo(() => { return formatHashTag(productInfo.code, productInfo.name) @@ -112,7 +91,17 @@ export default (props: Params) => { const img = formatImgUrl(shareImg, '!w400') setSortCode({ ...userObj.sort_code, shareShortDetail: { title: productName as string, code: resDetail.md5_key, img } }) } + useDidShow(() => { + judgeParam() + setShowCart(false) + getShopCount() + }) + useEffect(() => { + if (params.id) { + getProductDetail() + } + }, [params]) // 授权手机号和下单 const placeOrder = async(status = 'to_phone', e: any = {}) => { if (!productInfo.id) { return false } @@ -136,14 +125,7 @@ export default (props: Params) => { const [collectStatus, setCollectStatus] = useState(false) const [collectionShow, setCollectionShow] = useState(false) const { fetchData: addFavoritefetchData } = AddFavoriteApi() - const openCollection = () => { - if (productInfo.is_favorite) { - delFavoriteProduct() - } - else { - setCollectionShow(true) - } - } + const onAdd = useCallback( async(val) => { const res = await addFavoritefetchData({ favorite_id: val.id, product_id: Number(params.id) }) @@ -160,6 +142,13 @@ export default (props: Params) => { }, [params], ) + + useEffect(() => { + if (productInfo.code) { + getShortCode() + setCollectStatus(() => productInfo.is_favorite) + } + }, [productInfo]) const closeCollection = useCallback(() => { setCollectionShow(false) }, []) @@ -173,7 +162,14 @@ export default (props: Params) => { alert.none('已取消收藏') } } - + const openCollection = () => { + if (productInfo.is_favorite) { + delFavoriteProduct() + } + else { + setCollectionShow(true) + } + } // 页面下拉刷新 usePullDownRefresh(() => { getProductDetail() @@ -288,3 +284,5 @@ export default (props: Params) => { ) } + +export default Details diff --git a/src/pages/editOrder/components/shipmentMode/index.tsx b/src/pages/editOrder/components/shipmentMode/index.tsx index e4e9edc..ccdeeef 100644 --- a/src/pages/editOrder/components/shipmentMode/index.tsx +++ b/src/pages/editOrder/components/shipmentMode/index.tsx @@ -7,7 +7,7 @@ interface Param { onSelect?: (val: number) => void defaultValue?: 0|1|2 } -export default memo(({ onSelect, defaultValue = 0 }: Param) => { +const ShipmentMode = ({ onSelect, defaultValue = 0 }: Param) => { // 收货方法 0:没选择, 1:自提,2:物流 const shipmentMode = useRef([ { value: 1, label: '上门自提', selected: false }, @@ -24,9 +24,10 @@ export default memo(({ onSelect, defaultValue = 0 }: Param) => { return ( 收货方式 - {shipmentMode.current.map((item) => { - return selectShipmentMode(item.value)}>{item.label} + {shipmentMode.current.map((item, key) => { + return selectShipmentMode(item.value)}>{item.label} })} ) -}) +} +export default memo(ShipmentMode) diff --git a/src/pages/editOrder/index.tsx b/src/pages/editOrder/index.tsx index e840fde..e53a620 100644 --- a/src/pages/editOrder/index.tsx +++ b/src/pages/editOrder/index.tsx @@ -10,7 +10,7 @@ import { getParam } from '@/common/system' import { EditSaleOrderAddressApi, EditSaleOrderShipmentModeApi } from '@/api/order' import useLogin from '@/use/useLogin' -export default () => { +const EditOrder = () => { useLogin() // 获取临时传递的数据 const params = getParam() @@ -91,3 +91,5 @@ export default () => { ) } + +export default EditOrder diff --git a/src/pages/index/components/product/index.tsx b/src/pages/index/components/product/index.tsx index 8881811..55984db 100644 --- a/src/pages/index/components/product/index.tsx +++ b/src/pages/index/components/product/index.tsx @@ -1,12 +1,12 @@ import { Image, View } from '@tarojs/components' import styles from './index.module.scss' -export default () => { +const Product = () => { return ( - {new Array(10).fill('').map((item) => { + {new Array(10).fill('').map((item, index) => { return ( - + 230色 @@ -28,3 +28,5 @@ export default () => { ) } + +export default Product diff --git a/src/pages/index/components/productClass/index.tsx b/src/pages/index/components/productClass/index.tsx index b49eeae..3e5d308 100644 --- a/src/pages/index/components/productClass/index.tsx +++ b/src/pages/index/components/productClass/index.tsx @@ -13,7 +13,7 @@ interface Param { type ParamProduct = Omit -export default (option: Param) => { +const ProductClass = (option: Param) => { const { open = false, onOpenClick, onSelect, list, defaultSelectId } = option const getSelect = useCallback((id) => { onSelect?.(id) @@ -68,7 +68,7 @@ const ProductClassLine = memo((option: ParamProduct) => { clickEvent({ item, index })} + onClick={() => clickEvent({ item, index })} > {item.name} @@ -100,10 +100,11 @@ const ProductClassBlock = (option: ParamProduct & { open: boolean }) => { - {list?.map(item => ( + {list?.map((item, index) => ( clickEvent(item)} + onClick={() => clickEvent(item)} > {item.name} @@ -119,3 +120,5 @@ const ProductClassBlock = (option: ParamProduct & { open: boolean }) => { ) } + +export default ProductClass diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 0673901..3c97afc 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -14,23 +14,8 @@ import { GetProductKindListApi, GetProductListApi } from '@/api/material' import useLogin from '@/use/useLogin' import { dataLoadingStatus } from '@/common/util' -export default () => { +const Index = () => { useLogin() - useEffect(() => { - categoryList() - }, []) - - // 获取面料种类 - const [kindData, setKindData] = useState({ list: [], defaultId: 0 }) - const { fetchData } = GetProductKindListApi() - const categoryList = async() => { - const res = await fetchData() - if (res.data?.list) { - setKindData({ ...kindData, list: res.data.list, defaultId: res.data.list[0].id }) - setFiltrate({ ...filtrate, product_kind_id: res.data.list[0].id }) - product_kind_id_ref.current = res.data.list[0].id - } - } // 获取面料列表 const product_kind_id_ref = useRef(0) @@ -39,16 +24,6 @@ export default () => { const [filtrate, setFiltrate] = useState({ product_kind_id: 0, size: 5, page: 1 }) const pageNum = useRef({ size: filtrate.size, page: filtrate.page }) const { fetchData: productFetchData, state: productState } = GetProductListApi() - // 获取数据方法 - const getProductList = async() => { - const { data, total } = await productFetchData(filtrate) - setProductData({ ...productData, list: data.list, total }) - setRefresherTriggeredStatus(() => false) - } - // 监听查询条件 - useEffect(() => { - if (filtrate.product_kind_id) { getProductList() } - }, [filtrate]) // 点击面料类型 const getProductKindId = useCallback((e) => { @@ -95,7 +70,30 @@ export default () => { product_kind_id_next_ref.current = id setFiltrate(list => ({ ...list, size: 5, product_kind_id: kind_id })) }, []) - + // 获取面料种类 + const [kindData, setKindData] = useState({ list: [], defaultId: 0 }) + const { fetchData } = GetProductKindListApi() + const categoryList = async() => { + const res = await fetchData() + if (res.data?.list) { + setKindData({ ...kindData, list: res.data.list, defaultId: res.data.list[0].id }) + setFiltrate({ ...filtrate, product_kind_id: res.data.list[0].id }) + product_kind_id_ref.current = res.data.list[0].id + } + } + // 获取数据方法 + const getProductList = async() => { + const { data, total } = await productFetchData(filtrate) + setProductData({ ...productData, list: data.list, total }) + setRefresherTriggeredStatus(() => false) + } + // 监听查询条件 + useEffect(() => { + if (filtrate.product_kind_id) { getProductList() } + }, [filtrate]) + useEffect(() => { + categoryList() + }, []) return ( setShowShopCart(!showShopCart)}> @@ -130,3 +128,5 @@ export default () => { ) } + +export default Index diff --git a/src/pages/order/comfirm.tsx b/src/pages/order/comfirm.tsx index f8f7902..e71f031 100644 --- a/src/pages/order/comfirm.tsx +++ b/src/pages/order/comfirm.tsx @@ -17,7 +17,7 @@ import { SUBSCRIPTION_MESSAGE_SCENE } from '@/common/enum' import { UseSubscriptionMessage } from '@/use/useCommon' import { throttle } from '@/common/util' -export default () => { +const Comfirm = () => { const [showDesc, setShowDesc] = useState(false) // 下单信息 interface OrderParams { address_id?: number; remark?: string; sale_mode?: number; shipment_mode?: number; list?: any[] } @@ -30,6 +30,15 @@ export default () => { } const param = getParam() const idsAndSaleModel = useRef({ shopping_cart_product_color_list: [], sale_mode: 0 }) + // 获取销售预览订单 + const [preViewOrder, setPreViewOrder] = useState() // 获取到的原始数据 + const { fetchData } = SaleOrderPreViewApi() + const getSaleOrderPreView = async() => { + if (idsAndSaleModel.current.shopping_cart_product_color_list?.length > 0) { + const res = await fetchData(idsAndSaleModel.current) + setPreViewOrder(res.data) + } + } useDidShow(async() => { idsAndSaleModel.current = { shopping_cart_product_color_list: [], sale_mode: 0 } // 初始化 idsAndSaleModel.current.sale_mode = Number(param?.sale_mode) @@ -42,29 +51,6 @@ export default () => { setSubmitOrderData(val => ({ ...val, sale_mode: param?.sale_mode })) }) - // 获取销售预览订单 - const [preViewOrder, setPreViewOrder] = useState() // 获取到的原始数据 - const { fetchData } = SaleOrderPreViewApi() - const getSaleOrderPreView = async() => { - if (idsAndSaleModel.current.shopping_cart_product_color_list?.length > 0) { - const res = await fetchData(idsAndSaleModel.current) - setPreViewOrder(res.data) - } - } - - // 监听获取到的数据 - useEffect(() => { - if (preViewOrder) { - formatData() - getDataList() - setSubmitOrderData(val => ({ - ...val, - address_id: preViewOrder.default_address.id, - shipment_mode: preViewOrder.shipment_mode || 2, - })) - } - }, [preViewOrder]) - // 格式化数据格式 const [formatPreViewOrder, setFormatPreViewOrder] = useState() // 格式化后的数据 const formatData = () => { @@ -105,8 +91,8 @@ export default () => { // 获取提交格式数据列表 const getDataList = () => { const list: { shopping_cart_product_color_id: number }[] = [] - preViewOrder.product_list?.map((item) => { - item.product_colors?.map((colorItem) => { + preViewOrder.product_list?.forEach((item) => { + item.product_colors?.forEach((colorItem) => { list.push({ shopping_cart_product_color_id: colorItem.id }) }) }) @@ -167,7 +153,7 @@ export default () => { const res = await saleOrderFetchData(submitOrderData) if (res.success) { goLink('/pages/order/index', { id: res.data.id }, 'redirectTo') - } + } else { alert.none(res.msg) } @@ -178,7 +164,18 @@ export default () => { usePullDownRefresh(() => { getSaleOrderPreView() }) - + // 监听获取到的数据 + useEffect(() => { + if (preViewOrder) { + formatData() + getDataList() + setSubmitOrderData(val => ({ + ...val, + address_id: preViewOrder.default_address.id, + shipment_mode: preViewOrder.shipment_mode || 2, + })) + } + }, [preViewOrder]) return ( @@ -208,3 +205,5 @@ export default () => { ) } + +export default Comfirm diff --git a/src/pages/order/components/addressInfo/index.tsx b/src/pages/order/components/addressInfo/index.tsx index 734fdb8..c130c3f 100644 --- a/src/pages/order/components/addressInfo/index.tsx +++ b/src/pages/order/components/addressInfo/index.tsx @@ -19,14 +19,9 @@ interface Param { defaultValue?: AddressInfoParam|null // 默认值 disabled?: false|true // true禁用后只用于展示 } - -export default memo(({ onSelect, defaultValue = null, disabled = false }: Param) => { +const AddressInfo = ({ onSelect, defaultValue = null, disabled = false }: Param) => { const [showAddressList, setShowAddressList] = useState(false) - useEffect(() => { - setUserInfo(() => defaultValue) - }, [defaultValue]) - // 选择地址 const [userInfo, setUserInfo] = useState() const getAddress = useCallback((val) => { @@ -43,25 +38,28 @@ export default memo(({ onSelect, defaultValue = null, disabled = false }: Param) const changeShow = () => { if (!disabled) { setShowAddressList(() => true) } } + useEffect(() => { + setUserInfo(() => defaultValue) + }, [defaultValue]) return ( changeShow()}> {!userInfo - && <> - 请选择收货地址及信息 - - - || <> - - - {userInfo?.name} - {userInfo?.phone} - - {formatAddress} - - 修改 - } + ? <> + 请选择收货地址及信息 + + + : <> + + + {userInfo?.name} + {userInfo?.phone} + + {formatAddress} + + 修改 + } {!disabled && setShowAddressList(false)}> @@ -71,4 +69,5 @@ export default memo(({ onSelect, defaultValue = null, disabled = false }: Param) } ) -}) +} +export default memo(AddressInfo) diff --git a/src/pages/order/components/addressInfoDetail/index.tsx b/src/pages/order/components/addressInfoDetail/index.tsx index 509b204..82525a5 100644 --- a/src/pages/order/components/addressInfoDetail/index.tsx +++ b/src/pages/order/components/addressInfoDetail/index.tsx @@ -46,194 +46,190 @@ const { SaleOrderStatusRefund, SaleOrderStatusCancel, } = ORDER_STATUS +const AddressInfoDetail = ({ onSelect, onChangeShipmentMode, orderInfo, status = 2, disabled = false, onLogistics }: Param, ref) => { + const [addressInfo, setAddressInfo] = useState() + const { fetchData: addressFetchData } = EditSaleOrderAddressApi() -export default memo( - forwardRef(({ onSelect, onChangeShipmentMode, orderInfo, status = 2, disabled = false, onLogistics }: Param, ref) => { - const [addressInfo, setAddressInfo] = useState() - useEffect(() => { - if (orderInfo) { - setReceivingStatus(() => orderInfo.shipment_mode || 2) - setAddressInfo(() => orderInfo) - } - }, [orderInfo]) + // 打开地址列表 + const [showAddressList, setShowAddressList] = useState(false) - // 打开地址列表 - const [showAddressList, setShowAddressList] = useState(false) - const changeShow = () => { - if (receivingStatus == 2 && !logisticsShow && limitEdit()) { setShowAddressList(() => true) } + // 收货方法,1:自提,2物流 + const [receivingStatus, setReceivingStatus] = useState(2) + + // 当没有地址时获取地址列表中的第一个数据 + const { fetchData: addressListFetchData } = addressListApi() + const getAddressListOne = async() => { + if (orderInfo?.address_detail) { return true } + const res = await addressListFetchData() + if (res.data.list && res.data.list?.length > 0) { + const info = res.data.list[0] + await addressFetchData({ id: orderInfo?.id, address_id: info.id }) + setAddressInfo(e => ({ ...e, ...info, target_user_name: info.name, target_user_phone: info.phone })) + return true } - - // 把内部方法提供给外部 - useImperativeHandle(ref, () => ({ - changeShow, - })) - - // 收货方法,1:自提,2物流 - const [receivingStatus, setReceivingStatus] = useState(2) - const { fetchData: shipmentModeFetchData } = EditSaleOrderShipmentModeApi() - const onReceivingStatus = async(value, e) => { - e.stopPropagation() - if (limitEdit()) { changeReceivingStatus(value) } + else { + Taro.showModal({ + content: '您还没有地址,请前去新增地址', + success(res) { + if (res.confirm) { + goLink('/pages/addressManager/index') + } + else if (res.cancel) { + console.log('用户点击取消') + } + }, + }) + return false } + } + const { fetchData: shipmentModeFetchData } = EditSaleOrderShipmentModeApi() - // 当没有地址时获取地址列表中的第一个数据 - const { fetchData: addressListFetchData } = addressListApi() - const getAddressListOne = async() => { - if (orderInfo?.address_detail) { return true } - const res = await addressListFetchData() - if (res.data.list && res.data.list?.length > 0) { - const info = res.data.list[0] - await addressFetchData({ id: orderInfo?.id, address_id: info.id }) - setAddressInfo(e => ({ ...e, ...info, target_user_name: info.name, target_user_phone: info.phone })) - return true - } - else { - Taro.showModal({ - content: '您还没有地址,请前去新增地址', - success(res) { - if (res.confirm) { - goLink('/pages/addressManager/index') - } - else if (res.cancel) { - console.log('用户点击取消') - } - }, - }) - return false - } + const changeReceivingStatus = debounce(async(value) => { + if (!orderInfo || value == receivingStatus) { return false } + if (status == 1) { + onChangeShipmentMode?.(value) + setReceivingStatus(value) + return false } - - const changeReceivingStatus = debounce(async(value) => { - if (!orderInfo || value == receivingStatus) { return false } - if (status == 1) { - onChangeShipmentMode?.(value) - setReceivingStatus(value) - return false - } - if (value == 2) { - const res = await getAddressListOne() - if (!res) { return false } - } - alert.loading('正在修改') - const res = await shipmentModeFetchData({ id: orderInfo.id, shipment_mode: value }) - if (res.success) { - alert.success('收货方式修改成功') - onChangeShipmentMode?.(value) - setReceivingStatus(() => value) - } - else { - alert.none(res.msg) - } - }, 300) - - // 修改地址 - const [addressId, setAddressId] = useState(0) - const { fetchData: addressFetchData } = EditSaleOrderAddressApi() - const getAddress = async(value) => { - if (!orderInfo) { return false } - if (status == 1) { - setShowAddressList(() => false) - setAddressId(value.id) - setAddressInfo(e => ({ ...e, ...value, target_user_name: value.name, target_user_phone: value.phone })) - onSelect?.(value) - return false - } - alert.loading('正在修改') - const res = await addressFetchData({ id: orderInfo.id, address_id: value.id }) - if (res.success) { - alert.success('地址修改成功') - onSelect?.(value) - setShowAddressList(() => false) - setAddressId(value.id) - setAddressInfo(e => ({ ...e, ...value, target_user_name: value.name, target_user_phone: value.phone })) - } - else { - alert.none(res.msg) - } + if (value == 2) { + const res = await getAddressListOne() + if (!res) { return false } } - - // 根据订单状态判断是否可修改 - const limitEdit = () => { - const res = [ - SaleorderstatusWaitingPrePayment.value, - SaleOrderStatusBooking.value, - SaleOrderStatusArranging.value, - SaleOrderStatusArranged.value, - SaleOrderStatusWaitingPayment.value, - ].includes(orderInfo?.status as number) - if (!res && status != 1) { alert.none('该订单状态不能修改地址!') } - return status == 1 ? true : res + alert.loading('正在修改') + const res = await shipmentModeFetchData({ id: orderInfo.id, shipment_mode: value }) + if (res.success) { + alert.success('收货方式修改成功') + onChangeShipmentMode?.(value) + setReceivingStatus(() => value) } + else { + alert.none(res.msg) + } + }, 300) - // 根据订单状态判断是否显示物流 - const logisticsShowList = [ - SaleOrderStatusWaitingReceipt.value, - SaleOrderStatusAlreadyReceipt.value, - SaleOrderStatusComplete.value, - SaleOrderStatusRefund.value, - ] - const logisticsShow = useMemo(() => { - return logisticsShowList.includes(orderInfo?.status as number) - }, [orderInfo]) + // 修改地址 + const [addressId, setAddressId] = useState(0) + const getAddress = async(value) => { + if (!orderInfo) { return false } + if (status == 1) { + setShowAddressList(() => false) + setAddressId(value.id) + setAddressInfo(e => ({ ...e, ...value, target_user_name: value.name, target_user_phone: value.phone })) + onSelect?.(value) + return false + } + alert.loading('正在修改') + const res = await addressFetchData({ id: orderInfo.id, address_id: value.id }) + if (res.success) { + alert.success('地址修改成功') + onSelect?.(value) + setShowAddressList(() => false) + setAddressId(value.id) + setAddressInfo(e => ({ ...e, ...value, target_user_name: value.name, target_user_phone: value.phone })) + } + else { + alert.none(res.msg) + } + } - // 地址格式 - const formatAddress = useMemo(() => { - if (receivingStatus == 2) { - return addressInfo?.address_detail ? addressInfo.province_name + addressInfo.city_name + addressInfo.district_name + addressInfo.address_detail : '' - } - else { - return addressInfo?.take_goods_address - } - }, [receivingStatus, addressInfo]) - - return ( - - changeShow()}> - - - - {formatAddress || '请选择收货地址及信息'} - {receivingStatus == 2 && !logisticsShow && } - - - {receivingStatus == 1 ? '谭先生' : addressInfo?.target_user_name} - {receivingStatus == 1 ? addressInfo?.take_goods_phone : addressInfo?.target_user_phone} - + // 根据订单状态判断是否可修改 + const limitEdit = () => { + const res = [ + SaleorderstatusWaitingPrePayment.value, + SaleOrderStatusBooking.value, + SaleOrderStatusArranging.value, + SaleOrderStatusArranged.value, + SaleOrderStatusWaitingPayment.value, + ].includes(orderInfo?.status as number) + if (!res && status != 1) { alert.none('该订单状态不能修改地址!') } + return status == 1 ? true : res + } + const onReceivingStatus = async(value, e) => { + e.stopPropagation() + if (limitEdit()) { changeReceivingStatus(value) } + } + // 根据订单状态判断是否显示物流 + const logisticsShowList = [ + SaleOrderStatusWaitingReceipt.value, + SaleOrderStatusAlreadyReceipt.value, + SaleOrderStatusComplete.value, + SaleOrderStatusRefund.value, + ] + const logisticsShow = useMemo(() => { + return logisticsShowList.includes(orderInfo?.status as number) + }, [orderInfo]) + const changeShow = () => { + if (receivingStatus == 2 && !logisticsShow && limitEdit()) { setShowAddressList(() => true) } + } + // 地址格式 + const formatAddress = useMemo(() => { + if (receivingStatus == 2) { + return addressInfo?.address_detail ? addressInfo.province_name + addressInfo.city_name + addressInfo.district_name + addressInfo.address_detail : '' + } + else { + return addressInfo?.take_goods_address + } + }, [receivingStatus, addressInfo]) + useEffect(() => { + if (orderInfo) { + setReceivingStatus(() => orderInfo.shipment_mode || 2) + setAddressInfo(() => orderInfo) + } + }, [orderInfo]) + // 把内部方法提供给外部 + useImperativeHandle(ref, () => ({ + changeShow, + })) + return ( + + changeShow()}> + + + + {formatAddress || '请选择收货地址及信息'} + {receivingStatus == 2 && !logisticsShow && } - {(!logisticsShow && ( - - - onReceivingStatus(1, e)} - > + + {receivingStatus == 1 ? '谭先生' : addressInfo?.target_user_name} + {receivingStatus == 1 ? addressInfo?.take_goods_phone : addressInfo?.target_user_phone} + + + {(!logisticsShow && ( + + + onReceivingStatus(1, e)} + > 自提 - - onReceivingStatus(2, e)} - > - 物流 - - + onReceivingStatus(2, e)} + > + 物流 + - )) + + + )) || (orderInfo?.status != SaleOrderStatusRefund.value && ( 查看物流 ))} - - setShowAddressList(false)}> - - 请选择收货地址 - - - - - - ) - }), + setShowAddressList(false)}> + + 请选择收货地址 + + + + + + + ) +} +export default memo( + forwardRef(AddressInfoDetail), ) diff --git a/src/pages/order/components/advanceOrderState/index.tsx b/src/pages/order/components/advanceOrderState/index.tsx index 73aa558..3e62826 100644 --- a/src/pages/order/components/advanceOrderState/index.tsx +++ b/src/pages/order/components/advanceOrderState/index.tsx @@ -23,8 +23,7 @@ interface Param { status: number // 订单状态 } } - -export default memo(({ orderInfo, onRefresh }: Param) => { +const AdvanceOrderState = ({ orderInfo, onRefresh }: Param) => { const { showTime, onStart, timeStatus } = useTimeCountDown() // 订单状态枚举 @@ -68,4 +67,5 @@ export default memo(({ orderInfo, onRefresh }: Param) => { ) -}) +} +export default memo(AdvanceOrderState) diff --git a/src/pages/order/components/amountShow/index.tsx b/src/pages/order/components/amountShow/index.tsx index 10f4fea..f0fbb79 100644 --- a/src/pages/order/components/amountShow/index.tsx +++ b/src/pages/order/components/amountShow/index.tsx @@ -7,7 +7,7 @@ interface Param { number: number // 数字 status: 0|1|2 // 0 小型,1中型,2大 } -export default memo(({ number = 0, status = 1 }: Param) => { +const AmountShow = ({ number = 0, status = 1 }: Param) => { const priceDom = useCallback(() => { const res = number.toFixed(2).split('.') const int_num = `${parseInt(res[0])}` @@ -25,4 +25,5 @@ export default memo(({ number = 0, status = 1 }: Param) => { {priceDom()} ) -}) +} +export default memo(AmountShow) diff --git a/src/pages/order/components/applyRefund/index.tsx b/src/pages/order/components/applyRefund/index.tsx index 2d86e73..75eb7e0 100644 --- a/src/pages/order/components/applyRefund/index.tsx +++ b/src/pages/order/components/applyRefund/index.tsx @@ -14,7 +14,7 @@ interface Param { orderId?: number onSuccess?: () => void } -export default memo(({ show, onClose, orderId, onSuccess }: Param) => { +const ApplyRefund = ({ show, onClose, orderId, onSuccess }: Param) => { // 提交的数据 const submitData = useRef({ return_explain: 0, @@ -22,13 +22,6 @@ export default memo(({ show, onClose, orderId, onSuccess }: Param) => { reason_describe: '', }) - useEffect(() => { - if (show && orderId) { - submitData.current.sale_order_id = orderId - refundExplain() - } - }, [orderId, show]) - // 申请退款 const { fetchData } = ApplyRefundApi() const getApplyRefund = async() => { @@ -37,7 +30,7 @@ export default memo(({ show, onClose, orderId, onSuccess }: Param) => { if (res.success) { alert.success('申请成功') onSuccess?.() - } + } else { alert.error('申请失败') } @@ -51,12 +44,6 @@ export default memo(({ show, onClose, orderId, onSuccess }: Param) => { const res = await refundExplainFetchdata() setList(() => res.data.list) } - const [reason, setReason] = useState({ id: 0, name: '' }) - const reasonSelect = useCallback((e) => { - setReason({ ...reason, name: e.name, id: e.id }) - submitData.current.return_explain = e.id - closeReason() - }, []) // 备注 const getOtherReason = useCallback((val) => { @@ -68,12 +55,17 @@ export default memo(({ show, onClose, orderId, onSuccess }: Param) => { const closeReason = useCallback(() => { setShowReason(false) }, []) - + const [reason, setReason] = useState({ id: 0, name: '' }) + const reasonSelect = useCallback((e) => { + setReason({ ...reason, name: e.name, id: e.id }) + submitData.current.return_explain = e.id + closeReason() + }, []) // 提交 const onSubmit = (val) => { if (val == 2) { getApplyRefund() - } + } else { onClose?.() submitData.current = { @@ -83,7 +75,12 @@ export default memo(({ show, onClose, orderId, onSuccess }: Param) => { } } } - + useEffect(() => { + if (show && orderId) { + submitData.current.sale_order_id = orderId + refundExplain() + } + }, [orderId, show]) return ( <> @@ -111,4 +108,5 @@ export default memo(({ show, onClose, orderId, onSuccess }: Param) => { ) -}) +} +export default memo(ApplyRefund) diff --git a/src/pages/order/components/estimatedAmount/index.tsx b/src/pages/order/components/estimatedAmount/index.tsx index 25a6962..7aae5a4 100644 --- a/src/pages/order/components/estimatedAmount/index.tsx +++ b/src/pages/order/components/estimatedAmount/index.tsx @@ -17,7 +17,7 @@ interface Param { messageWidth?: number messageShow?: true|false } -export default memo(({ number = 0, titleStatus = true, title = '', messageTitle = '', numberStatus = 1, messageHeight = 70, messageWidth = 430, messageShow = false }: Param) => { +const EstimatedAmount = ({ number = 0, titleStatus = true, title = '', messageTitle = '', numberStatus = 1, messageHeight = 70, messageWidth = 430, messageShow = false }: Param) => { const [show, setShow] = useState(messageShow) const onClose = () => { setShow(false) @@ -28,14 +28,6 @@ export default memo(({ number = 0, titleStatus = true, title = '', messageTitle const [style, setStyle] = useState<{ top: string }>() - useEffect(() => { - if (show) { - getDomDes('#message') - } - else { - setStyle(() => ({ top: '0' })) - } - }, [show]) // 设置弹出层高度 const getDomDes = (id) => { setTimeout(() => { @@ -46,6 +38,14 @@ export default memo(({ number = 0, titleStatus = true, title = '', messageTitle }).exec() }, 0) } + useEffect(() => { + if (show) { + getDomDes('#message') + } + else { + setStyle(() => ({ top: '0' })) + } + }, [show]) return ( <> @@ -61,4 +61,5 @@ export default memo(({ number = 0, titleStatus = true, title = '', messageTitle ) -}) +} +export default memo(EstimatedAmount) diff --git a/src/pages/order/components/kindList/index.tsx b/src/pages/order/components/kindList/index.tsx index dc2e0ff..90e553d 100644 --- a/src/pages/order/components/kindList/index.tsx +++ b/src/pages/order/components/kindList/index.tsx @@ -28,8 +28,7 @@ interface Param { order: OrderParam comfirm?: boolean // 是否是确认订单页面使用 } - -export default memo(({ order, comfirm = false }: Param) => { +const KindList = ({ order, comfirm = false }: Param) => { const { SaleOrderStatusBooking, // 待接单 SaleOrderStatusArranging, // 配布中 @@ -171,12 +170,12 @@ export default memo(({ order, comfirm = false }: Param) => { (weight) => { if (order.sale_mode == 2) { const showWeight = [SaleorderstatusWaitingPrePayment.value, SaleOrderStatusBooking.value, SaleOrderStatusArranging.value].includes(order.status) - return showWeight + return showWeight ? ( ; ≈{formatWeightDiv(weight)}kg - ) + ) : ( <> ) @@ -239,4 +238,5 @@ export default memo(({ order, comfirm = false }: Param) => { ) -}) +} +export default memo(KindList) diff --git a/src/pages/order/components/movableAreaBtn/index.tsx b/src/pages/order/components/movableAreaBtn/index.tsx index eca24bc..218c06c 100644 --- a/src/pages/order/components/movableAreaBtn/index.tsx +++ b/src/pages/order/components/movableAreaBtn/index.tsx @@ -1,6 +1,6 @@ import { Button, MovableArea, MovableView, View } from '@tarojs/components' import Taro, { useReady } from '@tarojs/taro' -import type { ReactElement } from 'react' +import type { ReactElement } from 'react' import { useEffect, useLayoutEffect, useRef, useState } from 'react' import classnames from 'classnames' import styles from './index.module.scss' @@ -9,7 +9,7 @@ interface param { children?: ReactElement | null orderInfo?: any } -export default ({ children = null, orderInfo }: param) => { +const MovableAreaBtn = ({ children = null, orderInfo }: param) => { const [screenHeight, setScreenHeight] = useState(0) const screenWidthRef = useRef(0) useLayoutEffect(() => { @@ -31,10 +31,12 @@ export default ({ children = null, orderInfo }: param) => { openType="contact" sendMessageTitle={orderInfo?.order_no} showMessageCard - sendMessagePath={`/pages/order/index?id=${orderInfo?.id}`} + sendMessagePath={`/pages/order/index?id=${orderInfo?.id}`} > ) } + +export default MovableAreaBtn diff --git a/src/pages/order/components/offlinePay/index.tsx b/src/pages/order/components/offlinePay/index.tsx index 709f70e..1d18a7c 100644 --- a/src/pages/order/components/offlinePay/index.tsx +++ b/src/pages/order/components/offlinePay/index.tsx @@ -17,7 +17,7 @@ interface Param { transfer_remittance_account: string } } -export default memo(({ show = true, onClose, offlineInfo }: Param) => { +const OfflinePay = ({ show = true, onClose, offlineInfo }: Param) => { // 复制功能 const clipboardData = () => { Taro.setClipboardData({ @@ -53,4 +53,5 @@ export default memo(({ show = true, onClose, offlineInfo }: Param) => { ) -}) +} +export default memo(OfflinePay) diff --git a/src/pages/order/components/orderState/index.tsx b/src/pages/order/components/orderState/index.tsx index a010009..3baf34f 100644 --- a/src/pages/order/components/orderState/index.tsx +++ b/src/pages/order/components/orderState/index.tsx @@ -24,8 +24,7 @@ interface Param { account_period_time?: string // 还款日期 } } - -export default memo(({ orderInfo = { logistics_details: [], payment_method: 0, status: 0 }, onRefresh }: Param) => { +const OrderState = ({ orderInfo = { logistics_details: [], payment_method: 0, status: 0 }, onRefresh }: Param) => { useEffect(() => { console.log('orderInfo33::', orderInfo) }, [orderInfo]) @@ -51,7 +50,7 @@ export default memo(({ orderInfo = { logistics_details: [], payment_method: 0, s <> {(dataList?.length > 0) && - {dataList.map((item, index) => + {dataList.map((item, index) => {(dataList.length > 1) && } {(dataList.length != (index + 1)) && } @@ -62,7 +61,7 @@ export default memo(({ orderInfo = { logistics_details: [], payment_method: 0, s )} {(dataList.length > 2) && changeMore()}> - {showMore && '收起详情' || '点击查看详情'} + {showMore ? '收起详情' : '点击查看详情'} } @@ -76,4 +75,5 @@ export default memo(({ orderInfo = { logistics_details: [], payment_method: 0, s } ) -}) +} +export default memo(OrderState) diff --git a/src/pages/order/components/orderStatusTag/index.tsx b/src/pages/order/components/orderStatusTag/index.tsx index 66ce2c7..d9b78e5 100644 --- a/src/pages/order/components/orderStatusTag/index.tsx +++ b/src/pages/order/components/orderStatusTag/index.tsx @@ -7,7 +7,7 @@ import { REFUND_STATUS_ORDER } from '@/common/enum' interface Param { status?: number } -export default memo(({ status = 0 }: Param) => { +const OrderStatusTag = ({ status = 0 }: Param) => { const { ReturnApplyOrderTypeAdvanceReceiptRefund, // 预收退款 ReturnApplyOrderTypeReturnForRefund, // 退货退款 @@ -21,4 +21,5 @@ export default memo(({ status = 0 }: Param) => { } ) -}) +} +export default memo(OrderStatusTag) diff --git a/src/pages/order/components/payment/index.tsx b/src/pages/order/components/payment/index.tsx index 9ce43b3..eb7044d 100644 --- a/src/pages/order/components/payment/index.tsx +++ b/src/pages/order/components/payment/index.tsx @@ -34,7 +34,7 @@ interface OrderInfo { } type PayStatus = 1 | 2 | 3 | 4 | 5 | null // 1:预存款, 2:账期,3:线下汇款, 4:扫码支付, 5:货到付款 -export default memo(({ show = false, onClose, orderInfo, onSubmitSuccess }: Param) => { +const Payment = ({ show = false, onClose, orderInfo, onSubmitSuccess }: Param) => { // 支付方式枚举 const { PaymentMethodPreDeposit, PaymentMethodAccountPeriod, PaymentMethodCashOnDelivery } = PAYMENT_METHOD // 订单状态枚举 @@ -69,7 +69,7 @@ export default memo(({ show = false, onClose, orderInfo, onSubmitSuccess }: Para // 有应收单id时用应收单获取数据 const { data } = await orderFetchData({ id: orderInfo?.should_collect_order_id }) setPayInfo(() => data) - } + } else { // 用预付单id获取支付信息 const { data } = await prepayOrderFetchData({ id: orderInfo?.pre_collect_order_id }) @@ -125,14 +125,14 @@ export default memo(({ show = false, onClose, orderInfo, onSubmitSuccess }: Para let res: any = null if (orderInfo?.should_collect_order_id) { res = await submitFetchData(submitData) - } + } else { res = await submitPrepayOrderFetchData(submitData) } if (res.success) { alert.success('支付成功') onSubmitSuccess?.() - } + } else { alert.none(res.msg) } @@ -264,4 +264,5 @@ export default memo(({ show = false, onClose, orderInfo, onSubmitSuccess }: Para setScanPayShow(false)} /> ) -}) +} +export default memo(Payment) diff --git a/src/pages/order/components/reasonPopup/index.tsx b/src/pages/order/components/reasonPopup/index.tsx index 26d2b8f..c2461ff 100644 --- a/src/pages/order/components/reasonPopup/index.tsx +++ b/src/pages/order/components/reasonPopup/index.tsx @@ -13,7 +13,7 @@ interface ReasonInfoParam { onSelect?: (val: object) => void // 选择 defaultValue?: number // 默认选中 } -export default memo(({ show = false, onClose, title = '', list = [], onSelect, defaultValue }: ReasonInfoParam) => { +const ReasonPopup = ({ show = false, onClose, title = '', list = [], onSelect, defaultValue }: ReasonInfoParam) => { return ( @@ -26,4 +26,5 @@ export default memo(({ show = false, onClose, title = '', list = [], onSelect, d ) -}) +} +export default memo(ReasonPopup) diff --git a/src/pages/order/components/remark/index.tsx b/src/pages/order/components/remark/index.tsx index e5fb460..c4de6ca 100644 --- a/src/pages/order/components/remark/index.tsx +++ b/src/pages/order/components/remark/index.tsx @@ -8,17 +8,13 @@ interface Param { onSave?: (val: string) => void defaultValue?: string } -export default ({ onBlur, onSave, defaultValue = '' }: Param) => { +const Remark = ({ onBlur, onSave, defaultValue = '' }: Param) => { const [descData, setDescData] = useState({ number: 0, value: '', count: 200, }) - useEffect(() => { - getDesc(defaultValue) - }, [defaultValue]) - const getDesc = (value) => { let res = value if (value.length > descData.count) { @@ -30,6 +26,9 @@ export default ({ onBlur, onSave, defaultValue = '' }: Param) => { const setSave = () => { onSave?.(descData.value) } + useEffect(() => { + getDesc(defaultValue) + }, [defaultValue]) return ( 编辑备注 @@ -40,4 +39,5 @@ export default ({ onBlur, onSave, defaultValue = '' }: Param) => { setSave()}>保存 ) -} +} +export default Remark diff --git a/src/pages/order/components/returnRecord/index.tsx b/src/pages/order/components/returnRecord/index.tsx index 1549887..8572c45 100644 --- a/src/pages/order/components/returnRecord/index.tsx +++ b/src/pages/order/components/returnRecord/index.tsx @@ -19,7 +19,7 @@ interface Param { onSubmit?: () => void id?: number } -export default memo(({ show, onClose, onSubmit, id }: Param) => { +const ReturnRecord = ({ show, onClose, onSubmit, id }: Param) => { // 搜索参数 const searchField = useRef({ page: 1, @@ -27,13 +27,6 @@ export default memo(({ show, onClose, onSubmit, id }: Param) => { sale_order_id: 0, }) - useEffect(() => { - if (show && id) { - searchField.current.sale_order_id = id - getOrderList() - } - }, [show, id]) - const userInfo = useSelector(state => state.userInfo) // 获取售后订单列表 @@ -83,12 +76,17 @@ export default memo(({ show, onClose, onSubmit, id }: Param) => { const onscroll = useCallback((e) => { if (e.detail.scrollTop > 20) { setScrollStatus(true) - } + } else { setScrollStatus(false) } }, []) - + useEffect(() => { + if (show && id) { + searchField.current.sale_order_id = id + getOrderList() + } + }, [show, id]) // 数据加载状态 const statusMore = useMemo(() => { return dataLoadingStatus({ list: orderData.list, total: orderData.total, status: orderState.loading }) @@ -162,4 +160,5 @@ export default memo(({ show, onClose, onSubmit, id }: Param) => { ) -}) +} +export default memo(ReturnRecord) diff --git a/src/pages/order/components/scanPay/index.tsx b/src/pages/order/components/scanPay/index.tsx index 7e6f2c6..d3158da 100644 --- a/src/pages/order/components/scanPay/index.tsx +++ b/src/pages/order/components/scanPay/index.tsx @@ -30,14 +30,32 @@ interface ListParam { total_price: string weight_error: string } -export default memo(({ show = true, onClose, company, orderInfo }: Param) => { +const ScanPay = ({ show = true, onClose, company, orderInfo }: Param) => { const [detail, setDetail] = useState() + // 收货地址 + const address = (addressInfo) => { + if (addressInfo?.shipment_mode == 2) { + return addressInfo?.province_name ? addressInfo.province_name + addressInfo.city_name + addressInfo.district_name + addressInfo.address_detail : '' + } + else { + return addressInfo?.take_goods_address + } + } + // 收件人 + const userName = (addressInfo) => { + return addressInfo?.shipment_mode == 2 ? orderInfo.target_user_name : '' + } + + // 手机号 + const userPhone = (addressInfo) => { + return addressInfo?.shipment_mode == 2 ? orderInfo.target_user_phone : orderInfo.take_goods_phone + } useEffect(() => { if (orderInfo) { const lists: ListParam[] = [] - orderInfo.product_list?.map((pitem) => { - pitem?.product_colors?.map((citem) => { + orderInfo.product_list?.forEach((pitem) => { + pitem?.product_colors?.forEach((citem) => { lists.push({ product_code: formatRemoveHashTag(pitem.code), product_name: pitem.name, @@ -96,26 +114,6 @@ export default memo(({ show = true, onClose, company, orderInfo }: Param) => { } }, [orderInfo, show]) - // 收货地址 - const address = (addressInfo) => { - if (addressInfo?.shipment_mode == 2) { - return addressInfo?.province_name ? addressInfo.province_name + addressInfo.city_name + addressInfo.district_name + addressInfo.address_detail : '' - } - else { - return addressInfo?.take_goods_address - } - } - - // 收件人 - const userName = (addressInfo) => { - return addressInfo?.shipment_mode == 2 ? orderInfo.target_user_name : '' - } - - // 手机号 - const userPhone = (addressInfo) => { - return addressInfo?.shipment_mode == 2 ? orderInfo.target_user_phone : orderInfo.take_goods_phone - } - // 获取支付二维码 const [payCodeImage, setPayCodeImage] = useState('') const fileData = useRef({ @@ -148,10 +146,6 @@ export default memo(({ show = true, onClose, company, orderInfo }: Param) => { scope: 'scope.writePhotosAlbum', msg: '您没授权,无法保存图片', }) - const saveImageCheck = async() => { - const res = await check() - res && saveImage() - } // 保存图片 const saveImage = () => { @@ -166,7 +160,10 @@ export default memo(({ show = true, onClose, company, orderInfo }: Param) => { }, }) } - + const saveImageCheck = async() => { + const res = await check() + res && saveImage() + } // 预览图片 const showImage = () => { console.log('fileData.current.filePath::', fileData.current.filePath) @@ -201,4 +198,5 @@ export default memo(({ show = true, onClose, company, orderInfo }: Param) => { ) -}) +} +export default memo(ScanPay) diff --git a/src/pages/order/components/scanPayCheck/index.tsx b/src/pages/order/components/scanPayCheck/index.tsx index 022ed91..e0d33ea 100644 --- a/src/pages/order/components/scanPayCheck/index.tsx +++ b/src/pages/order/components/scanPayCheck/index.tsx @@ -29,9 +29,80 @@ interface ListParam { total_price: string weight_error: string } -export default memo(({ show = true, onClose, company, orderInfo }: Param) => { +const ScanPayCheck = ({ show = true, onClose, company, orderInfo }: Param) => { const [detail, setDetail] = useState() + // 收货地址 + const address = (addressInfo) => { + if (addressInfo?.shipment_mode == 2) { + return addressInfo?.province_name ? addressInfo.province_name + addressInfo.city_name + addressInfo.district_name + addressInfo.address_detail : '' + } + else { + return addressInfo?.take_goods_address + } + } + + // 收件人 + const userName = (addressInfo) => { + return addressInfo?.shipment_mode == 2 ? orderInfo.target_user_name : '' + } + + // 手机号 + const userPhone = (addressInfo) => { + return addressInfo?.shipment_mode == 2 ? orderInfo.target_user_phone : orderInfo.take_goods_phone + } + + // 获取支付二维码 + const [payCodeImage, setPayCodeImage] = useState('') + const fileData = useRef({ + filePath: '', + base64: '', + }) + const { fetchData, state } = GetPayCode() + const getCore = async() => { + const res = await fetchData(detail) + const base64 = res.data.base64 + setPayCodeImage(() => base64) + const time = new Date().valueOf() + const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64) || [] + const filePath = `${Taro.env.USER_DATA_PATH}/img${time}.${format}` + fileData.current.filePath = filePath + fileData.current.base64 = bodyData + const save = Taro.getFileSystemManager() + save.writeFile({ + filePath: fileData.current.filePath, + data: fileData.current.base64, + encoding: 'base64', + }) + } + + // 保存图片 + const saveImage = () => { + alert.loading('正在保存图片') + Taro.saveImageToPhotosAlbum({ + filePath: fileData.current.filePath, + success() { + alert.success('图片保存成功') + }, + fail(err) { + console.log('err::', err) + }, + }) + } + // 检查是否开启保存图片权限 + const { check } = useCheckAuthorize({ scope: 'scope.writePhotosAlbum', msg: '您没授权,无法保存图片' }) + const saveImageCheck = async() => { + const res = await check() + res && saveImage() + } + // 预览图片 + const showImage = () => { + console.log('fileData.current.filePath::', fileData.current.filePath) + Taro.previewImage({ + current: fileData.current.filePath, // 当前显示 + urls: [fileData.current.filePath], // 需要预览的图片http链接列表 + }) + } useEffect(() => { if (show) { getCore() @@ -41,8 +112,8 @@ export default memo(({ show = true, onClose, company, orderInfo }: Param) => { useEffect(() => { if (orderInfo) { const lists: ListParam[] = [] - orderInfo.product_list?.map((pitem) => { - pitem?.product_colors?.map((citem) => { + orderInfo.product_list?.forEach((pitem) => { + pitem?.product_colors?.forEach((citem) => { lists.push({ product_code: formatRemoveHashTag(pitem.code), product_name: pitem.name, @@ -98,81 +169,6 @@ export default memo(({ show = true, onClose, company, orderInfo }: Param) => { })) } }, [orderInfo]) - - // 收货地址 - const address = (addressInfo) => { - if (addressInfo?.shipment_mode == 2) { - return addressInfo?.province_name ? addressInfo.province_name + addressInfo.city_name + addressInfo.district_name + addressInfo.address_detail : '' - } - else { - return addressInfo?.take_goods_address - } - } - - // 收件人 - const userName = (addressInfo) => { - return addressInfo?.shipment_mode == 2 ? orderInfo.target_user_name : '' - } - - // 手机号 - const userPhone = (addressInfo) => { - return addressInfo?.shipment_mode == 2 ? orderInfo.target_user_phone : orderInfo.take_goods_phone - } - - // 获取支付二维码 - const [payCodeImage, setPayCodeImage] = useState('') - const fileData = useRef({ - filePath: '', - base64: '', - }) - const { fetchData, state } = GetPayCode() - const getCore = async() => { - const res = await fetchData(detail) - const base64 = res.data.base64 - setPayCodeImage(() => base64) - const time = new Date().valueOf() - const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64) || [] - const filePath = `${Taro.env.USER_DATA_PATH}/img${time}.${format}` - fileData.current.filePath = filePath - fileData.current.base64 = bodyData - const save = Taro.getFileSystemManager() - save.writeFile({ - filePath: fileData.current.filePath, - data: fileData.current.base64, - encoding: 'base64', - }) - } - - // 检查是否开启保存图片权限 - const { check } = useCheckAuthorize({ scope: 'scope.writePhotosAlbum', msg: '您没授权,无法保存图片' }) - const saveImageCheck = async() => { - const res = await check() - res && saveImage() - } - - // 保存图片 - const saveImage = () => { - alert.loading('正在保存图片') - Taro.saveImageToPhotosAlbum({ - filePath: fileData.current.filePath, - success() { - alert.success('图片保存成功') - }, - fail(err) { - console.log('err::', err) - }, - }) - } - - // 预览图片 - const showImage = () => { - console.log('fileData.current.filePath::', fileData.current.filePath) - Taro.previewImage({ - current: fileData.current.filePath, // 当前显示 - urls: [fileData.current.filePath], // 需要预览的图片http链接列表 - }) - } - // 复制功能 return ( @@ -194,4 +190,5 @@ export default memo(({ show = true, onClose, company, orderInfo }: Param) => { ) -}) +} +export default memo(ScanPayCheck) diff --git a/src/pages/order/components/shipmentMode/index.tsx b/src/pages/order/components/shipmentMode/index.tsx index fcae893..7e2a972 100644 --- a/src/pages/order/components/shipmentMode/index.tsx +++ b/src/pages/order/components/shipmentMode/index.tsx @@ -6,7 +6,7 @@ import styles from './index.module.scss' interface Param { onSelect?: (val: number) => void } -export default memo(({ onSelect }: Param) => { +const ShipmentMode = ({ onSelect }: Param) => { // 收货方法 1:自提,2:物流 const shipmentMode = useRef([ { value: 1, label: '上门自提', selected: false }, @@ -20,9 +20,10 @@ export default memo(({ onSelect }: Param) => { return ( 收货方式 - {shipmentMode.current.map((item) => { - return selectShipmentMode(item.value)}>{item.label} + {shipmentMode.current.map((item, key) => { + return selectShipmentMode(item.value)}>{item.label} })} ) -}) +} +export default memo(ShipmentMode) diff --git a/src/pages/order/components/submitOrderBtn/index.tsx b/src/pages/order/components/submitOrderBtn/index.tsx index b708478..f8c5d1b 100644 --- a/src/pages/order/components/submitOrderBtn/index.tsx +++ b/src/pages/order/components/submitOrderBtn/index.tsx @@ -2,7 +2,7 @@ import { Text, View } from '@tarojs/components' import { memo, useCallback, useEffect, useMemo } from 'react' import classnames from 'classnames' import styles from './index.module.scss' -import { formatKbPrice } from '@/common/common' +import { formatKbPrice } from '@/common/common' interface Param { style?: Object @@ -10,7 +10,7 @@ interface Param { priceTitle: string // 描述 } -export default memo(({ style, number = 0, priceTitle = '' }: Param) => { +const SubmitOrderBtn = ({ style, number = 0, priceTitle = '' }: Param) => { const priceDom = useCallback(() => { const res = number.toFixed(2).split('.') const int_num = `${parseInt(res[0])}` @@ -36,4 +36,5 @@ export default memo(({ style, number = 0, priceTitle = '' }: Param) => { ) -}) +} +export default memo(SubmitOrderBtn) diff --git a/src/pages/order/components/weightMemo/index.tsx b/src/pages/order/components/weightMemo/index.tsx index 7ce2889..987852d 100644 --- a/src/pages/order/components/weightMemo/index.tsx +++ b/src/pages/order/components/weightMemo/index.tsx @@ -8,7 +8,7 @@ interface Param { onCheck?: () => void onCustom?: () => void } -export default memo(({ onCheck, onCustom }: Param) => { +const WeightMemo = ({ onCheck, onCustom }: Param) => { return ( onCheck?.()}> @@ -33,4 +33,5 @@ export default memo(({ onCheck, onCustom }: Param) => { ) -}) +} +export default memo(WeightMemo) diff --git a/src/pages/order/index.tsx b/src/pages/order/index.tsx index c9457b8..9665239 100644 --- a/src/pages/order/index.tsx +++ b/src/pages/order/index.tsx @@ -1,4 +1,3 @@ -import useLogin from '@/use/useLogin' import { MovableArea, Text, View } from '@tarojs/components' import Taro, { useDidShow, usePullDownRefresh, useRouter } from '@tarojs/taro' import classnames from 'classnames' @@ -14,6 +13,7 @@ import Remark from './components/remark' import ReturnRecord from './components/returnRecord' import ScanPayCheck from './components/scanPayCheck' import styles from './index.module.scss' +import useLogin from '@/use/useLogin' import ShopCart from '@/components/shopCart' import SearchInput from '@/components/searchInput' import Popup from '@/components/popup' @@ -25,14 +25,11 @@ import { SubscriptionMessageApi } from '@/api/user' import { AddShoppingCartApi } from '@/api/shopCart' import { EditSaleOrderRemarkApi, GetSaleOrderDetailApi } from '@/api/order' -export default () => { +const Order = () => { useLogin() const [showDesc, setShowDesc] = useState(false) const router = useRouter() const orderId = useRef(Number(router.params.id)) - useDidShow(() => { - getSaleOrderPreView() - }) // 订单状态枚举 const { @@ -50,6 +47,13 @@ export default () => { const firstOpen = useRef(true) const [orderDetail, setOrderDetail] = useState() // 获取到的原始数据 const { fetchData: getOrderFetchData } = GetSaleOrderDetailApi() + const [orderRemark, setOrderRemark] = useState('') + + // 去付款 + const [payMentShow, setPayMentShow] = useState(false) + const toPay = () => { + setPayMentShow(true) + } const getSaleOrderPreView = async() => { if (orderId.current) { const res = await getOrderFetchData({ id: orderId.current }) @@ -65,11 +69,6 @@ export default () => { // Taro.hideToast() } - // 监听获取到的数据 - useEffect(() => { - if (orderDetail) { formatData() } - }, [orderDetail]) - // 格式化数据格式 const [formatDetailOrder, setFormatDetailOrder] = useState() // 格式化后的数据 const formatData = () => { @@ -116,14 +115,13 @@ export default () => { // 订单备注 const { fetchData: remarkFetchData } = EditSaleOrderRemarkApi() - const [orderRemark, setOrderRemark] = useState('') const getRemark = useCallback(async(e) => { setOrderRemark(() => e) const res = await remarkFetchData({ remark: e, id: orderId.current }) if (res.success) { getSaleOrderPreView() alert.success('提交成功') - } + } else { alert.error(res.msg) } @@ -143,12 +141,6 @@ export default () => { setShowDesc(() => true) } - // 去付款 - const [payMentShow, setPayMentShow] = useState(false) - const toPay = () => { - setPayMentShow(true) - } - // 打开地址修改 const addressRef = useRef(null) @@ -162,53 +154,24 @@ export default () => { getSaleOrderPreView() }, [orderDetail]) - // 获取底部按钮点击, 获取按钮状态 - const orderStateClick = useCallback( - (val) => { - if (val == 1 || val == 6 || val == 8) { - getSaleOrderPreView() - } - else if (val == 2) { - // 待付款 - toPay() - } - else if (val == 3) { - // 申请退款 - if (!orderDetail?.av_return_roll) { return alert.none('该订单已申请过退款') } - setRefundShow(true) - } - else if (val == 7) { - // 再购 - addShopCart() - } - else if (val == 9) { - // 售后记录 - onReturnRecordShow() - } - else if (val == 10) { - setShowScanPayCheck(true) - } - }, - [orderDetail], - ) - // 页面下拉刷新 usePullDownRefresh(() => { getSaleOrderPreView() }) + useDidShow(() => { + getSaleOrderPreView() + }) + // 关闭支付弹窗 + const closePayShow = useCallback(() => { + setPayMentShow(() => false) + }, [orderDetail]) // 支付成功 const onPaySuccess = useCallback(() => { alert.success('支付成功') getSaleOrderPreView() closePayShow() }, [orderDetail]) - - // 关闭支付弹窗 - const closePayShow = useCallback(() => { - setPayMentShow(() => false) - }, [orderDetail]) - // 按钮所需数据 const orderInfo = useMemo(() => { return { @@ -251,11 +214,11 @@ export default () => { const { fetchData: addFetchData } = AddShoppingCartApi() const addShopCart = async() => { const color_list: { product_color_id: number; roll?: number; length?: number }[] = [] - orderDetail?.product_list.map((pitem) => { + orderDetail?.product_list.forEach((pitem) => { pitem?.product_colors.map((citem) => { if (orderDetail?.sale_mode == 0) { return color_list.push({ product_color_id: citem.id, roll: citem.roll }) - } + } else { return color_list.push({ product_color_id: citem.id, length: citem.length }) } @@ -270,7 +233,7 @@ export default () => { title: '已加入购物车', }) setShowCart(true) - } + } else { Taro.showToast({ icon: 'none', @@ -278,7 +241,10 @@ export default () => { }) } } - + // 监听获取到的数据 + useEffect(() => { + if (orderDetail) { formatData() } + }, [orderDetail]) // 显示售后记录 const [returnRecordShow, setReturnRecordShow] = useState(false) const onReturnRecordShow = useCallback(() => { @@ -290,7 +256,35 @@ export default () => { // 显示 const [showScanPayCheck, setShowScanPayCheck] = useState(false) - + // 获取底部按钮点击, 获取按钮状态 + const orderStateClick = useCallback( + (val) => { + if (val == 1 || val == 6 || val == 8) { + getSaleOrderPreView() + } + else if (val == 2) { + // 待付款 + toPay() + } + else if (val == 3) { + // 申请退款 + if (!orderDetail?.av_return_roll) { return alert.none('该订单已申请过退款') } + setRefundShow(true) + } + else if (val == 7) { + // 再购 + addShopCart() + } + else if (val == 9) { + // 售后记录 + onReturnRecordShow() + } + else if (val == 10) { + setShowScanPayCheck(true) + } + }, + [orderDetail], + ) return ( @@ -352,3 +346,4 @@ export default () => { ) } +export default Order diff --git a/src/pages/order/orderList/components/order/index.tsx b/src/pages/order/orderList/components/order/index.tsx index 3d2b93e..ab0bb9f 100644 --- a/src/pages/order/orderList/components/order/index.tsx +++ b/src/pages/order/orderList/components/order/index.tsx @@ -39,7 +39,7 @@ interface Param { } onClickBtn?: (val: { status: number; orderInfo: Param['value'] }) => void } -export default memo(({ value, onClickBtn }: Param) => { +const Order = ({ value, onClickBtn }: Param) => { const userInfo = useSelector(state => state.userInfo) // 对应数量 const formatCount = useCallback( @@ -89,7 +89,7 @@ export default memo(({ value, onClickBtn }: Param) => { const orderStatus = useMemo(() => { if (value.status == SaleOrderStatusWaitingReceipt.value && value.shipment_mode == 1) { return '待提货' - } + } else { return value?.status_name } @@ -161,4 +161,5 @@ export default memo(({ value, onClickBtn }: Param) => { ) -}) +} +export default memo(Order) diff --git a/src/pages/order/orderList/components/orderStatusList/index.tsx b/src/pages/order/orderList/components/orderStatusList/index.tsx index 5bb5d40..d1d0a63 100644 --- a/src/pages/order/orderList/components/orderStatusList/index.tsx +++ b/src/pages/order/orderList/components/orderStatusList/index.tsx @@ -8,7 +8,7 @@ interface Param { defaultId?: number onSelect?: (val: number) => void } -export default memo(({ list = [], defaultId = -1, onSelect }: Param) => { +const OrderStatusList = ({ list = [], defaultId = -1, onSelect }: Param) => { const [selectInfo, setSelectInfo] = useState({ selected: -1, // 当前选中的id tabId: '', // 需要滚动到的id @@ -39,7 +39,7 @@ export default memo(({ list = [], defaultId = -1, onSelect }: Param) => { key={item.id} id={`tabs_${item.id}`} onClick={() => clickEvent({ item, index })} - className={classnames(styles.order_status_item, selectInfo.selected == item.id && styles.selected)} + className={classnames(styles.order_status_item, selectInfo.selected == item.id && styles.selected)} > {item.name} @@ -49,4 +49,5 @@ export default memo(({ list = [], defaultId = -1, onSelect }: Param) => { ) -}) +} +export default memo(OrderStatusList) diff --git a/src/pages/order/orderList/index.tsx b/src/pages/order/orderList/index.tsx index c1b2f26..a3fcd42 100644 --- a/src/pages/order/orderList/index.tsx +++ b/src/pages/order/orderList/index.tsx @@ -16,7 +16,7 @@ import { AddShoppingCartApi } from '@/api/shopCart' import ShopCart from '@/components/shopCart' import { alert } from '@/common/common' -export default () => { +const OrderList = () => { const { checkLogin } = useLogin() useDidShow(async() => { await checkLogin() @@ -24,19 +24,6 @@ export default () => { // 传递过来的参数 const router = useRouter() - useEffect(() => { - if (router?.params.status != undefined && router?.params.status !== '') { - setSearchField(e => ({ ...e, status: router?.params.status as unknown as number })) - } - else { - setSearchField(e => ({ ...e, status: -1 })) - } - getOrderStatusList() - }, []) - - useDidHide(() => { - setSearchField(e => ({ ...e, status: -1 })) - }) // 搜索参数 const [searchField, setSearchField] = useState<{ status: number | null; page: number; size: number; name: string }>({ @@ -54,6 +41,8 @@ export default () => { setStatusList(() => [{ id: -1, name: '全部' }, ...res.data.list]) } + // 列表下拉刷新 + const [refresherTriggeredStatus, setRefresherTriggeredStatus] = useState(false) // 获取订单列表 const { fetchData: listFetchData, state: orderState } = GetOrderListApi() const [orderData, setOrderData] = useState<{ list: any[]; total: number }>({ list: [], total: 0 }) @@ -97,44 +86,12 @@ export default () => { setSearchField(val => ({ ...val, name: e, size: 10 })) }, []) - // 列表下拉刷新 - const [refresherTriggeredStatus, setRefresherTriggeredStatus] = useState(false) const getRefresherRefresh = async() => { pageNum.current.size = 1 setRefresherTriggeredStatus(true) setSearchField(val => ({ ...val, size: 10 })) } - // 监听点击的按钮 - const clickOrderBtn = useCallback( - ({ status, orderInfo }) => { - setCallBackPayOrderInfo(() => orderInfo) - if (status == 1 || status == 6 || status == 8) { - getOrderList() - } - else if (status == 2) { - // 去支付 - toPay() - } - else if (status == 3) { - // 申请退款 - if (!orderInfo?.av_return_roll) { return alert.none('该订单已申请过退款') } - setRefundShow(true) - } - else if (status == 7) { - // 购买 - addShopCart(orderInfo) - } - else if (status == 9) { - onReturnRecordShow() - } - else if (status == 10) { - setShowScanPayCheck(true) - } - }, - [orderData], - ) - const [callBackOrderInfo, setCallBackPayOrderInfo] = useState() // 去付款 @@ -157,8 +114,8 @@ export default () => { const { fetchData: addFetchData } = AddShoppingCartApi() const addShopCart = async(item) => { const color_list: { product_color_id: number; roll?: number; length?: number }[] = [] - item?.product_list.map((pitem) => { - pitem?.product_colors.map((citem) => { + item?.product_list.forEach((pitem) => { + pitem?.product_colors.forEach((citem) => { if (item?.sale_mode == 0) { return color_list.push({ product_color_id: citem.id, roll: citem.roll }) } @@ -205,7 +162,47 @@ export default () => { // 显示 const [showScanPayCheck, setShowScanPayCheck] = useState(false) - + useEffect(() => { + if (router?.params.status != undefined && router?.params.status !== '') { + setSearchField(e => ({ ...e, status: router?.params.status as unknown as number })) + } + else { + setSearchField(e => ({ ...e, status: -1 })) + } + getOrderStatusList() + }, []) + // 监听点击的按钮 + const clickOrderBtn = useCallback( + ({ status, orderInfo }) => { + setCallBackPayOrderInfo(() => orderInfo) + if (status == 1 || status == 6 || status == 8) { + getOrderList() + } + else if (status == 2) { + // 去支付 + toPay() + } + else if (status == 3) { + // 申请退款 + if (!orderInfo?.av_return_roll) { return alert.none('该订单已申请过退款') } + setRefundShow(true) + } + else if (status == 7) { + // 购买 + addShopCart(orderInfo) + } + else if (status == 9) { + onReturnRecordShow() + } + else if (status == 10) { + setShowScanPayCheck(true) + } + }, + [orderData], + ) + useDidHide(() => { + setSearchField(e => ({ ...e, status: -1 })) + }) return ( @@ -236,3 +233,5 @@ export default () => { ) } + +export default OrderList diff --git a/src/pages/salesAfter/index.tsx b/src/pages/salesAfter/index.tsx index 28ff014..08ea396 100644 --- a/src/pages/salesAfter/index.tsx +++ b/src/pages/salesAfter/index.tsx @@ -17,124 +17,7 @@ import { formatDateTime, formatImgUrl, formatPriceDiv } from '@/common/fotmat' import { AFTER_ORDER_STATUS, ORDER_STATUS } from '@/common/enum' import { SaleOrderOrderDetailApi } from '@/api/salesAfterOrder' -export default () => { - useLogin() - const router = useRouter() - const orderId = useRef(Number(router.params.id)) - useDidShow(() => { - getSaleOrderPreView() - }) - - // 获取订单详情 - const [orderDetail, setOrderDetail] = useState() // 获取到的原始数据 - const { fetchData: saleOrderOrderDetailData } = SaleOrderOrderDetailApi() - const getSaleOrderPreView = async() => { - if (orderId.current) { - const res = await saleOrderOrderDetailData({ id: orderId.current }) - setOrderDetail(res.data) - } - Taro.stopPullDownRefresh() - } - - // 监听获取到的数据 - useEffect(() => { - if (orderDetail) { formatData() } - }, [orderDetail]) - - // 格式化数据格式 - const [formatDetailOrder, setFormatDetailOrder] = useState() // 格式化后的数据 - const formatData = () => { - setFormatDetailOrder({ - ...orderDetail, - unit: orderDetail.sale_mode == 0 ? '条' : 'm', // 单位 - }) - } - const formatPreViewOrderMemo = useMemo(() => { - return formatDetailOrder - }, [formatDetailOrder]) - - // 获取底部按钮点击, 获取按钮状态 - const orderStateClick = useCallback( - (val) => { - if (val == 1 || val == 6) { - getSaleOrderPreView() - } - else if (val == 8) { - // 申请记录 - setApplyRecord(true) - } - else if (val == 5) { - onShowLogistics(1) - } - else if (val == 7) { - setReturnCodeShow(true) - } - }, - [orderDetail], - ) - - // 页面下拉刷新 - usePullDownRefresh(() => { - getSaleOrderPreView() - }) - - // 按钮所需数据 - const orderInfo = useMemo(() => { - return { - ...orderDetail, - } - }, [orderDetail]) - - // 售后订单状态枚举 - const {} = AFTER_ORDER_STATUS - - // 物流显示 - const [logisticsShow, setLogisticsShow] = useState(false) - const [logistics, setLogistics] = useState(false) - const onShowLogistics = useCallback((val) => { - setLogisticsShow(true) - if (val != 1) { setLogistics(true) } - }, []) - const onCloseLogistics = useCallback(() => { - setLogisticsShow(false) - }, []) - // 物流成功上传 - const logisticsSuccess = useCallback(() => { - setLogisticsShow(false) - getSaleOrderPreView() - }, []) - - // 显示记录 - const [applyRecord, setApplyRecord] = useState(false) - - // 显示码单 - const [returnCodeShow, setReturnCodeShow] = useState(false) - - return ( - - - - - - - - - setApplyRecord(false)} /> - setReturnCodeShow(false)} /> - - - ) -} - -const OrderDes = memo(({ orderInfo }: { orderInfo?: any }) => { +const OrderDes = ({ orderInfo }: { orderInfo?: any }) => { // 复制功能 const clipboardData = (val) => { Taro.setClipboardData({ @@ -183,9 +66,9 @@ const OrderDes = memo(({ orderInfo }: { orderInfo?: any }) => { ) -}) - -const AfterSalePricture = memo(({ urls = [] }: { urls: string[] }) => { +} +const OrderDesWithMemo = memo(OrderDes) +const AfterSalePricture = ({ urls = [] }: { urls: string[] }) => { const showList = useMemo(() => { const res = urls.map((item) => { return formatImgUrl(item, '!w800') @@ -203,12 +86,126 @@ const AfterSalePricture = memo(({ urls = [] }: { urls: string[] }) => { return ( - {urls?.map(item => ( - + {urls?.map((item, key) => ( + ))} ) -}) +} +const AfterSalePrictureWithMemo = memo(AfterSalePricture) +const SalesAfter = () => { + useLogin() + const router = useRouter() + const orderId = useRef(Number(router.params.id)) + + // 获取订单详情 + const [orderDetail, setOrderDetail] = useState() // 获取到的原始数据 + const { fetchData: saleOrderOrderDetailData } = SaleOrderOrderDetailApi() + const getSaleOrderPreView = async() => { + if (orderId.current) { + const res = await saleOrderOrderDetailData({ id: orderId.current }) + setOrderDetail(res.data) + } + Taro.stopPullDownRefresh() + } + + // 格式化数据格式 + const [formatDetailOrder, setFormatDetailOrder] = useState() // 格式化后的数据 + const formatData = () => { + setFormatDetailOrder({ + ...orderDetail, + unit: orderDetail.sale_mode == 0 ? '条' : 'm', // 单位 + }) + } + const formatPreViewOrderMemo = useMemo(() => { + return formatDetailOrder + }, [formatDetailOrder]) + + // 页面下拉刷新 + usePullDownRefresh(() => { + getSaleOrderPreView() + }) + useDidShow(() => { + getSaleOrderPreView() + }) + // 按钮所需数据 + const orderInfo = useMemo(() => { + return { + ...orderDetail, + } + }, [orderDetail]) + + // 售后订单状态枚举 + const {} = AFTER_ORDER_STATUS + + // 物流显示 + const [logisticsShow, setLogisticsShow] = useState(false) + const [logistics, setLogistics] = useState(false) + const onShowLogistics = useCallback((val) => { + setLogisticsShow(true) + if (val != 1) { setLogistics(true) } + }, []) + const onCloseLogistics = useCallback(() => { + setLogisticsShow(false) + }, []) + // 物流成功上传 + const logisticsSuccess = useCallback(() => { + setLogisticsShow(false) + getSaleOrderPreView() + }, []) + + // 显示记录 + const [applyRecord, setApplyRecord] = useState(false) + + // 显示码单 + const [returnCodeShow, setReturnCodeShow] = useState(false) + // 获取底部按钮点击, 获取按钮状态 + const orderStateClick = useCallback( + (val) => { + if (val == 1 || val == 6) { + getSaleOrderPreView() + } + else if (val == 8) { + // 申请记录 + setApplyRecord(true) + } + else if (val == 5) { + onShowLogistics(1) + } + else if (val == 7) { + setReturnCodeShow(true) + } + }, + [orderDetail], + ) + // 监听获取到的数据 + useEffect(() => { + if (orderDetail) { formatData() } + }, [orderDetail]) + return ( + + + + + + + + + setApplyRecord(false)} /> + setReturnCodeShow(false)} /> + + + ) +} +export default SalesAfter diff --git a/src/pages/salesAfter/salesAfterList/index.tsx b/src/pages/salesAfter/salesAfterList/index.tsx index 03855de..6f1c80d 100644 --- a/src/pages/salesAfter/salesAfterList/index.tsx +++ b/src/pages/salesAfter/salesAfterList/index.tsx @@ -14,7 +14,7 @@ import { GetSaleOrderListApi, RefundOrderSatausApi } from '@/api/salesAfterOrder import useLogin from '@/use/useLogin' import Search from '@/components/search' -export default () => { +const SalesAfterList = () => { useLogin() // 搜索参数 @@ -40,20 +40,6 @@ export default () => { // 获取订单列表 const { fetchData: listFetchData, state: orderState } = GetSaleOrderListApi() const [orderData, setOrderData] = useState<{ list: any[]; total: number }>({ list: [], total: 0 }) - const getOrderList = async() => { - const res = await listFetchData(getFilterData(searchField)) - setOrderData({ list: res.data.list, total: res.data.total }) - setRefresherTriggeredStatus(() => false) - } - - useDidShow(() => { - if (searchField.status != null) { getOrderList() } - }) - - // 监听筛选条件变化 - useEffect(() => { - if (searchField.status != null) { getOrderList() } - }, [searchField]) // 上拉加载数据 const pageNum = useRef({ size: searchField.size, page: searchField.page }) @@ -91,9 +77,40 @@ export default () => { setRefresherTriggeredStatus(true) setSearchField(val => ({ ...val, size: 10 })) } - + const getOrderList = async() => { + const res = await listFetchData(getFilterData(searchField)) + setOrderData({ list: res.data.list, total: res.data.total }) + setRefresherTriggeredStatus(() => false) + } // 监听点击的按钮 const [callBackOrderInfo, setCallBackPayOrderInfo] = useState() + + // 显示记录 + const [applyRecord, setApplyRecord] = useState(false) + + // 显示码单 + const [returnCodeShow, setReturnCodeShow] = useState(false) + useDidShow(() => { + if (searchField.status != null) { getOrderList() } + }) + + // 监听筛选条件变化 + useEffect(() => { + if (searchField.status != null) { getOrderList() } + }, [searchField]) + // 物流显示 + const [logisticsShow, setLogisticsShow] = useState(false) + const onShowLogistics = useCallback((val) => { + setLogisticsShow(true) + }, []) + const onCloseLogistics = useCallback(() => { + setLogisticsShow(false) + }, []) + // 物流成功上传 + const logisticsSuccess = useCallback(() => { + setLogisticsShow(false) + getOrderList() + }, [orderData]) const clickOrderBtn = useCallback( ({ status, orderInfo }) => { if (status == 1 || status == 6) { @@ -113,27 +130,6 @@ export default () => { }, [orderData], ) - - // 显示记录 - const [applyRecord, setApplyRecord] = useState(false) - - // 显示码单 - const [returnCodeShow, setReturnCodeShow] = useState(false) - - // 物流显示 - const [logisticsShow, setLogisticsShow] = useState(false) - const onShowLogistics = useCallback((val) => { - setLogisticsShow(true) - }, []) - const onCloseLogistics = useCallback(() => { - setLogisticsShow(false) - }, []) - // 物流成功上传 - const logisticsSuccess = useCallback(() => { - setLogisticsShow(false) - getOrderList() - }, [orderData]) - return ( @@ -170,3 +166,5 @@ export default () => { ) } + +export default SalesAfterList diff --git a/src/pages/search/index.tsx b/src/pages/search/index.tsx index b229a4f..ba7bbb9 100644 --- a/src/pages/search/index.tsx +++ b/src/pages/search/index.tsx @@ -7,7 +7,7 @@ import Search from '@/components/search' import { goLink } from '@/common/common' import useLogin from '@/use/useLogin' -export default () => { +const SearchBar = () => { useLogin() return ( @@ -45,3 +45,5 @@ export default () => { ) } + +export default SearchBar diff --git a/src/pages/subjectList/components/filter/index.tsx b/src/pages/subjectList/components/filter/index.tsx index e92e4fa..9f78be2 100644 --- a/src/pages/subjectList/components/filter/index.tsx +++ b/src/pages/subjectList/components/filter/index.tsx @@ -3,12 +3,12 @@ import classnames from 'classnames' import { useEffect, useState } from 'react' import styles from './index.module.scss' import Popup from '@/components/popup' -import type { Params as PopuParams } from '@/components/popup' +import type { Params as PopuParams } from '@/components/popup' type params = { onFiltr?: (val: object) => void } & PopuParams -export default ({ onClose, onFiltr, show = false }: params) => { +const Filter = ({ onClose, onFiltr, show = false }: params) => { const [filterObj, setFilterObj] = useState({ series: '', minWidth: '', @@ -43,9 +43,9 @@ export default ({ onClose, onFiltr, show = false }: params) => { const setNumber = (e, field) => { console.log(e) const num = parseFloat(e.detail.value) - if (isNaN(num)) { + if (Number.isNaN(num)) { filterObj[field] = null - } + } else { filterObj[field] = parseFloat(num.toFixed(2)) } @@ -156,3 +156,5 @@ export default ({ onClose, onFiltr, show = false }: params) => { ) } + +export default Filter diff --git a/src/pages/user/index.tsx b/src/pages/user/index.tsx index fea24d2..e45bc45 100644 --- a/src/pages/user/index.tsx +++ b/src/pages/user/index.tsx @@ -11,83 +11,8 @@ import { userassets, userorderStatistics } from '@/api/mine' import { formatImgUrl, formatPriceDiv } from '@/common/fotmat' import { GetAdminUserInfoApi } from '@/api/user' -export default () => { - // 用户信息 - const { getSelfUserInfo, getAdminUserInfo } = useLogin() - const { adminUserInfo } = useSelector(state => state.userInfo) - - const [current_version, setCurrent_version] = useState(CURRENT_VERSION) - const [current_githash, setCurrent_githash] = useState(CURRENT_GITHASH) - const [current_env, setCurrent_env] = useState(CURRENT_ENV) - - const handleAuth = async() => { - console.log('授权面版') - if (adminUserInfo?.is_authorize_name) { return false } - getSelfUserInfo() - .then() - .catch(() => { - alert.none('授权失败,请授权后再使用') - }) - } - const { fetchData: Apiassets, state } = userassets() - const { fetchData: ApigetTotal, state: stateData } = userorderStatistics() - - useDidShow(() => { - ApigetTotal() - getAdminUserInfo() - Apiassets() - }) - - // 临时注释 - // const checkGo = async () => { - // if (adminUserInfo?.authentication_status !== 4) { - // let res = await Taro.showModal({ - // title: '提示', - // content: '你暂未开通授信,目前仅支持线下申请,开通后可使用账期采购。', - // cancelText: '稍后认证', - // confirmText: '联系客服', - // }) - // if (res.confirm) { - // Taro.showModal({ - // content: '联系电话:0757-8270 6695', - // cancelText: '取消', - // confirmText: '拨打', - // success: function (res) { - // if (res.confirm) { - // Taro.makePhoneCall({ - // phoneNumber: '(0757)82706695', - // }) - // } - // }, - // }) - // } - // } else { - // Taro.navigateTo({ - // url: '/pages/creditLine/index', - // }) - // } - // } - const checkGo = async() => { - Taro.navigateTo({ - url: '/pages/creditLine/index', - }) - } - - return ( - -
- checkGo()} userInfo={adminUserInfo} /> -
- {/* {(adminUserInfo as any)?.authentication_status==1&&} */} - {/* 测试暂时添加 */} - {current_version} - {current_env === 'development' && {BASE_URL}} - {!adminUserInfo?.is_authorize_name && } - - ) -} // 提示弹窗 -const Modal = memo((props: any) => { +const Modal = (props: any) => { const { data } = props const [modalShow, setModalShow] = useState(true) const handleouter = () => {} @@ -115,10 +40,11 @@ const Modal = memo((props: any) => { )} ) -}) +} +const ModalWithMemo = memo(Modal) // 头部 | 订单 -const Header = memo((props: any) => { +const Header = (props: any) => { const { data } = props console.log(props, 'propsprops') const menu = [ @@ -220,24 +146,24 @@ const Header = memo((props: any) => { )} {/* - - 1 - {data?.authentication_status==1&&"未认证"} - {data?.authentication_status==2&&"认证中"} - {data?.authentication_status==3&&"认证不通过"} - {data?.authentication_status==4&&"已认证"} - - {data?.authentication_status==1&&认证通过后,解锁更多权限 } - {data?.authentication_status==2&&1-3个工作日,审核完成 } - {data?.authentication_status==3&&重新认证 } - {data?.authentication_status==4&&认证通过,可以下单啦 } - */} + + 1 + {data?.authentication_status==1&&"未认证"} + {data?.authentication_status==2&&"认证中"} + {data?.authentication_status==3&&"认证不通过"} + {data?.authentication_status==4&&"已认证"} + + {data?.authentication_status==1&&认证通过后,解锁更多权限 } + {data?.authentication_status==2&&1-3个工作日,审核完成 } + {data?.authentication_status==3&&重新认证 } + {data?.authentication_status==4&&认证通过,可以下单啦 } + */} {/* - {data?.authentication_status==1&&"暂未加入或注册组织"} - {data?.authentication_status==2&&data?.company_name} - {data?.authentication_status==3&&data?.company_name} - {data?.authentication_status==4&&data?.company_name} - */} + {data?.authentication_status==1&&"暂未加入或注册组织"} + {data?.authentication_status==2&&data?.company_name} + {data?.authentication_status==3&&data?.company_name} + {data?.authentication_status==4&&data?.company_name} + */} @@ -249,7 +175,7 @@ const Header = memo((props: any) => { {menu.map((item, index) => { return ( - + {item.text} {index == 0 && props.MenuData.data.wait_match !== 0 && ( @@ -285,7 +211,8 @@ const Header = memo((props: any) => { ) -}) +} +const HeaderWithMemo = memo(Header) // 我的资产 const Assets = (props: any) => { return ( @@ -303,12 +230,12 @@ const Assets = (props: any) => { 预存款 {/* - - {props.data.data.coupon_count || 0} - - - 优惠券 - */} + + {props.data.data.coupon_count || 0} + + + 优惠券 + */} props.checkShow()}> ¥ @@ -325,7 +252,7 @@ const Assets = (props: any) => { } // 功能 -const Main = memo(() => { +const Main = () => { const menu = [ { text: '我的客服', icon: 'icon-wodekefu', type: 'customer', label: '(0757) 8270 6695' }, { text: '地址管理', icon: 'icon-daohang', url: '/pages/addressManager/index', type: 'url' }, @@ -359,4 +286,81 @@ const Main = memo(() => { ) -}) +} +const MainWithMemo = memo(Main) +const User = () => { + // 用户信息 + const { getSelfUserInfo, getAdminUserInfo } = useLogin() + const { adminUserInfo } = useSelector(state => state.userInfo) + + const [current_version, setCurrent_version] = useState(CURRENT_VERSION) + const [current_githash, setCurrent_githash] = useState(CURRENT_GITHASH) + const [current_env, setCurrent_env] = useState(CURRENT_ENV) + + const handleAuth = async() => { + console.log('授权面版') + if (adminUserInfo?.is_authorize_name) { return false } + getSelfUserInfo() + .then() + .catch(() => { + alert.none('授权失败,请授权后再使用') + }) + } + const { fetchData: Apiassets, state } = userassets() + const { fetchData: ApigetTotal, state: stateData } = userorderStatistics() + + useDidShow(() => { + ApigetTotal() + getAdminUserInfo() + Apiassets() + }) + + // 临时注释 + // const checkGo = async () => { + // if (adminUserInfo?.authentication_status !== 4) { + // let res = await Taro.showModal({ + // title: '提示', + // content: '你暂未开通授信,目前仅支持线下申请,开通后可使用账期采购。', + // cancelText: '稍后认证', + // confirmText: '联系客服', + // }) + // if (res.confirm) { + // Taro.showModal({ + // content: '联系电话:0757-8270 6695', + // cancelText: '取消', + // confirmText: '拨打', + // success: function (res) { + // if (res.confirm) { + // Taro.makePhoneCall({ + // phoneNumber: '(0757)82706695', + // }) + // } + // }, + // }) + // } + // } else { + // Taro.navigateTo({ + // url: '/pages/creditLine/index', + // }) + // } + // } + const checkGo = async() => { + Taro.navigateTo({ + url: '/pages/creditLine/index', + }) + } + + return ( + + + checkGo()} userInfo={adminUserInfo} /> + + {/* {(adminUserInfo as any)?.authentication_status==1&&} */} + {/* 测试暂时添加 */} + {current_version} + {current_env === 'development' && {BASE_URL}} + {!adminUserInfo?.is_authorize_name && } + + ) +} +export default User diff --git a/src/store/index.ts b/src/store/index.ts index c8c7122..bd6b12c 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -7,7 +7,8 @@ const composeEnhancers && (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ // Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize... - }) : compose + }) + : compose const middlewares = [ thunkMiddleware, @@ -24,4 +25,4 @@ const enhancer = composeEnhancers( export default function configStore() { const store = createStore(rootReducer, enhancer) return store -} +} diff --git a/src/use/BlueToothCopy.tsx b/src/use/BlueToothCopy.tsx index a34611d..0cfc29d 100644 --- a/src/use/BlueToothCopy.tsx +++ b/src/use/BlueToothCopy.tsx @@ -69,8 +69,10 @@ const stateObj: stateStype = { // 取色仪主动返回的数据 deviceLab: null, } - -export default (props) => { +interface PropsType { + children?: React.ReactNode +} +const BlueToothCopy = (props: PropsType) => { const refStatus = useRef(stateObj) const [state, setState] = useState(refStatus.current) @@ -78,7 +80,32 @@ export default (props) => { refStatus.current = { ...refStatus.current, ...obj } setState({ ...refStatus.current }) } + /** 打开蓝牙适配器 */ + const openAdapter = () => { + return new Promise((resolve, reject) => { + Taro.openBluetoothAdapter({ + success: resolve, + fail: reject, + }) + }) + } + /** + * 推送事件 + * @param {{type: string; data: any}} event + */ + const emit = (event) => { + refStatus.current.listeners.forEach((cb) => { + cb && cb(event) + }) + } + const subscribe = (cb) => { + if (cb) { + changeStatus({ + listeners: refStatus.current.listeners.add(cb), + }) + } + } const init = async() => { try { await openAdapter() @@ -123,34 +150,6 @@ export default (props) => { }) } - /** 打开蓝牙适配器 */ - const openAdapter = () => { - return new Promise((resolve, reject) => { - Taro.openBluetoothAdapter({ - success: resolve, - fail: reject, - }) - }) - } - - /** - * 推送事件 - * @param {{type: string; data: any}} event - */ - const emit = (event) => { - refStatus.current.listeners.forEach((cb) => { - cb && cb(event) - }) - } - - const subscribe = (cb) => { - if (cb) { - changeStatus({ - listeners: refStatus.current.listeners.add(cb), - }) - } - } - /** * 获取蓝牙适配器状态 * @returns {Promise<{discovering: boolean; available: boolean}>} @@ -163,7 +162,15 @@ export default (props) => { }) }) } - + // 获取搜索到的设备 + const getDevices = (res) => { + res.devices.forEach((device) => { + // 排除掉已搜索到的设备和名称不合法的设备, 将新发现的设备添加到列表中 + if (/^CM/.test(device.name) && !refStatus.current.devices.find(i => i.deviceId === device.deviceId)) { + changeStatus({ devices: [...refStatus.current.devices, device] }) + } + }) + } /** * 启动设备扫描 * @param {(res: { devices: { name: string, deviceId: string, RSSI: number }[] }) => void} cb @@ -190,16 +197,6 @@ export default (props) => { }) } - // 获取搜索到的设备 - const getDevices = (res) => { - res.devices.forEach((device) => { - // 排除掉已搜索到的设备和名称不合法的设备, 将新发现的设备添加到列表中 - if (/^CM/.test(device.name) && !refStatus.current.devices.find(i => i.deviceId === device.deviceId)) { - changeStatus({ devices: [...refStatus.current.devices, device] }) - } - }) - } - /** * 连接设备 * @param {{ name: string, deviceId: string, RSSI: number }} device @@ -354,6 +351,7 @@ export default (props) => { * @returns {Promise} */ function exec(command) { + // eslint-disable-next-line no-async-promise-executor return new Promise(async(resolve, reject) => { if (refStatus.current.command) { reject(new Error('正在执行其他命令')) @@ -488,3 +486,5 @@ export const useBluetoothTwo = () => { return {} } } + +export default BlueToothCopy diff --git a/src/use/contextBlueTooth.tsx b/src/use/contextBlueTooth.tsx index 86e9881..503120b 100644 --- a/src/use/contextBlueTooth.tsx +++ b/src/use/contextBlueTooth.tsx @@ -69,8 +69,10 @@ const stateObj: stateStype = { // 取色仪主动返回的数据 deviceLab: null, } - -export default (props) => { +interface PropsType { + children?: React.ReactNode +} +const ContextBlueTooth = (props: PropsType) => { const refStatus = useRef(stateObj) const [state, setState] = useState(refStatus.current) @@ -79,50 +81,6 @@ export default (props) => { setState({ ...refStatus.current }) } - const init = async() => { - try { - await openAdapter() - } - catch (e) { - changeStatus({ available: false }) - } - - // 绑定事件通知 - Taro.onBluetoothAdapterStateChange((res) => { - emit({ type: 'stateUpdate', detail: res }) - }) - Taro.onBLEConnectionStateChange((res) => { - emit({ type: res.connected ? 'connected' : 'disconnect', detail: res }) - }) - Taro.onBLECharacteristicValueChange(({ value }) => notifySubscriber(value)) - subscribe(async(ev) => { - if (ev.type === 'stateUpdate') { - // 蓝牙状态发生的变化 - changeStatus({ discovering: ev.detail.discovering, available: ev.detail.available }) - } - else if (ev.type === 'disconnect' && refStatus.current.connected && refStatus.current.connected.deviceId === ev.detail.deviceId) { - // 断开连接 - changeStatus({ - connected: null, - serviceId: null, - characteristicId: null, - deviceLab: null, - devices: [], - }) - Taro.showToast({ icon: 'none', title: '蓝牙连接已断开' }) - } - else if (ev.type === 'connected' && refStatus.current.connecting) { - // 连接成功 - changeStatus({ connected: refStatus.current.connecting, connecting: null }) - Taro.showToast({ title: '蓝牙已连接' }) - } - else if (ev.type === 'measure') { - // 监听取色仪主动推送lab - await measureAndGetLab() - } - }) - } - /** 打开蓝牙适配器 */ const openAdapter = () => { return new Promise((resolve, reject) => { @@ -163,7 +121,59 @@ export default (props) => { }) }) } + const init = async() => { + try { + await openAdapter() + } + catch (e) { + changeStatus({ available: false }) + } + // 绑定事件通知 + Taro.onBluetoothAdapterStateChange((res) => { + emit({ type: 'stateUpdate', detail: res }) + }) + Taro.onBLEConnectionStateChange((res) => { + emit({ type: res.connected ? 'connected' : 'disconnect', detail: res }) + }) + Taro.onBLECharacteristicValueChange(({ value }) => notifySubscriber(value)) + subscribe(async(ev) => { + if (ev.type === 'stateUpdate') { + // 蓝牙状态发生的变化 + changeStatus({ discovering: ev.detail.discovering, available: ev.detail.available }) + } + else if (ev.type === 'disconnect' && refStatus.current.connected && refStatus.current.connected.deviceId === ev.detail.deviceId) { + // 断开连接 + changeStatus({ + connected: null, + serviceId: null, + characteristicId: null, + deviceLab: null, + devices: [], + }) + Taro.showToast({ icon: 'none', title: '蓝牙连接已断开' }) + } + else if (ev.type === 'connected' && refStatus.current.connecting) { + // 连接成功 + changeStatus({ connected: refStatus.current.connecting, connecting: null }) + Taro.showToast({ title: '蓝牙已连接' }) + } + else if (ev.type === 'measure') { + // 监听取色仪主动推送lab + await measureAndGetLab() + } + }) + } + + // 获取搜索到的设备 + const getDevices = (res) => { + res.devices.forEach((device) => { + // 排除掉已搜索到的设备和名称不合法的设备, 将新发现的设备添加到列表中 + if (/^CM/.test(device.name) && !refStatus.current.devices.find(i => i.deviceId === device.deviceId)) { + changeStatus({ devices: [...refStatus.current.devices, device] }) + } + }) + } /** * 启动设备扫描 * @param {(res: { devices: { name: string, deviceId: string, RSSI: number }[] }) => void} cb @@ -190,16 +200,6 @@ export default (props) => { }) } - // 获取搜索到的设备 - const getDevices = (res) => { - res.devices.forEach((device) => { - // 排除掉已搜索到的设备和名称不合法的设备, 将新发现的设备添加到列表中 - if (/^CM/.test(device.name) && !refStatus.current.devices.find(i => i.deviceId === device.deviceId)) { - changeStatus({ devices: [...refStatus.current.devices, device] }) - } - }) - } - /** * 连接设备 * @param {{ name: string, deviceId: string, RSSI: number }} device @@ -212,7 +212,7 @@ export default (props) => { await discoverService(device.deviceId) await discoverCharacteristic(device.deviceId) await notifyCharacteristicValueChange(device.deviceId) - } + } catch (e) { changeStatus({ connecting: null }) Taro.showToast({ icon: 'none', title: '蓝牙连接失败' }) @@ -273,7 +273,7 @@ export default (props) => { const service = services.find(i => refStatus.current.serviceRule.test(i.uuid)) if (!service) { reject(new Error('服务不可用')) - } + } else { changeStatus({ serviceId: service.uuid }) resolve(service) @@ -294,7 +294,7 @@ export default (props) => { const characteristic = characteristics.find(i => refStatus.current.characteristicRule.test(i.uuid)) if (!characteristic) { reject(new Error('特征不可用')) - } + } else { changeStatus({ characteristicId: characteristic.uuid }) resolve(characteristic) @@ -332,13 +332,13 @@ export default (props) => { if (refStatus.current.command.isComplete) { if (refStatus.current.command.isValid && refStatus.current.responseResolve) { refStatus.current.responseResolve(refStatus.current.command.response) - } + } else if (!refStatus.current.command.isValid) { refStatus.current.responseReject(new Error('无效数据')) } resetCommand() } - } + } else { const uint8Array = new Uint8Array(buffer) if (uint8Array[0] === 0xBB && uint8Array[1] === 1 && uint8Array[3] === 0) { @@ -354,10 +354,11 @@ export default (props) => { * @returns {Promise} */ function exec(command) { + // eslint-disable-next-line no-async-promise-executor return new Promise(async(resolve, reject) => { if (refStatus.current.command) { reject(new Error('正在执行其他命令')) - } + } else { try { refStatus.current.command = command @@ -369,7 +370,7 @@ export default (props) => { if (command.responseSize <= 0) { resolve(true) resetCommand() - } + } else { refStatus.current.responseReject = reject refStatus.current.responseResolve = resolve @@ -378,7 +379,7 @@ export default (props) => { resetCommand() }, command.timeout) } - } + } catch (e) { reject(e) } @@ -483,8 +484,10 @@ export const useBluetooth = () => { const res = React.useContext(Context) if (res) { return { ...res } - } + } else { return {} } } + +export default ContextBlueTooth diff --git a/src/use/useCheckAuthorize.tsx b/src/use/useCheckAuthorize.tsx index a5ad7c7..075cadc 100644 --- a/src/use/useCheckAuthorize.tsx +++ b/src/use/useCheckAuthorize.tsx @@ -23,32 +23,34 @@ interface Param { export default ({ scope, msg }: Param) => { // 这个hook微信授权检查授权 const check = useCallback(() => { - return new Promise((reslove, reject) => { + return new Promise((resolve, reject) => { Taro.getSetting({ success: (res) => { if (res.authSetting[scope]) { - reslove(true) - } + resolve(true) + } else if (res.authSetting[scope] === undefined) { Taro.authorize({ scope, success() { - reslove(true) + resolve(true) }, fail() { alert.none(msg) + // eslint-disable-next-line prefer-promise-reject-errors reject(false) }, }) - } + } else { Taro.openSetting({ success(res) { if (res.authSetting[scope]) { - reslove(true) - } + resolve(true) + } else { alert.none(msg) + // eslint-disable-next-line prefer-promise-reject-errors reject(false) } }, diff --git a/src/use/useCommon.ts b/src/use/useCommon.ts index 0ecf498..9492537 100644 --- a/src/use/useCommon.ts +++ b/src/use/useCommon.ts @@ -14,16 +14,7 @@ export const useTimeCountDown = () => { const [timeStatus, setTimeStatus] = useState<0 | 1 | 2>(0) // 倒计时状体 0:倒计时未开始 1:倒计时中, 2:倒计时已结束 const timeObj: any = useRef() const endTime = useRef('') - const onStart = (val = '') => { - console.log('time:::', val) - endTime.current = val - if (endTime.current) { - clearInterval(timeObj.current) - timeObj.current = setInterval(() => { - count_down() - }, 1000) - } - } + useEffect(() => { return () => { clearInterval(timeObj.current) @@ -55,6 +46,16 @@ export const useTimeCountDown = () => { console.log('endTime::', `${DD}-${HH}-${MM}-${SS}`) setShowTime(e => ({ ...e, DD, HH, MM, SS })) } + const onStart = (val = '') => { + console.log('time:::', val) + endTime.current = val + if (endTime.current) { + clearInterval(timeObj.current) + timeObj.current = setInterval(() => { + count_down() + }, 1000) + } + } return { showTime, onStart, @@ -66,6 +67,7 @@ export const useTimeCountDown = () => { export const UseSubscriptionMessage = () => { const { fetchData: fetchDataMessage } = SubscriptionMessageApi() const openSubscriptionMessage = ({ orderId = 0, scenes = 0 }: { orderId?: number; scenes: number }) => { + // eslint-disable-next-line no-async-promise-executor return new Promise(async(resolve) => { const params: { sale_order_id?: number; scenes?: number } = {} orderId && (params.sale_order_id = orderId) @@ -78,7 +80,7 @@ export const UseSubscriptionMessage = () => { resolve(res) }, }) - } + } else { resolve(true) } diff --git a/src/use/useLogin.ts b/src/use/useLogin.ts index 5867cc1..578b604 100644 --- a/src/use/useLogin.ts +++ b/src/use/useLogin.ts @@ -11,11 +11,50 @@ import { formatImgUrl } from '@/common/fotmat' export default () => { const { setUserInfo, setAdminUserInfo, setSortCode, userInfo } = useUserInfo() + // 获取用户信息 + const { fetchData: FetchData } = GetAdminUserInfoApi() - useDidShow(() => { - checkLogin() - }) + // 获取分享码(右上角分享码) + const { SharePage } = SHARE_SCENE + const { fetchData: fetchDataShortCode } = GetShortCodeApi() + const getShortCode = async(user_id) => { + const { data: resPage } = await fetchDataShortCode({ share_user_id: user_id, type: SharePage.value }) + setSortCode({ + ...userInfo.sort_code, + shareShortPage: { title: '打造面料爆品 专注客户服务', code: resPage.md5_key, img: `${IMG_CND_Prefix}/mall/share_img_01.png` }, + }) + } + const getAdminUserInfo = async() => { + const res = await FetchData() + res.data.avatar_url = res.data.avatar_url ? res.data.avatar_url : formatImgUrl('/user/avatar.png') + setAdminUserInfo({ ...res.data }) + getShortCode(res.data.user_id) + } + // 获取用户头像等信息数据 + const { fetchData: fetchDataUserInfo } = GetWxUserInfoApi() + // 获取手机号码 + const { fetchData: fetchDataUserPhone } = GetPhoneNumberApi() + const { fetchData: fetchBindingCompany } = BindingCompanyApi() + const getPhoneNumber = (code) => { + // eslint-disable-next-line no-async-promise-executor + return new Promise(async(resolve, reject) => { + if (userInfo.adminUserInfo?.is_authorize_phone) { + resolve(true) + return true + } + const res = await fetchDataUserPhone({ code }) + if (res.success) { + setUserInfo({ ...userInfo.userInfo, phone: res.data.phone_number }) + await fetchBindingCompany() + getAdminUserInfo() + resolve(res.data) + } + else { + reject(res.msg) + } + }) + } // 登录请求 const { login } = useLoginRequest() // const {fetchData:login} = LoginApi() @@ -23,50 +62,41 @@ export default () => { try { await login() getAdminUserInfo() - } + } catch (e) { console.log('登录失败::', e) } } - - // 获取用户信息 - const { fetchData: useFetchData } = GetAdminUserInfoApi() - const getAdminUserInfo = async() => { - const res = await useFetchData() - res.data.avatar_url = res.data.avatar_url ? res.data.avatar_url : formatImgUrl('/user/avatar.png') - setAdminUserInfo({ ...res.data }) - getShortCode(res.data.user_id) - } - // 登录加checkLogin检查 const checkLogin = () => { - return new Promise(async(reslove) => { + // eslint-disable-next-line no-async-promise-executor + return new Promise(async(resolve) => { if (!userInfo.token) { await wxLogin() - reslove(true) - } + resolve(true) + } else { // 这个东西不要打开,checkSession有调用频率问题 // Taro.checkSession({ // success: async () => { - // reslove(true) + // resolve(true) // if(!userInfo.adminUserInfo) getAdminUserInfo() // }, // fail: async () => { // await wxLogin() - // reslove(true) + // resolve(true) // } // }) } }) } - - // 获取用户头像等信息数据 - const { fetchData: fetchDataUserInfo } = GetWxUserInfoApi() + useDidShow(() => { + checkLogin() + }) const getSelfUserInfo = async() => { - return new Promise((reslove, reject) => { + return new Promise((resolve, reject) => { if (userInfo.adminUserInfo?.is_authorize_name) { - reslove(true) + resolve(true) return true } Taro.getUserProfile({ @@ -85,8 +115,8 @@ export default () => { if (user_res.success) { setUserInfo({ ...user_res.data }) getAdminUserInfo() - reslove(true) - } + resolve(true) + } else { reject(user_res.msg) } @@ -98,40 +128,6 @@ export default () => { }) }) } - - // 获取手机号码 - const { fetchData: fetchDataUserPhone } = GetPhoneNumberApi() - const { fetchData: fetchBindingCompany } = BindingCompanyApi() - const getPhoneNumber = (code) => { - return new Promise(async(reslove, reject) => { - if (userInfo.adminUserInfo?.is_authorize_phone) { - reslove(true) - return true - } - const res = await fetchDataUserPhone({ code }) - if (res.success) { - setUserInfo({ ...userInfo.userInfo, phone: res.data.phone_number }) - await fetchBindingCompany() - getAdminUserInfo() - reslove(res.data) - } - else { - reject(res.msg) - } - }) - } - - // 获取分享码(右上角分享码) - const { SharePage } = SHARE_SCENE - const { fetchData: fetchDataShortCode } = GetShortCodeApi() - const getShortCode = async(user_id) => { - const { data: resPage } = await fetchDataShortCode({ share_user_id: user_id, type: SharePage.value }) - setSortCode({ - ...userInfo.sort_code, - shareShortPage: { title: '打造面料爆品 专注客户服务', code: resPage.md5_key, img: `${IMG_CND_Prefix}/mall/share_img_01.png` }, - }) - } - return { checkLogin, wxLogin, diff --git a/src/use/useLoginRequest.ts b/src/use/useLoginRequest.ts index ab55f64..13e82f1 100644 --- a/src/use/useLoginRequest.ts +++ b/src/use/useLoginRequest.ts @@ -9,7 +9,7 @@ import { BASE_URL, WX_APPID } from '@/common/constant' interface Param { success: true|false; data: any; msg: string; code: null|number; loading: false|true } let loginStatus = false // 登录状态,true登录中 -export default () => { +export default () => { const initData = { success: false, data: null, @@ -39,15 +39,15 @@ export default () => { loginData.current.code = code loginData.current.msg = msg loginData.current.data = data - } + } else { Taro.showToast({ title: '错误:登录失败', icon: 'none', }) - console.log('登录错误:', result.errMsg) + console.log('登录错误:', result.errMsg) } - } + } catch (e) { Taro.showToast({ title: '错误:登录失败', @@ -62,7 +62,7 @@ export default () => { const login = () => { if (loginStatus) { return false } loginStatus = true - return new Promise((reslove, reject) => { + return new Promise((resolve, reject) => { Taro.login({ success: async(res) => { if (res.code) { @@ -70,20 +70,20 @@ export default () => { if (success) { setToken(data.token) setSessionKey(data.session_key) - reslove(data) + resolve(data) const params = router.params delete params.$taroTimestamp if (router.path === '/pages/index/index' || router.path === '/pages/user/index') { Taro.reLaunch({ url: `${router.path}?${qs.stringify(params)}`, }) - } + } else { Taro.redirectTo({ url: `${router.path}?${qs.stringify(params)}`, }) } - } + } else { Taro.showToast({ title: '登录失败', @@ -91,7 +91,7 @@ export default () => { }) reject(msg) } - } + } else { console.log(`登录失败!${res.errMsg}`) reject(res.errMsg) @@ -104,10 +104,10 @@ export default () => { loginStatus = false }, }) - }) + }) } return { login, - } + } } diff --git a/src/use/useUploadImage.ts b/src/use/useUploadImage.ts index 6b2edf1..bbe1169 100644 --- a/src/use/useUploadImage.ts +++ b/src/use/useUploadImage.ts @@ -11,6 +11,7 @@ export default () => { type 类型值,区分上传业务bucket */ const getSecret = (scene, type) => { + // eslint-disable-next-line no-async-promise-executor return new Promise(async(resolve, reject) => { const SAVE_PATH = `/${scene}/{filemd5}{day}{hour}{min}{sec}{.suffix}`