maintenanceStatic.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="title"
  5. :visible.sync="dialogVisible"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. :show-close="false"
  9. append-to-body
  10. fullscreen
  11. class="dialog paper-detail-dialog"
  12. top="0"
  13. >
  14. <div slot="title" class="dialog-title">
  15. <span class="dialogtitle">{{ title }}</span>
  16. <div>
  17. <ibps-toolbar :actions="toolbars" @action-event="handleActionEvent" />
  18. </div>
  19. </div>
  20. <div class="container">
  21. <div class="left" :style="{width:initWidth}">
  22. <div class="search">
  23. <div class="item">
  24. <div class="label">维护月份:</div>
  25. <div class="content">
  26. <el-date-picker
  27. v-model="month"
  28. :clearable="false"
  29. type="month"
  30. placeholder="选择查询的月份"
  31. value-format="yyyy-MM"
  32. :picker-options="pickerOptions"
  33. size="mini"
  34. @change="handleMonthChange"
  35. />
  36. </div>
  37. </div>
  38. </div>
  39. <div class="agend">
  40. <div class="descript">
  41. <div class="item">
  42. <div class="green-circle" />
  43. <span>全部完成</span>
  44. </div>
  45. <div class="item">
  46. <div class="orange-circle" />
  47. <span>部分完成</span>
  48. </div>
  49. <div class="item">
  50. <div class="red-circle" />
  51. <span>全部未完成</span>
  52. </div>
  53. <div class="item">
  54. <div class="grey-bg" />
  55. <span>设备未使用</span>
  56. </div>
  57. <div class="item">
  58. <div class="red-bg" />
  59. <span>设备异常</span>
  60. </div>
  61. <div class="item" style="margin-left:60px">
  62. <span>设备异常次数:{{ formatData.repairCount }}</span>
  63. </div>
  64. <div class="item">
  65. <span>设备总维护次数:{{ formatData.maintenanceCount }}</span>
  66. </div>
  67. <div class="item">
  68. <span>设备故障率:{{ formatData.faultRate }} %</span>
  69. <el-tooltip
  70. effect="dark"
  71. content="设备故障率计算公式:异常次数/总维护次数*100%,待处理与未使用不计入总维护次数中。"
  72. placement="top"
  73. >
  74. <i class="el-icon-question question-icon" />
  75. </el-tooltip>
  76. </div>
  77. </div>
  78. <div class="item-time">
  79. <span>统计时间:{{ curTime }}</span>
  80. </div>
  81. </div>
  82. <div class="table">
  83. <div class="column">
  84. <div class="item">保养类型/日期</div>
  85. <div v-for="item in type" :key="item" class="item">{{ item }}</div>
  86. </div>
  87. <div class="column">
  88. <div v-for="(item,index) in formatData.list" :key="index" class="content-item">
  89. <div class="item">{{ index+1 }}</div>
  90. <div
  91. v-for="(i,ind) in item"
  92. :key="ind"
  93. class="item"
  94. :class="{
  95. unusual: i.status === false, // 异常
  96. unused: i.isUsed === false // 未使用
  97. }"
  98. >
  99. <el-tooltip v-show="i.count>0" class="item" effect="light" placement="top-start">
  100. <template slot="content">
  101. <div>
  102. <span v-if="i.todo">待处理:{{ i.todo }};</span>
  103. <span v-if="i.done">已完成:{{ i.done }};</span>
  104. <div v-for="(ii,indd) in i.data" :key="indd" class="detail">
  105. <el-divider />
  106. <div class="detail-item">
  107. <div class="item" style="margin:2px 0">处理人:{{ switchIdToUserName(ii.bian_zhi_ren_)|| '/' }}</div>
  108. <div class="item" style="margin:2px 0">设备状态:{{ ii.wei_hu_zhuang_tai|| '/' }}</div>
  109. <div class="item" style="margin:2px 0">维护项目:{{ ii.wei_hu_xiang_mu_c|| '/' }}</div>
  110. <div class="item" style="margin:2px 0">备注:{{ ii.bei_zhu_|| '/' }}</div>
  111. </div>
  112. </div>
  113. </div>
  114. </template>
  115. <div v-if="i.todo === 0 && i.isUsed" class="green-circle" />
  116. <div v-if="i.done === 0 && i.todo !== 0" class="red-circle" />
  117. <div v-if="i.todo !== 0 && i.done !== 0" class="orange-circle" />
  118. </el-tooltip>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. </el-dialog>
  126. </template>
  127. <script>
  128. import xlsx from 'xlsx'
  129. import fs from 'file-saver'
  130. import dayjs from 'dayjs'
  131. import ibpsUserSelector from '@/business/platform/org/selector'
  132. export default {
  133. components: {
  134. ibpsUserSelector
  135. },
  136. props: {
  137. params: {
  138. type: Object,
  139. default: function () {
  140. return {}
  141. }
  142. },
  143. dialogVisible: {
  144. type: Boolean,
  145. default: false
  146. }
  147. },
  148. data () {
  149. const monthList = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  150. const monthValue = dayjs().format('YYYY-MM')
  151. const year = +monthValue.split('-')[0]
  152. const month = +monthValue.split('-')[1]
  153. const monthDays = monthList[month - 1]
  154. if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) {
  155. monthList[1] = 29
  156. }
  157. const { userId, position, level } = this.$store.getters
  158. return {
  159. curTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  160. pickerOptions: {
  161. disabledDate (time) {
  162. return time.getTime() > Date.now()
  163. }
  164. },
  165. monthList: monthList,
  166. month: monthValue,
  167. monthDays: monthDays,
  168. userId: userId,
  169. position: position,
  170. level: level.second || level.first,
  171. loading: false,
  172. title: '设备维护统计',
  173. toolbars: [
  174. { key: 'export', label: '导出', type: 'primary', hidden: true },
  175. { key: 'cancel', label: '返回', type: 'danger' }
  176. ],
  177. initWidth: '1800px',
  178. isEdit: false,
  179. isFinished: false,
  180. readonly: false,
  181. preParams: {},
  182. Ids: [],
  183. form: {
  184. },
  185. rules: {
  186. },
  187. dataList: [],
  188. type: ['日保养', '周保养', '月保养', '季度保养', '半年保养', '年保养', '按需保养', '间隔保养']
  189. }
  190. },
  191. computed: {
  192. deviceColumns () {
  193. return {
  194. 'leiXing': '保养类型',
  195. 'One': this.month + '-01',
  196. 'Two': this.month + '-02',
  197. 'Three': this.month + '-03',
  198. 'Four': this.month + '-04',
  199. 'Five': this.month + '-05',
  200. 'Six': this.month + '-06',
  201. 'Seven': this.month + '-07',
  202. 'Eight': this.month + '-08',
  203. 'Nine': this.month + '-09',
  204. 'Ten': this.month + '-10',
  205. 'Eleven': this.month + '-11',
  206. 'Twelve': this.month + '-12',
  207. 'Thirteen': this.month + '-13',
  208. 'Fourteen': this.month + '-14',
  209. 'Fifteen': this.month + '-15',
  210. 'Sixteen': this.month + '-16',
  211. 'Seventeen': this.month + '-17',
  212. 'Eighteen': this.month + '-18',
  213. 'Nineteen': this.month + '-19',
  214. 'Twenty': this.month + '-20',
  215. 'Twenty-One': this.month + '-21',
  216. 'Twenty-Two': this.month + '-22',
  217. 'Twenty-Three': this.month + '-23',
  218. 'Twenty-Four': this.month + '-24',
  219. 'Twenty-Five': this.month + '-25',
  220. 'Twenty-Six': this.month + '-26',
  221. 'Twenty-Seven': this.month + '-27',
  222. 'Twenty-Eight': this.month + '-28',
  223. 'Twenty-Nine': this.month + '-29',
  224. 'Thirty': this.month + '-30',
  225. 'Thirty-One': this.month + '-31'
  226. }
  227. },
  228. formatData () {
  229. let repairCount = 0 // 异常
  230. let maintenanceCount = 0 // 维护
  231. const fliterData = this.dataList
  232. const result = []
  233. fliterData.forEach(item => {
  234. const { wei_hu_lei_xing_ } = item
  235. const t = result.find(i => i.wei_hu_lei_xing_ === wei_hu_lei_xing_)
  236. if (t) {
  237. t.children.push(item)
  238. } else {
  239. result.push({
  240. wei_hu_lei_xing_: wei_hu_lei_xing_,
  241. children: [item]
  242. })
  243. }
  244. })
  245. // console.log('fliterData', result)
  246. const answer = new Array(this.monthDays)
  247. for (let i = 0; i < this.monthDays; i++) {
  248. const arr = []
  249. const day = ('0' + (i + 1)).slice(-2)
  250. const fullDay = this.month + '-' + day
  251. // console.log(fullDay)
  252. this.type.forEach(item => {
  253. const obj = {
  254. data: [],
  255. count: 0,
  256. todo: 0,
  257. done: 0,
  258. status: true,
  259. isUsed: true
  260. }
  261. const t = result.find(j => j.wei_hu_lei_xing_ === item)
  262. if (t) {
  263. const tempList = t.children.filter(k => k.ji_hua_shi_jian_ === fullDay)
  264. obj.count = tempList.length
  265. obj.todo = tempList.filter(k => k.shi_fou_guo_shen_ === '待处理').length
  266. const yiwancheng = tempList.filter(k => k.shi_fou_guo_shen_ === '已完成')
  267. obj.done = yiwancheng.length
  268. obj.data = yiwancheng
  269. const weixiu = tempList.filter(item => item.wei_hu_zhuang_tai === '异常')
  270. obj.isUsed = !tempList.some(item => item.wei_hu_zhuang_tai === '未使用')
  271. obj.status = weixiu.length === 0
  272. repairCount += weixiu.length
  273. maintenanceCount += yiwancheng.filter(item => item.wei_hu_zhuang_tai !== '未使用').length
  274. }
  275. arr.push(obj)
  276. })
  277. answer[i] = arr
  278. }
  279. // 故障率
  280. const faultRate = maintenanceCount === 0 ? '0.00' : ((repairCount / maintenanceCount) * 100).toFixed(2)
  281. // console.log('data', answer)
  282. return { list: answer, repairCount, maintenanceCount, faultRate }
  283. }
  284. },
  285. mounted () {
  286. if (this.params.searchMonth) {
  287. this.month = this.params.searchMonth
  288. this.handleMonthChange(this.month)
  289. } else {
  290. this.init()
  291. }
  292. },
  293. methods: {
  294. handleActionEvent ({ key }) {
  295. switch (key) {
  296. case 'cancel':
  297. this.closeDialog()
  298. break
  299. case 'export':
  300. this.handleExport()
  301. break
  302. default:
  303. break
  304. }
  305. },
  306. // 人员id 转人员名称
  307. switchIdToUserName (id) {
  308. const { userList } = this.$store.getters
  309. const temp = userList.find(item => item.userId === id)
  310. return temp ? temp.userName : ''
  311. },
  312. xlsx (json, fields, filename = '.xlsx') { // 导出xlsx
  313. json.forEach(item => {
  314. for (const i in item) {
  315. if (fields.hasOwnProperty(i)) {
  316. item[fields[i]] = item[i]
  317. }
  318. delete item[i] // 删除原先的对象属性
  319. }
  320. })
  321. const sheetName = filename // excel的文件名称
  322. const wb = xlsx.utils.book_new() // 工作簿对象包含一SheetNames数组,以及一个表对象映射表名称到表对象。XLSX.utils.book_new实用函数创建一个新的工作簿对象。
  323. const ws = xlsx.utils.json_to_sheet(json, { header: Object.values(fields) }) // 将JS对象数组转换为工作表。
  324. wb.SheetNames.push(sheetName)
  325. wb.Sheets[sheetName] = ws
  326. // console.log('json', ws)
  327. const defaultCellStyle = { font: { name: 'Verdana', sz: 13, color: 'FF00FF88' }, fill: { fgColor: { rgb: 'FFFFAA00' }}}// 设置表格的样式
  328. const wopts = { bookType: 'xlsx', bookSST: false, type: 'binary', cellStyles: true, defaultCellStyle: defaultCellStyle, showGridLines: false } // 写入的样式
  329. const wbout = xlsx.write(wb, wopts)
  330. const blob = new Blob([this.s2ab(wbout)], { type: 'application/octet-stream' })
  331. fs.saveAs(blob, filename + '.xlsx')
  332. },
  333. s2ab (s) {
  334. let buf
  335. if (typeof ArrayBuffer !== 'undefined') {
  336. buf = new ArrayBuffer(s.length)
  337. const view = new Uint8Array(buf)
  338. for (let i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xff
  339. return buf
  340. } else {
  341. buf = new Array(s.length)
  342. for (let i = 0; i !== s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF
  343. return buf
  344. }
  345. },
  346. getTimeStamp () {
  347. return dayjs().format('YYYYMMDDHHmmss')
  348. },
  349. handleExport () {
  350. const exportData = this.type.map((item, index) => {
  351. const obj = { 'leiXing': item }
  352. for (let i = 1; i < this.monthDays + 1; i++) {
  353. const t = this.formatData.list[i - 1][index]
  354. const text = `已完成:${t.done};待处理:${t.todo}`
  355. obj[Object.keys(this.deviceColumns)[i]] = text
  356. }
  357. return obj
  358. })
  359. // const copyData = JSON.parse(JSON.stringify(exportData))
  360. // console.log('导出数据', copyData)
  361. this.xlsx(exportData, this.deviceColumns, '设备维护统计' + this.getTimeStamp())
  362. this.$message.success('导出设备成功!')
  363. },
  364. async handleMonthChange (val) {
  365. const year = +val.split('-')[0]
  366. const month = +val.split('-')[1]
  367. this.monthDays = this.monthList[month - 1]
  368. if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) {
  369. this.monthList[1] = 29
  370. } else {
  371. this.monthList[1] = 28
  372. }
  373. await this.init()
  374. },
  375. // 获取人员部门
  376. getPersonPosition (id) {
  377. const userList = this.$store.getters.userList
  378. const bianzhiUserid = userList.find(i => i.userId === id)
  379. if (bianzhiUserid) {
  380. return bianzhiUserid.positionId
  381. }
  382. },
  383. checkRequired (flag) {
  384. },
  385. // 刷新
  386. async goRefresh () {
  387. },
  388. // 关闭当前窗口
  389. closeDialog (needRefresh) {
  390. this.$emit('update:dialogVisible', false, needRefresh)
  391. },
  392. async init () {
  393. this.loading = true
  394. this.title = `[${this.params.original_device_n}/${this.params.she_bei_ming_chen}]月度设备维护统计`
  395. const y = +this.month.split('-')[0]
  396. const m = +this.month.split('-')[1]
  397. const sql = `select a.id_ AS mainId,a.shi_fou_guo_shen_,a.bian_zhi_bu_men_,c.wei_hu_xiang_mu_c,a.bian_zhi_ren_,a.she_bei_ming_chen,a.she_bei_bian_hao_,a.ri_qi_,a.original_device_n,a.zhu_zhou_qi_,a.nei_rong_qing_kua,a.ji_hua_shi_jian_,c.she_bei_lei_xing_,c.wei_hu_ri_qi_,c.wei_hu_lei_xing_,c.ri_qi_shu_zi_,d.bei_zhu_,d.wei_hu_zhuang_tai from t_mjsbwhbyjlby a left join t_mjsbwhjhzb b on a.ji_hua_wai_jian_ = b.id_ left join v_device_devicemaintenance c on b.she_bei_bian_hao_ = c.id_ left join t_mjsbwhbyjlzby d on a.id_ = d.parent_id_ where a.ri_qi_='${this.params.ri_qi_}' and a.shi_fou_guo_shen_!='已删除' and YEAR(a.ji_hua_shi_jian_) = ${y} and MONTH(a.ji_hua_shi_jian_) = ${m}`
  398. const { variables: { data }} = await this.$common.request('sql', sql)
  399. this.dataList = data
  400. this.dataList.forEach(item => {
  401. if (!Object.hasOwn(item, 'wei_hu_lei_xing_') || !item.wei_hu_lei_xing_) {
  402. item.wei_hu_lei_xing_ = '按需保养'
  403. }
  404. })
  405. this.loading = false
  406. }
  407. }
  408. }
  409. </script>
  410. <style lang="scss" scoped>
  411. .paper-detail-dialog {
  412. ::v-deep {
  413. .el-dialog__header {
  414. text-align: center;
  415. }
  416. }
  417. .dialog-title{
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. div{
  422. z-index: 99999999;
  423. position: absolute;
  424. right:8vw;
  425. }
  426. .dialogtitle{
  427. font-size: 22px;
  428. font-family: SimHei;
  429. font-weight: bold;
  430. color: #222;
  431. }
  432. }
  433. .container {
  434. display: flex;
  435. width: 100%;
  436. justify-content: center;
  437. .el-row{
  438. margin: 0 !important;
  439. }
  440. .required{
  441. color: #606266 !important;
  442. &::before{
  443. content: '*';
  444. margin: 0 4px 0 -7.5px;
  445. color: #F56C6C;
  446. }
  447. }
  448. .left{
  449. height: calc(100vh - 100px);
  450. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  451. padding:20px;
  452. overflow-y: auto;
  453. .agend{
  454. margin: 20px 0 10px 0;
  455. display: flex;
  456. justify-content: space-between;
  457. .descript{
  458. display: flex;
  459. gap: 18px;
  460. .item{
  461. width: auto;
  462. display: flex;
  463. align-items: center;
  464. gap: 4px;
  465. .green-circle {
  466. width: 12px;
  467. height: 12px;
  468. background-color: #67C23A;
  469. border-radius: 50%;
  470. }
  471. .red-circle {
  472. width: 12px;
  473. height: 12px;
  474. background-color: #F56C6C;
  475. border-radius: 50%;
  476. }
  477. .orange-circle {
  478. width: 12px;
  479. height: 12px;
  480. background-color: #E6A23C;
  481. border-radius: 50%;
  482. }
  483. .red-bg {
  484. width: 12px;
  485. height: 12px;
  486. background-color: #F56C6C;
  487. opacity: .7;
  488. }
  489. .grey-bg{
  490. width: 12px;
  491. height: 12px;
  492. background-color: #a6b1bd;
  493. opacity: .7;
  494. }
  495. }
  496. }
  497. }
  498. .search{
  499. .label{
  500. font-size: 12px;
  501. }
  502. .item{
  503. display: flex;
  504. align-items: center;
  505. }
  506. }
  507. .item{
  508. width: 100%;
  509. }
  510. .title{
  511. margin: 16px 0 6px -16px;
  512. }
  513. .table{
  514. display: flex;
  515. .column{
  516. flex: 1;
  517. &:nth-child(2){
  518. display: flex;
  519. }
  520. >.item{
  521. height: 50px;
  522. text-align: center;
  523. line-height: 50px;
  524. border-bottom: 1px solid #333;
  525. border-right: 1px solid #333;
  526. border-left: 1px solid #333;
  527. min-width: 100px;
  528. }
  529. @media screen and (max-width: 1800px) {
  530. >.item{
  531. height: 44px;
  532. line-height: 44px;
  533. }
  534. }
  535. @media screen and (max-width: 1550px) {
  536. >.item{
  537. height: 40px;
  538. line-height: 40px;
  539. }
  540. }
  541. >.item:nth-child(1){
  542. font-weight: 600;
  543. border-top: 1px solid #333;
  544. height: 30px;
  545. line-height: 30px;
  546. }
  547. .content-item{
  548. .unusual{
  549. background-color: #F56C6C !important;
  550. opacity: .7 !important;
  551. }
  552. .unused{
  553. background-color: #a6b1bd;
  554. opacity: .7;
  555. }
  556. >.item{
  557. position: relative;
  558. height: 50px;
  559. width: 50px;
  560. text-align: center;
  561. line-height: 50px;
  562. border-bottom: 1px solid #333;
  563. border-right: 1px solid #333;
  564. }
  565. @media screen and (max-width: 1800px) {
  566. >.item{
  567. height: 44px;
  568. width: 44px;
  569. line-height: 44px;
  570. }
  571. }
  572. @media screen and (max-width: 1550px) {
  573. >.item{
  574. height: 40px;
  575. width: 40px;
  576. line-height: 40px;
  577. }
  578. }
  579. >.item:nth-child(1){
  580. font-weight: 600;
  581. border-top: 1px solid #333;
  582. height: 30px;
  583. line-height: 30px;
  584. }
  585. .green-circle {
  586. cursor: pointer;
  587. position: absolute;
  588. top: 50%;
  589. left: 50%;
  590. transform: translate(-50%, -50%);
  591. width: 10px;
  592. height: 10px;
  593. background-color: #67C23A;
  594. border-radius: 50%;
  595. }
  596. .red-circle {
  597. cursor: pointer;
  598. position: absolute;
  599. top: 50%;
  600. left: 50%;
  601. transform: translate(-50%, -50%);
  602. width: 10px;
  603. height: 10px;
  604. background-color: #F56C6C;
  605. border-radius: 50%;
  606. }
  607. .orange-circle {
  608. cursor: pointer;
  609. position: absolute;
  610. top: 50%;
  611. left: 50%;
  612. transform: translate(-50%, -50%);
  613. width: 10px;
  614. height: 10px;
  615. background-color: #E6A23C;
  616. border-radius: 50%;
  617. }
  618. }
  619. }
  620. }
  621. }
  622. }
  623. }
  624. ::v-deep {
  625. .el-form-item__label{
  626. text-align: left;
  627. font-size: 12px !important;
  628. }
  629. .el-form-item__content{
  630. font-size: 12px !important;
  631. }
  632. .el-divider--horizontal{
  633. margin: 10px 0;
  634. }
  635. }
  636. </style>