choosePlot.vue 6.9 KB

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