index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <div class="container store-page">
  3. <!-- <div class="store-toolbar">
  4. <div class="toolbar">
  5. <div class="item item1" >
  6. <van-search
  7. value="{{ value }}"
  8. placeholder="请输入搜索关键词"
  9. show-action
  10. shape="round"
  11. background="#efefef"
  12. focus
  13. @change="onChange"
  14. @cancel="onCancel"
  15. />
  16. </div>
  17. </div>
  18. </div> -->
  19. <div class="content">
  20. <div class="all-city">
  21. <scroll-view class="city-scroll" scroll-y="true" scroll-with-animation="true" :scroll-into-view="toView">
  22. <div class="city-list">
  23. <div id="gps" class="city-con">
  24. <span @click='selectcity(currentCity)' class="city-box">
  25. <van-icon style="font-size: 14px; color: red;vertical-align: middle;" name="location-o" />
  26. <span >{{currentCity.name}}</span>
  27. </span>
  28. </div>
  29. <div class="city-con" id="hot">
  30. <div class="nav-text">
  31. <span>热门城市</span>
  32. </div>
  33. <div class="hot-list">
  34. <span @click='selectcity(item)' class="city-box" v-for="(item,index) in hotList" :key="index" >{{item.name}}</span>
  35. </div>
  36. </div>
  37. <!-- 循环城市列表 start -->
  38. <div v-for="(item,index) in cityList" :key="index" :id="'city' + item.title" :data-title="item.title">
  39. <div class="nav-text">
  40. <span>{{item.title}}</span>
  41. </div>
  42. <div class="show-city">
  43. <span @click='selectcity(item)' v-for="(item,indexx) in item.lists" :key="indexx" >{{item.name}}</span>
  44. </div>
  45. </div>
  46. <!-- 循环城市列表 end -->
  47. </div>
  48. </scroll-view>
  49. </div>
  50. <!-- 字母索引 start -->
  51. <div class="search-nav" >
  52. <span @click="cityScroll(item)" :data-index="index" v-for="(item,index) in searchNav" :key="index" >{{item}}</span>
  53. </div>
  54. <!-- 字母索引 end -->
  55. </div>
  56. <view v-if="showCon" class="modal-mask" @click="showCon=false">
  57. <view class="modal-dialog">
  58. <view class="modal-title">温馨提示</view>
  59. <view class="modal-content">
  60. 获取定位失败,请前往设置打开定位权限
  61. </view>
  62. <view class="modal-footer">
  63. <view class="btn-cancel" @click="showCon=false">取消</view>
  64. <button open-type="openSetting" class="btn-confirm button-on-view" style="padding:0rpx;" @click="showCon=false">设置</button>
  65. </view>
  66. </view>
  67. </view>
  68. </div>
  69. </template>
  70. <script>
  71. import { listStore, getLookUpData } from '@/api/api';
  72. import NoData from '@/components/NoData';
  73. import storage from '@/utils/storage.js';
  74. import { getListArea } from '@/api/store.js';
  75. import { province, city, area } from '@/api/address.js'
  76. import pinyin from 'pinyin'
  77. export default {
  78. name: 'storeSearch',
  79. components: { 'no-data': NoData },
  80. data() {
  81. return {
  82. showCon: false,
  83. searchVal: '',
  84. // 当前定位城市code name
  85. currentCity: {
  86. code:'',
  87. name:''
  88. },
  89. isfocus: true,
  90. toView:'',//用来做定位联动
  91. searchNav: ["定","热"],
  92. hotList: [
  93. {name:"西安市",code:"6101"},
  94. {name:"咸阳市",code:"6104"},
  95. {name:"渭南市",code:"6105"},
  96. {name:"商洛市",code:"6110"},
  97. {name:"铜川市",code:"6102"},
  98. {name:"兰州市",code:"6201"}
  99. ],
  100. cityList: [],
  101. currentPosition: {
  102. lat: '',
  103. lng: ''
  104. },
  105. };
  106. },
  107. computed: {
  108. },
  109. methods: {
  110. onChange (e) {
  111. this.searchVal = e.mp.detail
  112. console.log(e, "e.detail")
  113. console.log(this.searchVal, "this.searchVal")
  114. },
  115. onCancel () {
  116. wx.navigateBack({
  117. delta: 1
  118. })
  119. },
  120. // 获取已开通城市
  121. getAllCity () {
  122. getListArea({}).then(res => {
  123. console.log(res)
  124. if(res.status == 200){
  125. this.getCityList(res.data)
  126. }
  127. })
  128. },
  129. // 格式化城市列表
  130. getCityList (data){
  131. this.cityList = []
  132. this.searchNav = ["定","热"]
  133. let zmIndex = []
  134. for(let i=0;i<data.length;i++){
  135. let item = data[i]
  136. if(String(item.addrDistrict).length == 4){
  137. // 如果是直辖市
  138. if(item.addrDistrictName == '市辖区'){
  139. //console.log(province)
  140. //console.log(item.addrDistrict)
  141. let b = province.find(k=>{
  142. return k.children[0].value == item.addrDistrict
  143. })
  144. console.log(b)
  145. item.addrDistrictName = b.name
  146. }
  147. let py = pinyin(item.addrDistrictName)
  148. let pyIndex = py[0][0].substr(0,1).toUpperCase()
  149. const hasPy = zmIndex.find(item => {return item == pyIndex})
  150. const hasCity = this.cityList.find(item => {return item.title == pyIndex})
  151. if(!hasPy){
  152. zmIndex.push(pyIndex)
  153. }
  154. // 已存在
  155. if(hasCity){
  156. hasCity.lists.push({ name: item.addrDistrictName , code: item.addrDistrict})
  157. }else{
  158. this.cityList.push({
  159. "title": pyIndex,
  160. "lists":[{ name: item.addrDistrictName , code: item.addrDistrict}]
  161. })
  162. }
  163. }
  164. }
  165. // 缓存数据
  166. //storage.put('cityListData', this.cityList , 5)
  167. // 按字母排序
  168. this.cityList = this.cityList.sort(function(a,b){
  169. return a.title.charCodeAt(0) - b.title.charCodeAt(0)
  170. })
  171. this.searchNav = this.searchNav.concat(zmIndex.sort())
  172. //console.log(this.cityList,'cityList')
  173. //console.log(this.searchNav,'searchNav')
  174. },
  175. // 选择城市
  176. selectcity(data){
  177. wx.reLaunch({
  178. url: `/pages/store/main?code=${data.code}&name=${data.name}`
  179. })
  180. },
  181. // 点击英文字母进行跳转到相应位置
  182. cityScroll(index){
  183. console.log(index, 'eeeee')
  184. if (index == "定") {
  185. this.toView = "gps"
  186. } else if (index == "热"){
  187. this.toView = "hot"
  188. }
  189. this.toView = `city${index}`
  190. console.log(this.toView, 'this.toView')
  191. },
  192. },
  193. onShow() {
  194. this.searchVal = '';
  195. this.isfocus = true
  196. },
  197. onLoad(options) {
  198. console.log(options)
  199. this.currentCity.code = options.code != 'undefined' ? options.code : null
  200. this.currentCity.name = options.name != 'undefined' ? options.name : '未开启'
  201. this.getAllCity()
  202. }
  203. };
  204. </script>
  205. <style lang="stylus">
  206. .modal-mask {
  207. width: 100%;
  208. height: 100%;
  209. position: fixed;
  210. top: 0;
  211. left: 0;
  212. background-color: rgba(0, 0, 0, 0.5);
  213. overflow: hidden;
  214. z-index: 9999;
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. }
  219. .modal-dialog {
  220. width: 540rpx;
  221. overflow: hidden;
  222. z-index: 9999;
  223. background: #f9f9f9;
  224. border-radius: 5rpx;
  225. }
  226. .modal-title {
  227. padding-top: 30rpx;
  228. font-size: 32rpx;
  229. color: #030303;
  230. text-align: center;
  231. }
  232. .modal-content {
  233. padding: 20rpx 32rpx;
  234. font-size: 28rpx;
  235. }
  236. .modal-footer {
  237. display: flex;
  238. flex-direction: row;
  239. height: 86rpx;
  240. border-top: 1px solid #dedede;
  241. font-size: 34rpx;
  242. line-height: 86rpx;
  243. }
  244. .btn-cancel {
  245. width: 50%;
  246. color: #abb4bd;
  247. text-align: center;
  248. border-right: 1px solid #dedede;
  249. }
  250. .btn-confirm {
  251. width: 50%;
  252. color: #6fb64b;
  253. text-align: center;
  254. font-weight: 500;
  255. }
  256. ._v-card .v-card{
  257. border-bottom: 1px solid #eee;
  258. height:auto;
  259. }
  260. .vcard .van-card__img{
  261. border-radius:5px;
  262. }
  263. .container {
  264. height: 100%;
  265. overflow: hidden;
  266. box-sizing: border-box;
  267. padding-top: 30rpx;
  268. }
  269. .store-content {
  270. height: 100%;
  271. box-sizing: border-box;
  272. }
  273. .store-toolbar {
  274. position: fixed;
  275. top: 0;
  276. width: 100%;
  277. box-sizing: border-box;
  278. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  279. background-color: #fff;
  280. z-index: 9;
  281. .toolbar {
  282. display: flex;
  283. justify-content: space-around;
  284. height: 70rpx;
  285. .item {
  286. width: 100%;
  287. border-bottom : 1px solid #d9d9d9;
  288. }
  289. .item1 {
  290. text-align: right;
  291. }
  292. }
  293. }
  294. .city-con{
  295. width :100%;
  296. padding: 5px 0px;
  297. }
  298. .city-box{
  299. width: 80px;
  300. border :1px solid #dfdfdf;
  301. border-radius :5px;
  302. height: 30px;
  303. display: inline-block;
  304. text-align: center;
  305. line-height: 30px;
  306. margin-bottom: 10px;
  307. font-size: 14px;
  308. margin-left :15px;
  309. }
  310. .content{
  311. // margin-top: 90rpx;
  312. width: 100%;
  313. }
  314. .nav-text{
  315. background-color :#efefef;
  316. width :100%;
  317. font-size :16px;
  318. padding :10px 0px;
  319. }
  320. .nav-text span {
  321. margin-left :15px;
  322. }
  323. .hot-list {
  324. width :100%;
  325. padding-top: 10px;
  326. }
  327. .city-scroll {
  328. // left: 15px;
  329. // position: fixed;
  330. height: 100%;
  331. width: 100%;
  332. }
  333. .search-nav{
  334. position: fixed;
  335. top: 140rpx;
  336. bottom: 160rpx;
  337. right: 5rpx;
  338. z-index :99;
  339. display:flex;
  340. flex-direction: column;
  341. }
  342. .search-nav span{
  343. padding : 10px;
  344. text-align: center;
  345. font-size: 24rpx;
  346. }
  347. .show-city{
  348. display: flex;
  349. flex-direction: column;
  350. justify-content: left;
  351. }
  352. .show-city span{
  353. padding :10px 15px
  354. font-size: 28rpx;
  355. }
  356. </style>