deviceAdd.vue 12 KB

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