newAssociatedPage.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <template>
  2. <div class="newAssociatedPage">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" class="form-box">
  4. <el-form-item label="关键字" prop="name">
  5. <el-input
  6. style="width:160px;"
  7. maxlength="10"
  8. v-model="queryParams.searchValue"
  9. placeholder="实验室/危险源"
  10. clearable
  11. size="small"
  12. />
  13. </el-form-item>
  14. <el-form-item label="安全分类" prop="typeId">
  15. <el-select v-model="queryParams.typeId" placeholder="请选择安全分类" style="width:160px;">
  16. <el-option
  17. v-for="dict in typeList"
  18. :key="dict.id"
  19. :label="dict.typeName"
  20. :value="dict.id"
  21. ></el-option>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="安全分级" prop="leve">
  25. <el-select v-model="queryParams.leve" placeholder="请选择安全分级" style="width:160px;">
  26. <el-option
  27. v-for="item in levelList"
  28. :key="item.id"
  29. :label="item.classifiedName"
  30. :value="item.id">
  31. </el-option>
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="关联时间" prop="senseState">
  35. <el-date-picker
  36. :clearable="false"
  37. v-model="dateRange"
  38. size="small"
  39. style="width: 240px"
  40. value-format="yyyy-MM-dd"
  41. type="daterange"
  42. range-separator="-"
  43. start-placeholder="开始日期"
  44. end-placeholder="结束日期"
  45. ></el-date-picker>
  46. </el-form-item>
  47. <el-form-item style="float: right;">
  48. <el-col :span="1.5">
  49. <p class="reset-button-one"
  50. @click="backButton"
  51. style="float: right;"
  52. >返回</p>
  53. <p class="add-button-one-90"
  54. @click="handleAdd(1)"
  55. style="float: right;margin-right:20px;"
  56. >新增</p>
  57. </el-col>
  58. </el-form-item>
  59. <el-form-item>
  60. <p class="inquire-button-one" style="margin-right:10px;" @click="handleQuery">查询</p>
  61. <p class="reset-button-one" @click="resetQuery">重置</p>
  62. </el-form-item>
  63. </el-form>
  64. <el-table v-loading="loading" border :data="tableData">
  65. <el-table-column label="实验室" align="left" prop="name" width="300" show-overflow-tooltip/>
  66. <el-table-column label="安全分类" align="left" prop="typeName" width="140"/>
  67. <el-table-column label="安全分级" align="left" prop="leveName" width="140"/>
  68. <el-table-column label="危险源" align="left" prop="labSensorHazardRelationsList" show-overflow-tooltip>
  69. <template slot-scope="scope">
  70. <span style="margin-right:10px;" v-for="(item,index) in scope.row.labSensorHazardRelationsList" :key="index">
  71. {{item.hazardName}}-{{item.sensorName}}
  72. </span>
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="关联时间" align="left" prop="relationTime" width="200"/>
  76. <el-table-column label="状态" align="left" prop="senseState" width="140"/>
  77. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="100">
  78. <template slot-scope="scope">
  79. <div class="button-box">
  80. <p style="height: 23px;
  81. color: #0183FA;
  82. line-height: 23px;
  83. font-size: 14px;
  84. cursor: pointer;
  85. padding: 0 10px !important;
  86. margin: 0;
  87. text-align: center;"
  88. @click="handleDelete(scope.row)"
  89. >移除</p>
  90. </div>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. <pagination :page-sizes="[20, 30, 40, 50]"
  95. v-show="total>0"
  96. :total="total"
  97. layout="total, prev, pager, next, sizes, jumper"
  98. :page.sync="queryParams.pageNum"
  99. :limit.sync="queryParams.pageSize"
  100. @pagination="getList"
  101. />
  102. <el-dialog title='关联实验室' v-if="dialogAssociatedOpen" :visible.sync="dialogAssociatedOpen" width="1200px">
  103. <div style="height: 600px;overflow: hidden;display: flex;flex-direction: column;flex:1;">
  104. <el-form :model="param" ref="queryForm" :inline="true" label-width="80px">
  105. <el-form-item label="关键字" prop="searchValue">
  106. <el-input
  107. maxlength="10"
  108. v-model="param.searchValue"
  109. placeholder="实验室/危险源"
  110. clearable
  111. size="small"
  112. />
  113. </el-form-item>
  114. <el-form-item label="安全分类" prop="typeId" label-width="80px">
  115. <el-select v-model="param.typeId" placeholder="请选择安全分类" clearable size="small">
  116. <el-option
  117. v-for="dict in typeList"
  118. :key="dict.id"
  119. :label="dict.typeName"
  120. :value="dict.id"
  121. ></el-option>
  122. </el-select>
  123. </el-form-item>
  124. <el-form-item label="安全分级" prop="leve" label-width="80px">
  125. <el-select v-model="param.leve" placeholder="请选择安全分级" clearable size="small">
  126. <el-option
  127. v-for="dict in levelList"
  128. :key="dict.id"
  129. :label="dict.classifiedName"
  130. :value="dict.id"
  131. ></el-option>
  132. </el-select>
  133. </el-form-item>
  134. <el-form-item>
  135. <p class="inquire-button-one" style="margin-right:10px;" @click="onSearch">查询</p>
  136. <p class="reset-button-one" @click="resetForm">重置</p>
  137. </el-form-item>
  138. </el-form>
  139. <!--<div style="display: flex;background: rgb(202,229,253);height:40px;line-height:40px;font-size:16px;padding:0 82px;margin-bottom:20px;">-->
  140. <!--<p style="margin-right:24px;">已选择 <span style="color:#0183FA;">{{allNum}}</span> 项</p>-->
  141. <!--<p style="color:#0183FA;cursor: pointer;" @click="allButton(1)">全选本页</p>-->
  142. <!--<p style="color:#0183FA;margin:0 32px 0 30px;cursor: pointer;" @click="allButton(2)">选择全部</p>-->
  143. <!--</div>-->
  144. <el-table ref="table" v-loading="loading" border :data="dialogTableData" @selection-change="handleSelectionChange" :row-key="getRowKeys">
  145. <el-table-column type="selection" width="55" :reserve-selection="true" align="center" />
  146. <el-table-column label="实验室" width="220" align="center" prop="id" />
  147. <el-table-column label="安全分类" width="100" align="center" prop="name" />
  148. <el-table-column label="安全分级" width="100" align="center" prop="key" />
  149. <el-table-column label="危险源" align="left">
  150. <template slot-scope="scope">
  151. <div style="margin-bottom:10px;">
  152. <div v-for="(item,index) in scope.row.buttonList" :key="index"
  153. style="display: inline-block;padding:0 10px;border:1px solid #E0E0E0;margin:10px 10px 0 0;">
  154. <span style="line-height:40px;font-size:14px;">{{item.hazardSubjectName}}-{{item.sensorName}}</span>
  155. <span class="el-icon-circle-close" @click="delMinObj(scope.row.buttonList,index)"
  156. style="cursor: pointer;width:14px;height:14px;margin-left:10px;margin-top:14px;color:#666;"></span>
  157. </div>
  158. <p v-if="scope.row.buttonType == 0"
  159. @click="addObjButton(1,scope.row)"
  160. style="color:#0183FA;font-size:16px;border:1px solid #0183FA;
  161. border-radius:4px;width:88px;height:30px;line-height:30px;
  162. display: inline-block;margin:5px 0 0 10px;text-align: center;cursor: pointer;">新增危险源</p>
  163. <div v-if="scope.row.buttonType == 1"
  164. style="display: flex;margin-top:10px;">
  165. <el-select v-model="scope.row.hazardSubjectId" placeholder="请选择危险源"
  166. @change="(val)=>hardwareChange(val,scope.row)"
  167. style="width:168px;">
  168. <el-option
  169. v-for="dict in scope.row.labHazardSubVOList"
  170. :key="dict.xyId"
  171. :label="dict.label"
  172. :value="dict.xyId"
  173. ></el-option>
  174. </el-select>
  175. <p style="width:30px;text-align: center;line-height:40px;">-</p>
  176. <el-select v-model="scope.row.sensorId" placeholder="请选择传感器"
  177. @change="(val)=>sensorChange(val,scope.row)"
  178. style="width:168px;">
  179. <el-option
  180. v-for="dict in scope.row.labSensorList"
  181. :key="dict.id"
  182. :label="dict.name"
  183. :value="dict.id"
  184. ></el-option>
  185. </el-select>
  186. <p style="color:#CCCCCC;font-size:16px;border:1px solid #E0E0E0;
  187. border-radius:4px;width:80px;height:30px;line-height:30px;
  188. display: inline-block;margin:5px 0 0 10px;text-align: center;cursor: pointer;" @click="addObjButton(2,scope.row)">取消</p>
  189. <p style="color:#0183FA;font-size:16px;border:1px solid #0183FA;
  190. border-radius:4px;width:80px;height:30px;line-height:30px;
  191. display: inline-block;margin:5px 0 0 10px;text-align: center;cursor: pointer;" @click="addObjButton(3,scope.row)">确定</p>
  192. </div>
  193. </div>
  194. </template>
  195. </el-table-column>
  196. </el-table>
  197. <pagination
  198. v-show="dialogTotal>0"
  199. :total="dialogTotal"
  200. :page.sync="param.pageNum"
  201. :limit.sync="param.pageSize"
  202. @pagination="getList"
  203. />
  204. </div>
  205. <div slot="footer" class="dialog-footer">
  206. <div style="display: flex">
  207. <p style="flex:1;"></p>
  208. <p style="cursor: pointer;border-radius:6px;width:70px;line-height:30px;font-size:12px;text-align:center;margin-right:17px;color:#999999;background:#E0E0E0;" @click="handleAdd(2)">取消</p>
  209. <p style="cursor: pointer;border-radius:6px;width:70px;line-height:30px;font-size:12px;text-align:center;color:#fff;background:#0045AF;" @click="handleAdd(3)">确定</p>
  210. <p style="flex:1;"></p>
  211. </div>
  212. </div>
  213. </el-dialog>
  214. </div>
  215. </template>
  216. <script>
  217. import { optionHardware } from "@/api/laboratory/hardware";
  218. import { optionSensor } from "@/api/laboratory/sensor";
  219. import { listClassifiedAll } from "@/api/laboratory/classified";
  220. import { listClasstypeAll } from "@/api/laboratory/classtype";
  221. import { getLabRiskPlanJoinSub,getLabRiskPlanNoJoinSub,deleteRiskPlanJoinSub,riskPlanJoinSub,riskPlanBatchJoinSub } from "@/api/evacuation3_2/index";
  222. export default {
  223. name: 'newAssociatedPage',
  224. props:{
  225. associationData:{},
  226. },
  227. data() {
  228. return {
  229. loading:false,
  230. levelList:[],
  231. typeList:[],
  232. // 查询参数
  233. dateRange:[],
  234. queryParams:{
  235. pageNum: 1,
  236. pageSize:20,
  237. searchValue:"",
  238. },
  239. total:0,
  240. tableData:[],
  241. /***************关联危险源开始****************/
  242. // 选中数组
  243. ids: [],
  244. // 非单个禁用
  245. single: true,
  246. // 非多个禁用
  247. multiple: true,
  248. // 查询数据
  249. param:{
  250. pageNum:1,
  251. pageSize:10,
  252. },
  253. dialogTotal:5,
  254. //关联实验室
  255. dialogAssociatedOpen:false,
  256. dialogTableData:[],
  257. //传感器
  258. sensorList:[],
  259. sensorListData:[],
  260. //设备
  261. hardwareList:[],
  262. /***************关联危险源结束****************/
  263. allNum:0,
  264. }
  265. },
  266. created(){
  267. this.getListAll();
  268. },
  269. mounted(){
  270. this.getList();
  271. },
  272. methods:{
  273. getListAll(){
  274. optionSensor({}).then(response => {
  275. this.sensorList = response.data;
  276. this.sensorListData = JSON.parse(JSON.stringify(response.data))
  277. });
  278. optionHardware({}).then(response => {
  279. this.hardwareList = response.data;
  280. });
  281. listClassifiedAll().then(response=>{
  282. if(response.code==200){
  283. this.levelList=response.data
  284. }
  285. })
  286. listClasstypeAll().then(response=>{
  287. if(response.code==200){
  288. this.typeList=response.data;
  289. }
  290. });
  291. },
  292. //新增关联实验室弹窗
  293. handleAdd(type){
  294. let self = this;
  295. if (type == 1){
  296. this.resetForm();
  297. this.$set(this,'allNum',0);
  298. this.$set(this,'dialogAssociatedOpen',true);
  299. }else if(type == 2){
  300. this.$set(this,'dialogAssociatedOpen',false);
  301. }else if(type == 3){
  302. let list = JSON.parse(JSON.stringify(this.$refs.table.selection));
  303. if(!list[0]){
  304. this.msgError('请勾选需要关联的实验室');
  305. return
  306. }
  307. let newList = [];
  308. for(let i=0;i<list.length;i++){
  309. let obj = {
  310. riskPlanId:self.associationData.id,
  311. subjectId:list[i].id,
  312. labSensorHazardRelations:list[i].buttonList,
  313. }
  314. newList.push(obj);
  315. }
  316. let newObj = {
  317. riskPlanId:self.associationData.id,
  318. yesOrNo:0,
  319. labRiskPlanSubVos:newList,
  320. }
  321. riskPlanJoinSub(newObj).then(response => {
  322. if(response.data.ifConflict == 1){
  323. self.$confirm(response.data.message, "警告", {
  324. confirmButtonText: "确定",
  325. cancelButtonText: "取消",
  326. type: "warning"
  327. }).then(function() {
  328. let newData = {
  329. riskPlanId:self.associationData.id,
  330. yesOrNo:1,
  331. labRiskPlanSubVos:newList,
  332. }
  333. riskPlanJoinSub(newData).then(response => {
  334. self.msgSuccess(response.msg);
  335. self.resetQuery();
  336. self.$set(self,'dialogAssociatedOpen',false);
  337. });
  338. }).then(() => {
  339. }).catch(() => {});
  340. }else{
  341. self.msgSuccess(response.msg);
  342. self.resetQuery();
  343. self.$set(self,'dialogAssociatedOpen',false);
  344. }
  345. });
  346. }
  347. },
  348. //查询
  349. onSearch(){
  350. this.$set(this.param,'pageNum',1);
  351. this.getLabRiskPlanNoJoinSub();
  352. },
  353. //重置
  354. resetForm(){
  355. this.$set(this,'param',{
  356. pageNum:1,
  357. pageSize:20,
  358. searchValue:"",
  359. typeId:"",
  360. leve:"",
  361. });
  362. this.$set(this,'dialogTotal',0);
  363. this.$set(this,'dialogTableData',[]);
  364. this.onSearch();
  365. },
  366. //获取未关联实验室列表
  367. getLabRiskPlanNoJoinSub(){
  368. this.$set(this.param,'riskPlanId',this.associationData.id);
  369. getLabRiskPlanNoJoinSub(this.param).then(response => {
  370. for(let i=0;i<response.rows.length;i++){
  371. response.rows[i].buttonType = 0;
  372. response.rows[i].buttonList = [];
  373. response.rows[i].sensorId = null;
  374. response.rows[i].sensorName = null;
  375. response.rows[i].hazardSubjectId = null;
  376. response.rows[i].hazardSubjectName = null;
  377. }
  378. this.dialogTableData = response.rows;
  379. this.dialogTotal = response.total;
  380. this.loading = false;
  381. });
  382. },
  383. //新增对象至选中实验室
  384. addObjButton(type,item){
  385. if(type == 1){
  386. if(item.buttonList.length>8){
  387. this.msgError('最多添加9项')
  388. return
  389. }
  390. item.buttonType = 1;
  391. }else if(type == 2){
  392. item.buttonType = 0;
  393. }else if(type == 3){
  394. if(item.sensorId == null){
  395. this.msgError('请选择要添加的危险源')
  396. return
  397. }
  398. if(item.hazardSubjectId == null){
  399. this.msgError('请选择要添加的传感器')
  400. return
  401. }
  402. let obj = {
  403. sensorId:item.sensorId,
  404. sensorName:item.sensorName,
  405. hazardSubjectId:item.hazardSubjectId,
  406. hazardSubjectName:item.hazardSubjectName,
  407. };
  408. for(let i=0;i<item.buttonList.length;i++){
  409. if(item.buttonList[i].sensorId == item.sensorId && item.buttonList[i].hazardSubjectId == item.hazardSubjectId){
  410. this.msgError('该条件已存在');
  411. return
  412. }
  413. }
  414. item.buttonList.push(obj);
  415. item.sensorId = null;
  416. item.sensorName = null;
  417. item.hazardSubjectId = null;
  418. item.hazardSubjectName = null;
  419. item.buttonType = 0;
  420. this.$forceUpdate();
  421. }
  422. },
  423. //删除列表内的对象
  424. delMinObj(list,index){
  425. list.splice(index,1)
  426. this.$forceUpdate();
  427. },
  428. sensorChange(val,row){
  429. console.log('传感器')
  430. for(let i=0;i<row.labSensorList.length;i++){
  431. if(row.labSensorList[i].id == val){
  432. row.sensorId = row.labSensorList[i].id;
  433. row.sensorName = row.labSensorList[i].name;
  434. }
  435. }
  436. this.$forceUpdate();
  437. },
  438. hardwareChange(val,row){
  439. console.log('危险源')
  440. for(let i=0;i<row.labHazardSubVOList.length;i++){
  441. if(row.labHazardSubVOList[i].xyId == val){
  442. row.hazardSubjectId = row.labHazardSubVOList[i].xyId;
  443. row.hazardSubjectName = row.labHazardSubVOList[i].label;
  444. }
  445. }
  446. this.$forceUpdate();
  447. },
  448. //删除关联实验室
  449. handleDelete(item){
  450. let self = this;
  451. this.$confirm('确定要删除该预案规则吗?', "警告", {
  452. confirmButtonText: "确定",
  453. cancelButtonText: "取消",
  454. type: "warning"
  455. }).then(function() {
  456. let obj = {
  457. riskPlanId:self.associationData.id,
  458. subjectId:item.id
  459. }
  460. deleteRiskPlanJoinSub(obj).then((response) => {
  461. self.msgSuccess(response.msg)
  462. self.resetQuery();
  463. });
  464. }).then(() => {
  465. }).catch(() => {});
  466. },
  467. //查询
  468. handleQuery(){
  469. this.$set(this.queryParams,'pageNum',1);
  470. if(this.dateRange[0]){
  471. this.queryParams.startDate = this.dateRange[0]
  472. this.queryParams.endDate = this.dateRange[1]
  473. }else {
  474. this.queryParams.startDate = null
  475. this.queryParams.endDate = null
  476. }
  477. this.getList();
  478. },
  479. //重置
  480. resetQuery(){
  481. this.$set(this,'queryParams',{
  482. pageNum:1,
  483. pageSize:20,
  484. searchValue:"",
  485. typeId:"",
  486. leve:"",
  487. });
  488. this.$set(this,'dateRange',[]);
  489. this.$set(this,'total',0);
  490. this.$set(this,'tableData',[]);
  491. this.handleQuery();
  492. },
  493. /** 查询列表 */
  494. getList() {
  495. let self = this;
  496. this.loading = true;
  497. this.$set(this.queryParams,'riskPlanId',this.associationData.id);
  498. getLabRiskPlanJoinSub(this.queryParams).then(response => {
  499. for(let i=0;i<response.rows.length;i++){
  500. for(let o=0;o<self.typeList.length;o++){
  501. if(response.rows[i].typeId == self.typeList[o].id){
  502. response.rows[i].typeName = self.typeList[o].typeName;
  503. }
  504. }
  505. for(let o=0;o<self.levelList.length;o++){
  506. if(response.rows[i].level == self.levelList[o].id){
  507. response.rows[i].leveName = self.levelList[o].classifiedName;
  508. }
  509. }
  510. response.rows[i].labSensorHazardRelationsList = [];
  511. for(let o=0;o<response.rows[i].labSensorHazardRelations.length;o++){
  512. let obj = {
  513. hazardName:response.rows[i].labSensorHazardRelations[o].hazardName,
  514. sensorName:response.rows[i].labSensorHazardRelations[o].sensorName,
  515. }
  516. response.rows[i].labSensorHazardRelationsList.push(obj);
  517. }
  518. }
  519. this.tableData = response.rows;
  520. this.total = response.total;
  521. this.loading = false;
  522. });
  523. },
  524. //返回
  525. backButton(){
  526. if(this.associationData.type == 1){
  527. this.$parent.tableClickButton(6)
  528. }else{
  529. this.$parent.tableClickButton(5)
  530. }
  531. },
  532. /*===记录勾选数据===
  533. 需要再el-table 添加 :row-key="getRowKeys"
  534. 需要在selection 添加 :reserve-selection="true"
  535. */
  536. getRowKeys(row) {
  537. return row.id
  538. },
  539. //勾选
  540. handleSelectionChange(selection){
  541. this.$set(this,'allNum',selection.length);
  542. // console.log('selection',selection)
  543. },
  544. allButton(type){
  545. let self = this;
  546. if(type == 1){
  547. let list = [];
  548. for(let i=0;i<self.dialogTableData.length;i++){
  549. list.push(self.dialogTableData[i].id);
  550. }
  551. let obj = {
  552. riskPlanId:self.associationData.id,
  553. subjectIds:list+''
  554. }
  555. riskPlanBatchJoinSub(obj).then(response => {
  556. this.msgSuccess(response.msg);
  557. this.resetQuery();
  558. this.$set(this,'dialogAssociatedOpen',false);
  559. });
  560. }else if(type == 2){
  561. let obj = {
  562. riskPlanId:self.associationData.id,
  563. searchValue:self.param.searchValue,
  564. typeId:self.param.typeId,
  565. level:self.param.leve,
  566. subjectIds:'-1'
  567. };
  568. riskPlanBatchJoinSub(obj).then(response => {
  569. this.msgSuccess(response.msg);
  570. this.resetQuery();
  571. this.$set(this,'dialogAssociatedOpen',false);
  572. });
  573. }
  574. },
  575. },
  576. }
  577. </script>
  578. <style scoped lang="scss">
  579. .newAssociatedPage{
  580. flex: 1;
  581. display: flex !important;
  582. flex-direction: column;
  583. overflow: hidden;
  584. padding:20px;
  585. p {
  586. margin: 0;
  587. font-weight: 500;
  588. }
  589. }
  590. </style>