deviceAdd.vue 12 KB

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