<template>
  <div>
    <tabset v-ref:tabs :close="false" style="height: 450px;">
      <tab header='公告信息'>
        <user-notice-essentiallion-info :baseinfo="data.baseinfo" :old-address="oldAddress" @valid="essentialInfo = true"
                             @invalid="essentialInfo = false" v-ref:usernoticeessential></user-notice-essentiallion-info>
      </tab>
    </tabset>
    <div class="form-horizontal auto">
      <div class="form-group">
        <div class="col-sm-offset-9 col-sm-3">
          <button type="button" class="btn btn-success" @click="confirm()"
                  :disabled="!(essentialInfo && meterInfo && addressInfo)">
            保存
          </button>
          <button type="button" class="btn btn-default" @click="cancel()">
            取消
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    title: '综合信息',
    props: ['row', 'areainfo'],
    data () {
      return {
        data: {
          baseinfo: {
            base: {
              f_title: '',
              f_date: '',
              f_enddate: '',
              f_state: '',
              f_explain: ''
            }
          }
        },

        // 子组件验证
        essentialInfo: false,
        meterInfo: false,
        addressInfo: false,

        // 地址相关属性
        params: {
          areas: [],
          f_street: [],
          f_residential_area: []
        },

        blodid: '' // 附件的临时id
      }
    },
    ready () {
      this.blodid = '临时id' + Date.now()
      console.log('ready，，，', this.row, this.areainfo)
      if (this.row && !this.areainfo) { // 修改用户
        this.areaGen(this.row)
      } else if (!this.row && this.areainfo) { // 小区批量建档
        // 将小区信息转化为综合信息的格式
        this.areainfoInUser(this.areainfo)
      }
    },
    watch: {
      'row' (val) {
        console.log('观察row', val)
        if (val) {
          this.areaGen(val)
        } else {
          this.areainfoInUser(this.areainfo)
        }
      },
      'areainfo' (val) {
        console.log('小区观察。。', val)
        if (val) {
          this.$refs.meter.clearMeter()
          this.blodid = '临时id' + Date.now()
          this.areainfoInUser(val)
        }
      }
    },
    methods: {
      confirm () {
        this.data.addressinfo.f_address = this.$refs.useraddress.address
        console.log('公告保存之前，。。。', this.data)
        this.$FileService.fileSave(this.data).then((res) => {
          this.$dispatch('success')
        }).catch((error) => {
          if (error.status === 603) {
            this.$error('重复提交')
            return
          }
          this.$dispatch('error', '公告保存', this.data, error)
        })
      },
      areaGen (data) {
        data.f_user_id = data.f_user_id + ''
        getFileGen(this, data)
      },
      cancel () {
        this.$dispatch('clean', '取消公告修正', 'user-general-info', this.row)
      },
      getPricenames (f_user_type, f_gasproperties, f_price_type) {
        let rs = []
        if (f_user_type.length === 1 && f_gasproperties.length === 1 && f_price_type.length === 1) {
          rs = this.$GetSaleParam.getPrice({
            f_user_type: f_user_type[0],
            f_gasproperties: f_gasproperties[0],
            f_price_type: f_price_type[0],
            filter: this.$login.f.f_fengongsi
          })
        }
        return rs
      }
    },
    computed: {
      meterbrands () {
        return this.$GetSaleParam.getGasbrand()
      },
      adjustables () {
        return this.$GetSaleParam.getAdjustable()
      }
    }
  }
</script>
