index.jsx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. import React, { useEffect, useState, useRef } from 'react'
  2. import { Tag, Select, Tooltip, Input, DatePicker, Button } from 'antd'
  3. import ProTable from '@ant-design/pro-table'
  4. import consts from '@/consts'
  5. import { useModel, connect } from 'umi'
  6. import { queryLock } from '@/services/lock'
  7. import LocksDetail from '@/pages/Product/Lock/LockStore/components/LocksDetail'
  8. import ContactDetail from '@/pages/Customer/Client/components/ClientDetail'
  9. import SoftwareDetail from '@/pages/Product/Lock/LockStore/components/SoftwareDetail'
  10. import { useModal } from '@/components/Modal'
  11. import { useTableScroll } from '@/hooks/useAutoTable'
  12. import CompanyDetail from '@/pages/Customer/Company/components/CompanyDetail'
  13. import { refactorSortField } from '@/utils/utils'
  14. import ReceiveLock from './components/ReceiveLock'
  15. import ReceiveNewLock from './components/ReceiveNewLock'
  16. import PermSelect from '@/pages/Customer/Company/components/PermSelect'
  17. import { PermDataTypeEunm } from '@/pages/Customer/Company/components/PermSelect'
  18. // 渲染产品标签
  19. export const ProductLabel = ({ data }) => {
  20. if (!data) return <></>
  21. let newData = data
  22. if (!Array.isArray(data)) {
  23. newData = data.split('+')
  24. }
  25. return (
  26. <div>
  27. {newData.map((item, index) => (
  28. <span key={index} className="mr-5px">
  29. <Tag color="#886ab5">{item}</Tag>
  30. </span>
  31. ))}
  32. </div>
  33. )
  34. }
  35. const longleStatusNum = {
  36. 1: {
  37. text: '生成'
  38. },
  39. 2: {
  40. text: '接收'
  41. },
  42. 3: {
  43. text: '借出'
  44. },
  45. 4: {
  46. text: '销售'
  47. },
  48. 5: {
  49. text: '升级'
  50. },
  51. 6: {
  52. text: '更换'
  53. },
  54. 7: {
  55. text: '收回'
  56. },
  57. 8: {
  58. text: '备注'
  59. },
  60. 9: {
  61. text: '赠送'
  62. }
  63. }
  64. const LockStore = ({ prodList = [], dispatch, shouldUpdate }) => {
  65. const tRef = useRef()
  66. const [selectKeys] = useState([])
  67. const { toggleDrawer, setDrawerProps, toggleModal, setModalProps } = useModal()
  68. const showReceiveLockModal = () => {
  69. setModalProps({
  70. width: '60vw',
  71. modalRender: () => <ReceiveLock />,
  72. onCancel: () => toggleModal()
  73. })
  74. toggleModal()
  75. }
  76. const showReceiveNewLockModal = () => {
  77. setModalProps({
  78. width: '60vw',
  79. modalRender: () => <ReceiveNewLock />,
  80. onCancel: () => toggleModal()
  81. })
  82. toggleModal()
  83. }
  84. const { initialState: { permData } = { permData: {} } } = useModel('@@initialState')
  85. const [state, setState] = useState({
  86. params: { dataPermission: 'oneself', staffIds: null },
  87. data: [],
  88. totalOld: 0, // 待接收锁总数
  89. totalNew: 0,
  90. id: ''
  91. })
  92. // 获取软件锁产品列表
  93. function fetchSoftProducts() {
  94. dispatch({
  95. type: 'lock/fetchProdList'
  96. })
  97. }
  98. const handleSearch = value => {
  99. setState({ ...state, params: { ...state.params, search: value } })
  100. }
  101. // 刷新
  102. // const refreshData = () => {
  103. // tRef.current.reload()
  104. // }
  105. useEffect(() => {
  106. if (shouldUpdate) {
  107. tRef.current.reload()
  108. }
  109. }, [shouldUpdate])
  110. // 展示drawer
  111. const showDrawer = id => {
  112. setDrawerProps({
  113. closable: true,
  114. onClose: () => toggleDrawer(),
  115. bodyStyle: {
  116. height: '100vh',
  117. overflowY: 'hidden'
  118. },
  119. children: <LocksDetail id={id} orderIds={state.orderIds} />
  120. })
  121. toggleDrawer()
  122. }
  123. // 展示DrawerClient
  124. const showDrawerClient = id => {
  125. setDrawerProps({
  126. closable: true,
  127. onClose: () => toggleDrawer(),
  128. bodyStyle: {
  129. height: '100vh',
  130. overflowY: 'hidden'
  131. },
  132. children: <ContactDetail dataId={id} />
  133. })
  134. toggleDrawer()
  135. }
  136. // 展示DrawerResponsible
  137. const showDrawerResponsible = id => {
  138. setDrawerProps({
  139. closable: true,
  140. onClose: () => toggleDrawer(),
  141. bodyStyle: {
  142. height: '100vh',
  143. overflowY: 'hidden'
  144. },
  145. children: <SoftwareDetail dataId={id} />
  146. })
  147. toggleDrawer()
  148. }
  149. // 展示客户详情抽屉
  150. const showCompanyDrawer = id => {
  151. setDrawerProps({
  152. closable: true,
  153. onClose: () => toggleDrawer(),
  154. bodyStyle: {
  155. height: '100vh',
  156. overflowY: 'hidden'
  157. },
  158. children: <CompanyDetail dataId={id} />
  159. })
  160. toggleDrawer()
  161. }
  162. const columns = [
  163. {
  164. title: '锁号',
  165. dataIndex: 'keyNum',
  166. width: 150,
  167. render: (keyNum, record) => (
  168. <span
  169. onClick={() => showDrawer(record.id)}
  170. className="text-primary cursor-pointer hover:text-[#967bbd]">
  171. {keyNum}
  172. </span>
  173. )
  174. },
  175. {
  176. title: '产品',
  177. dataIndex: 'product',
  178. width: 200,
  179. render: text => <ProductLabel data={text} />
  180. },
  181. {
  182. title: '出库时间',
  183. dataIndex: 'makeDay',
  184. valueType: 'date',
  185. sorter: true,
  186. width: 150
  187. },
  188. {
  189. title: '状态',
  190. dataIndex: 'status',
  191. width: 150,
  192. filters: true,
  193. onFilter: true,
  194. valueType: 'select',
  195. valueEnum: longleStatusNum,
  196. render: (_, { status }) => {
  197. return <>{longleStatusNum[status]?.text}</>
  198. }
  199. },
  200. {
  201. title: '责任人',
  202. dataIndex: 'responsible',
  203. width: 150,
  204. render: (text, record) => (
  205. <span
  206. onClick={() => showDrawerResponsible(record.responsibleId)}
  207. className="text-primary cursor-pointer hover:text-[#967bbd]">
  208. {text}
  209. </span>
  210. )
  211. },
  212. {
  213. title: '客户',
  214. dataIndex: 'customerName',
  215. render: (text, record) => (
  216. <span
  217. onClick={() => showCompanyDrawer(record.customerId)}
  218. className="text-primary cursor-pointer hover:text-[#967bbd]">
  219. {text}
  220. </span>
  221. )
  222. },
  223. {
  224. title: '联系人',
  225. dataIndex: 'client',
  226. width: 150,
  227. render: (text, record) => (
  228. <span
  229. onClick={() => showDrawerClient(record.clientId)}
  230. className="text-primary cursor-pointer hover:text-[#967bbd]">
  231. {text}
  232. </span>
  233. )
  234. },
  235. {
  236. title: '销售/借出/赠送时间',
  237. dataIndex: 'allotedTime',
  238. width: 160
  239. },
  240. {
  241. title: '办事处',
  242. dataIndex: 'category',
  243. width: 150
  244. },
  245. {
  246. title: '部门',
  247. dataIndex: 'departmentName',
  248. width: 150
  249. }
  250. ]
  251. const { getScrollRef, redoHeight } = useTableScroll(columns, selectKeys)
  252. // 处理权限Select下拉组件OnChange事件
  253. const handlePermChange = ({ staffIds = [], dataPermission }) => {
  254. if (staffIds?.length) {
  255. setState({ ...state, params: { ...state.params, staffIds, dataPermission: null } })
  256. return
  257. }
  258. setState({ ...state, params: { ...state.params, staffIds: null, dataPermission } })
  259. }
  260. return (
  261. <ProTable
  262. rowKey={record => record.id}
  263. search={false}
  264. bordered
  265. actionRef={tRef}
  266. params={state.params}
  267. columns={columns}
  268. onLoadingChange={loadingStatus => {
  269. loadingStatus && redoHeight()
  270. }}
  271. request={async (params, sort, filter) => {
  272. const srotOrder = refactorSortField(sort)
  273. const {
  274. code = -1,
  275. data: { longle = [], total = 0, totalOld = 0, totalNew = 0 } = {
  276. longle: [],
  277. total: 0,
  278. totalOld: 0,
  279. totalNew: 0
  280. }
  281. } = await queryLock({ ...params, ...srotOrder, ...filter })
  282. setState({ ...state, totalOld, totalNew })
  283. return {
  284. data: longle,
  285. success: code === consts.RET_CODE.SUCCESS,
  286. total
  287. }
  288. }}
  289. scroll={getScrollRef}
  290. headerTitle={
  291. <>
  292. <PermSelect onConfirm={handlePermChange} dataType={PermDataTypeEunm.PRODUCT} />
  293. <Button type="primary" className="ml-4" onClick={() => showReceiveLockModal()}>
  294. 待接收锁 ({state.totalOld})
  295. </Button>
  296. <Button type="primary" className="ml-4" onClick={() => showReceiveNewLockModal()}>
  297. 待接收新锁 ({state.totalNew})
  298. </Button>
  299. </>
  300. }
  301. toolbar={{
  302. search: (
  303. <Tooltip placement="bottom" title="输入软件锁号">
  304. <Input.Search
  305. style={{ width: '300px' }}
  306. allowClear={true}
  307. placeholder={`在${
  308. permData[PermDataTypeEunm.PRODUCT]?.find(
  309. item => item.value === state.params.dataPermission
  310. )?.label || '自定义'
  311. }下搜索`}
  312. onSearch={handleSearch}
  313. />
  314. </Tooltip>
  315. ),
  316. actions: [
  317. <DatePicker
  318. key="date"
  319. bordered={false}
  320. placeholder="请选择出库时间"
  321. onChange={e =>
  322. setState({
  323. ...state,
  324. params: { ...state.params, makeDay: e ? e.format('YYYY-MM-DD') : '' }
  325. })
  326. }
  327. />,
  328. <Select
  329. key="select"
  330. bordered={false}
  331. style={{ width: '150px' }}
  332. labelInValue={true}
  333. allowClear={true}
  334. placeholder="请选择产品"
  335. onDropdownVisibleChange={async e => {
  336. e && !prodList?.length && (await fetchSoftProducts())
  337. }}
  338. options={prodList.map(item => ({ value: item.title }))}
  339. onChange={e =>
  340. setState({ ...state, params: { ...state.params, product: e?.value || '' } })
  341. }
  342. />
  343. ]
  344. }}
  345. />
  346. )
  347. }
  348. export default connect(({ lock, refresh }) => ({
  349. prodList: lock.prodList,
  350. shouldUpdate: refresh.longle
  351. }))(LockStore)