maintenanceStatic.vue 22 KB

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