address-popup.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <popup v-model="currentValue">
  3. <view class="addresTitle">
  4. <text @click="currentValue = false">取消</text>
  5. <view>所在地区</view>
  6. <text class="main-text-color" @click="onConfirm">确定</text>
  7. </view>
  8. <z-address :dataList="addressVal" @change="addressChange" :length="length" :force="force"></z-address>
  9. </popup>
  10. </template>
  11. <script>
  12. import Popup from './popup.vue';
  13. import zAddress from './address.vue';
  14. export default {
  15. components: {
  16. Popup,
  17. zAddress
  18. },
  19. props: {
  20. dataList: {
  21. type: Array,
  22. default() {
  23. return [];
  24. }
  25. },
  26. value: {
  27. type: Boolean,
  28. default: false
  29. },
  30. length: {
  31. type: Number,
  32. default: 2
  33. },
  34. force:{
  35. type: Boolean,
  36. default: true
  37. }
  38. },
  39. created() {
  40. if (typeof this.value !== 'undefined') {
  41. this.currentValue = this.value;
  42. }
  43. if (this.dataList instanceof Array) {
  44. this.addressVal = this.dataList;
  45. }
  46. },
  47. watch: {
  48. value(val) {
  49. this.currentValue = val;
  50. },
  51. currentValue(val) {
  52. this.$emit(val ? 'on-show' : 'on-hide');
  53. this.$emit('input', val);
  54. },
  55. dataList(val) {
  56. this.addressVal = val;
  57. }
  58. },
  59. data() {
  60. return {
  61. currentValue: false,
  62. //选出的值
  63. addressVal: []
  64. };
  65. },
  66. methods: {
  67. addressChange(val) {
  68. console.log(val);
  69. this.addressVal = val;
  70. },
  71. onConfirm() {
  72. if (parseInt(this.length) <= this.addressVal.length || !this.force && this.addressVal.length > 0) {
  73. this.currentValue = false;
  74. this.$emit('change', this.addressVal);
  75. } else {
  76. uni.showToast({
  77. title: '请选择',
  78. icon: 'none'
  79. });
  80. }
  81. }
  82. },
  83. mounted() {}
  84. };
  85. </script>
  86. <style scoped>
  87. .addresTitle {
  88. display: flex;
  89. justify-content: space-between;
  90. height: 88upx;
  91. line-height: 88upx;
  92. border-bottom: 2upx solid #ebebeb;
  93. padding: 0 20upx;
  94. background-color: #FFF;
  95. }
  96. .addresTitle view {
  97. font-size: 32upx;
  98. }
  99. .addresTitle text {
  100. width: 80upx;
  101. flex-shrink: 0;
  102. text-align: center;
  103. }
  104. .addresTitle text {
  105. font-size: 28upx;
  106. color: #999;
  107. }
  108. </style>