addPage.vue 27 KB

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