index.vue 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. <template>
  2. <div class="main-container">
  3. <ibps-container
  4. class="page"
  5. >
  6. <template>
  7. <ibps-crud
  8. key="istree"
  9. ref="crud"
  10. :data="listData"
  11. :toolbars="listConfig.toolbars"
  12. :search-form="listConfig.searchForm"
  13. :pk-key="pkKey"
  14. :columns="listConfig.columns"
  15. :loading="loading"
  16. :pagination="pagination"
  17. :display-field="tableTitle"
  18. :index-row="false"
  19. @sort-change="handleSortChange"
  20. @action-event="handleAction"
  21. @pagination-change="handlePaginationChange"
  22. >
  23. <template
  24. slot="posSlot"
  25. slot-scope="{row}"
  26. >
  27. <ibps-user-selector
  28. v-model="row.bianZhiBuMen"
  29. type="org"
  30. readonly-text="text"
  31. :multiple="true"
  32. :disabled="true"
  33. />
  34. </template>
  35. <template
  36. slot="userSlot"
  37. slot-scope="{row}"
  38. >
  39. <ibps-user-selector
  40. v-model="row.guanLiRen"
  41. type="user"
  42. readonly-text="text"
  43. :multiple="true"
  44. :disabled="true"
  45. />
  46. </template>
  47. <template
  48. slot="deviceSlot"
  49. slot-scope="{row}"
  50. >
  51. <ibps-custom-dialog
  52. v-model="row.weiHuFangShi"
  53. size="mini"
  54. template-key="sbfzpz"
  55. multiple
  56. :disabled="true"
  57. type="dialog"
  58. class="custom-dialog"
  59. placeholder="请选择"
  60. icon="el-icon-search"
  61. />
  62. </template>
  63. <template
  64. slot="deviceStateSlot"
  65. slot-scope="{row}"
  66. >
  67. <span>{{ stateList[row.sheBeiZhuangTa] || row.sheBeiZhuangTa }}</span>
  68. </template>
  69. <template
  70. slot="placeSlot"
  71. slot-scope="{row}"
  72. >
  73. <ibps-custom-dialog
  74. v-model="row.cunFangWeiZhi"
  75. size="mini"
  76. template-key="fjwzdhk"
  77. multiple
  78. :disabled="true"
  79. type="dialog"
  80. class="custom-dialog"
  81. placeholder="请选择"
  82. icon="el-icon-search"
  83. />
  84. </template>
  85. <template
  86. slot="customButton"
  87. slot-scope="{row}"
  88. >
  89. <el-button type="text" icon="el-icon-edit-outline" @click="goEdit(row)">修改</el-button>
  90. <!-- <el-button type="text" icon="el-icon-view" @click="goLook(row)">查阅</el-button> -->
  91. <el-button type="text" icon="ibps-icon-table" @click="goLookForm(row)">表单</el-button>
  92. </template>
  93. <template
  94. slot="expandSlot"
  95. slot-scope="{row}"
  96. >
  97. <el-row :gutter="20" style="height:145px;padding:0 20px 0 0" type="flex" align="middle">
  98. <el-col :span="5" :push="2">
  99. <el-row>
  100. <el-col :span="3">
  101. <el-image
  102. class="icon-image"
  103. :src="images[0]"
  104. fit="contain"
  105. />
  106. </el-col>
  107. <el-col :span="21">
  108. <div class="title">验收信息</div>
  109. <div class="ctx">
  110. <div class="item">接收日期:{{ row.jieShouRiQi || '/' }}</div>
  111. <div class="item">验收日期:{{ row.yanShouRiQi || '/' }}</div>
  112. <div class="item">核查日期:{{ row.biXuSheShi || '/' }}</div>
  113. </div>
  114. </el-col>
  115. </el-row>
  116. </el-col>
  117. <el-col :span="5" :push="2">
  118. <el-row>
  119. <el-col :span="3">
  120. <el-image
  121. class="icon-image"
  122. :src="images[1]"
  123. fit="contain"
  124. />
  125. </el-col>
  126. <el-col :span="21">
  127. <div class="title">建档信息</div>
  128. <div class="ctx">
  129. <div class="item">
  130. <div class="cusitem">
  131. <span class="span">建档人:</span>
  132. <ibps-user-selector
  133. :value="row.bianZhiRen"
  134. type="user"
  135. readonly-text="text"
  136. :multiple="true"
  137. :disabled="true"
  138. size="mini"
  139. style="width:100px"
  140. />
  141. </div>
  142. </div>
  143. <div class="item">
  144. <div class="cusitem">
  145. <span class="span">建档部门:</span>
  146. <ibps-user-selector
  147. :value="row.bianZhiBuMen"
  148. type="org"
  149. readonly-text="text"
  150. :disabled="true"
  151. :multiple="false"
  152. size="mini"
  153. style="width:100px"
  154. />
  155. </div>
  156. </div>
  157. <div class="item">建档时间:{{ row.bianZhiShiJian || '/' }}</div>
  158. </div>
  159. </el-col>
  160. </el-row>
  161. </el-col>
  162. <el-col :span="5" :push="2">
  163. <el-row>
  164. <el-col :span="3">
  165. <el-image
  166. class="icon-image"
  167. :src="images[2]"
  168. fit="contain"
  169. />
  170. </el-col>
  171. <el-col :span="21">
  172. <div class="title">维护信息</div>
  173. <div class="ctx">
  174. <div class="item">是否维护:{{ row.shiFouWeiHu || '/' }}</div>
  175. <div class="item">是否24H开机:{{ row.jianKongYiJu || '/' }}</div>
  176. <div class="item">是否限用:{{ row.xiaoZhunWuCha || '/' }}</div>
  177. </div>
  178. </el-col>
  179. </el-row>
  180. </el-col>
  181. <el-col :span="5" :push="2">
  182. <el-row>
  183. <el-col :span="3">
  184. <el-image
  185. class="icon-image"
  186. :src="images[3]"
  187. fit="contain"
  188. />
  189. </el-col>
  190. <el-col :span="21">
  191. <div class="title">校准信息</div>
  192. <div class="ctx">
  193. <div class="item">是否校准:{{ row.shiFouXiaoZhun || '/' }}</div>
  194. <div class="item">校准周期:{{ row.xiaoZhunZQ?`${row.xiaoZhunZQ}月` : '/' }}</div>
  195. <div class="item">最近校准时间:{{ row.yiXiaoRiQi || '/' }}</div>
  196. </div>
  197. </el-col>
  198. </el-row>
  199. </el-col>
  200. <el-col :span="4" :push="1">
  201. <el-row>
  202. <el-col :span="24">
  203. <el-image
  204. class="device-image"
  205. :src="ImageUrl(row)"
  206. fit="fill"
  207. :preview-src-list="ImageAllUrl(row)"
  208. :title="`[${row.sheBeiMingCheng}]设备首图,点击查看更多`"
  209. >
  210. <div slot="error" class="image-slot">
  211. <el-empty class="device-image" description="暂无图片" :image-size="70" />
  212. </div>
  213. </el-image>
  214. </el-col>
  215. </el-row>
  216. </el-col>
  217. </el-row>
  218. </template>
  219. <!-- 搜索条件 -->
  220. <template slot="pos">
  221. <ibps-user-selector
  222. v-model="search.pos"
  223. type="org"
  224. readonly-text="text"
  225. :multiple="true"
  226. size="mini"
  227. :filter="filter"
  228. filtrate
  229. />
  230. </template>
  231. <template slot="time">
  232. <el-date-picker
  233. v-model="search.time"
  234. size="mini"
  235. type="daterange"
  236. :picker-options="pickerOptions"
  237. range-separator="至"
  238. start-placeholder="开始日期"
  239. end-placeholder="结束日期"
  240. align="right"
  241. value-format="yyyy-MM-dd"
  242. />
  243. </template>
  244. <template slot="nowNumber">
  245. <el-input v-model="search.nowNumber" size="mini" />
  246. </template>
  247. <template slot="preNumber">
  248. <el-input v-model="search.preNumber" size="mini" />
  249. </template>
  250. <template slot="deviceName">
  251. <el-input v-model="search.deviceName" size="mini" />
  252. </template>
  253. <template slot="deviceType">
  254. <el-select v-model="search.deviceType" placeholder="请选择" size="mini" :clearable="true">
  255. <el-option
  256. v-for="item in ['检验系统','通用设备','软件','信息系统']"
  257. :key="item"
  258. :label="item"
  259. :value="item"
  260. />
  261. </el-select>
  262. </template>
  263. <template slot="deviceStatus">
  264. <el-select v-model="search.deviceStatus" placeholder="请选择" size="mini" :clearable="true">
  265. <el-option
  266. v-for="(v,k) in stateList"
  267. :key="k"
  268. :label="v"
  269. :value="k"
  270. />
  271. </el-select>
  272. </template>
  273. <template slot="place">
  274. <el-input v-model="search.place" size="mini" />
  275. </template>
  276. <template slot="managePeople">
  277. <ibps-user-selector
  278. v-model="search.managePeople"
  279. type="user"
  280. readonly-text="text"
  281. :multiple="true"
  282. size="mini"
  283. :filter="filter"
  284. filtrate
  285. />
  286. </template>
  287. <template slot="deviceClass">
  288. <ibps-custom-dialog
  289. v-model="search.deviceClass"
  290. size="mini"
  291. template-key="sbfzpz"
  292. multiple
  293. :disabled="false"
  294. type="dialog"
  295. class="custom-dialog"
  296. placeholder="请选择"
  297. icon="el-icon-search"
  298. />
  299. </template>
  300. </ibps-crud>
  301. </template>
  302. </ibps-container>
  303. <DeviceDialog v-if="deviceDialogShow" :params="params" :state-list="stateList" @close="close" />
  304. <input id="" ref="file1" type="file" name="" accept=".xlsx,.xls" @change="handleUploadChange1">
  305. <input id="" ref="file2" type="file" name="" accept=".xlsx,.xls" @change="handleUploadChange2">
  306. <custom-dialog
  307. :visible="customDialogVisible"
  308. :value="[]"
  309. template-key="sbfzpz"
  310. :dynamic-params="{}"
  311. @close="(visible) => (customDialogVisible = visible)"
  312. />
  313. <bpmn-formrender
  314. :visible="npmDialogFormVisible"
  315. def-id="1055162372286578688"
  316. @close="visible => npmDialogFormVisible = visible"
  317. />
  318. <DeviceTag :scan-visible="printVisible" :obj="printObj" :state-list="stateList" @scanOff="scanOff" />
  319. <el-dialog
  320. :close-on-click-modal="false"
  321. :close-on-press-escape="false"
  322. :top="'3vh'"
  323. :width="'90%'"
  324. class="js-custom-dialog"
  325. append-to-body
  326. :fullscreen="false"
  327. :visible.sync="iframeVisible"
  328. >
  329. <iframe :src="srcUrl" :height="'100%'" :width="'100%'" frameborder="0" scrolling="no" />
  330. </el-dialog>
  331. </div>
  332. </template>
  333. <script>
  334. import { getSetting } from '@/utils/query'
  335. import image01 from '@/assets/images/device/01.png'
  336. import image02 from '@/assets/images/device/02.png'
  337. import image03 from '@/assets/images/device/03.png'
  338. import image04 from '@/assets/images/device/04.png'
  339. import { getImage } from '@/api/platform/file/attachment'
  340. import xlsx from 'xlsx'
  341. import fs from 'file-saver'
  342. import DataTemplateFormrenderDialog from '@/business/platform/data/templaterender/form/dialog.vue'
  343. import ActionUtils from '@/utils/action'
  344. import FixHeight from '@/mixins/height'
  345. import ibpsUserSelector from '@/business/platform/org/selector'
  346. import DeviceDialog from './deviceDialog.vue'
  347. import { queryequipmentCard, removeEquipmentCard, getequipmentCard, saveEquipmentCard } from '@/api/platform/device/device'
  348. import CustomDialog from '@/business/platform/data/templaterender/custom-dialog/dialog'
  349. import dayjs from 'dayjs'
  350. import DeviceTag from '@/views/system/jbdScan/goods/deviceTag.vue'
  351. export default {
  352. components: {
  353. DeviceTag,
  354. DataTemplateFormrenderDialog,
  355. DeviceDialog,
  356. ibpsUserSelector,
  357. CustomDialog,
  358. IbpsCustomDialog: () => import('@/business/platform/data/templaterender/custom-dialog')
  359. },
  360. mixins: [FixHeight],
  361. data () {
  362. const { userId, position } = this.$store.getters || {}
  363. console.log(userId, position)
  364. return {
  365. filter: [{
  366. descVal: '1',
  367. includeSub: true,
  368. old: 'position',
  369. partyId: this.$store.getters.userInfo.employee.positions,
  370. partyName: '',
  371. scriptContent: '',
  372. type: 'user',
  373. userType: 'position'
  374. }],
  375. images: [image01, image02, image03, image04],
  376. ImportDeviceType: '',
  377. iframeVisible: false,
  378. srcUrl: '',
  379. printObj: [],
  380. printVisible: false,
  381. DialogVisible: true,
  382. npmDialogFormVisible: false,
  383. customDialogVisible: false,
  384. pickerOptions: {
  385. shortcuts: [{
  386. text: '最近一周',
  387. onClick (picker) {
  388. const end = new Date()
  389. const start = new Date()
  390. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  391. picker.$emit('pick', [start, end])
  392. }
  393. }, {
  394. text: '最近一个月',
  395. onClick (picker) {
  396. const end = new Date()
  397. const start = new Date()
  398. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  399. picker.$emit('pick', [start, end])
  400. }
  401. }, {
  402. text: '最近三个月',
  403. onClick (picker) {
  404. const end = new Date()
  405. const start = new Date()
  406. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  407. picker.$emit('pick', [start, end])
  408. }
  409. }]
  410. },
  411. params: {},
  412. deviceDialogShow: false,
  413. position: position,
  414. userId: userId,
  415. search: {
  416. pos: '',
  417. time: [],
  418. nowNumber: '',
  419. preNumber: '',
  420. deviceName: '',
  421. deviceType: '',
  422. deviceStatus: '',
  423. place: '',
  424. managePeople: '',
  425. deviceClass: ''
  426. },
  427. loading: false,
  428. pkKey: 'id', // 主键 如果主键不是pk需要传主键
  429. pkValue: '',
  430. templateKey: '',
  431. visible: false,
  432. categoryKey: '',
  433. tableTitle: '设备基本信息列表', // 标题
  434. listData: [],
  435. selectListData: [], // 全部数据
  436. bianlistData: {
  437. dataResult: [],
  438. pageResult: {
  439. limit: 0,
  440. page: 0,
  441. totalCount: 0,
  442. totalPages: 0
  443. }
  444. },
  445. listConfig: {
  446. // 工具栏
  447. toolbars: [
  448. { key: 'search' },
  449. { key: 'customAdd', label: '设备建档', icon: 'ibps-icon-plus', type: 'success' },
  450. { key: 'customBpm', label: '设备台账', icon: 'ibps-icon-file-text', type: 'info' },
  451. { key: 'customPrint', label: '打印标签', icon: 'ibps-icon-cog', type: 'warning' },
  452. { key: 'customExport', label: '导出数据', icon: 'ibps-icon-sign-in', type: 'primary' },
  453. { key: 'customImport', label: '导入数据', icon: 'ibps-icon-sign-in', type: 'primary' },
  454. { key: 'customSetting', label: '设置分组配置', icon: 'ibps-icon-cogs', type: 'info' },
  455. { key: 'customRemove', label: '删除', icon: 'ibps-icon-close', type: 'danger' }
  456. ],
  457. // 查询条件
  458. searchForm: {
  459. forms: [
  460. { prop: '', label: '部门', fieldType: 'slot', slotName: 'pos' }, // user 插槽
  461. { prop: '', label: '建档时间', fieldType: 'slot', slotName: 'time' },
  462. { prop: '', label: '设备编号', fieldType: 'slot', slotName: 'nowNumber' },
  463. { prop: '', label: '原设备编号', fieldType: 'slot', slotName: 'preNumber' },
  464. { prop: '', label: '设备名称', fieldType: 'slot', slotName: 'deviceName' },
  465. { prop: '', label: '设备类型', fieldType: 'slot', slotName: 'deviceType' },
  466. { prop: '', label: '设备状态', fieldType: 'slot', slotName: 'deviceStatus' },
  467. { prop: '', label: '放置地点', fieldType: 'slot', slotName: 'place' },
  468. { prop: '', label: '管理人', fieldType: 'slot', slotName: 'managePeople' },
  469. { prop: '', label: '设备分组', fieldType: 'slot', slotName: 'deviceClass' }
  470. ]
  471. },
  472. // 表格字段配置
  473. columns: [
  474. { type: 'expand', slotName: 'expandSlot' },
  475. { prop: 'bianZhiBuMen', label: '部门', slotName: 'posSlot', sortable: true },
  476. { prop: 'bianZhiShiJian', label: '建档时间', sortable: true },
  477. { prop: 'sheBeiShiBieH', label: '设备编号', sortable: true },
  478. { prop: 'yuanSheBeiBian', label: '原设备编号', sortable: true },
  479. { prop: 'sheBeiMingCheng', label: '设备名称', sortable: true },
  480. { prop: 'sheBeiLeiXing', label: '设备类型', sortable: true },
  481. { prop: 'guiGeXingHao', label: '规格型号', sortable: true },
  482. { prop: 'sheBeiZhuangTa', label: '设备状态', sortable: true, slotName: 'deviceStateSlot' },
  483. { prop: 'guanLiRen', label: '保管人', slotName: 'userSlot', sortable: true },
  484. { prop: 'weiHuFangShi', label: '设备分组', slotName: 'deviceSlot', sortable: true },
  485. { prop: 'cunFangWeiZhi', label: '放置地点', slotName: 'placeSlot', sortable: true },
  486. { prop: '', label: '操作', width: 130, slotName: 'customButton' }
  487. ]
  488. },
  489. pagination: {
  490. limit: 20, page: 1
  491. },
  492. sorts: [{ field: 'BIAN_ZHI_SHI_JIAN', order: 'desc' }],
  493. sqlWhere: {},
  494. searchWhere: {},
  495. deviceColumns: {
  496. bianZhiBuMen: '部门',
  497. sheBeiMingCheng: '设备名称',
  498. // sheBeiShiBieH: '设备编号(导入无需填写)',
  499. yuanSheBeiBian: '原设备编号(必填,且不可重复)',
  500. sheBeiZhuangTa: '设备状态(合格/停用/限用)',
  501. sheBeiLeiXing: '设备类型(检验系统/通用设备/软件/信息系统)',
  502. shiFouWeiHu: '是否维护(是/否)',
  503. shiFouXiaoZhun: '是否校准(是/否)',
  504. weiHuFangShi: '设备分组',
  505. guiGeXingHao: '规格型号',
  506. cunFangDiDian: '存放地点(格式:房间号+空格+房间名)',
  507. guanLiRen: '保管人',
  508. ziChanBianHao: '资产编号',
  509. gongYingShang: '供应商',
  510. lianXiFangShi: '联系方式',
  511. changShang: '厂商',
  512. jiShenXuHao: '机身序号',
  513. zhuCeZhengHao: '注册证号',
  514. chuChangRiQi: '出厂日期',
  515. yanShouRiQi: '验收日期',
  516. jieShouRiQi: '接收日期',
  517. qiYongRiQi: '投入日期',
  518. yiXiaoRiQi: '已校日期',
  519. xiaoZhunZQ: '检定/校准周期(以月为单位)',
  520. xiaoZhunYouXia: '校准有效期至',
  521. shiYongKeShi: '检定/校准单位',
  522. ceLiangGongZuo: '测量/工作范围',
  523. huanJingYaoQiu: '环境要求',
  524. dianYuanYaoQiu: '电源要求',
  525. jieShouZhuangTai: '接收时状态(新设备/二手或翻新设备)',
  526. jianDingXiao: '检定/校准参数',
  527. zuiDaYunCha: 'U/精确度/最大允差',
  528. zhengShuBianHa: '证书编号',
  529. xiuZhengZhiXiu: '修正值/修正因子',
  530. wenDuYingYong: '温度应用修正值',
  531. shiDuYingYong: '湿度应用修正值',
  532. biXuDeHuanJin: '核查人',
  533. biXuSheShi: '核查日期',
  534. heChaXiaoZhun: '使用年限(年)'
  535. },
  536. projectColums: {
  537. yuanSheBeiBian: '设备编号*',
  538. sheBeiMingCheng: '设备名称*',
  539. weiHuLeiXing: '维护类型*(日保养/周保养/月保养/季度保养/半年保养/年保养/按需保养)',
  540. weiHuRiQi: '维护日期*',
  541. weiHuXiangMuC: '维护项目*'
  542. },
  543. dateFieldRange: ['chuChangRiQi', 'yanShouRiQi', 'jieShouRiQi', 'qiYongRiQi', 'yiXiaoRiQi', 'xiaoZhunYouXia', 'biXuSheShi'],
  544. requiredFieldMap: {
  545. bianZhiBuMen: '部门',
  546. sheBeiMingCheng: '设备名称',
  547. yuanSheBeiBian: '原设备编号',
  548. sheBeiZhuangTa: '设备状态',
  549. sheBeiLeiXing: '设备类型',
  550. shiFouWeiHu: '是否维护',
  551. shiFouXiaoZhun: '是否校准'
  552. },
  553. dateFieldsMap: {
  554. 'chuChangRiQi': '出厂日期',
  555. 'yanShouRiQi': '验收日期',
  556. 'jieShouRiQi': '接收日期',
  557. 'qiYongRiQi': '投入日期',
  558. 'yiXiaoRiQi': '已校日期',
  559. 'xiaoZhunYouXia': '校准有效期至',
  560. 'biXuSheShi': '核查日期'
  561. },
  562. validationRules: {
  563. '设备状态': {
  564. field: 'sheBeiZhuangTa',
  565. range: ['合格', '停用', '限用']
  566. },
  567. '设备类型': {
  568. field: 'sheBeiLeiXing',
  569. range: ['检验系统', '通用设备', '软件', '信息系统']
  570. },
  571. '接收时状态': {
  572. field: 'jieShouZhuangTai',
  573. range: ['新设备', '二手或翻新设备']
  574. },
  575. '是否校准': {
  576. field: 'shiFouXiaoZhun',
  577. range: ['是', '否']
  578. },
  579. '是否维护': {
  580. field: 'shiFouWeiHu',
  581. range: ['是', '否']
  582. }
  583. },
  584. numberFieldsMap: {
  585. 'xiaoZhunZQ': '检定/校准周期(以月为单位)',
  586. 'heChaXiaoZhun': '使用年限(年)'
  587. },
  588. maintenanceRequiredFieldMap: {
  589. yuanSheBeiBian: '原设备编号',
  590. sheBeiMingCheng: '设备名称',
  591. weiHuLeiXing: '维护类型',
  592. weiHuRiQi: '维护日期',
  593. weiHuXiangMuC: '维护项目'
  594. },
  595. maintenanceValidationRules: {
  596. '维护类型': {
  597. field: 'weiHuLeiXing',
  598. range: ['日保养', '周保养', '月保养', '季度保养', '半年保养', '年保养', '按需保养']
  599. }
  600. },
  601. maintenanceDateValidationRules: {
  602. '日保养': this.generateDayRule(),
  603. '周保养': this.generateRule(7, `每周`, ``),
  604. '月保养': this.generateRule(28, `每月第`, `日`),
  605. '半年保养': this.generateRule(6, `每半年第`, `个月`),
  606. '季度保养': this.generateRule(3, `每季度第`, `个月`),
  607. '年保养': this.generateRule(12, `每年第`, `个月`),
  608. '按需保养': ['/']
  609. },
  610. stateList: { '停用': '停用', '报废': '报废', '合格': '合格' }
  611. }
  612. },
  613. async mounted () {
  614. const stateList = await getSetting('device', 'stateList')
  615. if (stateList) {
  616. console.debug(stateList)
  617. this.stateList = stateList
  618. }
  619. this.getDatas()
  620. },
  621. methods: {
  622. ImageAllUrl (row) {
  623. if (row && row.buMen) {
  624. const imgId = row.buMen.split(',')
  625. return imgId.map(item => getImage(item))
  626. }
  627. return []
  628. },
  629. ImageUrl (row) {
  630. if (row && row.buMen) {
  631. const imgId = row.buMen.split(',')[0]
  632. return getImage(imgId)
  633. }
  634. return ''
  635. },
  636. async getDatas () {
  637. this.loading = true
  638. const parameters = {
  639. relation: 'AND',
  640. parameters: []
  641. }
  642. // 部门搜索(可多选)
  643. if (this.search.pos) {
  644. const obj = { relation: 'OR', parameters: [] }
  645. this.search.pos.split(',').forEach(item => {
  646. obj.parameters.push({ key: 'Q^bian_zhi_bu_men_^S', value: item, param: this.$utils.guid() })
  647. })
  648. parameters.parameters.push(obj)
  649. }
  650. // 建档时间搜索
  651. if (this.search.time && this.search.time.length === 2) {
  652. const obj = { relation: 'AND', parameters: [] }
  653. obj.parameters.push({ key: 'Q^bian_zhi_shi_jian^DL^yyyy-MM-dd', value: this.search.time[0], param: this.$utils.guid() })
  654. obj.parameters.push({ key: 'Q^bian_zhi_shi_jian^DG^yyyy-MM-dd', value: this.search.time[1], param: this.$utils.guid() })
  655. parameters.parameters.push(obj)
  656. }
  657. // 设备编号搜索
  658. if (this.search.nowNumber) {
  659. const obj = { relation: 'AND', parameters: [] }
  660. obj.parameters.push({ key: 'Q^she_bei_shi_bie_h^SL', value: this.search.nowNumber, param: this.$utils.guid() })
  661. parameters.parameters.push(obj)
  662. }
  663. // 原设备编号搜索
  664. if (this.search.preNumber) {
  665. const obj = { relation: 'AND', parameters: [] }
  666. obj.parameters.push({ key: 'Q^yuan_she_bei_bian^SL', value: this.search.preNumber, param: this.$utils.guid() })
  667. parameters.parameters.push(obj)
  668. }
  669. // 设备名称搜索
  670. if (this.search.deviceName) {
  671. const obj = { relation: 'AND', parameters: [] }
  672. obj.parameters.push({ key: 'Q^she_bei_ming_cheng_^SL', value: this.search.deviceName, param: this.$utils.guid() })
  673. parameters.parameters.push(obj)
  674. }
  675. // 设备类型搜索
  676. if (this.search.deviceType) {
  677. const obj = { relation: 'AND', parameters: [] }
  678. obj.parameters.push({ key: 'Q^she_bei_lei_xing_^S', value: this.search.deviceType, param: this.$utils.guid() })
  679. parameters.parameters.push(obj)
  680. }
  681. // 设备状态搜索
  682. if (this.search.deviceStatus) {
  683. const obj = { relation: 'AND', parameters: [] }
  684. obj.parameters.push({ key: 'Q^she_bei_zhuang_ta^S', value: this.search.deviceStatus, param: this.$utils.guid() })
  685. parameters.parameters.push(obj)
  686. }
  687. // 放置地点搜索
  688. if (this.search.place) {
  689. const obj = { relation: 'AND', parameters: [] }
  690. obj.parameters.push({ key: 'Q^cun_fang_di_dian_^SL', value: this.search.place, param: this.$utils.guid() })
  691. parameters.parameters.push(obj)
  692. }
  693. // 保管人搜索(可多选)
  694. if (this.search.managePeople) {
  695. const obj = { relation: 'OR', parameters: [] }
  696. this.search.managePeople.split(',').forEach(item => {
  697. obj.parameters.push({ key: 'Q^guan_li_ren_^S', value: item, param: this.$utils.guid() })
  698. })
  699. parameters.parameters.push(obj)
  700. }
  701. // 设备分组搜索(可多选)
  702. if (this.search.deviceClass) {
  703. const obj = { relation: 'OR', parameters: [] }
  704. this.search.deviceClass.split(',').forEach(item => {
  705. obj.parameters.push({ key: 'Q^wei_hu_fang_shi_^S', value: item, param: this.$utils.guid() })
  706. })
  707. parameters.parameters.push(obj)
  708. }
  709. const params = {
  710. requestPage: {
  711. pageNo: this.pagination.page,
  712. limit: this.pagination.limit
  713. },
  714. sorts: this.sorts
  715. }
  716. if (parameters.parameters.length > 0) {
  717. params.parameters = [parameters]
  718. }
  719. const { data: { dataResult, pageResult }} = await queryequipmentCard(params)
  720. this.bianlistData.pageResult = pageResult
  721. this.bianlistData.dataResult = dataResult
  722. ActionUtils.handleListData(this, this.bianlistData) // 调用内置方法
  723. this.loading = false
  724. },
  725. // 查看表单
  726. goLookForm (row) {
  727. const orgId = this.$store.getters.org.id
  728. this.srcUrl = this.$reportPath.replace('show', 'pdf') + '设备/设备档案卡.rpx&id_=' + row.id
  729. this.iframeVisible = true
  730. },
  731. // 按钮事件处理
  732. handleAction (command, position, selection, data, index, button) {
  733. switch (command) {
  734. case 'search':// 查询
  735. this.getDatas()
  736. break
  737. case 'customAdd':
  738. this.handleCustomAdd()
  739. break
  740. case 'customSetting':
  741. this.handleCustomSetting()
  742. break
  743. case 'customRemove':
  744. this.handleCustomRemove(selection)
  745. break
  746. case 'customExport':
  747. this.handleCustomExport(selection, data)
  748. break
  749. case 'customImport':
  750. this.handleCustomImport()
  751. break
  752. case 'customBpm':
  753. this.handleCustomBpm()
  754. break
  755. case 'customPrint':
  756. this.handleCustomPrint(selection)
  757. break
  758. default:
  759. break
  760. }
  761. },
  762. // 打印标签
  763. handleCustomPrint (selection = []) {
  764. if (selection.length === 0) {
  765. return this.$message.warning('请先选择需要打印标签的数据!')
  766. }
  767. this.printObj = selection
  768. this.printVisible = true
  769. },
  770. // 关闭标签
  771. scanOff () {
  772. this.printVisible = false
  773. },
  774. // 设备台账
  775. handleCustomBpm () {
  776. this.npmDialogFormVisible = true
  777. },
  778. // 处理分页事件
  779. async handlePaginationChange (page) {
  780. ActionUtils.setPagination(this.pagination, page)
  781. this.getDatas()
  782. },
  783. // 处理排序
  784. handleSortChange (sort) {
  785. function removeUnderscores (str) {
  786. return str.replace(/^_+|_+$/g, '')
  787. }
  788. const { order, sortBy } = sort
  789. let s = ''
  790. switch (sortBy) {
  791. case 'BIAN_ZHI_SHI_JIAN_':
  792. case 'SHE_BEI_SHI_BIE_H_':
  793. case 'YUAN_SHE_BEI_BIAN_':
  794. case 'SHE_BEI_ZHUANG_TA_':
  795. s = removeUnderscores(sortBy)
  796. break
  797. default:
  798. s = sortBy
  799. }
  800. let o = null
  801. if (order === 'descending') {
  802. o = 'desc'
  803. } else if (order === 'ascending') {
  804. o = 'asc'
  805. }
  806. this.sorts = [{ field: s, order: o }]
  807. this.getDatas()
  808. },
  809. handleCustomAdd () {
  810. this.params = {}
  811. this.deviceDialogShow = true
  812. },
  813. close () {
  814. this.deviceDialogShow = false
  815. this.getDatas()
  816. },
  817. goEdit (row) {
  818. console.log('aa')
  819. this.params = row
  820. this.deviceDialogShow = true
  821. },
  822. handleCustomSetting () {
  823. this.customDialogVisible = true
  824. },
  825. handleCustomRemove (selection) {
  826. console.log('selection', selection)
  827. if (!selection || selection.length === 0) {
  828. return this.$message.warning('请选择要删除的数据!')
  829. }
  830. this.$confirm('确定删除所选项?删除后无法恢复!', '提示', {
  831. confirmButtonText: '继续',
  832. cancelButtonText: '取消',
  833. type: 'warning'
  834. }).then(async () => {
  835. await removeEquipmentCard({
  836. ids: selection + ''
  837. })
  838. // 删除后刷新
  839. await this.getDatas()
  840. this.$message.success('删除成功!')
  841. }).catch(() => {})
  842. },
  843. // 导出
  844. handleCustomExport (selection, data) {
  845. this.$confirm('请选择导出的类型', '提示', {
  846. confirmButtonText: '导出设备',
  847. cancelButtonText: '导出维护项目',
  848. closeOnClickModal: false,
  849. closeOnPressEscape: false,
  850. distinguishCancelAndClose: true,
  851. type: 'info'
  852. }).then(() => {
  853. this.ExportDevice(selection, data)
  854. }).catch((action) => {
  855. if (action === 'close') return
  856. if (action === 'cancel') {
  857. this.ExportProject(selection, data)
  858. }
  859. })
  860. },
  861. // 导入
  862. handleCustomImport () {
  863. this.$confirm('确请选择导入的类型', '提示', {
  864. confirmButtonText: '导入设备',
  865. cancelButtonText: '导入维护项目',
  866. closeOnClickModal: false,
  867. closeOnPressEscape: false,
  868. distinguishCancelAndClose: true,
  869. type: 'info'
  870. }).then(() => {
  871. this.ImportDevice()
  872. }).catch((action) => {
  873. if (action === 'close') return
  874. if (action === 'cancel') {
  875. this.$confirm('请选择设备维护项目导入类型', '提示', {
  876. confirmButtonText: '增量添加',
  877. cancelButtonText: '全量替换',
  878. closeOnClickModal: false,
  879. closeOnPressEscape: false,
  880. distinguishCancelAndClose: true,
  881. type: 'info'
  882. }).then(() => {
  883. this.ImportDeviceType = '增量添加'
  884. this.ImportProject()
  885. }).catch((action) => {
  886. if (action === 'close') return
  887. if (action === 'cancel') {
  888. this.ImportDeviceType = '全量替换'
  889. this.ImportProject()
  890. }
  891. })
  892. }
  893. })
  894. },
  895. // 导入设备
  896. ImportDevice () {
  897. this.$refs.file1.click()
  898. console.log('导入设备')
  899. },
  900. // 导入维护项目
  901. ImportProject () {
  902. this.$refs.file2.click()
  903. console.log('导入维护项目')
  904. },
  905. getTimeStamp () {
  906. return dayjs().format('YYYYMMDDHHmmss')
  907. },
  908. xlsx (json, fields, filename = '.xlsx') { // 导出xlsx
  909. json.forEach(item => {
  910. for (const i in item) {
  911. if (fields.hasOwnProperty(i)) {
  912. item[fields[i]] = item[i]
  913. }
  914. delete item[i] // 删除原先的对象属性
  915. }
  916. })
  917. const sheetName = filename // excel的文件名称
  918. const wb = xlsx.utils.book_new() // 工作簿对象包含一SheetNames数组,以及一个表对象映射表名称到表对象。XLSX.utils.book_new实用函数创建一个新的工作簿对象。
  919. const ws = xlsx.utils.json_to_sheet(json, { header: Object.values(fields) }) // 将JS对象数组转换为工作表。
  920. wb.SheetNames.push(sheetName)
  921. wb.Sheets[sheetName] = ws
  922. const defaultCellStyle = { font: { name: 'Verdana', sz: 13, color: 'FF00FF88' }, fill: { fgColor: { rgb: 'FFFFAA00' }}}// 设置表格的样式
  923. const wopts = { bookType: 'xlsx', bookSST: false, type: 'binary', cellStyles: true, defaultCellStyle: defaultCellStyle, showGridLines: false } // 写入的样式
  924. const wbout = xlsx.write(wb, wopts)
  925. const blob = new Blob([this.s2ab(wbout)], { type: 'application/octet-stream' })
  926. fs.saveAs(blob, filename + '.xlsx')
  927. },
  928. s2ab (s) {
  929. let buf
  930. if (typeof ArrayBuffer !== 'undefined') {
  931. buf = new ArrayBuffer(s.length)
  932. const view = new Uint8Array(buf)
  933. for (let i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xff
  934. return buf
  935. } else {
  936. buf = new Array(s.length)
  937. for (let i = 0; i !== s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF
  938. return buf
  939. }
  940. },
  941. async switchExportData (data) {
  942. const deviceGroupSql = `select id_,wei_hu_gang_wei_ from t_sbwhgwpzb` // 设备分组信息
  943. // const supplierSql = `select id_,gong_ying_shang_m from t_hggysxx` // 供应商信息
  944. const { variables: { data: deviceGroupData }} = await this.$common.request('sql', deviceGroupSql)
  945. // const { variables: { data: gysData }} = await this.$common.request('sql', supplierSql)
  946. const exportData = JSON.parse(JSON.stringify(data))
  947. for (let i = 0; i < exportData.length; i++) {
  948. const item = exportData[i]
  949. item.bianZhiBuMen = this.switchIdToDept(item.bianZhiBuMen.split(',')[0])
  950. item.guanLiRen = this.switchIdToUserName(item.guanLiRen.split(',')[0])
  951. item.biXuDeHuanJin = this.switchIdToUserName(item.biXuDeHuanJin.split(',')[0])
  952. item.weiHuFangShi = this.switchDeviceIdToName(item.weiHuFangShi, deviceGroupData)
  953. // item.shiYongKeShi = this.switchGYSIdToName(item.shiYongKeShi, gysData)
  954. if (this.stateList[item.sheBeiZhuangTa]) {
  955. item.sheBeiZhuangTa = this.stateList[item.sheBeiZhuangTa]
  956. }
  957. }
  958. return exportData
  959. },
  960. // 设备分组id 转 设备分组名称
  961. switchDeviceIdToName (val, deviceGroupList) {
  962. const result = []
  963. const valList = val?.split(',') || []
  964. valList.forEach(item => result.push((deviceGroupList?.find(i => i.id_ === item)?.wei_hu_gang_wei_) || ''))
  965. return result.join(',')
  966. },
  967. // 供应商id 转 供应商名称 检定/校准单位
  968. switchGYSIdToName (val, gysList) {
  969. const result = gysList.find(item => item.id_ === val)?.gong_ying_shang_m || ''
  970. return result
  971. },
  972. // 部门id 转 部门名称
  973. switchIdToDept (id) {
  974. const { deptList } = this.$store.getters
  975. const temp = deptList.find(item => item.positionId === id)
  976. return temp ? temp.positionName : ''
  977. },
  978. // 部门名称 转 部门id
  979. switchDeptToId (dep) {
  980. const { deptList } = this.$store.getters
  981. const temp = deptList.find(item => item.positionName === dep)
  982. return temp ? temp.positionId : ''
  983. },
  984. // 人员id 转人员名称
  985. switchIdToUserName (id) {
  986. const { userList } = this.$store.getters
  987. const temp = userList.find(item => item.userId === id)
  988. return temp ? temp.userName : ''
  989. },
  990. // 人员名称 转 人员id
  991. switchUserNameToId (name) {
  992. const { userList } = this.$store.getters
  993. const temp = userList.find(item => item.userName === name)
  994. return temp ? temp.userId : ''
  995. },
  996. // 导出设备
  997. async ExportDevice (selection, data = []) {
  998. const exportData = await this.switchExportData(data)
  999. this.xlsx(exportData, this.deviceColumns, '设备档案卡基本数据' + this.getTimeStamp())
  1000. this.$message.success('导出设备成功!')
  1001. },
  1002. // 导出维护项目
  1003. async ExportProject (selection = []) {
  1004. let exportData = []
  1005. console.log('导出维护项目')
  1006. if (selection.length > 0) {
  1007. const sql = `select b.yuan_she_bei_bian as yuanSheBeiBian,b.she_bei_ming_cheng_ as sheBeiMingCheng,a.parent_id_,a.wei_hu_xiang_mu_c as weiHuXiangMuC,a.wei_hu_ri_qi_ as weiHuRiQi,a.wei_hu_lei_xing_ as weiHuLeiXing,a.ri_qi_shu_zi_ as riQiShuZi from t_whzqjxm a,t_sbdj b where a.parent_id_=b.id_ and a.parent_id_ in (${selection.map(i => `'${i}'`).join(',')})`
  1008. const { variables: { data }} = await this.$common.request('sql', sql)
  1009. exportData = data
  1010. }
  1011. this.xlsx(exportData, this.projectColums, '设备维护项目数据' + this.getTimeStamp())
  1012. this.$message.success('导出维护项目成功!')
  1013. },
  1014. // value 转 key
  1015. switchV2K (value, obj) {
  1016. const key = Object.keys(obj).find(key => obj[key] === value)
  1017. return key || ''
  1018. },
  1019. // 转换对象的key
  1020. switchDeviceObj (data, originalObj) {
  1021. const result = []
  1022. // data.forEach(item => {
  1023. // const obj = {}
  1024. // for (const key in item) {
  1025. // obj[this.switchV2K(key, originalObj)] = item[key]
  1026. // }
  1027. // result.push(obj)
  1028. // })
  1029. data.forEach(item => {
  1030. const obj = {}
  1031. for (const key in originalObj) {
  1032. // 对日期格式的数据做兼容处理
  1033. if (item[originalObj[key]] instanceof Date) {
  1034. obj[key] = dayjs(item[originalObj[key]]).add(8, 'hour').format('YYYY-MM-DD') || ''
  1035. } else {
  1036. obj[key] = String(item[originalObj[key]] || '')
  1037. }
  1038. }
  1039. result.push(obj)
  1040. })
  1041. return result
  1042. },
  1043. /* 读取文件 将文件转换为二进制 */
  1044. readFile (file) {
  1045. return new Promise(resolve => {
  1046. const reader = new FileReader()
  1047. reader.readAsBinaryString(file)
  1048. reader.onload = ev => {
  1049. resolve(ev.target.result)
  1050. }
  1051. })
  1052. },
  1053. checkDeviceRequiredFieldsIfEmpty (list, requiredMap) {
  1054. const msgList = []
  1055. list.forEach((item, index) => {
  1056. const invalidFieldNames = []
  1057. Object.entries(requiredMap).forEach(([field, name]) => {
  1058. if (item.weiHuLeiXing === '按需保养' && field === 'weiHuRiQi') {
  1059. console.log('按需pass1')
  1060. } else {
  1061. if (!item[field]) {
  1062. invalidFieldNames.push(name)
  1063. }
  1064. }
  1065. })
  1066. if (invalidFieldNames.length > 0) {
  1067. msgList.push({ row: index + 2, field: invalidFieldNames })
  1068. }
  1069. })
  1070. return msgList
  1071. },
  1072. /**
  1073. * 专门发送提示
  1074. * @param {*} allResult
  1075. * @returns
  1076. */
  1077. sendWarningMessages (allResult, mark = 'range') {
  1078. if (allResult.length < 1) {
  1079. return
  1080. }
  1081. console.log('%c Msg Obj %c', 'background:#FF5733; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;', 'background:transparent', allResult)
  1082. const item = allResult[0]
  1083. switch (mark) {
  1084. case 'required':
  1085. this.$message.warning(`第${item.row}行,字段【${item.field.join(',')}】的值不能为空!`)
  1086. break
  1087. case 'range':
  1088. this.$message.warning(`第${item.row}行,字段【${item.field}】的值【${item.value}】不在限定范围内!`)
  1089. break
  1090. case 'dateFormat':
  1091. this.$message.warning(`第${item.row}行,字段【${item.field}】日期格式错误!格式支持【2024-01-01】、【2024/01/01】,请检查您的数据!`)
  1092. break
  1093. case 'duplicateOriginalDevice':
  1094. this.$message.warning(`${item.field}!`)
  1095. break
  1096. default:
  1097. throw new Error(`${mark}类型未定义!`)
  1098. }
  1099. },
  1100. /**
  1101. * 根据规则校验字段的限定范围
  1102. * @param {*} list
  1103. */
  1104. checkFieldsRange (list, rules) {
  1105. const msgList = []
  1106. for (const ruleKey in rules) {
  1107. const rule = rules[ruleKey]
  1108. const fieldName = ruleKey
  1109. list.forEach((item, index) => {
  1110. const fieldValue = item[rule.field]
  1111. if (fieldValue && !rule.range.includes(fieldValue)) {
  1112. msgList.push({ row: index + 2, field: fieldName, value: fieldValue })
  1113. }
  1114. })
  1115. }
  1116. return msgList
  1117. },
  1118. /**
  1119. * 校验日期字段填写的格式
  1120. * @param {*} list
  1121. * @returns
  1122. */
  1123. checkDateFields (list) {
  1124. const dateRegex = /^(\d{4})[-/](0[1-9]|1[0-2])[-/](0[1-9]|[12]\d|3[01])$/
  1125. for (let i = 0; i < list.length; i++) {
  1126. const row = list[i]
  1127. for (const field in this.dateFieldsMap) {
  1128. if (row[field] && !dateRegex.test(row[field])) {
  1129. console.error('error field:', row[field])
  1130. return [{ row: i + 2, field: this.dateFieldsMap[field] }]
  1131. }
  1132. }
  1133. }
  1134. return []
  1135. },
  1136. checkDuplicateOriginalDeviceNo (arr) {
  1137. const occurrences = {}
  1138. arr.forEach((item, index) => {
  1139. const key = item.yuanSheBeiBian
  1140. if (occurrences[key]) {
  1141. occurrences[key].push(index + 2)
  1142. } else {
  1143. occurrences[key] = [index + 2]
  1144. }
  1145. })
  1146. // 检查是否有重复项(数组长度大于1)
  1147. for (const [key, indices] of Object.entries(occurrences)) {
  1148. if (indices.length > 1) {
  1149. return [{ field: `发现重复的原设备编号:${key} 在第 ${indices.join(', ')} 行` }]
  1150. }
  1151. }
  1152. return []
  1153. },
  1154. /**
  1155. * 负责导入设备数据的第一部分校验,全部成功则返回true
  1156. * @param {*} data
  1157. * @returns
  1158. */
  1159. deviceInvalidPartOne (data) {
  1160. // 校验必填信息
  1161. const invalidResult = this.checkDeviceRequiredFieldsIfEmpty(data, this.requiredFieldMap)
  1162. if (invalidResult.length > 0) {
  1163. this.sendWarningMessages(invalidResult, 'required')
  1164. return false
  1165. }
  1166. // 根据规则校验字段的限定范围
  1167. const allResult = this.checkFieldsRange(data, this.validationRules)
  1168. if (allResult.length > 0) {
  1169. this.sendWarningMessages(allResult, 'range')
  1170. return false
  1171. }
  1172. // 校验日期字段是否符合要求
  1173. const dateResult = this.checkDateFields(data)
  1174. if (dateResult.length > 0) {
  1175. this.sendWarningMessages(dateResult, 'dateFormat')
  1176. return false
  1177. }
  1178. // 校验是否存在重复的原设备编号
  1179. const duplicateOriginalDeviceResult = this.checkDuplicateOriginalDeviceNo(data)
  1180. if (duplicateOriginalDeviceResult.length > 0) {
  1181. this.sendWarningMessages(duplicateOriginalDeviceResult, 'duplicateOriginalDevice')
  1182. return false
  1183. }
  1184. return true
  1185. },
  1186. /**
  1187. * 将日期字段信息格式化为 yyyy-MM-dd
  1188. * @param {*} list
  1189. * @returns
  1190. */
  1191. formatDateFieldsToReal (list) {
  1192. list.forEach(item => {
  1193. this.dateFieldRange.forEach(field => {
  1194. item[field] = item[field]?.replace(/\//g, '-')
  1195. })
  1196. })
  1197. return list
  1198. },
  1199. getNextAlias () {
  1200. return new Promise((resolve, reject) => {
  1201. this.$common.getNextIdByAlias({
  1202. 'alias': 'sbbh'
  1203. }).then(response => {
  1204. resolve(response.data)
  1205. }).catch((error) => {
  1206. reject(error)
  1207. })
  1208. })
  1209. },
  1210. /**
  1211. * 过滤出来excel 的原设备编号存在当前数据库中的数据
  1212. * @param {*} list 导入的数据
  1213. */
  1214. async filterOriginalDeviceNo (list) {
  1215. const uniqueArr = Array.from(new Set(list.map(i => i.yuanSheBeiBian.trim())))
  1216. const sql = `select id_,yuan_she_bei_bian from t_sbdj where find_in_set(yuan_she_bei_bian,'${uniqueArr.join(',')}')`
  1217. const res = await this.$common.request('sql', sql)
  1218. const { data = [] } = res.variables || {}
  1219. const originalDeviceNoList = data.map(i => i.yuan_she_bei_bian.trim())
  1220. // 给要更新的数据加上id (接口需要!!!)
  1221. data.forEach(item => {
  1222. const temp = list.find(i => i.yuanSheBeiBian === item.yuan_she_bei_bian)
  1223. temp.id = item.id_
  1224. })
  1225. return originalDeviceNoList || ''
  1226. },
  1227. /**
  1228. *
  1229. * @param {*} list excel数据
  1230. * @param {*} currentTime 当前时间
  1231. * @param {*} currentApartment 当前部门ID
  1232. * @param {*} currentUser 当前用户ID
  1233. * @param {*} currentPosition 当前地点ID
  1234. */
  1235. async handleBasicData (list, currentTime, currentApartment, currentUser, deptList) {
  1236. // 使用map生成一个异步操作的数组
  1237. const promises = list.map(async (element) => {
  1238. element.bianZhiShiJian = currentTime
  1239. element.bianZhiRen = currentUser
  1240. element.shiFouGuoShen = '已完成'
  1241. const o = deptList?.find(i => i.positionName === element.bianZhiBuMen.trim())
  1242. const { positionId = currentApartment } = o || {}
  1243. element.bianZhiBuMen = positionId
  1244. if (!element.id) {
  1245. // 获取下一个编号
  1246. element.sheBeiShiBieH = await this.getNextAlias()
  1247. }
  1248. })
  1249. // 使用Promise.all并发执行所有异步操作
  1250. await Promise.all(promises)
  1251. },
  1252. /**
  1253. *
  1254. * @param {*} list excel数据
  1255. * @param {*} positionList 现有房间信息
  1256. * @param {*} supplierList 现有供应商信息
  1257. * @param {*} employeeList 现有人员信息
  1258. * @returns
  1259. */
  1260. handleExcelData (list, positionList, employeeList, deviceGroupList) {
  1261. if (list.length < 1) {
  1262. return
  1263. }
  1264. // this.handleSupplierInfo(list, supplierList)
  1265. this.handlePositionInfo(list, positionList)
  1266. this.handlePersonInfo(list, employeeList)
  1267. this.handleDeviceGroupInfo(list, deviceGroupList)
  1268. },
  1269. /**
  1270. *
  1271. * @param {*} list excel数据
  1272. * @param {*} supplierList 现有供应商信息
  1273. */
  1274. handleSupplierInfo (list, supplierList) {
  1275. list.forEach(element => {
  1276. if (element.gongYingShang.trim()) {
  1277. const supplier = supplierList.find(i => i.gong_ying_shang_m === element.gongYingShang.trim())
  1278. if (supplier) {
  1279. element.shiFouQiJianH = supplier.id_
  1280. } else {
  1281. element.shiFouQiJianH = ''
  1282. element.gongYingShang = ''
  1283. }
  1284. } else {
  1285. element.shiFouQiJianH = ''
  1286. }
  1287. if (element.shiYongKeShi.trim()) {
  1288. const supplier = supplierList.find(i => i.gong_ying_shang_m === element.shiYongKeShi.trim())
  1289. if (supplier) {
  1290. element.shiYongKeShi = supplier.id_
  1291. } else {
  1292. element.shiYongKeShi = ''
  1293. }
  1294. } else {
  1295. element.shiYongKeShi = ''
  1296. }
  1297. })
  1298. },
  1299. /**
  1300. *
  1301. * @param {*} list excel数据
  1302. * @param {*} positionList 现有房间信息
  1303. */
  1304. handlePositionInfo (list, positionList) {
  1305. list.forEach(element => {
  1306. if (element.cunFangDiDian !== '') {
  1307. const postion = positionList.find(i => (i.fang_jian_ming_ha.trim() || '') === element.cunFangDiDian.trim())
  1308. if (postion) {
  1309. const positionId = postion.id_
  1310. element.cunFangWeiZhi = positionId
  1311. } else {
  1312. element.cunFangWeiZhi = ''
  1313. element.cunFangDiDian = ''
  1314. }
  1315. } else {
  1316. element.cunFangWeiZhi = ''
  1317. }
  1318. })
  1319. },
  1320. handlePersonInfo (list, employeeList) {
  1321. list.forEach(element => {
  1322. // 处理保管人
  1323. if (element.guanLiRen !== '') {
  1324. const person = employeeList.find(i => i.userName === element.guanLiRen.trim())
  1325. if (person) {
  1326. const personId = person.userId
  1327. element.guanLiRen = personId
  1328. } else {
  1329. element.guanLiRen = ''
  1330. }
  1331. } else {
  1332. element.guanLiRen = ''
  1333. }
  1334. // 处理核查人
  1335. if (element.biXuDeHuanJin !== '') {
  1336. const checkPerson = employeeList.find(i => i.userName === element.biXuDeHuanJin.trim())
  1337. if (checkPerson) {
  1338. const checkPersonId = checkPerson.userId
  1339. element.biXuDeHuanJin = checkPersonId
  1340. } else {
  1341. element.biXuDeHuanJin = ''
  1342. }
  1343. } else {
  1344. element.biXuDeHuanJin = ''
  1345. }
  1346. })
  1347. },
  1348. handleDeviceGroupInfo (list, deviceGroupList) {
  1349. list.forEach(element => {
  1350. const result = []
  1351. const { weiHuFangShi } = element
  1352. const valList = weiHuFangShi.trim()?.split(',')
  1353. valList.forEach(item => result.push((deviceGroupList?.find(i => i.wei_hu_gang_wei_ === item)?.id_) || ''))
  1354. element.weiHuFangShi = result.join(',')
  1355. })
  1356. },
  1357. async handleUploadChange1 (file) {
  1358. const dataBinary = await this.readFile(file.target.files[0])
  1359. file.target.value = null // 注意上传后要将input的值设为空
  1360. const workBook = xlsx.read(dataBinary, { type: 'binary', cellDates: true })
  1361. const workSheet = workBook.Sheets[workBook.SheetNames[0]]
  1362. const data = xlsx.utils.sheet_to_json(workSheet)
  1363. let importData = this.switchDeviceObj(data, this.deviceColumns)
  1364. importData.forEach(i => {
  1365. delete i.sheBeiShiBieH // 设备编号需自动生成
  1366. // i.sheBeiZhuangTa = '合格'
  1367. const keyFound = Object.entries(this.stateList).find(([key, value]) => value === i.sheBeiZhuangTa)
  1368. if (keyFound) {
  1369. i.sheBeiZhuangTa = keyFound[0]
  1370. }
  1371. })
  1372. const { userList = [], deptList = [] } = this.$store.getters || {}
  1373. const positionSql = `select id_,fang_jian_ming_ha from t_jjqfjb ` // 房间信息
  1374. // const supplierSql = `select id_,gong_ying_shang_m from t_hggysxx ` // 供应商信息
  1375. const deviceGroupSql = `select id_,suo_shu_bu_men_,wei_hu_gang_wei_ from t_sbwhgwpzb` // 设备分组信息
  1376. const currentTime = dayjs().format('YYYY-MM-DD HH:mm')
  1377. const currentApartment = this.$store.getters.userInfo.employee.positions
  1378. const currentUser = this.userId
  1379. const partOneInvalidResult = this.deviceInvalidPartOne(importData)
  1380. if (!partOneInvalidResult) return
  1381. importData = this.formatDateFieldsToReal(importData)
  1382. this.loading = true
  1383. Promise.all([this.$common.request('sql', positionSql), this.$common.request('sql', deviceGroupSql)]).then(async ([res1, res2, res3]) => {
  1384. console.log('sss')
  1385. const { data: positionList = [] } = res1.variables || {}
  1386. // const { data: supplierList = [] } = res2.variables || {}
  1387. const { data: deviceGroupList = [] } = res3.variables || {}
  1388. // 根据原设备编号去重,检验原设备编号是否在数据库中存在
  1389. const originalDeviceNoList = await this.filterOriginalDeviceNo(importData)
  1390. await this.handleBasicData(importData, currentTime, currentApartment, currentUser, deptList)
  1391. this.handleExcelData(importData, positionList, userList, deviceGroupList)
  1392. // 分离出 已存在的设备,和新设备
  1393. const newDeviceList = importData.filter(i => !originalDeviceNoList.includes(i.yuanSheBeiBian.trim()))
  1394. const existDeviceList = importData.filter(i => originalDeviceNoList.includes(i.yuanSheBeiBian.trim()))
  1395. this.loading = false
  1396. this.$confirm(`<span style="color:#f56c6c; font-size: 18px; font-weight: 600;">
  1397. 经系统判定</span><br>1.预期新导入设备的数量为 ${newDeviceList.length} 台!<br>
  1398. 2.预期更新已存在的设备数量为 ${existDeviceList.length} 台!<br>
  1399. <span style="color:#f56c6c;">Tips:请确认数据无误再点击确定进行导入</span><br><span style="color:#f56c6c; font-size: 18px; font-weight: 600;">请谨慎操作!</span>`, '提示', {
  1400. confirmButtonText: '确定',
  1401. cancelButtonText: '取消',
  1402. dangerouslyUseHTMLString: true,
  1403. type: 'warning'
  1404. }).then(async () => {
  1405. await this.doImportDevice(importData)
  1406. this.loading = true
  1407. setTimeout(() => {
  1408. this.loading = false
  1409. this.$message.success('设备数据导入成功!')
  1410. this.getDatas()
  1411. }, 1000)
  1412. }).catch(() => { })
  1413. }).catch(() => {
  1414. this.loading = false
  1415. })
  1416. },
  1417. async doImportDevice (existDeviceList, currentPosition) {
  1418. this.loading = true
  1419. const allRequests = []
  1420. for (let index = 0; index < existDeviceList.length; index++) {
  1421. const item = existDeviceList[index]
  1422. let params = {}
  1423. if (item.id) {
  1424. // 获取设备数据
  1425. const { data: itemData } = await getequipmentCard({ id: item.id })
  1426. params = { ...itemData, ...item } // 合并数据
  1427. } else {
  1428. params = item // 直接使用当前 item
  1429. }
  1430. // 将每个 saveEquipmentCard 请求加入到 allRequests 数组中
  1431. allRequests.push(saveEquipmentCard(params))
  1432. }
  1433. // 等待所有异步请求完成
  1434. console.log(allRequests, '000')
  1435. await Promise.all(allRequests)
  1436. this.loading = false
  1437. },
  1438. generateDayRule () {
  1439. const days = ['每周1', '每周2', '每周3', '每周4', '每周5', '每周6', '每周7']
  1440. let combinations = []
  1441. for (let length = 1; length <= days.length; length++) {
  1442. this.generateCombinations([], days, combinations)
  1443. }
  1444. combinations = combinations.map(comb => '每周' + comb.map(item => item.slice(2)).join(','))
  1445. combinations.push('每天')
  1446. return combinations
  1447. },
  1448. generateRule (num, prefix, suffix) {
  1449. return Array.from({ length: num }, (_, i) => prefix + `${i + 1}` + suffix)
  1450. },
  1451. generateCombinations (current, remaining, results) {
  1452. if (remaining.length === 0) {
  1453. results.push(current)
  1454. return
  1455. }
  1456. const first = remaining[0]
  1457. const rest = remaining.slice(1)
  1458. // 包括当前数字和不包括当前数字两种情况
  1459. this.generateCombinations(current.concat([first]), rest, results)
  1460. this.generateCombinations(current, rest, results)
  1461. },
  1462. /**
  1463. * 负责导入设备维护项目数据的第一部分校验,全部成功则返回true
  1464. * @param {*} data
  1465. * @returns
  1466. */
  1467. maintenanceInvalidPartOne (data) {
  1468. // 1、对数据进行清洗校验(设备编号不能为空,维护周期、维护项目亦不可为空)
  1469. const invalidResult = this.checkDeviceRequiredFieldsIfEmpty(data, this.maintenanceRequiredFieldMap)
  1470. if (invalidResult.length > 0) {
  1471. this.sendWarningMessages(invalidResult, 'required')
  1472. return false
  1473. }
  1474. // 根据规则校验字段的限定范围
  1475. const allResult = this.checkFieldsRange(data, this.maintenanceValidationRules)
  1476. if (allResult.length > 0) {
  1477. this.sendWarningMessages(allResult, 'range')
  1478. return false
  1479. }
  1480. // 根据规则校验维护周期对应的维护日期的限定范围
  1481. const result = this.checkMaintenanceDateRange(data, this.maintenanceDateValidationRules)
  1482. if (result.length > 0) {
  1483. this.sendWarningMessages(result, 'range')
  1484. return false
  1485. }
  1486. return true
  1487. },
  1488. /**
  1489. * 根据规则校验维护周期对应的维护日期的限定范围
  1490. */
  1491. checkMaintenanceDateRange (list, rules) {
  1492. const msgList = []
  1493. list.forEach(({ weiHuLeiXing: type, weiHuRiQi: exactDate }, index) => {
  1494. if (type === '按需保养') {
  1495. console.log('按需pass2')
  1496. } else {
  1497. if (!rules[type].includes(exactDate)) {
  1498. msgList.push({ row: index + 2, field: '维护日期', value: exactDate })
  1499. }
  1500. }
  1501. })
  1502. return msgList
  1503. },
  1504. async handleUploadChange2 (file) {
  1505. const dataBinary = await this.readFile(file.target.files[0])
  1506. file.target.value = null // 注意上传后要将input的值设为空
  1507. const workBook = xlsx.read(dataBinary, { type: 'binary', cellDates: true })
  1508. const workSheet = workBook.Sheets[workBook.SheetNames[0]]
  1509. const data = xlsx.utils.sheet_to_json(workSheet)
  1510. const importData = this.switchDeviceObj(data, this.projectColums)
  1511. console.log(importData)
  1512. importData.forEach(item => {
  1513. if (item.weiHuLeiXing === '按需保养') {
  1514. item.weiHuRiQi = '/'
  1515. }
  1516. })
  1517. const { userList = [], deptList = [] } = this.$store.getters || {}
  1518. const positionSql = `select id_,fang_jian_ming_ha from t_jjqfjb ` // 房间信息
  1519. // const supplierSql = `select id_,gong_ying_shang_m from t_gysxxb ` // 供应商信息
  1520. const deviceGroupSql = `select id_,suo_shu_bu_men_,wei_hu_gang_wei_ from t_sbwhgwpzb` // 设备分组信息
  1521. const currentTime = dayjs().format('YYYY-MM-DD HH:mm')
  1522. const currentApartment = this.$store.getters.userInfo.employee.positions
  1523. const currentUser = this.userId
  1524. const partOneInvalidResult = this.maintenanceInvalidPartOne(importData)
  1525. if (!partOneInvalidResult) return
  1526. // 2、根据原设备编号去重,检验原设备编号是否在数据库中存在,如有不存在的数据,不进行导入,并提示用户
  1527. const uniqueArr = Array.from(new Set(importData.map(i => i.yuanSheBeiBian.trim())))
  1528. /* 3、根据去重的设备编号去查对应的设备ID,然后拼接data数据,赋值设备ID*/
  1529. const sql = `select id_,yuan_she_bei_bian from t_sbdj where find_in_set(yuan_she_bei_bian,'${uniqueArr.join(',')}')`
  1530. this.$common.request('sql', sql).then(async res => {
  1531. const deviceNoWithIdlist = res.variables.data
  1532. console.log(deviceNoWithIdlist, ' <=> ', uniqueArr)
  1533. const deviceNoSet = new Set(deviceNoWithIdlist.map(i => i.yuan_she_bei_bian))
  1534. const missStr = uniqueArr.filter(i => !deviceNoSet.has(i)).join(',') || ''
  1535. if (missStr !== '') {
  1536. this.$message.error(`设备维护项目数据中包含不存在于设备档案的原设备编号!具体原设备编号为:${missStr}`)
  1537. return
  1538. }
  1539. importData.forEach(item => {
  1540. item.id = deviceNoWithIdlist.find(i => i.yuan_she_bei_bian === item.yuanSheBeiBian).id_
  1541. })
  1542. const resultList = []
  1543. importData.forEach(item => {
  1544. const flag = item.weiHuLeiXing === '日保养'
  1545. const match = item.weiHuRiQi?.match(/\d+/g)
  1546. const o = {
  1547. id: item.id,
  1548. weiHuLeiXing: item.weiHuLeiXing.trim(),
  1549. weiHuRiQi: item.weiHuRiQi?.trim() || '',
  1550. weiHuXiangMuC: item.weiHuXiangMuC.trim(),
  1551. riQiShuZi: match ? (flag ? match.join(',') : match[0]) : ''
  1552. }
  1553. if (o.weiHuLeiXing === '日保养' && o.weiHuRiQi === '每天') o.riQiShuZi = '1,2,3,4,5,6,7'
  1554. resultList.push(o)
  1555. })
  1556. // 4、根据用户选择 进行全量替换|增量添加
  1557. await this.doProjectImport(deviceNoWithIdlist, resultList, this.ImportDeviceType)
  1558. this.$message.success('维护项目数据' + this.ImportDeviceType + '成功!')
  1559. })
  1560. },
  1561. async doProjectImport (deviceNoWithIdlist, resultList, type) {
  1562. this.loading = true
  1563. const allRequests = []
  1564. deviceNoWithIdlist.forEach(async item => {
  1565. const { data: itemData } = await getequipmentCard({ id: item.id_ })
  1566. const temp = resultList.filter(i => i.id === item.id_).map(ii => {
  1567. delete ii.id
  1568. return ii
  1569. })
  1570. let params = {}
  1571. if (type === '增量添加') { // 增量
  1572. params = {
  1573. ...itemData,
  1574. maintenanceItemPoList: [...itemData.maintenanceItemPoList, ...temp]
  1575. }
  1576. } else if (type === '全量替换') { // 全量
  1577. params = {
  1578. ...itemData,
  1579. maintenanceItemPoList: temp
  1580. }
  1581. }
  1582. console.log('params', params)
  1583. allRequests.push(saveEquipmentCard(params))
  1584. })
  1585. await Promise.all(allRequests)
  1586. this.loading = false
  1587. }
  1588. }
  1589. }
  1590. </script>
  1591. <style lang="scss" scoped>
  1592. .icon-image{
  1593. width: 36px;
  1594. }
  1595. .device-image{
  1596. width: 152px;
  1597. height: 110px;
  1598. }
  1599. .title{
  1600. font-size: 12px;
  1601. font-weight: 900;
  1602. color: #333;
  1603. margin: 0 0 14px 20px;
  1604. }
  1605. .ctx{
  1606. margin: 0 0 0 20px;
  1607. .item{
  1608. .cusitem{
  1609. margin: -8px 0;
  1610. display: flex;
  1611. align-items: center;
  1612. }
  1613. .span{
  1614. min-width:60px
  1615. }
  1616. margin: 6px 0;
  1617. color: #999;
  1618. }
  1619. }
  1620. ::v-deep {
  1621. .el-form-item__label{
  1622. text-align: left;
  1623. font-size: 12px !important;
  1624. }
  1625. .el-form-item__ctx{
  1626. font-size: 12px !important;
  1627. }
  1628. }
  1629. </style>