safetyInfoConfig.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <!--安全信息类目-->
  2. <template>
  3. <div class="app-container approval_handle">
  4. <div class="tab-title">
  5. <div class="tab-title-l">
  6. <template>
  7. <el-tabs v-model="activeName" @tab-click="handleTabClick">
  8. <el-tab-pane :label="item.classifyName" :name="item.id+''" v-for="item in tabsList"></el-tab-pane>
  9. </el-tabs>
  10. </template>
  11. </div>
  12. <el-button
  13. type="primary"
  14. plain
  15. icon="el-icon-plus"
  16. size="mini"
  17. @click="handleClick('','','add')"
  18. >新增</el-button>
  19. </div>
  20. <div class="approval_handle-page" v-if="pageType == 1">
  21. <el-table border v-loading="loading" :data="tableData">
  22. <el-table-column label="序号" width="100" align="left" type="index"/>
  23. <el-table-column label="信息名称" align="left" prop="infoName"/>
  24. <el-table-column label="公共信息" align="left">
  25. <template slot-scope="scope">
  26. <el-switch
  27. @click.native="categoryShow(scope.row)"
  28. class="category-switch captcha-img"
  29. :active-value="2"
  30. :inactive-value="1"
  31. active-color="#FF9900"
  32. inactive-color="#999"
  33. v-model="scope.row.isCollective"
  34. active-text="是"
  35. inactive-text="否"
  36. disabled
  37. ></el-switch>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="添加人" align="left" prop="createBy"/>
  41. <el-table-column label="添加时间" align="left" prop="createTime"/>
  42. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120">
  43. <template slot-scope="scope">
  44. <div class="button-box">
  45. <p class="table-min-button"
  46. @click="handleClick('',scope.row,'edit')"
  47. >编辑</p>
  48. <p class="table-min-button"
  49. @click="handleClick('',scope.row,'delete')"
  50. >删除</p>
  51. </div>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <pagination :page-sizes="[20, 30, 40, 50]"
  56. :total="total"
  57. layout="total, prev, pager, next, sizes, jumper"
  58. :page.sync="queryParams.pageNum"
  59. :limit.sync="queryParams.pageSize"
  60. @pagination="getList"
  61. />
  62. </div>
  63. <safety-Info-Config v-if="pageType == 2"></safety-Info-Config>
  64. <!-- 添加或修改安全分级对话框 -->
  65. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  66. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  67. <el-form-item label="信息名称" prop="infoName">
  68. <el-input v-model="form.infoName" maxlength="10" placeholder="请输入名称" style="width:320px;"/>
  69. </el-form-item>
  70. <el-form-item label="信息类目" prop="infoClassifyId" class="form-item">
  71. <el-select placeholder="请选择类目" v-model="form.infoClassifyId" style="width:320px;" @change="categoryClick()">
  72. <el-option
  73. v-for="dict in categoryList"
  74. :key="dict.id"
  75. :label="dict.classifyName"
  76. :value="dict.id"
  77. ></el-option>
  78. </el-select>
  79. </el-form-item>
  80. <el-form-item label="信息类型">
  81. <el-input v-model="form.infoTypeName" placeholder="" disabled style="width:320px;"/>
  82. </el-form-item>
  83. <el-form-item label="信息内容" prop="infoContent" v-if="form.infoType==1">
  84. <el-input type="textarea" v-model="form.infoContent" placeholder="请输入内容" style="width:320px;"/>
  85. </el-form-item>
  86. <el-form-item label="信息内容" prop="infoContent" v-if="form.infoType==2">
  87. <el-upload
  88. class="certificate-avatar-uploader"
  89. :action="uploadImgUrl"
  90. :show-file-list="false"
  91. :on-success="handleAvatarSuccess"
  92. :headers="headers"
  93. :before-upload="beforeAvatarUpload">
  94. <div style="display: flex;">
  95. <img v-if="form.infoContent" :src="form.infoContent" style="width: 80px;height: 80px;margin-right: 10px">
  96. <i v-if="!form.infoContent" class="el-icon-plus avatar-uploader-icon"></i>
  97. </div>
  98. </el-upload>
  99. </el-form-item>
  100. </el-form>
  101. <div slot="footer" class="dialog-footer">
  102. <el-button type="primary" @click="submitForm">确 定</el-button>
  103. <el-button @click="cancel">取 消</el-button>
  104. </div>
  105. </el-dialog>
  106. </div>
  107. </template>
  108. <script>
  109. import { getToken } from "@/utils/auth";
  110. import {
  111. infoCategoryList,
  112. infoConfigAdd, infoConfigList, infoConfigPut,infoConfigDelete
  113. } from '@/api/laboratory/safetyInfo'
  114. import safetyInfoConfig from "./safetyInfoConfig.vue"
  115. import { listHazard } from '@/api/permissionRequired'
  116. export default {
  117. name: "Approval",
  118. components: {
  119. safetyInfoConfig
  120. },
  121. data() {
  122. return {
  123. uploadImgUrl: this.uploadUrl(), // 上传的图片服务器地址
  124. activeName: '',
  125. // 弹出层标题
  126. title: "",
  127. // 是否显示弹出层
  128. open: false,
  129. //页面状态
  130. pageType:1,
  131. loading:false,
  132. headers: {
  133. Authorization: "Bearer " + getToken()
  134. },
  135. // 查询参数
  136. queryParams: {
  137. pageNum: 1,
  138. pageSize:20,
  139. infoClassifyId:'',
  140. },
  141. total:0,
  142. tableData:[{}],
  143. dateRange:[],
  144. pageData2:{},
  145. tabsList:[],
  146. categoryList:[],
  147. // 表单参数
  148. form: {
  149. infoName:'',
  150. infoClassifyId:'',
  151. infoType:'',
  152. infoTypeName:'',
  153. infoContent:'',
  154. isCollective:'',
  155. },
  156. // 表单校验
  157. rules: {
  158. infoName: [
  159. { required: true, message: "请输入名称", trigger: "blur" },
  160. ],
  161. infoClassifyId: [
  162. { required: true, message: "请选择类目", trigger: "blur" },
  163. ],
  164. infoContent: [
  165. { required: true, message: "请添加信息内容", trigger: "blur" },
  166. ],
  167. }
  168. };
  169. },
  170. methods: {
  171. handleTabClick(tab){
  172. this.queryParams.infoClassifyId=tab.name;
  173. this.getList()
  174. },
  175. handleClick(index,row,doType){
  176. let self=this;
  177. if(doType=='add'){//添加
  178. delete this.form.id
  179. this.form.infoName='';
  180. this.form.infoClassifyId='';
  181. this.form.infoType='';
  182. this.form.infoTypeName='';
  183. this.form.infoContent='';
  184. this.open = true;
  185. }else if(doType=='edit'){//编辑
  186. this.form.id=row.id
  187. this.form.infoName=row.infoName
  188. this.form.infoClassifyId=row.infoClassifyId
  189. this.form.infoContent=row.infoContent
  190. this.form.infoType=row.infoType
  191. this.form.infoTypeName=row.infoType==1?'文字':'图片';
  192. this.open = true;
  193. }else if(doType=='deploy'){//信息牌配置
  194. self.pageType=2;
  195. }else if(doType=='delete'){//删除
  196. this.$confirm('确认要删除吗?', "警告", {
  197. confirmButtonText: "确定",
  198. cancelButtonText: "取消",
  199. type: "warning"
  200. }).then(() => {
  201. // 确定
  202. infoConfigDelete(row.id).then(response => {
  203. self.msgSuccess(response.msg);
  204. self.getList();
  205. });
  206. }).catch(function() {});
  207. }else if(doType=='back'){//返回
  208. self.pageType=1;
  209. }
  210. },
  211. categoryShow(row){
  212. let obj={
  213. id:row.id,
  214. isCollective:row.isCollective==1?2:1,
  215. }
  216. infoConfigPut(obj).then( response => {
  217. this.msgSuccess("修改成功");
  218. this.open = false;
  219. this.getList();
  220. });
  221. },
  222. categoryClick(){
  223. let _this=this;
  224. this.form.infoContent='';
  225. this.categoryList.forEach(function(item) {
  226. if(item.id==_this.form.infoClassifyId){
  227. _this.form.infoTypeName=item.classifyType==1?'文字':'图片';
  228. _this.form.infoType=item.classifyType;
  229. }
  230. })
  231. },
  232. /** 搜索按钮操作 */
  233. handleQuery() {
  234. this.queryParams.pageNum = 1;
  235. this.getList();
  236. },
  237. /** 重置按钮操作 */
  238. resetQuery() {
  239. this.handleQuery();
  240. },
  241. /** 取消按钮 */
  242. cancel() {
  243. this.open = false;
  244. },
  245. /** 提交按钮 */
  246. submitForm() {
  247. this.$refs["form"].validate(valid => {
  248. if (valid) {
  249. if (this.form.id != null) {
  250. infoConfigPut(this.form).then( response => {
  251. this.msgSuccess("修改成功");
  252. this.open = false;
  253. this.getList();
  254. });
  255. } else {
  256. infoConfigAdd(this.form).then( response => {
  257. this.msgSuccess("新增成功");
  258. this.open = false;
  259. this.getList();
  260. });
  261. }
  262. }
  263. });
  264. },
  265. //上传
  266. handleAvatarSuccess(res, file) {
  267. this.form.infoContent = res.data.url;
  268. this.$forceUpdate()
  269. },
  270. beforeAvatarUpload(file) {
  271. let type = false;
  272. if (file.type == 'image/png' || file.type == 'image/jpeg' || file.type == 'image/gif') {
  273. type = true;
  274. }else{
  275. this.$message.error('只能上传png/jpeg/gif格式图片');
  276. type = false;
  277. }
  278. return type;
  279. },
  280. //获取危险源列表
  281. getCategory(){
  282. listHazard({}).then(response=>{
  283. this.$set(this,'categoryList',response.data);
  284. })
  285. },
  286. //查询信息类目列表
  287. getCategoryList(){
  288. let _this=this;
  289. let obj={
  290. pageNum: 1,
  291. pageSize:100,
  292. isShow:1,
  293. remark:'sort',
  294. }
  295. infoCategoryList(obj).then( response => {
  296. let res=response.rows;
  297. if(response.code==200){
  298. if(res){
  299. _this.tabsList=res;
  300. _this.categoryList=res;
  301. _this.activeName=response.rows[0].id+''
  302. _this.queryParams.infoClassifyId=response.rows[0].id;
  303. this.getList()
  304. }
  305. }
  306. });
  307. },
  308. getList(){
  309. let _this=this;
  310. infoConfigList(_this.queryParams).then( response => {
  311. let res=response.rows;
  312. _this.tableData=res;
  313. _this.total=response.total;
  314. });
  315. },
  316. },
  317. mounted() {
  318. this.getCategoryList()
  319. }
  320. };
  321. </script>
  322. <style scoped lang="scss">
  323. .approval_handle {
  324. display: flex!important;
  325. flex-direction: column;
  326. flex-direction: column;
  327. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  328. border-radius:10px;
  329. padding-top: 20px !important;
  330. .approval_handle-page{
  331. padding:20px 20px 20px!important;
  332. flex:1;
  333. display: flex!important;
  334. flex-direction: column;
  335. .button-box{
  336. width:200px;
  337. display: flex;
  338. }
  339. }
  340. }
  341. </style>
  342. <style lang="scss">
  343. .tab-title{
  344. display: flex;
  345. justify-content: space-between;
  346. padding-bottom: 20px;
  347. box-sizing: border-box;
  348. border-bottom: 1px solid #E0E0E0;
  349. padding: 0 20px;
  350. .tab-title-l{
  351. flex: 1;
  352. .el-tabs__nav-wrap::after{
  353. background-color: #fff !important;
  354. }
  355. }
  356. }
  357. .category-switch .el-switch__label {
  358. position: absolute;
  359. display: none;
  360. color: #fff !important;
  361. }
  362. .category-switch .el-switch__label--right span {
  363. margin-left: 10px;
  364. }
  365. .category-switch .el-switch__label--left {
  366. z-index: 1;
  367. }
  368. .category-switch .el-switch__label--left span {
  369. margin-left: 24px;
  370. }
  371. .category-switch .el-switch__label.is-active {
  372. display: block;
  373. }
  374. .category-switch.el-switch .el-switch__core,
  375. .el-switch .el-switch__label {
  376. width: 60px !important;
  377. margin: 0;
  378. }
  379. </style>