choosePlot.vue 7.0 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. let params={
  143. location:latitude+","+longitude,
  144. key:config.key,
  145. }
  146. let operation = 'miniprogram/ws/geocoder/v1/location';
  147. getApp().globalData.postRequest(params, operation, function (res) {
  148. uni.hideLoading(); // console.log(res)
  149. let info=res.data.result.result.ad_info
  150. that.setData({
  151. city: info.city,
  152. currentCityCode: info.adcode,
  153. //区code 如,越秀区--440104
  154. county: info.district
  155. }); //兼容地图插件
  156. app.globalData.city = info.city;
  157. app.globalData.currentCityCode = info.adcode;
  158. app.globalData.county = info.district; //拉取小区信息
  159. that.getCommunity();
  160. });
  161. }
  162. });
  163. },
  164. //根据区编号获取小区列表
  165. getCommunity: function (residential_name) {
  166. let that = this;
  167. let params = {};
  168. params['region_area'] = this.currentCityCode;
  169. params['residential_name'] = residential_name;
  170. let operation = 'estate/getByRegionArea';
  171. app.globalData.postRequest(params, operation, function (res) {
  172. //获取成功
  173. if (res.data.result_code == 1) {
  174. that.setData({
  175. residential_list: res.data.list
  176. });
  177. } else {
  178. app.globalData.oneFailHint(res.data.result_msg);
  179. }
  180. });
  181. },
  182. //输入小区名字联想搜索
  183. nameInputSearch: function (e) {
  184. let residential_name = e.detail.value;
  185. this.getCommunity(residential_name);
  186. } // //小程序 点击搜索 按钮时 事件
  187. // inputSearch(e) {
  188. // console.info("11111111");
  189. // debugger
  190. // },
  191. }
  192. };
  193. </script>
  194. <style>
  195. page{
  196. overflow-y: scroll;
  197. background-color:#FFFFFF
  198. }
  199. input {
  200. text-align: center;
  201. font-size: 32rpx;
  202. padding: 5px;
  203. border-radius:10rpx;
  204. background-color: #fff;
  205. }
  206. .input {
  207. padding: 16rpx;
  208. border-bottom: 1rpx solid #e2e2e2;
  209. }
  210. /* pages/myHome/myHome.wxss */
  211. .nav_section {
  212. width: 100%;
  213. background-color: #FFFFFF;
  214. }
  215. .nav_section_items {
  216. display: flex;
  217. flex-direction: row;
  218. justify-content: space-between;
  219. padding: 30rpx;
  220. border-bottom: 2rpx solid #efefef;
  221. position: relative;
  222. }
  223. .nav_section_items:active {
  224. background: #ddd;
  225. }
  226. .nav_section_items .section_cont view {
  227. overflow: hidden;
  228. text-overflow: ellipsis;
  229. white-space: nowrap;
  230. display: block;
  231. }
  232. .nav_section_items .section_cont .section_cont_sub {
  233. font-size: 30rpx;
  234. line-height: 50rpx;
  235. color: #000;
  236. margin-bottom: 10rpx;
  237. }
  238. .section_cont_tel .info{
  239. width: 500rpx;
  240. overflow: hidden;
  241. white-space: nowrap;
  242. text-overflow: ellipsis;
  243. display: inline-block;
  244. }
  245. .local_city{
  246. padding: 30rpx;
  247. position:relative;
  248. background: #fff;
  249. }
  250. .local_city .changeCity{
  251. padding: 30rpx;
  252. position: absolute;
  253. right: 0rpx;
  254. top: 0;
  255. }
  256. .local_city .icon{
  257. padding: 20rpx;
  258. position: absolute;
  259. left: -36rpx;
  260. top: 50%;
  261. transform: translate(0,-50%);
  262. font-size: 40rpx;
  263. }
  264. .default {
  265. text-align: center;
  266. position: fixed;
  267. left: 50%;
  268. top: 50%;
  269. transform: translate(-50%, -50%);
  270. }
  271. .default image {
  272. width: 128rpx;
  273. height: 128rpx;
  274. display: inline-block;
  275. }
  276. </style>