en-data-picker.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view class="">
  3. <uni-data-picker style="z-index: 10;" :popup-title="title" :localdata="localData" v-model="dataValue"
  4. @change="onChange">
  5. <slot></slot>
  6. </uni-data-picker>
  7. </view>
  8. </template>
  9. <script>
  10. import {
  11. getRegion
  12. } from "@/api/common";
  13. export default {
  14. props: {
  15. title: {
  16. type: String,
  17. default: '请选择所在城市'
  18. },
  19. },
  20. data() {
  21. return {
  22. localData: [],
  23. }
  24. },
  25. created() {
  26. this.onGetRegion()
  27. },
  28. methods: {
  29. onGetRegion() {
  30. let localData = uni.getStorageSync('sysCityData')
  31. if (!localData) {
  32. getRegion({
  33. type: 1
  34. }).then((res) => {
  35. if (res.code === 1) {
  36. this.localData = res.data;
  37. uni.setStorageSync('sysCityData', JSON.stringify(this.localData))
  38. } else {
  39. tools.error(res.msg);
  40. }
  41. })
  42. } else {
  43. this.localData = JSON.parse(localData)
  44. }
  45. },
  46. onChange(e) {
  47. const address = e.detail.value.map(item => {
  48. return item.text
  49. })
  50. this.$emit('onChange', address.join("/"))
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. </style>