city.vue 3.26 KB
<style scoped>
  .address-select {
    margin-bottom: 10px;
    /*margin-left: 5em;
    height: 30px !important;
    overflow: hidden;
    width: 407px !important;
    border: 0px !important;*/

  }
  .address-readonly {
    color: #606f7a;
    background: #E1E1E1 !important;
  }
  .address-select span {
    display: inline-block;
    min-width:27%;
    text-align: right;
  }
  .address-select span:first-child {
    margin-left: 10px;
  }
  select {
    width: 110px;
    height: 32px;
    line-height: 32px;
    border: 0 none;
  }
</style>
<template>
  <div class="address-select address-readonly" v-if="readonly" :style="styles">
    <span :id='id' style='margin-left:5em;'>{{province}}</span>
    <span>{{city}}</span>
    <span>{{area}}</span>
  </div>

  <div class="address-select" v-else :style="styles" :disabled='disabled'>
    <select v-model="province" :style="selectstyle" class="hover-none" :id='id' style='margin-left:5em;' :disabled='disabled'>
      <option v-for="item in areaMap.provinceArray" :value="item">{{item}}</option>
    </select>

    <select v-model="city"  :style="selectstyle" class="hover-none" :disabled='disabled'>
      <option v-for="item in cityArray.sub" :value="item.name">{{item.name}}</option>
    </select>

    <select v-model="area"  :style="selectstyle" class="hover-none" :disabled='disabled'>
      <option v-for="item in areaArray.sub" :value="item.name">{{item.name}}</option>
    </select>

  </div>
</template>
<script>
  module.exports = {
    props: {
      province: {
        type: String,
        twoWay: true,
        default: '请选择'
      },
      city: {
        type: String,
        twoWay: true,
        default: '请选择'
      },
      area: {
        type: String,
        twoWay: true,
        default: '请选择'
      },
      readonly: {
        type: Boolean,
        default: false
      },
      styles:{},
      selectstyle:{},
      classname:{type:String,default:''},
      id:{
        type:String
      },
      hovers:{
        type:String
      },
      disabled:{
        type:Boolean
      }
    },
    data: function () {
      return {
        firstProvinceModified: true,
        firstCityModified: true
      };
    },
    computed: {
      areaMap: function () {
        return this.$store.state.area;
      },
      cityArray: function () {
        if (this.province === '请选择' || !this.province) {
          return {
            sub: []
          };
        }
        return this.areaMap.map[this.province];
      },
      areaArray: function () {
        if (this.province === '请选择' || this.city === '请选择' || !this.province || !this.city) {
          return {
            sub: []
          };
        }
        if (!this.cityArray[this.city]) {
          return {
            sub: []
          };
        }
        return this.cityArray[this.city];
      }
    },
    watch: {
      province: function () {
        if (this.firstProvinceModified) {
          this.firstProvinceModified = false;
        } else {
          this.city = '请选择';
          this.area = '请选择';
        }
      },
      city: function () {
        if (this.firstCityModified) {
          this.firstCityModified = false;
        } else {
          this.area = '请选择';
        }
      }
    }
  };
</script>