index.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import React, { useState, useEffect } from 'react'
  2. import { Tag } from 'antd'
  3. import ProTable from '@ant-design/pro-table'
  4. import useAutoTable from '@/hooks/useAutoTable'
  5. import consts from '@/consts'
  6. import { queryLock } from '@/services/lock'
  7. import Locks from '@/components/PopContent/Locks'
  8. const Lockstore = props => {
  9. const { collapsed } = props
  10. const needSubtractHeight = 48 + 48 + 48 + 64 + 24 + 32 // 需要被裁掉的高度
  11. const needSubtractWidth = (collapsed ? 208 : 48) + 48 + 48 + 48 // 需要被裁掉的高度
  12. const [x, y] = useAutoTable(collapsed, needSubtractHeight, needSubtractWidth)
  13. const [state, setState] = useState({
  14. data: [],
  15. total: 0,
  16. id: ''
  17. })
  18. const initData = async payload => {
  19. const {
  20. code = -1,
  21. data: { longle = [], log = [], total = 0 } = { longle: [], log: [], total: 0 }
  22. } = await queryLock(payload)
  23. if (code === consts.RET_CODE.SUCCESS) {
  24. setState({ ...state, data: longle, log, total })
  25. }
  26. // console.log(longle[0].product)
  27. // const productArr = longle[0].product.split('+')
  28. // console.log(productArr)
  29. }
  30. useEffect(() => {
  31. // props.getlist();
  32. initData()
  33. }, [])
  34. const handleSearch = value => {
  35. initData({ search: value })
  36. }
  37. // 展示drawer
  38. const showDrawer = id => {
  39. // console.log(id);
  40. setState({ ...state, id, visible: true })
  41. }
  42. // 隐藏drawer
  43. const hideDrawer = () => {
  44. setState({ ...state, visible: false, id: '' })
  45. }
  46. const onCreate = values => {
  47. console.log(values)
  48. }
  49. const columns = [
  50. {
  51. title: '锁号',
  52. dataIndex: 'keyNum',
  53. key: 'keyNum',
  54. width: 150,
  55. render: (keyNum, record) => <a onClick={() => showDrawer(record.id)}>{keyNum}</a>
  56. },
  57. {
  58. title: '产品',
  59. dataIndex: 'product',
  60. key: 'product',
  61. width: 350,
  62. render: (text, record) => {
  63. const productArr = text.split('+')
  64. return (
  65. <div>
  66. {productArr.map((item, index) => (
  67. <Tag key={index} color="#886ab5">
  68. {item}
  69. </Tag>
  70. ))}
  71. </div>
  72. )
  73. }
  74. },
  75. {
  76. title: '办事处',
  77. dataIndex: 'category',
  78. key: 'category',
  79. width: 150
  80. },
  81. {
  82. title: '出库时间',
  83. dataIndex: 'makeDay',
  84. key: 'makeDay',
  85. width: 150
  86. },
  87. {
  88. title: '销售/借出/赠送时间',
  89. dataIndex: 'allotedTime',
  90. key: 'allotedTime',
  91. width: 160
  92. },
  93. {
  94. title: '责任人',
  95. dataIndex: 'responsible',
  96. key: 'responsible',
  97. width: 150
  98. },
  99. {
  100. title: '状态',
  101. dataIndex: 'statusT',
  102. key: 'statusT',
  103. width: 150
  104. },
  105. {
  106. title: '联系人',
  107. dataIndex: 'client',
  108. key: 'client',
  109. width: 150
  110. }
  111. ]
  112. return (
  113. <div>
  114. <ProTable
  115. rowKey={record => record.id}
  116. search={false}
  117. headerTitle="公共锁库"
  118. bordered
  119. columns={columns}
  120. dataSource={state.data}
  121. scroll={{ x, y }}
  122. toolbar={{
  123. search: {
  124. onSearch: handleSearch
  125. }
  126. }}
  127. />
  128. <Locks onClose={hideDrawer} visible={state.visible} onCreate={onCreate} id={state.id} />
  129. </div>
  130. )
  131. }
  132. export default Lockstore