statistics.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. <template>
  2. <view class="statistics">
  3. <custom-nav>
  4. <view class="current-date" @click="goBack"><text class="iconfont iconzuojiantou" style="font-size:45rpx;color:#fff;"></text></view>
  5. </custom-nav>
  6. <view style="background:url(https://api.szy.jiuweiyun.cn/images/data_bg.png) no-repeat;background-size:100% 100%;width: 100%;height:644rpx;"></view>
  7. <view class="statistics_con">
  8. <view class="qiun-columns">
  9. <view class="title">代理等级组成及占比</view>
  10. <view class="circle flexS">
  11. <view class="qiun-charts"><canvas canvas-id="levelRing" id="levelRing" class="charts"></canvas></view>
  12. <view class="scale">
  13. <view>
  14. <view v-for="(item, index) in level" :key="index" style="display:flex;flex-direction: column;">
  15. <view class="flexS">
  16. <view class="hint" :style="{ background: item.color }"></view>
  17. <view>{{ item.name }}</view>
  18. </view>
  19. </view>
  20. </view>
  21. <view style="margin:0 10rpx;">
  22. <view class="intr">数量</view>
  23. <view v-for="(item, index) in level" :key="index" class="bold">{{ item.data }}</view>
  24. </view>
  25. <view>
  26. <view class="intr">比例</view>
  27. <view v-for="(item, index) in level" :key="index" class="bold">{{ Math.round((item.data / allLevel) * 10000) / 100.0 + '%' }}</view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="qiun-columns">
  33. <view class="title">代理性别组成及占比</view>
  34. <view class="circle flexS">
  35. <view class="qiun-charts"><canvas canvas-id="sexRing" id="sexRing" class="charts"></canvas></view>
  36. <view class="scale">
  37. <view>
  38. <view v-for="(item, index) in sex" :key="index" style="display:flex;flex-direction: column;">
  39. <view class="flexS">
  40. <view class="hint" :style="{ background: item.color }"></view>
  41. <view>{{ item.name }}</view>
  42. </view>
  43. </view>
  44. </view>
  45. <view style="margin:0 10rpx;">
  46. <view class="intr">数量</view>
  47. <view v-for="(item, index) in sex" :key="index" class="bold">{{ item.data }}</view>
  48. </view>
  49. <view>
  50. <view class="intr">比例</view>
  51. <view v-for="(item, index) in sex" :key="index" class="bold">{{ Math.round((item.data / allSex) * 10000) / 100.0 + '%' }}</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="qiun-columns age ">
  57. <view class="title">代理年龄组成及占比</view>
  58. <view class="circle flexS">
  59. <view class="qiun-charts"><canvas canvas-id="ageRing" id="ageRing" class="charts"></canvas></view>
  60. <view class="scale">
  61. <view>
  62. <view v-for="(item, index) in ages" :key="index" style="display:flex;flex-direction: column;">
  63. <view class="flexS">
  64. <view class="hint" :style="{ background: item.color }"></view>
  65. <view>{{ item.state }}</view>
  66. </view>
  67. </view>
  68. </view>
  69. <view style="margin:0 10rpx;">
  70. <view class="intr">数量</view>
  71. <view v-for="(item, index) in ages" :key="index" class="bold">{{ item.data }}</view>
  72. </view>
  73. <view>
  74. <view class="intr">比例</view>
  75. <view v-for="(item, index) in ages" :key="index" class="bold">{{ Math.round((item.data / allAges) * 10000) / 100.0 + '%' }}</view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <view class="strip">
  81. <view class="strip_con">
  82. <view class="title">团队老大人数及占比</view>
  83. <view class="strip_list flexB leader" v-for="(item, i) in leader" :key="i">
  84. <view class="label">
  85. <text>{{ item.name | getName }}</text>
  86. <text style="font-size:24rpx;color:#999;">{{ item.phone }}</text>
  87. </view>
  88. <view class="block flexS">
  89. <view class="blue" :style="{ width: Math.round((item.val / allLeader) * 10000) / 100.0 + '%' }"></view>
  90. <view class="ratio">{{ Math.round((item.val / allLeader) * 10000) / 100.0 + '%' }}</view>
  91. </view>
  92. <view class="line"></view>
  93. <text class="num">{{ item.val }}人</text>
  94. </view>
  95. <view class="more" @click="getMoreLeader">
  96. <text>{{ isPack ? '收起' : '查看更多' }}</text>
  97. <text class="iconfont iconshuangxiajiantou-" v-if="!isPack"></text>
  98. <text class="iconfont iconshuangshangjiantou-" v-else></text>
  99. </view>
  100. </view>
  101. </view>
  102. <view class="strip">
  103. <view class="strip_con">
  104. <view class="title">各省份人数及占比</view>
  105. <view class="strip_list flexB" v-for="(item, i) in province" :key="i">
  106. <text class="label">{{ item.name | getName }}</text>
  107. <view class="block flexS">
  108. <view class="blue" :style="{ width: Math.round((item.val / allprovince) * 10000) / 100.0 + '%' }"></view>
  109. <view class="ratio">{{ Math.round((item.val / allprovince) * 10000) / 100.0 + '%' }}</view>
  110. </view>
  111. <view class="line"></view>
  112. <text style="font-size:28rpx;color:#333;font-weight:600;" class="num">{{ item.val }}人</text>
  113. </view>
  114. <view class="more" @click="getMoreProvince">
  115. <text>{{ isMore ? '收起' : '查看更多' }}</text>
  116. <text class="iconfont iconshuangxiajiantou-" v-if="!isMore"></text>
  117. <text class="iconfont iconshuangshangjiantou-" v-else></text>
  118. </view>
  119. </view>
  120. </view>
  121. </view>
  122. </view>
  123. </template>
  124. <script>
  125. import uCharts from '@/components/u-charts/u-charts.js';
  126. import customNav from '../../components/custom-nav.vue';
  127. import { getData, countData } from '../../api/data.js';
  128. var _self;
  129. var canvaRing = null;
  130. export default {
  131. data() {
  132. return {
  133. cWidth: '', //圆环图宽度
  134. cHeight: '', //圆环图高度
  135. pixelRatio: 1,
  136. serverData: '',
  137. level: '', //等级
  138. allLevel: '', //等级人数总数
  139. sex: '', //性别
  140. allSex: '', //性别总数
  141. leader: '', //团队老大(前6)
  142. allLeader: '', //所有人数
  143. allLeaderData: '', //团队老大(所有)
  144. province: '', //省份(前8)
  145. allprovince: '', //所有人数
  146. allprovinceData: '', //省份 所有
  147. ages: '', //年龄
  148. allAges: '', //总人数
  149. isPack: false, //团队老大 false查看更多 收起
  150. isMore: false // 省份 false查看更多 收起
  151. };
  152. },
  153. onLoad() {
  154. _self = this;
  155. this.cWidth = uni.upx2px(300);
  156. this.cHeight = uni.upx2px(300);
  157. },
  158. onShow() {
  159. this.getData();
  160. },
  161. onPullDownRefresh() {
  162. if (uni.getStorageSync('token')) {
  163. this.getData();
  164. } else {
  165. uni.stopPullDownRefresh();
  166. }
  167. },
  168. filters: {
  169. getName(name) {
  170. if (name) {
  171. return name.length > 4 ? name.slice(0, 4) + '...' : name;
  172. }
  173. return '';
  174. }
  175. },
  176. components: {
  177. customNav
  178. },
  179. methods: {
  180. //返回上一页
  181. goBack() {
  182. uni.navigateBack({
  183. delta: 1
  184. });
  185. },
  186. //点击查看更多团队老大
  187. getMoreLeader() {
  188. let that = this;
  189. that.isPack = !that.isPack;
  190. if (that.isPack) {
  191. that.leader = that.allLeaderData;
  192. } else {
  193. that.leader = that.allLeaderData.slice(0, 6);
  194. }
  195. },
  196. //点击查看更多省份
  197. getMoreProvince() {
  198. let that = this;
  199. that.isMore = !that.isMore;
  200. if (that.isMore) {
  201. that.province = that.allprovinceData;
  202. } else {
  203. that.province = that.allprovinceData.slice(0, 6);
  204. }
  205. },
  206. //根据数组中对象某个值排序
  207. compare(property, desc) {
  208. return function(a, b) {
  209. var value1 = a[property];
  210. var value2 = b[property];
  211. if (desc == true) {
  212. // 升序排列
  213. return value1 - value2;
  214. } else {
  215. // 降序排列
  216. return value2 - value1;
  217. }
  218. };
  219. },
  220. getData() {
  221. getData()
  222. .then(res => {
  223. if (res.code == 200) {
  224. let levelData = res.data.level;
  225. levelData.map(i => {
  226. if (i.name == '代理公司') {
  227. this.$set(i, 'color', '#82CCFF');
  228. return false;
  229. }
  230. if (i.name == '销售经理') {
  231. this.$set(i, 'color', '#508CEC');
  232. return false;
  233. }
  234. this.$set(i, 'color', '#F56367');
  235. });
  236. this.level = levelData.sort(this.compare('data', false));
  237. this.allLevel = res.data.level_total;
  238. let sexData = res.data.sex;
  239. sexData.map(i => {
  240. if (i.name == '男') {
  241. this.$set(i, 'color', '#FFD182');
  242. } else {
  243. this.$set(i, 'color', '#F56367');
  244. }
  245. });
  246. this.sex = sexData.sort(this.compare('data', false));
  247. this.allSex = res.data.sex_total;
  248. _self.levelRing('levelRing', this.level);
  249. _self.sexRing('sexRing', this.sex);
  250. } else {
  251. uni.showModal({
  252. content: res.message || '获取失败',
  253. showCancel: false
  254. });
  255. }
  256. })
  257. .finally(() => {
  258. uni.stopPullDownRefresh();
  259. });
  260. countData()
  261. .then(res => {
  262. if (res.code == 200) {
  263. let ages = res.data.ages;
  264. ages.map(i => {
  265. if (i.name == '<30') {
  266. this.$set(i, 'color', '#CF429F');
  267. this.$set(i, 'state', '小于30岁');
  268. return false;
  269. }
  270. if (i.name == '30-40') {
  271. this.$set(i, 'color', '#F56367');
  272. this.$set(i, 'state', '30-40岁');
  273. return false;
  274. }
  275. if (i.name == '40-50') {
  276. this.$set(i, 'color', '#54D798');
  277. this.$set(i, 'state', '40-50岁');
  278. return false;
  279. }
  280. if (i.name == '50-60') {
  281. this.$set(i, 'color', '#B5DA4C');
  282. this.$set(i, 'state', '50-60岁');
  283. return false;
  284. }
  285. if (i.name == '>=60') {
  286. this.$set(i, 'color', '#A864F4');
  287. this.$set(i, 'state', '60岁以上');
  288. return false;
  289. }
  290. });
  291. this.ages = ages.sort(this.compare('data', false));
  292. _self.ageRing('ageRing', this.ages);
  293. this.allAges = this.ageSum(res.data.ages);
  294. let leader = res.data.crowns;
  295. let lead = [];
  296. for (let i in leader) {
  297. var rt = /(.+)?(?:\(|()(.+)(?=\)|))/.exec(i);
  298. lead.push({ name: rt[1], phone: rt[2], val: leader[i] });
  299. }
  300. this.allLeaderData = lead.sort(this.compare('val', false));
  301. this.leader = this.allLeaderData.slice(0, 6);
  302. let pro = res.data.province;
  303. let proArr = [];
  304. for (let i in pro) {
  305. proArr.push({ name: i, val: pro[i] });
  306. }
  307. this.allprovinceData = proArr.sort(this.compare('val', false));
  308. this.province = this.allprovinceData.slice(0, 8);
  309. var provinceArr = [];
  310. provinceArr = Object.values(res.data.province);
  311. this.allprovince = this.sum(provinceArr);
  312. var leaderArr = [];
  313. leaderArr = Object.values(res.data.crowns);
  314. this.allLeader = this.sum(leaderArr);
  315. } else {
  316. uni.showModal({
  317. content: res.message || '请求失败',
  318. showCancel: false
  319. });
  320. }
  321. })
  322. .finally(() => {
  323. uni.stopPullDownRefresh();
  324. });
  325. },
  326. toJSON() {},
  327. ageSum(arr) {
  328. var s = 0;
  329. for (var i = arr.length - 1; i >= 0; i--) {
  330. s += arr[i].data;
  331. }
  332. return s;
  333. },
  334. sum(arr) {
  335. var s = 0;
  336. for (var i = arr.length - 1; i >= 0; i--) {
  337. s += arr[i];
  338. }
  339. return s;
  340. },
  341. levelRing(canvasId, chartData) {
  342. canvaRing = new uCharts({
  343. $this: _self,
  344. canvasId: canvasId,
  345. type: 'ring',
  346. fontSize: 11,
  347. legend: { show: false },
  348. subtitle: {
  349. name: '等级组成',
  350. color: '#999999',
  351. fontSize: 14 * _self.pixelRatio,
  352. offsetY: 1 * _self.pixelRatio
  353. },
  354. extra: {
  355. pie: {
  356. offsetAngle: -45,
  357. ringWidth: 20 * _self.pixelRatio,
  358. labelWidth: 15
  359. }
  360. },
  361. background: '#FFFFFF',
  362. pixelRatio: _self.pixelRatio,
  363. series: chartData,
  364. animation: true,
  365. width: _self.cWidth * _self.pixelRatio,
  366. height: _self.cHeight * _self.pixelRatio,
  367. disablePieStroke: true,
  368. dataLabel: false
  369. });
  370. },
  371. sexRing(canvasId, chartData) {
  372. canvaRing = new uCharts({
  373. $this: _self,
  374. canvasId: canvasId,
  375. type: 'ring',
  376. fontSize: 11,
  377. legend: { show: false },
  378. subtitle: {
  379. name: '性别组成',
  380. color: '#999999',
  381. fontSize: 14 * _self.pixelRatio,
  382. offsetY: 1 * _self.pixelRatio
  383. },
  384. extra: {
  385. pie: {
  386. offsetAngle: -45,
  387. ringWidth: 20 * _self.pixelRatio,
  388. labelWidth: 15
  389. }
  390. },
  391. background: '#FFFFFF',
  392. pixelRatio: _self.pixelRatio,
  393. series: chartData,
  394. animation: true,
  395. width: _self.cWidth * _self.pixelRatio,
  396. height: _self.cHeight * _self.pixelRatio,
  397. disablePieStroke: true,
  398. dataLabel: false
  399. });
  400. },
  401. ageRing(canvasId, chartData) {
  402. canvaRing = new uCharts({
  403. $this: _self,
  404. canvasId: canvasId,
  405. type: 'ring',
  406. fontSize: 11,
  407. legend: { show: false },
  408. subtitle: {
  409. name: '年龄组成',
  410. color: '#999999',
  411. fontSize: 14 * _self.pixelRatio,
  412. offsetY: 1 * _self.pixelRatio
  413. },
  414. extra: {
  415. pie: {
  416. offsetAngle: -45,
  417. ringWidth: 20 * _self.pixelRatio,
  418. labelWidth: 15
  419. }
  420. },
  421. background: '#FFFFFF',
  422. pixelRatio: _self.pixelRatio,
  423. series: chartData,
  424. animation: true,
  425. width: _self.cWidth * _self.pixelRatio,
  426. height: _self.cHeight * _self.pixelRatio,
  427. disablePieStroke: true,
  428. dataLabel: false
  429. });
  430. }
  431. }
  432. };
  433. </script>
  434. <style>
  435. page {
  436. width: 100%;
  437. height: 100%;
  438. background-color: #fff;
  439. }
  440. </style>
  441. <style lang="scss">
  442. .statistics {
  443. width: 100%;
  444. padding-bottom: 50rpx;
  445. overflow-x: hidden;
  446. }
  447. .statistics_con {
  448. margin-top: -344rpx;
  449. }
  450. .title {
  451. font-size: 32rpx;
  452. color: #333;
  453. font-weight: 600;
  454. }
  455. .more {
  456. width: 100%;
  457. text-align: center;
  458. padding: 30rpx 0;
  459. text {
  460. font-size: 28rpx;
  461. color: #999999;
  462. }
  463. image {
  464. height: 28rpx;
  465. width: 28rpx;
  466. vertical-align: -4rpx;
  467. margin-left: 5rpx;
  468. }
  469. }
  470. .strip,
  471. .qiun-columns {
  472. width: 690rpx;
  473. margin: 30rpx auto 0;
  474. background: #fff;
  475. box-shadow: 0 0 12rpx rgba(67, 147, 255, 0.19);
  476. box-sizing: border-box;
  477. border-radius: 24rpx;
  478. }
  479. .qiun-columns {
  480. height: 386rpx;
  481. .title {
  482. padding: 20rpx 0 0 30rpx;
  483. }
  484. .circle {
  485. width: 95%;
  486. margin: 0 auto;
  487. .scale {
  488. font-size: 28rpx;
  489. display: flex;
  490. justify-content: space-between;
  491. align-items: flex-end;
  492. > view {
  493. > view {
  494. margin-bottom: 15rpx;
  495. text-align: center;
  496. }
  497. }
  498. .bold {
  499. font-weight: 600;
  500. }
  501. .intr {
  502. color: #508cec;
  503. }
  504. .hint {
  505. height: 16rpx;
  506. width: 16rpx;
  507. margin-right: 10rpx;
  508. }
  509. }
  510. .name {
  511. text {
  512. font-size: 24rpx;
  513. color: #508cec;
  514. }
  515. }
  516. .data_con {
  517. margin-top: 15rpx;
  518. text {
  519. font-size: 28rpx;
  520. font-weight: 600;
  521. }
  522. }
  523. .name,
  524. .data_con {
  525. width: 230rpx;
  526. display: flex;
  527. justify-content: space-around;
  528. align-items: center;
  529. text:last-child {
  530. margin-left: 15rpx;
  531. }
  532. }
  533. }
  534. .qiun-charts {
  535. width: 300rpx;
  536. height: 300rpx;
  537. }
  538. .charts {
  539. width: 300rpx;
  540. height: 300rpx;
  541. }
  542. }
  543. .age {
  544. height: 420rpx;
  545. }
  546. .strip_con {
  547. width: 630rpx;
  548. margin: 0 auto;
  549. .title {
  550. padding: 20rpx 0;
  551. }
  552. .strip_list {
  553. margin-top: 30rpx;
  554. position: relative;
  555. .label {
  556. width: 180rpx;
  557. font-size: 32rpx;
  558. color: #333;
  559. flex-shrink: 0;
  560. }
  561. .line {
  562. width: 340rpx;
  563. height: 2rpx;
  564. border-bottom: 1rpx dashed #8a8a8a;
  565. z-index: 88;
  566. }
  567. .num {
  568. width: 100rpx;
  569. flex-shrink: 0;
  570. text-align: center;
  571. font-size: 28rpx;
  572. color: #333;
  573. font-weight: 600;
  574. }
  575. .block {
  576. width: 340rpx;
  577. position: absolute;
  578. top: 2rpx;
  579. left: 153rpx;
  580. z-index: 99;
  581. .blue {
  582. height: 12rpx;
  583. background: #508cec;
  584. border-radius: 10rpx;
  585. }
  586. .ratio {
  587. color: #508cec;
  588. font-size: 28rpx;
  589. font-weight: 600;
  590. background-color: #fff;
  591. padding-left: 14rpx;
  592. }
  593. }
  594. }
  595. .leader {
  596. .label {
  597. display: flex;
  598. flex-direction: column;
  599. justify-content: center;
  600. }
  601. .block {
  602. top: 19rpx;
  603. left: 174rpx;
  604. }
  605. }
  606. }
  607. </style>