machineDetailEdit.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="top">
  3. <view>
  4. <view class="machine-name">机柜名称</view>
  5. <view class="input-box ddflex">
  6. <input placeholder="输入机柜名称"/>
  7. </view>
  8. </view>
  9. <view>
  10. <view class="machine-name">所在地区</view>
  11. <view class="input-box ddflex">
  12. <input v-model="addressObj.name" :disabled="true" class="fflex" placeholder="选择所在地区"/>
  13. <view style="margin-left: 10rpx;" @click="chooseLocation">
  14. <image class="address-icon" src="../../static/pages/images/address-icon2.png"></image>
  15. <view class="address-label">定位</view>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="select-label">
  20. 请选择地址
  21. </view>
  22. <view>
  23. <view class="address-item">
  24. <view class="address-text">{{addressObj.address}}</view>
  25. <view class="address-text2">当前所在区域</view>
  26. </view>
  27. <view class="address-item" v-for="item in addressList" @click="selectAddress(item)">
  28. <view class="address-text">{{item.title}}</view>
  29. <view class="address-text2">{{item.address}}</view>
  30. </view>
  31. </view>
  32. <!-- 保存按钮 -->
  33. <view class="savepadding" style="height: 150rpx;"></view>
  34. <view class="savepadding submit-box">
  35. <view class="submit-btn" @click="jumpUrl('')">
  36. 保存
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. const app = getApp();
  43. const req = require("../../utils/request.js");
  44. // 引入SDK核心类
  45. var QQMapWX = require("../../utils/qqmap.js");
  46. export default {
  47. components: {},
  48. props: {},
  49. data() {
  50. return {
  51. systems: {},
  52. isTop:0,
  53. latitude:28.23529,
  54. longitude:112.93134,
  55. addressObj:{
  56. name:'',
  57. address:''
  58. },
  59. addressList:[]
  60. }
  61. },
  62. onLoad(options) {
  63. // 实例化API核心类
  64. QQMapWX.initMap();
  65. let location={
  66. latitude:this.latitude,
  67. longitude:this.longitude,
  68. }
  69. this.reverseGeocoder(location,true)
  70. },
  71. onShow() {
  72. },
  73. methods: {
  74. jumpUrl(url) {
  75. if (req.isLogins(true)) {
  76. uni.navigateTo({
  77. url: url
  78. })
  79. }
  80. },
  81. chooseLocation() {
  82. var tha = this;
  83. uni.chooseLocation({
  84. success: function(res) {
  85. if (res.name) {
  86. tha.addressObj= res;
  87. tha.reverseGeocoder(res);
  88. console.log('地址数据》》》:', res);
  89. }
  90. }
  91. });
  92. },
  93. reverseGeocoder(location,init) {
  94. QQMapWX.reverseGeocoder(location, data => {
  95. if(init){
  96. this.addressObj.address = data.address
  97. this.addressObj.name = data.formatted_addresses.recommend
  98. }
  99. this.addressList = data.pois
  100. console.log('解析后的地址地址数据:', data);
  101. });
  102. },
  103. // 直接选择地址
  104. selectAddress(item){
  105. this.addressObj.address = item.address
  106. this.addressObj.name = item.title
  107. this.latitude = item.location.lat
  108. this.longitude = item.location.lng
  109. let location={
  110. latitude:this.latitude,
  111. longitude:this.longitude,
  112. }
  113. this.reverseGeocoder(location)
  114. }
  115. },
  116. mounted() {
  117. const systemInfo = uni.getSystemInfoSync();
  118. // px转换到rpx的比例
  119. let pxToRpxScale = 750 / systemInfo.windowWidth;
  120. let systems = {
  121. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  122. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  123. };
  124. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  125. this.systems = systems;
  126. },
  127. onPageScroll: function(e) {
  128. if (e.scrollTop > this.systems.barHeight) {
  129. this.isTop = 1;
  130. } else {
  131. this.isTop = 0;
  132. }
  133. }
  134. }
  135. </script>
  136. <style>
  137. @import "./machineDetailEdit.css";
  138. </style>