app-address-selection.vue 2.0 KB
Newer Older
1 2 3
<template>
    <div class="appAddressSelection">
        <el-cascader
4
            style="width:100%"
5 6 7 8 9 10 11 12 13 14 15 16 17
            :disabled="disabled"
            size ="medium"
            v-model="CurrentVal"
            :options="city">
        </el-cascader>
    </div>
</template>

<script lang='ts'>
import { Component, Vue, Prop, Model, Watch } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
import axios from 'axios';
18
import { cityCode } from './city_code'
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
@Component({})
export default class AppAddressSelection extends Vue {

 /**
   * 传入值
   * @type {any}
   * @memberof AppAddressSelection
   */
  @Prop() public value?:any;

  /**
   * 是否禁用
   * @type {boolean}
   * @memberof AppAddressSelection
   */
  @Prop() public disabled?: boolean;


  /**
   * 当前值
   *
   * @memberof AppAddressSelection
   */
  get CurrentVal() {
        return this.value;
  }

 /**
   * 值变化
   *
   * @memberof AppAddressSelection
   */
  set CurrentVal(val: any) {
      this.$emit("change", val); 
  }

 /**
   * 城市数据
   *
   * @memberof AppAddressSelection
   */
    public city :any = [];

 /**
   * 获取城市数据
   *
   * @memberof AppAddressSelection
   */
    public  getcity() {
68
        this.format(cityCode);
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

    }
    /**
   * 生命周期
   *
   * @memberof AppAddressSelection
   */
    public created() {
        this.getcity();
    }

 /**
   * 数据格式化
   *
   * @memberof AppAddressSelection
   */
    public format(data :any) {
86 87 88 89 90
        let town  = JSON.parse(JSON.stringify(data).replace(/city/g, 'children')) 
        let county = JSON.parse(JSON.stringify(town).replace(/name/g, 'label')) 
        let city = JSON.parse(JSON.stringify(county).replace(/area/g, 'children')) 
        let province = JSON.parse(JSON.stringify(city).replace(/code/g, 'value')) 
        this.city = province;
91 92 93 94 95 96 97 98
    }
    
}
</script>

<style lang='less'>
@import './app-address-selection.less';
</style>