xlh-picker.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <view>
  3. <uni-forms ref="baseForm" >
  4. <uni-forms-item label="城市" required>
  5. <picker class="addRess" @change="bindPickerChange" @columnchange="pluginclass" :value="pickVal" :range="cityArr"
  6. range-key="AreaName" mode="multiSelector">
  7. <view v-if="pickVal2.length==0">请选择</view>
  8. <view v-else class="uni-input">
  9. <text>{{cityArr[0][pickVal2[0]].AreaName}}</text>
  10. <text>{{cityArr[1][pickVal2[1]].AreaName}}</text>
  11. <text>{{cityArr[2][pickVal2[2]].AreaName}}</text>
  12. </view>
  13. </picker>
  14. </uni-forms-item>
  15. </uni-forms>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. pickVal: [0, 0, 0], // 选择器默认值
  23. pickVal2:[], // 辅助城市名字线索
  24. cityArr: [], // 所有城市
  25. }
  26. },
  27. mounted() {
  28. // 页面初始化
  29. this.loadProvinces()
  30. },
  31. methods: {
  32. loadProvinces() { // 加载省份
  33. uni.request({
  34. url: 'http://test-api.tiananhub.com/api/province/GetListProvince',
  35. method: 'get',
  36. success: async (res) => {
  37. let {
  38. data
  39. } = res.data
  40. console.log(data)
  41. this.cityArr[0] = data
  42. this.loadCities(data[0].AreaId)
  43. this.$forceUpdate()
  44. },
  45. fail: async (res) => {}
  46. })
  47. },
  48. // 请求地级市
  49. loadCities(AreaId) {
  50. uni.request({
  51. url: 'http://test-api.tiananhub.com/api/province/GetListCity',
  52. data: {
  53. AreaId
  54. },
  55. method: 'get',
  56. success: async (res) => {
  57. let {
  58. data
  59. } = res.data
  60. this.cityArr[1] = data
  61. this.loadAreas(data[0].AreaId)
  62. this.$forceUpdate()
  63. },
  64. fail: async (res) => {}
  65. })
  66. },
  67. // 请求县区市
  68. loadAreas(AreaId) {
  69. uni.request({
  70. url: 'http://test-api.tiananhub.com/api/province/GetListCity',
  71. data: {
  72. AreaId
  73. },
  74. method: 'get',
  75. success: async (res) => {
  76. let {
  77. data
  78. } = res.data
  79. this.cityArr[2] = data
  80. this.$forceUpdate()
  81. },
  82. fail: async (res) => {}
  83. })
  84. },
  85. // 确定其他选择的值
  86. bindPickerChange(data) {
  87. this.pickVal=data.target.value;
  88. this.pickVal2=data.target.value;
  89. // 以下拓展区域业务逻辑
  90. },
  91. // 选择时且未点击确定是的值
  92. pluginclass(e) {
  93. console.log('修改的列为:' + e.detail.column + ',值为:' + e.detail.value)
  94. if (e.detail.column == 0) {
  95. this.loadCities(this.cityArr[0][e.detail.value].AreaId);
  96. }
  97. if (e.detail.column == 1) {
  98. this.loadAreas(this.cityArr[1][e.detail.value].AreaId);
  99. }
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. .addRess{
  106. line-height: 80rpx;
  107. }
  108. </style>