modification.vue 7.2 KB

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