// 成长值规则配置 成长规则配置 import React, { useRef, useState, Suspense } from 'react'; import moment from 'moment'; // 时间相关引用,没有使用可以删除 import numeral from "numeral"; // 数字相关引用,没有使用可以删除 import { connect } from 'umi'; import useRequest from '@ahooksjs/use-request'; // 请求数据的引用 import Draggable from 'react-draggable'; import SubMenu from "antd/lib/menu/SubMenu"; import ProTable from '@ant-design/pro-table'; import ProDescriptions from '@ant-design/pro-descriptions'; import ProForm, { ProFormDatePicker, ProFormDateTimePicker, ProFormMoney, ProFormSelect, ProFormText, ProFormTextArea, ProFormUploadButton } from '@ant-design/pro-form'; import { MenuFoldOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import { PageContainer } from '@ant-design/pro-layout'; import { Button, Col, Drawer, message, Row, Popconfirm, Space, Image, Modal, Form, Switch, Upload, Tooltip, Descriptions, TreeSelect } from 'antd'; import type { CurrentUser } from "umi"; import type { ConnectState } from '@/models/connect'; import type { ActionType, ProColumns } from '@ant-design/pro-table'; import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; import type { FormInstance } from 'antd'; import { getFieldEnumTree, getFieldEnumName } from "@/services/options"; // 枚举的引用,没有使用可以删除 import { handleDeleteGROWTHSETTING, handleGetGROWTHSETTINGList, handleSynchroGROWTHSETTING } from '../service'; import session from '@/utils/session'; import PageTitleBox from '@/components/PageTitleBox'; import ModalFooter from '../scenicSpotConfig/component/modalFooter'; import GrowthConfig from './components/growthConfig'; import { handleSetlogSave } from '@/utils/format'; import MembershipTypeConfig from './components/MEMBERSHIPTYPEConfig'; const { confirm } = Modal; const GrowthValueRuleConfig: React.FC<{ currentUser: CurrentUser | undefined }> = (props) => { const { currentUser } = props const actionRef = useRef(); const formRef = useRef(); const [currentRow, setCurrentRow] = useState(); const [showDetail, setShowDetail] = useState(); const [modalVisible, handleModalVisible] = useState(); const [showConfig, setShowConfig] = useState(); const [showTypeConfig, setShowTypeConfig] = useState(); const [confirmLoading, handleConfirmLoading] = useState(false) // 弹出框的内容表单是否在提交 const [searchParams, setSearchParams] = useState(); // 会员成长值枚举 let GROWTHTYPEList = session.get('GROWTHTYPEList') let GROWTHTYPEObj = session.get('GROWTHTYPEObj') let MEMBERSHIPTYPEYNObj = session.get('MEMBERSHIPTYPEYNObj') let MEMBERSHIPTYPEYNList = session.get('MEMBERSHIPTYPEYNList') let MEMBERSHIPLEVELYNObj = session.get('MEMBERSHIPLEVELYNObj') let MEMBERSHIPLEVELYNList = session.get('MEMBERSHIPLEVELYNList') // 弹出框拖动效果 const [bounds, setBounds] = useState<{ left: number, right: number, top: number, bottom: number }>() // 移动的位置 const [disabled, setDraggleDisabled] = useState() // 是否拖动 const draggleRef = React.createRef() // 初始会员等级列表 const [defaultMemberLevel, setDefaultMemberLevel] = useState(MEMBERSHIPLEVELYNList) // 晋升后会员等级列表 const [promotionMemberLevel, setPromotionMemberLevel] = useState(MEMBERSHIPLEVELYNList) // 先存表格数据 const [tableData, setTableData] = useState([]); // 判断是不是第一次进入页面 const [isFirst, setIsFirst] = useState(true) const onDraggaleStart = (event, uiData) => { const { clientWidth, clientHeight } = window.document.documentElement; const targetRect = draggleRef.current?.getBoundingClientRect(); if (!targetRect) { return; } setBounds({ left: -targetRect.left + uiData.x, right: clientWidth - (targetRect.right - uiData.x), top: -targetRect.top + uiData.y, bottom: clientHeight - (targetRect.bottom - uiData.y), }); }; // 拖动结束 // 定义列表字段内容 const columns: any = [ { dataIndex: 'GROWTHSETTING_TYPE', title: '规则类型', width: 120, align: 'center', hideInSearch: true, valueType: 'select', // valueEnum: GROWTHTYPEObj request: () => { let GROWTHTYPEList = session.get('GROWTHTYPEList') return GROWTHTYPEList }, render: (_, record) => { return record?.GROWTHSETTING_TYPE && GROWTHTYPEObj && GROWTHTYPEObj[record?.GROWTHSETTING_TYPE] ? { console.log('recordrecordrecord', record); handleSetlogSave(`查看【${record?.GROWTHSETTING_NAME}】规则详情`) setCurrentRow({ ...record }); handleModalVisible(true); }}> {GROWTHTYPEObj[record?.GROWTHSETTING_TYPE]} : '-' } }, // { // dataIndex: 'GROWTHSETTING_NAME', // title: '规则名称', // align: 'center', // width: 120, // hideInSearch: true, // hideInDescriptions: true, // render: (_, record) => { // return record?.GROWTHSETTING_NAME ? { // handleSetlogSave(`查看【${record?.GROWTHSETTING_NAME}】规则详情`) // setCurrentRow({ ...record }); // handleModalVisible(true); // }}>{record?.GROWTHSETTING_NAME} : '-' // } // }, { dataIndex: 'MEMBERSHIP_TYPE', title: '会员类型', align: 'center', width: 120, // hideInSearch: true, valueType: 'select', // valueEnum: MEMBERSHIPTYPEYNObj request: async () => { return MEMBERSHIPTYPEYNList } }, { dataIndex: 'MEMBERSHIP_LEVEL', title: '会员等级', align: 'center', width: 120, hideInSearch: true, valueType: 'select', valueEnum: MEMBERSHIPLEVELYNObj }, { dataIndex: 'PROMOTION_LEVEL', title: '晋升等级', width: 120, align: 'center', hideInSearch: true, valueEnum: MEMBERSHIPLEVELYNObj }, { dataIndex: 'GROWTH_VALUE', title: '所需成长值', width: 120, align: 'center', hideInSearch: true, }, // { // dataIndex: 'GROWTHDAILY_CAP', // title: '每日上限', // width: 120, // align: 'center', // hideInSearch: true, // }, { dataIndex: 'GROWTHTOTAL_CAP', title: '晋升后成长值', width: 120, align: 'center', hideInSearch: true, }, // { // dataIndex: 'PROVINCE_CODE', // title: '省份编码', // align: 'center', // hideInSearch: true, // }, // { // dataIndex: 'OWNERUNIT_NAME', // title: '业主单位名称', // align: 'center', // hideInSearch: true, // }, { dataIndex: 'GROWTHSETTING_STATE', title: '有效状态', width: 120, align: 'center', valueType: 'select', valueEnum: { "0": "无效", "1": "有效", }, initialValue: "1" }, // { // dataIndex: 'STAFF_NAME', // title: '操作人员', // align: 'center', // hideInSearch: true, // }, // { // dataIndex: 'OPERATE_DATE', // title: '操作时间', // valueType: 'fromNow', // align: 'center', // hideInSearch: true, // }, { dataIndex: 'GROWTHSETTING_DESC', title: '备注说明', width: 250, ellipsis: true, align: 'center', hideInSearch: true, }, // { // dataIndex: 'option', // title: '操作', // width: 120, // align: 'center', // valueType: 'option', // hideInSearch: true, // render: (_, record) => { // return ( // // { // setCurrentRow({ ...record }); // handleModalVisible(true); // }} // > // 编辑 // // { // await handelDelete(record.GROWTHSETTING_ID); // }} // > // 删除 // // // ); // }, // }, ]; const handelDelete = async (id: number) => { const result = await handleDeleteGROWTHSETTING({ GROWTHSETTINGId: id }); if (result.Result_Code !== 100) { message.error(`${result.Result_Desc}` || `${result.Result_Code}:删除失败`); } else { message.success('删除成功!'); handleSetlogSave(`删除【${currentRow?.GROWTHSETTING_NAME}】成功`) actionRef.current?.reload() handleConfirmLoading(false) handleModalVisible(false) } }; const handleAddUpdate = async (res: any) => { let req: any = {} if (res?.GROWTHSETTING_ID) { req = { ...currentRow, ...res } } else { req = { ...res, ADDTIME: moment().format('YYYY-MM-DD HH:mm:ss'), STAFF_ID: currentUser?.ID, STAFF_NAME: currentUser?.Name, OWNERUNIT_ID: currentUser?.OwnerUnitId, OWNERUNIT_NAME: currentUser?.OwnerUnitName, PROVINCE_CODE: currentUser?.ProvinceCode } } const data = await handleSynchroGROWTHSETTING(req); if (data.Result_Code === 100) { handleSetlogSave(`${currentRow?.GROWTHSETTING_ID ? '更新' : '新增'}【${data.Result_Data.GROWTHSETTING_NAME}】成功`) message.success(data.Result_Desc) formRef?.current?.resetFields() setCurrentRow(undefined) handleModalVisible(false) actionRef.current?.reload() } else { message.error(data.Result_Desc) } }; // 支持会员类型单个选择或者多个选择的 const handleNewAddUpdate = (newValue: any, newList: any) => { // newValue 表单数据 会员类型的数组 选择单个或所有类型 // 入参列表 let reqList: any = [] // 入参列表的提示信息 更新的 let reqListUpdateMsg: any = [] // 入参列表的提示信息 新增的 let reqListAddMsg: any = [] // for 循环 遍历去调用 批量新增 for (let i = 0; i < newList.length; i++) { let nowItem = newList[i]; // 找到当前项的会员类型 会员等级 规则类型 外面表格数据是否已经存在了 console.log('nowItemnowItemnowItemnowItem', nowItem); console.log('table', tableData); let req: any = {} if (tableData && tableData.length > 0) { tableData.forEach((item: any) => { // 判断 会员类型、会员等级、规则类型 是否一致 if (Number(item.MEMBERSHIP_TYPE) === Number(nowItem.value) && Number(newValue?.MEMBERSHIP_LEVEL) === Number(item.MEMBERSHIP_LEVEL) && Number(newValue?.GROWTHSETTING_TYPE) === Number(item.GROWTHSETTING_TYPE) && item.GROWTHSETTING_STATE === 1) { console.log('itemitemitemitem', item); req = { ...item } } }) } // 如果req 里面 有 GROWTHSETTING_ID 说明是更新的 console.log('reqreqreqreqreq', req); if (req?.GROWTHSETTING_ID) { reqList.push({ ...req, ...newValue, MEMBERSHIP_TYPE: nowItem.value }) reqListUpdateMsg.push(`${nowItem.label}【${GROWTHTYPEObj[newValue.GROWTHSETTING_TYPE]}】${MEMBERSHIPLEVELYNObj[newValue.PROMOTION_LEVEL]}`) } else { req = { ...newValue, MEMBERSHIP_TYPE: nowItem.value } reqList.push(req) reqListAddMsg.push(`${nowItem.label}【${GROWTHTYPEObj[newValue.GROWTHSETTING_TYPE]}】${MEMBERSHIPLEVELYNObj[newValue.PROMOTION_LEVEL]}`) } } console.log('reqListreqListreqListreqList', reqList); console.log('reqListUpdateMsgreqListUpdateMsgreqListUpdateMsg', reqListUpdateMsg); console.log('reqListAddMsgreqListAddMsgreqListAddMsgreqListAddMsg', reqListAddMsg); confirm({ title: '提示', content: `本次操作将 ${reqListUpdateMsg && reqListUpdateMsg.length > 0 ? '更新:' + reqListUpdateMsg.toString() : ""}${reqListAddMsg && reqListAddMsg.length > 0 ? ',新增:' + reqListAddMsg.toString() : ""},是否确认此次操作?`, width: 600, icon: , async onOk() { let isOK: boolean = await handleBatchUpdate(reqList) if (isOK) { formRef?.current?.resetFields() setCurrentRow(undefined) handleModalVisible(false) actionRef.current?.reload() } }, onCancel() { }, }); } // 批量更新的方法 const handleBatchUpdate = async (reqList: any) => { // reqList 入参列表 for (let i = 0; i < reqList.length; i++) { let res: any = reqList[i] let req: any = {} if (res?.GROWTHSETTING_ID) { req = { ...res } } else { req = { ...res, ADDTIME: moment().format('YYYY-MM-DD HH:mm:ss'), STAFF_ID: currentUser?.ID, STAFF_NAME: currentUser?.Name, OWNERUNIT_ID: currentUser?.OwnerUnitId, OWNERUNIT_NAME: currentUser?.OwnerUnitName, PROVINCE_CODE: currentUser?.ProvinceCode } } const data = await handleSynchroGROWTHSETTING(req); console.log('datadatadatadata', data); handleSetlogSave(`${currentRow?.GROWTHSETTING_ID ? '更新' : '新增'}【${data.Result_Data.GROWTHSETTING_NAME}】成功`) } return true } // 拿到最全的规则的数据 const handleGetAllRuleData = async () => { const req: any = { searchParameter: { PROVINCE_CODE: currentUser?.ProvinceCode || "", OWNERUNIT_ID: 911, GROWTHSETTING_STATE: "", MEMBERSHIP_TYPES: "" }, SortStr: "MEMBERSHIP_TYPE,MEMBERSHIP_LEVEL,PROMOTION_LEVEL desc", PageIndex: 1, PageSize: 999999 } const data = await handleGetGROWTHSETTINGList(req); setTableData(data.List) } return ( { return `${record?.GROWTHSETTING_ID}` }} formRef={formRef} headerTitle={} actionRef={actionRef} bordered search={{ span: 6, labelWidth: 'auto' }} // 请求数据 request={async (params, sorter) => { const req: any = { searchParameter: { PROVINCE_CODE: currentUser?.ProvinceCode || "", OWNERUNIT_ID: 911, GROWTHSETTING_STATE: params?.GROWTHSETTING_STATE, MEMBERSHIP_TYPES: params?.MEMBERSHIP_TYPE }, SortStr: "MEMBERSHIP_TYPE,MEMBERSHIP_LEVEL,PROMOTION_LEVEL desc", PageIndex: 1, PageSize: 20 } const data = await handleGetGROWTHSETTINGList(req); if (data.List && data.List.length > 0) { handleSetlogSave(`查看了成长规则配置列表`) // if (isFirst) { // setTableData(data.List); // setIsFirst(false) // } handleGetAllRuleData() return { data: data.List, success: true, total: data.TotalCount } } return { data: [], success: true } }} columns={columns} toolbar={{ actions: [ // 新增按钮 , // 配置成长值规则枚举 , // 配置会员类型枚举 ], }} pagination={{ defaultPageSize: 10 }} /> { setCurrentRow(undefined); setShowDetail(false); }} closable={false} > {currentRow?.GROWTHSETTING_ID && ( ({ data: currentRow || {}, })} params={{ id: currentRow?.GROWTHSETTING_ID, }} columns={columns} /> )} { if (disabled) { setDraggleDisabled(false) } }} onMouseOut={() => { setDraggleDisabled(true) }} onFocus={() => { }} onBlur={() => { }} > {currentRow ? '更新会员成长值配置' : '新建会员成长值配置'} } destroyOnClose={true} width={900} bodyStyle={{ height: '700px', // 你可以根据需要调整高度 overflowY: 'auto', }} footer={ { await handelDelete(currentRow?.GROWTHSETTING_ID) }} handleCancel={() => { handleConfirmLoading(false) handleModalVisible(false) }} handleOK={() => { formRef?.current?.validateFields().then(() => { handleConfirmLoading(true) formRef?.current?.submit() }) }} />} visible={modalVisible} confirmLoading={confirmLoading} afterClose={() => { formRef.current?.resetFields(); setCurrentRow(undefined); }} onCancel={() => { handleConfirmLoading(false) handleModalVisible(false) }} onOk={async () => { // 提交框内的数据 formRef?.current?.validateFields().then(() => { handleConfirmLoading(true) formRef?.current?.submit() }) }} modalRender={(modal) => { return onDraggaleStart(event, uiData)} handle='.GrowthValueModal' >
{modal}
}} > { let newValue: any = { ...values }; if (currentRow) { // 编辑数据 newValue = { ...currentRow, ...values, GROWTHSETTING_ID: currentRow.GROWTHSETTING_ID }; } console.log('newValuenewValuenewValue', newValue); let newList: any = [] if (newValue?.MEMBERSHIP_TYPE === 1) { let list: any = JSON.parse(JSON.stringify(MEMBERSHIPTYPEYNList)) if (list && list.length > 0) { list.forEach((item: any) => { if (item.value < 9000 && Number(item.value) !== 1) { newList.push({ label: item.label, value: Number(item.value) }) } }) } console.log('newListnewListnewListnewList', newList); } else { newList = [{ label: MEMBERSHIPTYPEYNObj[newValue.MEMBERSHIP_TYPE], value: newValue.MEMBERSHIP_TYPE }] } // 判断会员类型 是不是选了所有类型 所有类型的话 需要遍历操作下 不然就走正常的 handleNewAddUpdate(newValue, newList) handleConfirmLoading(false) // return // if (newValue?.MEMBERSHIP_TYPE === 1) { // let list: any = JSON.parse(JSON.stringify(MEMBERSHIPTYPEYNList)) // let newList: any = [] // if (list && list.length > 0) { // list.forEach((item: any) => { // if (item.value < 9000 && Number(item.value) !== 1) { // newList.push({ // label: item.label, // value: Number(item.value) // }) // } // }) // } // console.log('newListnewListnewListnewList', newList); // // 入参列表 // let reqList: any = [] // // 入参列表的提示信息 更新的 // let reqListUpdateMsg: any = [] // // 入参列表的提示信息 新增的 // let reqListAddMsg: any = [] // // for 循环 遍历去调用 批量新增 // for (let i = 0; i < newList.length; i++) { // let nowItem = newList[i]; // // 找到当前项的会员类型 会员等级 规则类型 外面表格数据是否已经存在了 // console.log('nowItemnowItemnowItemnowItem', nowItem); // console.log('table', tableData); // let req: any = {} // if (tableData && tableData.length > 0) { // tableData.forEach((item: any) => { // // 判断 会员类型、会员等级、规则类型 是否一致 // if (Number(item.MEMBERSHIP_TYPE) === Number(nowItem.value) && Number(newValue?.MEMBERSHIP_LEVEL) === Number(item.MEMBERSHIP_LEVEL) && Number(newValue?.GROWTHSETTING_TYPE) === Number(item.GROWTHSETTING_TYPE)) { // req = { // ...item // } // } // }) // } // // 如果req 里面 有 GROWTHSETTING_ID 说明是更新的 // console.log('reqreqreqreqreq', req); // if (req?.GROWTHSETTING_ID) { // reqList.push({ // ...req, // ...newValue, // MEMBERSHIP_TYPE: nowItem.value // }) // reqListUpdateMsg.push(`${nowItem.label}【${GROWTHTYPEObj[newValue.GROWTHSETTING_TYPE]}】${MEMBERSHIPLEVELYNObj[newValue.PROMOTION_LEVEL]}`) // } else { // req = { // ...newValue, // MEMBERSHIP_TYPE: nowItem.value // } // reqList.push(req) // reqListAddMsg.push(`${nowItem.label}【${GROWTHTYPEObj[newValue.GROWTHSETTING_TYPE]}】${MEMBERSHIPLEVELYNObj[newValue.PROMOTION_LEVEL]}`) // } // } // console.log('reqListreqListreqListreqList', reqList); // console.log('reqListUpdateMsgreqListUpdateMsgreqListUpdateMsg', reqListUpdateMsg); // console.log('reqListAddMsgreqListAddMsgreqListAddMsgreqListAddMsg', reqListAddMsg); // confirm({ // title: '提示', // content: `本次操作将 ${reqListUpdateMsg && reqListUpdateMsg.length > 0 ? '更新:' + reqListUpdateMsg.toString() : ""}${reqListAddMsg && reqListAddMsg.length > 0 ? ',新增:' + reqListAddMsg.toString() : ""},是否确认此次操作?`, // width: 600, // icon: , // async onOk() { // let isOK: boolean = await handleBatchUpdate(reqList) // if (isOK) { // formRef?.current?.resetFields() // setCurrentRow(undefined) // handleModalVisible(false) // actionRef.current?.reload() // } // }, // onCancel() { // }, // }); // } else { // await handleAddUpdate(newValue); // } }} > { let GROWTHTYPEList = session.get('GROWTHTYPEList') let newList: any = [] if (GROWTHTYPEList && GROWTHTYPEList.length > 0) { GROWTHTYPEList.forEach((item: any) => { if (item.value === '90') { newList.push(item) } }) } return newList }} // options={GROWTHTYPEList} /> {/* */} { let list: any = JSON.parse(JSON.stringify(MEMBERSHIPTYPEYNList)) let newList: any = [] if (list && list.length > 0) { list.forEach((item: any) => { if (item.value < 9000) { newList.push({ label: item.label, value: Number(item.value) }) } }) } return newList }} /> { let list: any = JSON.parse(JSON.stringify(defaultMemberLevel)) let newList: any = [] if (list && list.length > 0) { list.forEach((item: any) => { if (Number(item.value) !== 1 && Number(item.value) < 9000) { newList.push({ label: item.label, value: Number(item.value), }) } }) } return newList }} fieldProps={{ onChange: (e: any) => { console.log('e', e); let newList: any = [] if (defaultMemberLevel && defaultMemberLevel.length > 0) { defaultMemberLevel.forEach((item: any) => { if (Number(item.value) !== 1 && Number(item.value) < 9000 && Number(e) < Number(item.value)) { newList.push({ label: item.label, value: item.value.toString(), }) } }) } formRef.current?.setFieldsValue({ PROMOTION_LEVEL: newList && newList.length > 0 ? newList[0].value : "" }) // console.log('promotionMemberLevel', promotionMemberLevel); // if (promotionMemberLevel && promotionMemberLevel.length > 0) { // let list: any = JSON.parse(JSON.stringify(promotionMemberLevel)) // list.forEach((item: any) => { // item.disabled = false // }) // list.forEach((item: any) => { // if (Number(item.value) <= Number(e)) { // item.disabled = true // } // }) // setPromotionMemberLevel(list) // } } }} /> {/* */}
{ setShowConfig(false) }} > { setShowTypeConfig(false) }} >
); }; export default connect(({ user }: ConnectState) => ({ currentUser: user.currentUser }))(GrowthValueRuleConfig);