<template>
  <div class="auto" style="height:80%">
    <validator name='v'>
        <div v-if="baseinfo.f_user_type=='民用'" >
          <div class="col-sm-4 form-group " v-show="false"
               :class="[$v.f_pcd_id.required ? 'has-error' : 'has-success']">
            <label class="font_normal_body">省&ensp;市&ensp;区</label>
            <input type="text" style="width:41%" v-show="false" v-model="newmodel.f_pcd_id"
            >
            <v-select :value.sync="newmodel.f_pcd_id" :value-single="true"
                      :options='pcdslist' placeholder='请选择'
                      close-on-select search="true"  @change="pcdChange" >
            </v-select>
          </div>

          <div class="col-sm-4 form-group " v-show="false"
               :class="[$v.f_street_id.required ? 'has-error' : 'has-success']">
            <label class="font_normal_body">街道名称</label>
            <input type="text" style="width:41%" v-show="false" v-model="newmodel.f_street_id"
            >
            <v-select :value.sync="newmodel.f_street_id" :value-single="true"
                      :options='streetslist' placeholder='请选择'
                      close-on-select search="true" >
            </v-select>
          </div>

          <div  class="col-sm-4 form-group "
                :class="[$v.f_residential_area_id.required ? 'has-error' : 'has-success']">
            <label class="font_normal_body">小区名称</label>
            <input type="text" style="width:41%" v-show="false" v-model="newmodel.f_residential_area_id"
                   v-validate:f_residential_area_id='{required: true }'>
            <v-select :value.sync="newmodel.f_residential_area_id" :value-single="true"
                      :options='areaslist' placeholder='请选择'
                      @change="areaChange"
                      close-on-select search="true">
            </v-select>
          </div>

          <div  class="col-sm-4 form-group"  :disabled="newmodel.f_address_type!='独院'" >
            <label class="font_normal_body">地址类型</label>
            <input type="text" style="width:41%" v-show="false" v-model="newmodel.f_address_type" >
            <v-select :value.sync="newmodel.f_address_type" :value-single="true"
                      :options='typelist' placeholder='请选择'
                      @change="typechange"
                      close-on-select search="true">
            </v-select>
          </div>
          <div class="col-sm-4 form-group " v-show="false" :class="[$v.slice.required ? 'has-error' : 'has-success']">
            <label class="font_normal_body">片&emsp;&emsp;区</label>
            <input type="text" style="width:60%" class="input_search" v-show="false" v-model="$refs.slice.selectedItems"
                   v-validate:slice='{required: true }'>
            <v-select :value.sync="newmodel.f_slice_area" v-model="newmodel.f_slice_area" :value-single="true"
                      :options='sliceArea' placeholder='片区/管理站' filer-key="name"
                      close-on-select v-ref:slice>
            </v-select>
          </div>
          <div v-if="typeflag" class="col-sm-4 form-group ">
            <label for="f_address" class="font_normal_body">楼&emsp;&emsp;号</label>
            <input type="text" style="width:40%" v-model="newmodel.f_building" class="input_search"
                   placeholder="楼号"/>

            <div>
              <input type="text" style="width:20%" v-model="newmodel.f_building_suffix" :value="newmodel.f_building_suffix" class="input_search"/>
            </div>
          </div>
          <div v-if="typeflag" class="col-sm-4 form-group ">
            <label for="f_address" class="font_normal_body">单&emsp;&emsp;元</label>
            <input type="text" style="width:40%" v-model="newmodel.f_unit" class="input_search" placeholder="单元"/>
            <input type="text" style="width:20%" v-model="newmodel.f_unit_suffix" :value="newmodel.f_unit_suffix" class="input_search"
            />
          </div>
          <div v-if="!typeflag" class="col-sm-4 form-group ">
            <label for="f_address" class="font_normal_body">&nbsp;&nbsp;组&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
            <input type="text" style="width:40%" v-model="newmodel.f_unit" class="input_search" placeholder="组"/>
            <input type="text" style="width:20%" v-model="newmodel.f_unit_suffix" :value="newmodel.f_unit_suffix" class="input_search"
            />
          </div>
          <div v-if="!typeflag" class="col-sm-4 form-group "
               :class="[$v.f_room.required ? 'has-error' : 'has-success']">
            <label for="f_address" class="font_normal_body">&nbsp;&nbsp;号&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
            <input type="text" style="width:40%" v-model="newmodel.f_room" class="input_search" placeholder="号"
                   v-validate:f_room='{required: true }'/>
            <input type="text" style="width:20%" v-model="newmodel.f_room_suffix"  :value="newmodel.f_room_suffix" class="input_search"
            />
          </div>
          <div v-if="typeflag" class="col-sm-4 form-group ">
            <label for="f_address" class="font_normal_body">楼&emsp;&emsp;层</label>
            <input type="text" style="width:40%" v-model="newmodel.f_floor" class="input_search"
                   placeholder="楼层" />
            <input type="text" style="width:20%" v-model="newmodel.f_floor_suffix"  :value="newmodel.f_floor_suffix" class="input_search"
            />
          </div>
          <div v-if="typeflag " class="col-sm-4 form-group "
               :class="[$v.f_room.required ? 'has-error' : 'has-success']">
            <label for="f_address" class="font_normal_body">门&ensp;牌&ensp;号</label>
            <input type="text" style="width:40%" v-model="newmodel.f_room" class="input_search" placeholder="门牌号"
                   v-validate:f_room='{required: true }'/>
            <input type="text" style="width:20%" v-model="newmodel.f_room_suffix"  :value="newmodel.f_room_suffix"  class="input_search"
            />
          </div>

          <div  class="col-sm-12 form-group "
               :class="[$v.f_address.required ? 'has-error' : 'has-success']">
            <label for="f_address" class="font_normal_body">详细地址</label>
            <input type="text" style="width:86%" v-model="addressconcat" class="input_search" placeholder="详细地址"
                   v-validate:f_address='{required: true }'/>
          </div>


        </div>
        <!--批量录入-->
        <div v-if="baseinfo.f_user_type=='非民用'" class="row">
