<template>
  <div>
    <validator name='v'  @valid="$emit('valid')"  @invalid="$emit('invalid')">
      <form class="form-horizontal">
        <div class="row">
          <div class="col-sm-8 form-group form-input-group"  :class="[$v.f_title.required ? 'has-error' : '']">
            <label for="f_title" class="control-label">标题</label>
            <input type="text"  v-model="baseinfo.base.f_title" v-validate:f_title='{required: true }' class="form-control" placeholder="请输入标题" v-next-el="phone">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-8">
            <upload :blodid="blodid" :reload-all="true"></upload>
          </div>
        </div>
      </form>
    </validator>
  </div>
</template>

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

  let getEditUserState = async function (self) {
    try {
      let http = new HttpResetClass()
      let result = await http.load('GET', `rs/vue/EidtUserState.json`,{},{resolveMsg: null, rejectMsg: null})
      console.log(result.data.EditUserState)
      self.edituserstate = result.data.EditUserState
    }catch (e) {
      console.log(e)
    }
  }

  export default {
    title: '基本信息',
    props: ['baseinfo', 'oldAddress'],
    data () {
      return {
        site: '',

        blodid: '', //附件的临时id

        areas: [],
        streets: [],
        residentials: [],
        inputtores: this.$appdata.getParam('抄表员'),
        credentials: this.$appdata.getParam('证件类型'),
        costtypes: this.$appdata.getParam('缴费类型'),
        banknames: this.$appdata.getParam('银行名称'),
        userstates: this.$appdata.getParam('用户状态'),
        edituserstate: false
      }
    },
    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)
      }
      getEditUserState(this)
    },
    methods: {

      onValid (res) {
        this.$dispatch('valid')
      },
      upload(){
        console.log('upload')
      },
      onInvalid (res) {
        this.$dispatch('invalid')
      }
    },
    watch: {
      // 重置验证结果，当证件类型切换时，验证结果不能立即刷新，需要重置
      'baseinfo.base.f_credentials[0]' () {
        console.log('验证器重置')
        this.$resetValidation()
      },
      'baseinfo.base.f_cost_type[0]' () {
        console.log('验证器重置')
        this.$resetValidation()
      },
      // 当选择销户，需要给其提醒是否进行销户
      'baseinfo.base.f_user_state' (val) {
        if (val[0] === '销户') {
          this.$showMessage('是否要对该用户进行销户操作？', ['confirm', 'cancel']).then((res) => {
            if (res !== 'confirm') {
              this.baseinfo.base.f_user_state = ['正常']
            }
          })
        }
      }
    },
    computed: {
    }
  }
</script>
