p-i-statistics.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="time">
  5. 2020年11月6日 星期五 10:15:32
  6. </view>
  7. </view>
  8. <view class="content">
  9. <view class="title">
  10. 今日产量
  11. </view>
  12. <view class="inner">
  13. <canvas style="width: 720upx; height:500upx;" canvas-id="canvasRing" id="canvasRing" @touchstart="touchRing"></canvas>
  14. </view>
  15. </view>
  16. <!-- 产量趋势 -->
  17. <view class="content">
  18. <view class="title_box">
  19. <picker mode="selector" :range="array_active" :value="index_active" @change="bindPickerChange_active">
  20. <view class="box">
  21. <view>{{array_active[index_active]}}</view>
  22. <view class="icon">
  23. <uni-icons type="arrowdown"></uni-icons>
  24. </view>
  25. </view>
  26. </picker>
  27. <view v-if="index_active==1">
  28. <picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange" fields="month">
  29. <view class="box">
  30. <view>{{date}}</view>
  31. </view>
  32. </picker>
  33. </view>
  34. <view v-if="index_active==2">
  35. <picker mode="date" :value="date_year" :start="startDate_year" :end="endDate_year" @change="bindDateChange_year" fields="year">
  36. <view class="box">
  37. <view>{{date_year}}</view>
  38. </view>
  39. </picker>
  40. </view>
  41. </view>
  42. <view class="inner">
  43. <view v-if="index_active == 0">
  44. <view class="inner_content">
  45. <canvas style="width: 720upx; height:600upx;" canvas-id="canvasColumnStack" id="canvasColumnStack" class="charts" @touchstart="touchColumn"></canvas>
  46. </view>
  47. </view>
  48. <view v-if="index_active == 1">
  49. <view class="inner_content">
  50. <canvas style="width: 720upx; height:2500upx;" canvas-id="canvasColumnStack_month" id="canvasColumnStack_month" class="charts" @touchstart="touchColumn_month"></canvas>
  51. </view>
  52. </view>
  53. <view v-if="index_active == 2">
  54. <view class="inner_content">
  55. <canvas style="width: 720upx; height:600upx;" canvas-id="canvasColumnStack_year" id="canvasColumnStack_year" class="charts" @touchstart="touchColumn_year"></canvas>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="inner_bottom">
  60. <view class="list">
  61. <view class="item item_title">
  62. <view class="item_box">日期</view>
  63. <view class="item_box">晚班</view>
  64. <view class="item_box">早班</view>
  65. <view class="item_box">中班</view>
  66. <view class="item_box">日产量</view>
  67. </view>
  68. <view class="item">
  69. <view class="item_box">8-22</view>
  70. <view class="item_box">3000吨</view>
  71. <view class="item_box">10000吨</view>
  72. <view class="item_box">21231吨</view>
  73. <view class="item_box">110000吨</view>
  74. </view>
  75. <view class="item">
  76. <view class="item_box">8-22</view>
  77. <view class="item_box">3000吨</view>
  78. <view class="item_box">10000吨</view>
  79. <view class="item_box">21231吨</view>
  80. <view class="item_box">110000吨</view>
  81. </view>
  82. <view class="item">
  83. <view class="item_box">8-22</view>
  84. <view class="item_box">3000吨</view>
  85. <view class="item_box">10000吨</view>
  86. <view class="item_box">21231吨</view>
  87. <view class="item_box">110000吨</view>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. </template>
  94. <script>
  95. import uCharts from '@/components/u-charts/u-charts.js';
  96. var _self;
  97. // 今日产量
  98. var canvaRing = null;
  99. // 周产量
  100. var canvaColumn=null;
  101. // 月产量
  102. var canvaColumn_month=null;
  103. // 年产量
  104. var canvaColumn_year=null;
  105. export default {
  106. data() {
  107. const currentDate = this.getDate({
  108. format: true
  109. })
  110. const currentDate_year = this.getDate_year({
  111. format: true
  112. })
  113. return {
  114. cWidth: '',
  115. cHeight: '',
  116. pixelRatio: 1,
  117. // serverData: '',
  118. // 月
  119. cWidth_month: '',
  120. cHeight_month: '',
  121. pixelRatio_month: 1,
  122. cHeight_month:'',
  123. // 周产量
  124. // 产量趋势
  125. array_active: ['周产量趋势', '月产量趋势','年产量趋势'],
  126. index_active: 1,
  127. // 年 月
  128. date: currentDate,
  129. //
  130. date_year:currentDate_year,
  131. }
  132. },
  133. computed: {
  134. // 月
  135. startDate() {
  136. return this.getDate('start');
  137. },
  138. endDate() {
  139. return this.getDate('end');
  140. },
  141. // 年
  142. startDate_year() {
  143. return this.getDate_year('start');
  144. },
  145. endDate_year() {
  146. return this.getDate_year('end');
  147. }
  148. },
  149. onLoad() {
  150. _self = this;
  151. this.cWidth = uni.upx2px(720);
  152. this.cHeight = uni.upx2px(500);
  153. this.cWidth_month = uni.upx2px(720);
  154. this.cHeight_month = uni.upx2px(2500);
  155. // 今日产量
  156. this.getServerData();
  157. // 周产量
  158. this.getServerData_week();
  159. // 月产量
  160. this.getServerData_month();
  161. // 年产量
  162. this.getServerData_year();
  163. },
  164. methods: {
  165. getServerData() {
  166. let Ring = {
  167. series: [{
  168. "name": "晚班",
  169. "data": 10000
  170. }, {
  171. "name": "中班",
  172. "data": 3000
  173. }, {
  174. "name": "早班",
  175. "data": 1000
  176. }, ]
  177. }
  178. _self.showRing("canvasRing", Ring);
  179. },
  180. showRing(canvasId, chartData) {
  181. canvaRing = new uCharts({
  182. $this: _self,
  183. canvasId: canvasId,
  184. type: 'ring',
  185. fontSize: 11,
  186. // 图裂配置
  187. // legend: true,
  188. legend: {
  189. position: "right",
  190. lineHeight: 30,
  191. },
  192. title: {
  193. name: '今日产量',
  194. color: '#666666',
  195. fontSize: 15 * _self.pixelRatio,
  196. offsetY: 0 * _self.pixelRatio,
  197. },
  198. subtitle: {
  199. name: '14000吨',
  200. color: '#666666',
  201. fontSize: 20 * _self.pixelRatio,
  202. offsetY: 0 * _self.pixelRatio,
  203. },
  204. extra: {
  205. pie: {
  206. offsetAngle: -45,
  207. ringWidth: 30 * _self.pixelRatio,
  208. labelWidth: 20
  209. }
  210. },
  211. background: '#FFFFFF',
  212. pixelRatio: _self.pixelRatio,
  213. series: chartData.series,
  214. animation: true,
  215. width: _self.cWidth * _self.pixelRatio,
  216. height: _self.cHeight * _self.pixelRatio,
  217. disablePieStroke: true,
  218. // 百分比指示 关
  219. dataLabel: false,
  220. });
  221. },
  222. touchRing(e) {
  223. canvaRing.showToolTip(e, {
  224. format: function(item) {
  225. return item.name + ':' + item.data + '吨'
  226. }
  227. });
  228. },
  229. // 产量趋势 选择列表
  230. bindPickerChange_active: function(e) {
  231. console.log('picker发送选择改变,携带值为', e.target.value)
  232. this.index_active = e.target.value
  233. if(this.index_active == 0){
  234. this.getServerData_week()
  235. }else if(this.index_active == 1){
  236. uni.switchTab({
  237. url:"../tabbar/production/production",
  238. animationType:"fade-in",
  239. animationDuration:150
  240. })
  241. uni.navigateTo({
  242. url:"../../p-i-statistics/p-i-statistics",
  243. animationType:"fade-in",
  244. animationDuration:150
  245. })
  246. }else if(this.index_active == 2){
  247. this.getServerData_year()
  248. }
  249. },
  250. // 月
  251. bindDateChange: function(e) {
  252. this.date = e.target.value
  253. console.log(this.date)
  254. this.getServerData_month();
  255. },
  256. getDate(type) {
  257. const date = new Date();
  258. let year = date.getFullYear();
  259. let month = date.getMonth() + 1;
  260. let day = date.getDate();
  261. if (type === 'start') {
  262. year = year - 60;
  263. } else if (type === 'end') {
  264. year = year + 2;
  265. }
  266. month = month > 9 ? month : '0' + month;
  267. return `${year}-${month}`;
  268. },
  269. // 年
  270. bindDateChange_year: function(e) {
  271. this.date_year = e.target.value
  272. console.log(this.date_year)
  273. this.getServerData_year()
  274. },
  275. getDate_year(type) {
  276. const date = new Date();
  277. let year = date.getFullYear();
  278. if (type === 'start') {
  279. year = year - 60;
  280. } else if (type === 'end') {
  281. year = year + 2;
  282. }
  283. return `${year}`;
  284. },
  285. // 周产量
  286. getServerData_week(){
  287. let ColumnStack={
  288. categories:["11-16", "11-17", "11-18", "11-19", "11-20", "11-21"],
  289. series:[
  290. {
  291. "name": "晚班",
  292. "data": [7652.62, 10443.55, 15854.48, 15241.27, 13046.29, 12791.2]
  293. }, {
  294. "name": "早班",
  295. "data": [655.55, 6.05, 363.9, 2207.58, 1916.27, 1796.61]
  296. }, {
  297. "name": "中班",
  298. "data": [14719.67, 14176.65, 10660.04, 12575.22, 12125.56, 13293.5]
  299. }
  300. ],
  301. };
  302. _self.showColumnStack("canvasColumnStack",ColumnStack);
  303. },
  304. showColumnStack(canvasId,chartData){
  305. canvaColumn=new uCharts({
  306. $this:_self,
  307. canvasId: canvasId,
  308. type: 'column',
  309. legend:{show:true},
  310. fontSize:11,
  311. background:'#FFFFFF',
  312. pixelRatio:_self.pixelRatio,
  313. animation: true,
  314. categories: chartData.categories,
  315. legend:{
  316. position:'top',
  317. margin:10,
  318. },
  319. series: chartData.series,
  320. xAxis: {
  321. disableGrid:true,
  322. },
  323. yAxis: {
  324. //disabled:true
  325. },
  326. dataLabel: false,
  327. width: _self.cWidth*_self.pixelRatio,
  328. height: _self.cHeight*_self.pixelRatio,
  329. extra: {
  330. column: {
  331. type:'stack',
  332. width: _self.cWidth*_self.pixelRatio*0.5/chartData.categories.length
  333. }
  334. }
  335. });
  336. },
  337. touchColumn(e){
  338. canvaColumn.showToolTip(e, {
  339. format: function (item, category) {
  340. return category + ' ' + item.name + ':' + item.data
  341. }
  342. });
  343. },
  344. // 月产量
  345. getServerData_month(){
  346. let ColumnStack_month={
  347. categories:["11-01", "11-02", "11-03", "11-04", "11-05","11-06", "11-07","11-08","11-09","11-10","11-11","11-12","11-13", "11-14", "11-15","11-16", "11-17","11-18","11-19","11-20","11-21","11-22","11-23", "11-24", "11-25","11-26", "11-27","11-28","11-29"],
  348. series:[
  349. {
  350. "name": "晚班",
  351. "data": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]
  352. }, {
  353. "name": "早班",
  354. "data": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]
  355. }, {
  356. "name": "中班",
  357. "data": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]
  358. }
  359. ],
  360. };
  361. _self.showColumnStack_month("canvasColumnStack_month",ColumnStack_month);
  362. },
  363. showColumnStack_month(canvasId,chartData){
  364. canvaColumn_month=new uCharts({
  365. $this:_self,
  366. canvasId: canvasId,
  367. type: 'column',
  368. legend:{show:true},
  369. fontSize:11,
  370. background:'#FFFFFF',
  371. pixelRatio:_self.pixelRatio_month,
  372. animation: true,
  373. rotate:true,
  374. categories: chartData.categories,
  375. legend:{
  376. show:false,
  377. position:'top',
  378. margin:10,
  379. },
  380. series: chartData.series,
  381. xAxis: {
  382. disableGrid:true,
  383. },
  384. yAxis: {
  385. //disabled:true
  386. },
  387. dataLabel: false,
  388. width: _self.cWidth_month*_self.pixelRatio_month,
  389. height: _self.cHeight_month*_self.pixelRatio_month,
  390. extra: {
  391. column: {
  392. type:'stack',
  393. width: _self.cWidth_month*_self.pixelRatio_month*0.5/chartData.categories.length
  394. }
  395. }
  396. });
  397. },
  398. touchColumn_month(e){
  399. canvaColumn_month.showToolTip(e, {
  400. format: function (item, category) {
  401. return item.name + ':' + item.data
  402. }
  403. });
  404. },
  405. // 年产量
  406. getServerData_year(){
  407. let ColumnStack_year={
  408. categories:["1", "2", "3", "4", "5","6", "7", "8", "9", "10", "11","12"],
  409. series:[
  410. {
  411. "name": "晚班",
  412. "data": [7652.62, 10443.55, 15854.48, 15241.27, 13046.29, 12791.2,7652.62, 10443.55, 15854.48, 15241.27, 13046.29, 12791.2]
  413. }, {
  414. "name": "早班",
  415. "data": [655.55, 6.05, 363.9, 2207.58, 1916.27, 1796.61,655.55, 6.05, 363.9, 2207.58, 1916.27, 1796.61]
  416. }, {
  417. "name": "中班",
  418. "data": [14719.67, 14176.65, 10660.04, 12575.22, 12125.56, 13293.5,655.55, 6.05, 363.9, 2207.58, 1916.27, 1796.61]
  419. }
  420. ],
  421. };
  422. _self.showColumnStack_year("canvasColumnStack_year",ColumnStack_year);
  423. },
  424. showColumnStack_year(canvasId,chartData){
  425. canvaColumn_year=new uCharts({
  426. $this:_self,
  427. canvasId: canvasId,
  428. type: 'column',
  429. legend:{show:true},
  430. fontSize:11,
  431. background:'#FFFFFF',
  432. pixelRatio:_self.pixelRatio,
  433. animation: true,
  434. categories: chartData.categories,
  435. legend:{
  436. position:'top',
  437. margin:10,
  438. },
  439. series: chartData.series,
  440. xAxis: {
  441. disableGrid:true,
  442. },
  443. yAxis: {
  444. //disabled:true
  445. },
  446. dataLabel: false,
  447. width: _self.cWidth*_self.pixelRatio,
  448. height: _self.cHeight*_self.pixelRatio,
  449. extra: {
  450. column: {
  451. type:'stack',
  452. width: _self.cWidth*_self.pixelRatio*0.5/chartData.categories.length
  453. }
  454. }
  455. });
  456. },
  457. touchColumn_year(e){
  458. canvaColumn_year.showToolTip(e, {
  459. format: function (item, category) {
  460. return item.name + ':' + item.data
  461. }
  462. });
  463. },
  464. }
  465. }
  466. </script>
  467. <style lang="scss">
  468. page{
  469. background-color: #f3f3f3;
  470. padding: 15rpx;
  471. box-sizing: border-box;
  472. }
  473. .content{
  474. margin-top: 16rpx;
  475. background: #FFFFFF;
  476. box-shadow: 0px 3rpx 29rpx 0px rgba(59, 74, 116, 0.14);
  477. border-radius: 20rpx;
  478. .time{
  479. line-height: 94rpx;
  480. padding: 0 20rpx;
  481. box-sizing: border-box;
  482. }
  483. .title{
  484. line-height: 96rpx;
  485. text-align: center;
  486. font-size: 30rpx;
  487. font-family: PingFangSC-Regular, PingFang SC;
  488. font-weight: 400;
  489. color: #232627;
  490. border-bottom: 2rpx solid #f3f3f3;
  491. }
  492. .inner{
  493. min-height: 200rpx;
  494. .inner_content{
  495. margin-top: 20rpx;
  496. }
  497. }
  498. .inner_bottom{
  499. padding-bottom: 20rpx;
  500. .list{
  501. box-sizing: border-box;
  502. padding: 0 10rpx;
  503. .item{
  504. width: 700rpx;
  505. height: 80rpx;
  506. display: flex;
  507. align-items: center;
  508. text-align: center;
  509. border-bottom: 1px solid #f3f3f3;
  510. .item_box{
  511. width: 140rpx;
  512. font-size: 27rpx;
  513. font-family: PingFangSC-Regular, PingFang SC;
  514. font-weight: 400;
  515. color: #232627;
  516. }
  517. }
  518. .item_title{
  519. background: #F3F6FA;
  520. }
  521. }
  522. }
  523. .title_box{
  524. height: 96rpx;
  525. border-bottom: 2rpx solid #f3f3f3;
  526. display: flex;
  527. align-items: center;
  528. .box{
  529. margin-left: 22rpx;
  530. height: 50rpx;
  531. border-radius: 14rpx;
  532. border: 1px solid #BDC3C7;
  533. box-sizing: border-box;
  534. padding: 0 20rpx;
  535. // 文本
  536. font-size: 28rpx;
  537. font-family: PingFangSC-Regular, PingFang SC;
  538. font-weight: 400;
  539. color: #232627;
  540. line-height: 50rpx;
  541. display: flex;
  542. .icon{
  543. margin-left: 10rpx;
  544. }
  545. }
  546. }
  547. }
  548. </style>