modification.vue 6.0 KB

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