maintenanceStaticAll.vue 26 KB

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