statistics.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="statistics">
  3. <view class="top">
  4. <view class="time">
  5. <view class="text">
  6. 开始时间:
  7. </view>
  8. <uni-datetime-picker type="date" :clear-icon="false"
  9. v-model="BeginSingle" @change='change1' />
  10. </view>
  11. <view class="time">
  12. <view class="text">
  13. 结束时间:
  14. </view>
  15. <uni-datetime-picker type="date" :clear-icon="false"
  16. v-model="FinishSingle" @change='change2' />
  17. </view>
  18. </view>
  19. <view class="bom">
  20. <view class="wu" v-if="wu">
  21. 此段时间暂无数据
  22. </view>
  23. <view class="pie">
  24. <view class="text" @click="unit = !unit">
  25. {{ unit ? '单位: 箱' : '单位: 吨'}}
  26. </view>
  27. <qiun-data-charts type="pie" :opts="opts" :tapLegend='false' :chartData="data" :canvas2d="true" canvasId="kuhCWprwlKvrkiRCafgDvemkjMpuflUb"/>
  28. <view class="legend">
  29. <view class="btn" v-for="(v,i) in chartData" :key="i" :style="{backgroundColor: opts.color[i]}"
  30. @click="$goBack(2,'/pages/statistics/particulars?name='+v.typeName + '&startTime='+BeginSingle+'&endTime=' + FinishSingle + '&id='+name + '&sum=' + v.Num)">
  31. <view class="">
  32. {{v.typeName}}
  33. </view>
  34. <view class="">
  35. {{ unit ? v.Num : v.ton.toFixed(2) }}
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. mapState
  46. } from 'vuex'
  47. import {
  48. statistics
  49. } from '../../api/statistics.js'
  50. export default {
  51. data() {
  52. return {
  53. wu: false,
  54. unit: true,
  55. name: '', // 标题
  56. BeginSingle: '', // 开始时间
  57. FinishSingle: '', // 结束时间
  58. chartData: [],
  59. data: {
  60. series: [{
  61. data: [{}]
  62. }]
  63. },
  64. opts: {
  65. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  66. "#ea7ccc"
  67. ],
  68. dataPointShape: false,
  69. dataLabel: false,
  70. padding: [5, 5, 5, 5],
  71. enableScroll: false,
  72. legend: {
  73. show: false
  74. },
  75. extra: {
  76. pie: {
  77. activeOpacity: 0.5,
  78. activeRadius: 10,
  79. offsetAngle: 0,
  80. labelWidth: 15,
  81. border: false,
  82. borderWidth: 3,
  83. borderColor: "#FFFFFF"
  84. }
  85. }
  86. }
  87. };
  88. },
  89. onLoad(options) {
  90. this.name = options.name
  91. if (this.name) {
  92. uni.setNavigationBarTitle({
  93. title: this.name == 1 ? '产能统计' : '出库统计'
  94. });
  95. }
  96. },
  97. created() {
  98. this.getTime()
  99. },
  100. mounted() {
  101. this.getData()
  102. },
  103. computed: {
  104. ...mapState({
  105. user: store => store.user
  106. })
  107. },
  108. methods: {
  109. change1(e) {
  110. this.BeginSingle = e
  111. this.getData()
  112. },
  113. change2(e) {
  114. this.FinishSingle = e
  115. this.getData()
  116. },
  117. async getData() {
  118. uni.showLoading({
  119. title: '加载中'
  120. });
  121. const res = await statistics({
  122. type: this.name,
  123. startTime: this.BeginSingle, // 开始时间
  124. endTime: this.FinishSingle, // 结束时间
  125. accessToken: this.user.token, // token
  126. account: this.user.account // 用户名
  127. })
  128. uni.hideLoading();
  129. this.chartData = res.data.list
  130. if(this.chartData.length === 0){
  131. this.wu = true
  132. }
  133. this.setdata(res.data.list)
  134. },
  135. //整理数据
  136. setdata(list) {
  137. let that = this
  138. let Data = []
  139. list.forEach(v => {
  140. Data.push({
  141. name: v.typeName,
  142. value: v.Num
  143. })
  144. })
  145. that.data.series = [{
  146. data: Data
  147. }]
  148. },
  149. // 获取时间
  150. getTime() {
  151. let date = new Date();
  152. let year = date.getFullYear();
  153. let month = date.getMonth() + 1;
  154. let month1 = date.getMonth();
  155. let day = date.getDate();
  156. month >= 1 && month <= 9 ? (month = "0" + month) : "";
  157. month1 >= 1 && month1 <= 9 ? (month1 = "0" + month1) : "";
  158. day >= 0 && day <= 9 ? (day = "0" + day) : "";
  159. let timer = year + '-' + month + '-' + day;
  160. let timer1 = year + '-' + month1 + '-' + day;
  161. this.BeginSingle = timer1;
  162. this.FinishSingle = timer
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss">
  168. .statistics {
  169. height: 100%;
  170. .top {
  171. height: 180rpx;
  172. padding: 30rpx;
  173. border-bottom: 1rpx solid #cecece;
  174. .time {
  175. display: flex;
  176. align-items: center;
  177. &:first-child {
  178. margin-bottom: 40rpx;
  179. }
  180. .text {
  181. width: 30%;
  182. }
  183. }
  184. }
  185. .bom {
  186. height: calc(100%-180rpx);
  187. padding: 30rpx;
  188. .wu{
  189. text-align: center;
  190. margin-top: 30rpx;
  191. }
  192. .pie {
  193. height: 50%;
  194. .text {
  195. color: #4f9ce3;
  196. }
  197. .legend {
  198. margin-top: 40rpx;
  199. display: flex;
  200. justify-content: center;
  201. flex-wrap: wrap;
  202. .btn {
  203. padding: 5rpx 30rpx;
  204. text-align: center;
  205. color: #fff;
  206. border-radius: 10rpx;
  207. margin-right: 20rpx;
  208. margin-top: 15rpx;
  209. &:last-child {
  210. margin-right: 0;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. }
  217. </style>