123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import { useState, useEffect } from 'react'
  2. import Taro from "@tarojs/taro";
  3. import withLayout from '@/layout'
  4. import '@/assets/css/iconfont.css'
  5. import { Image, Textarea } from '@tarojs/components'
  6. import { fetch } from '@/utils/request'
  7. import { API_GET_CUSTOMER_INFO } from '@/constants/api'
  8. import { getCustomerDetail, addFollowRecord } from '@/services/person'
  9. import { getImgURL } from '@/utils/image'
  10. import { BIZ_STATUS } from '@/constants/user'
  11. import './index.scss'
  12. import UserDetailBasicInfo from '../components/UserDetailBasicInfo/index'
  13. import UserDetailViewRecord from '../components/UserDetailViewRecord/index'
  14. import UserDetailActivityInfo from '../components/UserDetailActivityInfo/index'
  15. import UserDetailFollowRecord from '../components/UserDetailFollowRecord/index'
  16. export default withLayout((props) => {
  17. const { router } = props
  18. const { id : CustomerId, } = router.params
  19. const [custBaseInfo, setCustBaseInfo] = useState({})
  20. const [CustomerInfo, setCustomerInfo] = useState({})
  21. const [ShowAddFollow, setShowAddFollow] = useState(false)
  22. const [MenuList] = useState([
  23. { name: '基本信息', id: 1 },
  24. { name: '访问记录', id: 2 },
  25. { name: '活动信息', id: 3 },
  26. { name: '跟进记录', id: 4 }
  27. ])
  28. const [CurrentMenuId, setCurrentMenuId] = useState(1)
  29. const [FollowContent, setFollowContent] = useState('')
  30. const [FollowAddCounts, setFollowAddCounts] = useState(0)
  31. const UpdateCustomerInfo = () => {
  32. fetch({ url: `${API_GET_CUSTOMER_INFO}/${CustomerId}` }).then((res) => {
  33. setCustomerInfo(res || {})
  34. })
  35. }
  36. const CutMenu = (item) => {
  37. return () => {
  38. setCurrentMenuId(item.id)
  39. }
  40. }
  41. const AddFollow = () => {
  42. setShowAddFollow(true)
  43. }
  44. const FollowInput = (e) => {
  45. setFollowContent(e.detail.value.substring(0, 150))
  46. }
  47. const SaveFollow = () => {
  48. const payload = {
  49. recordType: '添加跟进',
  50. recordContent: FollowContent,
  51. customerSex: CustomerInfo.sex,
  52. customerId: CustomerId,
  53. }
  54. addFollowRecord(payload).then(() => {
  55. Taro.showToast({
  56. title: '添加跟进成功',
  57. icon: 'none'
  58. })
  59. setShowAddFollow(false)
  60. setFollowContent('')
  61. if (CurrentMenuId === 4) {
  62. setFollowAddCounts(FollowAddCounts + 1)
  63. }
  64. }).catch(() => {
  65. Taro.showToast({
  66. title: '添加跟进失败',
  67. icon: 'none'
  68. })
  69. })
  70. }
  71. const CancelAddFollow = () => {
  72. setShowAddFollow(false)
  73. setFollowContent('')
  74. }
  75. useEffect(() => {
  76. if (CustomerId) {
  77. UpdateCustomerInfo()
  78. getCustomerDetail(CustomerId).then((res) => setCustBaseInfo(res || {}))
  79. }
  80. }, [CustomerId])
  81. const ToChat = () => {
  82. if(CustomerInfo.personId) {
  83. Taro.navigateTo({
  84. url: `/pages/chat/chatDetail/index?friend=${CustomerInfo.personId}`
  85. })
  86. } else {
  87. Taro.showToast({
  88. title: '当前人员未登录本小程序',
  89. icon: 'none'
  90. })
  91. }
  92. }
  93. return (
  94. <view className='Page customerDetail flex-v'>
  95. <view className='UserInfo'>
  96. <view>
  97. <view>
  98. <view className='centerLabel'>
  99. <view className='flex-h'>
  100. <view className='Icon'>
  101. <Image mode='aspectFill' src={getImgURL(custBaseInfo.avatarurl || custBaseInfo.picture)}></Image>
  102. </view>
  103. <view className='flex-item'>
  104. <view>
  105. <text>{custBaseInfo.name}</text>
  106. <text className={custBaseInfo.sex - 0 === 1 ? 'iconfont icon-nanxing' : 'iconfont icon-nvxing'}></text>
  107. </view>
  108. <text>{custBaseInfo.phone}</text>
  109. </view>
  110. <text className='iconfont icon-liaotian' onClick={ToChat}></text>
  111. <text className='iconfont icon-dianhua' onClick={() => { Taro.makePhoneCall({ phoneNumber: custBaseInfo.phone }) }}></text>
  112. </view>
  113. </view>
  114. <text className='Status'>{BIZ_STATUS[custBaseInfo.status] || '报备'}</text>
  115. <text className='Tips'>NEW</text>
  116. <text className='Tips'>NEW</text>
  117. </view>
  118. </view>
  119. </view>
  120. <view className='MenuList'>
  121. <view>
  122. {
  123. MenuList.map((item, index) => (
  124. <text key={`MenuItem-${index}`} className={CurrentMenuId === item.id ? 'active' : ''} onClick={CutMenu(item)}>{item.name}</text>
  125. ))
  126. }
  127. </view>
  128. </view>
  129. <view className='flex-item'>
  130. <view>
  131. {/* 基本信息 */}
  132. {
  133. CurrentMenuId === 1 &&
  134. <UserDetailBasicInfo CustomerId={CustomerId} CustomerInfo={CustomerInfo} AddFollow={AddFollow} Update={UpdateCustomerInfo}></UserDetailBasicInfo>
  135. }
  136. {/* 访问记录 */}
  137. {
  138. CurrentMenuId === 2 &&
  139. <UserDetailViewRecord CustomerId={CustomerId} AddFollow={AddFollow}></UserDetailViewRecord>
  140. }
  141. {/* 活动信息 */}
  142. {
  143. CurrentMenuId === 3 &&
  144. <UserDetailActivityInfo CustomerId={CustomerId} AddFollow={AddFollow}></UserDetailActivityInfo>
  145. }
  146. {/* 跟进记录 */}
  147. {
  148. CurrentMenuId === 4 &&
  149. <UserDetailFollowRecord CustomerId={CustomerId} AddFollow={AddFollow} AddFollowCounts={FollowAddCounts}></UserDetailFollowRecord>
  150. }
  151. </view>
  152. </view>
  153. {
  154. ShowAddFollow &&
  155. <view className='AddFollow'>
  156. <view className='centerLabel'>
  157. <view>
  158. <view>
  159. <text>跟进内容</text>
  160. <view className='FollowContent'>
  161. <Textarea placeholder='不超过150字' maxLength={150} value={FollowContent} onInput={FollowInput} />
  162. </view>
  163. <view className='Save flex-h'>
  164. <view className='flex-item'>
  165. <text onClick={CancelAddFollow}>取消</text>
  166. </view>
  167. <view className='flex-item'>
  168. <text onClick={SaveFollow}>保存</text>
  169. </view>
  170. </view>
  171. </view>
  172. </view>
  173. </view>
  174. </view>
  175. }
  176. </view>
  177. )
  178. })