facilityEnvConfig.vue 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="dialogVisible"
  5. :close-on-click-modal="false"
  6. :close-on-press-escape="false"
  7. :show-close="false"
  8. append-to-body
  9. fullscreen
  10. class="dialog paper-detail-dialog"
  11. top="0"
  12. >
  13. <div class="container">
  14. <div class="main">
  15. <div class="form">
  16. <el-form ref="form" :model="form" label-width="120px" :rules="rules">
  17. <el-row>
  18. <el-col :span="8">
  19. <el-form-item label="类型:" prop="lei_xing_">
  20. <el-select v-model="form.lei_xing_" placeholder="请选择" size="mini" style="width:80%">
  21. <el-option
  22. v-for="(value,key) in config"
  23. :key="key"
  24. :label="key.split('-')[1]"
  25. :value="key"
  26. />
  27. </el-select>
  28. </el-form-item>
  29. </el-col>
  30. </el-row>
  31. <el-row v-if="isShowDevice">
  32. <el-col :span="12">
  33. <el-form-item label="设备编号:">
  34. <ibps-custom-dialog
  35. v-model="form.she_bei_bian_hao_"
  36. size="mini"
  37. template-key="sbxzmcgl"
  38. :multiple="true"
  39. :disabled="false"
  40. type="dialog"
  41. class="custom-dialog"
  42. placeholder="请选择设备"
  43. icon="el-icon-search"
  44. style="width:80%"
  45. />
  46. </el-form-item>
  47. </el-col>
  48. </el-row>
  49. <el-alert
  50. title="默认数据,配置详情中的同名字段为空则使用以下默认数据"
  51. type="success"
  52. :closable="false"
  53. />
  54. <el-row>
  55. <el-col :span="12">
  56. <el-form-item label="部门:">
  57. <ibps-user-selector
  58. v-model="form.bian_zhi_bu_men_"
  59. size="mini"
  60. type="position"
  61. readonly-text="text"
  62. :disabled="false"
  63. :multiple="false"
  64. style="width:80%"
  65. />
  66. </el-form-item>
  67. </el-col>
  68. <el-col :span="12">
  69. <el-form-item label="监测岗位:">
  70. <el-select v-model="form.gang_wei_" placeholder="请选择" size="mini" style="width:80%">
  71. <el-option
  72. v-for="item in jianCeGangWeiList"
  73. :key="item.id_"
  74. :label="item.wei_hu_gang_wei_"
  75. :value="item.wei_hu_gang_wei_"
  76. />
  77. </el-select>
  78. </el-form-item>
  79. </el-col>
  80. </el-row>
  81. <el-row>
  82. <el-col :span="12">
  83. <el-form-item label="监测周期:">
  84. <el-select v-model="form.zhou_qi_" placeholder="请选择" size="mini" style="width:80%">
  85. <el-option
  86. v-for="item in period"
  87. :key="item.value"
  88. :label="item.label"
  89. :value="item.value"
  90. />
  91. </el-select>
  92. </el-form-item>
  93. </el-col>
  94. </el-row>
  95. <el-row v-if="form.zhou_qi_!==''">
  96. <el-col :span="12">
  97. <el-form-item :label="labelShow">
  98. <el-checkbox-group v-if="form.zhou_qi_==='每日'" v-model="dayCheck">
  99. <el-checkbox :label="1">周一</el-checkbox>
  100. <el-checkbox :label="2">周二</el-checkbox>
  101. <el-checkbox :label="3">周三</el-checkbox>
  102. <el-checkbox :label="4">周四</el-checkbox>
  103. <el-checkbox :label="5">周五</el-checkbox>
  104. <el-checkbox :label="6">周六</el-checkbox>
  105. <el-checkbox :label="7">周日</el-checkbox>
  106. </el-checkbox-group>
  107. <template v-if="form.zhou_qi_==='每周'">
  108. <el-radio v-model="weekCheck" :label="1">周一</el-radio>
  109. <el-radio v-model="weekCheck" :label="2">周二</el-radio>
  110. <el-radio v-model="weekCheck" :label="3">周三</el-radio>
  111. <el-radio v-model="weekCheck" :label="4">周四</el-radio>
  112. <el-radio v-model="weekCheck" :label="5">周五</el-radio>
  113. <el-radio v-model="weekCheck" :label="6">周六</el-radio>
  114. <el-radio v-model="weekCheck" :label="7">周日</el-radio>
  115. </template>
  116. <el-select v-if="form.zhou_qi_==='每月'" v-model="monthCheck" placeholder="请选择">
  117. <el-option
  118. v-for="item in 28"
  119. :key="item"
  120. :label="`第${item}天`"
  121. :value="item"
  122. />
  123. </el-select>
  124. <el-select v-if="form.zhou_qi_==='每季度'" v-model="quarterCheck" placeholder="请选择">
  125. <el-option
  126. v-for="item in 3"
  127. :key="item"
  128. :label="`第${item}个月`"
  129. :value="item"
  130. />
  131. </el-select>
  132. <el-select v-if="form.zhou_qi_==='每半年'" v-model="halfYearCheck" placeholder="请选择">
  133. <el-option
  134. v-for="item in 6"
  135. :key="item"
  136. :label="`第${item}个月`"
  137. :value="item"
  138. />
  139. </el-select>
  140. <el-select v-if="form.zhou_qi_==='每年'" v-model="yearCheck" placeholder="请选择">
  141. <el-option
  142. v-for="item in 12"
  143. :key="item"
  144. :label="`第${item}个月`"
  145. :value="item"
  146. />
  147. </el-select>
  148. </el-form-item>
  149. </el-col>
  150. <el-col v-if="nextDate" :span="12">
  151. <el-form-item label="下次监测日期为:">
  152. <el-tag>{{ nextDate }}</el-tag>
  153. </el-form-item>
  154. </el-col>
  155. </el-row>
  156. <el-row>
  157. <el-col :span="12">
  158. <el-form-item label="控制条件:">
  159. <el-input v-model="form.tiao_jian_" type="textarea" :rows="2" size="mini" style="width:80%" />
  160. </el-form-item>
  161. </el-col>
  162. </el-row>
  163. <el-row>
  164. <el-col :span="12">
  165. <el-form-item v-if="labelText.label1" :label="labelText.label1">
  166. <el-input-number v-model="form.temperatureMin" size="mini" controls-position="right" :min="-100" :max="form.temperatureMax" :step="1" />
  167. <el-input-number v-model="form.temperatureMax" size="mini" controls-position="right" :min="form.temperatureMin" :max="100" :step="1" />
  168. (℃)
  169. </el-form-item>
  170. </el-col>
  171. <el-col :span="12">
  172. <el-form-item v-if="labelText.label2" :label="labelText.label2">
  173. <el-input-number v-model="form.humidityMin" size="mini" controls-position="right" :min="-100" :max="form.humidityMax" :step="1" />
  174. <el-input-number v-model="form.humidityMax" size="mini" controls-position="right" :min="form.humidityMin" :max="100" :step="1" />
  175. (%)
  176. </el-form-item>
  177. </el-col>
  178. </el-row>
  179. </el-form>
  180. </div>
  181. <div class="table">
  182. <div class="btn">
  183. <el-upload
  184. ref="uploadRef"
  185. class="upload-demo"
  186. action=""
  187. accept=".xlsx,.xls"
  188. :auto-upload="false"
  189. :show-file-list="false"
  190. :on-change="handleUploadChange"
  191. >
  192. <el-button type="primary" size="mini" icon="el-icon-upload2">导入</el-button>
  193. </el-upload>
  194. <el-button type="primary" size="mini" icon="el-icon-download" @click="exportExcel">导出</el-button>
  195. <el-button type="success" size="mini" icon="el-icon-plus" @click="openDialog">添加</el-button>
  196. <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeItem">删除</el-button>
  197. <el-button v-if="subForm.length>0" type="info" size="mini" icon="el-icon-setting" @click="settingData">使用默认数据</el-button>
  198. </div>
  199. <el-table
  200. :data="showPaperList"
  201. style="width: 100%"
  202. border
  203. @selection-change="handleSelectionChange"
  204. >
  205. <el-table-column
  206. width="50"
  207. type="selection"
  208. />
  209. <el-table-column
  210. prop=""
  211. label="序号"
  212. width="50"
  213. type="index"
  214. :index="showIndex"
  215. />
  216. <el-table-column
  217. prop="bu_men_"
  218. label="部门"
  219. width="100"
  220. >
  221. <template slot-scope="{row}">
  222. <ibps-user-selector
  223. type="position"
  224. :value="row.bu_men_"
  225. readonly-text="text"
  226. :disabled="true"
  227. :multiple="true"
  228. />
  229. </template>
  230. </el-table-column>
  231. <el-table-column
  232. prop="qu_yu_"
  233. label="区域"
  234. />
  235. <el-table-column
  236. prop="fang_jian_"
  237. label="房间"
  238. />
  239. <el-table-column
  240. v-if="isShowDevice"
  241. prop="deviceno1_"
  242. label="被控设备编号"
  243. />
  244. <el-table-column
  245. v-if="isShowDevice"
  246. prop="devicename1_"
  247. label="被控设备名称"
  248. />
  249. <el-table-column
  250. prop="deviceno2_"
  251. label="监控设备"
  252. />
  253. <el-table-column
  254. prop="jian_ce_zhou_qi_"
  255. label="监测周期"
  256. width="80"
  257. />
  258. <el-table-column
  259. prop="jian_ce_ri_qi_"
  260. label="监测日期"
  261. width="110"
  262. />
  263. <el-table-column
  264. prop="jian_ce_gang_wei_"
  265. label="监测岗位"
  266. />
  267. <el-table-column
  268. prop="shi_fou_qi_yong_"
  269. label="是否启用"
  270. width="80"
  271. >
  272. <template slot-scope="{row}">
  273. <el-tag v-if="row.shi_fou_qi_yong_==='1'">启用</el-tag>
  274. <el-tag v-if="row.shi_fou_qi_yong_==='0'" type="danger">停用</el-tag>
  275. </template>
  276. </el-table-column>
  277. <el-table-column
  278. fixed="right"
  279. prop=""
  280. label="操作栏目"
  281. >
  282. <template slot-scope="{row}">
  283. <el-button type="primary" icon="el-icon-edit" size="mini" @click="openDialog(row)">编辑</el-button>
  284. </template>
  285. </el-table-column>
  286. </el-table>
  287. <el-pagination
  288. style="margin-top: 5px; padding-bottom: 10px"
  289. :current-page="currentPage"
  290. :page-sizes="[10, 20,30, 50]"
  291. :page-size="pageSize"
  292. layout="prev,pager,next,jumper,sizes,->,total"
  293. :total="subForm.length"
  294. @size-change="handleSizeChange"
  295. @current-change="handleCurrentChange"
  296. />
  297. </div>
  298. </div>
  299. </div>
  300. <div slot="footer" class="el-dialog--center">
  301. <ibps-toolbar :actions="toolbars" @action-event="handleActionEvent" />
  302. </div>
  303. <FecDialog ref="FecDialogRef" @onSubmit="sonSubmit" />
  304. </el-dialog>
  305. </template>
  306. <script>
  307. import IbpsAttachment from '@/business/platform/file/attachment/selector'
  308. import ibpsUserSelector from '@/business/platform/org/selector'
  309. import xlsx from 'xlsx'
  310. import fs from 'file-saver'
  311. import FecDialog from './fecDialog.vue'
  312. export default {
  313. components: {
  314. ibpsUserSelector,
  315. IbpsAttachment,
  316. FecDialog,
  317. IbpsCustomDialog: () => import('@/business/platform/data/templaterender/custom-dialog')
  318. },
  319. props: {
  320. parentData: {
  321. type: [Object, Array],
  322. default: () => {}
  323. },
  324. visible: {
  325. type: Boolean,
  326. default: false
  327. }
  328. },
  329. data () {
  330. const { userId, level = {}} = this.$store.getters || {}
  331. return {
  332. level: level.second || level.first,
  333. userId: userId,
  334. pageSize: 10,
  335. currentPage: 1,
  336. multipleSelection: [],
  337. nextDate: '',
  338. rules: {
  339. lei_xing_: [
  340. { required: true, message: '请选择类型', trigger: 'blur' }
  341. ]
  342. },
  343. jianCeGangWeiList: [],
  344. dialogVisible: true,
  345. title: '设施环境配置表',
  346. toolbars: [{ key: 'save', label: '保存' }, { key: 'cancel', label: '退出' }],
  347. dayCheck: [],
  348. weekCheck: '',
  349. monthCheck: '',
  350. quarterCheck: '',
  351. halfYearCheck: '',
  352. yearCheck: '',
  353. form: {
  354. temperatureMin: 0,
  355. temperatureMax: 0,
  356. humidityMin: 0,
  357. humidityMax: 0,
  358. di_dian_: level.second || level.first,
  359. bian_zhi_ren_: userId,
  360. lei_xing_: '',
  361. bian_zhi_bu_men_: '',
  362. zhou_qi_: '',
  363. gang_wei_: '',
  364. tiao_jian_: '',
  365. default_environme: '',
  366. she_bei_bian_hao_: '', // 设备编号
  367. jian_ce_ri_qi_: '',
  368. ri_qi_lie_biao_: '',
  369. mo_kuai_lu_jing_: ''
  370. },
  371. subForm: [
  372. ],
  373. period: [
  374. { label: '日监测', value: '每日' },
  375. { label: '周监测', value: '每周' },
  376. { label: '月监测', value: '每月' },
  377. { label: '季度监测', value: '每季度' },
  378. { label: '半年监测', value: '每半年' },
  379. { label: '年监测', value: '每年' }
  380. ],
  381. config: {
  382. '01-室内温湿度监控': {
  383. keyword: '',
  384. path: '/sshjgl/wdjc/snwsdjkcd'
  385. },
  386. '02-冰箱温度监控': {
  387. keyword: '冰箱,冰柜,冷藏,冷冻,低温,恒温,生化培养箱',
  388. path: '/sshjgl/wdjc/bxwdjc',
  389. showDevice: true
  390. },
  391. '03-温浴箱温度监控': {
  392. keyword: '',
  393. path: '/sshjgl/wdjc/wyxwdjkywh',
  394. showDevice: true
  395. },
  396. '04-阴凉柜温度监控': {
  397. keyword: '',
  398. path: '/sshjgl/wdjc/ylgwdjc',
  399. showDevice: true
  400. },
  401. '05-纯水机水质监测': {
  402. keyword: '',
  403. path: '/sshjgl/csjszjcb',
  404. showDevice: true
  405. },
  406. '06-每日安全检查': {
  407. keyword: '',
  408. path: '/sshjgl/aqgl/mraqjc'
  409. },
  410. // '07-每月安全检查': {
  411. // keyword: '',
  412. // path: '/sshjgl/aqgl/myaqjc'
  413. // },
  414. '08-含氯有效性监测': {
  415. keyword: '',
  416. path: '/sshjgl/aqgl/hlyxxjc'
  417. },
  418. // '09-紫外灯辐照测定': {
  419. // keyword: '',
  420. // path: '/sshjgl/aqgl/zwdfzd',
  421. // showDevice: true
  422. // },
  423. '10-洗眼器检查': {
  424. keyword: '',
  425. path: '/sshjgl/aqgl/xyqjc',
  426. showDevice: true
  427. },
  428. '11-紧急淋浴器检查': {
  429. keyword: '',
  430. path: '/sshjgl/aqgl/jjlyqjc',
  431. showDevice: true
  432. },
  433. '12-紫外灯消毒': {
  434. keyword: '',
  435. path: '/sshjgl/aqgl/jykzwdxdjlb',
  436. showDevice: true
  437. },
  438. '13-高压灭菌': {
  439. keyword: '',
  440. path: '/sshjgl/aqgl/gymjjlb',
  441. showDevice: true
  442. },
  443. '14-空气消毒机': {
  444. keyword: '',
  445. path: '/sshjgl/aqgl/xdjsyjlb',
  446. showDevice: true
  447. }
  448. },
  449. listHander: {
  450. bu_men_: '部门',
  451. qu_yu_: '区域',
  452. fang_jian_: '房间',
  453. jian_ce_zhou_qi_: '监测周期',
  454. jian_ce_ri_qi_: '监测日期',
  455. jian_ce_gang_wei_: '监测岗位',
  456. kong_zhi_tiao_jia: '控制条件',
  457. xiu_zheng_shi_du_: '湿度修正值',
  458. xiu_zheng_wen_du_: '温度修正值',
  459. deviceno1_: '被控设备编号',
  460. devicename1_: '被控设备名称',
  461. deviceno2_: '监控设备编号'
  462. },
  463. subIdList: [],
  464. isFirstDevice: true
  465. }
  466. },
  467. computed: {
  468. showPaperList () {
  469. const start = (this.currentPage - 1) * this.pageSize
  470. const end = start + this.pageSize
  471. return this.subForm.slice(start, end)
  472. },
  473. isShowDevice () {
  474. return this.form.lei_xing_ !== '01-室内温湿度监控' && this.form.lei_xing_ !== '06-每日安全检查' && this.form.lei_xing_ !== '08-含氯有效性监测'
  475. },
  476. isEdit () {
  477. return this.parentData instanceof Object && this.parentData.mainId
  478. },
  479. labelShow () {
  480. return this.form.zhou_qi_.split('每')[1] + '监测日期:'
  481. },
  482. labelText () {
  483. switch (this.form.lei_xing_) {
  484. case '02-冰箱温度监控':
  485. return { label1: '冷藏温度范围限值:', label2: '冷冻温度范围限值:' }
  486. case '03-温浴箱温度监控':
  487. case '04-阴凉柜温度监控':
  488. return { label1: '温度范围限值:', label2: '' }
  489. case '05-纯水机水质监测':
  490. case '06-每日安全检查':
  491. case '08-含氯有效性监测':
  492. case '10-洗眼器检查':
  493. case '11-紧急淋浴器检查':
  494. case '13-高压灭菌':
  495. case '14-空气消毒机':
  496. case '12-紫外灯消毒':
  497. return { label1: '', label2: '' }
  498. default:
  499. return { label1: '温度范围限值:', label2: '湿度范围限值:' }
  500. }
  501. }
  502. },
  503. watch: {
  504. 'form.temperatureMin' (val) {
  505. this.form.default_environme = this.formatEnv(this.form.temperatureMax, this.form.temperatureMin, this.form.humidityMax, this.form.humidityMin)
  506. },
  507. 'form.temperatureMax' (val) {
  508. this.form.default_environme = this.formatEnv(this.form.temperatureMax, this.form.temperatureMin, this.form.humidityMax, this.form.humidityMin)
  509. },
  510. 'form.humidityMin' (val) {
  511. this.form.default_environme = this.formatEnv(this.form.temperatureMax, this.form.temperatureMin, this.form.humidityMax, this.form.humidityMin)
  512. },
  513. 'form.humidityMax' (val) {
  514. this.form.default_environme = this.formatEnv(this.form.temperatureMax, this.form.temperatureMin, this.form.humidityMax, this.form.humidityMin)
  515. },
  516. 'form.she_bei_bian_hao_' (val) {
  517. if (!this.isFirstDevice) {
  518. const sql = `select yuan_she_bei_bian,she_bei_ming_cheng_ from t_sbdj where find_in_set(id_, '${val}')`
  519. this.$common.request('sql', sql).then(res => {
  520. const { data = [] } = res.variables || {}
  521. data.forEach(item => {
  522. const bianHao = item.yuan_she_bei_bian
  523. const mingChneg = item.she_bei_ming_cheng_
  524. const t = this.subForm.find(sub => sub.deviceno1_ === bianHao)
  525. if (!t) {
  526. this.subForm.push({
  527. deviceno1_: bianHao,
  528. devicename1_: mingChneg,
  529. shi_fou_qi_yong_: '1',
  530. bu_men_: this.form.bian_zhi_bu_men_,
  531. jian_ce_gang_wei_: this.form.gang_wei_,
  532. jian_ce_zhou_qi_: this.form.zhou_qi_,
  533. kong_zhi_tiao_jia: this.form.tiao_jian_,
  534. environment_range: this.form.default_environme,
  535. xiu_zheng_shi_du_: '',
  536. xiu_zheng_wen_du_: '',
  537. fang_jian_: '',
  538. qu_yu_: '',
  539. deviceno2_: '',
  540. jian_ce_ri_qi_: this.form.jian_ce_ri_qi_,
  541. ri_qi_lie_biao_: this.form.ri_qi_lie_biao_,
  542. zi_wai_deng_wai_j: this.$utils.guid()
  543. })
  544. }
  545. })
  546. })
  547. }
  548. },
  549. 'form.lei_xing_' (val) {
  550. this.form.mo_kuai_lu_jing_ = this.config[val].path
  551. },
  552. 'form.zhou_qi_' (val) {
  553. this.dayCheck = []
  554. this.weekCheck = ''
  555. this.monthCheck = ''
  556. this.quarterCheck = ''
  557. this.halfYearCheck = ''
  558. this.yearCheck = ''
  559. this.nextDate = ''
  560. },
  561. dayCheck: {
  562. handler: function (val, oldVal) {
  563. this.formatRiQi()
  564. if (val.length === 0) {
  565. this.nextDate = ''
  566. return
  567. }
  568. const temp_val = JSON.parse(JSON.stringify(val))
  569. const today = new Date()
  570. temp_val.sort(function (a, b) {
  571. return a - b
  572. })
  573. const num = temp_val.findIndex(e => e > today.getDay())
  574. if (temp_val.length > 0 && num !== -1) {
  575. this.nextDate = this.getDayDate(temp_val[num], 0)
  576. } else if (temp_val.length > 0 && num === -1) {
  577. this.nextDate = this.getDayDate(temp_val[0], 1)
  578. } else {
  579. this.nextDate = ''
  580. }
  581. },
  582. immediate: true
  583. },
  584. weekCheck: {
  585. handler: function (val, oldVal) {
  586. this.formatRiQi()
  587. if (val === '') {
  588. this.nextDate = ''
  589. return
  590. }
  591. const today = new Date()
  592. const weekNum = []
  593. weekNum.push(val)
  594. const num = weekNum.findIndex(e => e > today.getDay())
  595. if (val !== '' && num !== -1) {
  596. this.nextDate = this.getDayDate(weekNum[0], 0)
  597. } else if (val !== '' && num === -1) {
  598. this.nextDate = this.getDayDate(weekNum[0], 1)
  599. } else {
  600. this.nextDate = ''
  601. }
  602. },
  603. immediate: true
  604. },
  605. monthCheck: {
  606. handler: function (val, oldVal) {
  607. this.formatRiQi()
  608. if (val === '') {
  609. this.nextDate = ''
  610. return
  611. }
  612. const today = new Date()
  613. const day = today.getDate()
  614. const nextMonth = this.getNextMonthDate(today, val, 1)
  615. const currentMonth = this.getNextMonthDate(today, val, 0)
  616. this.nextDate = val > day ? currentMonth : nextMonth
  617. }
  618. // immediate: true
  619. },
  620. quarterCheck: {
  621. handler: function (val, oldVal) {
  622. this.formatRiQi()
  623. if (val === '') {
  624. this.nextDate = ''
  625. return
  626. }
  627. const quarterList = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
  628. const today = new Date()
  629. const month = today.getMonth() + 1
  630. const qu = this.getQuarter(today)
  631. const nowM = quarterList[qu - 1][val - 1]
  632. const nextM = quarterList[qu][val - 1]
  633. const endMonth = month >= nowM ? nextM : nowM
  634. const yearPJ = today.getFullYear()
  635. const monthPJ = endMonth > 9 ? endMonth : '0' + endMonth
  636. this.nextDate = yearPJ + '-' + monthPJ + '-01'
  637. }
  638. // immediate: true
  639. },
  640. halfYearCheck: {
  641. handler: function (val, oldVal) {
  642. this.formatRiQi()
  643. if (val === '') {
  644. this.nextDate = ''
  645. return
  646. }
  647. const midList = [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]
  648. const today = new Date()
  649. const month = today.getMonth() + 1
  650. const qu = month > 6 ? 2 : 1
  651. const nowM = midList[qu - 1][val - 1]
  652. const nextM = midList[qu][val - 1]
  653. const endMonth = month >= nowM ? nextM : nowM
  654. const yearPJ = today.getFullYear()
  655. const monthPJ = endMonth > 9 ? endMonth : '0' + endMonth
  656. this.nextDate = yearPJ + '-' + monthPJ + '-01'
  657. }
  658. // immediate: true
  659. },
  660. yearCheck: {
  661. handler: function (val, oldVal) {
  662. this.formatRiQi()
  663. if (val === '') {
  664. this.nextDate = ''
  665. return
  666. }
  667. const today = new Date()
  668. const month = today.getMonth() + 1
  669. const year = today.getFullYear()
  670. const qu = month >= val ? year + 1 : year
  671. const monthPJ = val > 9 ? val : '0' + val
  672. this.nextDate = qu + '-' + monthPJ + '-01'
  673. }
  674. // immediate: true
  675. }
  676. },
  677. mounted () {
  678. this.init()
  679. if (this.isEdit) {
  680. this.loadData()
  681. this.loadSubData()
  682. } else {
  683. this.isFirstDevice = false
  684. }
  685. },
  686. methods: {
  687. init () {
  688. this.loadSelectorData()
  689. },
  690. loadSelectorData () {
  691. const pos = this.$store.getters.level.second ? this.$store.getters.level.second : this.$store.getters.level.first
  692. const sql = `select * from t_sbwhgwpzb where di_dian_='${pos}'`
  693. this.$common.request('sql', sql).then(res => {
  694. const { data = [] } = res.variables || {}
  695. this.jianCeGangWeiList = data
  696. })
  697. },
  698. loadData () {
  699. const sql = `select * from t_sshjpzb where id_=${this.parentData.mainId}`
  700. this.$common.request('sql', sql).then(res => {
  701. const { data = [] } = res.variables || {}
  702. // console.log('主表', data)
  703. if (!data.length) {
  704. return this.$message.warning(``)
  705. }
  706. this.form = data[0]
  707. const jian_ce_ri_qi_ = data[0].jian_ce_ri_qi_
  708. if (this.form.default_environme) {
  709. const { humidity, temperature } = JSON.parse(this.form.default_environme)
  710. this.$set(this.form, 'temperatureMin', +temperature.min)
  711. this.$set(this.form, 'temperatureMax', +temperature.max)
  712. this.$set(this.form, 'humidityMin', +humidity.min)
  713. this.$set(this.form, 'humidityMax', +humidity.max)
  714. }
  715. if (this.form.jian_ce_ri_qi_) {
  716. this.$nextTick(() => {
  717. switch (this.form.zhou_qi_) {
  718. case '每日':
  719. if (jian_ce_ri_qi_ === '每天') {
  720. this.dayCheck = [1, 2, 3, 4, 5, 6, 7]
  721. } else {
  722. this.dayCheck = jian_ce_ri_qi_.split('每周')[1].split(',').map(item => +item)
  723. }
  724. break
  725. case '每周':
  726. this.weekCheck = +jian_ce_ri_qi_.split('每周')[1]
  727. break
  728. case '每月':
  729. this.monthCheck = +jian_ce_ri_qi_.split('每个月第')[1].split('天')[0]
  730. break
  731. case '每季度':
  732. this.quarterCheck = +jian_ce_ri_qi_.split('每季度第')[1].split('个月')[0]
  733. break
  734. case '每半年':
  735. this.halfYearCheck = +jian_ce_ri_qi_.split('每半年第')[1].split('个月')[0]
  736. break
  737. case '每年':
  738. this.yearCheck = +jian_ce_ri_qi_.split('每年第')[1].split('个月')[0]
  739. break
  740. default:
  741. break
  742. }
  743. })
  744. }
  745. this.$nextTick(() => {
  746. this.isFirstDevice = false
  747. })
  748. })
  749. },
  750. loadSubData () {
  751. const sql = `select * from t_sshjpzxq where parent_id_=${this.parentData.mainId}`
  752. this.$common.request('sql', sql).then(res => {
  753. const { data = [] } = res.variables || {}
  754. // console.log('子表', data)
  755. if (!data.length) {
  756. return this.$message.warning(``)
  757. }
  758. this.subForm = data
  759. this.subIdList = data.map(item => item.zi_wai_deng_wai_j)
  760. })
  761. },
  762. formatEnv (temperatureMax, temperatureMin, humidityMax, humidityMin) {
  763. const temp_environment_range = {
  764. temperature: {
  765. max: temperatureMax,
  766. min: temperatureMin
  767. },
  768. humidity: {
  769. max: humidityMax,
  770. min: humidityMin
  771. }
  772. }
  773. return JSON.stringify(temp_environment_range)
  774. },
  775. formatRiQi () {
  776. switch (this.form.zhou_qi_) {
  777. case '每日':
  778. if (!this.dayCheck || this.dayCheck.length === 0) {
  779. this.form.jian_ce_ri_qi_ = ''
  780. this.form.ri_qi_lie_biao_ = ''
  781. } else if (this.dayCheck.length === 7) {
  782. this.form.jian_ce_ri_qi_ = '每天'
  783. this.form.ri_qi_lie_biao_ = '1,2,3,4,5,6,7'
  784. } else {
  785. const temp_dayCheck = JSON.parse(JSON.stringify(this.dayCheck))
  786. temp_dayCheck.sort(function (a, b) {
  787. return a - b
  788. })
  789. this.form.ri_qi_lie_biao_ = temp_dayCheck.join(',')
  790. this.form.jian_ce_ri_qi_ = '每周' + temp_dayCheck.join(',')
  791. }
  792. break
  793. case '每周':
  794. if (this.weekCheck) {
  795. this.form.jian_ce_ri_qi_ = '每周' + this.weekCheck
  796. this.form.ri_qi_lie_biao_ = this.weekCheck + ''
  797. } else {
  798. this.form.jian_ce_ri_qi_ = ''
  799. this.form.ri_qi_lie_biao_ = ''
  800. }
  801. break
  802. case '每月':
  803. if (this.monthCheck) {
  804. this.form.jian_ce_ri_qi_ = '每个月第' + this.monthCheck + '天'
  805. this.form.ri_qi_lie_biao_ = this.monthCheck + ''
  806. } else {
  807. this.form.jian_ce_ri_qi_ = ''
  808. this.form.ri_qi_lie_biao_ = ''
  809. }
  810. break
  811. case '每季度':
  812. if (this.quarterCheck) {
  813. this.form.jian_ce_ri_qi_ = '每季度第' + this.quarterCheck + '个月'
  814. this.form.ri_qi_lie_biao_ = this.quarterCheck + ''
  815. } else {
  816. this.form.jian_ce_ri_qi_ = ''
  817. this.form.ri_qi_lie_biao_ = ''
  818. }
  819. break
  820. case '每半年':
  821. if (this.halfYearCheck) {
  822. this.form.jian_ce_ri_qi_ = '每半年第' + this.halfYearCheck + '个月'
  823. this.form.ri_qi_lie_biao_ = this.halfYearCheck + ''
  824. } else {
  825. this.form.jian_ce_ri_qi_ = ''
  826. this.form.ri_qi_lie_biao_ = ''
  827. }
  828. break
  829. case '每年':
  830. if (this.yearCheck) {
  831. this.form.jian_ce_ri_qi_ = '每年第' + this.yearCheck + '个月'
  832. this.form.ri_qi_lie_biao_ = this.yearCheck + ''
  833. } else {
  834. this.form.jian_ce_ri_qi_ = ''
  835. this.form.ri_qi_lie_biao_ = ''
  836. }
  837. break
  838. default:
  839. this.form.jian_ce_ri_qi_ = ''
  840. this.form.ri_qi_lie_biao_ = ''
  841. break
  842. }
  843. },
  844. // 当前页码改变
  845. handleCurrentChange (val) {
  846. this.currentPage = val
  847. },
  848. // 页码选择器改变
  849. handleSizeChange (val) {
  850. this.pageSize = val
  851. this.currentPage = 1
  852. },
  853. // 分页连续序号
  854. showIndex (index) {
  855. return index + 1 + (this.currentPage - 1) * this.pageSize
  856. },
  857. handleActionEvent ({ key }) {
  858. switch (key) {
  859. case 'cancel':
  860. this.dialogVisible = false
  861. break
  862. case 'save':
  863. this.saveResult()
  864. break
  865. default:
  866. break
  867. }
  868. },
  869. // 使用默认数据
  870. settingData () {
  871. this.$confirm('使用默认数据后子表中为空的字段将会被以上数据代替,是否继续?', '提示', {
  872. confirmButtonText: '确定',
  873. cancelButtonText: '取消',
  874. type: 'warning'
  875. })
  876. .then(() => {
  877. this.subForm.forEach(item => {
  878. if (item.bu_men_ === '') {
  879. item.bu_men_ = this.form.bian_zhi_bu_men_
  880. }
  881. if (item.jian_ce_gang_wei_ === '') {
  882. item.jian_ce_gang_wei_ = this.form.gang_wei_
  883. }
  884. if (item.kong_zhi_tiao_jia === '') {
  885. item.kong_zhi_tiao_jia = this.form.tiao_jian_
  886. }
  887. if (item.environment_range === '' || item.environment_range === this.formatEnv(0, 0, 0, 0)) {
  888. item.environment_range = this.form.default_environme
  889. }
  890. if (item.jian_ce_ri_qi_ === '') {
  891. item.jian_ce_ri_qi_ = this.form.jian_ce_ri_qi_
  892. }
  893. if (item.ri_qi_lie_biao_ === '') {
  894. item.ri_qi_lie_biao_ = this.form.ri_qi_lie_biao_
  895. }
  896. if (item.jian_ce_zhou_qi_ === '') {
  897. item.jian_ce_zhou_qi_ = this.form.zhou_qi_
  898. }
  899. })
  900. })
  901. },
  902. // 子表单添加/编辑按钮
  903. openDialog (row) {
  904. if (this.form.lei_xing_ === '') {
  905. return this.$message.warning('请先选择类型!')
  906. }
  907. this.$refs.FecDialogRef.open(row, this.jianCeGangWeiList, this.form, { dayCheck: this.dayCheck, weekCheck: this.weekCheck, monthCheck: this.monthCheck, quarterCheck: this.quarterCheck, halfYearCheck: this.halfYearCheck, yearCheck: this.yearCheck })
  908. },
  909. // 子表的提交事件
  910. sonSubmit (data) {
  911. const { dayCheck, weekCheck, monthCheck, quarterCheck, halfYearCheck, yearCheck, form, isEdit, row } = data
  912. const temp_form = JSON.parse(JSON.stringify(form))
  913. const temp_environment_range = {
  914. temperature: {
  915. max: temp_form.temperatureMax,
  916. min: temp_form.temperatureMin
  917. },
  918. humidity: {
  919. max: temp_form.humidityMax,
  920. min: temp_form.humidityMin
  921. }
  922. }
  923. // 温度湿度格式化
  924. temp_form.environment_range = JSON.stringify(temp_environment_range)
  925. // 监测日期格式化
  926. switch (temp_form.jian_ce_zhou_qi_) {
  927. case '每日':
  928. if (!dayCheck || dayCheck.length === 0) {
  929. temp_form.jian_ce_ri_qi_ = ''
  930. temp_form.ri_qi_lie_biao_ = ''
  931. } else if (dayCheck.length === 7) {
  932. temp_form.jian_ce_ri_qi_ = '每天'
  933. temp_form.ri_qi_lie_biao_ = '1,2,3,4,5,6,7'
  934. } else {
  935. dayCheck.sort(function (a, b) {
  936. return a - b
  937. })
  938. temp_form.jian_ce_ri_qi_ = '每周' + dayCheck.join(',')
  939. temp_form.ri_qi_lie_biao_ = dayCheck.join(',')
  940. }
  941. break
  942. case '每周':
  943. if (weekCheck) {
  944. temp_form.jian_ce_ri_qi_ = '每周' + weekCheck
  945. temp_form.ri_qi_lie_biao_ = weekCheck + ''
  946. } else {
  947. temp_form.jian_ce_ri_qi_ = ''
  948. temp_form.ri_qi_lie_biao_ = ''
  949. }
  950. break
  951. case '每月':
  952. if (monthCheck) {
  953. temp_form.jian_ce_ri_qi_ = '每个月第' + monthCheck + '天'
  954. temp_form.ri_qi_lie_biao_ = monthCheck + ''
  955. } else {
  956. temp_form.jian_ce_ri_qi_ = ''
  957. temp_form.ri_qi_lie_biao_ = ''
  958. }
  959. break
  960. case '每季度':
  961. if (quarterCheck) {
  962. temp_form.jian_ce_ri_qi_ = '每季度第' + [quarterCheck] + '个月'
  963. temp_form.ri_qi_lie_biao_ = quarterCheck + ''
  964. } else {
  965. temp_form.jian_ce_ri_qi_ = ''
  966. temp_form.ri_qi_lie_biao_ = ''
  967. }
  968. break
  969. case '每半年':
  970. if (halfYearCheck) {
  971. temp_form.jian_ce_ri_qi_ = '每半年第' + [halfYearCheck] + '个月'
  972. temp_form.ri_qi_lie_biao_ = halfYearCheck + ''
  973. } else {
  974. temp_form.jian_ce_ri_qi_ = ''
  975. temp_form.ri_qi_lie_biao_ = ''
  976. }
  977. break
  978. case '每年':
  979. if (yearCheck) {
  980. temp_form.jian_ce_ri_qi_ = '每年第' + [yearCheck] + '个月'
  981. temp_form.ri_qi_lie_biao_ = yearCheck + ''
  982. } else {
  983. temp_form.jian_ce_ri_qi_ = ''
  984. temp_form.ri_qi_lie_biao_ = ''
  985. }
  986. break
  987. default:
  988. break
  989. }
  990. // 是否启用格式化
  991. temp_form.shi_fou_qi_yong_ = temp_form.shi_fou_qi_yong_ ? '1' : '0'
  992. // 删除多余项
  993. delete temp_form.temperatureMax
  994. delete temp_form.humidityMax
  995. delete temp_form.temperatureMin
  996. delete temp_form.humidityMin
  997. if (isEdit === true) {
  998. Object.assign(row, temp_form)
  999. } else {
  1000. this.subForm.push(temp_form)
  1001. }
  1002. this.$refs.FecDialogRef.close()
  1003. },
  1004. // 关闭当前窗口
  1005. closeDialog () {
  1006. this.dialogVisible = false
  1007. this.$emit('close', false)
  1008. },
  1009. // 子表删除
  1010. removeItem () {
  1011. if (this.multipleSelection.length === 0) {
  1012. return this.$message.warning('请选择要删除的数据!')
  1013. } else {
  1014. this.$confirm('请确认是否删除所选项?', '提示', {
  1015. confirmButtonText: '确定',
  1016. cancelButtonText: '取消',
  1017. type: 'warning'
  1018. }).then(() => {
  1019. this.multipleSelection.forEach(item => {
  1020. const index = this.subForm.indexOf(item)
  1021. this.subForm.splice(index, 1)
  1022. })
  1023. this.$message.success('删除成功!')
  1024. this.multipleSelection = []
  1025. }).catch(() => {
  1026. this.$message({
  1027. type: 'info',
  1028. message: '已取消删除'
  1029. })
  1030. })
  1031. }
  1032. },
  1033. // table复选框
  1034. handleSelectionChange (val) {
  1035. this.multipleSelection = val
  1036. },
  1037. submit () {
  1038. if (this.subForm.length === 0) {
  1039. return this.$message.warning('请添加子表数据')
  1040. }
  1041. for (var i = 0; i < this.subForm.length; i++) {
  1042. const item = this.subForm[i]
  1043. if (item.bu_men_ === '') {
  1044. return this.$message.warning(`子表第${i + 1}行部门信息缺失!`)
  1045. }
  1046. if (item.jian_ce_ri_qi_ === '') {
  1047. return this.$message.warning(`子表第${i + 1}行监测日期信息缺失!`)
  1048. }
  1049. if (item.jian_ce_gang_wei_ === '') {
  1050. return this.$message.warning(`子表第${i + 1}行监测岗位信息缺失!`)
  1051. }
  1052. }
  1053. delete this.form.temperatureMax
  1054. delete this.form.humidityMax
  1055. delete this.form.temperatureMin
  1056. delete this.form.humidityMin
  1057. // console.log('主表', this.form)
  1058. // console.log('子表', this.subForm)
  1059. const allUid = this.subForm.map(item => item.zi_wai_deng_wai_j)
  1060. const existUid = this.subIdList
  1061. const addList = this.subForm.filter(item => !existUid.includes(item.zi_wai_deng_wai_j))
  1062. const deleteList = existUid.filter(item => !allUid.includes(item))
  1063. const updateList = this.subForm.filter(item => existUid.includes(item.zi_wai_deng_wai_j))
  1064. // console.log('原来数据', existUid)
  1065. // console.log('全部数据', allUid)
  1066. // console.log('需要添加', addList)
  1067. // console.log('需要更新', updateList)
  1068. // console.log('需要删除', deleteList)
  1069. // return
  1070. // 主表修改
  1071. if (this.isEdit) {
  1072. const params = {
  1073. tableName: 't_sshjpzb',
  1074. updList: [
  1075. {
  1076. where: {
  1077. id_: this.parentData.mainId
  1078. },
  1079. param: {
  1080. lei_xing_: this.form.lei_xing_,
  1081. bian_zhi_bu_men_: this.form.bian_zhi_bu_men_,
  1082. zhou_qi_: this.form.zhou_qi_,
  1083. gang_wei_: this.form.gang_wei_,
  1084. tiao_jian_: this.form.tiao_jian_,
  1085. default_environme: this.form.default_environme,
  1086. she_bei_bian_hao_: this.form.she_bei_bian_hao_,
  1087. jian_ce_ri_qi_: this.form.jian_ce_ri_qi_,
  1088. ri_qi_lie_biao_: this.form.ri_qi_lie_biao_,
  1089. mo_kuai_lu_jing_: this.form.mo_kuai_lu_jing_
  1090. }
  1091. }
  1092. ]
  1093. }
  1094. this.$common.request('update', params).then(() => {
  1095. console.log('主表更新数据成功')
  1096. if (addList.length) {
  1097. const params = {
  1098. tableName: 't_sshjpzxq',
  1099. paramWhere: addList.map(item => {
  1100. return { ...item, parent_id_: this.parentData.mainId }
  1101. })
  1102. }
  1103. this.$common.request('add', params).then(() => { console.log('子表添加数据成功') })
  1104. }
  1105. if (updateList.length) {
  1106. const params = {
  1107. tableName: 't_sshjpzxq',
  1108. updList: updateList.map(item => ({
  1109. where: {
  1110. zi_wai_deng_wai_j: item.zi_wai_deng_wai_j
  1111. },
  1112. param: {
  1113. qu_yu_: item.qu_yu_,
  1114. fang_jian_: item.fang_jian_,
  1115. bu_men_: item.bu_men_,
  1116. deviceno1_: item.deviceno1_,
  1117. devicename1_: item.devicename1_,
  1118. deviceno2_: item.deviceno2_, // 监控设备
  1119. jian_ce_zhou_qi_: item.jian_ce_zhou_qi_,
  1120. jian_ce_gang_wei_: item.jian_ce_gang_wei_,
  1121. shi_fou_qi_yong_: item.shi_fou_qi_yong_,
  1122. kong_zhi_tiao_jia: item.kong_zhi_tiao_jia,
  1123. environment_range: item.environment_range,
  1124. xiu_zheng_shi_du_: item.xiu_zheng_shi_du_,
  1125. xiu_zheng_wen_du_: item.xiu_zheng_wen_du_,
  1126. jian_ce_ri_qi_: item.jian_ce_ri_qi_,
  1127. ri_qi_lie_biao_: item.ri_qi_lie_biao_
  1128. }
  1129. }))
  1130. }
  1131. this.$common.request('update', params).then(() => { console.log('子表更新数据成功') })
  1132. }
  1133. if (deleteList.length) {
  1134. const params = {
  1135. tableName: 't_sshjpzxq',
  1136. paramWhere: { zi_wai_deng_wai_j: deleteList.join(',') }
  1137. }
  1138. this.$common.request('delete', params).then(() => { console.log('子表删除数据成功') })
  1139. }
  1140. this.$nextTick(() => {
  1141. this.$message.success('修改成功!')
  1142. this.closeDialog()
  1143. })
  1144. })
  1145. } else {
  1146. const params = {
  1147. tableName: 't_sshjpzb',
  1148. paramWhere: [this.form]
  1149. }
  1150. this.$common.request('add', params).then((res) => {
  1151. console.log('主表新增数据成功')
  1152. const { cont = [] } = res.variables || {}
  1153. if (addList.length) {
  1154. const params = {
  1155. tableName: 't_sshjpzxq',
  1156. paramWhere: addList.map(item => {
  1157. return { ...item, parent_id_: cont[0].id_ }
  1158. })
  1159. }
  1160. this.$common.request('add', params).then(() => {
  1161. this.$message.success('添加成功!')
  1162. console.log('子表添加数据成功')
  1163. this.closeDialog()
  1164. })
  1165. }
  1166. })
  1167. }
  1168. // 紫外灯数据同步更新紫外灯消毒记录表
  1169. if (this.form.lei_xing_.includes('12')) {
  1170. const tableName = 't_jykzwdxdjlbsc'
  1171. // 生成添加请求参数
  1172. const addParams = addList.length ? {
  1173. tableName,
  1174. paramWhere: addList.map(item => ({
  1175. di_dian_: this.level,
  1176. bian_zhi_bu_men_: item.bu_men_,
  1177. bian_zhi_ren_: this.userId,
  1178. zi_wai_deng_ming_: item.deviceName1,
  1179. she_shi_id_: item.zi_wai_deng_wai_j
  1180. }))
  1181. } : null
  1182. // 生成更新请求参数
  1183. const updateParams = updateList.length ? {
  1184. tableName,
  1185. updList: updateList.map(item => ({
  1186. where: {
  1187. she_shi_id_: item.zi_wai_deng_wai_j
  1188. },
  1189. param: {
  1190. bian_zhi_bu_men_: item.bu_men_,
  1191. zi_wai_deng_ming_: item.deviceName1
  1192. }
  1193. }))
  1194. } : null
  1195. // 生成删除请求参数
  1196. const deleteParams = deleteList.length ? {
  1197. tableName,
  1198. paramWhere: { she_shi_id_: deleteList.map(item => item.sheShiId).join(',') }
  1199. } : null
  1200. // 合并所有请求
  1201. const allRequests = []
  1202. if (addParams) {
  1203. allRequests.push(this.$common.request('add', addParams).then(() => console.log('添加紫外灯数据成功')))
  1204. }
  1205. if (updateParams) {
  1206. allRequests.push(this.$common.request('update', updateParams).then(() => console.log('更新紫外灯数据成功')))
  1207. }
  1208. if (deleteParams) {
  1209. allRequests.push(this.$common.request('delete', deleteParams).then(() => console.log('删除紫外灯数据成功')))
  1210. }
  1211. // 执行所有请求
  1212. Promise.all(allRequests)
  1213. .then(() => console.log('所有请求完成'))
  1214. .catch(error => console.error('请求出错:', error))
  1215. }
  1216. },
  1217. saveResult () {
  1218. this.$refs.form.validate((valid) => {
  1219. if (valid) {
  1220. this.submit()
  1221. } else {
  1222. this.$message.warning('请填写必填项')
  1223. return false
  1224. }
  1225. })
  1226. },
  1227. /* 读取文件 */
  1228. readFile (file) {
  1229. return new Promise(resolve => {
  1230. const reader = new FileReader()
  1231. reader.readAsBinaryString(file)
  1232. reader.onload = ev => {
  1233. resolve(ev.target.result)
  1234. }
  1235. })
  1236. },
  1237. // 获取 excel 的 json 数据
  1238. async handleUploadChange (file) {
  1239. const dataBinary = await this.readFile(file.raw)
  1240. const workBook = xlsx.read(dataBinary, { type: 'binary', cellDates: true })
  1241. const workSheet = workBook.Sheets[workBook.SheetNames[0]]
  1242. const data = xlsx.utils.sheet_to_json(workSheet)
  1243. if (data.length === 0) {
  1244. return this.$message.warning('文件内容为空!')
  1245. }
  1246. data.forEach(item => {
  1247. this.subForm.push({
  1248. deviceno1_: item['被控设备编号'] || '',
  1249. devicename1_: item['被控设备名称'] || '',
  1250. shi_fou_qi_yong_: '1',
  1251. bu_men_: this.switchDeptid(item['部门']),
  1252. jian_ce_gang_wei_: item['监测岗位'] || '',
  1253. jian_ce_zhou_qi_: item['监测周期'] || '',
  1254. kong_zhi_tiao_jia: item['控制条件'] || '',
  1255. environment_range: '',
  1256. xiu_zheng_shi_du_: item['湿度修正值'] || '',
  1257. xiu_zheng_wen_du_: item['温度修正值'] || '',
  1258. fang_jian_: item['房间'] || '',
  1259. qu_yu_: item['区域'] || '',
  1260. deviceno2_: item['监控设备编号'] || '',
  1261. jian_ce_ri_qi_: '',
  1262. ri_qi_lie_biao_: '',
  1263. zi_wai_deng_wai_j: this.$utils.guid()
  1264. })
  1265. })
  1266. this.$message.success('导入成功!')
  1267. },
  1268. // 部门id转部门
  1269. switchDept (dep) {
  1270. const userList = this.$store.getters.userList
  1271. for (let i = 0; i < userList.length; i++) {
  1272. const user = userList[i]
  1273. const positionId = user.positionId.split(',')
  1274. const positions = user.positions.split(',')
  1275. const pos = positionId.findIndex(p => p === dep)
  1276. if (pos >= 0) {
  1277. return positions[pos]
  1278. }
  1279. }
  1280. },
  1281. // id 转部门
  1282. switchDeptid (id) {
  1283. const userList = this.$store.getters.userList
  1284. for (let i = 0; i < userList.length; i++) {
  1285. const user = userList[i]
  1286. const positionId = user.positionId.split(',')
  1287. const positions = user.positions.split(',')
  1288. const pos = positions.findIndex(p => p === id)
  1289. if (pos >= 0) {
  1290. return positionId[pos]
  1291. }
  1292. }
  1293. return ''
  1294. },
  1295. // 导出
  1296. exportExcel () {
  1297. const temp_subForm = JSON.parse(JSON.stringify(this.subForm))
  1298. temp_subForm.forEach(item => {
  1299. item.bu_men_ = this.switchDept(item.bu_men_)
  1300. })
  1301. this.xlsx(temp_subForm, this.listHander, '设施环境配置表')
  1302. this.$message.success('导出成功!')
  1303. },
  1304. xlsx (json, fields, filename = '.xlsx') { // 导出xlsx
  1305. json.forEach(item => {
  1306. for (const i in item) {
  1307. if (fields.hasOwnProperty(i)) {
  1308. item[fields[i]] = item[i]
  1309. }
  1310. delete item[i] // 删除原先的对象属性
  1311. }
  1312. })
  1313. const sheetName = filename // excel的文件名称
  1314. const wb = xlsx.utils.book_new() // 工作簿对象包含一SheetNames数组,以及一个表对象映射表名称到表对象。XLSX.utils.book_new实用函数创建一个新的工作簿对象。
  1315. const ws = xlsx.utils.json_to_sheet(json, { header: Object.values(fields) }) // 将JS对象数组转换为工作表。
  1316. wb.SheetNames.push(sheetName)
  1317. wb.Sheets[sheetName] = ws
  1318. const defaultCellStyle = { font: { name: 'Verdana', sz: 13, color: 'FF00FF88' }, fill: { fgColor: { rgb: 'FFFFAA00' }}}// 设置表格的样式
  1319. const wopts = { bookType: 'xlsx', bookSST: false, type: 'binary', cellStyles: true, defaultCellStyle: defaultCellStyle, showGridLines: false } // 写入的样式
  1320. const wbout = xlsx.write(wb, wopts)
  1321. const blob = new Blob([this.s2ab(wbout)], { type: 'application/octet-stream' })
  1322. fs.saveAs(blob, filename + '.xlsx')
  1323. },
  1324. s2ab (s) {
  1325. let buf
  1326. if (typeof ArrayBuffer !== 'undefined') {
  1327. buf = new ArrayBuffer(s.length)
  1328. const view = new Uint8Array(buf)
  1329. for (let i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xff
  1330. return buf
  1331. } else {
  1332. buf = new Array(s.length)
  1333. for (let i = 0; i !== s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF
  1334. return buf
  1335. }
  1336. },
  1337. getDayDate (type, dates) {
  1338. const now = new Date()
  1339. const nowTime = now.getTime()
  1340. const day = now.getDay()
  1341. const longTime = 24 * 60 * 60 * 1000
  1342. const n = longTime * 7 * (dates || 0)
  1343. let dd = nowTime - (day - type) * longTime + n
  1344. dd = new Date(dd)
  1345. const y = dd.getFullYear()
  1346. let m = dd.getMonth() + 1
  1347. let d = dd.getDate()
  1348. m = m < 10 ? '0' + m : m
  1349. d = d < 10 ? '0' + d : d
  1350. const daynow = y + '-' + m + '-' + d
  1351. return daynow
  1352. },
  1353. // 获取往后几个月相应的日期
  1354. // currentDate:当前日期
  1355. // dayOfMonth:获取几号
  1356. // val:往后几个月
  1357. getNextMonthDate (currentDate, dayOfMonth, val) {
  1358. const currentYear = currentDate.getFullYear()
  1359. const currentMonth = currentDate.getMonth()
  1360. const nextMonth = currentMonth + val
  1361. const nextMonthDate = new Date(currentYear, nextMonth, dayOfMonth)
  1362. const formattedDate = nextMonthDate.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-')
  1363. return formattedDate
  1364. },
  1365. // 获取当前季度
  1366. getQuarter (date) {
  1367. return Math.floor(date.getMonth() / 3) + 1
  1368. }
  1369. }
  1370. }
  1371. </script>
  1372. <style lang="scss" scoped>
  1373. .paper-detail-dialog {
  1374. ::v-deep {
  1375. .el-dialog__header {
  1376. text-align: center;
  1377. }
  1378. }
  1379. .container {
  1380. display: flex;
  1381. width: 100%;
  1382. justify-content: center;
  1383. .main{
  1384. width: 80%;
  1385. height: calc(100vh - 135px);
  1386. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  1387. padding:20px;
  1388. // overflow-y: auto;
  1389. .form{
  1390. .el-row{
  1391. margin: 10px 0;
  1392. }
  1393. }
  1394. .btn{
  1395. display: flex;
  1396. .upload-demo{
  1397. margin-right: 10px;
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. </style>