newAssociatedPage.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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="level">
  25. <el-select v-model="queryParams.level" 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="level" label-width="80px">
  125. <el-select v-model="param.level" 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="name" show-overflow-tooltip/>
  147. <el-table-column label="安全分类" width="100" align="center" prop="typeId" show-overflow-tooltip>
  148. <template slot-scope="scope">
  149. <span v-for="(item,index) in typeList" :key="index" v-if="item.id == scope.row.typeId">{{item.typeName}}</span>
  150. </template>
  151. </el-table-column>
  152. <el-table-column label="安全分级" width="100" align="center" prop="level" show-overflow-tooltip>
  153. <template slot-scope="scope">
  154. <span v-for="(item,index) in levelList" :key="index" v-if="item.id == scope.row.level">{{item.classifiedName}}</span>
  155. </template>
  156. </el-table-column>
  157. <el-table-column label="危险源" align="left">
  158. <template slot-scope="scope">
  159. <div style="margin-bottom:10px;">
  160. <div v-for="(item,index) in scope.row.buttonList" :key="index"
  161. style="display: inline-block;padding:0 10px;border:1px solid #E0E0E0;margin:10px 10px 0 0;">
  162. <span style="line-height:40px;font-size:14px;">{{item.hazardSubjectName}}-{{item.sensorName}}</span>
  163. <span class="el-icon-circle-close" @click="delMinObj(scope.row.buttonList,index)"
  164. style="cursor: pointer;width:14px;height:14px;margin-left:10px;margin-top:14px;color:#666;"></span>
  165. </div>
  166. <p v-if="scope.row.buttonType == 0"
  167. @click="addObjButton(1,scope.row)"
  168. style="color:#0183FA;font-size:16px;border:1px solid #0183FA;
  169. border-radius:4px;width:88px;height:30px;line-height:30px;
  170. display: inline-block;margin:5px 0 0 10px;text-align: center;cursor: pointer;">新增危险源</p>
  171. <div v-if="scope.row.buttonType == 1"
  172. style="display: flex;margin-top:10px;">
  173. <el-select v-model="scope.row.hazardSubjectId" placeholder="请选择危险源"
  174. @change="(val)=>hardwareChange(val,scope.row)"
  175. style="width:168px;">
  176. <el-option
  177. v-for="dict in scope.row.labHazardSubVOList"
  178. :key="dict.xyId"
  179. :label="dict.label"
  180. :value="dict.xyId"
  181. ></el-option>
  182. </el-select>
  183. <p style="width:30px;text-align: center;line-height:40px;">-</p>
  184. <el-select v-model="scope.row.sensorId" placeholder="请选择传感器"
  185. @change="(val)=>sensorChange(val,scope.row)"
  186. style="width:168px;">
  187. <el-option
  188. v-for="dict in scope.row.labSensorList"
  189. :key="dict.id"
  190. :label="dict.name"
  191. :value="dict.id"
  192. ></el-option>
  193. </el-select>
  194. <p style="color:#CCCCCC;font-size:16px;border:1px solid #E0E0E0;
  195. border-radius:4px;width:80px;height:30px;line-height:30px;
  196. display: inline-block;margin:5px 0 0 10px;text-align: center;cursor: pointer;" @click="addObjButton(2,scope.row)">取消</p>
  197. <p style="color:#0183FA;font-size:16px;border:1px solid #0183FA;
  198. border-radius:4px;width:80px;height:30px;line-height:30px;
  199. display: inline-block;margin:5px 0 0 10px;text-align: center;cursor: pointer;" @click="addObjButton(3,scope.row)">确定</p>
  200. </div>
  201. </div>
  202. </template>
  203. </el-table-column>
  204. </el-table>
  205. <pagination
  206. v-show="dialogTotal>0"
  207. :total="dialogTotal"
  208. :page.sync="param.pageNum"
  209. :limit.sync="param.pageSize"
  210. @pagination="getList"
  211. />
  212. </div>
  213. <div slot="footer" class="dialog-footer">
  214. <div style="display: flex">
  215. <p style="flex:1;"></p>
  216. <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>
  217. <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>
  218. <p style="flex:1;"></p>
  219. </div>
  220. </div>
  221. </el-dialog>
  222. </div>
  223. </template>
  224. <script>
  225. import { optionHardware } from "@/api/laboratory/hardware";
  226. import { optionSensor } from "@/api/laboratory/sensor";
  227. import { listClassifiedAll } from "@/api/laboratory/classified";
  228. import { listClasstypeAll } from "@/api/laboratory/classtype";
  229. import { getLabRiskPlanJoinSub,getLabRiskPlanNoJoinSub,deleteRiskPlanJoinSub,riskPlanJoinSub,riskPlanBatchJoinSub } from "@/api/evacuation3_2/index";
  230. export default {
  231. name: 'newAssociatedPage',
  232. props:{
  233. associationData:{},
  234. },
  235. data() {
  236. return {
  237. loading:false,
  238. levelList:[],
  239. typeList:[],
  240. // 查询参数
  241. dateRange:[],
  242. queryParams:{
  243. pageNum: 1,
  244. pageSize:20,
  245. searchValue:"",
  246. },
  247. total:0,
  248. tableData:[],
  249. /***************关联危险源开始****************/
  250. // 选中数组
  251. ids: [],
  252. // 非单个禁用
  253. single: true,
  254. // 非多个禁用
  255. multiple: true,
  256. // 查询数据
  257. param:{
  258. pageNum:1,
  259. pageSize:10,
  260. },
  261. dialogTotal:5,
  262. //关联实验室
  263. dialogAssociatedOpen:false,
  264. dialogTableData:[],
  265. //传感器
  266. sensorList:[],
  267. sensorListData:[],
  268. //设备
  269. hardwareList:[],
  270. /***************关联危险源结束****************/
  271. allNum:0,
  272. }
  273. },
  274. created(){
  275. this.getListAll();
  276. },
  277. mounted(){
  278. this.getList();
  279. },
  280. methods:{
  281. getListAll(){
  282. optionSensor({}).then(response => {
  283. this.sensorList = response.data;
  284. this.sensorListData = JSON.parse(JSON.stringify(response.data))
  285. });
  286. optionHardware({}).then(response => {
  287. this.hardwareList = response.data;
  288. });
  289. listClassifiedAll().then(response=>{
  290. if(response.code==200){
  291. this.levelList=response.data
  292. }
  293. })
  294. listClasstypeAll().then(response=>{
  295. if(response.code==200){
  296. this.typeList=response.data;
  297. }
  298. });
  299. },
  300. //新增关联实验室弹窗
  301. handleAdd(type){
  302. let self = this;
  303. if (type == 1){
  304. this.resetForm();
  305. this.$set(this,'allNum',0);
  306. this.$set(this,'dialogAssociatedOpen',true);
  307. }else if(type == 2){
  308. this.$set(this,'dialogAssociatedOpen',false);
  309. }else if(type == 3){
  310. let list = JSON.parse(JSON.stringify(this.$refs.table.selection));
  311. if(!list[0]){
  312. this.msgError('请勾选需要关联的实验室');
  313. return
  314. }
  315. let newList = [];
  316. for(let i=0;i<list.length;i++){
  317. let obj = {
  318. riskPlanId:self.associationData.id,
  319. subjectId:list[i].id,
  320. labSensorHazardRelations:list[i].buttonList,
  321. }
  322. newList.push(obj);
  323. }
  324. let newObj = {
  325. riskPlanId:self.associationData.id,
  326. yesOrNo:0,
  327. labRiskPlanSubVos:newList,
  328. }
  329. riskPlanJoinSub(newObj).then(response => {
  330. if(response.data.ifConflict == 1){
  331. self.$confirm(response.data.message, "警告", {
  332. confirmButtonText: "确定",
  333. cancelButtonText: "取消",
  334. type: "warning"
  335. }).then(function() {
  336. let newData = {
  337. riskPlanId:self.associationData.id,
  338. yesOrNo:1,
  339. labRiskPlanSubVos:newList,
  340. }
  341. riskPlanJoinSub(newData).then(response => {
  342. self.msgSuccess(response.msg);
  343. self.resetQuery();
  344. self.$set(self,'dialogAssociatedOpen',false);
  345. });
  346. }).then(() => {
  347. }).catch(() => {});
  348. }else{
  349. self.msgSuccess(response.msg);
  350. self.resetQuery();
  351. self.$set(self,'dialogAssociatedOpen',false);
  352. }
  353. });
  354. }
  355. },
  356. //查询
  357. onSearch(){
  358. this.$set(this.param,'pageNum',1);
  359. this.getLabRiskPlanNoJoinSub();
  360. },
  361. //重置
  362. resetForm(){
  363. this.$set(this,'param',{
  364. pageNum:1,
  365. pageSize:20,
  366. searchValue:"",
  367. typeId:"",
  368. level:"",
  369. });
  370. this.$set(this,'dialogTotal',0);
  371. this.$set(this,'dialogTableData',[]);
  372. this.onSearch();
  373. },
  374. //获取未关联实验室列表
  375. getLabRiskPlanNoJoinSub(){
  376. this.$set(this.param,'riskPlanId',this.associationData.id);
  377. getLabRiskPlanNoJoinSub(this.param).then(response => {
  378. for(let i=0;i<response.rows.length;i++){
  379. response.rows[i].buttonType = 0;
  380. response.rows[i].buttonList = [];
  381. response.rows[i].sensorId = null;
  382. response.rows[i].sensorName = null;
  383. response.rows[i].hazardSubjectId = null;
  384. response.rows[i].hazardSubjectName = null;
  385. }
  386. this.dialogTableData = response.rows;
  387. this.dialogTotal = response.total;
  388. this.loading = false;
  389. });
  390. },
  391. //新增对象至选中实验室
  392. addObjButton(type,item){
  393. if(type == 1){
  394. if(item.buttonList.length>8){
  395. this.msgError('最多添加9项')
  396. return
  397. }
  398. item.buttonType = 1;
  399. }else if(type == 2){
  400. item.buttonType = 0;
  401. }else if(type == 3){
  402. if(item.sensorId == null){
  403. this.msgError('请选择要添加的危险源')
  404. return
  405. }
  406. if(item.hazardSubjectId == null){
  407. this.msgError('请选择要添加的传感器')
  408. return
  409. }
  410. let obj = {
  411. sensorId:item.sensorId,
  412. sensorName:item.sensorName,
  413. hazardSubjectId:item.hazardSubjectId,
  414. hazardSubjectName:item.hazardSubjectName,
  415. };
  416. for(let i=0;i<item.buttonList.length;i++){
  417. if(item.buttonList[i].sensorId == item.sensorId && item.buttonList[i].hazardSubjectId == item.hazardSubjectId){
  418. this.msgError('该条件已存在');
  419. return
  420. }
  421. }
  422. item.buttonList.push(obj);
  423. item.sensorId = null;
  424. item.sensorName = null;
  425. item.hazardSubjectId = null;
  426. item.hazardSubjectName = null;
  427. item.buttonType = 0;
  428. this.$forceUpdate();
  429. }
  430. },
  431. //删除列表内的对象
  432. delMinObj(list,index){
  433. list.splice(index,1)
  434. this.$forceUpdate();
  435. },
  436. sensorChange(val,row){
  437. console.log('传感器')
  438. for(let i=0;i<row.labSensorList.length;i++){
  439. if(row.labSensorList[i].id == val){
  440. row.sensorId = row.labSensorList[i].id;
  441. row.sensorName = row.labSensorList[i].name;
  442. }
  443. }
  444. this.$forceUpdate();
  445. },
  446. hardwareChange(val,row){
  447. console.log('危险源')
  448. for(let i=0;i<row.labHazardSubVOList.length;i++){
  449. if(row.labHazardSubVOList[i].xyId == val){
  450. row.hazardSubjectId = row.labHazardSubVOList[i].xyId;
  451. row.hazardSubjectName = row.labHazardSubVOList[i].label;
  452. }
  453. }
  454. this.$forceUpdate();
  455. },
  456. //删除关联实验室
  457. handleDelete(item){
  458. let self = this;
  459. this.$confirm('确定要删除该预案规则吗?', "警告", {
  460. confirmButtonText: "确定",
  461. cancelButtonText: "取消",
  462. type: "warning"
  463. }).then(function() {
  464. let obj = {
  465. riskPlanId:self.associationData.id,
  466. subjectId:item.id
  467. }
  468. deleteRiskPlanJoinSub(obj).then((response) => {
  469. self.msgSuccess(response.msg)
  470. self.resetQuery();
  471. });
  472. }).then(() => {
  473. }).catch(() => {});
  474. },
  475. //查询
  476. handleQuery(){
  477. this.$set(this.queryParams,'pageNum',1);
  478. if(this.dateRange[0]){
  479. this.queryParams.startDate = this.dateRange[0]
  480. this.queryParams.endDate = this.dateRange[1]
  481. }else {
  482. this.queryParams.startDate = null
  483. this.queryParams.endDate = null
  484. }
  485. this.getList();
  486. },
  487. //重置
  488. resetQuery(){
  489. this.$set(this,'queryParams',{
  490. pageNum:1,
  491. pageSize:20,
  492. searchValue:"",
  493. typeId:"",
  494. level:"",
  495. });
  496. this.$set(this,'dateRange',[]);
  497. this.$set(this,'total',0);
  498. this.$set(this,'tableData',[]);
  499. this.handleQuery();
  500. },
  501. /** 查询列表 */
  502. getList() {
  503. let self = this;
  504. this.loading = true;
  505. this.$set(this.queryParams,'riskPlanId',this.associationData.id);
  506. getLabRiskPlanJoinSub(this.queryParams).then(response => {
  507. for(let i=0;i<response.rows.length;i++){
  508. for(let o=0;o<self.typeList.length;o++){
  509. if(response.rows[i].typeId == self.typeList[o].id){
  510. response.rows[i].typeName = self.typeList[o].typeName;
  511. }
  512. }
  513. for(let o=0;o<self.levelList.length;o++){
  514. if(response.rows[i].level == self.levelList[o].id){
  515. response.rows[i].leveName = self.levelList[o].classifiedName;
  516. }
  517. }
  518. response.rows[i].labSensorHazardRelationsList = [];
  519. for(let o=0;o<response.rows[i].labSensorHazardRelations.length;o++){
  520. let obj = {
  521. hazardName:response.rows[i].labSensorHazardRelations[o].hazardName,
  522. sensorName:response.rows[i].labSensorHazardRelations[o].sensorName,
  523. }
  524. response.rows[i].labSensorHazardRelationsList.push(obj);
  525. }
  526. }
  527. this.tableData = response.rows;
  528. this.total = response.total;
  529. this.loading = false;
  530. });
  531. },
  532. //返回
  533. backButton(){
  534. if(this.associationData.type == 1){
  535. this.$parent.tableClickButton(6)
  536. }else{
  537. this.$parent.tableClickButton(5)
  538. }
  539. },
  540. /*===记录勾选数据===
  541. 需要再el-table 添加 :row-key="getRowKeys"
  542. 需要在selection 添加 :reserve-selection="true"
  543. */
  544. getRowKeys(row) {
  545. return row.id
  546. },
  547. //勾选
  548. handleSelectionChange(selection){
  549. this.$set(this,'allNum',selection.length);
  550. // console.log('selection',selection)
  551. },
  552. allButton(type){
  553. let self = this;
  554. if(type == 1){
  555. let list = [];
  556. for(let i=0;i<self.dialogTableData.length;i++){
  557. list.push(self.dialogTableData[i].id);
  558. }
  559. let obj = {
  560. riskPlanId:self.associationData.id,
  561. subjectIds:list+''
  562. }
  563. riskPlanBatchJoinSub(obj).then(response => {
  564. this.msgSuccess(response.msg);
  565. this.resetQuery();
  566. this.$set(this,'dialogAssociatedOpen',false);
  567. });
  568. }else if(type == 2){
  569. let obj = {
  570. riskPlanId:self.associationData.id,
  571. searchValue:self.param.searchValue,
  572. typeId:self.param.typeId,
  573. level:self.param.level,
  574. subjectIds:'-1'
  575. };
  576. riskPlanBatchJoinSub(obj).then(response => {
  577. this.msgSuccess(response.msg);
  578. this.resetQuery();
  579. this.$set(this,'dialogAssociatedOpen',false);
  580. });
  581. }
  582. },
  583. },
  584. }
  585. </script>
  586. <style scoped lang="scss">
  587. .newAssociatedPage{
  588. flex: 1;
  589. display: flex !important;
  590. flex-direction: column;
  591. overflow: hidden;
  592. padding:20px;
  593. p {
  594. margin: 0;
  595. font-weight: 500;
  596. }
  597. }
  598. </style>