addPage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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 { listFloorByBuildId } from "@/api/laboratory/building";
  95. import { subjectDictList } from "@/api/laboratory/group";
  96. import { selBuildOrFloorList } from "@/api/evacuation3_2/index";
  97. export default {
  98. name: 'addPage',
  99. props:{
  100. propsData:{},
  101. },
  102. data() {
  103. return {
  104. form:{
  105. name:"",
  106. type:"",
  107. deviceType:1,
  108. hardwareNum:"",
  109. port:"",
  110. buildId:"",
  111. floorId:"",
  112. },
  113. // 表单校验
  114. rules: {
  115. name: [
  116. { required: true, message: "请输入设备名称", trigger: "change" },
  117. { required: true, message: "请输入设备名称", validator: this.spaceJudgment, trigger: "blur" }
  118. ],
  119. type: [
  120. { required: true, message: "请选择设备类型", trigger: "change" }
  121. ],
  122. // deviceVol: [
  123. // { required: true, message: "请设置喇叭音量", trigger: "change" }
  124. // ],
  125. hardwareNum: [
  126. { required: true, message: "请输入设备编号", trigger: "change" },
  127. { required: true, message: "请输入设备编号", validator: this.spaceJudgment, trigger: "blur" }
  128. ],
  129. port: [
  130. { required: true, message: "请输入远程端口", trigger: "change" },
  131. { required: true, message: "请输入远程端口", validator: this.spaceJudgment, trigger: "blur" }
  132. ],
  133. deviceType: [
  134. { required: true, message: "请选择设备类型", trigger: "change" }
  135. ],
  136. buildId: [
  137. { required: true, message: "请选择楼栋", trigger: "change" }
  138. ],
  139. floorId: [
  140. { required: true, message: "请选择楼层", trigger: "change" }
  141. ],
  142. subjectId: [
  143. { required: true, message: "请选择实验室", trigger: "change" }
  144. ],
  145. },
  146. //设备类型
  147. typeList:[
  148. {name:"摄像头",value:1},{name:"喇叭",value:2},
  149. ],
  150. //楼栋数据
  151. buildList:[],
  152. //楼层数据
  153. floorList:[],
  154. //实验室数据
  155. subjectAddOptions:[],
  156. typeDisabled:false,
  157. }
  158. },
  159. created() {
  160. if(this.propsData){
  161. this.$set(this,'form',JSON.parse(JSON.stringify(this.propsData)));
  162. this.form.type = parseInt(this.form.type);
  163. if(this.form.type == 2){
  164. this.$set(this,'typeDisabled',true);
  165. this.$set(this.form,'deviceVol',parseInt(this.form.deviceVol));
  166. }
  167. if(this.form.deviceType == 1){
  168. this.form.buildId = parseInt(this.form.buildId);
  169. this.form.floorId = parseInt(this.form.floorId);
  170. selBuildOrFloorList({type:2}).then(response => {
  171. this.$set(this,'buildList', response.data)
  172. selBuildOrFloorList({type:3,parentId:this.form.buildId}).then(response => {
  173. this.$set(this,'floorList', response.data)
  174. })
  175. });
  176. }
  177. console.log("12")
  178. }else{
  179. console.log("32")
  180. }
  181. },
  182. mounted(){
  183. this.getDeptListTow();
  184. this.subjectDictList();
  185. },
  186. methods: {
  187. //设备状态切换
  188. typeChange(val){
  189. if(val == 1){
  190. this.$set(this,'typeDisabled',false);
  191. }else if(val == 2){
  192. this.$set(this.form,'deviceType',1);
  193. this.$set(this,'typeDisabled',true);
  194. }
  195. },
  196. radioChange(){
  197. if(this.form.buildId){
  198. selBuildOrFloorList({type:2}).then(response => {
  199. this.$set(this,'buildList', response.data)
  200. selBuildOrFloorList({type:3,parentId:this.form.buildId}).then(response => {
  201. this.$set(this,'floorList', response.data)
  202. })
  203. });
  204. }
  205. },
  206. //提交按钮
  207. upData(){
  208. this.$refs["form"].validate(valid => {
  209. if (valid) {
  210. if(this.propsData){
  211. //编辑
  212. let obj = {
  213. id:this.form.id,
  214. name:this.form.name,
  215. type:this.form.type,
  216. hardwareNum:this.form.hardwareNum,
  217. port:this.form.port,
  218. deviceType:this.form.deviceType,
  219. };
  220. if(this.form.deviceType == '1'){
  221. obj.buildId = this.form.buildId;
  222. obj.floorId = this.form.floorId;
  223. }else if(this.form.deviceType == '2'){
  224. obj.subjectId = this.form.subjectId;
  225. }
  226. if(this.form.type == '2'){
  227. obj.deviceVol = this.form.deviceVol;
  228. }
  229. updateSparseHardware(obj).then( response => {
  230. this.msgSuccess("操作成功");
  231. this.$parent.pageTypeClick(1);
  232. });
  233. }else{
  234. //新增
  235. let obj = {
  236. name:this.form.name,
  237. type:this.form.type,
  238. hardwareNum:this.form.hardwareNum,
  239. port:this.form.port,
  240. deviceType:this.form.deviceType,
  241. };
  242. if(this.form.deviceType == '1'){
  243. obj.buildId = this.form.buildId;
  244. obj.floorId = this.form.floorId;
  245. }else if(this.form.deviceType == '2'){
  246. obj.subjectId = this.form.subjectId;
  247. }
  248. if(this.form.type == '2'){
  249. obj.deviceVol = this.form.deviceVol;
  250. }
  251. addSparseHardware(obj).then( response => {
  252. this.msgSuccess("操作成功");
  253. this.$parent.pageTypeClick(1);
  254. });
  255. }
  256. }
  257. })
  258. },
  259. /** 查询楼栋列表 */
  260. getDeptListTow() {
  261. selBuildOrFloorList({type:2}).then(response => {
  262. this.$set(this,'buildList', response.data)
  263. })
  264. // getBuildsList().then(response => {
  265. // // this.deptOptionsTwo = response.data;
  266. // this.$set(this,'buildList', response.data)
  267. // });
  268. },
  269. //选择楼栋
  270. buildChange(e){
  271. console.log("选择楼栋",e)
  272. selBuildOrFloorList({type:3,parentId:e}).then(response => {
  273. this.$set(this,'floorList', response.data)
  274. this.$set(this.form,'floorId', "")
  275. })
  276. //根据学院获取楼栋
  277. // listFloorByBuildId(this.form.buildId).then(response => {
  278. // this.$set(this,'floorList', response.data)
  279. // this.$set(this.form,'floorId', "")
  280. // });
  281. },
  282. //选择楼层
  283. floorChange(e){
  284. console.log("选择楼层",e)
  285. },
  286. //选择实验室
  287. layoutChange(e){
  288. console.log("实验室",e)
  289. },
  290. subjectDictList(){
  291. subjectDictList({}).then(response => {
  292. this.subjectAddOptions = response.data;
  293. });
  294. },
  295. //返回
  296. backPage(){
  297. this.$parent.pageTypeClick(1);
  298. },
  299. }
  300. }
  301. </script>
  302. <style scoped lang="scss">
  303. .sparseHardwareAddPage {
  304. flex: 1;
  305. display: flex;
  306. flex-direction: column;
  307. overflow: hidden !important;
  308. padding:20px;
  309. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  310. border-radius: 10px;
  311. .top-title-box{
  312. line-height:60px;
  313. padding-bottom:20px;
  314. border-bottom:1px solid #dedede;
  315. color: #0045AF;
  316. font-size:18px;
  317. p{
  318. margin:0;
  319. }
  320. }
  321. .bottom-button-box{
  322. display: flex;
  323. margin-top:50px;
  324. p:nth-child(1){
  325. margin:0 20px 0 200px;
  326. }
  327. }
  328. }
  329. </style>