change-city.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="change-city">
  3. <view class="change-header">
  4. <view class="header-top u-flex u-row-between">
  5. <view class="top-left u-flex">
  6. <u-icon name="search" color="#B0B0B0"></u-icon>
  7. <input type="text" placeholder="请输入地址" v-model="keyword" confirm-type="search" @confirm="tosearch">
  8. </view>
  9. <text class="quxiao" @click="quxiao">取消</text>
  10. </view>
  11. <view class="header-down u-flex">
  12. <view class="down-item u-flex-col u-col-center u-row-center" :class="{'down-item1' : current == 0}" @click="changeshengfen">
  13. <text>省楼盘</text>
  14. <text></text>
  15. </view>
  16. <view class="down-item u-flex-col u-col-center u-row-center" :class="{'down-item1' : current == 1}">
  17. <text>市楼盘</text>
  18. <text></text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="city-item" v-for="(item,index) in list" :key="index" @click="changitem(item)">
  23. {{item.name}}
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. current: 0,
  32. sheng: [],
  33. shengdata: {},
  34. shi: [],
  35. list: [],
  36. keyword: ''
  37. }
  38. },
  39. onLoad() {
  40. this.getsheng()
  41. },
  42. methods: {
  43. quxiao() {
  44. this.keyword = ''
  45. if (this.current == 0) {
  46. this.list = JSON.parse(JSON.stringify(this.sheng))
  47. } else {
  48. this.list = JSON.parse(JSON.stringify(this.shi))
  49. }
  50. },
  51. tosearch() {
  52. if (this.current == 0) {
  53. if (this.keyword) {
  54. this.list = []
  55. this.sheng.forEach(val => {
  56. if (val.name.indexOf(this.keyword) > -1) {
  57. this.list.push(val)
  58. }
  59. })
  60. } else {
  61. this.list = JSON.parse(JSON.stringify(this.sheng))
  62. }
  63. } else {
  64. if (this.keyword) {
  65. this.list = []
  66. this.shi.forEach(val => {
  67. if (val.name.indexOf(this.keyword) > -1) {
  68. this.list.push(val)
  69. }
  70. })
  71. } else {
  72. this.list = JSON.parse(JSON.stringify(this.shi))
  73. }
  74. }
  75. },
  76. getsheng() {
  77. this.$u.post('/api/Data/area_list', {
  78. level: 1
  79. }).then(res => {
  80. this.sheng = res.data
  81. this.list = res.data
  82. })
  83. },
  84. changitem(item) {
  85. if (this.current == 0) {
  86. this.shengdata = item
  87. uni.showLoading({
  88. mask: true,
  89. title: "请稍后"
  90. })
  91. this.$u.post('/api/Data/area_list', {
  92. level: 2,
  93. province_id: item.id
  94. }).then(res => {
  95. this.list = res.data
  96. this.shi = res.data
  97. this.keyword = ''
  98. this.current = 1
  99. })
  100. } else {
  101. const eventChannel = this.getOpenerEventChannel();
  102. eventChannel.emit('changecity', { sheng: this.shengdata, shi: item });
  103. uni.navigateBack()
  104. }
  105. },
  106. changeshengfen() {
  107. this.current = 0
  108. this.list = JSON.parse(JSON.stringify(this.sheng))
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss">
  114. .change-city {
  115. .city-item {
  116. line-height: 88rpx;
  117. padding: 0 24rpx;
  118. font-size: 28rpx;
  119. font-family: PingFangSC-Regular, PingFang SC;
  120. font-weight: 400;
  121. color: #666666;
  122. border-bottom: 2rpx solid #F5F5F5;
  123. }
  124. .change-header {
  125. position: sticky;
  126. top: 0;
  127. left: 0;
  128. z-index: 10;
  129. width: 750rpx;
  130. height: 188rpx;
  131. background: #FFFFFF;
  132. padding: 0 24rpx;
  133. border-bottom: 12rpx solid #F5F5F5;
  134. .header-down {
  135. .down-item {
  136. margin-right: 60rpx;
  137. text:first-child {
  138. font-size: 28rpx;
  139. font-family: PingFangSC-Regular, PingFang SC;
  140. font-weight: 400;
  141. color: #666666;
  142. }
  143. text:last-child {
  144. width: 84rpx;
  145. height: 8rpx;
  146. border-radius: 6rpx;
  147. margin-top: -12rpx;
  148. position: relative;
  149. z-index: -1;
  150. }
  151. }
  152. .down-item1 {
  153. text:first-child {
  154. font-size: 28rpx;
  155. font-family: PingFangSC-Medium, PingFang SC;
  156. font-weight: 500;
  157. color: #333333;
  158. }
  159. text:last-child {
  160. background: #1677FF;
  161. }
  162. }
  163. }
  164. .header-top {
  165. padding: 20rpx 0;
  166. .quxiao {
  167. font-size: 28rpx;
  168. font-family: PingFangSC-Regular, PingFang SC;
  169. font-weight: 400;
  170. color: #333333;
  171. }
  172. .top-left {
  173. width: 612rpx;
  174. height: 72rpx;
  175. background: #FFFFFF;
  176. border-radius: 20rpx;
  177. border: 2rpx solid #F2F2F2;
  178. padding: 0 22rpx;
  179. input {
  180. flex: 1;
  181. margin-left: 16rpx;
  182. }
  183. }
  184. }
  185. }
  186. }
  187. </style>