linzq-citySelect.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <template>
  2. <div class="wrapper" :style="'top:'+statusBarHeight+'px'">
  3. <div class="header">
  4. <!-- <view class="back_div">
  5. <image class="back_img" @click="back_city()" src="../../static/img/login/logo@2x.png" mode=""></image>
  6. </view> -->
  7. <input class="input" @input="onInput" placeholder="请输入城市中文/拼音/首字母" v-model="searchValue" />
  8. </div>
  9. <scroll-view class="calendar-list" scroll-y="true" :scroll-into-view="scrollIntoId">
  10. <view v-if="disdingwei" id="hot">
  11. <!-- 定位模块 -->
  12. <view class="dingwei">
  13. <view class="dingwei_Tips">
  14. 当前城市
  15. </view>
  16. <view class="dingwei_citytop">
  17. <view class="" style="margin-bottom: 0;">
  18. {{position}}
  19. </view>
  20. <view class="dingweis_div" @click="getWarpweft">
  21. <text>{{po_tips}}</text>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 最近模块 -->
  27. <view class="dingwei vist-list" v-if="Visit.length>=0">
  28. <view class="dingwei_Tips">
  29. 访问记录
  30. </view>
  31. <view class="dingwei_city dingwei_city_zuijin">
  32. <view class="dingwei_city_one toright" v-for="(item,index) in Visit" @click="back_city(item)">
  33. {{item.cityName}}
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 城市列表 -->
  38. <view v-if="searchValue == ''" v-for="(item, index) in list" :id="getId(index)" :key="index">
  39. <view class="letter-header">{{ getId(index) }}</view>
  40. <view class="city-div" v-for="(city, i) in item" :key="i" @click="back_city(city)">
  41. <text class="city">{{ city.cityName }}</text>
  42. </view>
  43. </view>
  44. <!-- 搜索结果 -->
  45. <view class="city-div" v-for="(item, index) in searchList" @click="back_city(item)">
  46. <text class="city">{{ item.cityName }}</text>
  47. </view>
  48. </scroll-view>
  49. <!-- 右侧字母 -->
  50. <view class="letters" v-if="searchValue == ''">
  51. <!-- <view class="letters-item" @click="scrollTo('hot')">最近</view> -->
  52. <view class="letters-item" v-for="item in letter" :key="item" @click="scrollTo(item)">{{ item }}</view>
  53. </view>
  54. <!-- 选中之后字母 -->
  55. <view class="mask" v-if="showMask">
  56. <view class="mask-r">{{selectLetter}}</view>
  57. </view>
  58. </div>
  59. </template>
  60. <script>
  61. import Citys from '../city.js';
  62. export default {
  63. components: {},
  64. props: {},
  65. computed: {
  66. hotCity() {
  67. return Citys.hotCity;
  68. },
  69. citys() {
  70. return Citys.cities;
  71. }
  72. },
  73. data() {
  74. return {
  75. // statusBarHeight: this.statusBarHeight,
  76. statusBarHeight: 45,
  77. ImgUrl: this.ImgUrl,
  78. letter: [],
  79. selectLetter: '',
  80. searchValue: '',
  81. scrollIntoId: '',
  82. list: [],
  83. tId: null,
  84. searchList: [],
  85. showMask: false,
  86. disdingwei: true,
  87. Visit: [], //最近访问
  88. position: '营口',
  89. longitude: '', //经度
  90. latitude: '', //纬度
  91. seconds: 3,
  92. po_tips: '重新定位',
  93. }
  94. },
  95. created() {
  96. //获取存储的最近访问
  97. var that = this
  98. uni.getStorage({
  99. key: 'Visit_key',
  100. success: function(res) {
  101. that.Visit = res.data
  102. }
  103. });
  104. //获取定位 经度纬度
  105. that.getWarpweft()
  106. //获取city.js 的程序字母
  107. var mu = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'w', 'x', 'y',
  108. 'z'
  109. ];
  110. var tmp = [];
  111. for (var i = 0; i < mu.length; i++) {
  112. var item = mu[i];
  113. for (var j = 0; j < this.citys.length; j++) {
  114. var py = this.citys[j].py;
  115. if (py.substring(0, 1) == item) {
  116. if (tmp.indexOf(item) == -1) {
  117. this.list[i] = [this.citys[j]];
  118. tmp.push(item);
  119. this.letter.push(item.toUpperCase());
  120. } else {
  121. this.list[i].push(this.citys[j]);
  122. }
  123. }
  124. }
  125. }
  126. },
  127. methods: {
  128. getId(index) {
  129. return this.letter[index];
  130. },
  131. scrollTo(letter) {
  132. this.showMask = true
  133. this.selectLetter = letter == 'hot' ? '最' : letter
  134. setTimeout(() => {
  135. this.showMask = false
  136. }, 300);
  137. this.scrollIntoId = letter;
  138. },
  139. query(source, text) {
  140. let res = [];
  141. var self = this;
  142. res = source.filter(item => {
  143. const arr = [];
  144. let isHave = false;
  145. Object.keys(item).forEach(prop => {
  146. const itemStr = item[prop];
  147. self.isString(itemStr) &&
  148. itemStr.split(',').forEach(val => {
  149. arr.push(val);
  150. });
  151. });
  152. arr.some(val => {
  153. isHave = new RegExp('^' + text).test(val);
  154. return isHave;
  155. });
  156. return isHave;
  157. });
  158. console.log(JSON.stringify(res));
  159. return res;
  160. },
  161. isString(obj) {
  162. return typeof obj === 'string';
  163. },
  164. onInput(e) {
  165. const value = e.target.value;
  166. console.log(value);
  167. if (value !== '' && this.citys && this.citys.length > 0) {
  168. const queryData = this.query(this.citys, String(value).trim());
  169. this.searchList = queryData;
  170. this.disdingwei = false
  171. } else {
  172. this.searchList = [];
  173. this.disdingwei = true
  174. }
  175. },
  176. back_city(item) {debugger
  177. if (item) {
  178. this.$emit('back_city', item);
  179. //unshift 把数据插入到首位,与push相反
  180. this.Visit.unshift(item)
  181. this.searchValue = "";
  182. this.disdingwei = true
  183. var arr = this.Visit
  184. //数组去重
  185. function distinct(arr) {
  186. let newArr = []
  187. for (let i = 0; i < arr.length; i++) {
  188. if (newArr.indexOf(arr[i]) < 0) {
  189. newArr.push(arr[i])
  190. }
  191. }
  192. return newArr
  193. }
  194. this.Visit = distinct(arr)
  195. debugger
  196. console.log(this.Visit, "---最近访问")
  197. uni.setStorage({
  198. key: 'Visit_key',
  199. data: this.Visit
  200. });
  201. } else {
  202. this.$emit('back_city', 'no');
  203. }
  204. },
  205. getWarpweft() {
  206. var that = this
  207. that.po_tips = '定位中...'
  208. let countdown = setInterval(() => {
  209. that.seconds--;
  210. uni.getLocation({
  211. type: 'gcj02',
  212. success: function(res) {
  213. console.log('当前位置的经度:' + res.longitude);
  214. console.log('当前位置的纬度:' + res.latitude);
  215. that.longitude = res.longitude
  216. that.latitude = res.latitude
  217. that.position = res.address.city
  218. }
  219. });
  220. if (that.seconds <= 0) {
  221. that.seconds = 3
  222. that.po_tips = '重新定位'
  223. clearInterval(countdown);
  224. }
  225. }, 1000);
  226. }
  227. }
  228. };
  229. </script>
  230. <style scoped>
  231. .wrapper {
  232. position: fixed;
  233. z-index: 999999;
  234. /* background: #ffffff; */
  235. height: 100%;
  236. width: 100%;
  237. top: 0px;
  238. left: 0px;
  239. }
  240. .mask {
  241. position: absolute;
  242. bottom: 0upx;
  243. top: 83upx;
  244. left: 0upx;
  245. right: 0upx;
  246. width: 750upx;
  247. display: flex;
  248. justify-content: center;
  249. align-items: center;
  250. background: rgba(0, 0, 0, 0);
  251. }
  252. .mask-r {
  253. height: 120upx;
  254. width: 120upx;
  255. border-radius: 60upx;
  256. display: flex;
  257. background:#22C572;
  258. justify-content: center;
  259. align-items: center;
  260. font-size: 40upx;
  261. color: #FFFFFF
  262. }
  263. .content {
  264. height: 100%;
  265. width: 100%;
  266. /* background-color: #ffffff; */
  267. }
  268. .header {
  269. height: 85upx;
  270. display: flex;
  271. justify-content: center;
  272. align-items: center;
  273. background: white;
  274. }
  275. .back_div {
  276. width: 65upx;
  277. height: 100%;
  278. display: flex;
  279. justify-content: center;
  280. align-items: center;
  281. }
  282. .back_img {
  283. width: 35upx;
  284. height: 35upx;
  285. }
  286. .input {
  287. font-size: 28upx;
  288. width: 90%;
  289. height: 55upx;
  290. border-radius: 40upx;
  291. background-color: #F5F5F5;
  292. padding-left: 20upx;
  293. padding-right: 20upx;
  294. box-sizing: border-box;
  295. }
  296. .title {
  297. font-size: 30upx;
  298. color: white;
  299. }
  300. .show {
  301. left: 0;
  302. width: 100%;
  303. transition: left 0.3s ease;
  304. }
  305. .hide {
  306. left: 100%;
  307. width: 100%;
  308. transition: left 0.3s ease;
  309. }
  310. .title {
  311. font-size: 30upx;
  312. color: white;
  313. }
  314. .calendar-list {
  315. position: absolute;
  316. top: 83upx;
  317. bottom: 0upx;
  318. width: 100%;
  319. /* background-color: #FFFFFF; */
  320. }
  321. .letters {
  322. position: absolute;
  323. right: 30upx;
  324. bottom: 0px;
  325. width: 50upx;
  326. top: 260upx;
  327. color: #333333;
  328. text-align: center;
  329. font-size: 24upx;
  330. }
  331. .letters-item {
  332. margin-bottom: 5upx;
  333. }
  334. .letter-header {
  335. height: 45upx;
  336. font-size: 22upx;
  337. color: #333333;
  338. padding-left: 24upx;
  339. box-sizing: border-box;
  340. display: flex;
  341. align-items: center;
  342. background-color: #ebedef;
  343. }
  344. .city-div {
  345. width: 660upx;
  346. height: 85upx;
  347. margin-left: 24upx;
  348. border-bottom-width: 0.5upx;
  349. border-bottom-color: #ebedef;
  350. border-bottom-style: solid;
  351. display: flex;
  352. align-items: center;
  353. margin-right: 35upx;
  354. }
  355. .city {
  356. font-size: 28upx;
  357. color: #000000;
  358. padding-left: 30upx;
  359. }
  360. .dingwei {
  361. width: 100%;
  362. padding-top: 25upx;
  363. box-sizing: border-box;
  364. /* margin-bottom: 26upx; */
  365. background: reds;
  366. padding-bottom: 20rpx;
  367. }
  368. .dingwei_Tips {
  369. margin-left: 24upx;
  370. margin-bottom: 24upx;
  371. font-size: 24upx;
  372. color: #A5A5A5;
  373. }
  374. .dingwei_city {
  375. width: 100%;
  376. /* height: 60upx; */
  377. /* padding-left: 55upx;
  378. padding-right: 70upx; */
  379. /* box-sizing: border-box;
  380. display: flex;
  381. justify-content: space-between; */
  382. /* width: 25%; */
  383. padding-left: 20rpx;
  384. display: inline-block;
  385. }
  386. .dingwei_city_one {
  387. display: inline-block;
  388. text-align: center;
  389. line-height: 60rpx;
  390. width: 25%;
  391. height: 60rpx;
  392. background: #F5F6F9;
  393. border-radius: 40rpx;
  394. font-size: 24rpx;
  395. color: #333333;
  396. margin-bottom: 20rpx;
  397. }
  398. .dingweis_div {
  399. display: inline-block;
  400. font-size: 24upx;
  401. color: #22C572;
  402. font-weight: 400;
  403. }
  404. .dingweis {
  405. width: 32upx;
  406. height: 32upx;
  407. }
  408. .dingwei_city_zuijin {
  409. /* display: flex;
  410. justify-content: flex-start; */
  411. }
  412. .toright {
  413. margin-right: 30upx;
  414. }
  415. .dingwei_citytop{
  416. /* background: red; */
  417. display: flex;
  418. justify-content: space-between;
  419. align-items: center;
  420. padding: 0 30rpx;
  421. }
  422. #hot{
  423. background:white;
  424. font-size: 28rpx;
  425. padding-bottom: 1rpx;
  426. border-radius: 0 0 30rpx 30rpx;
  427. }
  428. .vist-list{
  429. background: white;
  430. margin-top: 20rpx;
  431. border-radius: 30rpx 30rpx 0 0 ;
  432. }
  433. </style>