addPage.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <!--化学品柜管理/新增/编辑-->
  2. <template>
  3. <div class="addPage">
  4. <div class="title-box">
  5. <p>{{addPropsData.id?'编辑':'新增'}}</p>
  6. <p class="reset-button-one" @click="backPage"><i class="el-icon-arrow-left"></i>返回</p>
  7. </div>
  8. <el-form :model="formData" ref="form" :inline="true" :rules="rules" label-width="120px" style="margin-top:40px;">
  9. <div class="form-min-box">
  10. <el-form-item label="化学品柜:" prop="cabinetName">
  11. <el-input
  12. maxlength="15"
  13. style="width:400px;"
  14. v-model="formData.cabinetName"
  15. placeholder="请输入化学品柜"
  16. clearable
  17. size="small"/>
  18. </el-form-item>
  19. </div>
  20. <div class="form-min-box">
  21. <el-form-item label="所属学院:" prop="deptId">
  22. <el-select v-model="formData.deptId" placeholder="请选择所属学院" style="width:400px;" @change="deptChange(formData.deptId)" @clear="clearButton">
  23. <el-option
  24. v-for="item in optionsListOne"
  25. :key="item.deptId"
  26. :label="item.deptName"
  27. :value="item.deptId">
  28. </el-option>
  29. </el-select>
  30. </el-form-item>
  31. </div>
  32. <div class="form-min-box">
  33. <el-form-item label="实验室:" prop="subId">
  34. <el-select v-model="formData.subId" placeholder="请选择实验室" style="width:400px;" @change="subChange(formData.subId)">
  35. <el-option
  36. v-for="item in optionsListTwo"
  37. :key="item.id"
  38. :label="item.name"
  39. :value="item.id">
  40. </el-option>
  41. </el-select>
  42. </el-form-item>
  43. </div>
  44. <div class="form-text-box">
  45. <p>位置:</p>
  46. <p>{{address?address:'请选择学院与实验室'}}</p>
  47. </div>
  48. <div class="form-text-box" style="margin-top:24px;">
  49. <p>安全责任人:</p>
  50. <p>{{userName?userName:'请选择学院与实验室'}}</p>
  51. </div>
  52. <div class="bottom-button-box">
  53. <p class="inquire-button-one right-button" @click="upData">提交</p>
  54. </div>
  55. </el-form>
  56. </div>
  57. </template>
  58. <script>
  59. import { getAddress,hxpCabinet,putHxpCabinet } from "@/api/medicUniversity-3_1/index";
  60. import { listDepartments } from "@/api/system/dept";
  61. import { getNoAdminSubjectListNopage } from "@/api/laboratory/sparseHardware";
  62. export default {
  63. name: "addPage",
  64. props:{
  65. addPropsData:{},
  66. },
  67. data() {
  68. return {
  69. formData:{},
  70. optionsListOne:[],
  71. optionsListTwo:[],
  72. rules:{
  73. cabinetName:[
  74. { required: true, message: '请输入化学品柜', trigger: 'blur' },
  75. { required: true, message: "请输入化学品柜", validator: this.spaceJudgment, trigger: "blur" }
  76. ],
  77. deptId:[
  78. { required: true, message: '请选择所属学院', trigger: 'blur' },
  79. ],
  80. subId:[
  81. { required: true, message: '请选择实验室', trigger: 'blur' },
  82. ],
  83. },
  84. address:"",
  85. userName:"",
  86. };
  87. },
  88. created() {
  89. },
  90. mounted(){
  91. this.listDepartments();
  92. if(this.addPropsData.id){
  93. this.$set(this.formData,'cabinetName',this.addPropsData.cabinetName);
  94. this.$set(this.formData,'deptId',this.addPropsData.deptId);
  95. this.$set(this.formData,'subId',this.addPropsData.subId);
  96. this.getListData(this.formData.deptId);
  97. }
  98. },
  99. methods: {
  100. getListData(deptId){
  101. let self = this;
  102. let obj = {
  103. deptId:deptId,
  104. };
  105. getNoAdminSubjectListNopage(obj).then(response => {
  106. this.optionsListTwo = response.data;
  107. for(let i=0;i<self.optionsListTwo.length;i++){
  108. if(self.formData.subId == self.optionsListTwo[i].id){
  109. if(self.optionsListTwo[i].safeUserNames){
  110. self.userName = self.optionsListTwo[i].safeUserNames;
  111. }else{
  112. self.userName = "该实验室未设置安全责任人"
  113. }
  114. if(self.optionsListTwo[i].deptName && self.optionsListTwo[i].roomName){
  115. self.address = self.optionsListTwo[i].deptName+'-'+self.optionsListTwo[i].roomName;
  116. }else{
  117. self.address = "该实验室未设置位置"
  118. }
  119. // safeUserNames //负责人
  120. // getAddress(self.optionsListTwo[i].layoutId).then(response => {
  121. // if(response.data.deptName&&response.data.room){
  122. // self.address = response.data.deptName +'-'+ response.data.room;
  123. // }else{
  124. // self.address = "该实验室未设置位置"
  125. // }
  126. // });
  127. }
  128. }
  129. });
  130. },
  131. //数据提交操作
  132. upData(){
  133. this.$refs["form"].validate(valid => {
  134. if (valid) {
  135. if(this.addPropsData.id){
  136. //编辑
  137. let obj = {
  138. id:this.addPropsData.id,
  139. cabinetName:this.formData.cabinetName,
  140. subId:this.formData.subId,
  141. };
  142. putHxpCabinet(obj).then(response => {
  143. this.msgSuccess(response.msg)
  144. this.$parent.pageToggle(1,'get');
  145. });
  146. }else{
  147. //新增
  148. let obj = {
  149. cabinetName:this.formData.cabinetName,
  150. subId:this.formData.subId,
  151. }
  152. hxpCabinet(obj).then(response => {
  153. this.msgSuccess(response.msg)
  154. this.$parent.pageToggle(1,'refresh');
  155. });
  156. }
  157. }
  158. })
  159. },
  160. //学院清空操作
  161. clearButton(){
  162. this.$set(this,'optionsListTwo',[])
  163. this.$set(this.formData,'subId','')
  164. },
  165. //根据学院获取实验室
  166. deptChange(deptId){
  167. if (deptId){
  168. let obj = {
  169. deptId:deptId,
  170. }
  171. getNoAdminSubjectListNopage(obj).then(response => {
  172. this.optionsListTwo = response.data;
  173. this.$set(this.formData,'subId','')
  174. this.address = "";
  175. this.userName = "";
  176. });
  177. }
  178. },
  179. subChange(id){
  180. let self = this;
  181. for(let i=0;i<self.optionsListTwo.length;i++){
  182. if(id == self.optionsListTwo[i].id){
  183. if(self.optionsListTwo[i].safeUserNames){
  184. self.userName = self.optionsListTwo[i].safeUserNames;
  185. }else{
  186. self.userName = "该实验室未设置安全责任人"
  187. }
  188. if(self.optionsListTwo[i].deptName && self.optionsListTwo[i].roomName){
  189. self.address = self.optionsListTwo[i].deptName+'-'+self.optionsListTwo[i].roomName;
  190. }else{
  191. self.address = "该实验室未设置位置"
  192. }
  193. // safeUserNames //负责人
  194. // getAddress(self.optionsListTwo[i].layoutId).then(response => {
  195. // if(response.data.deptName&&response.data.room){
  196. // self.address = response.data.deptName +'-'+ response.data.room;
  197. // }else{
  198. // self.address = "该实验室未设置位置"
  199. // }
  200. // });
  201. }
  202. }
  203. },
  204. // 获取学院
  205. listDepartments(){
  206. listDepartments().then(response => {
  207. this.optionsListOne = response.data;
  208. });
  209. },
  210. backPage(){
  211. this.$parent.pageToggle(1);
  212. },
  213. }
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. .addPage {
  218. flex: 1;
  219. display: flex;
  220. flex-direction: column;
  221. overflow: hidden;
  222. p {
  223. margin: 0;
  224. padding: 0;
  225. }
  226. .title-box{
  227. display: flex;
  228. height:90px;
  229. border-bottom: 1px solid #D8D8D8;
  230. p:nth-child(1){
  231. flex:1;
  232. font-size:16px;
  233. line-height:90px;
  234. margin-left:18px;
  235. color:#0045AF;
  236. }
  237. p:nth-child(2){
  238. margin:25px 25px 0 0;
  239. }
  240. }
  241. .form-min-box{
  242. display: inline-block;
  243. width:700px;
  244. height:70px;
  245. .form-i-icon{
  246. margin-right:10px;
  247. color:rgba(255,192,0,1);
  248. }
  249. .form-left-text{
  250. line-height:30px;
  251. font-size:14px;
  252. color:#606266;
  253. margin-right:40px;
  254. }
  255. .form-right-text{
  256. line-height:40px;
  257. font-size:14px;
  258. color:#606266;
  259. }
  260. }
  261. .form-text-box{
  262. display: flex;
  263. p{
  264. color:#333;
  265. line-height:20px;
  266. }
  267. p:nth-child(1){
  268. width:108px;
  269. font-weight:500;
  270. text-align: right;
  271. font-size:14px;
  272. }
  273. p:nth-child(2){
  274. flex:1;
  275. font-size:14px;
  276. font-weight:500;
  277. margin-left:12px;
  278. }
  279. }
  280. .bottom-button-box{
  281. display: flex;
  282. width:160px;
  283. margin:40px auto;
  284. .left-button{
  285. margin-right:20px;
  286. }
  287. }
  288. }
  289. </style>