modification.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  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" 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. <p><span style="color: #ff0000;" v-if="quanxian.cityalter">*</span>设备位置</p>
  23. <view style="display: flex;">
  24. <input type="text" :value="city" disabled style="width: 400rpx;" />
  25. <u-icon name="arrow-right"></u-icon>
  26. </view>
  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;" v-if="quanxian.infoalter">*</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.showModal({
  67. title: "修改地址失败",
  68. icon: "none"
  69. })
  70. }
  71. },
  72. async eqlistname() { //修改设备名称
  73. const res = await this.$myRequest({
  74. url: '/api/api_gateway?method=forecast.worm_lamp.revise_device',
  75. data: {
  76. device_id: this.moddata.imei,
  77. device_name: this.moddata.device_name,
  78. }
  79. })
  80. console.log(res)
  81. if (res==false) {
  82. uni.showModal({
  83. title: "修改名称失败",
  84. icon: "none"
  85. })
  86. }
  87. },
  88. async eqlistuser(id, imei) { //获取设备信息
  89. const res = await this.$myRequest({
  90. url: '/api/api_gateway?method=forecast.worm_lamp.lamp_list',
  91. data: {
  92. device_type_id: id,
  93. device_id: imei,
  94. }
  95. })
  96. this.moddata = res.data[0]
  97. console.log(res)
  98. this.selectaddress(this.moddata.lng, this.moddata.lat)
  99. },
  100. btn() {
  101. this.eqlistcity(this.moddata.lat, this.moddata.lng)
  102. this.eqlistname()
  103. uni.removeStorage({
  104. key: "location"
  105. })
  106. this.clickLeft()
  107. },
  108. clickLeft() {
  109. uni.navigateBack({
  110. delta:1
  111. })
  112. },
  113. amendcity() { //修改设备地址
  114. if(this.quanxian.cityalter){
  115. this.selectcityTF = true
  116. uni.navigateTo({
  117. url: "../fourBase/city"
  118. })
  119. }else{
  120. uni.showToast({
  121. title: "您暂无权限进行此操作,如有需要,请联系管理员",
  122. icon: "none"
  123. })
  124. }
  125. },
  126. selectaddress(lng, lat) { //获取分布位置
  127. uni.request({
  128. type: "GET",
  129. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," + lat +
  130. "&key=27273b81090f78759e4057f94474516f&radius=1000&extensions=all",
  131. dataType: "json",
  132. complete: ress => {
  133. // console.log(ress)
  134. if (ress.data.regeocode.formatted_address.length == 0) {
  135. this.city = "--"
  136. } else {
  137. this.city = ress.data.regeocode.formatted_address
  138. }
  139. }
  140. });
  141. },
  142. },
  143. onLoad(option) {
  144. console.log(option)
  145. this.eqlistuser(option.id, JSON.parse(option.data).imei)
  146. uni.getStorage({
  147. key:"jurisdiction",
  148. success:(res)=>{
  149. console.log(JSON.parse(res.data))
  150. let items = JSON.parse(res.data).filter((item)=>{
  151. return item.purview_name == "设备管理"
  152. })
  153. let items2 = items[0].children.filter((item)=>{
  154. return item.purview_name == "分配设备"
  155. })
  156. this.quanxian.namealter = items2[0].children.some((item)=>{
  157. return item.purview_name == "修改名称"
  158. })
  159. this.quanxian.cityalter = items2[0].children.some((item)=>{
  160. return item.purview_name == "添加位置"
  161. })
  162. this.quanxian.infoalter = items2[0].children.some((item)=>{
  163. return item.purview_name == "修改名称" || item.purview_name == "添加位置"
  164. })
  165. },
  166. })
  167. },
  168. onShow(){
  169. uni.getStorage({
  170. key: "location",
  171. success: (res) => {
  172. // console.log(res);
  173. this.moddata.lat = res.data[1]
  174. this.moddata.lng = res.data[0]
  175. this.selectaddress(this.moddata.lng, this.moddata.lat)
  176. }
  177. })
  178. }
  179. }
  180. </script>
  181. <style lang="scss">
  182. page{
  183. background-color: #FAFAFA;
  184. }
  185. .mod {
  186. width: 100%;
  187. position: absolute;
  188. top: 44px;
  189. .mod_name,
  190. .mod_id,
  191. .mod_user,
  192. .mod_time,
  193. .mod_city {
  194. width: 90%;
  195. margin: 30rpx auto;
  196. display: flex;
  197. justify-content: space-between;
  198. background-color: #FFFFFF;
  199. padding: 20rpx 10rpx;
  200. color: #57C77A;
  201. line-height: 50rpx;
  202. .namebg{
  203. background-color: #FAFAFA;
  204. }
  205. input {
  206. text-align: right;
  207. font-size: 28rpx;
  208. padding: 10rpx;
  209. }
  210. }
  211. }
  212. .sub {
  213. width: 90%;
  214. margin: 30rpx auto;
  215. text-align: center;
  216. height: 70rpx;
  217. line-height: 70rpx;
  218. background-color: #57C77A;
  219. border-radius: 35rpx;
  220. color: #FFFFFF;
  221. }
  222. </style>