index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view>
  3. <u-popup :show="show" round="20rpx" @close="close">
  4. <!-- 标题 -->
  5. <view class="popup-title">
  6. <text class="text" @click="close">取消</text>
  7. <view class="flex"></view>
  8. <text class="text" @click="confirm">确定</text>
  9. </view>
  10. <!-- 城市数据 -->
  11. <picker-view class="picker-view" :indicator-style="indicatorStyle" :value="cityIndex" @change="cityChange">
  12. <picker-view-column>
  13. <view v-for="(item,index) in list" :key="index">
  14. <text class="name">{{item.name}}</text>
  15. </view>
  16. </picker-view-column>
  17. <picker-view-column>
  18. <view v-for="(item,index) in list[cityIndex[0]].children" :key="index">
  19. <text class="name">{{item.name}}</text>
  20. </view>
  21. </picker-view-column>
  22. <picker-view-column>
  23. <view v-for="(item,index) in list[cityIndex[0]].children[cityIndex[1]].children" :key="index">
  24. <text class="name">{{item.name}}</text>
  25. </view>
  26. </picker-view-column>
  27. </picker-view>
  28. </u-popup>
  29. </view>
  30. </template>
  31. <script>
  32. let cityData = require('./cityData.js').pca;
  33. export default {
  34. data() {
  35. return {
  36. show: false,
  37. list: cityData,
  38. cityIndex: [0, 0, 0],
  39. indicatorStyle: `height: 50px;`,
  40. }
  41. },
  42. methods: {
  43. // 显示
  44. showd() {
  45. this.show = true
  46. },
  47. // 确认
  48. confirm(e) {
  49. let current = this.list[this.cityIndex[0]].name + '' + this.list[this.cityIndex[0]].children[this
  50. .cityIndex[1]].name + '' + this.list[this.cityIndex[0]].children[this.cityIndex[1]].children[this
  51. .cityIndex[2]].name;
  52. this.$emit('confirm', this.list[this.cityIndex[0]], this.list[this.cityIndex[0]].children[this
  53. .cityIndex[1]], this.list[this.cityIndex[0]].children[this.cityIndex[1]].children[this
  54. .cityIndex[2]])
  55. this.close();
  56. },
  57. // 滑动
  58. cityChange(e) {
  59. let currentIndex = e.detail.value;
  60. if (currentIndex[0] != this.cityIndex[0]) {
  61. this.cityIndex.splice(0, 3, currentIndex[0], 0, 0);
  62. return;
  63. }
  64. if (currentIndex[1] != this.cityIndex[1]) {
  65. this.cityIndex.splice(1, 2, currentIndex[1], 0);
  66. return;
  67. }
  68. if (currentIndex[2] != this.cityIndex[2]) {
  69. this.cityIndex.splice(2, 1, currentIndex[2]);
  70. return;
  71. }
  72. },
  73. // 取消
  74. close() {
  75. this.show = false
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. // scss混入,为了少写几行#ifndef
  82. @mixin flex($direction: row) {
  83. /* #ifndef APP-NVUE */
  84. display: flex;
  85. /* #endif */
  86. flex-direction: $direction;
  87. }
  88. .picker-view {
  89. height: 500rpx;
  90. .name {
  91. text-align: center;
  92. font-size: 30rpx;
  93. height: 50px;
  94. line-height: 50px;
  95. }
  96. }
  97. .popup-title {
  98. @include flex(row);
  99. align-items: center;
  100. padding: 30rpx;
  101. .text {
  102. color: #3c9cff;
  103. }
  104. .flex {
  105. flex: 1;
  106. }
  107. }
  108. </style>