chooseCity.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view class="content">
  3. <!-- 城市列表 -->
  4. <scroll-view class="scroll-view" scroll-y scroll-with-animation="true" enable-back-to-top="true"
  5. :scroll-into-view="toIndex" >
  6. <view class="listContent">
  7. <view class="city-list">
  8. <!-- 城市列表 -->
  9. <view v-for="(item, index) in cityData">
  10. <view class="c-title" :id="item['首字母']">{{item['首字母']}}</view>
  11. <view class="item" v-for="(city,index2) in item['城市列表']" @click="selectCity(city)">
  12. {{city.city}}
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </scroll-view>
  18. <!-- 字母列表 -->
  19. <view class="zhimubox">
  20. <view v-for="(item, index) in alphabet">
  21. <view class="alphabet" :class="{select:toIndex == item}" @click="tap(item)">
  22. {{item}}
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. searchValue: '',
  33. cityData: [],
  34. alphabet: [],
  35. toIndex: '', //跳转的索引的字母
  36. searchData:[],
  37. locationCity: {
  38. cityName: '',
  39. cityCode: '',
  40. lng: '',
  41. lat: '',
  42. },
  43. type:'',
  44. id:'',
  45. }
  46. },
  47. onLoad(opt) {
  48. this.type=opt.type
  49. this.id=opt.id
  50. this.getData();
  51. },
  52. onShow() {
  53. /* var nowCity = uni.getStorageSync("locationCity");
  54. if (nowCity) {
  55. this.locationCity = nowCity
  56. } else {
  57. this.getLocation()
  58. } */
  59. this.getData();
  60. },
  61. methods: {
  62. tap(item) {
  63. console.log('字母点击', item);
  64. this.toIndex = item
  65. },
  66. againDingWei() {
  67. console.log('重新定位');
  68. this.getLocation();
  69. },
  70. getLocation() {
  71. const that = this
  72. uni.getLocation({
  73. type: 'wgs84',
  74. success: function(res) {
  75. console.log('定位', res)
  76. that.locationCity.lng = res.longitude
  77. that.locationCity.lat = res.latitude
  78. that.getAdress();
  79. },
  80. fail(err) {
  81. console.log(err)
  82. }
  83. });
  84. },
  85. getAdress() {
  86. // 根据经纬度 逆城市地理编码 获取城市信息
  87. var location = this.locationCity.lng + ',' + this.locationCity.lat
  88. uni.request({
  89. url: 'https://restapi.amap.com/v3/geocode/regeo',
  90. data: {
  91. key: '389a059efa3f499d9145eb84b1c3248d',
  92. location: location,
  93. //location: '117.06533,36.68013',
  94. //types: "190000",
  95. //extensions: "all",
  96. //radius: 100
  97. },
  98. dataType: "json",
  99. success: (res) => {
  100. console.log('定位城市', res);
  101. if(res.data.regeocode){
  102. console.log("城市名称")
  103. console.log(res.data.regeocode.addressComponent.city)
  104. // console.log(res.data.pois[0].cityname)
  105. let cityname = res.data.regeocode.addressComponent.city;
  106. var cityCode = res.data.regeocode.addressComponent.adcode
  107. cityCode = cityCode.slice(0, -2)
  108. cityCode = cityCode + '00'
  109. this.locationCity.cityName = cityname
  110. this.locationCity.cityCode = cityCode
  111. uni.setStorage({
  112. key: 'locationCity',
  113. data: this.locationCity,
  114. success: function() {
  115. console.log('定位城市,保存成功');
  116. }
  117. })
  118. }else{
  119. console.log("接口获取失败")
  120. }
  121. }
  122. });
  123. },
  124. search(val) {
  125. // console.log(val);
  126. this.searchValue = val
  127. this.getData()
  128. },
  129. getData() {
  130. uni.showLoading({
  131. title: '加载中'
  132. })
  133. var params = {
  134. }
  135. if(this.type==2){
  136. //项目商品下单
  137. var url = 'openMall/shop-city-list'
  138. params.id=this.id
  139. }else if(this.type==3){
  140. //板金喷漆
  141. var url = 'openSheetMetalSprayPaint/shop-city-list'
  142. }else if(this.type==1){
  143. //门店列表
  144. var url = 'opencarOwnerHome/shop-city-list'
  145. }else if(this.type==4){
  146. //积分商城
  147. var url = 'openIntegralMall/shop-city-list'
  148. params.id=this.id
  149. }else if(this.type==5){
  150. //集客
  151. var url = 'openHome/shop-city-list'
  152. params.collectingID=this.id
  153. }
  154. this.$http(url, params, 'GET').then(res => {
  155. uni.hideLoading()
  156. if (res.code == 0) {
  157. this.cityData = res.data
  158. var arr = []
  159. this.cityData.forEach((item, index) => {
  160. arr.push(item.首字母)
  161. });
  162. }
  163. this.alphabet = arr
  164. })
  165. },
  166. selectDingCity(locationCity){
  167. console.log('选择了定位城市:', locationCity);
  168. var city={}
  169. city.city = locationCity.cityName
  170. city.code = locationCity.cityCode
  171. uni.setStorage({
  172. key: 'selectCity',
  173. data: city,
  174. success: function() {
  175. console.log('选择了定位城市,保存成功');
  176. }
  177. })
  178. uni.navigateBack({
  179. })
  180. },
  181. selectCity(city) {
  182. console.log('选择的城市:', city);
  183. uni.setStorage({
  184. key: 'selectCity',
  185. data: city,
  186. success: function() {
  187. console.log('选择的城市,保存成功');
  188. }
  189. })
  190. uni.navigateBack({
  191. })
  192. },
  193. },
  194. onPullDownRefresh() {
  195. this.getData()
  196. setTimeout(function() {
  197. uni.stopPullDownRefresh();
  198. }, 1000);
  199. },
  200. }
  201. </script>
  202. <style scoped>
  203. .zhimubox{
  204. position: fixed;
  205. right: 25rpx;
  206. top: 200rpx;
  207. height: 80vh;
  208. overflow-y: scroll;
  209. }
  210. .content {
  211. background: #FFFFFF;
  212. min-height: 100vh;
  213. }
  214. .topView {
  215. background: #FFFFFF;
  216. position: fixed;
  217. width: 100%;
  218. height: 120rpx;
  219. z-index: 99;
  220. }
  221. .searchBoxBg {
  222. width: 100%;
  223. background-color: #FFFFFF;
  224. border-top: 1rpx solid #EEEEEE;
  225. }
  226. .searchBox {
  227. display: flex;
  228. height: 72rpx;
  229. margin: 24rpx;
  230. background-color: #F4F5F7;
  231. border-radius: 36rpx;
  232. }
  233. .scroll-view {
  234. width: 100%;
  235. /* height: calc(100vh - 80rpx); */
  236. height: 100vh;
  237. box-sizing: border-box;
  238. }
  239. .nowArea {
  240. width: 100%;
  241. height: 147rpx;
  242. }
  243. .area {
  244. color: #999999;
  245. font-size: 24rpx;
  246. margin-bottom: 20rpx;
  247. }
  248. .dingwBox {
  249. display: flex;
  250. justify-content: space-between;
  251. }
  252. .dingweiCity {
  253. background-color: #F4F5F7;
  254. border-radius: 49rpx;
  255. width: 140rpx;
  256. height: 64rpx;
  257. text-align: center;
  258. line-height: 64rpx;
  259. font-size: 26rpx;
  260. }
  261. .dingBg {
  262. display: flex;
  263. align-items: center;
  264. color: #3F90F7;
  265. font-size: 26rpx;
  266. }
  267. .icon {
  268. width: 33rpx;
  269. height: 33rpx;
  270. margin-right: 5rpx;
  271. }
  272. .listContent {
  273. display: flex;
  274. justify-content: space-between;
  275. padding: 20rpx 24rpx 20rpx;
  276. }
  277. .city-list {
  278. display: flex;
  279. flex-direction: column;
  280. width: 95%;
  281. }
  282. .c-title {
  283. color: #999999;
  284. font-size: 24rpx;
  285. height: 33rpx;
  286. line-height: 33rpx;
  287. padding-top: 30rpx;
  288. }
  289. .item {
  290. width: 100%;
  291. height: 46rpx;
  292. padding: 30rpx 13rpx;
  293. color: #3C3C3C;
  294. font-size: 28rpx;
  295. border-bottom: 1rpx solid #EEEEEE;
  296. }
  297. .alphabet {
  298. font-size: 22rpx;
  299. font-weight: bold;
  300. color: #999999;
  301. width: 4%;
  302. margin: 2rpx 0;
  303. text-align: center;
  304. padding: 10rpx 20rpx 10rpx 20rpx;
  305. }
  306. .select {
  307. color: #FF4F00;
  308. }
  309. .reach-content{
  310. width: 100%;
  311. height: calc(100vh - 120rpx);
  312. box-sizing: border-box;
  313. padding: 120rpx 24rpx 20rpx;
  314. }
  315. /* 空白页css */
  316. .nodataBox {
  317. text-align: center;
  318. }
  319. .nodataImg {
  320. width: 400rpx;
  321. padding-top: 300rpx;
  322. }
  323. .noTxt {
  324. font-size: 30rpx;
  325. color: #999999;
  326. padding-top: 50rpx;
  327. }
  328. </style>