123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import React, { useState, useEffect, useRef } from 'react'
  2. import withLayout from '@/layout'
  3. import Taro from '@tarojs/taro'
  4. import { ScrollView, Image } from '@tarojs/components'
  5. import { BIZ_STATUS } from '@/constants/user'
  6. import DateRangePicker from '@/components/DateRangePicker'
  7. import Picker from '@/components/Picker'
  8. import LineChat from './components/LineChat'
  9. import useRank from './hooks/useRank'
  10. import useReport from './hooks/useReport'
  11. import useChart from './hooks/useChart'
  12. // import '@/assets/css/iconfont.css'
  13. import './index.scss'
  14. import { fillTime, cutDays, cutMonths } from './utils'
  15. const statTypeDicts = [
  16. {name: '按天', id: 'day'},
  17. {name: '按月', id: 'month'},
  18. ]
  19. const custTypeDicts = [
  20. {name: '新增人员', id: 'new'},
  21. {name: '跟进', id: 'follow'},
  22. {name: '成交', id: 'success'},
  23. ]
  24. export default withLayout((props) => {
  25. const [showPicker, setShowPicker] = useState(false)
  26. const pickerTrigger = useRef()
  27. const [,setRankDateRange, rankList] = useRank()
  28. const [,setReportDateRange, reportInfo] = useReport()
  29. const [
  30. statType,
  31. setStatType,
  32. custType,
  33. setCustType,
  34. chartData,
  35. xAxisDataRef,
  36. ] = useChart()
  37. const handleMore = () => {
  38. Taro.navigateTo({ url: '/pages/mine/myCustomer/index' })
  39. }
  40. const handleRankDate = () => {
  41. pickerTrigger.current = 'rank'
  42. setShowPicker(true)
  43. }
  44. const handleReportDate = () => {
  45. pickerTrigger.current = 'report'
  46. setShowPicker(true)
  47. }
  48. const handlePickerChange = (e) => {
  49. setShowPicker(false)
  50. if (pickerTrigger.current == 'rank') {
  51. setRankDateRange(e)
  52. } else {
  53. setReportDateRange(e)
  54. }
  55. }
  56. const SortChange = (e) => {
  57. setStatType(e)
  58. const num = e === 'month' ? 6 : 7
  59. const now = new Date()
  60. const startDate = e === 'month' ? cutMonths(now, num) : cutDays(now, num)
  61. setReportDateRange([fillTime(startDate.toJSON().substring(0, 10), true), fillTime(now.toJSON().substring(0, 10), false)])
  62. }
  63. const [tp1 = {}, tp2 = {}, tp3 = {}] = rankList||[]
  64. return (
  65. <view className='Page partnerChannel'>
  66. <DateRangePicker visable={showPicker} close={() => setShowPicker(false)} change={handlePickerChange} />
  67. <ScrollView scrollY>
  68. <view className='PageContent'>
  69. {/* 排行榜 */}
  70. <view className='Ranking'>
  71. <view className='Top flex-h'>
  72. <text className='flex-item'>龙虎榜</text>
  73. <Image mode='heightFix' src={require('@/assets/mine-icon23.png')} onClick={handleRankDate} />
  74. </view>
  75. <view className='List flex-h'>
  76. {/* 第二名 */}
  77. <view className='flex-item'>
  78. <Image mode='heightFix' src={require('@/assets/mine-icon21.png')}></Image>
  79. <view className='Icon'>
  80. <Image mode='aspectFill' src={tp2.avatarurl} style={{width: '100%', height: '100%'}}></Image>
  81. </view>
  82. <view className='Index'>
  83. <text>{tp2.name||'暂无'}</text>
  84. <text>2</text>
  85. </view>
  86. <view className='Num'>
  87. <text></text>
  88. <text>{tp2.number ? `到访 ${tp2.number} 人` : '暂无'}</text>
  89. </view>
  90. </view>
  91. {/* 第一名 */}
  92. <view className='flex-item active' style={{zIndex:'1'}}>
  93. <Image mode='heightFix' src={require('@/assets/mine-icon20.png')}></Image>
  94. <view className='Icon'>
  95. <Image mode='aspectFill' src={tp1.avatarurl} style={{width: '100%', height: '100%'}}></Image>
  96. </view>
  97. <view className='Index'>
  98. <text>{tp1.name||'暂无'}</text>
  99. <text>1</text>
  100. </view>
  101. <view className='Num'>
  102. <text></text>
  103. <text>{tp1.number ? `到访 ${tp1.number} 人` : '暂无'}</text>
  104. </view>
  105. </view>
  106. {/* 第三名 */}
  107. <view className='flex-item'>
  108. <Image mode='heightFix' src={require('@/assets/mine-icon22.png')}></Image>
  109. <view className='Icon'>
  110. <Image mode='aspectFill' src={tp3.avatarurl} style={{width: '100%', height: '100%'}}></Image>
  111. </view>
  112. <view className='Index'>
  113. <text>{tp3.name||'暂无'}</text>
  114. <text>3</text>
  115. </view>
  116. <view className='Num'>
  117. <text></text>
  118. <text>{tp3.number ? `到访 ${tp3.number} 人` : '暂无'}</text>
  119. </view>
  120. </view>
  121. </view>
  122. </view>
  123. {/* 销售简报 */}
  124. <view className='SaleNews'>
  125. <view className='Top flex-h'>
  126. <text>销售简报</text>
  127. <Image mode='heightFix' src={require('@/assets/mine-icon23.png')} onClick={handleReportDate}></Image>
  128. <view className='flex-item'></view>
  129. <text onClick={handleMore}>更多</text>
  130. <text className='iconfont icon-jiantouright'></text>
  131. </view>
  132. <view className='List'>
  133. <view className='flex-h'>
  134. <text className='flex-item'>新增客户</text>
  135. <text>{`${reportInfo.newCustomerNum||0}人`}</text>
  136. {/* <text className='iconfont icon-jiantouright'></text> */}
  137. </view>
  138. <view className='flex-h'>
  139. <text className='flex-item'>跟进客户</text>
  140. <text>{`${reportInfo.followCustomerNum||0}人`}</text>
  141. {/* <text className='iconfont icon-jiantouright'></text> */}
  142. </view>
  143. <view className='flex-h'>
  144. <text className='flex-item'>成交客户</text>
  145. <text>{`${reportInfo.successCustomerNum||0}人`}</text>
  146. {/* <text className='iconfont icon-jiantouright'></text> */}
  147. </view>
  148. </view>
  149. </view>
  150. {/* 销售趋势 */}
  151. <view className='SaleLineChart'>
  152. <view className='Top flex-h'>
  153. <text>销售趋势</text>
  154. <view className='flex-item'></view>
  155. <view className='Type'>
  156. <Picker kv={['name', 'id']} dicts={custTypeDicts} value={custType} onChange={setCustType} />
  157. <text className='iconfont icon-sanjiaoxingdown'></text>
  158. </view>
  159. <view className='Sort'>
  160. <Picker kv={['name', 'id']} dicts={statTypeDicts} value={statType} onChange={SortChange} />
  161. <text className='iconfont icon-sanjiaoxingdown'></text>
  162. </view>
  163. </view>
  164. <view className='LineChart'>
  165. <LineChat xAxisDataRef={xAxisDataRef} dataSource={chartData} />
  166. </view>
  167. </view>
  168. </view>
  169. </ScrollView>
  170. </view>
  171. )
  172. })