modification.vue 7.2 KB

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