modification.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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><span style="color: #ff0000;" v-if="quanxian.namealter">*</span>设备名称</p>
  11. <input type="text" v-model="moddata.device_name" :class="quanxian.namealter?'namebg':''" :disabled="!quanxian.namealter"/>
  12. </view>
  13. <view class="mod_id">
  14. <p>设备ID</p>
  15. <input type="text" :value="moddata.imei || moddata.device_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" v-if="quanxian.infoalter" @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,
  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() { //修改设备名称
  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,
  82. device_name: this.moddata.device_name,
  83. }
  84. })
  85. console.log(res)
  86. if (res==false) {
  87. uni.showToast({
  88. title: '修改名称失败!',
  89. icon: "none"
  90. });
  91. }else{
  92. uni.showToast({
  93. title: '修改名称成功!',
  94. icon: "none"
  95. });
  96. uni.removeStorage({
  97. key: "location"
  98. })
  99. this.clickLeft()
  100. }
  101. },
  102. async eqlistuser(id, imei) { //获取设备信息
  103. const res = await this.$myRequest({
  104. url: '/api/api_gateway?method=forecast.worm_lamp.lamp_list',
  105. data: {
  106. device_type_id: id,
  107. device_id: imei,
  108. }
  109. })
  110. this.moddata = res.data[0]
  111. console.log(res)
  112. this.selectaddress(this.moddata.lng, this.moddata.lat)
  113. },
  114. async xyeqlistuser(imei) { //获取设备信息
  115. const res = await this.$myRequest({
  116. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_list',
  117. data: {
  118. device_id: imei,
  119. }
  120. })
  121. console.log(res)
  122. this.moddata = res.data[0]
  123. this.selectaddress(this.moddata.lng, this.moddata.lat)
  124. },
  125. btn() {
  126. this.eqlistcity(this.moddata.lat, this.moddata.lng)
  127. this.eqlistname()
  128. },
  129. clickLeft() {
  130. uni.navigateBack({
  131. delta:1
  132. })
  133. },
  134. amendcity() { //修改设备地址
  135. if(this.quanxian.cityalter){
  136. this.selectcityTF = true
  137. uni.navigateTo({
  138. url: "../fourBase/city"
  139. })
  140. }else{
  141. uni.showToast({
  142. title: "您暂无权限进行此操作,如有需要,请联系管理员",
  143. icon: "none"
  144. })
  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. this.xyeqlistuser(JSON.parse(option.data).device_id)
  168. }else{
  169. this.eqlistuser(option.id, JSON.parse(option.data).imei)
  170. }
  171. uni.getStorage({
  172. key:"jurisdiction",
  173. success:(res)=>{
  174. console.log(JSON.parse(res.data))
  175. let items = JSON.parse(res.data).filter((item)=>{
  176. return item.purview_name == "设备管理"
  177. })
  178. let items2 = items[0].children.filter((item)=>{
  179. return item.purview_name == "设备列表"
  180. })
  181. this.quanxian.namealter = items2[0].children.some((item)=>{
  182. return item.purview_name == "修改名称"
  183. })
  184. this.quanxian.cityalter = items2[0].children.some((item)=>{
  185. return item.purview_name == "添加位置"
  186. })
  187. this.quanxian.infoalter = items2[0].children.some((item)=>{
  188. return item.purview_name == "修改名称" || item.purview_name == "添加位置"
  189. })
  190. },
  191. })
  192. },
  193. onShow(){
  194. uni.getStorage({
  195. key: "location",
  196. success: (res) => {
  197. // console.log(res);
  198. this.moddata.lat = res.data[1]
  199. this.moddata.lng = res.data[0]
  200. this.selectaddress(this.moddata.lng, this.moddata.lat)
  201. }
  202. })
  203. }
  204. }
  205. </script>
  206. <style lang="scss">
  207. page{
  208. background-color: #FAFAFA;
  209. }
  210. .mod {
  211. width: 100%;
  212. position: absolute;
  213. top: 44px;
  214. .mod_name,
  215. .mod_id,
  216. .mod_user,
  217. .mod_time {
  218. width: 90%;
  219. margin: 30rpx auto;
  220. display: flex;
  221. justify-content: space-between;
  222. background-color: #FFFFFF;
  223. padding: 20rpx 10rpx;
  224. color: #57C77A;
  225. line-height: 50rpx;
  226. .namebg{
  227. background-color: #FAFAFA;
  228. }
  229. input {
  230. text-align: right;
  231. font-size: 28rpx;
  232. padding: 10rpx;
  233. }
  234. }
  235. .mod_city{
  236. width: 90%;
  237. margin: 30rpx auto;
  238. background-color: #FFFFFF;
  239. padding: 20rpx 10rpx;
  240. color: #57C77A;
  241. line-height: 50rpx;
  242. display: flex;
  243. justify-content: space-between;
  244. .namebg{
  245. background-color: #FAFAFA;
  246. }
  247. input {
  248. width: 90%;
  249. font-size: 28rpx;
  250. padding: 10rpx;
  251. }
  252. }
  253. }
  254. .sub {
  255. width: 90%;
  256. margin: 30rpx auto;
  257. text-align: center;
  258. height: 70rpx;
  259. line-height: 70rpx;
  260. background-color: #57C77A;
  261. border-radius: 35rpx;
  262. color: #FFFFFF;
  263. }
  264. </style>