linzq-citySelect.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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;">
  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. this.Visit.unshift(item)
  183. this.searchValue = "";
  184. this.disdingwei = true
  185. var arr = this.Visit
  186. //数组去重
  187. function distinct(arr) {
  188. let newArr = []
  189. for (let i = 0; i < arr.length; i++) {
  190. if (newArr.indexOf(arr[i]) < 0) {
  191. newArr.push(arr[i])
  192. }
  193. }
  194. return newArr
  195. }
  196. this.Visit = distinct(arr)
  197. console.log(this.Visit, "---最近访问")
  198. uni.setStorage({
  199. key: 'Visit_key',
  200. data: this.Visit
  201. });
  202. } else {
  203. this.$emit('back_city', 'no');
  204. }
  205. },
  206. getWarpweft() {
  207. var that = this
  208. that.po_tips = '定位中...'
  209. let countdown = setInterval(() => {
  210. that.seconds--;
  211. uni.getLocation({
  212. type: 'gcj02',
  213. geocode: true,
  214. success: function(res) {
  215. // console.log('当前位置的经度:' + res.longitude);
  216. // console.log('当前位置的纬度:' + res.latitude);
  217. // console.log(res)
  218. that.positionObj = res;
  219. that.longitude = res.longitude
  220. that.latitude = res.latitude
  221. // that.position = res.address.city
  222. }
  223. });
  224. if (that.seconds <= 0) {
  225. that.seconds = 3
  226. that.po_tips = '重新定位'
  227. clearInterval(countdown);
  228. }
  229. }, 1000);
  230. }
  231. }
  232. };
  233. </script>
  234. <style scoped>
  235. .wrapper {
  236. position: fixed;
  237. z-index: 999999;
  238. /* background: #ffffff; */
  239. height: 100%;
  240. width: 100%;
  241. top: 0px;
  242. left: 0px;
  243. }
  244. .mask {
  245. position: absolute;
  246. bottom: 0upx;
  247. top: 83upx;
  248. left: 0upx;
  249. right: 0upx;
  250. width: 750upx;
  251. display: flex;
  252. justify-content: center;
  253. align-items: center;
  254. background: rgba(0, 0, 0, 0);
  255. }
  256. .mask-r {
  257. height: 120upx;
  258. width: 120upx;
  259. border-radius: 60upx;
  260. display: flex;
  261. background:#22C572;
  262. justify-content: center;
  263. align-items: center;
  264. font-size: 40upx;
  265. color: #FFFFFF
  266. }
  267. .content {
  268. height: 100%;
  269. width: 100%;
  270. /* background-color: #ffffff; */
  271. }
  272. .header {
  273. height: 85upx;
  274. display: flex;
  275. justify-content: center;
  276. align-items: center;
  277. background: white;
  278. }
  279. .back_div {
  280. width: 65upx;
  281. height: 100%;
  282. display: flex;
  283. justify-content: center;
  284. align-items: center;
  285. }
  286. .back_img {
  287. width: 35upx;
  288. height: 35upx;
  289. }
  290. .input {
  291. font-size: 28upx;
  292. width: 90%;
  293. height: 55upx;
  294. border-radius: 40upx;
  295. background-color: #F5F5F5;
  296. padding-left: 20upx;
  297. padding-right: 20upx;
  298. box-sizing: border-box;
  299. }
  300. .title {
  301. font-size: 30upx;
  302. color: white;
  303. }
  304. .show {
  305. left: 0;
  306. width: 100%;
  307. transition: left 0.3s ease;
  308. }
  309. .hide {
  310. left: 100%;
  311. width: 100%;
  312. transition: left 0.3s ease;
  313. }
  314. .title {
  315. font-size: 30upx;
  316. color: white;
  317. }
  318. .calendar-list {
  319. position: absolute;
  320. top: 83upx;
  321. bottom: 0upx;
  322. width: 100%;
  323. /* background-color: #FFFFFF; */
  324. }
  325. .letters {
  326. position: absolute;
  327. right: 30upx;
  328. bottom: 0px;
  329. width: 50upx;
  330. top: 260upx;
  331. color: #333333;
  332. text-align: center;
  333. font-size: 24upx;
  334. }
  335. .letters-item {
  336. margin-bottom: 5upx;
  337. }
  338. .letter-header {
  339. height: 45upx;
  340. font-size: 22upx;
  341. color: #333333;
  342. padding-left: 24upx;
  343. box-sizing: border-box;
  344. display: flex;
  345. align-items: center;
  346. background-color: #ebedef;
  347. }
  348. .city-div {
  349. width: 660upx;
  350. height: 85upx;
  351. margin-left: 24upx;
  352. border-bottom-width: 0.5upx;
  353. border-bottom-color: #ebedef;
  354. border-bottom-style: solid;
  355. display: flex;
  356. align-items: center;
  357. margin-right: 35upx;
  358. }
  359. .city {
  360. font-size: 28upx;
  361. color: #000000;
  362. padding-left: 30upx;
  363. }
  364. .dingwei {
  365. width: 100%;
  366. padding-top: 25upx;
  367. box-sizing: border-box;
  368. /* margin-bottom: 26upx; */
  369. background: reds;
  370. padding-bottom: 20rpx;
  371. }
  372. .dingwei_Tips {
  373. margin-left: 24upx;
  374. margin-bottom: 24upx;
  375. font-size: 24upx;
  376. color: #A5A5A5;
  377. }
  378. .dingwei_city {
  379. width: 100%;
  380. /* height: 60upx; */
  381. /* padding-left: 55upx;
  382. padding-right: 70upx; */
  383. /* box-sizing: border-box;
  384. display: flex;
  385. justify-content: space-between; */
  386. /* width: 25%; */
  387. padding-left: 20rpx;
  388. display: inline-block;
  389. }
  390. .dingwei_city_one {
  391. display: inline-block;
  392. text-align: center;
  393. line-height: 60rpx;
  394. width: 25%;
  395. height: 60rpx;
  396. background: #F5F6F9;
  397. border-radius: 40rpx;
  398. font-size: 24rpx;
  399. color: #333333;
  400. margin-bottom: 20rpx;
  401. }
  402. .dingweis_div {
  403. display: inline-block;
  404. font-size: 24upx;
  405. color: #22C572;
  406. font-weight: 400;
  407. }
  408. .dingweis {
  409. width: 32upx;
  410. height: 32upx;
  411. }
  412. .dingwei_city_zuijin {
  413. /* display: flex;
  414. justify-content: flex-start; */
  415. }
  416. .toright {
  417. margin-right: 30upx;
  418. }
  419. .dingwei_citytop{
  420. /* background: red; */
  421. display: flex;
  422. justify-content: space-between;
  423. align-items: center;
  424. padding: 0 30rpx;
  425. }
  426. #hot{
  427. background:white;
  428. font-size: 28rpx;
  429. padding-bottom: 1rpx;
  430. border-radius: 0 0 30rpx 30rpx;
  431. }
  432. .vist-list{
  433. background: white;
  434. margin-top: 20rpx;
  435. border-radius: 30rpx 30rpx 0 0 ;
  436. }
  437. </style>