Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

107 rader
2.7 KiB

  1. <template>
  2. <view class="">
  3. <l-label :title="title">
  4. <picker mode="multiSelector" @columnchange="bindMultiPickerColumnChange" :value="multiIndex" :range="multiArray" @change="locationChange">
  5. <view class="picker">{{ multiArray[0][multiIndex[0]] }}-{{ multiArray[1][multiIndex[1]] }}-{{ multiArray[2][multiIndex[2]] }}</view>
  6. </picker>
  7. </l-label>
  8. </view>
  9. </template>
  10. <script>
  11. import city from '@/common/js/city.js';
  12. export default {
  13. name: 'location-picker',
  14. props: {
  15. multiIndex: {
  16. type: Array,
  17. default() {
  18. return [0, 0, 0]
  19. },
  20. },
  21. code:{}
  22. },
  23. data() {
  24. return {
  25. title: '省市区',
  26. multiArray: [[], [], []],
  27. codeArr: null
  28. };
  29. },
  30. methods:{
  31. init(){
  32. var _this = this;
  33. //根据code回显
  34. if(this.code != ''){
  35. this.codeArr = this.code.split(',');
  36. this.Feedback(city.cityData, 0);
  37. }
  38. this.cityCl(city.cityData, 0);
  39. this.locationChange()
  40. // console.log(this.code)
  41. // console.log(this.codeArr)
  42. // console.log(this.multiIndex)
  43. },
  44. Feedback(data, num) {
  45. let _this = this;
  46. data.forEach((n, i) => {
  47. if(n.value == _this.codeArr[num]){
  48. _this.multiIndex[num] = i;
  49. if (n.children) {
  50. let number = num + 1;
  51. _this.Feedback(n.children, number);
  52. }
  53. }
  54. });
  55. },
  56. locationChange() {
  57. let province = city.cityData[this.multiIndex[0]];
  58. let citys = province.children[this.multiIndex[1]];
  59. let area = citys.children[this.multiIndex[2]];
  60. // console.log(`province.value , citys.value , area.value`)
  61. this.$emit('input', province.value + ',' + citys.value + ',' + area.value)
  62. this.$emit('change', province.value + ',' + citys.value + ',' + area.value)
  63. },
  64. bindMultiPickerColumnChange: function(e) {
  65. // console.log(e);
  66. // console.log('修改的列为:' + e.detail.column + ',值为:' + e.detail.value);
  67. let _this = this;
  68. this.multiIndex[e.detail.column] = e.detail.value;
  69. if (e.detail.column == 0) {
  70. _this.multiArray[1].length = 0;
  71. _this.multiArray[2].length = 0;
  72. _this.multiIndex[1] = 0;
  73. _this.multiIndex[2] = 0;
  74. this.cityCl(city.cityData[_this.multiIndex[0]].children, 1);
  75. } else if (e.detail.column == 1) {
  76. _this.multiArray[2].length = 0;
  77. _this.multiIndex[2] = 0;
  78. this.cityCl(city.cityData[_this.multiIndex[0]].children[_this.multiIndex[1]].children, 2);
  79. }
  80. this.$forceUpdate();
  81. },
  82. cityCl(data, num) {
  83. let _this = this;
  84. data.forEach((n, i) => {
  85. if (i == _this.multiIndex[num] && n.children) {
  86. let number = num + 1;
  87. _this.cityCl(n.children, number);
  88. }
  89. _this.multiArray[num].push(n.text);
  90. });
  91. },
  92. watch: {
  93. value() {
  94. this.locationChange()
  95. }
  96. }
  97. },
  98. mounted() {
  99. this.init()
  100. }
  101. };
  102. </script>
  103. <style lang="less" scoped></style>