EntrustNumber.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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 a.shou_yang_ri_qi_, a.yang_pin_shu_lian FROM (select t_lhypdjb.* from t_lhypdjb LEFT JOIN t_lhwtsqb on t_lhypdjb.wei_tuo_dan_hao_ = t_lhwtsqb.wei_tuo_bian_hao_ where t_lhwtsqb.wei_tuo_lei_xing_ = '客户委托') as a WHERE YEAR(a.shou_yang_ri_qi_)='"+this.yearA+"' and MONTH(a.shou_yang_ri_qi_) = '"+this.monthA+"'"
  120. let sql12 = "select a.shou_yang_ri_qi_, a.yang_pin_shu_lian FROM (select t_lhypdjb.* from t_lhypdjb LEFT JOIN t_lhwtsqb on t_lhypdjb.wei_tuo_dan_hao_ = t_lhwtsqb.wei_tuo_bian_hao_ where t_lhwtsqb.wei_tuo_lei_xing_ != '客户委托') as a WHERE YEAR(a.shou_yang_ri_qi_)='"+this.yearA+"' and MONTH(a.shou_yang_ri_qi_) = '"+this.monthA+"'"
  121. let sql2 ="select shou_yang_ri_qi_,yang_pin_shu_lian FROM t_lhypdjb WHERE yan_shou_jie_guo_ = '残缺' AND shou_yang_ri_qi_ LIKE '"+this.NowTime+'%'+"'"
  122. let sql3 = "select liu_yang_ri_qi_,liu_yang_shu_lian FROM (SELECT * FROM t_lhypdjb ) a WHERE a.shi_fou_liu_yang_ != '否' AND shou_yang_ri_qi_ LIKE '"+this.NowTime+'%'+"'"
  123. Promise.all([
  124. curdPost('sql', sql1),
  125. curdPost('sql', sql12),
  126. curdPost('sql', sql2),
  127. curdPost('sql', sql3),
  128. ]).then(([ res1, res12, res2, res3]) => {
  129. let data1 = res1.variables.data
  130. let data12 = res12.variables.data
  131. let data2 = res2.variables.data
  132. let data3 = res3.variables.data
  133. // console.log('返回的全部数据',data1,data2)
  134. console.log('返回的全部数据',data1,data2,data3)
  135. const receivedData = this.dealingData(data1,dayNum)
  136. const receivedData2 = this.dealingData(data12,dayNum)
  137. const unqualifiedData = this.dealingData(data2,dayNum)
  138. const retentionData = this.dealingRetentionData(data3,dayNum)
  139. console.log('xxxxxxxxx方法返回的数据1 -------',receivedData2,sql1)
  140. // console.log('xxxxxxxxx方法返回的数据2 -------',unqualifiedData)
  141. // console.log('xxxxxxxxx方法返回的数据3 -------',retentionData)
  142. //三组数据处理完毕之后,传给图表进行渲染 (月份天数数组,已收样,不合格,留样)
  143. this.entrustNumberInit(this.days,receivedData,receivedData2,unqualifiedData,retentionData)
  144. })
  145. },
  146. //处理sql查询出来的数据
  147. dealingData(data,dayNum){
  148. console.log(data,'data1')
  149. let newArray = data.reduce((total, cur, index) => {
  150. let hasValue = total.findIndex(current => {
  151. return current.shou_yang_ri_qi_ === cur.shou_yang_ri_qi_;
  152. });
  153. hasValue === -1 && total.push(cur);
  154. hasValue !== -1 && (total[hasValue].yang_pin_shu_lian = Number(total[hasValue].yang_pin_shu_lian) + Number(cur.yang_pin_shu_lian));
  155. return total;
  156. }, []);
  157. //console.log('日期相同数量相加 处理结果',newArray);
  158. //创建一个长度为当前月份天数的数组
  159. this.filledNum = Array(dayNum).fill(0)
  160. //遍历拿到的数组,截取出月份对应的 // 2022-11-01
  161. newArray.forEach(item =>{
  162. 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)
  163. let value =Number(item.yang_pin_shu_lian)
  164. this.filledNum.splice(key - 1,1,value)
  165. })
  166. //返回处理好的数量数组
  167. console.log(this.filledNum,'90900990',data)
  168. return this.filledNum;
  169. },
  170. //处理留样数据
  171. dealingRetentionData(data,dayNum){
  172. let newArray = data.reduce((total, cur, index) => {
  173. let hasValue = total.findIndex(current => {
  174. return current.liu_yang_ri_qi_ === cur.liu_yang_ri_qi_;
  175. });
  176. hasValue === -1 && total.push(cur);
  177. hasValue !== -1 && (total[hasValue].liu_yang_shu_lian = Number(total[hasValue].liu_yang_shu_lian) + Number(cur.liu_yang_shu_lian));
  178. return total;
  179. }, []);
  180. //console.log('日期相同数量相加 处理结果',newArray);
  181. //创建一个长度为当前月份天数的数组
  182. this.filledNum = Array(dayNum).fill(0)
  183. //遍历拿到的数组,截取出月份对应的 // 2022-11-01
  184. newArray.forEach(item =>{
  185. 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)
  186. let value =Number(item.liu_yang_shu_lian)
  187. this.filledNum.splice(key - 1,1,value)
  188. })
  189. //返回处理好的数量数组
  190. return this.filledNum;
  191. },
  192. //委托样品图表
  193. entrustNumberInit(dayArray,receivedData,receivedData2,unqualifiedData,retentionData){
  194. // console.log('拿到日期数组',dayArray)
  195. console.log(receivedData,receivedData2,unqualifiedData,retentionData,'we12e12312312312')
  196. this.entrustNumber = echarts.init(this.$refs.Number_refs);
  197. var entrustNumberOption = {
  198. xAxis:{
  199. type: "category",
  200. //当前月的每一天 数组
  201. data: dayArray,
  202. splitLine:{
  203. show:false
  204. },
  205. axisLine: {
  206. lineStyle: {
  207. type: 'solid',
  208. color: 'white',//坐标线的颜色
  209. }
  210. },
  211. axisLabel: {
  212. style: {
  213. fill: '#fff'
  214. }
  215. },
  216. },
  217. yAxis: {
  218. type: "value",
  219. name:'数量',
  220. axisLine: {
  221. lineStyle: {
  222. type: 'solid',
  223. color: 'white',//坐标线的颜色
  224. }
  225. },
  226. splitLine: {
  227. show: false
  228. },
  229. },
  230. grid:{
  231. left:'2%',
  232. right:"5%",
  233. top:'15%',
  234. bottom:'2%',
  235. containLabel:true
  236. },
  237. // tooltip悬浮提示框
  238. tooltip:{
  239. show:true
  240. },
  241. //图例的位置
  242. legend: {
  243. show:true,
  244. orient: 'horizontal', //horizontal 水平排列
  245. top:'0',
  246. left:'center',
  247. lineStyle:{},
  248. textStyle: {
  249. color: '#fff',
  250. },
  251. },
  252. //隐藏刻度线
  253. axisTick:{
  254. show:false,
  255. },
  256. series: [
  257. {
  258. type:"bar",
  259. name:'客户送检样品数',
  260. //显示数字的颜色
  261. label: {
  262. show: true,
  263. position: 'top',
  264. color:'#fff'
  265. },
  266. //柱子的颜色
  267. itemStyle:{
  268. show:true,
  269. color:'rgba(0, 186, 255, 0.4)',
  270. },
  271. data:receivedData
  272. },
  273. {
  274. type:"bar",
  275. name:'内部送检样品数',
  276. //显示数字的颜色
  277. label: {
  278. show: true,
  279. position: 'top',
  280. color:'#fff'
  281. },
  282. //柱子的颜色
  283. itemStyle:{
  284. show:true,
  285. color:'rgba(255, 255, 51, 0.4)',
  286. },
  287. data:receivedData2
  288. },
  289. {
  290. type: 'line',
  291. name:'不合格样品',
  292. label: {
  293. show: true,
  294. position: 'top',
  295. color:'#f52aa0'
  296. },
  297. //柱子的颜色
  298. itemStyle:{
  299. show:true,
  300. color:'rgba(245, 41, 160,0.4)',
  301. },
  302. data:unqualifiedData
  303. },
  304. {
  305. type: 'line',
  306. name:'留样样品',
  307. label: {
  308. show: true,
  309. position: 'top',
  310. color:'#7FFF00'
  311. },
  312. //柱子的颜色
  313. itemStyle:{
  314. show:true,
  315. color:'rgba(127,255,0,0.4)',
  316. },
  317. data:retentionData
  318. },
  319. ],
  320. }
  321. this.entrustNumber.setOption(entrustNumberOption)
  322. }
  323. }
  324. }
  325. </script>
  326. <style lang="less" scoped>
  327. * body{
  328. padding: 0px;
  329. margin: 0px;
  330. border: 0;
  331. }
  332. .entrustNumber{
  333. width: 100%;
  334. height: 100%;
  335. #dv-border-box-7{
  336. background-size: 100% 100%;
  337. border: 2px solid rgb(3, 59, 31);
  338. display: flex;
  339. flex-direction:column;
  340. align-content:space-between;
  341. }
  342. .entrustNumber_title{
  343. width: 100%;
  344. height: 50px;
  345. position: relative;
  346. // border: 2px solid rgb(245, 41, 160);
  347. .demonstration{
  348. line-height: 50px;
  349. position: absolute;
  350. left: 50%;
  351. top: 50%;
  352. margin-left: -50px;
  353. margin-top: -25px;
  354. color: '#fff';
  355. font-size:20px;
  356. font-weight:600;
  357. }
  358. .chooseMonth{
  359. display: none;
  360. width: 120px;
  361. line-height: 50px;
  362. margin-left: 10px;
  363. }
  364. }
  365. .entrustNumber_content{
  366. width: 100%;
  367. //calc()里面内容需要两边有空格,否则无效
  368. height: calc(100% - 50px);
  369. }
  370. }
  371. </style>