deviceAdd.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <view class="appWrapper">
  3. <!-- 站点新增start -->
  4. <form action="" @submit="formSubmit" v-if="!deviceCode">
  5. <view class="form-item margin-top">
  6. <view class="title">
  7. <text class="necessary">*</text>
  8. 设备编号:
  9. </view>
  10. <input name="deviceCode" v-model="formMess.deviceCode"></input>
  11. </view>
  12. <view class="form-item">
  13. <view class="title"><text class="necessary">*</text>设备名称:</view>
  14. <input name="input" v-model="formMess.deviceName"></input>
  15. </view>
  16. <view class="form-item">
  17. <view class="title"><text class="necessary">*</text>安装位置:</view>
  18. <input name="input" v-model="formMess.deviceInstallationPosition"></input>
  19. </view>
  20. <view class="form-item">
  21. <view class="title"><text class="necessary">*</text>所属楼层:</view>
  22. <!-- <select name="" id="" v-model="formMess.floor" filterable clearable>
  23. <option value="1" >楼层1</option>
  24. <option value="2" >楼层2</option>
  25. </select> -->
  26. <select name="" id="" v-model="formMess.floor" filterable clearable>
  27. <option value="" >请选择</option>
  28. <option value="-10">楼层B10</option>
  29. <option value="-9">楼层B9</option>
  30. <option value="-8">楼层B8</option>
  31. <option value="-7">楼层B7</option>
  32. <option value="-6">楼层B6</option>
  33. <option value="-5">楼层B5</option>
  34. <option value="-4">楼层B4</option>
  35. <option value="-3">楼层B3</option>
  36. <option value="-2">楼层B2</option>
  37. <option value="-1">楼层B1</option>
  38. <option :value=item v-for="item in 60">楼层{{item}}</option>
  39. </select>
  40. </view>
  41. <view class="form-item">
  42. <view class="title"><text class="necessary">*</text>设备类型:</view>
  43. <select name="" id="" v-model="formMess.deviceType" filterable clearable>
  44. <option value="">请选择</option>
  45. <option value="1">183用电设备</option>
  46. <option value="2">视频监控设备</option>
  47. <option value="3">171用电设备</option>
  48. <option value="4">173用电设备</option>
  49. <!-- <option value="5">158智能网关</option>
  50. <option value="6">其他</option> -->
  51. </select>
  52. </view>
  53. <view class="form-item">
  54. <view class="title"><text class="necessary">*</text>站点:</view>
  55. <select name="" id="" v-model="formMess.siteId" filterable clearable>
  56. <option value="">请选择</option>
  57. <option :value=item.id v-for="item in siteList">{{ item.siteName}}</option>
  58. </select>
  59. </view>
  60. <view class="btn-area submitBottomBtn padding-lr-sm">
  61. <button class="bg-blue round margin-top" @click="$noMultipleClicks(addSubmit)">提 交 </button>
  62. </view>
  63. </form>
  64. <!-- 站点新增end -->
  65. <!-- 站点修改start -->
  66. <form action="" @submit="formSubmit" v-else>
  67. <view class="form-item margin-top">
  68. <view class="title">
  69. <text class="necessary">*</text>
  70. 设备编号:
  71. </view>
  72. <input name="deviceCode" v-model="deviceMessage.deviceCode" disabled="disabled"></input>
  73. </view>
  74. <view class="form-item">
  75. <view class="title"><text class="necessary">*</text>设备名称:</view>
  76. <input name="input" v-model="deviceMessage.deviceName" ></input>
  77. </view>
  78. <view class="form-item">
  79. <view class="title"><text class="necessary">*</text>安装位置:</view>
  80. <input name="input" v-model="deviceMessage.deviceInstallationPosition"></input>
  81. </view>
  82. <view class="form-item">
  83. <view class="title"><text class="necessary">*</text>所属楼层:</view>
  84. <select name="" id="" v-model="deviceMessage.floor" filterable clearable>
  85. <!-- <option value="" >请选择</option> -->
  86. <option value="-10">楼层B10</option>
  87. <option value="-9">楼层B9</option>
  88. <option value="-8">楼层B8</option>
  89. <option value="-7">楼层B7</option>
  90. <option value="-6">楼层B6</option>
  91. <option value="-5">楼层B5</option>
  92. <option value="-4">楼层B4</option>
  93. <option value="-3">楼层B3</option>
  94. <option value="-2">楼层B2</option>
  95. <option value="-1">楼层B1</option>
  96. <option :value=index+1 v-for="(item,index) in 60">楼层{{item}}</option>
  97. </select>
  98. </view>
  99. <view class="form-item">
  100. <view class="title"><text class="necessary">*</text>设备类型:</view>
  101. <select name="" id="" v-model="deviceMessage.deviceType" filterable clearable>
  102. <option value="">请选择</option>
  103. <option value="1">183用电设备</option>
  104. <option value="2">视频监控设备</option>
  105. <option value="3">171用电设备</option>
  106. <option value="4">173用电设备</option>
  107. </select>
  108. </view>
  109. <view class="form-item">
  110. <view class="title"><text class="necessary">*</text>站点:</view>
  111. <select name="" id="" v-model="deviceMessage.siteId" filterable clearable>
  112. <option :value=item.id v-for="item in siteList">{{ item.siteName}}</option>
  113. </select>
  114. </view>
  115. <view class="btn-area submitBottomBtn padding-lr-sm">
  116. <button class="bg-blue round margin-top" @click="$noMultipleClicks(editSubmit)">提 交 </button>
  117. </view>
  118. </form>
  119. <!-- 站点修改end -->
  120. </view>
  121. </template>
  122. <script>
  123. export default {
  124. data() {
  125. return {
  126. noClick:true,
  127. siteList: [],
  128. id: 0,
  129. deviceCode:'',
  130. formMess: {
  131. "deviceCode": "",
  132. "siteId": "",
  133. "deviceType": "",
  134. "deviceName": "",
  135. "deviceInstallationPosition": "",
  136. "floor": "",
  137. },
  138. deviceMessage: {}
  139. }
  140. },
  141. onLoad: function(option) {
  142. this.id = option.id
  143. this.deviceCode=option.deviceCode
  144. this.getSiteList()
  145. if (option.deviceCode) {
  146. uni.setNavigationBarTitle({
  147. title: '设备修改'
  148. });
  149. this.getDeviceList({
  150. "siteId": option.id,
  151. "deviceCode": option.deviceCode
  152. })
  153. } else {
  154. uni.setNavigationBarTitle({
  155. title: '设备新增'
  156. });
  157. }
  158. },
  159. methods: {
  160. //新增验证并提交
  161. addSubmit() {
  162. if (!this.formMess.deviceCode.replace(/^\s*/g,'')) {
  163. uni.showToast({
  164. title: "请填写设备编号",
  165. icon: "none"
  166. });
  167. return
  168. }
  169. if (!this.formMess.deviceName.replace(/^\s*/g,'')) {
  170. uni.showToast({
  171. title: "请填写设备名称",
  172. icon: "none"
  173. });
  174. return
  175. }
  176. if (!this.formMess.deviceInstallationPosition.replace(/^\s*/g,'')) {
  177. uni.showToast({
  178. title: "请填写安装位置",
  179. icon: "none"
  180. });
  181. return
  182. }
  183. if (!this.formMess.floor) {
  184. uni.showToast({
  185. title: "请选择所属楼层",
  186. icon: "none"
  187. });
  188. return
  189. }
  190. if (!this.formMess.deviceType) {
  191. uni.showToast({
  192. title: "请选择设备类型",
  193. icon: "none"
  194. });
  195. return
  196. }
  197. if (!this.formMess.siteId) {
  198. uni.showToast({
  199. title: "请选择站点",
  200. icon: "none"
  201. });
  202. return
  203. }
  204. this.setAddDevice({
  205. "deviceCode": this.formMess.deviceCode,
  206. "siteId": this.formMess.siteId,
  207. "deviceType": this.formMess.deviceType,
  208. "deviceName": this.formMess.deviceName,
  209. "deviceInstallationPosition": this.formMess.deviceInstallationPosition,
  210. "floor": this.formMess.floor
  211. })
  212. },
  213. //编辑验证并提交
  214. editSubmit() {
  215. if (!this.deviceMessage.deviceCode.replace(/^\s*/g,'')) {
  216. uni.showToast({
  217. title: "请填写设备编号",
  218. icon: "none"
  219. });
  220. return
  221. }
  222. if (!this.deviceMessage.deviceName.replace(/^\s*/g,'')) {
  223. uni.showToast({
  224. title: "请填写设备名称",
  225. icon: "none"
  226. });
  227. return
  228. }
  229. if (!this.deviceMessage.deviceInstallationPosition.replace(/^\s*/g,'')) {
  230. uni.showToast({
  231. title: "请填写安装位置",
  232. icon: "none"
  233. });
  234. return
  235. }
  236. if (!this.deviceMessage.floor) {
  237. uni.showToast({
  238. title: "请选择所属楼层",
  239. icon: "none"
  240. });
  241. return
  242. }
  243. if (!this.deviceMessage.deviceType) {
  244. uni.showToast({
  245. title: "请选择设备类型",
  246. icon: "none"
  247. });
  248. return
  249. }
  250. if (!this.deviceMessage.siteId) {
  251. uni.showToast({
  252. title: "请选择站点",
  253. icon: "none"
  254. });
  255. return
  256. }
  257. this.setEditDevice({
  258. "deviceCode": this.deviceMessage.deviceCode,
  259. "siteId": this.deviceMessage.siteId,
  260. "deviceType": this.deviceMessage.deviceType,
  261. "deviceName": this.deviceMessage.deviceName,
  262. "deviceInstallationPosition": this.deviceMessage.deviceInstallationPosition,
  263. "floor": this.deviceMessage.floor
  264. })
  265. },
  266. // 新增请求
  267. async setAddDevice(ming = {}) {
  268. const res = await this.$myRequest({
  269. url: 'DeviceManagement/setAddDevice',
  270. data: ming
  271. })
  272. if (!res.data.flag) {
  273. uni.showToast({
  274. title: "添加失败",
  275. icon: "none"
  276. });
  277. } else {
  278. uni.showToast({
  279. title: "添加成功",
  280. });
  281. }
  282. setTimeout(() => {
  283. uni.navigateTo({
  284. url: '/pages/siteManage/siteManage',
  285. });
  286. }, 1000);
  287. },
  288. // 站点下拉
  289. async getSiteList(ming = {}) {
  290. const res = await this.$myRequest({
  291. url: 'SiteManagement/getSiteList',
  292. data: ming
  293. })
  294. // this.deviceMessage=res.data.data[0];
  295. this.siteList = res.data.data
  296. // console.log(res.data.data)
  297. },
  298. // 修改回显请求
  299. async getDeviceList(ming = {}) {
  300. const res = await this.$myRequest({
  301. url: 'DeviceManagement/getDeviceList',
  302. data: ming
  303. })
  304. console.log('res.data.data')
  305. console.log(res.data.data[0])
  306. this.deviceMessage = res.data.data[0];
  307. console.log(this.deviceMessage)
  308. },
  309. // 编辑请求
  310. async setEditDevice(ming = {}) {
  311. const res = await this.$myRequest({
  312. url: 'DeviceManagement/setEditDevice',
  313. data: ming
  314. })
  315. if (!res.data.flag) {
  316. uni.showToast({
  317. title: "编辑失败",
  318. icon: "none"
  319. });
  320. } else {
  321. uni.showToast({
  322. title: "编辑成功",
  323. });
  324. }
  325. setTimeout(() => {
  326. uni.navigateTo({
  327. url: '/pages/siteManage/siteManage',
  328. });
  329. }, 1000);
  330. },
  331. }
  332. }
  333. </script>
  334. <style lang="scss">
  335. .cu-form-group {
  336. border-top: 0;
  337. }
  338. input,
  339. select,
  340. option {
  341. line-height: 70rpx;
  342. padding: 0 20rpx;
  343. height: 70rpx;
  344. border: 1px solid #EDEDED;
  345. // width:500rpx!important;
  346. background-color: #fff;
  347. box-sizing: border-box;
  348. appearance: none;
  349. -moz-appearance: none;
  350. -webkit-appearance: none;
  351. color: #999;
  352. }
  353. select:focus,
  354. select:active,
  355. select:hover {
  356. outline: none;
  357. }
  358. select {
  359. background: url(../../static/arrow.png) no-repeat scroll 98% center;
  360. background-size: 6%;
  361. }
  362. .form-item label text {
  363. position: relative;
  364. top: 2rpx
  365. }
  366. .form-item {
  367. padding: 0 40rpx;
  368. display: flex;
  369. align-items: top;
  370. margin-bottom: 20rpx;
  371. .title {
  372. width: 170rpx;
  373. position: relative;
  374. .necessary {
  375. color: red;
  376. display: inline-block;
  377. position: absolute;
  378. top: -2rpx;
  379. left: -20rpx;
  380. font-size: 40rpx;
  381. }
  382. }
  383. input,
  384. select {
  385. width: 500rpx;
  386. font-size: 28rpx;
  387. }
  388. }
  389. /* 站点多选下拉样式 start */
  390. .layui-btn {
  391. background-color: #5fb878;
  392. }
  393. a {
  394. text-decoration: none;
  395. }
  396. .label {
  397. padding: 2px 0px;
  398. background: #aaa;
  399. border-radius: 2px;
  400. color: #fff;
  401. display: block;
  402. line-height: 20px;
  403. height: 20px;
  404. margin: 2px 5px 2px 0;
  405. float: left;
  406. }
  407. .label span {
  408. padding: 0 5px;
  409. color: #fff;
  410. }
  411. .close {
  412. padding: 1px 5px !important;
  413. }
  414. .close:hover {
  415. /* background-color: #009E94;
  416. border-radius: 2px;
  417. color: tomato; */
  418. }
  419. .selectId input {
  420. width: 100% !important;
  421. }
  422. .selectId input {
  423. height: 25px;
  424. padding: 1px 5px;
  425. border-radius: 3px;
  426. width: calc(100% - 12px);
  427. outline-color: #5fb878;
  428. border: 1px solid #5fb878;
  429. }
  430. .selectId {
  431. position: relative;
  432. }
  433. .selectId dl {
  434. border: 1px solid #eee;
  435. border-radius: 3px;
  436. margin: 2px 0px;
  437. max-height: 300px;
  438. overflow-x: hidden;
  439. white-space: nowrap;
  440. position: absolute;
  441. width: 100%;
  442. top: 40px;
  443. background: #fff;
  444. z-index: 1000
  445. }
  446. .selectId dl dd {
  447. margin: 0;
  448. padding: 5px 10px;
  449. }
  450. .selectId dl dd:hover {
  451. background-color: #5FB878;
  452. color: white;
  453. }
  454. .AD {
  455. /* width: 210px;
  456. margin-left: 40px; */
  457. overflow-y: auto;
  458. max-height: 200px;
  459. /* border: 2px solid #5fb878;
  460. border-radius: 6px;
  461. padding: 1px 2px; */
  462. }
  463. form .AD span {
  464. width: auto;
  465. }
  466. .siteSelect {
  467. width: 71%;
  468. display: inline-block;
  469. }
  470. /* 站点多选下拉样式end */
  471. </style>