maintenanceStatic.vue 22 KB

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