storageInfoAnalysis.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="content">
  3. <view class="chart-top">
  4. <view class="chart-top-item left">
  5. <view class="title">按粮食品种展示</view>
  6. <qiun-data-charts type="mount" :opts="opts" :chart-data="chartData1" class="chart-line"
  7. @getIndex="onTap"></qiun-data-charts>
  8. </view>
  9. <view class="chart-top-item right">
  10. <view class="title">按粮食性质展示</view>
  11. <qiun-data-charts type="mount" :opts="opts" :chart-data="chartData2"
  12. class="chart-line" @getIndex="gotoList"></qiun-data-charts>
  13. </view>
  14. </view>
  15. <view class="chart-bottom">
  16. <view class="chart-bottom-item">
  17. <view class="title">按生产年度展示</view>
  18. <view class="bar">
  19. <uni-data-select
  20. v-model="pzValue"
  21. :localdata="[
  22. { value: '小麦', text: '小麦'},
  23. { value: '青稞', text: '青稞'},
  24. { value: '稻谷', text: '稻谷'},
  25. ]"
  26. :clear="false"
  27. @change="change"
  28. class="pz-select"
  29. ></uni-data-select>
  30. <view class="unit">单位: 吨</view>
  31. </view>
  32. <qiun-data-charts type="area" :opts="opts2" :chart-data="chartData3" class="chart-line"></qiun-data-charts>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. getReserveChartDatas
  40. } from '@/api/storageInfoAnalysis';
  41. export default {
  42. data() {
  43. return {
  44. chartData3: {},
  45. chartData1: {},
  46. chartData2: {},
  47. pzValue: '小麦',
  48. opts: {
  49. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  50. "#ea7ccc"
  51. ],
  52. padding: [15, 15, 0, 5],
  53. enableScroll: false,
  54. legend: {},
  55. xAxis: {
  56. disableGrid: true,
  57. rotateLabel: false,
  58. rotateAngle: 45,
  59. },
  60. yAxis: {
  61. data: [{
  62. min: 0
  63. }]
  64. },
  65. extra: {
  66. mount: {
  67. type: "bar",
  68. widthRatio: 0.8,
  69. }
  70. }
  71. },
  72. opts2: {
  73. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  74. "#ea7ccc"
  75. ],
  76. padding: [15, 15, 0, 15],
  77. enableScroll: false,
  78. legend: {},
  79. xAxis: {
  80. disableGrid: true
  81. },
  82. yAxis: {
  83. gridType: "dash",
  84. dashLength: 2
  85. },
  86. extra: {
  87. area: {
  88. type: "straight",
  89. opacity: 0.2,
  90. addLine: true,
  91. width: 2,
  92. gradient: false,
  93. activeType: "hollow"
  94. }
  95. }
  96. },
  97. }
  98. },
  99. mounted() {
  100. this.getServerData()
  101. },
  102. methods: {
  103. //图表渲染
  104. getServerData() {
  105. getReserveChartDatas({
  106. type: 1
  107. }).then(resp => {
  108. if (resp.code === 200) {
  109. const data = resp.data.map(d => {
  110. return {
  111. name: d.pzName,
  112. value: d.kcsl,
  113. raw: d,
  114. }
  115. })
  116. this.chartData1 = {
  117. series: [{
  118. data: data,
  119. }, ]
  120. };
  121. }
  122. })
  123. getReserveChartDatas({
  124. type: 2
  125. }).then(resp => {
  126. if (resp.code === 200) {
  127. const data = resp.data.map(d => {
  128. let name = d.hwxzName
  129. if(name && name.length > 6) {
  130. name = `${name.substr(0, 6)}...`
  131. }
  132. return {
  133. name: name ,
  134. value: d.kcsl,
  135. raw: d,
  136. }
  137. })
  138. this.chartData2 = {
  139. series: [{
  140. data: data,
  141. }, ]
  142. };
  143. }
  144. })
  145. this.renderChart3()
  146. },
  147. renderChart3() {
  148. return getReserveChartDatas({
  149. type: 3,
  150. pzName: this.pzValue,
  151. }).then(resp => {
  152. if(resp.code == 200) {
  153. const categories = []
  154. const maps = {}
  155. resp.data.forEach(d => {
  156. if(! categories.includes(d.scnfName)) {
  157. categories.push(d.scnfName)
  158. }
  159. })
  160. const data = []
  161. categories.forEach(d => {
  162. const n = resp.data.find(dd => dd.scnfName === d)?.kcsl || 0
  163. data.push(n)
  164. })
  165. console.log('data', data);
  166. this.chartData3 = {
  167. categories: categories,
  168. series: [{
  169. name: this.pzValue,
  170. data: data,
  171. }, ]
  172. };
  173. }
  174. })
  175. },
  176. onTap() {
  177. console.log('tap', arguments);
  178. uni.navigateTo({
  179. // url: '/pages/storageInfoAnalysis/granaryInfo',
  180. url: '/pages/storageInfoAnalysis/details'
  181. })
  182. },
  183. gotoList() {
  184. uni.navigateTo({
  185. url: '/pages/storageInfoAnalysis/list'
  186. })
  187. },
  188. change(pzName) {
  189. this.renderChart3()
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss">
  195. .content {
  196. padding: 10px;
  197. height: 100vh;
  198. .chart-top {
  199. display: flex;
  200. justify-content: space-around;
  201. height: 40vh;
  202. .chart-top-item {
  203. width: 45%;
  204. }
  205. .chart-line {
  206. width: 100%;
  207. }
  208. }
  209. .chart-bottom {
  210. margin-top: 40px;
  211. .bar {
  212. margin-top: 5px;
  213. margin-bottom: 5px;
  214. display: flex;
  215. justify-content: space-between;
  216. .pz-select {
  217. margin-left: 10px;
  218. max-width: 200px;
  219. }
  220. .unit {
  221. margin-right: 10px;
  222. }
  223. }
  224. }
  225. }
  226. </style>