chartRanking.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <view class="chart-ranking">
  3. <template v-if="!$isEmpty(rankList)">
  4. <view class="rank-list rank-header">
  5. <view class="column">
  6. 排名
  7. </view>
  8. <view class="column">
  9. 姓名
  10. </view>
  11. <view class="column">
  12. {{ typeLabel }}
  13. </view>
  14. <view v-if="showRate" class="column">
  15. 目标完成率
  16. </view>
  17. </view>
  18. <scroll-view
  19. scroll-y
  20. :style="{
  21. height: wrapperHeight + 'px'
  22. }"
  23. class="scroll-rank">
  24. <view class="rank-list">
  25. <view class="column">
  26. <view
  27. v-for="(item, index) in rankList"
  28. :key="index"
  29. class="column-item sort">
  30. <image
  31. v-if="index < 3"
  32. :src="$static(`images/rank/${item.sort}.png`)"
  33. alt=""
  34. class="icon-img" />
  35. <text
  36. v-else class="rank">
  37. {{ item.sort }}
  38. </text>
  39. </view>
  40. </view>
  41. <view class="column">
  42. <view
  43. v-for="(item, index) in rankList"
  44. :key="index"
  45. class="column-item user">
  46. <wk-avatar
  47. :name="item.realname"
  48. :avatar="item.img"
  49. :size="12"
  50. class="avatar" />
  51. <text class="username">
  52. {{ item.realname }}
  53. </text>
  54. </view>
  55. </view>
  56. <view v-if="showRate" class="column">
  57. <view
  58. v-for="(item, index) in rankList"
  59. :key="index"
  60. class="column-item money">
  61. <template v-if="!$isEmpty(item.money)">
  62. ¥{{ item.money }}
  63. </template>
  64. </view>
  65. </view>
  66. <view v-else class="column">
  67. <view
  68. v-for="(item, index) in rankList"
  69. :key="index"
  70. class="column-item count">
  71. <template v-if="!$isEmpty(item.count)">
  72. {{ item.count }}
  73. </template>
  74. </view>
  75. </view>
  76. <view v-if="showRate" class="column">
  77. <view
  78. v-for="(item, index) in rankList"
  79. :key="index"
  80. class="column-item rate">
  81. <template v-if="!$isEmpty(item.rate)&&item.rate!=='暂无目标'">
  82. {{ item.rate }}%
  83. </template>
  84. </view>
  85. </view>
  86. </view>
  87. </scroll-view>
  88. </template>
  89. <view
  90. v-else
  91. :style="{backgroundImage: bgUrl('images/no_data.png')}"
  92. class="no-data">
  93. 暂无数据
  94. </view>
  95. <view
  96. v-if="!$isEmpty(selfData)"
  97. class="rank-list self">
  98. <view class="column">
  99. <view
  100. class="column-item sort">
  101. <image
  102. v-if="selfData.sort <= 3"
  103. :src="$static(`images/rank/${selfData.sort}.png`)"
  104. alt=""
  105. class="icon-img" />
  106. <text
  107. v-else class="rank">
  108. {{ selfData.sort }}
  109. </text>
  110. </view>
  111. </view>
  112. <view class="column">
  113. <view class="column-item user">
  114. <wk-avatar
  115. :name="selfData.realname"
  116. :avatar="selfData.img"
  117. :size="12"
  118. class="avatar" />
  119. <text class="username">
  120. {{ selfData.realname }}
  121. </text>
  122. </view>
  123. </view>
  124. <template v-if="showRate">
  125. <view class="column">
  126. <view class="column-item money">
  127. <template v-if="!$isEmpty(selfData.money)">
  128. ¥{{ selfData.money }}
  129. </template>
  130. </view>
  131. </view>
  132. </template>
  133. <template v-else>
  134. <view class="column">
  135. <view class="column-item count">
  136. <template v-if="!$isEmpty(selfData.count)">
  137. {{ selfData.count }}
  138. </template>
  139. </view>
  140. </view>
  141. </template>
  142. <view v-if="showRate" class="column">
  143. <view class="column-item rate">
  144. <template v-if="!$isEmpty(selfData.rate)&&selfData.rate!=='暂无目标'">
  145. {{ selfData.rate }}%
  146. </template>
  147. </view>
  148. </view>
  149. </view>
  150. </view>
  151. </template>
  152. <script>
  153. // import { RankingList } from 'API/crm/work'
  154. import {
  155. biRankingReceivablesAPI,
  156. biRankingContractAPI,
  157. biRankingContractCountAPI,
  158. biRankingCustomerCountAPI,
  159. biRankingContactsCountAPI,
  160. biRankingRecordCountAPI
  161. } from 'API/crm/work'
  162. import { mapGetters } from 'vuex'
  163. export default {
  164. name: 'ChartRanking',
  165. props: {
  166. params: {
  167. type: Object,
  168. default: () => {}
  169. }
  170. },
  171. data() {
  172. return {
  173. dropOptions: [
  174. { label: '合同金额', value: 1, request: biRankingContractAPI },
  175. { label: '回款金额', value: 2, request: biRankingReceivablesAPI },
  176. { label: '合同数', value: 3, request: biRankingContractCountAPI },
  177. { label: '新增客户数', value: 4, request: biRankingCustomerCountAPI },
  178. { label: '新增联系人', value: 5, request: biRankingContactsCountAPI },
  179. { label: '新增跟进记录数', value: 8, request: biRankingRecordCountAPI }
  180. ],
  181. dropVal: 2,
  182. rankList: [],
  183. selfData: {}
  184. }
  185. },
  186. computed: {
  187. ...mapGetters({
  188. userInfo: 'user/userInfo'
  189. }),
  190. typeLabel() {
  191. const findRes = this.dropOptions.find(o => o.value === this.dropVal)
  192. return findRes ? findRes.label : ''
  193. },
  194. wrapperHeight() {
  195. if (this.rankList.length <= 3) {
  196. return uni.upx2px(300)
  197. }
  198. if (this.rankList.length <= 7) {
  199. return uni.upx2px(100 * this.rankList.length)
  200. }
  201. return uni.upx2px(700)
  202. },
  203. showRate() {
  204. return [1, 2].includes(this.dropVal)
  205. },
  206. optionInfo() {
  207. if (
  208. this.dropVal == 1 ||
  209. this.dropVal == 2 ||
  210. this.dropVal == 7
  211. ) {
  212. return {
  213. key: 'money',
  214. unit: '元'
  215. }
  216. } else if (
  217. this.dropVal == 8
  218. ) {
  219. return {
  220. key: 'count',
  221. unit: '条'
  222. }
  223. }
  224. return {
  225. key: 'count',
  226. unit: '个'
  227. }
  228. },
  229. },
  230. watch: {
  231. params: {
  232. handler() {
  233. this.getRankData()
  234. },
  235. deep: true,
  236. immediate: true
  237. }
  238. },
  239. methods: {
  240. bgUrl(val) {
  241. return `url(${this.$static(val)})`
  242. },
  243. getData(val) {
  244. console.log('toggle: ', val)
  245. this.dropVal = val
  246. this.getRankData()
  247. },
  248. getRankData() {
  249. const request = this.dropOptions.find(item => item.value === this.dropVal).request
  250. request({
  251. ...this.params
  252. }).then(res => {
  253. const list = res || []
  254. const ranking = list.slice(0, 10)
  255. const myData = list.find(o => o.userId === this.userInfo.userId)
  256. this.rankList = ranking.map((item, index) => {
  257. item.sort = index + 1
  258. item.value = item[this.optionInfo.key]
  259. return item
  260. })
  261. if (myData) {
  262. this.selfData = {
  263. ...myData,
  264. value: myData[this.optionInfo.key]
  265. }
  266. } else {
  267. this.selfData = {
  268. ...this.userInfo,
  269. sort: '--',
  270. value: '--',
  271. rate: '--'
  272. }
  273. }
  274. }).catch()
  275. }
  276. }
  277. }
  278. </script>
  279. <style scoped lang="scss">
  280. .no-data {
  281. width: 100%;
  282. height: 336rpx;
  283. text-align: center;
  284. font-size: 26rpx;
  285. color: #BBBBBB;
  286. background-position: center 50rpx;
  287. background-repeat: no-repeat;
  288. background-size: 25%;
  289. padding-top: 250rpx;
  290. }
  291. .rank-list {
  292. width: 100%;
  293. display: flex;
  294. align-items: flex-start;
  295. justify-content: flex-start;
  296. .column {
  297. &:nth-child(1) {
  298. width: 80rpx;
  299. }
  300. &:nth-child(2) {
  301. flex: 1;
  302. }
  303. &:nth-child(3) {
  304. width: 220rpx;
  305. }
  306. &:nth-child(4) {
  307. width: 130rpx;
  308. }
  309. .column-item {
  310. font-size: $wk-font-medium;
  311. height: 100rpx;
  312. &.sort {
  313. font-size: 32rpx;
  314. color: #666;
  315. @include left;
  316. .icon-img {
  317. width: 46rpx;
  318. height: 40rpx;
  319. }
  320. }
  321. &.count {
  322. font-size: 32rpx;
  323. color: #666;
  324. @include left;
  325. }
  326. &.user {
  327. @include left;
  328. .avatar {
  329. width: 66rpx;
  330. height: 66rpx;
  331. }
  332. .username {
  333. max-width: 180rpx;
  334. font-size: $wk-font-medium;
  335. margin-left: 20rpx;
  336. @include ellipsis;
  337. }
  338. }
  339. &.money {
  340. font-size: $wk-font-medium;
  341. @include left;
  342. // @include ellipsis;
  343. }
  344. &.rate {
  345. font-size: $wk-font-medium;
  346. @include right;
  347. }
  348. }
  349. }
  350. }
  351. .scroll-rank {
  352. overflow: hidden;
  353. }
  354. .rank-header {
  355. padding-top: 15rpx;
  356. .column {
  357. height: 36rpx;
  358. line-height: 36rpx;
  359. font-size: $wk-font-mini;
  360. color: $light;
  361. }
  362. }
  363. .self {
  364. width: 100%;
  365. padding: 0;
  366. border-top: 1rpx solid $border-color;
  367. }
  368. </style>