deviceAdd.vue 12 KB

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