selectCity.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view v-if="show">
  3. <uv-index-list :index-list="indexList" customNavHeight="100rpx">
  4. <template v-slot:header>
  5. <view class="mlr-m">
  6. <view v-if="location.cityCode" class="flex-gap-m" style="align-items: baseline;">
  7. <view><uv-text text="当前选择的城市:" color="#666" size="13" /></view>
  8. <view><uv-text :text="location.city" size="16" /></view>
  9. </view>
  10. <view class="mtb-m flex-gap-m" style="flex-wrap: wrap;">
  11. <view v-for="(item,index) in hotList" :key="index" class="flex">
  12. <uv-tags :text="item.cityName" bg-color="#f4f4f4" border-color="#f4f4f4" color="#666"
  13. @click="onSelect(item)" />
  14. </view>
  15. </view>
  16. </view>
  17. <!-- <view style="height: 100rpx;width: 750rpx;background-color: #3c9cff;">头部内容</view> -->
  18. </template>
  19. <view v-for="(item, index) in itemArr" :key="index">
  20. <!-- #ifdef APP-NVUE -->
  21. <uv-index-anchor :text="indexList[index]"></uv-index-anchor>
  22. <!-- #endif -->
  23. <uv-index-item>
  24. <!-- #ifndef APP-NVUE -->
  25. <uv-index-anchor :text="indexList[index]"></uv-index-anchor>
  26. <!-- #endif -->
  27. <view class="list-cell" v-for="(cell, key) in item" :key="key" @click="onSelect(cell)">
  28. {{cell.cityName}}
  29. </view>
  30. </uv-index-item>
  31. </view>
  32. </uv-index-list>
  33. </view>
  34. </template>
  35. <script>
  36. import cityList from '@/common/city-list.js'
  37. export default {
  38. props: {
  39. show: {
  40. type: [Boolean, String],
  41. default: false,
  42. }
  43. },
  44. data() {
  45. return {
  46. indexList: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
  47. 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
  48. ],
  49. hotList: [{
  50. "cityName": "全国",
  51. "unicode": 21271,
  52. "oldData": {
  53. "cityCode": "",
  54. "cityName": "全国"
  55. }
  56. }, {
  57. "cityName": "北京",
  58. "unicode": 21271,
  59. "oldData": {
  60. "cityCode": "110100",
  61. "cityName": "北京"
  62. }
  63. }, {
  64. "cityName": "南京市",
  65. "unicode": 21335,
  66. "oldData": {
  67. "cityCode": "320100",
  68. "cityName": "南京市"
  69. }
  70. }, {
  71. "cityName": "上海市",
  72. "unicode": 19978,
  73. "oldData": {
  74. "cityCode": "310100",
  75. "cityName": "上海市"
  76. }
  77. }, {
  78. "cityName": "杭州市",
  79. "unicode": 26477,
  80. "oldData": {
  81. "cityCode": "330100",
  82. "cityName": "杭州市"
  83. }
  84. }, {
  85. "cityName": "深圳市",
  86. "unicode": 28145,
  87. "oldData": {
  88. "cityCode": "440300",
  89. "cityName": "深圳市"
  90. }
  91. }, {
  92. "cityName": "广州市",
  93. "unicode": 24191,
  94. "oldData": {
  95. "cityCode": "440100",
  96. "cityName": "广州市"
  97. }
  98. }, {
  99. "cityName": "桂林市",
  100. "unicode": 26690,
  101. "oldData": {
  102. "cityCode": "450300",
  103. "cityName": "桂林市"
  104. }
  105. }, {
  106. "cityName": "南宁市",
  107. "unicode": 21335,
  108. "oldData": {
  109. "cityCode": "450100",
  110. "cityName": "南宁市"
  111. }
  112. }],
  113. subCateIndex: -1,
  114. location: {
  115. cityCode: '21271',
  116. city: '全国'
  117. }
  118. };
  119. },
  120. onLoad() {
  121. this.location = this.$store.state.location;
  122. },
  123. methods: {
  124. onSelect(item) {
  125. this.$store.commit('setLocation', item);
  126. //uni.$emit('select', item)
  127. }
  128. },
  129. computed: {
  130. itemArr() {
  131. let arr = []
  132. this.indexList.forEach((item, index) => {
  133. arr.push(cityList[index].citys)
  134. })
  135. return arr
  136. }
  137. },
  138. }
  139. </script>
  140. <style lang="scss">
  141. .list-cell {
  142. /* #ifndef APP-PLUS */
  143. display: flex;
  144. box-sizing: border-box;
  145. width: 100%;
  146. /* #endif */
  147. padding: 10px 24rpx;
  148. overflow: hidden;
  149. color: #323233;
  150. font-size: 14px;
  151. line-height: 24px;
  152. background-color: #fff;
  153. }
  154. </style>