modification.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  5. <view style="position: fixed;z-index: 100;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" title="修改名称"></uni-nav-bar>
  7. </view>
  8. <view class="mod">
  9. <view class="mod_name">
  10. <p>设备名称</p>
  11. <input type="text" v-model="moddata.device_name" :class="quanxian.namealter?'namebg':''" />
  12. </view>
  13. <view class="mod_id">
  14. <p>设备ID</p>
  15. <input type="text" :value="moddata.imei || moddata.device_id || moddata.id" disabled />
  16. </view>
  17. <view class="mod_user">
  18. <p>适配用户</p>
  19. <input type="text" :value="moddata.real_name==''?'无':moddata.real_name" disabled />
  20. </view>
  21. <view class="mod_city" @click="amendcity">
  22. <view style="width: 90%;">
  23. <p><span style="color: #ff0000;" v-if="quanxian.cityalter">*</span>设备位置</p>
  24. <input type="text" :value="city" disabled />
  25. </view>
  26. <u-icon name="arrow-right"></u-icon>
  27. </view>
  28. <view class="mod_time">
  29. <p>设备添加时间</p>
  30. <input type="text" :value="moddata.addtime|timeFormat()" disabled />
  31. </view>
  32. <p style="width: 90%;margin: 0 auto;text-align: right;color: #06B535;"><span style="color: #ff0000;">*</span>为可修改</p>
  33. <view class="sub" @click="btn">
  34. 提 交
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. moddata: [],
  45. city: "",
  46. selectcityTF: false,
  47. quanxian:{
  48. namealter:false,
  49. cityalter:false,
  50. infoalter:false
  51. }
  52. }
  53. },
  54. methods: {
  55. async eqlistcity(lat, lng) { //修改设备定位
  56. const res = await this.$myRequest({
  57. url: '/api/api_gateway?method=forecast.worm_lamp.revise_device',
  58. data: {
  59. device_id: this.moddata.imei || this.moddata.device_id || this.moddata.id,
  60. lat: lat,
  61. lng: lng
  62. }
  63. })
  64. console.log(res)
  65. if (res==false) {
  66. uni.showToast({
  67. title: '修改地址失败!',
  68. icon: "none"
  69. });
  70. }else{
  71. uni.showToast({
  72. title: '修改地址成功!',
  73. icon: "none"
  74. });
  75. }
  76. },
  77. async eqlistname(lat, lng) { //修改设备名称
  78. const res = await this.$myRequest({
  79. url: '/api/api_gateway?method=forecast.worm_lamp.revise_device',
  80. data: {
  81. device_id: this.moddata.imei || this.moddata.device_id || this.moddata.id,
  82. device_name: this.moddata.device_name,
  83. lat: lat,
  84. lng: lng,
  85. }
  86. })
  87. console.log(res)
  88. if (res==false) {
  89. uni.showToast({
  90. title: '修改名称失败!',
  91. icon: "none"
  92. });
  93. }else{
  94. uni.showToast({
  95. title: '修改名称成功!',
  96. icon: "none"
  97. });
  98. uni.removeStorage({
  99. key: "location"
  100. })
  101. this.clickLeft()
  102. }
  103. },
  104. async eqlistuser(id, imei,device_model) { //获取设备信息
  105. const res = await this.$myRequest({
  106. url: '/api/api_gateway?method=forecast.worm_lamp.lamp_list',
  107. data: {
  108. device_type_id: id,
  109. device_id: imei,
  110. device_model: device_model,
  111. }
  112. })
  113. this.moddata = res.data[0]
  114. console.log(res)
  115. this.selectaddress(this.moddata.lng, this.moddata.lat)
  116. },
  117. async xyeqlistuser(imei) { //获取设备信息
  118. const res = await this.$myRequest({
  119. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_list',
  120. data: {
  121. device_id: imei,
  122. }
  123. })
  124. console.log(res)
  125. this.moddata = res.data[0]
  126. this.selectaddress(this.moddata.lng, this.moddata.lat)
  127. },
  128. btn() {
  129. // this.eqlistcity(this.moddata.lat, this.moddata.lng)
  130. this.eqlistname(this.moddata.lat, this.moddata.lng)
  131. },
  132. clickLeft() {
  133. uni.navigateBack({
  134. delta:1,
  135. success:()=>{
  136. //告知上一页刷新数据
  137. uni.$emit('refreshData')
  138. }
  139. })
  140. },
  141. amendcity() { //修改设备地址
  142. this.selectcityTF = true
  143. uni.navigateTo({
  144. url: "/pages/fourBase/city"
  145. })
  146. },
  147. selectaddress(lng, lat) { //获取分布位置
  148. uni.request({
  149. type: "GET",
  150. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," + lat +
  151. "&key=27273b81090f78759e4057f94474516f&radius=1000&extensions=all",
  152. dataType: "json",
  153. complete: ress => {
  154. // console.log(ress)
  155. if (ress.data.regeocode.formatted_address.length == 0) {
  156. this.city = "--"
  157. } else {
  158. this.city = ress.data.regeocode.formatted_address
  159. }
  160. }
  161. });
  162. },
  163. },
  164. onLoad(option) {
  165. console.log(option)
  166. if(option.id==10){
  167. const data = JSON.parse(option.data)
  168. this.xyeqlistuser(data.device_id || data.id)
  169. }else{
  170. const data = JSON.parse(option.data)
  171. this.eqlistuser(data.type_id, data.imei || data.device_id || data.id,data.device_model)
  172. }
  173. uni.getStorage({
  174. key:"jurisdiction",
  175. success:(res)=>{
  176. console.log(JSON.parse(res.data))
  177. if(!res?.data){
  178. return;
  179. }
  180. let items = JSON.parse(res.data).filter((item)=>{
  181. return item.purview_name == "设备管理"
  182. })
  183. let items2 = items[0].children.filter((item)=>{
  184. return item.purview_name == "设备列表"
  185. })
  186. this.quanxian.namealter = items2[0].children.some((item)=>{
  187. return item.purview_name == "修改名称"
  188. })
  189. this.quanxian.cityalter = items2[0].children.some((item)=>{
  190. return item.purview_name == "添加位置"
  191. })
  192. this.quanxian.infoalter = items2[0].children.some((item)=>{
  193. return item.purview_name == "修改名称" || item.purview_name == "添加位置"
  194. })
  195. },
  196. })
  197. },
  198. onShow(){
  199. uni.getStorage({
  200. key: "location",
  201. success: (res) => {
  202. // console.log(res);
  203. this.moddata.lat = res.data[1]
  204. this.moddata.lng = res.data[0]
  205. this.selectaddress(this.moddata.lng, this.moddata.lat)
  206. }
  207. })
  208. }
  209. }
  210. </script>
  211. <style lang="scss">
  212. page{
  213. background-color: #FAFAFA;
  214. }
  215. .mod {
  216. width: 100%;
  217. position: absolute;
  218. top: 44px;
  219. .mod_name,
  220. .mod_id,
  221. .mod_user,
  222. .mod_time {
  223. width: 90%;
  224. margin: 30rpx auto;
  225. display: flex;
  226. justify-content: space-between;
  227. background-color: #FFFFFF;
  228. padding: 20rpx 10rpx;
  229. color: #57C77A;
  230. line-height: 50rpx;
  231. .namebg{
  232. background-color: #FAFAFA;
  233. }
  234. input {
  235. text-align: right;
  236. font-size: 28rpx;
  237. padding: 10rpx;
  238. }
  239. }
  240. .mod_city{
  241. width: 90%;
  242. margin: 30rpx auto;
  243. background-color: #FFFFFF;
  244. padding: 20rpx 10rpx;
  245. color: #57C77A;
  246. line-height: 50rpx;
  247. display: flex;
  248. justify-content: space-between;
  249. .namebg{
  250. background-color: #FAFAFA;
  251. }
  252. input {
  253. width: 90%;
  254. font-size: 28rpx;
  255. padding: 10rpx;
  256. }
  257. }
  258. }
  259. .sub {
  260. width: 90%;
  261. margin: 30rpx auto;
  262. text-align: center;
  263. height: 70rpx;
  264. line-height: 70rpx;
  265. background-color: #57C77A;
  266. border-radius: 35rpx;
  267. color: #FFFFFF;
  268. }
  269. </style>