modification copy.vue 6.8 KB

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