city.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <uni-popup ref="popupRef" type="bottom" border-radius="10px 10px 0 0">
  3. <!-- :indicator-style="indicatorStyle" -->
  4. <div class="city-box">
  5. <div class="city-picker-btn">
  6. <text @click.stop="cancel()">取消</text>
  7. <text @click.stop="confirm()">确定</text>
  8. </div>
  9. <picker-view indicator-class="indicator-class" :value="value||[]" class="picker-view" @change="bindChange">
  10. <picker-view-column>
  11. <view class="item" v-for="(item,index) in cityList" :key="index">{{item.label}}</view>
  12. </picker-view-column>
  13. </picker-view>
  14. </div>
  15. </uni-popup>
  16. </template>
  17. <script>
  18. import { cityJson } from "./json.js"
  19. export default {
  20. name: "city",
  21. props: {
  22. code: {
  23. type: String | Array,
  24. default: null
  25. }
  26. },
  27. data() {
  28. return {
  29. codeValue: [],
  30. labelValue: '',
  31. value: [0],
  32. // sheng: [cityJson[16]],
  33. // shi: [],
  34. // qu: [],
  35. cityList: cityJson
  36. }
  37. },
  38. watch: {
  39. },
  40. created() {
  41. },
  42. mounted() {
  43. },
  44. methods: {
  45. open() {
  46. this.$refs.popupRef.open()
  47. },
  48. bindChange(val) {
  49. const { value } = val.detail;
  50. // console.log("bindChange = ", value, this.value)
  51. // if (value[0] !== this.value[0]) {
  52. // this.value = [value[0], 0, 0];
  53. // return
  54. // }
  55. // if (value[1] !== this.value[1]) {
  56. // this.value = [value[0], value[1], 0];
  57. // return
  58. // }
  59. this.value = value;
  60. },
  61. confirm() {
  62. console.log("this.value = ", this.value)
  63. const index = this.value[0]
  64. const { value, label } = this.cityList[index];
  65. // value: '420113', label: '汉南区'
  66. this.$emit("update:code", value);
  67. this.$emit("cityName", label);
  68. this.$emit("onConfirm")
  69. this.cancel();
  70. },
  71. cancel() {
  72. this.$refs.popupRef.close()
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .uni-popup {
  79. z-index: 1002;
  80. .city-box {
  81. height: 55vh;
  82. background-color: #fff;
  83. border-radius: 30rpx 30rpx 0 0;
  84. .city-picker-btn {
  85. height: 100rpx;
  86. display: flex;
  87. justify-content: space-between;
  88. align-items: center;
  89. padding: 0 30rpx;
  90. }
  91. .picker-view {
  92. height: calc(100% - 100rpx);
  93. text-align: center;
  94. }
  95. }
  96. }
  97. /deep/ .indicator-class {
  98. height: 100rpx;
  99. }
  100. /deep/ .uni-picker-view-content {
  101. .item {
  102. text-align: center;
  103. line-height: 100rpx;
  104. }
  105. }
  106. </style>