SyncClient.jsx 5.1 KB

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