EntrustNumber.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div class="entrustNumber" >
  3. <!-- 委托样品情况 -->
  4. <dv-border-box-7 backgroundColor="rgba(6, 30, 93, 0.5)" >
  5. <div class="entrustNumber_title">
  6. <span class="demonstration">委托样品情况</span>
  7. <el-date-picker
  8. class="chooseMonth"
  9. v-model="NowTime"
  10. type="month"
  11. @change="changeTime"
  12. format="yyyy-MM"
  13. value-format="yyyy-MM"
  14. placeholder="请选择时间">
  15. </el-date-picker>
  16. </div>
  17. <div class="entrustNumber_content" ref="Number_refs"></div>
  18. </dv-border-box-7>
  19. </div>
  20. </template>
  21. <script>
  22. import curdPost from '@/business/platform/form/utils/custom/joinCURD.js'
  23. import echarts from 'echarts'
  24. import { resolve } from 'path';
  25. export default {
  26. props:{
  27. NowTime1:{
  28. type:String,
  29. default:""
  30. }
  31. },
  32. data(){
  33. return{
  34. NowTime: '',
  35. entrustNumber:null,
  36. //对应月份的每一天的数组
  37. days:[],
  38. //月份天数
  39. day:0,
  40. //填充数量的数组
  41. filledNum:[],
  42. yearA:'',
  43. monthA:'',
  44. monthB:''
  45. // //已收到要填充的数组
  46. // ReceivedNum:[],
  47. // //不合格要填充的数据
  48. // UnqualifiedNum:[],
  49. // //留样要填充的数据
  50. // RetentionNum:[],
  51. // //已收到样品数据
  52. // received:[],
  53. // //不合格样品数据
  54. // unqualifiedData:[],
  55. // //留样样品数据
  56. // retentionData:[],
  57. }
  58. },
  59. watch: {
  60. NowTime1(newValue, oldValue) {
  61. this.days.length=0
  62. this.getNowTime()
  63. }
  64. },
  65. mounted() {
  66. this.getNowTime()
  67. },
  68. methods:{
  69. //样品相关数据时间控件 :页面进来显示当前时间
  70. getNowTime(){
  71. // const nowDate = new Date();
  72. // const date = {
  73. // year: nowDate.getFullYear(),
  74. // month: nowDate.getMonth() + 1,
  75. // }
  76. this.yearA = ''
  77. this.monthA = ''
  78. this.yearA = this.NowTime1.split('-')[0]
  79. this.monthA = this.NowTime1.split('-')[1]
  80. this.monthB = Number(this.NowTime1.split('-')[1])>=10? Number(this.NowTime1.split('-')[1])+"":"0"+Number(this.NowTime1.split('-')[1])
  81. this.NowTime = this.yearA + '-' + this.monthB
  82. // console.log('页面第一次进来显示时间',date.year,date.month)
  83. //进来获取当前时间 之后获取当前月份天数 传给
  84. // console.log('页面显示的时间',this.NowTime) //2022-11
  85. //把页面第一次进来的 当前年度月份 传给该方法处理 得到day及days
  86. this.getDaysInMonth(this.yearA,this.monthA)
  87. },
  88. //手动操作时间控件改变时间
  89. changeTime(e){
  90. // console.log('改变时间',e) //2022-07
  91. let year = e.slice(0,4)
  92. let month = e.slice(5,7)
  93. this.NowTime = year + '-' + month
  94. // console.log('用户操作之后 页面显示的时间',this.NowTime,year,month) //2022-11 2022 11
  95. //把年度月份传给getDaysInMonth()之前,先清理上一次数据
  96. // this.entrustNumber.diswpose() //这个方法干嘛的?? 为啥清不掉entrustNumberInit()方法的数据
  97. this.days=[]
  98. //在这里打印一下this.days数组
  99. // console.log('用户操作了时间控件之后打印this.days数组',this.days)
  100. //把用户操作时间控件改变的时间 的年度月份 传给该方法处理 得到day及days
  101. this.getDaysInMonth(year,month)
  102. },
  103. //拿到当前年度 月份 获取当前月份的天数day及【天数数组】days
  104. getDaysInMonth(year,month){
  105. let temp = new Date(year,month,0);
  106. this.day = temp.getDate();
  107. // console.log('处理好的年 月 月份天数',year,month,this.day); //2022 11 30
  108. //把月份对应天数转化为数组
  109. for( let i=1;i <= this.day ;i++){
  110. this.days.push(i)
  111. }
  112. // console.log('月份每一天',this.days)
  113. this.getdemandData(this.day)
  114. },
  115. getdemandData(dayNum){
  116. // console.log('返回的全部数据 传日期到sql查询',this.NowTime,dayNum)
  117. //SELECT shou_yang_ri_qi_ FROM t_mjypdjb WHERE yan_shou_zhuang_t = '残缺' AND shou_yang_ri_qi_ LIKE '2022-11%' //不合格
  118. //SELECT liu_yang_ri_qi_,liu_yang_shu_lian FROM (SELECT * FROM t_mjypdjb WHERE liu_yang_ri_qi_ ='' ) a WHERE a.shi_fou_liu_yang_ != '否' AND shou_yang_ri_qi_ LIKE '2022-11%' //留样
  119. let sql1 = "select shou_yang_ri_qi_,shou_yang_shu_lia FROM t_mjypdjb WHERE shou_yang_ri_qi_ LIKE '"+this.NowTime+'%'+"'"
  120. let sql2 ="select shou_yang_ri_qi_,shou_yang_shu_lia FROM t_mjypdjb WHERE yan_shou_zhuang_t = '残缺' AND shou_yang_ri_qi_ LIKE '"+this.NowTime+'%'+"'"
  121. let sql3 = "select liu_yang_ri_qi_,liu_yang_shu_lian FROM (SELECT * FROM t_mjypdjb) a WHERE a.shi_fou_liu_yang_ != '否' AND shou_yang_ri_qi_ LIKE '"+this.NowTime+'%'+"'"
  122. Promise.all([
  123. curdPost('sql', sql1),
  124. curdPost('sql', sql2),
  125. curdPost('sql', sql3),
  126. ]).then(([ res1, res2, res3]) => {
  127. let data1 = res1.variables.data
  128. let data2 = res2.variables.data
  129. let data3 = res3.variables.data
  130. // console.log('返回的全部数据',data1,data2)
  131. // console.log('返回的全部数据',data1,data2,data3)
  132. let receivedData = this.dealingData(data1,dayNum)
  133. let unqualifiedData = this.dealingData(data2,dayNum)
  134. let retentionData = this.dealingRetentionData(data3,dayNum)
  135. // console.log('xxxxxxxxx方法返回的数据1 -------',receivedData)
  136. // console.log('xxxxxxxxx方法返回的数据2 -------',unqualifiedData)
  137. // console.log('xxxxxxxxx方法返回的数据3 -------',retentionData)
  138. //三组数据处理完毕之后,传给图表进行渲染 (月份天数数组,已收样,不合格,留样)
  139. this.entrustNumberInit(this.days,receivedData,unqualifiedData,retentionData)
  140. })
  141. },
  142. //处理sql查询出来的数据
  143. // dealingData(data,dayNum){
  144. // return data
  145. // },
  146. dealingData(data,dayNum){
  147. let newArray = data.reduce((total, cur, index) => {
  148. let hasValue = total.findIndex(current => {
  149. return current.shou_yang_ri_qi_ === cur.shou_yang_ri_qi_;
  150. });
  151. hasValue === -1 && total.push(cur);
  152. hasValue !== -1 && (total[hasValue].shou_yang_shu_lia = Number(total[hasValue].shou_yang_shu_lia) + Number(cur.shou_yang_shu_lia));
  153. return total;
  154. }, []);
  155. //console.log('日期相同数量相加 处理结果',newArray);
  156. //创建一个长度为当前月份天数的数组
  157. this.filledNum = Array(dayNum).fill(0)
  158. //遍历拿到的数组,截取出月份对应的 // 2022-11-01
  159. newArray.forEach(item =>{
  160. let key = item.shou_yang_ri_qi_.slice(8,10) < 10 ?item.shou_yang_ri_qi_.slice(9,10) :item.shou_yang_ri_qi_.slice(8,10)
  161. let value =Number(item.shou_yang_shu_lia)
  162. this.filledNum.splice(key - 1,1,value)
  163. })
  164. //返回处理好的数量数组
  165. return this.filledNum;
  166. },
  167. //处理留样数据
  168. dealingRetentionData(data,dayNum){
  169. let newArray = data.reduce((total, cur, index) => {
  170. let hasValue = total.findIndex(current => {
  171. return current.liu_yang_ri_qi_ === cur.liu_yang_ri_qi_;
  172. });
  173. hasValue === -1 && total.push(cur);
  174. hasValue !== -1 && (total[hasValue].liu_yang_shu_lian = Number(total[hasValue].liu_yang_shu_lian) + Number(cur.liu_yang_shu_lian));
  175. return total;
  176. }, []);
  177. //console.log('日期相同数量相加 处理结果',newArray);
  178. //创建一个长度为当前月份天数的数组
  179. this.filledNum = Array(dayNum).fill(0)
  180. //遍历拿到的数组,截取出月份对应的 // 2022-11-01
  181. newArray.forEach(item =>{
  182. let key = item.liu_yang_ri_qi_.slice(8,10) < 10 ?item.liu_yang_ri_qi_.slice(9,10) :item.liu_yang_ri_qi_.slice(8,10)
  183. let value =Number(item.liu_yang_shu_lian)
  184. this.filledNum.splice(key - 1,1,value)
  185. })
  186. //返回处理好的数量数组
  187. return this.filledNum;
  188. },
  189. //委托样品图表
  190. entrustNumberInit(dayArray,receivedData,unqualifiedData,retentionData){
  191. // console.log('拿到日期数组',dayArray)
  192. this.entrustNumber = this.$echarts.init(this.$refs.Number_refs);
  193. var entrustNumberOption = {
  194. xAxis:{
  195. type: "category",
  196. //当前月的每一天 数组
  197. data: dayArray,
  198. splitLine:{
  199. show:false
  200. },
  201. axisLine: {
  202. lineStyle: {
  203. type: 'solid',
  204. color: 'white',//坐标线的颜色
  205. }
  206. },
  207. axisLabel: {
  208. style: {
  209. fill: '#fff'
  210. }
  211. },
  212. },
  213. yAxis: {
  214. type: "value",
  215. name:'数量',
  216. axisLine: {
  217. lineStyle: {
  218. type: 'solid',
  219. color: 'white',//坐标线的颜色
  220. }
  221. },
  222. splitLine: {
  223. show: false
  224. },
  225. },
  226. grid:{
  227. left:'2%',
  228. right:"5%",
  229. top:'15%',
  230. bottom:'2%',
  231. containLabel:true
  232. },
  233. // tooltip悬浮提示框
  234. tooltip:{
  235. show:true
  236. },
  237. //图例的位置
  238. legend: {
  239. show:true,
  240. orient: 'horizontal', //horizontal 水平排列
  241. top:'0',
  242. left:'center',
  243. lineStyle:{},
  244. textStyle: {
  245. color: '#fff',
  246. },
  247. },
  248. //隐藏刻度线
  249. axisTick:{
  250. show:false,
  251. },
  252. series: [
  253. {
  254. type:"bar",
  255. name:'已收到样品',
  256. //显示数字的颜色
  257. label: {
  258. show: true,
  259. position: 'top',
  260. color:'#fff'
  261. },
  262. //柱子的颜色
  263. itemStyle:{
  264. show:true,
  265. color:'rgba(0, 186, 255, 0.4)',
  266. },
  267. data:receivedData
  268. },
  269. {
  270. type: 'line',
  271. name:'不合格样品',
  272. label: {
  273. show: true,
  274. position: 'top',
  275. color:'#f5f12a'
  276. },
  277. //柱子的颜色
  278. itemStyle:{
  279. show:true,
  280. color:'rgba(245, 241, 42, 0.4)',
  281. },
  282. data:unqualifiedData
  283. },
  284. {
  285. type: 'line',
  286. name:'留样样品',
  287. label: {
  288. show: true,
  289. position: 'top',
  290. color:'#f52aa0'
  291. },
  292. //柱子的颜色
  293. itemStyle:{
  294. show:true,
  295. color:'rgba(245, 41, 160,0.4)',
  296. },
  297. data:retentionData
  298. },
  299. ],
  300. }
  301. this.entrustNumber.setOption(entrustNumberOption)
  302. }
  303. }
  304. }
  305. </script>
  306. <style lang="less" scoped>
  307. * body{
  308. padding: 0px;
  309. margin: 0px;
  310. border: 0;
  311. }
  312. .entrustNumber{
  313. width: 100%;
  314. height: 100%;
  315. #dv-border-box-7{
  316. background-size: 100% 100%;
  317. border: 2px solid rgb(3, 59, 31);
  318. display: flex;
  319. flex-direction:column;
  320. align-content:space-between;
  321. }
  322. .entrustNumber_title{
  323. width: 100%;
  324. height: 50px;
  325. position: relative;
  326. // border: 2px solid rgb(245, 41, 160);
  327. .demonstration{
  328. line-height: 50px;
  329. position: absolute;
  330. left: 50%;
  331. top: 50%;
  332. margin-left: -50px;
  333. margin-top: -25px;
  334. color: '#fff';
  335. font-size:20px;
  336. font-weight:600;
  337. }
  338. .chooseMonth{
  339. display: none;
  340. width: 120px;
  341. line-height: 50px;
  342. margin-left: 10px;
  343. }
  344. }
  345. .entrustNumber_content{
  346. width: 100%;
  347. //calc()里面内容需要两边有空格,否则无效
  348. height: calc(100% - 50px);
  349. }
  350. }
  351. </style>