deviceAdd.vue 12 KB

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