<!--          <div class="col-sm-4 form-group "-->
<!--               :class="[$v.f_pcd_id.required ? 'has-error' : 'has-success']">-->
<!--            <label class="font_normal_body">省&ensp;市&ensp;区</label>-->
<!--            <input type="text" style="width:41%" v-show="false" v-model="model.f_pcd_id"-->
<!--            >-->
<!--            <v-select :value.sync="model.f_pcd_id" :value-single="true"-->
<!--                      :options='pcdslist' placeholder='请选择'-->
<!--                      close-on-select search="true"  @change="pcdChange" >-->
<!--            </v-select>-->
<!--          </div>-->

<!--          <div class="col-sm-4 form-group "-->
<!--               :class="[$v.f_street_id.required ? 'has-error' : 'has-success']">-->
<!--            <label class="font_normal_body">街道名称</label>-->
<!--            <input type="text" style="width:41%" v-show="false" v-model="model.f_street_id"-->
<!--            >-->
<!--            <v-select :value.sync="model.f_street_id" :value-single="true"-->
<!--                      :options='streetslist' placeholder='请选择'-->
<!--                      @change="streetChange"-->
<!--                      close-on-select search="true" >-->
<!--            </v-select>-->
<!--          </div>-->
          <div  class="col-sm-12 form-group "
                :class="[$v.f_corporate_name.required ? 'has-error' : 'has-success']">
            <label for="f_corporate_name" class="font_normal_body">&ensp;单位名称</label>
            <input type="text" style="width:86.5%" v-model="baseinfo.f_corporate_name" class="input_search" placeholder="公司名称"
                   v-validate:f_corporate_name='{required: true }'/>
          </div>
          <div  class="col-sm-12 form-group "
                :class="[$v.f_address1.required ? 'has-error' : 'has-success']">
            <label for="f_address1" class="font_normal_body">&ensp;详细地址</label>
            <input type="text" style="width:86.5%" v-model="newmodel.f_address" class="input_search" placeholder="详细地址"
                   />
          </div>

        </div>
      </div>
    </validator>
  </div>
