index.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. import React, { useEffect, useState, useRef } from 'react'
  2. import { Tag, Tooltip, Input, Button } from 'antd'
  3. import consts from '@/consts'
  4. import { useModel, connect } from 'umi'
  5. import { queryLock } from '@/services/product'
  6. import LocksDetail from '@/pages/Product/Lock/LockStore/components/LocksDetail'
  7. import ContactDetail from '@/pages/Customer/Client/components/ClientDetail'
  8. import SoftwareDetail from '@/pages/Product/Lock/LockStore/components/SoftwareDetail'
  9. import { useModal } from '@/components/Modal'
  10. import CompanyDetail from '@/pages/Customer/Company/components/CompanyDetail'
  11. import { refactorSortField } from '@/utils/utils'
  12. import ReceiveLock from './components/ReceiveLock'
  13. // import ReceiveNewLock from './components/ReceiveNewLock'
  14. import { PermDataTypeEunm } from '@/pages/Customer/Company/components/PermSelect'
  15. import BasicTable from '@/components/Table'
  16. import { getPermAuthCache } from '@/utils/auth'
  17. import FilterDatePicker from '@/components/Table/src/components/FilterDatePicker'
  18. // import { DownOutlined } from '@ant-design/icons'
  19. // 渲染产品标签
  20. export const ProductLabel = ({ data }) => {
  21. if (!data) return null
  22. let newData
  23. if (!Array.isArray(data)) {
  24. newData = data.split('+')
  25. }
  26. return (
  27. <div className="children:m-2px">
  28. {newData.map((item, idx) => (
  29. <Tag color="purple" key={item + idx}>
  30. {item}
  31. </Tag>
  32. ))}
  33. </div>
  34. )
  35. }
  36. // const longleStatusNum = {
  37. // 1: {
  38. // text: '生成'
  39. // },
  40. // 2: {
  41. // text: '接收'
  42. // },
  43. // 3: {
  44. // text: '借出'
  45. // },
  46. // 4: {
  47. // text: '销售'
  48. // },
  49. // 5: {
  50. // text: '升级'
  51. // },
  52. // 6: {
  53. // text: '更换'
  54. // },
  55. // 7: {
  56. // text: '收回'
  57. // },
  58. // 8: {
  59. // text: '备注'
  60. // },
  61. // 9: {
  62. // text: '赠送'
  63. // }
  64. // }
  65. // 出库状态
  66. const longleStockStatusNum = {
  67. 1: { text: '生成' },
  68. 2: { text: '接收' }
  69. }
  70. // 销售状态
  71. export const longleSellStatusNum = {
  72. 1: { text: '借出' },
  73. 2: { text: '销售' },
  74. 3: { text: '赠送' }
  75. }
  76. // 维护状态
  77. const longlePreserveStatusNum = {
  78. 1: { text: '升级' },
  79. 2: { text: '更换' },
  80. 3: { text: '收回' }
  81. }
  82. const LockStore = ({ prodList = [], dispatch, shouldUpdate }) => {
  83. const tRef = useRef()
  84. const { toggleDrawer, setDrawerProps, toggleModal, setModalProps } = useModal()
  85. // 刷新
  86. const refreshData = () => {
  87. tRef.current?.reload()
  88. }
  89. const showReceiveLockModal = () => {
  90. setModalProps({
  91. width: '60vw',
  92. modalRender: () => <ReceiveLock refresh={refreshData} />,
  93. onCancel: () => toggleModal()
  94. })
  95. toggleModal()
  96. }
  97. // const showReceiveNewLockModal = () => {
  98. // setModalProps({
  99. // width: '60vw',
  100. // modalRender: () => <ReceiveNewLock refresh={refreshData} />,
  101. // onCancel: () => toggleModal()
  102. // })
  103. // toggleModal()
  104. // }
  105. const { initialState: { permData } = { permData: {} } } = useModel('@@initialState')
  106. const [state, setState] = useState({
  107. data: [],
  108. totalOld: 0, // 待接收锁总数
  109. totalNew: 0,
  110. orderIds: []
  111. })
  112. const handleSearch = value => {
  113. setState({ ...state, params: { ...state.params, search: value } })
  114. }
  115. useEffect(() => {
  116. // 获取软件锁产品列表
  117. function fetchSoftProducts() {
  118. dispatch({
  119. type: 'lock/fetchProdList'
  120. })
  121. }
  122. if (!prodList?.length) {
  123. fetchSoftProducts()
  124. }
  125. if (shouldUpdate) {
  126. tRef.current.reload()
  127. }
  128. }, [shouldUpdate])
  129. // 展示drawer
  130. const showDrawer = id => {
  131. setDrawerProps({
  132. closable: true,
  133. onClose: () => toggleDrawer(),
  134. bodyStyle: {
  135. height: '100vh'
  136. // overflowY: 'hidden'
  137. },
  138. children: <LocksDetail dataId={id} orderIds={state.orderIds} />
  139. })
  140. toggleDrawer()
  141. }
  142. // 展示DrawerClient
  143. const showDrawerClient = id => {
  144. setDrawerProps({
  145. closable: true,
  146. onClose: () => toggleDrawer(),
  147. bodyStyle: {
  148. height: '100vh',
  149. overflowY: 'hidden'
  150. },
  151. children: <ContactDetail dataId={id} />
  152. })
  153. toggleDrawer()
  154. }
  155. // 展示DrawerResponsible
  156. const showDrawerResponsible = id => {
  157. setDrawerProps({
  158. closable: true,
  159. onClose: () => toggleDrawer(),
  160. bodyStyle: {
  161. height: '100vh',
  162. overflowY: 'hidden'
  163. },
  164. children: <SoftwareDetail dataId={id} />
  165. })
  166. toggleDrawer()
  167. }
  168. // 展示单位详情抽屉
  169. const showCompanyDrawer = id => {
  170. setDrawerProps({
  171. closable: true,
  172. onClose: () => toggleDrawer(),
  173. bodyStyle: {
  174. height: '100vh',
  175. overflowY: 'hidden'
  176. },
  177. children: <CompanyDetail dataId={id} updateKey="longle" />
  178. })
  179. toggleDrawer()
  180. }
  181. const columns = [
  182. {
  183. title: '锁号',
  184. dataIndex: 'keyNum',
  185. width: 90,
  186. fixed: 'left',
  187. render: (keyNum, record) => (
  188. <span
  189. onClick={() => showDrawer(record.id)}
  190. className="text-primary cursor-pointer hover:text-[#967bbd]"
  191. >
  192. {keyNum}
  193. </span>
  194. )
  195. },
  196. {
  197. title: '产品',
  198. dataIndex: 'product',
  199. key: 'product',
  200. width: 200,
  201. fixed: 'left',
  202. filters: true,
  203. filterMultiple: false,
  204. valueEnum: prodList.reduce((prev, curr) => {
  205. const obj = { ...prev }
  206. obj[curr.title] = {
  207. text: curr.title
  208. }
  209. return obj
  210. }, {}),
  211. render: (_, record) => <ProductLabel data={record.product} />
  212. },
  213. {
  214. title: '出库状态',
  215. dataIndex: 'stockStatus',
  216. key: 'stockStatus',
  217. width: 70,
  218. render: (_, { stockStatus }) => {
  219. return <>{longleStockStatusNum[stockStatus]?.text}</>
  220. }
  221. },
  222. {
  223. title: '出库时间',
  224. dataIndex: 'stockTime',
  225. valueType: 'date',
  226. key: 'stockTime',
  227. filterDropdown: filterDropdownProps => <FilterDatePicker {...filterDropdownProps} />,
  228. filters: true,
  229. sorter: true,
  230. width: 100
  231. },
  232. // {
  233. // title: '状态',
  234. // dataIndex: 'status',
  235. // width: 60,
  236. // filters: true,
  237. // onFilter: true,
  238. // valueType: 'select',
  239. // valueEnum: longleStatusNum,
  240. // renderText: (_, { status }) => longleStatusNum[status]?.text
  241. // },
  242. {
  243. title: '销售状态',
  244. dataIndex: 'sellStatus',
  245. key: 'sellStatus',
  246. width: 70,
  247. render: (_, { sellStatus }) => {
  248. return <>{longleSellStatusNum[sellStatus]?.text}</>
  249. }
  250. },
  251. {
  252. title: '销售时间',
  253. dataIndex: 'sellTime',
  254. valueType: 'date',
  255. key: 'sellTime',
  256. width: 90
  257. },
  258. {
  259. title: '维护状态',
  260. dataIndex: 'preserveStatus',
  261. key: 'preserveStatus',
  262. width: 60,
  263. render: (_, { preserveStatus }) => {
  264. return <>{longlePreserveStatusNum[preserveStatus]?.text}</>
  265. }
  266. },
  267. {
  268. title: '维护时间',
  269. dataIndex: 'preserveTime',
  270. key: 'preserveTime',
  271. valueType: 'date',
  272. width: 90
  273. },
  274. {
  275. title: '客户',
  276. dataIndex: 'client',
  277. key: 'client',
  278. sorter: true,
  279. width: 150,
  280. render: (text, record) => (
  281. <span
  282. onClick={() => showDrawerClient(record.clientId)}
  283. className="text-primary cursor-pointer hover:text-[#967bbd]"
  284. >
  285. {text}
  286. </span>
  287. )
  288. },
  289. {
  290. title: '单位名称',
  291. dataIndex: 'customerName',
  292. key: 'customerName',
  293. sorter: true,
  294. width: 300,
  295. render: (text, record) => (
  296. <span
  297. onClick={() => showCompanyDrawer(record.customerId)}
  298. className="text-primary cursor-pointer hover:text-[#967bbd]"
  299. >
  300. {text}
  301. </span>
  302. )
  303. },
  304. {
  305. title: '负责人',
  306. dataIndex: 'responsible',
  307. width: 80,
  308. render: (text, record) => (
  309. <span
  310. onClick={() => showDrawerResponsible(record.responsibleId)}
  311. className="text-primary cursor-pointer hover:text-[#967bbd]"
  312. >
  313. {text}
  314. </span>
  315. )
  316. },
  317. {
  318. title: '期限',
  319. dataIndex: 'allotedTime',
  320. width: 90
  321. },
  322. {
  323. title: '办事处',
  324. dataIndex: 'category',
  325. width: 90
  326. },
  327. {
  328. title: '纵横部门',
  329. dataIndex: 'departmentName',
  330. width: 90
  331. }
  332. ]
  333. const columnsStateMap = {
  334. preserveStatus: {
  335. show: false
  336. },
  337. preserveTime: {
  338. show: false
  339. }
  340. }
  341. // const dropDownMenClick = ({ key }) => {
  342. // if (key === '1') {
  343. // showReceiveLockModal()
  344. // } else {
  345. // showReceiveNewLockModal()
  346. // }
  347. // }
  348. const [defaultPermAuthCache] = getPermAuthCache(PermDataTypeEunm.PRODUCT)
  349. return (
  350. <BasicTable
  351. rowKey={record => record.id}
  352. mainMenuType="product"
  353. columnStateType="LOCKSTORE"
  354. search={false}
  355. actionRef={tRef}
  356. params={state.params}
  357. columns={columns}
  358. request={async (params, sort, filter) => {
  359. const srotOrder = refactorSortField(sort)
  360. const {
  361. code = -1,
  362. data: { longle = [], total = 0, totalOld = 0, totalNew = 0 } = {
  363. longle: [],
  364. total: 0,
  365. totalOld: 0,
  366. totalNew: 0
  367. }
  368. } = await queryLock({ ...params, ...srotOrder, ...filter })
  369. setState({ ...state, totalOld, totalNew, orderIds: longle.map(item => item.id) })
  370. return {
  371. data: longle,
  372. success: code === consts.RET_CODE.SUCCESS,
  373. total
  374. }
  375. }}
  376. columnsStateMap={columnsStateMap}
  377. headerTitle={
  378. // <Dropdown
  379. // trigger="click"
  380. // overlay={
  381. // <Menu onClick={dropDownMenClick}>
  382. // {state.totalOld ? <Menu.Item key="1">接收旧锁</Menu.Item> : null}
  383. // {state.totalNew ? <Menu.Item key="2">接收新锁</Menu.Item> : null}
  384. // </Menu>
  385. // }>
  386. // <Button>
  387. // 接收锁
  388. // <DownOutlined />
  389. // </Button>
  390. // </Dropdown>
  391. state.totalOld ? (
  392. <Button type="primary" onClick={showReceiveLockModal}>
  393. 接收旧锁({state.totalOld})
  394. </Button>
  395. ) : null
  396. }
  397. toolbar={{
  398. search: (
  399. <Tooltip placement="bottom" title="输入软件锁号">
  400. <Input.Search
  401. style={{ width: '300px' }}
  402. allowClear={true}
  403. placeholder={`在${
  404. permData[PermDataTypeEunm.PRODUCT]?.find(
  405. item => item.value === defaultPermAuthCache
  406. )?.label
  407. }下搜索`}
  408. onSearch={handleSearch}
  409. />
  410. </Tooltip>
  411. )
  412. // actions: [
  413. // <Tooltip title="产品出库时间" key="date">
  414. // <DatePicker.RangePicker
  415. // bordered={false}
  416. // onChange={time => {
  417. // const [time1, time2] = time || [null, null]
  418. // setState({
  419. // ...state,
  420. // params: {
  421. // ...state.params,
  422. // beginTime: time1 ? time1.format('YYYY-MM-DD') : null,
  423. // endTime: time2 ? time2.format('YYYY-MM-DD') : null
  424. // }
  425. // })
  426. // }}
  427. // />
  428. // </Tooltip>
  429. // ]
  430. }}
  431. />
  432. )
  433. }
  434. export default connect(({ lock, refresh }) => ({
  435. prodList: lock.prodList,
  436. shouldUpdate: refresh.longle
  437. }))(LockStore)