SyncClient.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import consts from '@/consts'
  2. import { syncToClient } from '@/services/customer'
  3. import { Copy } from '@icon-park/react'
  4. import { Button, Checkbox, message, Modal, Table } from 'antd'
  5. import { useState, useMemo } from 'react'
  6. import { useDispatch } from 'umi'
  7. import { VList } from 'virtuallist-antd'
  8. import styles from './index.less'
  9. const SyncClient = ({ customer, client, actionPayload }) => {
  10. const dispatch = useDispatch()
  11. const [state, setState] = useState({
  12. visible: false,
  13. loading: false,
  14. selectedKeys: null,
  15. checkValues: ['district', 'address']
  16. })
  17. const refreshCompany = () => {
  18. dispatch({
  19. type: 'refresh/commitAction',
  20. payload: actionPayload
  21. })
  22. }
  23. const handleOnConfirm = async () => {
  24. const { checkValues, selectedKeys } = state
  25. if (!checkValues?.length) {
  26. return message.error('同步选项至少选中一个')
  27. }
  28. if (!selectedKeys?.length) {
  29. return message.warning('请选择需要同步的客户')
  30. }
  31. const params = { customerId: customer.id, clientIds: selectedKeys }
  32. checkValues?.forEach(item => {
  33. params[item] = true
  34. })
  35. const { code = -1 } = await syncToClient(params)
  36. if (code === consts.RET_CODE.SUCCESS) {
  37. refreshCompany()
  38. setState({ ...state, visible: false, loading: false })
  39. return message.success('同步成功')
  40. }
  41. }
  42. const columns = [
  43. {
  44. dataIndex: 'clientName',
  45. title: '客户名称',
  46. width: '15%',
  47. ellipsis: true
  48. },
  49. {
  50. dataIndex: 'districtName',
  51. title: '客户地区',
  52. width: '15%',
  53. ellipsis: true,
  54. renderText: text => text?.replaceAll(' / ', ',')
  55. },
  56. {
  57. dataIndex: 'address',
  58. title: '地址',
  59. width: '20%',
  60. ellipsis: true
  61. },
  62. {
  63. dataIndex: 'ride',
  64. title: '乘车路线',
  65. width: '20%',
  66. ellipsis: true
  67. },
  68. {
  69. dataIndex: 'landmarks',
  70. title: '地标建筑',
  71. width: '15%',
  72. ellipsis: true
  73. },
  74. {
  75. dataIndex: 'stay',
  76. title: '参考住宿',
  77. ellipsis: true
  78. }
  79. ]
  80. const vList = useMemo(() => {
  81. return VList({
  82. height: 400,
  83. vid: 'sync_client'
  84. })
  85. }, [])
  86. const { checkValues, visible, loading } = state
  87. return (
  88. <>
  89. <Button
  90. size="small"
  91. ghost
  92. type="primary"
  93. loading={loading}
  94. onClick={() => setState({ ...state, visible: true, loading: true })}
  95. >
  96. <Copy theme="two-tone" fill={['#333', '#886ab5']} />
  97. <span className="ml-1">同步地址信息</span>
  98. </Button>
  99. <Modal
  100. width="70%"
  101. title={`同步 ${customer.companyName} 信息`}
  102. // getContainer={false}
  103. visible={visible}
  104. onCancel={() => setState({ ...state, visible: false, loading: false })}
  105. onOk={handleOnConfirm}
  106. >
  107. <div className="rounded-3 p-4 mb-2 pt-0">
  108. <Checkbox.Group defaultValue={checkValues} onChange={e => setState({ ...state, checkValues: e })}>
  109. <div className="flex flex-nowrap">
  110. <Checkbox value="district">
  111. <div className="w-100px text-left">地区</div>
  112. </Checkbox>
  113. <div>{customer.districtName?.replaceAll(' / ', ',')}</div>
  114. </div>
  115. <div className="flex flex-nowrap">
  116. <Checkbox value="address">
  117. <div className="w-100px text-left">地址</div>
  118. </Checkbox>
  119. <div>{customer.address}</div>
  120. </div>
  121. <div className="flex flex-nowrap">
  122. <Checkbox value="ride">
  123. <div className="w-100px text-left">乘车路线</div>
  124. </Checkbox>
  125. <div>{customer.ride}</div>
  126. </div>
  127. <div className="flex flex-nowrap">
  128. <Checkbox value="landmarks">
  129. <div className="w-100px text-left">地标建筑</div>
  130. </Checkbox>
  131. <div>{customer.landmarks}</div>
  132. </div>
  133. <div className="flex flex-nowrap">
  134. <Checkbox value="stay">
  135. <div className="w-100px text-left">参考住宿</div>
  136. </Checkbox>
  137. <div>{customer.stay}</div>
  138. </div>
  139. </Checkbox.Group>
  140. </div>
  141. <div className={styles.tableSyncClient}>
  142. <Table
  143. rowKey="id"
  144. size="small"
  145. columns={columns}
  146. dataSource={client}
  147. pagination={false}
  148. scroll={{ y: 400 }}
  149. components={vList}
  150. rowSelection={{
  151. onChange: selectedRowKeys => setState({ ...state, selectedKeys: selectedRowKeys })
  152. }}
  153. />
  154. </div>
  155. </Modal>
  156. </>
  157. )
  158. }
  159. export default SyncClient