</template>

<script>
import {HttpResetClass} from 'vue-client'

let getAreaConfig = async function (self) {
  // 获取气价里面的配置
  await self.$getConfig(self, 'UserAddress')
  console.log('原地址配置', self.config)
  console.log('获取地址配置', self.config)
  Object.assign(self.newmodel, self.config)

  self.initdata()
}

export default {
  title: '用户地址添加',
  data () {
    return {
      // 初始化省市区数据
      pcdslist: [],
      // 初始化街道数据
      streetslist: [],
      // 初始化街道数据
      areaslist: [],
      //
      typelist: [{label: '普通地址', value: '普通地址'}, {label: '独院', value: '独院'}],
      config: {
        f_building_suffix: '号楼',
        f_unit_suffix: '单元',
        f_floor_suffix: '层',
        f_room_suffix: '室'
      },
      newmodel: {
        f_address_type: '普通地址',
        f_pcd_id: '',
        f_street_id: '',
        f_residential_area_id: '',
        f_pcd: '',
        f_comments: '',
        f_street: '',
        f_residential_area: '',
        f_slice_area: '',
        f_building: '',
        f_building_start: '',
        f_building_end: '',
        f_building_prefix: '',
        f_building_suffix: '号楼',
        f_unit: '',
        f_unit_start: '',
        f_unit_end: '',
        f_unit_prefix: '',
        f_unit_suffix: '单元',
        f_floor: '',
        f_floor_start: '',
        f_floor_end: '',
        f_floor_prefix: '',
        f_floor_suffix: '层',
        f_room: '',
        f_room_start: '',
        f_room_end: '',
        f_room_prefix: '',
        f_room_suffix: '室',
        // 详细地址
        f_address: '',
        // 单位名称
        f_company: '',
        // 单位地址
        f_company_address: ''
      },
      // 判读是否为单个数据录入
      onedata: 'one',
      // 选中所有地址
      addresslist: [],
      usertype: true,

      // 公司信息
      curorgid: [this.$login.f.orgid],

      f_orgid: '',

      sliceArea: [],
      typeflag: true // 根据地址类型改变显示的值
    }
  },
  props: ['f_filialeids', 'model', 'baseinfo'],
  ready () {
    getAreaConfig(this)
  },
  methods: {
    concatdata () {
      if (this.model) {
        this.newmodel = Object.assign(this.newmodel, this.model)
      }
      this.$resetValidation()
    },
    typechange () {
      // if(this.model.f_address_type == null || this.model.f_address_type==''){
      //   this.model.f_address_type = '普通地址'
      // }
      // this.model = Object.assign(this.newmodel,this.model)
      if (this.newmodel.f_address_type == '普通地址') {
        this.typeflag = true
        if (this.model.f_building_suffix && this.model.f_building_suffix != '') {
          this.newmodel.f_building_suffix = this.model.f_building_suffix
        } else {
          this.newmodel.f_building_suffix = this.config.f_building_suffix
        }
        if (this.model.f_unit_suffix && this.model.f_unit_suffix != '') {
          this.newmodel.f_unit_suffix = this.model.f_unit_suffix
        } else {
          this.newmodel.f_unit_suffix = this.config.f_unit_suffix
        }
        if (this.model.f_room_suffix && this.model.f_room_suffix != '') {
          this.newmodel.f_room_suffix = this.model.f_room_suffix
        } else {
          this.newmodel.f_room_suffix = this.config.f_room_suffix
        }
        // Object.assign(this.model, this.config);
      } else if (this.newmodel.f_address_type == '独院') {
        this.typeflag = false
        this.newmodel.f_building_suffix = ''
        this.newmodel.f_building = ''
        this.newmodel.f_unit_suffix = '组'
        this.newmodel.f_room_suffix = '号'
      }
    },
    async initdata () {
      this.newmodel.f_address_state = '已通气'
      this.initAreas(this.f_filialeids)
      // 添加特殊地址选省市区

      this.initpcds(` f_orgid = '${this.f_filialeids}'`)
      this.initstreets(` f_orgid = '${this.f_filialeids}' `)
      this.initareas(` f_orgid = '${this.f_filialeids}'`)
    },

    async initAreas (val) {
      if (val) {
        let getAllArea = await this.$resetpost('/rs/search', {
          source: 'this.getParentByType($organization$).getAllChildrens().where(row.getType() == $zone$)',
          userid: this.$login.f.id
        }, {resolveMsg: null, rejectMsg: '获取片区出错！！！'})

        let arr = getAllArea.data.filter((res) => {
          return res.parentid == val
        })
        console.log('过滤之后的片区', arr)
        this.sliceArea = []
        arr.forEach((res) => {
          this.sliceArea.push({label: res.name, value: res.name})
        })
      }
    },
    // 初始化省市区,添加街道
    async initpcds (pconditon) {
      this.pcdslist = []
      let HttpReset = new HttpResetClass()
      let req = await HttpReset.load('POST', 'rs/sql/address_singleTableOrderBy?pageNo=1&pageSize=9999999', {
        data: {
          items: '*',
          tablename: 't_pcd',
          orderitem: 'id',
          condition: pconditon
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
      let redata = []
      req.data.forEach((row, n) => {
        redata[n] = {
          label: row.f_pcd,
          value: row.id,
          data: row,
          id: row.id
        }
      })
      this.pcdslist = redata
    },
    // 初始化街道 添加小区
    async initstreets (pconditon) {
      this.streetslist = []
      let HttpReset = new HttpResetClass()
      let req = await HttpReset.load('POST', 'rs/sql/address_singleTableOrderBy', {
        data: {
          items: '*',
          tablename: 't_street',
          orderitem: 'id',
          condition: pconditon
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
      let redata = []
      req.data.forEach((row, n) => {
        redata[n] = {
          label: row.f_street,
          value: row.id,
          data: row,
          id: row.id
        }
      })
      this.streetslist = redata
    },
    // 初始化小区添加小区
    async initareas (pconditon) {
      // if(this.usertype){
      //   pconditon=pconditon+` and  f_special='1' `
      // }
      this.areaslist = []
      let HttpReset = new HttpResetClass()
      let req = await HttpReset.load('POST', 'rs/sql/address_singleTableOrderBy?pageNo=1&pageSize=9999999', {
        data: {
          items: '*',
          tablename: 't_area',
          orderitem: 'id',
          condition: pconditon
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
      let redata = []
      req.data.forEach((row) => {
        redata.push({
          label: row.f_residential_area,
          value: row.id,
          data: row,
          id: row.id
        })
      })
      this.areaslist = redata
    },
    // 省/市/区变化
    async pcdChange (val) {
      // 只有添加特殊地址时才级联
      if (this.onedata == 'more') {
        return
      }
      console.log('省/市/区变化', val)
      if (val) {
        // 那就把[小区，街道]重新组织一下
        // await this.initstreets(`  f_pcd_id ='${val}' `)
        if (this.newmodel.f_street_id) {
          if (this.findbyid(this.streetslist, this.newmodel.f_street_id)) {
            let pcd_id = this.findbyid(this.streetslist, this.newmodel.f_street_id).f_pcd_id
            if (pcd_id != val) {
              this.newmodel.f_street_id = ''
            }
          } else {
            this.newmodel.f_street_id = ''
          }

          // 那就把[小区，街道]重新组织一下
          if (this.newmodel.f_street_id) {
            // await this.initareas(` f_street_id ='${this.model.f_street_id}' `)
            if (this.newmodel.f_residential_area_id) {
              if (this.findbyid(this.areaslist, this.newmodel.f_residential_area_id)) {
                let pcd_id = this.findbyid(this.areaslist, this.newmodel.f_residential_area_id).f_pcd_id
                if (pcd_id != val) {
                  this.newmodel.f_residential_area_id = ''
                }
              } else {
                this.newmodel.f_residential_area_id = ''
              }
            }
          }
        }
      }
      this.$resetValidation()
    },
    // 小区变化
    areaChange (val) {
      console.log('小区变化', val)
      // 选择小区后级联出省市区和街道
      let selectArea // 选中的小区数据
      for (let row of this.areaslist) {
        if (val == row.value) {
          selectArea = row.data
          break
        }
      }
      if (selectArea) {
        this.newmodel.f_street_id = selectArea.f_street_id
        this.newmodel.f_pcd_id = selectArea.f_pcd_id
        this.initstreets(` f_filialeid = '${this.f_filialeids}' and id ='${selectArea.f_street_id}' `)
        this.initpcds(` f_filialeid = '${this.f_filialeids}' and id ='${selectArea.f_pcd_id}' `)
        this.newmodel.f_slice_area = [{name: selectArea.f_slice_area, code: selectArea.f_area_code}]
        // 拼接地址
        this.$set('newmodel.f_street', selectArea.f_street)
        this.$set('newmodel.f_residential_area', selectArea.f_residential_area)
        // this.newmodel.f_address = `${selectArea.f_residential_area}`
      }
      this.$nextTick(() => {
        this.$resetValidation()
      })
    },
    // 街道变化
    async streetChange (val) {
      console.log('街道变化', val)
      if (this.streetslist[0]) {
        var street = ''
        this.streetslist.forEach((item) => {
          if (item.id === val) {
            street = item.label
          }
        })
        this.newmodel.f_address = street
      }
      if (val) {
        // 那就把[小区]重新组织一下
        // await this.initareas(` f_street_id ='${val}' `)
        if (this.newmodel.f_residential_area_id) {
          if (this.findbyid(this.areaslist, this.newmodel.f_residential_area_id)) {
            let street_id = this.findbyid(this.areaslist, this.newmodel.f_residential_area_id).f_street_id
            if (street_id != val) {
              this.newmodel.f_residential_area_id = ''
            }
          } else {
            this.newmodel.f_residential_area_id = ''
          }
        }
      }
      this.$resetValidation()
    },

    getorg (val) {
      this.f_orgid = val[0]
    },

    // 处理批量地址信息
    dealaddlist () {
      try {
        var resultlist = []
        for (var i = parseInt(this.newmodel.f_building_start); i <= parseInt(this.newmodel.f_building_end); i++) {
          for (var j = parseInt(this.newmodel.f_unit_start); j <= parseInt(this.newmodel.f_unit_end); j++) {
            for (var m = parseInt(this.newmodel.f_floor_start); m <= parseInt(this.newmodel.f_floor_end); m++) {
              for (var n = parseInt(this.newmodel.f_room_start); n <= parseInt(this.newmodel.f_room_end); n++) {
                // 预备一个空的json
                console.log('批量', this.newmodel)
                let data = Object.assign({}, this.newmodel)
                data.f_create_person = this.$login.f.name
                data.f_building = data.f_building_prefix + i
                data.f_unit = data.f_unit_prefix + j
                data.f_floor = data.f_floor_prefix + m
                // 目前房号都按两位处理 如： 101室 201室 110室
                if ((n + '').length == 1) {
                  data.f_room = data.f_room_prefix + m + '0' + n
                } else {
                  data.f_room = data.f_room_prefix + m + '' + n
                }
                data.f_filialeid = this.f_filialeids
                data.f_operator = this.$login.f.name
                data.f_operatorid = this.$login.f.id
                data.f_orgid = this.$login.f.orgid
                data.f_orgname = this.$login.f.orgs
                data.f_depid = this.$login.f.depids
                data.f_depname = this.$login.f.deps
                data.f_pcd = this.findbyid(this.pcdslist, this.newmodel.f_pcd_id).f_pcd
                data.f_street = this.findbyid(this.streetslist, this.newmodel.f_street_id).f_street
                data.f_residential_area = this.findbyid(this.areaslist, this.newmodel.f_residential_area_id).f_residential_area
                data.f_address = data.f_street +
                  data.f_residential_area +
                  data.f_building + data.f_building_suffix +
                  data.f_unit + data.f_unit_suffix +
                  data.f_floor + data.f_floor_suffix +
                  data.f_room + data.f_room_suffix
                if (this.newmodel.slice_area) {
                  if (this.newmodel.slice_area.length > 0) {
                    data.f_slice_area = this.newmodel.slice_area[0].name
                    data.f_area_code = this.newmodel.slice_area[0].code
                  }
                }
                resultlist.push(data)
              }
            }
          }
        }
        this.addresslist = resultlist
      } catch (e) {
        console.log(e)
        this.$showAlert('输出数据有误，请检查', 'warning', 2000)
      }
    },
    // 保存多个
    async confirmall () {
      this.dealaddlist()
      if (this.addresslist.length > 0) {
        let msg = {
          resolveMsg: '地址保存成功',
          rejectMsg: '地址保存失败'
        }
        this.$showMessage('确定要批量添加' + this.addresslist.length + '户地址吗？，如有已经存在的，将会重复添加！！！', ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            this.$resetpost('rs/logic/address_adduserlist', {data: {addlist: this.addresslist}}, msg).then((req) => {
              this.cleardara()
              this.$dispatch('confirm')
            })
          }
        })
      }
    },
    // 保存
    async confirm () {
      if (this.onedata == 'one') {
        await this.saveonedata()
      }
      this.cleardara()
      this.$dispatch('confirm')
    },
    // 保存一户信息
    async saveonedata () {
      this.newmodel.f_create_person = this.$login.f.name
      this.newmodel.f_filialeid = this.f_filialeids
      this.newmodel.f_operator = this.$login.f.name
      this.newmodel.f_operatorid = this.$login.f.id
      this.newmodel.f_orgid = this.$login.f.orgid
      this.newmodel.f_orgname = this.$login.f.orgs
      this.newmodel.f_depid = this.$login.f.depids
      this.newmodel.f_depname = this.$login.f.deps
      if (this.newmodel.slice_area) {
        if (this.newmodel.slice_area.length > 0) {
          this.newmodel.f_slice_area = this.newmodel.slice_area[0].name
          this.newmodel.f_area_code = this.newmodel.slice_area[0].code
        }
      }
      if (this.usertype) {
        // 非民用
        this.newmodel.f_special = '1'
        this.newmodel.f_building_suffix = ''
        this.newmodel.f_unit_suffix = ''
        this.newmodel.f_floor_suffix = ''
        this.newmodel.f_room_suffix = ''
        this.newmodel.f_pcd = this.findbyid(this.pcdslist, this.newmodel.f_pcd_id).f_pcd
        this.newmodel.f_street = this.findbyid(this.streetslist, this.newmodel.f_street_id).f_street
        this.newmodel.f_residential_area = this.findbyid(this.areaslist, this.newmodel.f_residential_area_id) ? this.findbyid(this.areaslist, this.newmodel.f_residential_area_id).f_residential_area : ''
      } else {
        // 民用
        // 当是挺院时,并且是添加时,单元变为组
        if (this.newmodel.f_address_type == '独院') {
          this.newmodel.f_pcd = this.findbyid(this.pcdslist, this.newmodel.f_pcd_id).f_pcd
          this.newmodel.f_street = this.findbyid(this.streetslist, this.newmodel.f_street_id).f_street
          this.newmodel.f_residential_area = this.findbyid(this.areaslist, this.newmodel.f_residential_area_id).f_residential_area
          this.newmodel.f_unit_suffix = '组'
          this.newmodel.f_room_suffix = '号'
          this.newmodel.f_address = this.newmodel.f_residential_area + (this.newmodel.f_unit ? this.newmodel.f_unit + this.newmodel.f_unit_suffix : '') + this.newmodel.f_address_type + this.newmodel.f_room + this.newmodel.f_room_suffix
        } else {
          this.newmodel.f_pcd = this.findbyid(this.pcdslist, this.newmodel.f_pcd_id).f_pcd
          this.newmodel.f_street = this.findbyid(this.streetslist, this.newmodel.f_street_id).f_street
          this.newmodel.f_residential_area = this.findbyid(this.areaslist, this.newmodel.f_residential_area_id).f_residential_area
          this.newmodel.f_address = this.newmodel.f_residential_area + (this.newmodel.f_building ? this.newmodel.f_building + this.newmodel.f_building_suffix : '') + (this.newmodel.f_unit ? this.newmodel.f_unit + this.newmodel.f_unit_suffix : '') + (this.newmodel.f_floor ? this.newmodel.f_floor + this.newmodel.f_floor_suffix : '') + this.newmodel.f_room + this.newmodel.f_room_suffix
        }
      }
      await this.$resetpost('rs/logic/address_updateuseraddress', this.newmodel)
    },
    cancel () {
      this.cleardara()
      this.$dispatch('cancel')
    },
    cleardara () {
      this.newmodel = {
        f_address_type: '普通地址',
        f_pcd_id: '',
        f_street_id: '',
        f_residential_area_id: '',
        f_pcd: '',
        f_comments: '',
        f_street: '',
        f_residential_area: '',
        f_slice_area: '',
        f_building: '',
        f_building_start: '',
        f_building_end: '',
        f_building_prefix: '',
        f_building_suffix: this.config.f_building_suffix,
        f_unit: '',
        f_unit_start: '',
        f_unit_end: '',
        f_unit_prefix: '',
        f_unit_suffix: this.config.f_unit_suffix,
        f_floor: '',
        f_floor_start: '',
        f_floor_end: '',
        f_floor_prefix: '',
        f_floor_suffix: this.config.f_floor_suffix,
        f_room: '',
        f_room_start: '',
        f_room_end: '',
        f_room_prefix: '',
        f_room_suffix: this.config.f_room_suffix,
        // 详细地址
        f_address: '',
        // 单位名称
        f_company: '',
        // 单位地址
        f_company_address: ''
      }
    },

    // 根据名字找数据
    findbyid (list, name) {
      var result
      list.forEach((row, n) => {
        if (name == row.value) {
          result = row.data
        }
      })
      return result
    }
  },
  watch: {
    // 分公司变化
    'f_filialeids' () {
      if (this.newmodel.f_filialeid) {
        if (this.newmodel.f_filialeid != this.f_filialeids) {
          this.$dispatch('cancel')
        }
      }
      this.cleardara()
      this.initdata()
    },
    'row' () {
      this.onedata = 'one'
    },
    'model' () {
      this.initdata()
      this.concatdata()
    }
  },
  computed: {
    addressconcat () {
      let resultaddress = ''
      let oldaddress = this.newmodel.f_address
      if (this.baseinfo.f_user_type = '民用') {
        this.newmodel.f_address = `${this.newmodel.f_residential_area ? this.newmodel.f_residential_area : ''}`
        this.newmodel.f_address = `${this.newmodel.f_address ? this.newmodel.f_address : ''}${this.newmodel.f_building ? this.newmodel.f_building + this.newmodel.f_building_suffix : ''}${this.newmodel.f_unit ? this.newmodel.f_unit + this.newmodel.f_unit_suffix : ''}${this.newmodel.f_floor ? this.newmodel.f_floor + this.newmodel.f_floor_suffix : ''}${this.newmodel.f_room ? this.newmodel.f_room + this.newmodel.f_room_suffix : ''}`
      }
      if (this.newmodel.f_address == '') {
        this.newmodel.f_address = oldaddress
      }
      resultaddress = this.newmodel.f_address
      return resultaddress
    },
    // 地址状态下拉框
    addresstate () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('地址状态')]
    }
  }
}
</script>
