modification.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <view class="modification">
  3. <view class="modification__header">
  4. <u-icon
  5. size="36"
  6. class="arrow-left"
  7. name="arrow-left"
  8. @click="handleBack"
  9. ></u-icon>
  10. 信息修改
  11. </view>
  12. <view class="modification__content">
  13. <view class="modification__content__item">
  14. <view class="modification__content__item__title">
  15. 设备名称
  16. </view>
  17. <view class="modification__content__item__input">
  18. <u-input v-model="moddata.device_name" placeholder="请输入设备名称" clearable class="input" :custom-style="{ 'text-align': 'right' }"></u-input>
  19. </view>
  20. </view>
  21. <view class="modification__content__item">
  22. <view class="modification__content__item__title">
  23. 设备ID
  24. </view>
  25. <view class="modification__content__item__input">
  26. <u-input disabled :value="moddata.imei || moddata.device_id || moddata.id" placeholder="请输入设备ID" clearable class="input" :custom-style="{ 'text-align': 'right' }"></u-input>
  27. </view>
  28. </view>
  29. <view class="modification__content__item">
  30. <view class="modification__content__item__title">
  31. 适配用户
  32. </view>
  33. <view class="modification__content__item__input">
  34. <u-input disabled :value="moddata.real_name || '无'" placeholder="请输入用户名" clearable class="input" :custom-style="{ 'text-align': 'right' }"></u-input>
  35. </view>
  36. </view>
  37. <view class="modification__content__item">
  38. <view class="modification__content__item__title">
  39. 设备位置
  40. </view>
  41. <view class="modification__content__item__input" @click.native="amendcity">
  42. <view class="location-city">{{ city }}</view>
  43. <u-icon name="arrow-right"></u-icon>
  44. </view>
  45. </view>
  46. <view class="modification__content__item">
  47. <view class="modification__content__item__title">
  48. 设备添加时间
  49. </view>
  50. <view class="modification__content__item__input">
  51. <u-input disabled :value="moddata.addtime | timeFormat()" placeholder="请输入设备添加时间" clearable class="input" :custom-style="{ 'text-align': 'right' }"></u-input>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="sub" @click="btn">
  56. 提 交
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. export default {
  62. data() {
  63. return {
  64. moddata: [],
  65. city: "",
  66. selectcityTF: false,
  67. locationCity: "",
  68. locationName: "",
  69. quanxian:{
  70. namealter:false,
  71. cityalter:false,
  72. infoalter:false
  73. }
  74. }
  75. },
  76. methods: {
  77. handleBack() {
  78. uni.navigateBack({
  79. delta: 1
  80. });
  81. },
  82. async eqlistcity(lat, lng) {
  83. const res = await this.$myRequest({
  84. url: '/api/api_gateway?method=forecast.worm_lamp.revise_device',
  85. data: {
  86. device_id: this.moddata.imei || this.moddata.device_id || this.moddata.id,
  87. lat: lat,
  88. lng: lng
  89. }
  90. })
  91. if (!res) {
  92. uni.showToast({
  93. title: '修改地址失败!',
  94. icon: "none"
  95. });
  96. }else{
  97. uni.showToast({
  98. title: '修改地址成功!',
  99. icon: "none"
  100. });
  101. }
  102. },
  103. async eqlistname(lat, lng) {
  104. const res = await this.$myRequest({
  105. url: '/api/api_gateway?method=forecast.worm_lamp.revise_device',
  106. data: {
  107. device_id: this.moddata.imei || this.moddata.device_id || this.moddata.id,
  108. device_name: this.moddata.device_name,
  109. lat: lat,
  110. lng: lng,
  111. }
  112. })
  113. if (!res) {
  114. uni.showToast({
  115. title: '修改名称失败!',
  116. icon: "none"
  117. });
  118. }else{
  119. uni.showToast({
  120. title: '修改名称成功!',
  121. icon: "none"
  122. });
  123. uni.removeStorage({
  124. key: "location"
  125. })
  126. this.clickLeft()
  127. }
  128. },
  129. async eqlistuser(id, imei,device_model) {
  130. const res = await this.$myRequest({
  131. url: '/api/api_gateway?method=forecast.worm_lamp.lamp_list',
  132. data: {
  133. device_type_id: id,
  134. device_id: imei,
  135. device_model: device_model,
  136. }
  137. })
  138. this.moddata = res.data[0]
  139. this.selectaddress(this.moddata.lng, this.moddata.lat)
  140. },
  141. async xyeqlistuser(imei) {
  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. this.moddata = res.data[0]
  149. this.selectaddress(this.moddata.lng, this.moddata.lat)
  150. },
  151. btn() {
  152. this.eqlistname(this.moddata.lat, this.moddata.lng)
  153. },
  154. clickLeft() {
  155. uni.navigateBack({
  156. delta:1,
  157. success:()=>{
  158. uni.$emit('refreshData')
  159. }
  160. })
  161. },
  162. getCity({city}){
  163. if(city.city == undefined){
  164. var add = city
  165. }else if(city.city != undefined){
  166. var add = city.city
  167. }
  168. // chooseLocation 是微信原生页,不进入 uni-app 页面栈,选完会自动回到本页,直接赋值即可
  169. this.city = add
  170. },
  171. selectedCity(city){
  172. this.getCity && this.getCity({city});
  173. },
  174. location(){
  175. let That = this;
  176. uni.chooseLocation({
  177. success(res){
  178. uni.setStorage({
  179. key:"location",
  180. data:[res.longitude,res.latitude]
  181. })
  182. That.city = res && res.address;
  183. That.locationName = res && res.name;
  184. That.selectedCity({city:That.city,name:That.locationName});
  185. },
  186. fail(){
  187. That.locationCity = "定位失败,请点击重试";
  188. That.locationName = "";
  189. }
  190. });
  191. },
  192. amendcity() {
  193. this.location()
  194. },
  195. selectaddress(lng, lat) { //获取分布位置
  196. uni.request({
  197. type: "GET",
  198. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," + lat +
  199. "&key=27273b81090f78759e4057f94474516f&radius=1000&extensions=all",
  200. dataType: "json",
  201. complete: ress => {
  202. if (ress.data.regeocode.formatted_address.length == 0) {
  203. this.city = "--"
  204. } else {
  205. this.city = ress.data.regeocode.formatted_address
  206. }
  207. }
  208. });
  209. },
  210. },
  211. onLoad(option) {
  212. if(option.id == 10){
  213. const data = JSON.parse(option.data)
  214. this.xyeqlistuser(data.device_id || data.id)
  215. }else{
  216. const data = JSON.parse(option.data)
  217. this.eqlistuser(data.type_id, data.imei || data.device_id || data.id,data.device_model)
  218. }
  219. uni.getStorage({
  220. key:"jurisdiction",
  221. success:(res)=>{
  222. if(!res?.data){
  223. return;
  224. }
  225. let items = JSON.parse(res.data).filter((item)=>{
  226. return item.purview_name == "设备管理"
  227. })
  228. let items2 = items[0]?.children?.filter((item)=>{
  229. return item.purview_name == "设备列表"
  230. })
  231. this.quanxian.namealter = items2[0]?.children?.some((item)=>{
  232. return item.purview_name == "修改名称"
  233. })
  234. this.quanxian.cityalter = items2[0]?.children?.some((item)=>{
  235. return item.purview_name == "添加位置"
  236. })
  237. this.quanxian.infoalter = items2[0]?.children?.some((item)=>{
  238. return item.purview_name == "修改名称" || item.purview_name == "添加位置"
  239. })
  240. },
  241. })
  242. },
  243. onShow(){
  244. uni.getStorage({
  245. key: "location",
  246. success: (res) => {
  247. this.moddata.lat = res.data[1]
  248. this.moddata.lng = res.data[0]
  249. this.selectaddress(this.moddata.lng, this.moddata.lat)
  250. }
  251. })
  252. }
  253. }
  254. </script>
  255. <style lang="scss">
  256. page{
  257. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  258. }
  259. .modification{
  260. display: flex;
  261. width: 100%;
  262. height: calc(100vh - 112rpx);
  263. padding-top: 112rpx;
  264. flex-direction: column;
  265. align-items: center;
  266. overflow-y: scroll;
  267. &__header{
  268. width: 100%;
  269. font-size: 28rpx;
  270. color: #042118;
  271. font-family: 'Source Han Sans CN VF';
  272. font-weight: 700;
  273. position: relative;
  274. text-align: center;
  275. .arrow-left {
  276. position: absolute;
  277. left: 32rpx;
  278. margin-right: 12rpx;
  279. }
  280. }
  281. &__content{
  282. width: calc(100% - 64rpx);
  283. margin-top: 32rpx;
  284. background: #ffffff;
  285. border-radius: 16rpx;
  286. padding: 32rpx;
  287. box-sizing: border-box;
  288. }
  289. &__content__item{
  290. display: flex;
  291. width: 100%;
  292. margin-bottom: 32rpx;
  293. justify-content: space-between;
  294. align-items: center;
  295. }
  296. &__content__item__title{
  297. width: 180rpx;
  298. font-size: 28rpx;
  299. color: #333333;
  300. font-family: 'Source Han Sans CN VF';
  301. }
  302. &__content__item__input{
  303. font-size: 26rpx;
  304. color: #042118;
  305. font-family: 'Source Han Sans CN VF';
  306. font-weight: 400;
  307. display:flex;
  308. align-items: center;
  309. .location-city{
  310. font-size: 28rpx;
  311. color:#333333;
  312. }
  313. .u-icon--right{
  314. color:#999999;
  315. margin-left: 12rpx;
  316. }
  317. .input{
  318. font-size: 26rpx;
  319. text-align: right;
  320. width: 100%;
  321. color: #333333;
  322. }
  323. }
  324. .sub {
  325. width: 90%;
  326. margin: 30rpx auto;
  327. text-align: center;
  328. height: 70rpx;
  329. line-height: 70rpx;
  330. background-color: #57C77A;
  331. border-radius: 16rpx;
  332. color: #FFFFFF;
  333. }
  334. }
  335. </style>