From 979373a2f464b5a92a81fd013febc8198785e00d Mon Sep 17 00:00:00 2001 From: xuan Date: Tue, 27 Dec 2022 15:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20build(svg):=20=E5=8D=87=E7=BA=A7?= =?UTF-8?q?taro-iconfont-svg=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/common.ts | 16 +++--- src/components/customer/index.tsx | 6 +-- src/components/shopCart/index.tsx | 42 ++++++++++++--- .../userEdit/components/ModifyModal/index.tsx | 21 +++++--- src/reducers/userInfo.ts | 51 ++++++++++--------- 5 files changed, 86 insertions(+), 50 deletions(-) diff --git a/src/common/common.ts b/src/common/common.ts index 2b2f0a4..b7c6a38 100644 --- a/src/common/common.ts +++ b/src/common/common.ts @@ -82,16 +82,16 @@ export const retrieval = (data: any, rules?: Object, message = '请填写完信 return new Promise((resolve, reject) => { if (rules) { const keys = Reflect.ownKeys(rules) - const result = keys.some((key: any) => { - for (const item of (rules as any)[key]) { + const result = keys.some((key: string) => { + return (rules as any)[key].some((rule) => { let _res = false - if (item.validator) { - if (item.validator(data[key], item)) { + if (rule.validator) { + if (rule.validator(data[key], rule)) { _res = true } } - else if (item.regex) { - if (!item.regex.test(data[key])) { + else if (rule.regex) { + if (!rule.regex.test(data[key])) { _res = true } } @@ -100,9 +100,9 @@ export const retrieval = (data: any, rules?: Object, message = '请填写完信 _res = true } } - message = item.message + message = rule.message return _res - } + }) }) if (result) { reject(message) diff --git a/src/components/customer/index.tsx b/src/components/customer/index.tsx index 2e3216f..cd503b8 100644 --- a/src/components/customer/index.tsx +++ b/src/components/customer/index.tsx @@ -9,8 +9,8 @@ import { alert } from '@/common/common' interface Param { onClose?: () => void - show: boolean, - messageTitle?: string, + show: boolean + messageTitle?: string messagePath?: string showCard?: true|false } @@ -46,7 +46,7 @@ export default (props: Param) => { className={styles.customer} openType="contact" sendMessageTitle={props.messageTitle} - showMessageCard = {props.showCard} + showMessageCard={props.showCard} sendMessagePath={props.messagePath} > diff --git a/src/components/shopCart/index.tsx b/src/components/shopCart/index.tsx index 0a7cd1d..0a4b86d 100644 --- a/src/components/shopCart/index.tsx +++ b/src/components/shopCart/index.tsx @@ -14,7 +14,7 @@ import Popup from '@/components/popup' import MCheckbox from '@/components/checkbox' import LoadingCard from '@/components/loadingCard' import InfiniteScroll from '@/components/infiniteScroll' -import { alert, goLink } from '@/common/common' +import { alert, goLink, retrieval } from '@/common/common' import { DelShoppingCartApi, GetShoppingCartApi, UpdateShoppingCartApi } from '@/api/shopCart' import { formatHashTag, formatImgUrl, formatPriceDiv } from '@/common/fotmat' import { setParam } from '@/common/system' @@ -22,6 +22,9 @@ import { debounce, throttle } from '@/common/util' import { ApplyOrderAccessApi, GetAdminUserInfoApi, SubscriptionMessageApi } from '@/api/user' import useCommonData from '@/use/useCommonData' import type { saleModeType } from '@/common/enum' +import { useSelector } from '@/reducers/hooks' +import { companyDetailApi, companyUpdateApi } from '@/api/company' +import useLogin from '@/use/useLogin' interface param { show?: true | false @@ -46,6 +49,8 @@ const ShopCart = ({ show = false, onClose, intoStatus = 'shop', default_sale_mod { value: 1, title: '剪板', unit: '米', eunit: 'm', step: 1, digits: 2, minNum: 0.3, maxNum: 100000, defaultNum: 0.3 }, { value: 2, title: '散剪', unit: '米', eunit: 'kg', step: 1, digits: 2, minNum: 3, maxNum: 100000, defaultNum: 3 }, ] + const userInfo = useSelector(state => state.userInfo) + const bindSalesManDialogRef = useRef(null) const [isPending, startTransition] = useTransition() @@ -276,12 +281,11 @@ const ShopCart = ({ show = false, onClose, intoStatus = 'shop', default_sale_mod if (res.data.order_access_status !== 3) { if (res.data.order_access_status == 1) { applyOrderAccessFetchData() } bindSalesManDialogRef.current?.handleChange(true) - // setShowBindSalesman(() => true) onClose?.() return } - // TODO 检测是否修改过组织昵称 - if (false) { + // 检测是否修改过组织昵称 + if (userInfo.adminUserInfo.first_change_name) { setShowModal(true) return } @@ -323,7 +327,31 @@ const ShopCart = ({ show = false, onClose, intoStatus = 'shop', default_sale_mod setSelectStatus(true) }) }, [selectIndex]) - + // 弹出修改组织昵称弹窗 + const handleBindSalesManSuccess = () => { + // 检测是否修改过组织昵称 + if (userInfo.adminUserInfo.first_change_name) { + setShowModal(true) + } + } + const { getAdminUserInfo } = useLogin() + const { fetchData: saveFetch } = companyUpdateApi() + const { fetchData: getCompanyFetch } = companyDetailApi() + const handleOrganizationNameModalConfirm = async(text: string) => { + const params = await getCompanyFetch() + const result = await saveFetch({ + ...params.data, + company_name: text, + }) + if (result.success) { + getAdminUserInfo() + handleClose() + alert.success('保存成功') + } + else { + alert.none(result.msg) + } + } return ( closePopup()}> @@ -389,12 +417,12 @@ const ShopCart = ({ show = false, onClose, intoStatus = 'shop', default_sale_mod - + - + ) } diff --git a/src/pages/userEdit/components/ModifyModal/index.tsx b/src/pages/userEdit/components/ModifyModal/index.tsx index 80f5312..8a1f90b 100644 --- a/src/pages/userEdit/components/ModifyModal/index.tsx +++ b/src/pages/userEdit/components/ModifyModal/index.tsx @@ -8,6 +8,7 @@ import styles from './index.module.scss' import Popup from '@/components/popup' import NormalButton from '@/components/normalButton' import IconFont from '@/components/iconfont/iconfont' +import { useSelector } from '@/reducers/hooks' interface Params { title?: string @@ -21,6 +22,7 @@ export interface ModifyModalRef { const ModifyModal = (props: Params, ref: Ref) => { const { title = '修改昵称', value: _value = '', isCompanyName = false } = props const [value, setValue] = useState('') + const userInfo = useSelector(state => state.userInfo) const [tipsComp, setTipsComp] = useState(null) // 不合法状态 @@ -42,8 +44,8 @@ const ModifyModal = (props: Params, ref: Ref) => { } // 修改组织名称 if (isCompanyName) { - // TODO 检测是否没机会修改 - if (true) { + // 检测是否没机会修改 + if (userInfo.adminUserInfo.first_change_name) { flag = false setTipsComp(() => { return @@ -67,7 +69,7 @@ const ModifyModal = (props: Params, ref: Ref) => { } } return flag - }, [value, isCompanyName]) + }, [value, isCompanyName, userInfo]) useEffect(() => { setValue(_value) @@ -101,14 +103,19 @@ const ModifyModal = (props: Params, ref: Ref) => { 请设置2-20个字符,可由中文、英文、数字组成 { - // TODO 检测是否没机会修改 - true - ? <> + // 检测是否没机会修改 + isCompanyName + ? userInfo.adminUserInfo.first_change_name + ? <> + 重置 + props.save(value)} type="primary" customClassName={classNames(styles.button, styles['modify-ickname-operation-save'])}>保存 + + : setModalShow(false)} type="primary" customClassName={classNames(styles.button, styles['modify-ickname-operation-IKnown'])}>知道了 + : <> 重置 props.save(value)} type="primary" customClassName={classNames(styles.button, styles['modify-ickname-operation-save'])}>保存 - : setModalShow(false)} type="primary" customClassName={classNames(styles.button, styles['modify-ickname-operation-IKnown'])}>知道了 } diff --git a/src/reducers/userInfo.ts b/src/reducers/userInfo.ts index 0a2fa90..36e087b 100644 --- a/src/reducers/userInfo.ts +++ b/src/reducers/userInfo.ts @@ -29,32 +29,33 @@ export interface UserParam { } export interface UserAdminParam { - avatar_url?: string - open_id?: string - physical_warehouse?: number - physical_warehouse_name?: string - union_id?: string - user_code?: string - user_id?: number - user_name?: string - wechat_user_open_id?: number - is_authorize_name?: false|true - is_authorize_phone?: false|true - phone?: string - authentication_status?: number + avatar_url: string + open_id: string + physical_warehouse: number + physical_warehouse_name: string + union_id: string + user_code: string + user_id: number + user_name: string + wechat_user_open_id: number + is_authorize_name: boolean + is_authorize_phone: boolean + phone: string + authentication_status: number authentication_status_name: string - company_id?: number - company_name?: string - founder_user_id?: string - founder_user_name?: string - order_access_status?: number - order_access_status_name?: string - purchaser_type?: number - purchaser_type_name?: string - collection_quantity?: number - sale_user_phone?: string - sale_user_name?: string - sale_user_id?: number|string + company_id: number + company_name: string + first_change_name: boolean + founder_user_id: string + founder_user_name: string + order_access_status: number + order_access_status_name: string + purchaser_type: number + purchaser_type_name: string + collection_quantity: number + sale_user_phone: string + sale_user_name: string + sale_user_id: number|string } export interface SortCodeParam {