facilityEnvConfig.vue 68 KB

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