safetyInfoConfig.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <!--安全信息配置-->
  2. <template>
  3. <div class=" safetyInfoConfig">
  4. <div class="title-box">
  5. <div @click="titleClick(1)">
  6. <p>安全类目</p>
  7. <p></p>
  8. </div>
  9. <div @click="titleClick(2)">
  10. <p>信息配置</p>
  11. <p class="bottom-p-color"></p>
  12. </div>
  13. </div>
  14. <div class="config_main">
  15. <div class="config_main_l scrollbar-box">
  16. <div class="config_main_l_title">
  17. <img src="@/assets/ZDimages/icon_xxpz_aqxxlm.png">
  18. 安全信息类目
  19. </div>
  20. <div :class='currentIndex==index?"active":""' class="config_main_l_li" v-for="(item,index) in tabsList" :key="index" @click="handleTabClick(item,index)">{{item.classifyName}}</div>
  21. </div>
  22. <p class="config_main_border"></p>
  23. <div class="approval_handle-page">
  24. <p>
  25. <el-button
  26. style="float: right;margin-bottom: 20px"
  27. v-hasPermi="['laboratory:classifyDet:add']"
  28. type="primary"
  29. plain
  30. icon="el-icon-plus"
  31. size="mini"
  32. @click="handleClick('','','add')"
  33. >新增</el-button>
  34. </p>
  35. <el-table border v-loading="loading" :data="tableData">
  36. <el-table-column label="序号" align="left" prop="sort" width="50"/>
  37. <el-table-column label="信息名称" align="left" prop="infoName"/>
  38. <el-table-column label="公共信息" align="left">
  39. <template slot-scope="scope">
  40. <el-switch
  41. @click.native="categoryShow(scope.row)"
  42. class="category-switch captcha-img"
  43. :active-value="2"
  44. :inactive-value="1"
  45. active-color="#FF9900"
  46. inactive-color="#999"
  47. v-model="scope.row.isCollective"
  48. active-text="是"
  49. inactive-text="否"
  50. disabled
  51. ></el-switch>
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="添加人" align="left" prop="createBy"/>
  55. <el-table-column label="添加时间" align="left" prop="createTime"/>
  56. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120">
  57. <template slot-scope="scope">
  58. <div class="button-box">
  59. <p class="table-min-button"
  60. v-hasPermi="['laboratory:classifyDet:edit']"
  61. @click="handleClick('',scope.row,'edit')"
  62. >编辑</p>
  63. <p class="table-min-button"
  64. v-hasPermi="['laboratory:classifyDet:remove']"
  65. @click="handleClick('',scope.row,'delete')"
  66. >删除</p>
  67. </div>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <pagination :page-sizes="[20, 30, 40, 50]"
  72. :total="total"
  73. layout="total, prev, pager, next, sizes, jumper"
  74. :page.sync="queryParams.pageNum"
  75. :limit.sync="queryParams.pageSize"
  76. @pagination="getList"
  77. />
  78. </div>
  79. </div>
  80. <!-- 添加或修改安全分级对话框 -->
  81. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body :before-close="closeDialog">
  82. <el-form ref="form" :model="form" :rules="rules" label-width="80px" >
  83. <el-form-item label="信息名称" prop="infoName">
  84. <el-input v-model="form.infoName" maxlength="10" placeholder="请输入名称" style="width:320px;"/>
  85. </el-form-item>
  86. <el-form-item label="信息类目" prop="infoClassifyId" class="form-item">
  87. <el-select placeholder="请选择类目" v-model="form.infoClassifyId" style="width:320px;" @change="categoryClick()">
  88. <el-option
  89. v-for="dict in categoryList"
  90. :key="dict.id"
  91. :label="dict.classifyName"
  92. :value="dict.id"
  93. ></el-option>
  94. </el-select>
  95. </el-form-item>
  96. <el-form-item label="信息类型">
  97. <el-input v-model="form.infoTypeName" placeholder="" disabled style="width:320px;"/>
  98. </el-form-item>
  99. <el-form-item label="信息内容" prop="infoContent" v-if="form.infoType==1">
  100. <el-input type="textarea" v-model="form.infoContent" maxlength="200" placeholder="请输入内容" style="width:320px;"/>
  101. </el-form-item>
  102. <el-form-item label="信息内容" prop="infoContent" v-if="form.infoType==2">
  103. <el-upload
  104. class="certificate-avatar-uploader"
  105. :action="uploadImgUrl"
  106. :show-file-list="false"
  107. :on-success="handleAvatarSuccess"
  108. :headers="headers"
  109. :before-upload="beforeAvatarUpload">
  110. <div style="display: flex;">
  111. <img v-if="form.infoContent" :src="form.infoContent" style="width: 80px;height: 80px;margin-right: 10px">
  112. <i v-if="!form.infoContent" class="el-icon-plus avatar-uploader-icon"></i>
  113. </div>
  114. </el-upload>
  115. </el-form-item>
  116. <P v-if="form.infoType==2" style="margin-left: 80px">图片最大上传630*78,建议尺寸58*78</P>
  117. </el-form>
  118. <div slot="footer" class="dialog-footer">
  119. <el-button type="primary" @click="submitForm">确 定</el-button>
  120. <el-button @click="cancel">取 消</el-button>
  121. </div>
  122. </el-dialog>
  123. </div>
  124. </template>
  125. <script>
  126. import { getToken } from "@/utils/auth";
  127. import {
  128. infoCategoryList,
  129. infoConfigAdd, infoConfigList, infoConfigPut,infoConfigDelete
  130. } from '@/api/laboratory/safetyInfo'
  131. import safetyInfoConfig from "./safetyInfoConfig.vue"
  132. import { listHazard } from '@/api/permissionRequired'
  133. export default {
  134. name: "Approval",
  135. components: {
  136. safetyInfoConfig
  137. },
  138. data() {
  139. return {
  140. uploadImgUrl: this.uploadUrl(), // 上传的图片服务器地址
  141. activeName: '',
  142. // 弹出层标题
  143. title: "",
  144. // 是否显示弹出层
  145. open: false,
  146. //页面状态
  147. pageType:1,
  148. loading:false,
  149. headers: {
  150. Authorization: "Bearer " + getToken()
  151. },
  152. // 查询参数
  153. queryParams: {
  154. pageNum: 1,
  155. pageSize:20,
  156. infoClassifyId:'',
  157. },
  158. total:0,
  159. tableData:[{}],
  160. dateRange:[],
  161. pageData2:{},
  162. tabsList:[],
  163. categoryList:[],
  164. // 表单参数
  165. form: {
  166. infoName:'',
  167. infoClassifyId:'',
  168. infoType:'',
  169. infoTypeName:'',
  170. infoContent:'',
  171. isCollective:'',
  172. },
  173. currentIndex:0,
  174. // 表单校验
  175. rules: {
  176. infoName: [
  177. { required: true, message: "请输入名称", trigger: "blur" },
  178. ],
  179. infoClassifyId: [
  180. { required: true, message: "请选择类目", trigger: "blur" },
  181. ],
  182. infoContent: [
  183. { required: true, message: "请添加信息内容", trigger: "blur" },
  184. ],
  185. }
  186. };
  187. },
  188. methods: {
  189. titleClick(type){
  190. this.$parent.titleClick(type);
  191. },
  192. closeDialog(){
  193. this.$refs['form'].clearValidate()
  194. this.open=false
  195. },
  196. handleTabClick(item,index){
  197. this.currentIndex = index
  198. this.queryParams.infoClassifyId=item.id;
  199. this.getList()
  200. },
  201. handleClick(index,row,doType){
  202. let self=this;
  203. if(doType=='add'){//添加
  204. this.title='新增安全信息';
  205. delete this.form.id
  206. this.form.infoName='';
  207. this.form.infoClassifyId='';
  208. this.form.infoType='';
  209. this.form.infoTypeName='';
  210. this.form.infoContent='';
  211. this.open = true;
  212. }else if(doType=='edit'){//编辑
  213. this.title='编辑安全信息';
  214. this.form.id=row.id
  215. this.form.infoName=row.infoName
  216. this.form.infoClassifyId=row.infoClassifyId
  217. this.form.infoContent=row.infoContent
  218. this.form.infoType=row.infoType
  219. this.form.infoTypeName=row.infoType==1?'文字':'图片';
  220. this.open = true;
  221. }else if(doType=='deploy'){//信息牌配置
  222. self.pageType=2;
  223. }else if(doType=='delete'){//删除
  224. this.$confirm('确认要删除吗?', "警告", {
  225. confirmButtonText: "确定",
  226. cancelButtonText: "取消",
  227. type: "warning"
  228. }).then(() => {
  229. // 确定
  230. infoConfigDelete(row.id).then(response => {
  231. self.msgSuccess(response.msg);
  232. self.getList();
  233. });
  234. }).catch(function() {});
  235. }else if(doType=='back'){//返回
  236. self.pageType=1;
  237. }
  238. },
  239. categoryShow(row){
  240. let obj={
  241. id:row.id,
  242. isCollective:row.isCollective==1?2:1,
  243. }
  244. infoConfigPut(obj).then( response => {
  245. this.msgSuccess("修改成功");
  246. this.open = false;
  247. this.getList();
  248. });
  249. },
  250. categoryClick(){
  251. let _this=this;
  252. this.form.infoContent='';
  253. this.categoryList.forEach(function(item) {
  254. if(item.id==_this.form.infoClassifyId){
  255. _this.form.infoTypeName=item.classifyType==1?'文字':'图片';
  256. _this.form.infoType=item.classifyType;
  257. }
  258. })
  259. },
  260. /** 搜索按钮操作 */
  261. handleQuery() {
  262. this.queryParams.pageNum = 1;
  263. this.getList();
  264. },
  265. /** 重置按钮操作 */
  266. resetQuery() {
  267. this.handleQuery();
  268. },
  269. /** 取消按钮 */
  270. cancel() {
  271. this.$refs['form'].clearValidate()
  272. this.open = false;
  273. },
  274. /** 提交按钮 */
  275. submitForm() {
  276. this.$refs["form"].validate(valid => {
  277. if (valid) {
  278. if (this.form.id != null) {
  279. infoConfigPut(this.form).then( response => {
  280. this.msgSuccess("修改成功");
  281. this.open = false;
  282. this.getList();
  283. });
  284. } else {
  285. infoConfigAdd(this.form).then( response => {
  286. this.msgSuccess("新增成功");
  287. this.open = false;
  288. this.getList();
  289. });
  290. }
  291. }
  292. });
  293. },
  294. //上传
  295. handleAvatarSuccess(res, file) {
  296. this.form.infoContent = res.data.url;
  297. this.$forceUpdate()
  298. },
  299. beforeAvatarUpload(file) {
  300. return new Promise((resolve, reject) => {
  301. if (file.type == 'image/png') {
  302. let reader = new FileReader()
  303. reader.readAsDataURL(file) // 必须用file.raw
  304. reader.onload = e => { // 让页面中的img标签的src指向读取的路径
  305. let img = e.target.result;
  306. const image = new Image()
  307. image.src=img
  308. image.onload = _=>{
  309. console.log(image.width)
  310. console.log(image.height)
  311. if(image.width <= 630 && image.height <= 78){
  312. resolve()
  313. }else{
  314. this.$message.error('尺寸限制为最大630*78px,支持PNG格式')
  315. reject();
  316. }
  317. }
  318. }
  319. }else{
  320. this.$message.error('请上传PNG格式');
  321. reject();
  322. }
  323. })
  324. },
  325. //获取危险源列表
  326. getCategory(){
  327. listHazard({}).then(response=>{
  328. this.$set(this,'categoryList',response.data);
  329. })
  330. },
  331. //查询信息类目列表
  332. getCategoryList(){
  333. let _this=this;
  334. let obj={
  335. pageNum: 1,
  336. pageSize:100,
  337. isShow:1,
  338. remark:'sort',
  339. }
  340. infoCategoryList(obj).then( response => {
  341. let res=response.rows;
  342. if(response.code==200){
  343. if(res){
  344. _this.tabsList=res;
  345. _this.categoryList=res;
  346. _this.activeName=response.rows[0].id+''
  347. _this.queryParams.infoClassifyId=response.rows[0].id;
  348. this.getList()
  349. }
  350. }
  351. });
  352. },
  353. getList(){
  354. let _this=this;
  355. infoConfigList(_this.queryParams).then( response => {
  356. let res=response.rows;
  357. _this.tableData=res;
  358. _this.total=response.total;
  359. });
  360. },
  361. },
  362. mounted() {
  363. this.getCategoryList()
  364. }
  365. };
  366. </script>
  367. <style scoped lang="scss">
  368. .safetyInfoConfig {
  369. overflow: hidden;
  370. flex:1;
  371. display: flex!important;
  372. flex-direction: column;
  373. .title-box{
  374. display: flex;
  375. border-bottom:1px solid #E0E0E0;
  376. margin-bottom:20px;
  377. div{
  378. height:80px;
  379. margin-right:20px;
  380. cursor: pointer;
  381. p:nth-child(1){
  382. font-size:18px;
  383. text-align: center;
  384. padding:0 20px;
  385. margin-top:26px;
  386. }
  387. p:nth-child(2){
  388. width:40px;
  389. height:4px;
  390. border-radius:40px;
  391. margin:12px auto;
  392. }
  393. .top-p-color{
  394. color: #0045AF;
  395. }
  396. .bottom-p-color{
  397. background: #0045AF;
  398. }
  399. }
  400. .buttonTitleColorA{
  401. color:#0045AF;
  402. }
  403. .buttonTitleColorB{
  404. color:#999999;
  405. }
  406. }
  407. .config_main{
  408. overflow: hidden;
  409. flex:1;
  410. display: flex;
  411. overflow: hidden;
  412. .config_main_l{
  413. flex: 1;
  414. padding-left: 42px;
  415. padding-top: 20px;
  416. .config_main_l_title{
  417. font-size: 16px;
  418. font-weight: 400;
  419. color: #0183FA;
  420. >img{
  421. width: 16px;
  422. height: 13px;
  423. margin-right: 12px;
  424. }
  425. }
  426. .config_main_l_li{
  427. font-size: 14px;
  428. font-family: Microsoft YaHei-Regular, Microsoft YaHei;
  429. font-weight: 400;
  430. color: #333333;
  431. line-height: 68px;
  432. cursor: pointer;
  433. }
  434. .active{
  435. color: #0183FA;
  436. }
  437. }
  438. .config_main_border{
  439. border-right: 1px dashed #A2A2A2;
  440. margin: 20px 35px 36px 0;
  441. }
  442. /*表格*/
  443. .approval_handle-page{
  444. display: flex!important;
  445. flex-direction: column;
  446. width: 1264px;
  447. padding:0px 20px 20px!important;
  448. .button-box{
  449. width:200px;
  450. display: flex;
  451. }
  452. }
  453. }
  454. }
  455. </style>
  456. <style lang="scss">
  457. .category-switch .el-switch__label {
  458. position: absolute;
  459. display: none;
  460. color: #fff !important;
  461. }
  462. .category-switch .el-switch__label--right span {
  463. margin-left: 10px;
  464. }
  465. .category-switch .el-switch__label--left {
  466. z-index: 1;
  467. }
  468. .category-switch .el-switch__label--left span {
  469. margin-left: 24px;
  470. }
  471. .category-switch .el-switch__label.is-active {
  472. display: block;
  473. }
  474. .category-switch.el-switch .el-switch__core,
  475. .el-switch .el-switch__label {
  476. width: 60px !important;
  477. margin: 0;
  478. }
  479. </style>