modification.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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(lat, lng) { //修改设备名称
  78. const res = await this.$myRequest({
  79. url: '/api/api_gateway?method=forecast.worm_lamp.revise_device',
  80. data: {
  81. lat: lat,
  82. lng: lng,
  83. device_id: this.moddata.imei,
  84. device_name: this.moddata.device_name,
  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) { //获取设备信息
  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. }
  111. })
  112. this.moddata = res.data[0] || {};
  113. console.log(res,'moddatamoddata')
  114. this.selectaddress(this.moddata.lng, this.moddata.lat)
  115. },
  116. async xyeqlistuser(imei) { //获取设备信息
  117. const res = await this.$myRequest({
  118. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_list',
  119. data: {
  120. device_id: imei,
  121. }
  122. })
  123. console.log(res)
  124. this.moddata = res.data[0] || {};
  125. this.selectaddress(this.moddata.lng, this.moddata.lat)
  126. },
  127. btn() {
  128. // this.eqlistcity(this.moddata.lat, this.moddata.lng)
  129. this.eqlistname(this.moddata.lat, this.moddata.lng)
  130. },
  131. clickLeft() {
  132. uni.navigateBack({
  133. delta:1
  134. })
  135. },
  136. amendcity() { //修改设备地址
  137. if(this.quanxian.cityalter){
  138. this.selectcityTF = true
  139. uni.navigateTo({
  140. url: "../../fourBase/city?lat=" + this.moddata.lat + "&lng=" + this.moddata.lng + "&city=" + this.moddata.city
  141. })
  142. }else{
  143. uni.showToast({
  144. title: "您暂无权限进行此操作,如有需要,请联系管理员",
  145. icon: "none"
  146. })
  147. }
  148. },
  149. selectaddress(lng, lat) { //获取分布位置
  150. uni.request({
  151. type: "GET",
  152. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," + lat +
  153. "&key=27273b81090f78759e4057f94474516f&radius=1000&extensions=all",
  154. dataType: "json",
  155. complete: ress => {
  156. // console.log(ress)
  157. if (ress.data.regeocode.formatted_address.length == 0) {
  158. this.city = "--"
  159. } else {
  160. this.city = ress.data.regeocode.formatted_address
  161. }
  162. }
  163. });
  164. },
  165. },
  166. onLoad(option) {
  167. console.log(option)
  168. if(option.id==10){
  169. this.xyeqlistuser(JSON.parse(option.data).device_id)
  170. }else{
  171. this.eqlistuser(option.id, JSON.parse(option.data).imei)
  172. }
  173. uni.getStorage({
  174. key:"jurisdiction",
  175. success:(res)=>{
  176. console.log(JSON.parse(res.data))
  177. let items = JSON.parse(res.data).filter((item)=>{
  178. return item.purview_name == "设备管理"
  179. })
  180. let items2 = items[0].children.filter((item)=>{
  181. return item.purview_name == "设备列表"
  182. })
  183. this.quanxian.namealter = items2[0].children.some((item)=>{
  184. return item.purview_name == "修改名称"
  185. })
  186. this.quanxian.cityalter = items2[0].children.some((item)=>{
  187. return item.purview_name == "添加位置"
  188. })
  189. this.quanxian.infoalter = items2[0].children.some((item)=>{
  190. return item.purview_name == "修改名称" || item.purview_name == "添加位置"
  191. })
  192. },
  193. })
  194. },
  195. onShow(){
  196. uni.getStorage({
  197. key: "location",
  198. success: (res) => {
  199. // console.log(res);
  200. this.moddata.lat = res.data[1]
  201. this.moddata.lng = res.data[0]
  202. this.selectaddress(this.moddata.lng, this.moddata.lat)
  203. }
  204. })
  205. }
  206. }
  207. </script>
  208. <style lang="scss">
  209. page{
  210. background-color: #FAFAFA;
  211. }
  212. .mod {
  213. width: 100%;
  214. position: absolute;
  215. top: 44px;
  216. .mod_name,
  217. .mod_id,
  218. .mod_user,
  219. .mod_time {
  220. width: 90%;
  221. margin: 30rpx auto;
  222. display: flex;
  223. justify-content: space-between;
  224. background-color: #FFFFFF;
  225. padding: 20rpx 10rpx;
  226. color: #57C77A;
  227. line-height: 50rpx;
  228. .namebg{
  229. background-color: #FAFAFA;
  230. }
  231. input {
  232. text-align: right;
  233. font-size: 28rpx;
  234. padding: 10rpx;
  235. }
  236. }
  237. .mod_city{
  238. width: 90%;
  239. margin: 30rpx auto;
  240. background-color: #FFFFFF;
  241. padding: 20rpx 10rpx;
  242. color: #57C77A;
  243. line-height: 50rpx;
  244. display: flex;
  245. justify-content: space-between;
  246. .namebg{
  247. background-color: #FAFAFA;
  248. }
  249. input {
  250. width: 90%;
  251. font-size: 28rpx;
  252. padding: 10rpx;
  253. }
  254. }
  255. }
  256. .sub {
  257. width: 90%;
  258. margin: 30rpx auto;
  259. text-align: center;
  260. height: 70rpx;
  261. line-height: 70rpx;
  262. background-color: #57C77A;
  263. border-radius: 35rpx;
  264. color: #FFFFFF;
  265. }
  266. </style>