addPage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <div class="sparseHardwareAddPage">
  3. <div class="top-title-box">{{form.id?'编辑疏散设备':'新增疏散设备'}}</div>
  4. <el-form :model="form" ref="form" :rules="rules" label-width="100px" style="margin-top:20px;">
  5. <el-form-item label="设备名称" prop="name">
  6. <el-input
  7. style="width:400px;"
  8. v-model="form.name"
  9. placeholder="请输入设备名称"
  10. maxLength="50"
  11. clearable
  12. size="small"
  13. />
  14. </el-form-item>
  15. <el-form-item label="设备类型" prop="type">
  16. <el-select v-model="form.type" clearable @change="typeChange" placeholder="请选择设备类型" style="width:400px;">
  17. <el-option
  18. v-for="dict in typeList"
  19. :key="dict.value"
  20. :label="dict.name"
  21. :value="dict.value"
  22. ></el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item label="喇叭音量" prop="deviceVol" v-if="typeDisabled">
  26. <el-slider :min="0" :max="100" v-model="form.deviceVol" :step="1" style="width:400px;"></el-slider>
  27. </el-form-item>
  28. <el-form-item label="设备编号" prop="hardwareNum" >
  29. <el-input
  30. style="width:400px;"
  31. v-model="form.hardwareNum"
  32. placeholder="请输入设备编号"
  33. maxLength="40"
  34. clearable
  35. size="small"
  36. />
  37. </el-form-item>
  38. <el-form-item label="远程端口" prop="port" >
  39. <el-input
  40. style="width:400px;"
  41. onkeyup="value=value.replace(/[^\d]/g,'')"
  42. v-model="form.port"
  43. placeholder="请输入远程端口"
  44. maxLength="6"
  45. clearable
  46. size="small"
  47. />
  48. </el-form-item>
  49. <el-form-item label="设备类别" prop="deviceType">
  50. <template>
  51. <el-radio v-model="form.deviceType" :label="1" @change="radioChange">楼层设备</el-radio>
  52. <el-radio v-model="form.deviceType" :label="2" @change="radioChange">实验室设备</el-radio>
  53. </template>
  54. </el-form-item>
  55. <el-form-item label="楼栋" prop="buildId" v-if="form.deviceType == '1'">
  56. <el-select v-model="form.buildId" placeholder="请选择楼栋" @change="buildChange" style="width:400px;">
  57. <el-option
  58. v-for="dict in buildList"
  59. :key="dict.id"
  60. :label="dict.name"
  61. :value="dict.id"
  62. ></el-option>
  63. </el-select>
  64. </el-form-item>
  65. <el-form-item label="楼层" prop="floorId" v-if="form.deviceType == '1'">
  66. <el-select v-model="form.floorId" placeholder="请选择楼层" @change="floorChange" style="width:400px;">
  67. <el-option
  68. v-for="dict in floorList"
  69. :key="dict.id"
  70. :label="dict.name"
  71. :value="dict.id"
  72. ></el-option>
  73. </el-select>
  74. </el-form-item>
  75. <el-form-item label="实验室" prop="subjectId" v-if="form.deviceType == '2'">
  76. <el-select v-model="form.subjectId" placeholder="请选择实验室" @change="layoutChange">
  77. <el-option
  78. v-for="dict in subjectAddOptions"
  79. :key="dict.id"
  80. :label="dict.name"
  81. :value="dict.id"
  82. ></el-option>
  83. </el-select>
  84. </el-form-item>
  85. <div class="bottom-button-box">
  86. <p class="reset-button-one" @click="backPage">返回</p>
  87. <p class="inquire-button-one" @click="upData">提交</p>
  88. </div>
  89. </el-form>
  90. </div>
  91. </template>
  92. <script>
  93. import { addSparseHardware, updateSparseHardware,getBuildsList } from "@/api/laboratory/sparseHardware";
  94. import { subjectDictList } from "@/api/laboratory/group";
  95. import { buildFloorGetlist } from "@/api/laboratory/building";
  96. export default {
  97. name: 'addPage',
  98. props:{
  99. propsData:{},
  100. },
  101. data() {
  102. return {
  103. form:{
  104. name:"",
  105. type:"",
  106. deviceType:1,
  107. hardwareNum:"",
  108. port:"",
  109. buildId:"",
  110. floorId:"",
  111. },
  112. // 表单校验
  113. rules: {
  114. name: [
  115. { required: true, message: "请输入设备名称", trigger: "change" },
  116. { required: true, message: "请输入设备名称", validator: this.spaceJudgment, trigger: "blur" }
  117. ],
  118. type: [
  119. { required: true, message: "请选择设备类型", trigger: "change" }
  120. ],
  121. // deviceVol: [
  122. // { required: true, message: "请设置喇叭音量", trigger: "change" }
  123. // ],
  124. hardwareNum: [
  125. { required: true, message: "请输入设备编号", trigger: "change" },
  126. { required: true, message: "请输入设备编号", validator: this.spaceJudgment, trigger: "blur" }
  127. ],
  128. port: [
  129. { required: true, message: "请输入远程端口", trigger: "change" },
  130. { required: true, message: "请输入远程端口", validator: this.spaceJudgment, trigger: "blur" }
  131. ],
  132. deviceType: [
  133. { required: true, message: "请选择设备类型", trigger: "change" }
  134. ],
  135. buildId: [
  136. { required: true, message: "请选择楼栋", trigger: "change" }
  137. ],
  138. floorId: [
  139. { required: true, message: "请选择楼层", trigger: "change" }
  140. ],
  141. subjectId: [
  142. { required: true, message: "请选择实验室", trigger: "change" }
  143. ],
  144. },
  145. //设备类型
  146. typeList:[
  147. {name:"摄像头",value:1},{name:"喇叭",value:2},
  148. ],
  149. //楼栋数据
  150. buildList:[],
  151. //楼层数据
  152. floorList:[],
  153. //实验室数据
  154. subjectAddOptions:[],
  155. typeDisabled:false,
  156. }
  157. },
  158. created() {
  159. if(this.propsData){
  160. this.$set(this,'form',JSON.parse(JSON.stringify(this.propsData)));
  161. this.form.type = parseInt(this.form.type);
  162. if(this.form.type == 2){
  163. this.$set(this,'typeDisabled',true);
  164. this.$set(this.form,'deviceVol',parseInt(this.form.deviceVol));
  165. }
  166. if(this.form.deviceType == 1){
  167. this.form.buildId = parseInt(this.form.buildId);
  168. this.form.floorId = parseInt(this.form.floorId);
  169. buildFloorGetlist({type:2}).then(response => {
  170. this.$set(this,'buildList', response.rows)
  171. buildFloorGetlist({type:3,parentId:this.form.buildId}).then(response => {
  172. this.$set(this,'floorList', response.rows)
  173. })
  174. });
  175. }
  176. console.log("12")
  177. }else{
  178. console.log("32")
  179. }
  180. },
  181. mounted(){
  182. this.getDeptListTow();
  183. this.subjectDictList();
  184. },
  185. methods: {
  186. //设备状态切换
  187. typeChange(val){
  188. if(val == 1){
  189. this.$set(this,'typeDisabled',false);
  190. }else if(val == 2){
  191. this.$set(this.form,'deviceType',1);
  192. this.$set(this,'typeDisabled',true);
  193. }
  194. },
  195. radioChange(){
  196. if(this.form.buildId){
  197. buildFloorGetlist({type:2}).then(response => {
  198. this.$set(this,'buildList', response.rows)
  199. buildFloorGetlist({type:3,parentId:this.form.buildId}).then(response => {
  200. this.$set(this,'floorList', response.rows)
  201. })
  202. });
  203. }
  204. },
  205. //提交按钮
  206. upData(){
  207. this.$refs["form"].validate(valid => {
  208. if (valid) {
  209. if(this.propsData){
  210. //编辑
  211. let obj = {
  212. id:this.form.id,
  213. name:this.form.name,
  214. type:this.form.type,
  215. hardwareNum:this.form.hardwareNum,
  216. port:this.form.port,
  217. deviceType:this.form.deviceType,
  218. };
  219. if(this.form.deviceType == '1'){
  220. obj.buildId = this.form.buildId;
  221. obj.floorId = this.form.floorId;
  222. }else if(this.form.deviceType == '2'){
  223. obj.subjectId = this.form.subjectId;
  224. }
  225. if(this.form.type == '2'){
  226. obj.deviceVol = this.form.deviceVol;
  227. }
  228. updateSparseHardware(obj).then( response => {
  229. this.msgSuccess("操作成功");
  230. this.$parent.pageTypeClick(1);
  231. });
  232. }else{
  233. //新增
  234. let obj = {
  235. name:this.form.name,
  236. type:this.form.type,
  237. hardwareNum:this.form.hardwareNum,
  238. port:this.form.port,
  239. deviceType:this.form.deviceType,
  240. };
  241. if(this.form.deviceType == '1'){
  242. obj.buildId = this.form.buildId;
  243. obj.floorId = this.form.floorId;
  244. }else if(this.form.deviceType == '2'){
  245. obj.subjectId = this.form.subjectId;
  246. }
  247. if(this.form.type == '2'){
  248. obj.deviceVol = this.form.deviceVol;
  249. }
  250. addSparseHardware(obj).then( response => {
  251. this.msgSuccess("操作成功");
  252. this.$parent.pageTypeClick(1);
  253. });
  254. }
  255. }
  256. })
  257. },
  258. /** 查询楼栋列表 */
  259. getDeptListTow() {
  260. buildFloorGetlist({type:2}).then(response => {
  261. this.$set(this,'buildList', response.rows)
  262. })
  263. // getBuildsList().then(response => {
  264. // // this.deptOptionsTwo = response.data;
  265. // this.$set(this,'buildList', response.data)
  266. // });
  267. },
  268. //选择楼栋
  269. buildChange(e){
  270. console.log("选择楼栋",e)
  271. buildFloorGetlist({type:3,parentId:e}).then(response => {
  272. this.$set(this,'floorList', response.rows)
  273. this.$set(this.form,'floorId', "")
  274. })
  275. //根据学院获取楼栋
  276. // buildFloorGetlist(this.form.buildId).then(response => {
  277. // this.$set(this,'floorList', response.rows)
  278. // this.$set(this.form,'floorId', "")
  279. // });
  280. },
  281. //选择楼层
  282. floorChange(e){
  283. console.log("选择楼层",e)
  284. },
  285. //选择实验室
  286. layoutChange(e){
  287. console.log("实验室",e)
  288. },
  289. subjectDictList(){
  290. subjectDictList({}).then(response => {
  291. this.subjectAddOptions = response.data;
  292. });
  293. },
  294. //返回
  295. backPage(){
  296. this.$parent.pageTypeClick(1);
  297. },
  298. }
  299. }
  300. </script>
  301. <style scoped lang="scss">
  302. .sparseHardwareAddPage {
  303. flex: 1;
  304. display: flex;
  305. flex-direction: column;
  306. overflow: hidden !important;
  307. padding:20px;
  308. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  309. border-radius: 10px;
  310. .top-title-box{
  311. line-height:60px;
  312. padding-bottom:20px;
  313. border-bottom:1px solid #dedede;
  314. color: #0045AF;
  315. font-size:18px;
  316. p{
  317. margin:0;
  318. }
  319. }
  320. .bottom-button-box{
  321. display: flex;
  322. margin-top:50px;
  323. p:nth-child(1){
  324. margin:0 20px 0 200px;
  325. }
  326. }
  327. }
  328. </style>