city.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <uni-popup class="picker-popup" ref="popupRef" type="bottom" border-radius="10px 10px 0 0">
  3. <div class="picker-content">
  4. <div class="city-picker-btn">
  5. <text @click.stop="cancel()">取消</text>
  6. <text @click.stop="confirm()">确定</text>
  7. </div>
  8. <picker-view indicator-class="indicator-class" :value="value||[]" class="picker-view" @change="bindChange">
  9. <picker-view-column>
  10. <view class="item" v-for="(item,index) in cityList" :key="index">{{item.label}}</view>
  11. </picker-view-column>
  12. </picker-view>
  13. </div>
  14. </uni-popup>
  15. </template>
  16. <script>
  17. import { cityJson } from "./json.js"
  18. export default {
  19. name: "city",
  20. props: {
  21. code: {
  22. type: String | Array,
  23. default: null
  24. }
  25. },
  26. data() {
  27. return {
  28. codeValue: [],
  29. labelValue: '',
  30. value: [0],
  31. // sheng: [cityJson[16]],
  32. // shi: [],
  33. // qu: [],
  34. cityList: cityJson
  35. }
  36. },
  37. watch: {
  38. },
  39. created() {
  40. },
  41. mounted() {
  42. },
  43. methods: {
  44. open() {
  45. this.$refs.popupRef.open()
  46. },
  47. bindChange(val) {
  48. const { value } = val.detail;
  49. // console.log("bindChange = ", value, this.value)
  50. // if (value[0] !== this.value[0]) {
  51. // this.value = [value[0], 0, 0];
  52. // return
  53. // }
  54. // if (value[1] !== this.value[1]) {
  55. // this.value = [value[0], value[1], 0];
  56. // return
  57. // }
  58. this.value = value;
  59. },
  60. confirm() {
  61. console.log("this.value = ", this.value)
  62. const index = this.value[0]
  63. const { value, label } = this.cityList[index];
  64. // value: '420113', label: '汉南区'
  65. this.$emit("update:code", value);
  66. this.$emit("cityName", label);
  67. this.$emit("onConfirm")
  68. this.cancel();
  69. },
  70. cancel() {
  71. this.$refs.popupRef.close()
  72. }
  73. }
  74. }
  75. </script>