choosePlot.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view>
  3. <view class="cu-bar bg-white search " >
  4. <view class="search-form round">
  5. <text class="cuIcon-search"></text>
  6. <input @input="nameInputSearch" placeholder="输入小区名称" placeholder-style="font-size: 28rpx"></input>
  7. </view>
  8. </view>
  9. <view class="bg-gray" style="padding: 12rpx 30rpx;">
  10. <text >当前选择城市:</text>
  11. </view>
  12. <view style="padding:30rpx 30rpx 20rpx 30rpx;border-bottom: 1rpx solid #efefef;display: flex;justify-content: space-between;">
  13. <view class="text-blue">
  14. <text class="cuIcon-location padding-right-10"></text>
  15. <text class="">{{city}}{{county}}</text>
  16. </view>
  17. <view class="cu-btn line-blue sm round" @tap="switchCity">
  18. <text class="cuIcon-refresh padding-right-10"></text>
  19. <text>切换城市</text>
  20. </view>
  21. </view>
  22. <view class="bg-gray" style="padding: 12rpx 30rpx;">
  23. <text >选择小区:</text>
  24. </view>
  25. <view class="nav_section" v-if="residential_list.length>0">
  26. <view v-for="(item, index) in residential_list" :key="index" @tap="jump" :data-id="item.id" :data-name="item.name">
  27. <view class="nav_section_items">
  28. <view class="section_cont">
  29. <view class="section_cont_tel">
  30. <text class="info">{{item.name}}</text>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="default" v-if="residential_list==null || residential_list.length==0">
  37. <image src="http://139.9.103.171:1888/img/image/default_icon.png"></image>
  38. <view>
  39. <text>没有获取到小区信息</text>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. const config = require("../../utils/config.js");
  46. var app = getApp();
  47. export default {
  48. data() {
  49. return {
  50. //location: app.defaultCity,
  51. //county: app.defaultCounty,
  52. //市的名字
  53. city: '',
  54. //区的名字
  55. county: '',
  56. currentCityCode: null,
  57. //选择的当前城市所在的区编号,
  58. residential_list: null,
  59. //小区数据列表
  60. sign: false
  61. };
  62. },
  63. components: {},
  64. props: {},
  65. /**
  66. * 生命周期函数--监听页面加载
  67. */
  68. onLoad: function (options) {
  69. console.log(options)
  70. if(!this.$isEmpty(options.city)&&!this.$isEmpty(options.county)&&!this.$isEmpty(options.currentCityCode)){
  71. this.currentCityCode=options.currentCityCode
  72. this.city=options.city
  73. this.county=options.county
  74. this.getCommunity();
  75. }else{
  76. uni.showLoading({
  77. mask: true,
  78. title: '定位中'
  79. });
  80. this.getLocation();
  81. }
  82. if (options.from_index == 'index') {
  83. this.setData({
  84. sign: true
  85. });
  86. } else {
  87. this.setData({
  88. sign: false
  89. });
  90. }
  91. },
  92. onShow() {
  93. },
  94. methods: {
  95. jump(e) {
  96. let that=this
  97. let id = e.currentTarget.dataset.id;
  98. app.globalData.residentialId=id
  99. let name = e.currentTarget.dataset.name;
  100. if (this.sign) {
  101. //清空全局list
  102. app.globalData.room_list = null;
  103. app.globalData.device_list = null;
  104. uni.setStorageSync('plotName', name);
  105. uni.navigateTo({
  106. url: '/pages/index/index?residential_id=' + id + '&residential_name=' + name
  107. });
  108. } else {
  109. console.log("1111")
  110. uni.navigateTo({
  111. url: '/pages/choosePlot/chooseUnit/chooseUnit?residential_id=' + id + '&residential_name=' + name,
  112. success: function (res) {
  113. },
  114. fail: function (res) {
  115. console.log(res)
  116. },
  117. complete: function (res) {}
  118. });
  119. }
  120. },
  121. //切换城市
  122. switchCity: function () {
  123. //兼容地图插件
  124. app.globalData.city = this.city;
  125. app.globalData.currentCityCode = this.currentCityCode;
  126. app.globalData.county = this.county;
  127. uni.navigateTo({
  128. url: '/pages/switchcity/switchcity'
  129. });
  130. },
  131. getLocation: function () {
  132. //console.log("正在定位城市");
  133. this.setData({
  134. county: ''
  135. });
  136. const that = this;
  137. uni.getLocation({
  138. type: 'wgs84',
  139. success: function (res) {
  140. let latitude = res.latitude;
  141. let longitude = res.longitude;
  142. uni.request({
  143. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`,
  144. success: res => {
  145. uni.hideLoading(); // console.log(res)
  146. console.log(res.data.result.ad_info.city + res.data.result.ad_info.adcode);
  147. that.setData({
  148. city: res.data.result.ad_info.city,
  149. currentCityCode: res.data.result.ad_info.adcode,
  150. //区code 如,越秀区--440104
  151. county: res.data.result.ad_info.district
  152. }); //兼容地图插件
  153. app.globalData.city = res.data.result.ad_info.city;
  154. app.globalData.currentCityCode = res.data.result.ad_info.adcode;
  155. app.globalData.county = res.data.result.ad_info.district; //拉取小区信息
  156. that.getCommunity();
  157. }
  158. });
  159. }
  160. });
  161. },
  162. //根据区编号获取小区列表
  163. getCommunity: function (residential_name) {
  164. let that = this;
  165. let params = {};
  166. params['region_area'] = this.currentCityCode;
  167. params['residential_name'] = residential_name;
  168. let operation = 'estate/getByRegionArea';
  169. app.globalData.postRequest(params, operation, function (res) {
  170. //获取成功
  171. if (res.data.result_code == 1) {
  172. that.setData({
  173. residential_list: res.data.list
  174. });
  175. } else {
  176. app.globalData.oneFailHint(res.data.result_msg);
  177. }
  178. });
  179. },
  180. //输入小区名字联想搜索
  181. nameInputSearch: function (e) {
  182. let residential_name = e.detail.value;
  183. this.getCommunity(residential_name);
  184. } // //小程序 点击搜索 按钮时 事件
  185. // inputSearch(e) {
  186. // console.info("11111111");
  187. // debugger
  188. // },
  189. }
  190. };
  191. </script>
  192. <style>
  193. page{
  194. overflow-y: scroll;
  195. background-color:#FFFFFF
  196. }
  197. input {
  198. text-align: center;
  199. font-size: 32rpx;
  200. padding: 5px;
  201. border-radius:10rpx;
  202. background-color: #fff;
  203. }
  204. .input {
  205. padding: 16rpx;
  206. border-bottom: 1rpx solid #e2e2e2;
  207. }
  208. /* pages/myHome/myHome.wxss */
  209. .nav_section {
  210. width: 100%;
  211. background-color: #FFFFFF;
  212. }
  213. .nav_section_items {
  214. display: flex;
  215. flex-direction: row;
  216. justify-content: space-between;
  217. padding: 30rpx;
  218. border-bottom: 2rpx solid #efefef;
  219. position: relative;
  220. }
  221. .nav_section_items:active {
  222. background: #ddd;
  223. }
  224. .nav_section_items .section_cont view {
  225. overflow: hidden;
  226. text-overflow: ellipsis;
  227. white-space: nowrap;
  228. display: block;
  229. }
  230. .nav_section_items .section_cont .section_cont_sub {
  231. font-size: 30rpx;
  232. line-height: 50rpx;
  233. color: #000;
  234. margin-bottom: 10rpx;
  235. }
  236. .section_cont_tel .info{
  237. width: 500rpx;
  238. overflow: hidden;
  239. white-space: nowrap;
  240. text-overflow: ellipsis;
  241. display: inline-block;
  242. }
  243. .local_city{
  244. padding: 30rpx;
  245. position:relative;
  246. background: #fff;
  247. }
  248. .local_city .changeCity{
  249. padding: 30rpx;
  250. position: absolute;
  251. right: 0rpx;
  252. top: 0;
  253. }
  254. .local_city .icon{
  255. padding: 20rpx;
  256. position: absolute;
  257. left: -36rpx;
  258. top: 50%;
  259. transform: translate(0,-50%);
  260. font-size: 40rpx;
  261. }
  262. .default {
  263. text-align: center;
  264. position: fixed;
  265. left: 50%;
  266. top: 50%;
  267. transform: translate(-50%, -50%);
  268. }
  269. .default image {
  270. width: 128rpx;
  271. height: 128rpx;
  272. display: inline-block;
  273. }
  274. </style>