TabList.jsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import { Button, message, Table, Tabs, Tag, Typography } from 'antd'
  2. import React, { useEffect, useState, useRef } from 'react'
  3. import consts from '@/consts'
  4. import { apiAddService } from '@/services/customer'
  5. import { useDispatch } from '@umijs/max'
  6. import ProTable from '@ant-design/pro-table'
  7. import { renderBadge } from '@/pages/Workbench/Dashboard/components/RatioPanels'
  8. import { longleSellStatusNum, longlePreserveStatusNum } from '@/pages/Product/Lock/LockStore/index'
  9. import { ProductLabel } from '@/pages/Product/Lock/LockStore/index'
  10. import { useModal } from '@/components/ModalStore'
  11. import { Plus } from '@icon-park/react'
  12. import classNames from 'classnames'
  13. import { queryRoadPricingListWithParams } from '@/services/product'
  14. import { cloudTitleEnum } from '@/pages/Product/Cloud/components/Detail/Form'
  15. const { TabPane } = Tabs
  16. const ClientTabList = ({ clientId, software, updatePayload }) => {
  17. const { Text } = Typography
  18. const dispatch = useDispatch()
  19. const dispatchModal = useModal()
  20. const [state, setState] = useState({
  21. params: {},
  22. cloud: [],
  23. loading: false // 云版表格loading
  24. })
  25. const clientHeight = (document.body.clientHeight - 124 - 78) / 2 - 54
  26. const columns = [
  27. {
  28. title: '锁号',
  29. dataIndex: 'keyNum',
  30. width: 90,
  31. render: (clientName, record) => (
  32. <span
  33. onClick={() =>
  34. dispatchModal('D_LOCK_DETAIL', {
  35. dataId: record.id,
  36. orderIds: software.longle.map(item => item.id)
  37. })
  38. }
  39. className={classNames('cursor-pointer hover:text-hex-967bbd', {
  40. 'text-primary': record.preserveStatus !== 3
  41. })}>
  42. {record.preserveStatus === 3 ? (
  43. <Text delete type="secondary">
  44. {clientName}
  45. </Text>
  46. ) : (
  47. <span className="text-primary">{clientName}</span>
  48. )}
  49. </span>
  50. )
  51. },
  52. {
  53. title: '产品',
  54. dataIndex: 'product',
  55. width: 230,
  56. render: (_, record) =>
  57. record.preserveStatus === 3 ? (
  58. <Text delete type="secondary">
  59. {record.product}
  60. </Text>
  61. ) : (
  62. <ProductLabel data={record.product} />
  63. )
  64. },
  65. {
  66. title: '销售状态',
  67. dataIndex: 'sellStatus',
  68. width: 90,
  69. ellipsis: true,
  70. render: (_, record) =>
  71. record.preserveStatus === 3 ? (
  72. <Text delete type="secondary">
  73. {longleSellStatusNum[record.sellStatus]?.text}
  74. </Text>
  75. ) : (
  76. <>{longleSellStatusNum[record.sellStatus]?.text}</>
  77. )
  78. },
  79. {
  80. title: '维护状态',
  81. dataIndex: 'preserveStatus',
  82. key: 'preserveStatus',
  83. width: 90,
  84. ellipsis: true,
  85. render: (_, record) =>
  86. record.preserveStatus === 3 ? (
  87. <Text delete type="secondary">
  88. {longlePreserveStatusNum[record.preserveStatus]?.text}
  89. </Text>
  90. ) : (
  91. <>{longlePreserveStatusNum[record.preserveStatus]?.text}</>
  92. )
  93. },
  94. {
  95. title: '责任人',
  96. dataIndex: 'responsible',
  97. width: 70,
  98. ellipsis: true,
  99. render: (_, record) =>
  100. record.preserveStatus === 3 ? (
  101. <Text delete type="secondary">
  102. {record.responsible}
  103. </Text>
  104. ) : (
  105. <>{record.responsible}</>
  106. )
  107. }
  108. ]
  109. const cloudColumns = [
  110. {
  111. dataIndex: 'project_type',
  112. title: '云版名称',
  113. width: '20%',
  114. filters: Object.keys(cloudTitleEnum).map(item => ({ text: cloudTitleEnum[item], value: item })),
  115. onFilter: (projectType, record) => record.project_type.toString() === projectType,
  116. render: text => cloudTitleEnum[text]
  117. },
  118. {
  119. dataIndex: 'mobile',
  120. title: '账号',
  121. width: '20%',
  122. render: (text, record) => (
  123. <div
  124. className="text-primary cursor-pointer hover:text-hex-967bbd"
  125. onClick={() =>
  126. dispatchModal('D_CLOUD_DETAIL', {
  127. dataId: record.ssoId,
  128. projectType: record.project_type
  129. })
  130. }>
  131. {text}
  132. </div>
  133. )
  134. },
  135. {
  136. dataIndex: 'real_name',
  137. title: '姓名',
  138. width: '20%'
  139. },
  140. {
  141. dataIndex: 'upgrade_list',
  142. title: '已升级专业版',
  143. width: '40%',
  144. render: text => (
  145. <div className="children:m-2px">
  146. {text
  147. .filter(item => item.isUpgrade)
  148. .map(item => {
  149. return (
  150. <Tag color="purple" key={item.compilationID}>
  151. {item.name}
  152. </Tag>
  153. )
  154. })}
  155. </div>
  156. )
  157. }
  158. ]
  159. const handleAddService = async values => {
  160. const { code = -1 } = await apiAddService({ ...values, clientId })
  161. if (code === consts.RET_CODE.SUCCESS) {
  162. message.success('新增成功')
  163. // 刷新数据
  164. dispatch({
  165. type: 'refresh/commitAction',
  166. payload: updatePayload
  167. })
  168. }
  169. // 请求完了
  170. return code === consts.RET_CODE.SUCCESS
  171. }
  172. const initCloudData = async () => {
  173. setState({ ...state, loading: true })
  174. const { data = [] } = await queryRoadPricingListWithParams({ clientId })
  175. setState({ ...state, cloud: data, loading: false })
  176. }
  177. const handleTabChange = activeKey => {
  178. if (activeKey === '2') {
  179. initCloudData()
  180. }
  181. }
  182. useEffect(() => {
  183. setState({ ...state, params: { ...state.params, clientId } })
  184. }, [clientId])
  185. return (
  186. <div>
  187. <div className="pl-15px">
  188. <Tabs onChange={handleTabChange}>
  189. <TabPane tab={<span>软件锁{renderBadge(software.total, true)}</span>} key="1">
  190. <div className="sheet-right-panel sheet-panel-has-btn">
  191. <ProTable
  192. size="small"
  193. columns={columns}
  194. search={false}
  195. toolBarRender={false}
  196. params={state.params}
  197. rowKey={record => record.id}
  198. dataSource={software.longle}
  199. pagination={false}
  200. scroll={{ y: clientHeight }}
  201. />
  202. </div>
  203. </TabPane>
  204. <TabPane tab="云版" key="2">
  205. <Table
  206. className="sheet-right-panel sheet-panel-has-btn"
  207. loading={state.loading}
  208. size="small"
  209. columns={cloudColumns}
  210. rowKey="_id"
  211. pagination={false}
  212. scroll={{ y: clientHeight }}
  213. dataSource={state.cloud}
  214. />
  215. </TabPane>
  216. </Tabs>
  217. </div>
  218. <div className="sheet-btns pl-15px pt-15px :not-first:ml-1">
  219. <Button
  220. type="primary"
  221. ghost
  222. size="small"
  223. className="mr-1"
  224. onClick={() => dispatchModal('M_RECORD_ADD', { onConfirm: handleAddService })}>
  225. <Plus className="mr-1" /> 添加服务记录
  226. </Button>
  227. </div>
  228. </div>
  229. )
  230. }
  231. export default ClientTabList