collectData.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. <template>
  2. <div>
  3. <div class="header_title">数据分析</div>
  4. <div class="collectData">
  5. <!-- 汇总数据的 nav -->
  6. <div class="box">
  7. <div class="box_item" v-for="item in boxList" :key="item.id">
  8. <p>{{item.name}}</p>
  9. <p>{{item.value}}</p>
  10. </div>
  11. </div>
  12. <div class="conditions">
  13. <el-form inline size="mini" label-width="110px">
  14. <el-form-item label="区域选择:" style="width: 310px">
  15. <!-- <el-input v-model="searchForm.registerTime" placeholder=""></el-input> -->
  16. <area-zz :countyCode="330000" @getCityCode="getCityCode" style="width: 200px"></area-zz>
  17. </el-form-item>
  18. <el-form-item style="margin-left: 55px">
  19. <el-button type="primary" @click="selectCity">查询</el-button>
  20. <!-- <el-button plain type="info" @click="resetForm('searchForm')">清空</el-button> -->
  21. </el-form-item>
  22. </el-form>
  23. </div>
  24. <!-- 以下为图表 -->
  25. <div>
  26. <!-- <div class="chartDiv">
  27. <div class="title">
  28. <span>母猪总存栏走势</span>
  29. <div class="right">
  30. <el-date-picker
  31. v-model="timeSelected"
  32. v-show="daySelected === 1"
  33. type="daterange"
  34. range-separator="—"
  35. start-placeholder="开始日期"
  36. end-placeholder="结束日期"
  37. @change="onChange"
  38. value-format="yyyy-MM-dd"
  39. size="mini">
  40. </el-date-picker>
  41. <el-date-picker
  42. v-model="monthSelected"
  43. v-show="daySelected === 2"
  44. type="monthrange"
  45. range-separator="至"
  46. start-placeholder="开始月份"
  47. end-placeholder="结束月份"
  48. @change="onChange"
  49. size="mini"
  50. value-format="yyyy-MM">
  51. </el-date-picker>
  52. <div v-show="daySelected === 3">
  53. <el-date-picker
  54. v-model="startYear"
  55. type="year"
  56. placeholder="选择年"
  57. size="mini"
  58. style="width: 100px;"
  59. value-format="yyyy">
  60. </el-date-picker>
  61. -
  62. <el-date-picker
  63. v-model="endYear"
  64. type="year"
  65. placeholder="选择年"
  66. size="mini"
  67. @change="onChange"
  68. style="width: 100px;"
  69. value-format="yyyy">
  70. </el-date-picker>
  71. </div>
  72. </div>
  73. <div class="right">
  74. <span :class="{'scopeEle': true, 'ifScoped': daySelected === 1, 'borderLeft': true}" @click="scopeDay(1)">日</span>
  75. <span :class="{'scopeEle': true, 'ifScoped': daySelected === 2}" @click="scopeDay(2)">月</span>
  76. <span :class="{'scopeEle': true, 'ifScoped': daySelected === 3, 'borderRight': true}" @click="scopeDay(3)">年</span>
  77. </div>
  78. </div>
  79. <line-chart :lineList="lineList"></line-chart>
  80. </div> -->
  81. <div class="chartDiv">
  82. <div class="title">
  83. <span>各{{ range }}母猪存栏比较</span>
  84. </div>
  85. <div>
  86. <his-chart :hisList="hisList"></his-chart>
  87. </div>
  88. </div>
  89. <div class="chartDiv">
  90. <div class="title">
  91. <span>牧场排名</span>
  92. </div>
  93. <!-- 查询 -->
  94. <!-- <div class="form_item">
  95. <el-form :inline="true" size="mini">
  96. <el-form-item label="母猪存栏:" style="width: 270px">
  97. <el-input style="width: 50px;" v-model="searchForm.pigAllMin"></el-input>
  98. &nbsp;至&nbsp;
  99. <el-input style="width: 50px;" v-model="searchForm.pigAllMax"></el-input>
  100. </el-form-item>
  101. <el-form-item label="母猪新增:" style="width: 270px">
  102. <el-input style="width: 50px;" v-model="searchForm.pigAddMin"></el-input>
  103. &nbsp;至&nbsp;
  104. <el-input style="width: 50px;" v-model="searchForm.pigAddMax"></el-input>
  105. </el-form-item>
  106. <el-form-item label="耳标离线:" style="width: 270px">
  107. <el-input style="width: 50px;" v-model="searchForm.eartagMin"></el-input>
  108. &nbsp;至&nbsp;
  109. <el-input style="width: 50px;" v-model="searchForm.eartagMax"></el-input>
  110. </el-form-item>
  111. <el-form-item label="能繁母猪:" style="width: 270px">
  112. <el-input style="width: 50px;" v-model="searchForm.bearPigMin"></el-input>
  113. &nbsp;至&nbsp;
  114. <el-input style="width: 50px;" v-model="searchForm.bearPigMax"></el-input>
  115. </el-form-item>
  116. <el-form-item>
  117. <el-button type="primary" @click="search">查询</el-button>
  118. </el-form-item>
  119. </el-form>
  120. </div> -->
  121. <div class="box_table">
  122. <el-table
  123. :data="tableData"
  124. border
  125. stripe
  126. :header-cell-style="{'text-align':'center', 'background-color': '#F9FAFC', 'padding': '5px 0', 'color': '#666666'}"
  127. :cell-style="{'text-align':'center', 'padding': '5px 0'}"
  128. height="700"
  129. row-key="name"
  130. default-expand-all
  131. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  132. style="width: 100%;"
  133. @selection-change="selectFarm"
  134. ref="table"
  135. @row-click="rowClick">
  136. <el-table-column
  137. type="selection"
  138. width="55">
  139. </el-table-column>
  140. <el-table-column
  141. label="牧场名"
  142. prop="farmName">
  143. </el-table-column>
  144. <el-table-column label="母猪存栏">
  145. <el-table-column
  146. label="存栏量"
  147. prop="sowLivestock">
  148. </el-table-column>
  149. <el-table-column
  150. label="省排名"
  151. prop="sowLivestockRank">
  152. </el-table-column>
  153. </el-table-column>
  154. <el-table-column
  155. label="母猪存栏月增长">
  156. <el-table-column
  157. label="存栏月环比增长量"
  158. prop="sowLivestockInc">
  159. </el-table-column>
  160. <el-table-column
  161. label="省排名"
  162. prop="sowLivestockIncRank">
  163. </el-table-column>
  164. </el-table-column>
  165. <el-table-column
  166. label="MSY">
  167. <el-table-column
  168. label="MSY"
  169. prop="sowMsy">
  170. </el-table-column>
  171. <el-table-column
  172. label="省排名"
  173. prop="sowMsyRank">
  174. </el-table-column>
  175. </el-table-column>
  176. <el-table-column
  177. prop="outStockCount"
  178. label="今年累计出栏量">
  179. </el-table-column>
  180. <el-table-column
  181. prop="outStockExpected"
  182. label="预计年出栏量">
  183. </el-table-column>
  184. <el-table-column
  185. prop="ainOutStock"
  186. label="目标年出栏量">
  187. </el-table-column>
  188. <el-table-column
  189. prop="finishPercent"
  190. label="目标完成度">
  191. </el-table-column>
  192. <el-table-column
  193. label="操作"
  194. width="100">
  195. <template slot-scope="scope">
  196. <el-button @click.stop="handleEdit(scope.row)" type="text" size="small">编辑</el-button>
  197. </template>
  198. </el-table-column>
  199. </el-table>
  200. <table-footer
  201. :totals="totalPages"
  202. :size="pageSize"
  203. @sizeChange="sizeChange"
  204. @pageChange="pageChange">
  205. </table-footer>
  206. <!-- 对比框 -->
  207. <div v-show="constrastShow" class="constrast_box">
  208. <el-card style="height: 100%">
  209. <div class="card_title">
  210. <span>对比框({{constrastNum}}/8)</span>
  211. <i class="el-icon-circle-close card_icon" @click="closeConstrast"></i>
  212. </div>
  213. <!-- 被选中的牧场 -->
  214. <div class="card_body">
  215. <ul class="card_ul">
  216. <li
  217. v-for="item in cardFarms"
  218. :key="item.id">
  219. {{ item.farmName }}
  220. </li>
  221. </ul>
  222. </div>
  223. <div class="card_footer">
  224. <el-button plain size="small" @click="handleClear">清 空</el-button>
  225. <el-button type="primary" size="small" @click="handleConstrast">对 比</el-button>
  226. </div>
  227. </el-card>
  228. </div>
  229. </div>
  230. </div>
  231. </div>
  232. <update ref="update" @refreshData="init"></update>
  233. </div>
  234. </div>
  235. </template>
  236. <script>
  237. // import lineChart from './charts/lineChart.vue'
  238. import hisChart from './charts/hisChart.vue'
  239. import areaZz from '../../components/areaZz.vue'
  240. import TableFooter from "../../components/TableFooter"
  241. import update from './update.vue'
  242. import { mapState, mapMutations } from 'vuex';
  243. export default {
  244. name: "collectData",
  245. data () {
  246. return {
  247. range: '市',
  248. areaSelected: '330000',
  249. boxList: [
  250. {
  251. id: 1,
  252. name: '母猪总存栏',
  253. value: 25000,
  254. },
  255. {
  256. id: 2,
  257. name: '母猪目标存栏',
  258. value: 500000
  259. },
  260. {
  261. id: 3,
  262. name: '预计年出栏量',
  263. value: 40000
  264. },
  265. {
  266. id: 4,
  267. name: '目标年出栏量',
  268. value: 800000
  269. }
  270. ],
  271. daySelected: 1, // 年月日选中值,默认月
  272. timeSelected: '', // 时间选择器选中的时间
  273. monthSelected: '', // 月份选择
  274. startYear: '',
  275. endYear: '',
  276. // 母猪总存栏走势
  277. lineList: [],
  278. // 母猪存栏比较
  279. hisList: [],
  280. searchForm: {
  281. pigAllMin: '', // 母猪存栏
  282. pigAllMax: '',
  283. pigAddMin: '', // 母猪新增
  284. pigAddMax: '',
  285. eartagMin: '', // 耳标离线
  286. eartagMax: '',
  287. bearPigMin: '', // 能繁母猪
  288. bearPigMax: ''
  289. },
  290. tableData: [
  291. {
  292. name: '测试牧场'
  293. }
  294. ],
  295. totalPages: 0,
  296. pageNum: 1,
  297. pageSize: 20,
  298. constrastNum: 0, // 对比框中的牧场数量
  299. constrastShow: false, // 对比框是否显示
  300. cardFarms: []
  301. }
  302. },
  303. computed: {
  304. ...mapState(['selected'])
  305. },
  306. components: {
  307. // lineChart,
  308. hisChart,
  309. areaZz,
  310. TableFooter,
  311. update
  312. },
  313. methods: {
  314. ...mapMutations(['updateSelected']),
  315. /* 年月日选择 */
  316. scopeDay (val) {
  317. this.daySelected = val
  318. switch (val) {
  319. case 1: // 日
  320. this.initEchart()
  321. break;
  322. case 2: // 月
  323. this.initEchart()
  324. break;
  325. case 3: // 年
  326. this.initEchart()
  327. break;
  328. default:
  329. break;
  330. }
  331. },
  332. toCollectDay () {
  333. this.$router.push('/collectDay')
  334. },
  335. // 修改size
  336. sizeChange(val) {
  337. this.pageSize = val
  338. this.init()
  339. },
  340. // 修改页数
  341. pageChange(val) {
  342. this.pageNum = val
  343. this.init()
  344. },
  345. // echarts 图的数据
  346. initEchart () {
  347. let data = {}
  348. if(this.daySelected === 1) {
  349. data = {
  350. regionCode: this.areaSelected,
  351. start: this.timeSelected[0] ? this.timeSelected[0]: '',
  352. end: this.timeSelected[1] ? this.timeSelected[1]: '',
  353. type: this.daySelected
  354. }
  355. } else if(this.daySelected === 2) {
  356. data = {
  357. regionCode: this.areaSelected,
  358. start: this.monthSelected[0] ? this.monthSelected[0] : '',
  359. end: this.monthSelected[1] ? this.monthSelected[1] : '',
  360. type: this.daySelected
  361. }
  362. } else {
  363. data = {
  364. regionCode: this.areaSelected,
  365. start: this.startYear ? this.startYear : '',
  366. end: this.endYear ? this.endYear : '',
  367. type: this.daySelected
  368. }
  369. }
  370. this.$http({
  371. url: this.$http.adornUrl(`http://122.112.224.199:9000/dataAnalysis/getPigStockByRegionCode`),
  372. method: 'post',
  373. data: this.$http.adornData(data)
  374. }).then(res => {
  375. if(res.data.code === 0) {
  376. this.lineList = [res.data.dateList, res.data.stockList];
  377. }
  378. })
  379. },
  380. // 牧场排名的查询
  381. search () {
  382. this.init()
  383. },
  384. // 牧场排名 - 表格
  385. init () {
  386. this.$http({
  387. url: this.$http.adornUrl(`http://122.112.224.199:9500/management/sowranktable/list`),
  388. method: 'get',
  389. params: this.$http.adornParams({
  390. 'page': this.pageNum,
  391. 'limit': this.pageSize,
  392. 'maxSowCount': this.searchForm.pigAllMax || undefined,
  393. 'minSowCount': this.searchForm.pigAllMin || undefined,
  394. 'maxSowInc': this.searchForm.pigAddMax || undefined,
  395. 'minSowInc': this.searchForm.pigAddMin || undefined,
  396. })
  397. }).then(({data}) => {
  398. if(data.code === 0) {
  399. this.tableData = data.page.list
  400. this.totalPages = data.page.totalCount
  401. } else {
  402. this.hisList = [];
  403. }
  404. })
  405. // 放一下上面的母猪总存栏 母猪目标存栏...
  406. this.$http({
  407. url: this.$http.adornUrl(`http://122.112.224.199:9000/management/stockout/findByCode`),
  408. method: 'get'
  409. }).then(({data}) => {
  410. if(data.code === 0) {
  411. this.boxList[0].value = data.data[0].sowTotalStock
  412. this.boxList[1].value = data.data[0].sowPlanStock
  413. this.boxList[2].value = data.data[0].expectOut
  414. this.boxList[3].value = data.data[0].planOut
  415. } else {
  416. // this.hisList = [];
  417. }
  418. })
  419. },
  420. // 点击表格的某一行
  421. rowClick (row) {
  422. this.updateSelected(1);
  423. this.$router.push({
  424. path: '/',
  425. query: {farmCode: row.farmCode, type: 4, isColl: true}
  426. })
  427. },
  428. // 牧场对比
  429. selectFarm (val) {
  430. this.constrastShow = true
  431. this.constrastNum = val.length
  432. this.cardFarms = val
  433. if (this.constrastNum === 0) {
  434. this.constrastShow = false
  435. }
  436. },
  437. // 关闭对比框
  438. closeConstrast () {
  439. this.constrastShow = false
  440. },
  441. // 清空牧场对比
  442. handleClear () {
  443. console.log('清空--------------------');
  444. this.cardFarms = []
  445. this.$refs.table.clearSelection()
  446. },
  447. // 进入 对比页面
  448. handleConstrast () {
  449. this.$router.push({
  450. name: 'collectFarm',
  451. params: {
  452. row: this.cardFarms
  453. }
  454. })
  455. },
  456. // 表格 - 编辑 - 更新数据
  457. handleEdit (row) {
  458. this.$nextTick(() => {
  459. this.$refs.update.init(row)
  460. })
  461. },
  462. // 省市县
  463. getCityCode (val) {
  464. console.log(val);
  465. let len = val.length
  466. this.areaSelected = val[len-1]
  467. const ranges = {
  468. 1: '市',
  469. 2: '县',
  470. 3: '牧场'
  471. }
  472. this.range = ranges[len]
  473. // this.initCom();
  474. },
  475. selectCity () {
  476. this.initCom();
  477. },
  478. onChange() {
  479. if(this.daySelected === 3) {
  480. if(this.startYear > this.endYear) {
  481. this.$message.error('起始年份不能大于终止年份')
  482. this.startYear = '';
  483. this.endYear = '';
  484. return false;
  485. } else {
  486. this.initEchart()
  487. }
  488. } else {
  489. this.initEchart()
  490. }
  491. },
  492. // 存栏比较
  493. initCom() {
  494. let params = {
  495. regionCode: this.areaSelected
  496. }
  497. this.$http({
  498. url: this.$http.adornUrl('http://122.112.224.199:9000/dataAnalysis/childPigStock'),
  499. method: 'get',
  500. params: this.$http.adornParams(params)
  501. })
  502. .then(res => {
  503. if(res.data.code === 0) {
  504. this.hisList = [res.data.regionList, res.data.regionStockList];
  505. } else {
  506. this.hisList = [];
  507. }
  508. })
  509. },
  510. // // 跳转
  511. // onSelect() {
  512. // this.updateSelected(1);
  513. // this.$router.push({
  514. // path: '/',
  515. // query: {farmCode: 'N0003', type: 4}
  516. // })
  517. // }
  518. },
  519. mounted() {
  520. this.initEchart();
  521. this.initCom();
  522. this.init()
  523. },
  524. }
  525. </script>
  526. <style scoped>
  527. .header_title {
  528. height: 40px;
  529. background-color: #F7F7F7;
  530. border: 1px solid #ddd;
  531. line-height: 40px;
  532. color: #6FA8C8;
  533. margin-bottom: 10px;
  534. padding-left: 20px;
  535. position: fixed;
  536. width: 1660px;
  537. z-index: 1000;
  538. }
  539. .box {
  540. width: 100%;
  541. height: 140px;
  542. background-color: #F9F9F9;
  543. display: flex;
  544. justify-content: space-around;
  545. align-items: center;
  546. /* margin-right: 10px; */
  547. }
  548. /* 汇总数据块的顶栏 */
  549. .box_item {
  550. width: 198px;
  551. height: 78px;
  552. border: 1px solid #ddd;
  553. text-align: center;
  554. }
  555. .box_item p {
  556. height: 39px;
  557. line-height: 39px;
  558. margin: 0;
  559. }
  560. /* 图表结构的大局 */
  561. .chartDiv {
  562. /* margin: 10px; */
  563. margin-top: 20px;
  564. margin-left: 0;
  565. border: 1px solid #ddd;
  566. background-color: #fff;
  567. }
  568. .title {
  569. background-color: rgba(243, 243, 243, 1);
  570. height: 50px;
  571. line-height: 50px;
  572. padding-left: 50px;
  573. font-size: 14px;
  574. border-bottom: 1px solid #ddd;
  575. }
  576. .right {
  577. float: right;
  578. margin-right: 20px;
  579. font-size: 12px;
  580. }
  581. /** 年月日选择 */
  582. .scopeEle {
  583. display: inline-block;
  584. border: 1px solid #ccc;
  585. width: 75px;
  586. text-align: center;
  587. height: 26px;
  588. line-height: 26px;
  589. margin-left: -1px;
  590. cursor: pointer;
  591. background-color: #fff;
  592. }
  593. .borderLeft {
  594. border-radius: 5px 0 0 5px;
  595. }
  596. .borderRight {
  597. border-radius: 0 5px 5px 0 ;
  598. }
  599. /* 如果选中了 */
  600. .ifScoped {
  601. background-color: #1abc9c;
  602. color: #fff;
  603. border: 1px solid #1abc9c;
  604. }
  605. .form_item {
  606. width: 100%;
  607. height: 60px;
  608. background-color: #fff;
  609. border-top: 1px solid #ddd;
  610. border-bottom: 1px solid #ddd;
  611. box-sizing: border-box;
  612. padding: 15px;
  613. margin-top: 15px;
  614. }
  615. .box_table {
  616. width: 100%;
  617. box-sizing: border-box;
  618. margin-top: 15px;
  619. padding-right: 10px;
  620. position: relative;
  621. /*padding: 10px;*/
  622. }
  623. /** 对比框 */
  624. .constrast_box {
  625. width: 220px;
  626. height: 340px;
  627. position: absolute;
  628. right: 50px;
  629. top: 10%;
  630. background-color: #fff;
  631. }
  632. /* 去除 el-card 自带的 padding */
  633. /deep/ .el-card__body {
  634. padding: 0;
  635. }
  636. /* 对比框的 title */
  637. .card_title {
  638. font-weight: 700;
  639. font-size: 17px;
  640. display: flex;
  641. flex-direction: row;
  642. justify-content: space-between;
  643. background-color: #eee;
  644. padding: 15px 20px;
  645. border-bottom: 1px solid #ddd;
  646. }
  647. .card_icon {
  648. cursor: pointer;
  649. }
  650. /* 对比框的 body */
  651. .card_body {
  652. border-bottom: 1px solid #ddd;
  653. height: 200px;
  654. }
  655. .card_ul {
  656. text-decoration: none;
  657. list-style: none;
  658. padding-left: 30px;
  659. }
  660. .card_ul li {
  661. margin-top: 5px;
  662. font-size: 14px;
  663. }
  664. /* 对比框的底部按钮 */
  665. .card_footer {
  666. display: flex;
  667. flex-direction: row;
  668. justify-content: space-around;
  669. padding: 15px 20px;
  670. }
  671. /** 选择条件 */
  672. .conditions {
  673. /* width: 100%; */
  674. background-color: #fff;
  675. margin: 30px 0;
  676. border: 1px solid #ddd;
  677. padding: 20px;
  678. padding-bottom: 10px;
  679. }
  680. .collectData {
  681. padding-top: 40px;
  682. }
  683. </style>