modification.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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':''"
  8. :disabled="!quanxian.namealter" />
  9. </view>
  10. <view class="mod_id">
  11. <p>设备ID</p>
  12. <input type="text" :value="moddata.imei || moddata.device_id" disabled />
  13. </view>
  14. <view class="mod_user">
  15. <p>适配用户</p>
  16. <input type="text" :value="moddata.real_name==''?'无':moddata.real_name" disabled />
  17. </view>
  18. <view class="mod_city" @click="amendcity" v-if="$QueryPermission(109)">
  19. <p><span style="color: #ff0000;" v-if="quanxian.cityalter">*</span>设备位置</p>
  20. <view style="display: flex;">
  21. <input type="text" :value="city" disabled style="width: 400rpx;" />
  22. <u-icon name="arrow-right"></u-icon>
  23. </view>
  24. </view>
  25. <view class="mod_time">
  26. <p>设备添加时间</p>
  27. <input type="text" :value="moddata.addtime|timeFormat()" disabled />
  28. </view>
  29. <p style="width: 90%;margin: 0 auto;text-align: right;color: #06B535;"><span
  30. style="color: #ff0000;">*</span>为可修改</p>
  31. <view class="sub" v-if="quanxian.infoalter" @click="btn">
  32. 提 交
  33. </view>
  34. </view>
  35. </view>
  36. <view class="loading" v-if="loading">
  37. <image src="../../static/images/ajax-loader.gif" mode="" class="img"></image>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. loading: false,
  46. moddata: [],
  47. city: "",
  48. selectcityTF: false,
  49. quanxian: {
  50. namealter: false,
  51. cityalter: false,
  52. infoalter: false
  53. }
  54. }
  55. },
  56. methods: {
  57. async eqlistcity(lat, lng) { //修改设备定位
  58. const res = await this.$myRequest({
  59. url: '/api/api_gateway?method=forecast.worm_lamp.revise_device_lnglat',
  60. data: {
  61. device_id: this.moddata.imei,
  62. lat: lat,
  63. lng: lng
  64. }
  65. })
  66. console.log(res)
  67. if (res == false) {
  68. uni.showToast({
  69. title: "修改地址失败",
  70. icon: "none"
  71. })
  72. } else {
  73. uni.showToast({
  74. title: "修改地址成功",
  75. icon: "none"
  76. })
  77. }
  78. },
  79. async eqlistname() { //修改设备名称
  80. const res = await this.$myRequest({
  81. url: '/api/api_gateway?method=forecast.worm_lamp.revise_device',
  82. data: {
  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)
  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.equipmentSubmit()
  129. // this.eqlistcity(this.moddata.lat, this.moddata.lng)
  130. // this.eqlistname()
  131. },
  132. equipmentSubmit() {
  133. if (!this.moddata.lat || !this.moddata.lng || !this.moddata.device_name) {
  134. uni.showToast({
  135. title: "请检查设备名称和设备位置是否填写完毕",
  136. icon: "none"
  137. })
  138. return
  139. }
  140. if (!this.moddata.imei) {
  141. uni.showToast({
  142. title: "未查询到当前设备ID,请刷新后重试!",
  143. icon: "none"
  144. })
  145. return
  146. }
  147. const payload = {
  148. device_id: this.moddata.imei,
  149. device_name: this.moddata.device_name,
  150. lat: this.moddata.lat,
  151. lng: this.moddata.lng
  152. }
  153. console.log(payload,'submit equipment info')
  154. this.$myRequest({
  155. url: '/api/api_gateway?method=forecast.worm_lamp.revise_device_name_lnglat',
  156. data: payload
  157. }).then(res=>{
  158. console.log(res,'-------------------------------------')
  159. if(res == false){
  160. uni.showToast({
  161. title: "修改失败,请稍后再试",
  162. icon: "none"
  163. })
  164. }else{
  165. uni.showToast({
  166. title: "修改成功",
  167. icon: "none"
  168. })
  169. this.clickLeft()
  170. }
  171. })
  172. },
  173. clickLeft() {
  174. uni.navigateBack({
  175. delta: 1
  176. })
  177. },
  178. amendcity() { //修改设备地址
  179. if (this.quanxian.cityalter) {
  180. this.selectcityTF = true
  181. uni.navigateTo({
  182. url: "../fourBase/city"
  183. })
  184. } else {
  185. uni.showToast({
  186. title: "您暂无权限进行此操作,如有需要,请联系管理员",
  187. icon: "none"
  188. })
  189. }
  190. },
  191. selectaddress(lng, lat) { //获取分布位置
  192. uni.request({
  193. type: "GET",
  194. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," + lat +
  195. "&key=78ce288400f4fc6d9458989875c833c2&radius=1000&extensions=all",
  196. dataType: "json",
  197. complete: ress => {
  198. // console.log(ress)
  199. if (ress.data.regeocode.formatted_address.length == 0) {
  200. this.city = "--"
  201. } else {
  202. this.city = ress.data.regeocode.formatted_address
  203. }
  204. }
  205. });
  206. },
  207. },
  208. onLoad(option) {
  209. console.log(option)
  210. if (option.id == 10) {
  211. this.xyeqlistuser(JSON.parse(option.data).device_id)
  212. } else {
  213. this.eqlistuser(option.id, JSON.parse(option.data).imei)
  214. }
  215. uni.getStorage({
  216. key: "jurisdiction",
  217. success: (res) => {
  218. console.log(JSON.parse(res.data))
  219. let items = JSON.parse(res.data).filter((item) => {
  220. return item.purview_name == "设备管理"
  221. })
  222. let items2 = items[0].children.filter((item) => {
  223. return item.purview_name == "设备列表"
  224. })
  225. this.quanxian.namealter = items2[0].children.some((item) => {
  226. return item.purview_name == "修改名称"
  227. })
  228. this.quanxian.cityalter = items2[0].children.some((item) => {
  229. return item.purview_name == "添加位置"
  230. })
  231. this.quanxian.infoalter = items2[0].children.some((item) => {
  232. return item.purview_name == "修改名称" || item.purview_name == "添加位置"
  233. })
  234. },
  235. })
  236. },
  237. onShow() {
  238. uni.getStorage({
  239. key: "location",
  240. success: (res) => {
  241. this.moddata.lat = res.data[1]
  242. this.moddata.lng = res.data[0]
  243. this.selectaddress(this.moddata.lng, this.moddata.lat)
  244. }
  245. })
  246. }
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. .loading {
  251. position: fixed;
  252. top: 0;
  253. left: 0;
  254. right: 0;
  255. bottom: 0;
  256. text-align: center;
  257. .img {
  258. width: 300rpx;
  259. height: 40rpx;
  260. }
  261. }
  262. </style>
  263. <style lang="scss">
  264. page {
  265. background-color: #FAFAFA;
  266. }
  267. .mod {
  268. width: 100%;
  269. padding-top: 30rpx;
  270. .mod_name,
  271. .mod_id,
  272. .mod_user,
  273. .mod_time,
  274. .mod_city {
  275. width: 90%;
  276. margin: 0 auto 30rpx;
  277. display: flex;
  278. justify-content: space-between;
  279. background-color: #FFFFFF;
  280. padding: 20rpx 10rpx;
  281. color: #57C77A;
  282. line-height: 50rpx;
  283. .namebg {
  284. background-color: #FAFAFA;
  285. }
  286. input {
  287. text-align: right;
  288. font-size: 28rpx;
  289. padding: 10rpx;
  290. }
  291. }
  292. }
  293. .sub {
  294. width: 90%;
  295. margin: 30rpx auto;
  296. text-align: center;
  297. height: 70rpx;
  298. line-height: 70rpx;
  299. background-color: #57C77A;
  300. border-radius: 35rpx;
  301. color: #FFFFFF;
  302. }
  303. </style>