Analysis.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <template>
  2. <div class="analysis">
  3. <!-- 工作看板 -->
  4. <board :title="title[0]">
  5. <div>
  6. <work-infos :dataList="workInfos" @workInfoClick="handleWorkInfoClick"></work-infos>
  7. <div class="table-content">
  8. <table-content
  9. :tableItems="tableItems"
  10. :height="height"
  11. :shows="tableShows"
  12. :listData="tableData">
  13. </table-content>
  14. </div>
  15. </div>
  16. </board>
  17. <!-- 存栏情况 -->
  18. <board :title="title[1]">
  19. <div>
  20. <div>
  21. <!-- 存栏结构 -->
  22. <chart-inventory-pie :data="inventoryPieData"></chart-inventory-pie>
  23. <!-- 存栏变动 -->
  24. <chart-inventory-lines :data="inventoryLinesData"></chart-inventory-lines>
  25. </div>
  26. <div>
  27. <!-- 存栏计数 -->
  28. <inventory-items :data="inventoryItemsData"></inventory-items>
  29. </div>
  30. </div>
  31. </board>
  32. <!-- 生产情况 -->
  33. <board :title="title[2]">
  34. <!-- 环形图 -->
  35. <production-donuts :data="productionPercents"></production-donuts>
  36. <!-- 8个格子 -->
  37. <production-items :data="productionItems"></production-items>
  38. </board>
  39. <!-- 经营分析 -->
  40. <board :title="title[3]">
  41. <!-- 成本分析 -->
  42. <div class="cost">
  43. <div class="select">
  44. <el-select size="small" v-model="costValue">
  45. <el-option
  46. v-for="item in costOptions"
  47. :key="item.value"
  48. :label="item.label"
  49. :value="item.value">
  50. </el-option>
  51. </el-select>
  52. </div>
  53. <div class="cost-content">
  54. <div class="cost-left">
  55. <cost-pie :data="costPieData"></cost-pie>
  56. </div>
  57. <div class="cost-right">
  58. <cost-histogram :data="costHisData"></cost-histogram>
  59. </div>
  60. </div>
  61. <h3 class="label">成本分析</h3>
  62. </div>
  63. <!-- 重要指标 -->
  64. <div class="important">
  65. <div class="condition">
  66. <el-select
  67. size="small"
  68. v-model="importantValue"
  69. style="margin-right: 20px">
  70. <el-option
  71. v-for="item in importantOptions"
  72. :key="item.value"
  73. :label="item.label"
  74. :value="item.value">
  75. </el-option>
  76. </el-select>
  77. <el-date-picker
  78. v-model="importantDates"
  79. size="small"
  80. type="daterange"
  81. range-separator="至"
  82. start-placeholder="开始日期"
  83. end-placeholder="结束日期">
  84. </el-date-picker>
  85. </div>
  86. <div class="important-chart">
  87. <important-line></important-line>
  88. </div>
  89. </div>
  90. <!-- 销售情况 -->
  91. <div class="sales">
  92. <div class="sales-condition">
  93. <!-- <x-form :formItems="salesFormItems" :day="salesDay" @setDay="salesSetDay" @onClickType="salesOnClickType"></x-form> -->
  94. <el-date-picker
  95. v-model="getSalesDates"
  96. type="datetimerange"
  97. :picker-options="pickerOptions"
  98. range-separator="至"
  99. start-placeholder="开始日期"
  100. end-placeholder="结束日期"
  101. align="right"
  102. size="small">
  103. </el-date-picker>
  104. </div>
  105. <div class="sales-content">
  106. <div class="sales-left">
  107. <div class="up">
  108. <label>本周销售额</label>
  109. <span>{{ weekSales }}元</span>
  110. <div class="sales-change">
  111. <div>
  112. <div class="triangle-change" :class="weekSalesChange>0? 'triangle-up': 'triangle-down'"></div>
  113. <span :class="weekSalesChange>0? 'color-up': 'color-down'">{{ weekSalesChange }}%</span>
  114. &nbsp;&nbsp;&nbsp;同比上周
  115. </div>
  116. </div>
  117. </div>
  118. <div class="down">
  119. <label>本周销售量</label>
  120. <span>{{ weekSalesVolume }}元</span>
  121. <div class="sales-change">
  122. <div>
  123. <div class="triangle-change" :class="weekSalesVolumeChange>0? 'triangle-up': 'triangle-down'"></div>
  124. <span :class="weekSalesVolumeChange>0? 'color-up': 'color-down'">{{ weekSalesVolumeChange }}%</span>
  125. &nbsp;&nbsp;&nbsp;同比上周
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. <div class="sales-right">
  131. <sales-chart :data="salesChartData"></sales-chart>
  132. </div>
  133. </div>
  134. </div>
  135. </board>
  136. <!-- 应收排名 -->
  137. <board :title="title[4]">
  138. <table-content
  139. :tableItems="yingshouTableItems"
  140. :height="height"
  141. :shows="yingshouTableShows"
  142. :listData="yingshouTableData">
  143. </table-content>
  144. </board>
  145. <!-- 应付排名 -->
  146. <board :title="title[5]">
  147. <table-content
  148. :tableItems="yingshouTableItems"
  149. :height="height"
  150. :shows="yingshouTableShows"
  151. :listData="yingfuTableData">
  152. </table-content>
  153. </board>
  154. <!-- 安全库存报警 -->
  155. <board :title="title[6]">
  156. <table-content
  157. :tableItems="safetyTableItems"
  158. :height="height"
  159. :shows="safetyTableShows"
  160. :listData="safetyTableData">
  161. </table-content>
  162. <table-footer
  163. :totals="total"
  164. :size="size"
  165. @sizeChange="sizeChange"
  166. @pageChange="pageChange">
  167. </table-footer>
  168. </board>
  169. </div>
  170. </template>
  171. <script>
  172. import Board from 'components/board/index.vue'
  173. import WorkInfos from './analysis/WorkInfos.vue'
  174. import TableContent from 'components/newTable/TableContent.vue'
  175. import ChartInventoryPie from './analysis/ChartInventoryPie.vue'
  176. import ChartInventoryLines from './analysis/ChartInventoryLines.vue'
  177. import InventoryItems from './analysis/InventoryItems.vue'
  178. import ProductionDonuts from './analysis/ProductionDonuts.vue'
  179. import ProductionItems from './analysis/ProductionItems.vue'
  180. import CostPie from './analysis/CostPie.vue'
  181. import CostHistogram from './analysis/CostHistogram.vue'
  182. import ImportantLine from './analysis/ImportantLine.vue'
  183. // import XForm from "components/XForm";
  184. import SalesChart from './analysis/SalesChart.vue'
  185. import TableFooter from "../../components/TableFooter"
  186. import { tableItems, tableShows } from './analysis/table.config'
  187. import { yingshouTableItems, yingshouTableShows } from './analysis/yingshouTable.config'
  188. import { safetyTableItems, safetyTableShows } from './analysis/safetyTable.config'
  189. // import { formItems } from './analysis/salesXForm.config'
  190. import { getInventoryLines, getInventoryAndProduct, getSalesChange, getSalesChart, getCosts, getYingShou, getYingFu } from 'utils/api'
  191. export default {
  192. name: "Analysis",
  193. components: {
  194. Board,
  195. WorkInfos,
  196. TableContent,
  197. ChartInventoryPie,
  198. ChartInventoryLines,
  199. InventoryItems,
  200. ProductionDonuts,
  201. ProductionItems,
  202. CostPie,
  203. CostHistogram,
  204. ImportantLine,
  205. // XForm,
  206. SalesChart,
  207. TableFooter
  208. },
  209. data() {
  210. return {
  211. title: ['工作看板', '存栏情况', '生产情况', '经营分析', '应收排名', '应付排名', '安全库存报警'],
  212. workInfos: [
  213. {
  214. label: '预警信息',
  215. number: 10
  216. },
  217. {
  218. label: '断奶数量',
  219. number: 1150
  220. },
  221. {
  222. label: '配种数量',
  223. number: 1540
  224. },
  225. {
  226. label: '转舍计划',
  227. number: 108
  228. },
  229. {
  230. label: '分娩数量',
  231. number: 180
  232. },
  233. {
  234. label: '日常计划',
  235. number: 10
  236. },
  237. {
  238. label: '天才计划',
  239. number: 10
  240. },
  241. {
  242. label: '保健计划',
  243. number: 10
  244. }
  245. ],
  246. tableItems: [],
  247. tableShows: {},
  248. height: 300,
  249. tableData: [],
  250. // 存栏情况
  251. inventoryLinesData: {}, // 折线图数据
  252. inventoryPieData: [], // 环形图数据
  253. inventoryItemsData: [], // 下面块图的数据
  254. // 生产情况
  255. productionPercents: [], // 百分比
  256. productionItems: [], // 下面块图的数据
  257. // 经营分析
  258. costOptions: [],
  259. costValue: '',
  260. costPieData: [], // 经营分析 - 成本分析环形图
  261. costHisData: [], // 经营分析 - 柱状图
  262. // 重要指标
  263. importantOptions: [],
  264. importantValue: '',
  265. importantDates: [],
  266. // 销售额
  267. // salesFormItems: [],
  268. salesDay: 2, //默认选择本周
  269. weekSales: 1545252,
  270. weekSalesChange: 10,
  271. weekSalesVolume: 1000,
  272. weekSalesVolumeChange: -10,
  273. getSalesDates: [], // 销售图的时间选择
  274. pickerOptions: { // 快捷选项
  275. shortcuts: [{
  276. text: '最近一周',
  277. onClick(picker) {
  278. const end = new Date();
  279. const start = new Date();
  280. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  281. picker.$emit('pick', [start, end]);
  282. }
  283. }, {
  284. text: '最近一个月',
  285. onClick(picker) {
  286. const end = new Date();
  287. const start = new Date();
  288. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  289. picker.$emit('pick', [start, end]);
  290. }
  291. }, {
  292. text: '最近三个月',
  293. onClick(picker) {
  294. const end = new Date();
  295. const start = new Date();
  296. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  297. picker.$emit('pick', [start, end]);
  298. }
  299. }]
  300. },
  301. salesChartData: {}, // 销售图的数据
  302. // 应收排名
  303. yingshouTableItems: [],
  304. yingshouTableShows: {},
  305. yingshouTableData: [],
  306. // 应付排名
  307. yingfuTableData: [],
  308. // 安全库存报警
  309. safetyTableItems: [],
  310. safetyTableShows: {},
  311. safetyTableData: [],
  312. total: 0,
  313. size: 20,
  314. pageNum: 1,
  315. }
  316. },
  317. mounted() {
  318. // this.salesFormItems = formItems
  319. this.tableItems = tableItems
  320. this.tableShows = tableShows
  321. this.yingshouTableItems = yingshouTableItems
  322. this.yingshouTableShows = yingshouTableShows
  323. this.safetyTableItems = safetyTableItems
  324. this.safetyTableShows = safetyTableShows
  325. /** 获取网络请求数据 */
  326. this.initInventoryLines()
  327. this.initInventoryAndProduct()
  328. this.initSalesChange()
  329. this.initSalesChart()
  330. this.initCosts()
  331. this.initYingShou()
  332. this.initYingFu()
  333. },
  334. methods: {
  335. handleWorkInfoClick(item) {
  336. console.log(item)
  337. },
  338. // 修改size
  339. sizeChange(val) {
  340. this.size = val;
  341. this.init();
  342. },
  343. // 修改页数
  344. pageChange(val) {
  345. this.pageNum= val;
  346. this.init();
  347. },
  348. init() {
  349. let params = {
  350. pageNum: this.pageNum,
  351. pageSize: this.size,
  352. searchStr: this.keyword
  353. }
  354. console.log(params)
  355. // 获取后端数据
  356. },
  357. // 销售额选中日期
  358. salesSetDay(data) {
  359. this.salesDay = data;
  360. console.log(this.salesDay)
  361. },
  362. // 销售额选中日周月
  363. salesOnClickType(data) {
  364. console.log(data)
  365. },
  366. // 存栏情况 - 存栏变动折线图数据请求
  367. initInventoryLines() {
  368. getInventoryLines({}).then(res => {
  369. if (res.code === 10000) {
  370. this.inventoryLinesData = res.data
  371. } else {
  372. this.inventoryLinesData = {
  373. boarStock: [],
  374. fatpigStock: [],
  375. griceStock: [],
  376. month: [],
  377. pigletStock: [],
  378. sowStock: []
  379. }
  380. }
  381. })
  382. },
  383. // 存栏情况 + 生产情况
  384. initInventoryAndProduct() {
  385. getInventoryAndProduct({}).then(res => {
  386. if (res.code === 10000) {
  387. // this.inventoryLinesData = res.data
  388. console.log(res.data)
  389. this.inventoryPieData = res.data.slice(0, 6)
  390. this.inventoryItemsData = [res.data[1].stockQuantity, res.data[6].stockQuantity, res.data[7].stockQuantity, res.data[8].stockQuantity, res.data[2].stockQuantity, res.data[9].stockQuantity]
  391. this.productionPercents = [res.data[12].rate*100, res.data[13].rate*100, res.data[14].rate*100, res.data[15].rate*100, res.data[16].rate*100]
  392. this.productionItems = [res.data[17].stockQuantity, res.data[18].stockQuantity, res.data[19].stockQuantity, res.data[20].stockQuantity, res.data[21].stockQuantity, res.data[22].stockQuantity, res.data[23].stockQuantity, res.data[24].stockQuantity]
  393. } else {
  394. // this.inventoryLinesData = {
  395. // boarStock: [],
  396. // fatpigStock: [],
  397. // griceStock: [],
  398. // month: [],
  399. // pigletStock: [],
  400. // sowStock: []
  401. // }
  402. }
  403. })
  404. },
  405. // 经营分析 - 销售改变
  406. initSalesChange() {
  407. getSalesChange({}).then(res => {
  408. if (res.code === 10000) {
  409. this.weekSales = res.data.quantityAll
  410. this.weekSalesChange = res.data.quantityType? res.data.quantityPercentage: -res.data.quantityPercentage
  411. this.weekSalesVolume = res.data.saleAll
  412. this.weekSalesVolumeChange = res.data.saleType? res.data.salePercentage: -res.data.salePercentage
  413. } else {
  414. this.weekSales = 0
  415. this.weekSalesChange = 0
  416. this.weekSalesVolume = 0
  417. this.weekSalesVolumeChange = 0
  418. }
  419. })
  420. },
  421. // 经营分析 - 销售情况图
  422. initSalesChart() {
  423. const params = {
  424. beginDate: this.getSalesDates[0] || '',
  425. endDate: this.getSalesDates[1] || ''
  426. }
  427. console.log('我要放参数了', params)
  428. getSalesChart(params).then(res => {
  429. if (res.code === 10000) {
  430. this.salesChartData = res.data
  431. }
  432. })
  433. },
  434. // 经营分析 - 成本分析
  435. initCosts() {
  436. getCosts({}).then(res => {
  437. if (res.code === 10000) {
  438. this.costPieData = []
  439. res.data.forEach(item => {
  440. this.costPieData.push({
  441. name: item.costName,
  442. value: item.costRate
  443. })
  444. })
  445. this.costHisData = []
  446. res.data.forEach(item => {
  447. this.costHisData.push(item.costVal)
  448. })
  449. }
  450. })
  451. },
  452. // 应收排名
  453. initYingShou() {
  454. getYingShou({}).then(res => {
  455. console.log('应收', res)
  456. if (res.code === 10000) {
  457. this.yingshouTableData = res.data
  458. }
  459. })
  460. },
  461. // 应付排名
  462. initYingFu() {
  463. getYingFu({}).then(res => {
  464. console.log('应付', res)
  465. if (res.code === 10000) {
  466. this.yingfuTableData = res.data
  467. }
  468. })
  469. }
  470. },
  471. watch: {
  472. getSalesDates(newValue) {
  473. this.getSalesDates = newValue
  474. this.initSalesChart()
  475. }
  476. }
  477. }
  478. </script>
  479. <style scoped>
  480. .analysis {
  481. width: 100%;
  482. height: 100%;
  483. box-sizing: border-box;
  484. padding: 20px;
  485. }
  486. .table-content {
  487. padding: 10px 15px 12px;
  488. }
  489. /* 成本分析echarts图排列 */
  490. .cost {
  491. border-bottom: 1px solid rgba(228, 228, 228, 1);
  492. position: relative;
  493. }
  494. .cost>.select {
  495. position: absolute;
  496. right: 0;
  497. margin: 20px;
  498. }
  499. .cost-content {
  500. padding-top: 20px;
  501. display: flex;
  502. }
  503. .cost-left {
  504. flex: 1;
  505. }
  506. .cost-right {
  507. flex: 1;
  508. }
  509. .cost>.label {
  510. text-align: center;
  511. font-weight: bold;
  512. font-size: 18px;
  513. }
  514. /* 重要指标 */
  515. .important {
  516. padding: 20px;
  517. position: relative;
  518. border-bottom: 1px solid rgba(228, 228, 228, 1);
  519. }
  520. .important>.condition {
  521. position: absolute;
  522. right: 0;
  523. margin-right: 20px;
  524. }
  525. .important-chart {
  526. margin-top: 20px;
  527. }
  528. /* 销售情况 */
  529. .sales {
  530. padding: 20px;
  531. padding-bottom: 0;
  532. }
  533. .sales-condition {
  534. margin-left: 250px;
  535. }
  536. .sales-content {
  537. padding-top: 20px;
  538. width: 100%;
  539. display: flex;
  540. flex-direction: row;
  541. justify-content: space-around
  542. }
  543. .sales-left {
  544. width: 15%;
  545. line-height: 25px;
  546. padding-top: 30px;
  547. }
  548. .sales-left>.up {
  549. margin-bottom: 20px;
  550. }
  551. .sales-left>.up>label,
  552. .sales-left>.down>label {
  553. display: block;
  554. text-align: center;
  555. font-size: 13px;
  556. color: #999;
  557. }
  558. .sales-left>.up>span,
  559. .sales-left>.down>span {
  560. display: block;
  561. text-align: center;
  562. font-size: 16px;
  563. color: #333;
  564. }
  565. .sales-left>.up>.sales-change,
  566. .sales-left>.down>.sales-change {
  567. display: flex;
  568. justify-content: space-around;
  569. font-size: 13px;
  570. }
  571. /* 三角形 */
  572. .triangle-change {
  573. display: inline-block;
  574. width: 8px;
  575. height: 8px;
  576. border-style: solid;
  577. border-width: 8px;
  578. margin-right: 20px;
  579. }
  580. .triangle-up {
  581. border-color: transparent transparent rgb(238, 16, 16) transparent;
  582. }
  583. .triangle-down {
  584. border-color: rgb(2, 112, 2) transparent transparent transparent;
  585. position: relative;
  586. top: 7px;
  587. }
  588. .color-up {
  589. color: rgb(238, 16, 16);
  590. }
  591. .color-down {
  592. color: rgb(2, 112, 2);
  593. }
  594. /* 销售情况右侧 */
  595. .sales-right {
  596. width: 85%;
  597. border-left: 1px solid rgba(228, 228, 228, 1);
  598. height: 300px;
  599. }
  600. </style>