choosePlot.vue 9.7 KB

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