linzq-citySelect.vue 9.7 KB

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