index.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { getGameListNewApi } from "@/services/gameData"
  3. import { StrategyListProps, delStrategyApi, getStrategyListApi } from "@/services/gameData/roleOperate"
  4. import { PlusOutlined } from "@ant-design/icons"
  5. import { Button, Card, Col, Form, Row, Select, Space, message } from "antd"
  6. import React, { useEffect, useState } from "react"
  7. import style from '../../components/TableData/index.less'
  8. import StrategyModal from "./strategyModal"
  9. import Tables from "@/components/Tables"
  10. import columnsPos from "./tableConfig"
  11. export const strategyType = [
  12. { label: '追踪玩家', value: 1, tips: '单笔充值金额大于XX,并且注册时间在XX小时内的玩家' },
  13. { label: '玩家流失', value: 2, tips: '累计充值金额大于XX,并且最近游戏距今时间超过XX小时的玩家' },
  14. { label: '新用户追踪', value: 3, tips: '新用户注册创角首日充值大于XX的用户' },
  15. { label: '累充追踪', value: 4, tips: '' },
  16. { label: '新增角色追踪', value: 5, tips: '新创建的角色在创角至今【XX】小时内,首次充值(角色首充,单笔充值)【XX】金额,触发报警一次' }
  17. ]
  18. /**
  19. * 游戏策略配置
  20. * @returns
  21. */
  22. const Strategy: React.FC = () => {
  23. /****************************/
  24. const [form] = Form.useForm()
  25. const [queryFrom, setQueryForm] = useState<StrategyListProps>({ pageNum: 1, pageSize: 20 })
  26. const [superGameList, setSuperGameList] = useState<any[]>([])
  27. const [initialValues, setInitialValues] = useState<any>({})
  28. const [visible, setVisible] = useState<boolean>(false)
  29. const getStrategyList = useAjax((params) => getStrategyListApi(params))
  30. const delStrategy = useAjax((params) => delStrategyApi(params))
  31. const getGameList = useAjax((params) => getGameListNewApi(params))
  32. /****************************/
  33. const onFinish = (data: any) => {
  34. let oldQueryFrom = JSON.parse(JSON.stringify(queryFrom))
  35. setQueryForm({ ...oldQueryFrom, ...data, pageNum: 1 })
  36. }
  37. useEffect(() => {
  38. getStrategyList.run(queryFrom)
  39. }, [queryFrom])
  40. useEffect(() => {
  41. getGameList.run({ sourceSystem: 'ZX_ONE' }).then(res => {
  42. if (res) {
  43. const { superGameList } = res
  44. setSuperGameList(superGameList)
  45. }
  46. })
  47. }, [])
  48. const editVip = (data: any) => {
  49. setInitialValues({ ...data, userIds: data.userNameIds || [], tagIds: data.tagsNameIds || [] })
  50. setVisible(true)
  51. }
  52. const del = (id: number) => {
  53. delStrategy.run(id).then(res => {
  54. if (res) {
  55. message.success('删除成功')
  56. getStrategyList.refresh()
  57. }
  58. })
  59. }
  60. return <Card
  61. style={{ borderRadius: 8 }}
  62. headStyle={{ textAlign: 'left' }}
  63. bodyStyle={{ padding: '5px 10px' }}
  64. >
  65. <div style={{ textAlign: 'center', fontWeight: 'bold', padding: '4px 6px 6px', fontSize: 16, marginBottom: 4, position: 'relative' }}>
  66. 游戏策略配置
  67. </div>
  68. <Space style={{ width: '100%' }} direction="vertical" size={10}>
  69. <Form layout="inline" className='queryForm' initialValues={initialValues} name="basicGameVip" form={form} onFinish={onFinish}>
  70. <Row gutter={[0, 6]}>
  71. <Col><Form.Item name='superGameId'>
  72. <Select
  73. maxTagCount={1}
  74. showSearch
  75. style={{ minWidth: 140 }}
  76. allowClear
  77. placeholder={'请选择超父游戏'}
  78. filterOption={(input, option) =>
  79. (option?.children as any)?.toLowerCase().indexOf(input.toLowerCase()) >= 0
  80. }
  81. >
  82. {superGameList?.map((item: any) => <Select.Option value={item.super_game_id} key={item.super_game_id}>{item.super_game_name}</Select.Option>)}
  83. </Select>
  84. </Form.Item></Col>
  85. <Col><Form.Item name='type'>
  86. <Select
  87. maxTagCount={1}
  88. showSearch
  89. style={{ width: 140 }}
  90. allowClear
  91. placeholder={'请选择策略类型'}
  92. filterOption={(input, option) =>
  93. (option?.children as any)?.toLowerCase().indexOf(input.toLowerCase()) >= 0
  94. }
  95. dropdownMatchSelectWidth={false}
  96. >
  97. {strategyType?.map((item: any) => <Select.Option value={item.value} key={item.value}>{item.label}_{item.tips}</Select.Option>)}
  98. </Select>
  99. </Form.Item></Col>
  100. <Col>
  101. <Space>
  102. <Button type="primary" htmlType="submit">搜索</Button>
  103. <Button onClick={() => form.resetFields()}>重置</Button>
  104. <Button icon={<PlusOutlined />} type="primary" onClick={() => { setVisible(true); setInitialValues({}) }}>新增游戏策略配置</Button>
  105. </Space>
  106. </Col>
  107. </Row>
  108. </Form>
  109. <div className={`${style['small']}`}>
  110. <Tables
  111. className={`all_table content_table_body`}
  112. bordered
  113. sortDirections={['ascend', 'descend', null]}
  114. current={queryFrom.pageNum}
  115. pageSize={queryFrom.pageSize}
  116. columns={columnsPos(editVip, del)}
  117. dataSource={getStrategyList?.data?.records}
  118. scroll={{ x: 1000, y: 600 }}
  119. onChange={(pagination: any, filters: any, sortData: any) => {
  120. let { current, pageSize } = pagination
  121. let newQueryForm = JSON.parse(JSON.stringify(queryFrom))
  122. if (sortData && sortData?.order) {
  123. newQueryForm['sortType'] = sortData?.order === 'ascend' ? 'asc' : 'desc'
  124. newQueryForm['sortFiled'] = sortData?.field
  125. } else {
  126. delete newQueryForm['sortType']
  127. delete newQueryForm['sortFiled']
  128. }
  129. newQueryForm.pageNum = current
  130. newQueryForm.pageSize = pageSize
  131. setQueryForm({ ...newQueryForm })
  132. }}
  133. size="small"
  134. total={getStrategyList?.data?.total}
  135. loading={getStrategyList?.loading}
  136. defaultPageSize={20}
  137. />
  138. </div>
  139. </Space>
  140. {visible && <StrategyModal
  141. superGameList={superGameList}
  142. visible={visible}
  143. initialValues={initialValues}
  144. onChange={() => {
  145. setInitialValues({});
  146. getStrategyList.refresh()
  147. setVisible(false)
  148. }}
  149. onClose={() => {
  150. setInitialValues({})
  151. setVisible(false)
  152. }}
  153. />}
  154. </Card>
  155. }
  156. export default Strategy