addPage.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. <!-- 新增/编辑物联设备 -->
  2. <template>
  3. <view id="iotDevice-add-page">
  4. <view class="addForm-max-big-box">
  5. <view class="addForm-big-box">
  6. <!-- 状态 -->
  7. <view class="addForm-input-box">
  8. <view class="addForm-input-icon">*</view>
  9. <view class="addForm-input-title">启用:</view>
  10. <view>
  11. <switch :checked="addForm.state" @change="switchChange" color="#0183FA" style="transform:scale(0.8)" />
  12. </view>
  13. </view>
  14. <!-- 名称 -->
  15. <view class="addForm-input-box">
  16. <view class="addForm-input-icon">*</view>
  17. <view class="addForm-input-title">名称:</view>
  18. <input class="addForm-input" v-model="addForm.deviceName" style="width:340rpx;" type="text" :maxlength="20"
  19. placeholder="输入名称" placeholder-style="color:#999;">
  20. </view>
  21. <!-- 编号 -->
  22. <view class="addForm-input-box">
  23. <view class="addForm-input-icon">*</view>
  24. <view class="addForm-input-title">编号:</view>
  25. <input class="addForm-input" :disabled="!!addForm.id" v-model="addForm.deviceNo" style="width:340rpx;" type="text" :maxlength="20"
  26. placeholder="输入编号" placeholder-style="color:#999;">
  27. </view>
  28. <!-- 设备分类 -->
  29. <view class="addForm-input-box">
  30. <view class="addForm-input-icon">*</view>
  31. <view class="addForm-input-title">设备类型:</view>
  32. <picker @change="optionsChange" :value="optionsIndex" :range="optionsNameList">
  33. <view class="addForm-input" style="width:340rpx;"
  34. :class="!optionsName?'addForm-input-placeholder':''">
  35. {{optionsName?optionsName:'选择设备类型'}}
  36. </view>
  37. </picker>
  38. </view>
  39. <!-- 设备属性 -->
  40. <view class="addForm-input-box">
  41. <view class="addForm-input-icon">*</view>
  42. <view class="addForm-input-title">设备属性:</view>
  43. <picker @change="optionsStatsChange" :value="optionsStatsIndex" :range="optionsStatsNameList">
  44. <view class="addForm-input" style="width:340rpx;"
  45. :class="!optionsStatsName?'addForm-input-placeholder':''">
  46. {{optionsStatsName?optionsStatsName:'选择设备属性'}}
  47. </view>
  48. </picker>
  49. </view>
  50. <!-- 自适配循环设备属性列表 -->
  51. <view class="for-addForm-max-input-box" v-if="modelList[0]">
  52. <view class="for-addForm-input-box" v-for="(item,index) in modelList" :key="index">
  53. <view class="addForm-input-icon">{{item.required?'*':''}}</view>
  54. <view class="addForm-input-title">{{item.label}}:</view>
  55. <!-- 文本框/文本域 -->
  56. <input v-if="item.type == 'text' || item.type == 'textarea'" class="addForm-input"
  57. v-model="reservedField[item.field]" style="width:340rpx;" type="text" :maxlength="50"
  58. :placeholder="'输入'+item.label" placeholder-style="color:#999;">
  59. <!-- 密码框 -->
  60. <input v-if="item.type == 'password'" password class="addForm-input"
  61. v-model="reservedField[item.field]" style="width:340rpx;" type="text" :maxlength="50" :placeholder="'输入'+item.label"
  62. placeholder-style="color:#999;">
  63. <!-- 计数器 -->
  64. <input v-if="item.type == 'number'" class="addForm-input"
  65. v-model="reservedField[item.field]" style="width:340rpx;" type="number" :min="1" :max="9999" :maxlength="4" :placeholder="'输入'+item.label"
  66. placeholder-style="color:#999;">
  67. <!-- 下拉单选/单选 -->
  68. <picker v-if="item.type == 'select' || item.type == 'radio'" @change="(event)=>forSelectChange(item,event)"
  69. :value="iotParamValueModels[item.field+'Index']" :range="iotParamValueModels[item.field+'NameList']">
  70. <view class="addForm-input" style="width:340rpx;"
  71. :class="!iotParamValueModels[item.field+'Name']?'addForm-input-placeholder':''">
  72. {{iotParamValueModels[item.field+'Name']?iotParamValueModels[item.field+'Name']:'请选择'+item.label}}
  73. </view>
  74. </picker>
  75. <!-- 下拉多选/复选 -->
  76. <checkbox-group v-if="item.type == 'selectMultiple' || item.type == 'checkbox'" class="check-max-box"
  77. @change="(event)=>forSelectChange(item,event,index)" style="flex-wrap: wrap">
  78. <checkbox class="check-min-box" :value="minItem.dictValue" :checked="minItem.type"
  79. v-for="(minItem,minIndex) in iotParamValueModels[item.field+'List']" :key="minIndex">
  80. {{minItem.dictKey}}
  81. </checkbox>
  82. </checkbox-group>
  83. </view>
  84. </view>
  85. <!-- 校区 -->
  86. <view class="addForm-input-box">
  87. <view class="addForm-input-icon">*</view>
  88. <view class="addForm-input-title">校区:</view>
  89. <picker @change="schoolChange" :value="schoolIndex" :range="schoolNameList">
  90. <view class="addForm-input" style="width:340rpx;"
  91. :class="!schoolName?'addForm-input-placeholder':''">
  92. {{schoolName?schoolName:'选择校区'}}
  93. </view>
  94. </picker>
  95. </view>
  96. <!-- 楼栋 -->
  97. <view class="addForm-input-box">
  98. <view class="addForm-input-icon">*</view>
  99. <view class="addForm-input-title">楼栋:</view>
  100. <picker @change="buildChange" :value="buildIndex" :range="buildNameList">
  101. <view class="addForm-input" style="width:340rpx;"
  102. :class="!buildName?'addForm-input-placeholder':''">
  103. {{buildName?buildName:'选择楼栋'}}
  104. </view>
  105. </picker>
  106. </view>
  107. <!-- 楼层 -->
  108. <view class="addForm-input-box">
  109. <view class="addForm-input-icon">*</view>
  110. <view class="addForm-input-title">楼层:</view>
  111. <picker @change="floorChange" :value="floorIndex" :range="floorNameList">
  112. <view class="addForm-input" style="width:340rpx;"
  113. :class="!floorName?'addForm-input-placeholder':''">
  114. {{floorName?floorName:'选择楼层'}}
  115. </view>
  116. </picker>
  117. </view>
  118. <!-- 实验室 -->
  119. <view class="addForm-input-box">
  120. <view class="addForm-input-icon"></view>
  121. <view class="addForm-input-title">实验室:</view>
  122. <picker @change="subChange" :value="subIndex" :range="subNameList">
  123. <view class="addForm-input" style="width:340rpx;"
  124. :class="!subName?'addForm-input-placeholder':''">
  125. {{subName?subName:'选择实验室'}}
  126. </view>
  127. </picker>
  128. </view>
  129. <!-- 说明 -->
  130. <view class="addForm-input-box">
  131. <view class="addForm-input-icon"></view>
  132. <view class="addForm-input-title">说明:</view>
  133. <input class="addForm-input" v-model="addForm.remark" style="width:340rpx;" type="text" :maxlength="50"
  134. placeholder="输入说明" placeholder-style="color:#999;">
  135. </view>
  136. </view>
  137. </view>
  138. <view class="addForm-button-box">
  139. <view class="button-null"></view>
  140. <view class="button-view" @click="submitForm">提交</view>
  141. <view class="button-null"></view>
  142. </view>
  143. </view>
  144. </template>
  145. <script>
  146. import {
  147. iotTypeGetAllTypes,
  148. systemBuildingGetTreeList,
  149. laboratorySubRelInfoGetListByFloor,
  150. iotAttributeGetByTypeId,
  151. iotTypeGetParamByTypeId,
  152. iotDeviceAdd,
  153. iotDeviceUpdate,
  154. iotDeviceDetail
  155. } from '@/api/index.js'
  156. export default {
  157. data() {
  158. return {
  159. addForm: {
  160. state: true,
  161. deviceName: '',
  162. deviceNo: '',
  163. typeId: '',
  164. typeKey: '',
  165. typeName: '',
  166. attributeId: '',
  167. code: '',
  168. networkId: '',
  169. schoolId: '',
  170. schoolName: '',
  171. buildId: '',
  172. buildName: '',
  173. floorId: '',
  174. floorName: '',
  175. subjectId: '',
  176. subjectName: '',
  177. remark:'',
  178. },
  179. //设备类型下拉列表
  180. options: [],
  181. optionsNameList: [],
  182. optionsIndex: 0,
  183. optionsName: '',
  184. //设备属性下拉列表
  185. optionsStats: [],
  186. optionsStatsNameList: [],
  187. optionsStatsIndex: 0,
  188. optionsStatsName: '',
  189. //校区/楼栋/楼层树
  190. treeOptions: [],
  191. //校区
  192. schoolList: [],
  193. schoolNameList: [],
  194. schoolIndex: 0,
  195. schoolName: '',
  196. //楼栋
  197. buildList: [],
  198. buildNameList: [],
  199. buildIndex: 0,
  200. buildName: '',
  201. //楼层
  202. floorList: [],
  203. floorNameList: [],
  204. floorIndex: 0,
  205. floorName: '',
  206. //实验室
  207. subList: [],
  208. subNameList: [],
  209. subIndex: 0,
  210. subName: '',
  211. //模组数据
  212. modelList: [],
  213. reservedField: {},
  214. iotParamValueModels: {},
  215. }
  216. },
  217. onLoad(option) {
  218. this.iotTypeGetAllTypes();
  219. this.systemBuildingGetTreeList();
  220. if(option.id){
  221. this.iotDeviceDetail(option.id);
  222. }
  223. },
  224. onShow() {
  225. },
  226. methods: {
  227. //详情接口
  228. async iotDeviceDetail(id){
  229. const { data } = await iotDeviceDetail({id:id});
  230. if (data.code == 200) {
  231. this.$set(this,'addForm',{
  232. id: data.data.id,
  233. state: data.data.state,
  234. deviceName: data.data.deviceName,
  235. deviceNo: data.data.deviceNo,
  236. typeId: data.data.typeId,
  237. typeKey: data.data.typeKey,
  238. typeName: data.data.typeName,
  239. attributeId: data.data.attributeId,
  240. code: data.data.code,
  241. networkId: data.data.networkId,
  242. schoolId: data.data.schoolId,
  243. schoolName: data.data.schoolName,
  244. buildId: data.data.buildId,
  245. buildName: data.data.buildName,
  246. floorId: data.data.floorId,
  247. floorName: data.data.floorName,
  248. subjectId: data.data.subjectId,
  249. subjectName: data.data.subjectName,
  250. remark: data.data.remark,
  251. });
  252. this.$set(this, 'optionsName', data.data.typeName);
  253. //等待配置与字段获取到后跳转
  254. Promise.all([
  255. this.iotAttributeGetByTypeId(data.data.typeId),
  256. this.iotTypeGetParamByTypeId(data.data.typeId)
  257. ]).then((result)=>{
  258. this.optionsStats.forEach((item) => {
  259. if(data.data.attributeId == item.id){
  260. this.$set(this,'optionsStatsName',item.name);
  261. }
  262. })
  263. this.getAddress(data.data);
  264. if(data.data.reservedField){
  265. this.getIotParamModels(data.data.reservedField);
  266. }
  267. }).catch((error) => {})
  268. }
  269. },
  270. //数据提交
  271. submitForm() {
  272. let self = this;
  273. if (!this.addForm.deviceName) {
  274. uni.showToast({
  275. mask: true,
  276. icon: "none",
  277. position: "center",
  278. title: '请输入名称',
  279. duration: 1000
  280. });
  281. return
  282. }else if(!this.addForm.deviceNo){
  283. uni.showToast({
  284. mask: true,
  285. icon: "none",
  286. position: "center",
  287. title: '请输入编号',
  288. duration: 1000
  289. });
  290. return
  291. }else if(!this.addForm.typeId){
  292. uni.showToast({
  293. mask: true,
  294. icon: "none",
  295. position: "center",
  296. title: '请选择设备类型',
  297. duration: 1000
  298. });
  299. return
  300. }else if(!this.addForm.attributeId){
  301. uni.showToast({
  302. mask: true,
  303. icon: "none",
  304. position: "center",
  305. title: '请选择设备属性',
  306. duration: 1000
  307. });
  308. return
  309. }else if(!this.addForm.schoolId){
  310. uni.showToast({
  311. mask: true,
  312. icon: "none",
  313. position: "center",
  314. title: '请选择校区',
  315. duration: 1000
  316. });
  317. return
  318. }else if(!this.addForm.buildId){
  319. uni.showToast({
  320. mask: true,
  321. icon: "none",
  322. position: "center",
  323. title: '请选择楼栋',
  324. duration: 1000
  325. });
  326. return
  327. }else if(!this.addForm.floorId){
  328. uni.showToast({
  329. mask: true,
  330. icon: "none",
  331. position: "center",
  332. title: '请选择楼层',
  333. duration: 1000
  334. });
  335. return
  336. }
  337. this.modelList.forEach((item) => {
  338. if(item.required){
  339. if(!this.reservedField[item.field]){
  340. uni.showToast({
  341. mask: true,
  342. icon: "none",
  343. position: "center",
  344. title: '请检查'+item.label,
  345. duration: 1000
  346. });
  347. return
  348. }
  349. }
  350. })
  351. let obj = {
  352. state:this.addForm.state,
  353. deviceName:this.addForm.deviceName,
  354. deviceNo:this.addForm.deviceNo,
  355. typeId:this.addForm.typeId,
  356. typeKey:this.addForm.typeKey,
  357. typeName:this.addForm.typeName,
  358. attributeId:this.addForm.attributeId,
  359. code:this.addForm.code,
  360. networkId:this.addForm.networkId,
  361. schoolId:this.addForm.schoolId,
  362. schoolName:this.addForm.schoolName,
  363. buildId:this.addForm.buildId,
  364. buildName:this.addForm.buildName,
  365. floorId:this.addForm.floorId,
  366. floorName:this.addForm.floorName,
  367. subjectId:this.addForm.subjectId,
  368. subjectName:this.addForm.subjectName,
  369. remark:this.addForm.remark,
  370. reservedField:JSON.stringify(this.reservedField),
  371. }
  372. uni.showModal({
  373. title:'警告',
  374. content:'是否确认提交?',
  375. showCancel: true,
  376. cancelColor:'#999999,',
  377. confirmColor: '#0183FA',
  378. success: (res) => {
  379. if(res.confirm){
  380. if(self.addForm.id){
  381. obj.id = self.addForm.id;
  382. self.iotDeviceUpdate(obj);
  383. }else{
  384. self.iotDeviceAdd(obj);
  385. }
  386. }
  387. },
  388. fail: (res) => {}
  389. })
  390. },
  391. async iotDeviceAdd(obj){
  392. const { data } = await iotDeviceAdd(obj);
  393. if (data.code == 200) {
  394. uni.showToast({
  395. mask: true,
  396. icon: "none",
  397. position: "center",
  398. title: data.message,
  399. duration: 2000
  400. });
  401. setTimeout(function(){
  402. uni.navigateBack();
  403. },1800);
  404. }
  405. },
  406. async iotDeviceUpdate(obj){
  407. const { data } = await iotDeviceUpdate(obj);
  408. if (data.code == 200) {
  409. uni.showToast({
  410. mask: true,
  411. icon: "none",
  412. position: "center",
  413. title: data.message,
  414. duration: 2000
  415. });
  416. setTimeout(function(){
  417. uni.navigateBack();
  418. },1800);
  419. }
  420. },
  421. //设备类型选中
  422. optionsChange(event) {
  423. this.$set(this, 'optionsIndex', event.target.value);
  424. this.$set(this, 'optionsName', this.options[event.target.value].typeName);
  425. this.$set(this.addForm, 'typeId', this.options[event.target.value].typeId);
  426. this.$set(this.addForm, 'typeKey', this.options[event.target.value].typeKey);
  427. this.$set(this.addForm, 'typeName', this.options[event.target.value].typeName);
  428. this.$set(this.addForm, 'attributeId', '');
  429. this.$set(this.addForm, 'code', '');
  430. this.$set(this.addForm, 'networkId', '');
  431. this.$set(this, 'optionsStatsIndex', 0);
  432. this.$set(this, 'optionsStatsName', '');
  433. this.iotAttributeGetByTypeId(this.options[event.target.value].typeId);
  434. this.iotTypeGetParamByTypeId(this.options[event.target.value].typeId);
  435. },
  436. //设备属性选中
  437. optionsStatsChange(event) {
  438. if (this.optionsStats[0]) {
  439. this.$set(this, 'optionsStatsIndex', event.target.value);
  440. this.$set(this, 'optionsStatsName', this.optionsStats[event.target.value].name);
  441. this.$set(this.addForm, 'attributeId', this.optionsStats[event.target.value].id);
  442. this.$set(this.addForm, 'code', this.optionsStats[event.target.value].code);
  443. this.$set(this.addForm, 'networkId', this.optionsStats[event.target.value].networkId);
  444. }
  445. },
  446. //状态开关
  447. switchChange(event) {
  448. this.$set(this.addForm, 'state', event.target.value);
  449. },
  450. //获取物联分类下拉列表
  451. async iotTypeGetAllTypes() {
  452. const {
  453. data
  454. } = await iotTypeGetAllTypes();
  455. if (data.code == 200) {
  456. this.$set(this, 'options', data.data);
  457. let list = [];
  458. data.data.forEach((item) => {
  459. list.push(item.typeName);
  460. })
  461. this.$set(this, 'optionsNameList', list);
  462. }
  463. },
  464. //通过设备类型查询设备属性
  465. async iotAttributeGetByTypeId(val) {
  466. const {
  467. data
  468. } = await iotAttributeGetByTypeId({
  469. typeId: val
  470. });
  471. if (data.code == 200) {
  472. this.$set(this, 'optionsStats', data.data);
  473. let list = [];
  474. data.data.forEach((item) => {
  475. list.push(item.name);
  476. })
  477. this.$set(this, 'optionsStatsNameList', list);
  478. }
  479. },
  480. //设备类型配置查询
  481. async iotTypeGetParamByTypeId(val) {
  482. const {
  483. data
  484. } = await iotTypeGetParamByTypeId({
  485. typeId: val
  486. });
  487. if (data.code == 200) {
  488. let reservedField = {};
  489. let iotParamValueModels = {};
  490. data.data.forEach((item) => {
  491. reservedField[item.field] = '';
  492. if (item.type == 'select' || item.type == 'selectMultiple' || item.type == 'radio' || item.type == 'checkbox') {
  493. let list = [];
  494. if (item.iotParamValueModels) {
  495. item.iotParamValueModels.forEach((minItem) => {
  496. list.push(minItem.dictKey)
  497. minItem.type = false;
  498. })
  499. }
  500. iotParamValueModels[item.field + 'List'] = item.iotParamValueModels ? item.iotParamValueModels : [];
  501. iotParamValueModels[item.field + 'NameList'] = list;
  502. iotParamValueModels[item.field + 'Index'] = 0;
  503. iotParamValueModels[item.field + 'Name'] = '';
  504. }
  505. })
  506. this.$set(this, 'modelList', data.data);
  507. this.$set(this, 'reservedField', reservedField);
  508. this.$set(this, 'iotParamValueModels', iotParamValueModels);
  509. }
  510. },
  511. /***************** 自适配循环设备列表操作 *****************/
  512. forSelectChange(item, event, index) {
  513. if (item.type == 'select' || item.type == 'radio') {
  514. this.$set(this.iotParamValueModels, [item.field + 'Index'], event.target.value);
  515. this.$set(this.iotParamValueModels, [item.field + 'Name'], this.iotParamValueModels[item.field + 'List'][event
  516. .target.value
  517. ].dictKey);
  518. this.$set(this.reservedField, [item.field], this.iotParamValueModels[item.field + 'List'][event.target.value]
  519. .dictValue);
  520. } else if (item.type == 'selectMultiple' || item.type == 'checkbox') {
  521. this.modelList[index].iotParamValueModels.forEach((maxItem) => {
  522. let num = 0;
  523. event.target.value.forEach((bigItem) => {
  524. if(bigItem == maxItem.dictValue){
  525. num++
  526. }
  527. })
  528. if(num == 0){
  529. maxItem.type = false;
  530. }else{
  531. maxItem.type = true;
  532. }
  533. })
  534. this.$set(this.reservedField, [item.field], event.target.value);
  535. }
  536. },
  537. /***************** 地址查询相关 *****************/
  538. //楼栋tree列表
  539. async systemBuildingGetTreeList() {
  540. const {
  541. data
  542. } = await systemBuildingGetTreeList();
  543. if (data.code == 200) {
  544. this.$set(this, 'treeOptions', data.data);
  545. let list = [];
  546. let nameList = [];
  547. data.data.forEach((item) => {
  548. list.push({
  549. id: item.id,
  550. name: item.name
  551. })
  552. nameList.push(item.name);
  553. })
  554. this.$set(this, 'schoolList', list);
  555. this.$set(this, 'schoolNameList', nameList);
  556. }
  557. },
  558. //校区选中
  559. schoolChange(event) {
  560. if (this.schoolList[0]) {
  561. this.$set(this, 'schoolIndex', event.target.value);
  562. this.$set(this, 'schoolName', this.schoolList[event.target.value].name);
  563. this.$set(this.addForm, 'schoolId', this.schoolList[event.target.value].id);
  564. this.$set(this.addForm, 'schoolName', this.schoolList[event.target.value].name);
  565. this.$set(this.addForm, 'buildId', '');
  566. this.$set(this.addForm, 'buildName', '');
  567. this.$set(this.addForm, 'floorId', '');
  568. this.$set(this.addForm, 'floorName', '');
  569. this.$set(this.addForm, 'subjectId', '');
  570. this.$set(this.addForm, 'subjectName', '');
  571. let list = [];
  572. let nameList = [];
  573. this.treeOptions.forEach((item) => {
  574. if (this.schoolList[event.target.value].id == item.id && item.buildFloorVoList[0]) {
  575. item.buildFloorVoList.forEach((minItem) => {
  576. list.push({
  577. id: minItem.id,
  578. name: minItem.name
  579. })
  580. nameList.push(minItem.name);
  581. })
  582. }
  583. })
  584. this.$set(this, 'buildList', list);
  585. this.$set(this, 'buildNameList', nameList);
  586. this.$set(this, 'buildIndex', 0);
  587. this.$set(this, 'buildName', '');
  588. this.$set(this, 'floorList', []);
  589. this.$set(this, 'floorNameList', []);
  590. this.$set(this, 'floorIndex', 0);
  591. this.$set(this, 'floorName', '');
  592. this.$set(this, 'subList', []);
  593. this.$set(this, 'subNameList', []);
  594. this.$set(this, 'subIndex', 0);
  595. this.$set(this, 'subName', '');
  596. }
  597. },
  598. //楼栋选中
  599. buildChange(event) {
  600. if (this.buildList[0]) {
  601. this.$set(this, 'buildIndex', event.target.value);
  602. this.$set(this, 'buildName', this.buildList[event.target.value].name);
  603. this.$set(this.addForm, 'buildId', this.buildList[event.target.value].id);
  604. this.$set(this.addForm, 'buildName', this.buildList[event.target.value].name);
  605. this.$set(this.addForm, 'floorId', '');
  606. this.$set(this.addForm, 'floorName', '');
  607. this.$set(this.addForm, 'subjectId', '');
  608. this.$set(this.addForm, 'subjectName', '');
  609. let list = [];
  610. let nameList = [];
  611. this.treeOptions.forEach((item) => {
  612. if (this.addForm.schoolId == item.id && item.buildFloorVoList[0]) {
  613. item.buildFloorVoList.forEach((maxItem) => {
  614. if (this.buildList[event.target.value].id == maxItem.id && maxItem.buildFloorVoList[0]) {
  615. maxItem.buildFloorVoList.forEach((minItem) => {
  616. list.push({
  617. id: minItem.id,
  618. name: minItem.name
  619. })
  620. nameList.push(minItem.name);
  621. })
  622. }
  623. })
  624. }
  625. })
  626. this.$set(this, 'floorList', list);
  627. this.$set(this, 'floorNameList', nameList);
  628. this.$set(this, 'floorIndex', 0);
  629. this.$set(this, 'floorName', '');
  630. this.$set(this, 'subList', []);
  631. this.$set(this, 'subNameList', []);
  632. this.$set(this, 'subIndex', 0);
  633. this.$set(this, 'subName', '');
  634. }
  635. },
  636. //楼层选中
  637. floorChange(event) {
  638. if (this.floorList[0]) {
  639. this.$set(this, 'floorIndex', event.target.value);
  640. this.$set(this, 'floorName', this.floorList[event.target.value].name);
  641. this.$set(this.addForm, 'floorId', this.floorList[event.target.value].id);
  642. this.$set(this.addForm, 'floorName', this.floorList[event.target.value].name);
  643. this.$set(this.addForm, 'subjectId', '');
  644. this.$set(this.addForm, 'subjectName', '');
  645. this.laboratorySubRelInfoGetListByFloor(this.floorList[event.target.value].id);
  646. }
  647. },
  648. //实验室选中
  649. subChange(event) {
  650. if (this.subList[0]) {
  651. this.$set(this, 'subIndex', event.target.value);
  652. this.$set(this, 'subName', this.subList[event.target.value].subName);
  653. this.$set(this.addForm, 'subjectId', this.subList[event.target.value].subId);
  654. this.$set(this.addForm, 'subjectName', this.subList[event.target.value].subName);
  655. }
  656. },
  657. //查询实验室
  658. async laboratorySubRelInfoGetListByFloor(floorId) {
  659. const {
  660. data
  661. } = await laboratorySubRelInfoGetListByFloor({
  662. floorId: floorId
  663. });
  664. if (data.code == 200) {
  665. this.$set(this, 'subList', data.data);
  666. let list = [];
  667. data.data.forEach((item) => {
  668. list.push(item.subName);
  669. })
  670. this.$set(this, 'subNameList', list);
  671. this.$set(this, 'subIndex', 0);
  672. this.$set(this, 'subName', '');
  673. }
  674. },
  675. //编辑匹配位置数据
  676. async getAddress(item){
  677. if(item.schoolId){
  678. this.$set(this, 'schoolName', item.schoolName);
  679. let buildList = [];
  680. let buildNameList = [];
  681. let floorList = [];
  682. let floorNameList = [];
  683. this.treeOptions.forEach((maxItem) => {
  684. if (item.schoolId == maxItem.id && maxItem.buildFloorVoList[0]) {
  685. maxItem.buildFloorVoList.forEach((bigItem) => {
  686. buildList.push({
  687. id: bigItem.id,
  688. name: bigItem.name
  689. })
  690. buildNameList.push(bigItem.name);
  691. if(item.buildId){
  692. this.$set(this, 'buildName', item.buildName);
  693. if(item.buildId == bigItem.id && bigItem.buildFloorVoList[0]){
  694. bigItem.buildFloorVoList.forEach((minItem) => {
  695. floorList.push({
  696. id: minItem.id,
  697. name: minItem.name
  698. })
  699. floorNameList.push(minItem.name);
  700. })
  701. if(item.floorId){
  702. this.$set(this, 'floorName', item.floorName);
  703. }
  704. }
  705. }
  706. })
  707. }
  708. })
  709. this.$set(this, 'buildList', buildList);
  710. this.$set(this, 'buildNameList', buildNameList);
  711. this.$set(this, 'floorList', floorList);
  712. this.$set(this, 'floorNameList', floorNameList);
  713. if(item.schoolId && item.buildId && item.floorId){
  714. const {
  715. data
  716. } = await laboratorySubRelInfoGetListByFloor({
  717. floorId: item.floorId
  718. });
  719. if (data.code == 200) {
  720. this.$set(this, 'subList', data.data);
  721. let list = [];
  722. data.data.forEach((subItem) => {
  723. list.push(subItem.subName);
  724. })
  725. this.$set(this, 'subNameList', list);
  726. this.$set(this, 'subIndex', 0);
  727. if(item.subjectId){
  728. this.$set(this, 'subName', item.subjectName);
  729. }
  730. }
  731. }
  732. }
  733. },
  734. //适配循环数据
  735. getIotParamModels(text){
  736. let list = JSON.parse(text)
  737. this.$set(this,'reservedField',list);
  738. this.modelList.forEach((maxItem) => {
  739. if(maxItem.type == 'select' || maxItem.type == 'radio'){
  740. this.iotParamValueModels[maxItem.field + 'List'].forEach((bigItem) => {
  741. if(bigItem.dictValue == this.reservedField[maxItem.field]){
  742. this.$set(this.iotParamValueModels, [maxItem.field + 'Name'], bigItem.dictKey);
  743. }
  744. })
  745. }else if(maxItem.type == 'selectMultiple' || maxItem.type == 'checkbox'){
  746. maxItem.iotParamValueModels.forEach((bigItem) => {
  747. let num = 0;
  748. list[maxItem.field].forEach((minItem) => {
  749. if(bigItem.dictValue == minItem){
  750. num++
  751. }
  752. })
  753. if(num == 0){
  754. bigItem.type = false;
  755. }else{
  756. bigItem.type = true;
  757. }
  758. })
  759. }
  760. })
  761. },
  762. },
  763. }
  764. </script>
  765. <style lang="stylus" scoped>
  766. #iotDevice-add-page {
  767. display: flex;
  768. flex: 1;
  769. flex-direction: column;
  770. overflow: hidden;
  771. .addForm-max-big-box {
  772. flex: 1;
  773. overflow-x: hidden;
  774. overflow-y: scroll;
  775. .addForm-big-box {
  776. background-color: #fff;
  777. margin: 20rpx;
  778. border-radius: 12rpx;
  779. padding: 0 0 30rpx;
  780. .for-addForm-max-input-box {
  781. border-top: 1px solid #dedede;
  782. border-bottom: 1px solid #dedede;
  783. margin-top: 30rpx;
  784. padding-bottom: 30rpx;
  785. .for-addForm-input-box {
  786. display: flex;
  787. margin: 10rpx 0 0 10rpx;
  788. padding: 20rpx 0 0 0;
  789. font-size: 28rpx;
  790. .addForm-input-icon {
  791. color: #FF6666;
  792. width: 40rpx;
  793. margin-right: 10rpx;
  794. text-align: right;
  795. line-height: 60rpx;
  796. }
  797. .addForm-input-title {
  798. width: 200rpx;
  799. color: #333;
  800. line-height: 60rpx;
  801. }
  802. .addForm-input {
  803. padding: 0 20rpx;
  804. height: 60rpx;
  805. line-height: 60rpx;
  806. font-size: 26rpx;
  807. border-radius: 8rpx;
  808. border: 1px solid #dedede;
  809. }
  810. .addForm-input-placeholder{
  811. color: #999 !important;
  812. }
  813. .check-max-box {
  814. width: 400rpx;
  815. .check-min-box {
  816. margin: 10rpx 10rpx 0 0;
  817. font-size: 26rpx;
  818. line-height: 30rpx;
  819. }
  820. }
  821. }
  822. }
  823. .addForm-input-box {
  824. display: flex;
  825. margin: 10rpx 0 0 10rpx;
  826. font-size: 28rpx;
  827. padding: 20rpx 0 0 0;
  828. .addForm-input-icon {
  829. color: #FF6666;
  830. width: 40rpx;
  831. margin-right: 10rpx;
  832. text-align: right;
  833. line-height: 60rpx;
  834. }
  835. .addForm-input-title {
  836. width: 200rpx;
  837. color: #333;
  838. line-height: 60rpx;
  839. }
  840. .addForm-input {
  841. padding: 0 20rpx;
  842. height: 60rpx;
  843. line-height: 60rpx;
  844. font-size: 26rpx;
  845. border-radius: 8rpx;
  846. border: 1px solid #dedede;
  847. }
  848. .addForm-input-placeholder{
  849. color: #999 !important;
  850. }
  851. }
  852. }
  853. }
  854. .addForm-button-box {
  855. height: 80rpx;
  856. display: flex;
  857. .button-null {
  858. flex: 1;
  859. }
  860. .button-view {
  861. width: 260rpx;
  862. margin: 10rpx 0 0 0;
  863. background-color: #0183FA;
  864. color: #fff;
  865. font-size: 26rpx;
  866. text-align: center;
  867. line-height: 60rpx;
  868. height: 60rpx;
  869. border-radius: 12rpx;
  870. }
  871. }
  872. }
  873. </style>