Analysis.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <template>
  2. <div class="page-header-index-wide">
  3. <template v-if="pageRoleNum > 2">
  4. <a-empty :description="false" style="height: 210px;margin-top: 200px;"/>
  5. </template>
  6. <template v-else>
  7. <a-row :gutter="24">
  8. <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px', cursor: 'pointer' }" v-for="(item, index) in zhibiaoTotal" :key="index" @click="clickItemTotal(item, index)">
  9. <chart-card :loading="loading" :title="item.title+'(元) / 当月'" :total="item.monthTotal+''">
  10. <a-tooltip :title="`点击查看${item.title}明细`" slot="action">
  11. <a-icon type="info-circle-o" />
  12. </a-tooltip>
  13. <div>
  14. <trend flag="up" style="margin-right: 16px;">
  15. <span slot="term">月同比</span>
  16. {{(Number(item.monthTb)*100).toFixed(2)}}%
  17. </trend>
  18. <trend flag="down">
  19. <span slot="term">月环比</span>
  20. {{(Number(item.monthHb)*100).toFixed(2)}}%
  21. </trend>
  22. </div>
  23. <template slot="footer">年{{item.title}}<span> {{item.yearTotal}}0</span>
  24. <trend flag="up" style="float: right;">
  25. <span slot="term">同比</span>
  26. {{(Number(item.yearTb)*100).toFixed(2)}}%
  27. </trend>
  28. </template>
  29. </chart-card>
  30. </a-col>
  31. </a-row>
  32. <a-card :loading="loading" :bordered="false" :body-style="{padding: '0'}">
  33. <div class="salesCard">
  34. <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
  35. <div class="extra-wrapper" slot="tabBarExtraContent">
  36. <div class="extra-item">
  37. <a-button :type=searchTypeMonth @click="searchTypeChange('month')">按月查询</a-button>
  38. <a-button :type="searchTypeYear" @click="searchTypeChange('year')">按年查询</a-button>
  39. </div>
  40. <!-- <a-range-picker :style="{width: '256px'}" /> -->
  41. <a-range-picker
  42. :placeholder="searchPlaceholder"
  43. :format="searchFormat"
  44. :mode="searchMode"
  45. :value="dateValue"
  46. @panelChange="handlePanelChange"
  47. @openChange="handleChange"
  48. >
  49. <template slot="renderExtraFooter">
  50. extra footer
  51. </template>
  52. </a-range-picker>
  53. </div>
  54. <a-tab-pane loading="true" :tab="chartTitle+'图表'" key="1">
  55. <a-row>
  56. <a-col :xl="16" :lg="16" :md="16" :sm="24" :xs="24">
  57. <!-- <bar title="销售额排行" :dataSource="barData"/> -->
  58. <twoYAxisChart v-if="chooseValue === 'hte'" :xAxisData="twoYAxisXAxisData" :seriesData="twoYAxisSeriesData" :title="chartTitle"
  59. style="height: 360px;"
  60. class="line-timePrice common-layout"></twoYAxisChart>
  61. <lineBarChart v-else :xAxisData="lineBarXAxisData" :seriesData="lineBarSeriesData" :title="chartTitle"
  62. style="height: 360px;"
  63. class="line-timePrice common-layout"></lineBarChart>
  64. </a-col>
  65. <a-col :xl="8" :lg="8" :md="8" :sm="24" :xs="24">
  66. <rank-list title="详情" :list="rankList"/>
  67. <!-- <pieContentChart style="height: 360px;"></pieContentChart> -->
  68. </a-col>
  69. </a-row>
  70. </a-tab-pane>
  71. <!-- <a-tab-pane tab="销售趋势" key="2">
  72. <a-row>
  73. <a-col :xl="16" :lg="12" :md="12" :sm="24" :xs="24">
  74. <bar title="销售额趋势" :dataSource="barData"/>
  75. </a-col>
  76. <a-col :xl="8" :lg="12" :md="12" :sm="24" :xs="24">
  77. <rank-list title="门店销售排行榜" :list="rankList"/>
  78. </a-col>
  79. </a-row>
  80. </a-tab-pane> -->
  81. </a-tabs>
  82. </div>
  83. </a-card>
  84. <!-- <a-card :loading="loading" :bordered="false" :body-style="{padding: '0'}" :style="{ marginTop: '24px' }">
  85. <div class="salesCard">
  86. <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
  87. <div class="extra-wrapper" slot="tabBarExtraContent">
  88. <div class="extra-item">
  89. <a>本月</a>
  90. <a>本季</a>
  91. <a>本年</a>
  92. </div>
  93. <a-range-picker :style="{width: '256px'}" />
  94. </div>
  95. <a-tab-pane loading="true" :tab="'部门'+chartTitle+'排行'" key="1">
  96. <a-row :gutter="24">
  97. <a-col :xl="6" :lg="12" :md="12" :sm="24" :xs="24">
  98. <rankingChart :title="chartTitle" :seriesData="rankingSeriesData" :yAxisNames="rankingYAxisNames" :yAxisNumbers="yAxisNumbers" style="height: 360px;"></rankingChart>
  99. </a-col>
  100. <a-col :xl="18" :lg="12" :md="12" :sm="24" :xs="24">
  101. <a-table
  102. ref="table"
  103. size="middle"
  104. :scroll="{x:true}"
  105. bordered
  106. rowKey="id"
  107. :columns="columns"
  108. :dataSource="dataSource"
  109. :pagination="ipagination"
  110. :loading="loading"
  111. class="j-table-force-nowrap"
  112. :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
  113. @change="handleTableChange"
  114. >
  115. </a-table>
  116. </a-col>
  117. </a-row>
  118. </a-tab-pane>
  119. </a-tabs>
  120. </div>
  121. </a-card> -->
  122. </template>
  123. </div>
  124. </template>
  125. <script>
  126. import moment from 'moment'
  127. import { getZhibiaoCollect, getdataByHt, getdataBySk, getdataByChb, getdataByLr, } from '@/api/kzksApi'
  128. import ChartCard from '@/components/ChartCard'
  129. import RankList from '@/components/chart/RankList'
  130. import Trend from '@/components/Trend'
  131. import lineBarChart from './components/lineBarChart.vue'
  132. import rankingChart from './components/rankingChart.vue'
  133. import pieContentChart from './components/pieContentChart.vue'
  134. import twoYAxisChart from './components/twoYAxisChart.vue'
  135. import { getLoginfo,getVisitInfo } from '@/api/api'
  136. const rankList = []
  137. for (let i = 0; i < 7; i++) {
  138. rankList.push({
  139. name: '费用 ' + (i+1) + '5%',
  140. total: 1234.56 - i * 100
  141. })
  142. }
  143. export default {
  144. name: "IndexChart",
  145. components: {
  146. ChartCard,
  147. Trend,
  148. RankList,
  149. lineBarChart,
  150. rankingChart,
  151. pieContentChart,
  152. twoYAxisChart,
  153. },
  154. data() {
  155. return {
  156. loading: true,
  157. rankList,
  158. loginfo:{},
  159. visitInfo:[],
  160. pageRoleNum: 0,
  161. // 顶部n项指标
  162. zhibiaoTotal: [
  163. // {
  164. // value: 'hte',
  165. // title: '合同数量',
  166. // totalMoney: '53',
  167. // lineBarSeriesData: [
  168. // {
  169. // name: '合同数量',
  170. // data: [32, 22, 21, 45, 23, 32, 34],
  171. // },
  172. // ],
  173. // },
  174. {
  175. value: 'hte',
  176. hdValue: 'hte',
  177. title: '合同额',
  178. data: {},
  179. },
  180. {
  181. value: 'ske',
  182. hdValue: 'ske',
  183. title: '收款额',
  184. data: {},
  185. },
  186. {
  187. value: 'chb',
  188. hdValue: 'zce',
  189. title: '成本额',
  190. data: {},
  191. },
  192. {
  193. value: 'lre',
  194. hdValue: 'lre',
  195. title: '利润额',
  196. data: {},
  197. },
  198. ],
  199. // 日期区间选择模块
  200. searchPlaceholder: ['开始月份', '结束月份'],
  201. searchTypeMonth: 'primary', // 按月查询按钮
  202. searchTypeYear: 'link', // 按年查询按钮
  203. searchFormat: 'YYYY-MM', // 日期区间选择器format(页面数据显示格式)
  204. dateValue: [null, null], // 日期区间选择器format(页面显示的数据)
  205. searchMode: ['month', 'month'], // 日期区间选择器mode(选择器形式)
  206. // 日期区间选择传参数据
  207. searchParams: {
  208. time: '',
  209. beginDate: null,
  210. endDate: null,
  211. },
  212. // 选择指标
  213. chooseValue: 'hte',
  214. chartTitle: '成本',
  215. // 折线柱形总览图
  216. lineBarXAxisData: [],
  217. lineBarSeriesData: [],
  218. // 排行
  219. rankingSeriesData: [50, 42, 26, 20, 15, 14, 12, 8, 5, 1],
  220. rankingYAxisNames: ["部门06", "部门01", "部门05", "部门10", "部门07", "部门04", "部门03", "部门08", "部门09", "部门02"],
  221. yAxisNumbers: [50, 42, 26, 23, 15, 14, 12, 8, 5, 1],
  222. // 双y轴总览图
  223. twoYAxisXAxisData: [],
  224. twoYAxisSeriesData: [],
  225. // 排行
  226. columns: [
  227. {
  228. title: '序号',
  229. dataIndex: '',
  230. key:'rowIndex',
  231. width:60,
  232. align:"center",
  233. customRender:function (t,r,index) {
  234. return parseInt(index)+1;
  235. }
  236. },
  237. {
  238. title:'部门',
  239. align:"center",
  240. dataIndex: 'wlbm'
  241. },
  242. {
  243. title:'已收款',
  244. align:"center",
  245. dataIndex: 'ggxh'
  246. },
  247. {
  248. title:'成本',
  249. align:"center",
  250. dataIndex: 'zlLevel'
  251. },
  252. {
  253. title:'利润',
  254. align:"center",
  255. dataIndex: 'pici'
  256. },
  257. // {
  258. // title:'利润率',
  259. // align:"center",
  260. // dataIndex: 'pici'
  261. // },
  262. {
  263. title:'合同数量',
  264. align:"center",
  265. dataIndex: 'danjia'
  266. },
  267. {
  268. title:'合同金额',
  269. align:"center",
  270. dataIndex: 'htDate'
  271. },
  272. ],
  273. dataSource: [],
  274. ipagination: {},
  275. }
  276. },
  277. created() {
  278. this.initLogInfo();
  279. this.getZhibiaoCollect()
  280. this.setNowDate()
  281. },
  282. methods: {
  283. getZhibiaoCollect(){
  284. this.loading = true
  285. getZhibiaoCollect().then(res => {
  286. console.log(res)
  287. if (res.success) {
  288. if(res.result.auth >2){
  289. // 0:所领导,1:部门领导,2:员工;3:未赋值或选了多个前面所说角色
  290. // 如果是管理员,默认显示所领导的
  291. this.pageRoleNum = res.result.auth
  292. return
  293. }
  294. var arr = []
  295. for (let i = 0; i < this.zhibiaoTotal.length; i++) {
  296. const element = this.zhibiaoTotal[i];
  297. // element.data = res.result[element.hdValue]
  298. arr[i] = {...element, ...res.result.data[element.hdValue]}
  299. }
  300. this.zhibiaoTotal = arr
  301. this.loading = false
  302. }else{
  303. this.$message.warning(res.message)
  304. this.loading = false
  305. }
  306. }).finally(() => {
  307. this.loading = false
  308. })
  309. },
  310. setNowDate(){
  311. const now = new Date()
  312. const year = now.getFullYear(); // 年
  313. const month = now.getMonth() + 1; // 月
  314. const beginDate = `${year}-01`
  315. const endDate = `${year}-${month}`
  316. this.dateValue = [beginDate, endDate]
  317. this.searchParams = {
  318. time: 'month',
  319. beginDate: beginDate,
  320. endDate: endDate,
  321. }
  322. this.getDataByDate()
  323. },
  324. // 点击指标转换下方数据
  325. clickItemTotal(item, index){
  326. console.log(item, index)
  327. this.chooseValue = item.value
  328. this.chartTitle = item.value === 'hte' ? '合同' : item.title
  329. // this.lineBarSeriesData = item.lineBarSeriesData
  330. console.log(this.dateValue)
  331. this.getDataByDate()
  332. },
  333. // 获取时间变化图表数据
  334. getDataByDate(){
  335. switch (this.chooseValue) {
  336. case 'hte':
  337. getdataByHt(this.searchParams).then(res => {
  338. console.log(res)
  339. if (res.success) {
  340. this.twoYAxisXAxisData = res.result.xaxisData
  341. this.twoYAxisSeriesData = [
  342. {
  343. name: '合同数量',
  344. type: 'line',
  345. data: res.result.contractTotal,
  346. },
  347. {
  348. name: '合同额',
  349. type: 'bar',
  350. barWidth: '30%',
  351. data: res.result.contractAmount,
  352. }
  353. ]
  354. }else{
  355. this.$message.warning(res.message)
  356. }
  357. }).finally(() => {
  358. // this.loading = false
  359. })
  360. break;
  361. case 'lre':
  362. getdataByLr(this.searchParams).then(res => {
  363. console.log(res)
  364. if (res.success) {
  365. this.lineBarXAxisData = res.result.xaxisData
  366. this.lineBarSeriesData = [
  367. {
  368. name: '利润额',
  369. data: res.result.seriesData,
  370. }
  371. ]
  372. }else{
  373. this.$message.warning(res.message)
  374. }
  375. }).finally(() => {
  376. // this.loading = false
  377. })
  378. break;
  379. case 'chb':
  380. getdataByChb(this.searchParams).then(res => {
  381. console.log(res)
  382. if(res){
  383. this.lineBarXAxisData = res[0].xaxisData
  384. this.lineBarSeriesData = [
  385. {
  386. name: '成本额',
  387. data: res[0].seriesData,
  388. }
  389. ]
  390. }
  391. }).finally(() => {
  392. // this.loading = false
  393. })
  394. break;
  395. default:
  396. break;
  397. }
  398. },
  399. // 查询类型选择:按年、按月
  400. searchTypeChange(type){
  401. this.searchTypeMonth = type === 'month' ? 'primary' : 'link'
  402. this.searchTypeYear = type === 'year' ? 'primary' : 'link'
  403. this.searchFormat = type === 'month' ? 'YYYY-MM' : 'YYYY'
  404. this.searchPlaceholder = type === 'month' ? ['开始月份', '结束月份'] : ['开始年份', '结束年份']
  405. this.searchMode = [type, type]
  406. },
  407. handlePanelChange(value, mode) {
  408. // console.log(value, this.searchMode)
  409. // console.log(moment(value[0]).format('YYYY-MM'))
  410. this.dateValue = value;
  411. if(this.searchMode[0] === 'month'){
  412. this.searchParams = {
  413. time: 'month',
  414. beginDate: moment(value[0]).format('YYYY-MM'),
  415. endDate: moment(value[1]).format('YYYY-MM'),
  416. }
  417. }
  418. if(this.searchMode[0] === 'year'){
  419. this.searchParams = {
  420. time: 'year',
  421. beginDate: moment(value[0]).format('YYYY'),
  422. endDate: moment(value[1]).format('YYYY'),
  423. }
  424. }
  425. // this.modeMonth = [mode[0] === 'date' ? 'month' : mode[0], mode[1] === 'date' ? 'month' : mode[1]];
  426. },
  427. handleChange(status){
  428. console.log(status)
  429. },
  430. initLogInfo () {
  431. getLoginfo(null).then((res)=>{
  432. if(res.success){
  433. Object.keys(res.result).forEach(key=>{
  434. res.result[key] =res.result[key]+""
  435. })
  436. this.loginfo = res.result;
  437. }
  438. })
  439. getVisitInfo().then(res=>{
  440. if(res.success){
  441. this.visitInfo = res.result;
  442. }
  443. })
  444. },
  445. }
  446. }
  447. </script>
  448. <style lang="less" scoped>
  449. .circle-cust{
  450. position: relative;
  451. top: 28px;
  452. left: -100%;
  453. }
  454. .extra-wrapper {
  455. line-height: 55px;
  456. padding-right: 24px;
  457. .extra-item {
  458. display: inline-block;
  459. margin-right: 24px;
  460. a {
  461. margin-left: 24px;
  462. }
  463. }
  464. }
  465. /* 首页访问量统计 */
  466. .head-info {
  467. position: relative;
  468. text-align: left;
  469. padding: 0 32px 0 0;
  470. min-width: 125px;
  471. &.center {
  472. text-align: center;
  473. padding: 0 32px;
  474. }
  475. span {
  476. color: rgba(0, 0, 0, .45);
  477. display: inline-block;
  478. font-size: .95rem;
  479. line-height: 42px;
  480. margin-bottom: 4px;
  481. }
  482. p {
  483. line-height: 42px;
  484. margin: 0;
  485. a {
  486. font-weight: 600;
  487. font-size: 1rem;
  488. }
  489. }
  490. }
  491. </style>