p-production-report-inner-2.vue 15 KB

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