<template>
  <div id="UserEssentialInfoTest">
    <validator name='v' @valid="$emit('valid')" @invalid="$emit('invalid')">
      <form class="form-horizontal select-overspread ">
        <div class="row">
          <div style="" class="col-sm-4 form-group">
            <label for="f_user_name" class="font_normal_body color-red">*客户姓名</label>
            <input type="text" v-model="baseinfo.base.f_user_name" v-validate:f_user_name='{required: true }'
                   class="input_search" style="width:60%" placeholder="客户名称" v-next-el="phone">
          </div>
          <div style="" class="col-sm-4 form-group">
            <label for="f_user_phone" class="font_normal_body color-red">*客户电话</label>
            <input type="text" maxlength="11" v-model="baseinfo.base.f_user_phone"
                   v-validate:f_user_phone="{minlength: 11, maxlength: 11  }" class="input_search" style="width:60%"
                   placeholder="客户电话" v-el:phone v-next-el="area">
          </div>
          <div class="col-sm-4 form-group" style="" v-if="true">
            <label for="f_user_state" class="font_normal_body">&ensp;客户状态</label>
            <v-select :value.sync="baseinfo.base.f_user_state"
                      :disabled="true"
                      :value-single="true"
                      :options='userstates' placeholder='客户状态'
                      close-on-select></v-select>
          </div>
        </div>
        <div class="row">
          <div style="" class="col-sm-4 form-group">
            <label for="f_credentials" class="font_normal_body">&ensp;证件类型</label>
            <v-select id="idCardType" :value.sync="baseinfo.base.f_credentials"
                      v-model="baseinfo.base.f_credentials"
                      :value-single="true"
                      :options='credentials' placeholder='证件类型'
                      style="width: 65%"
                      close-on-select></v-select>
          </div>
          <div style="" class="col-sm-8 form-group"]
               v-if="baseinfo.base.f_credentials === '身份证'">
            <label for="f_idnumber" class="font_normal_body color-red">*证件号码</label>
            <input type="text" maxlength="18" v-model="baseinfo.base.f_idnumber"
                   v-validate:f_idnumber2='{identityCardValid: true}' class="input_search" style="width:80%"
                   placeholder="证件号码">
          </div>
          <div style="" class="col-sm-8 form-group" v-if="baseinfo.base.f_credentials !== '身份证'">
            <label class="font_normal_body">&ensp;证件号码</label>
            <input type="text" v-model="baseinfo.base.f_idnumber" class="input_search" style="width:80%"
                   placeholder="证件号码">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-12 form-group">
            <label for="f_address" class="font_normal_body color-red">*地址信息</label>
            <input type="text" v-model="addressinfo.f_address" :value.sync="addressinfo.f_address" v-validate:f_address='{required: true }'
                   class="input_search" disabled="disabled" style="width:75%;" placeholder="用户地址" >
            <span>
              <button class="button_search button_spacing" type="button" style="width: max-content" v-if="!isedit" @click="selectaddress()">选择地址</button>
              <!--              <button class="button_search button_spacing" type="button" style="width: max-content" v-if="isedit" @click="modifyaddress()">修改地址</button>-->
              <button class="button_search button_spacing" type="button" style="width: max-content" v-if="isedit" @click="selectaddress()">修改地址</button>
            </span>
          </div>
        </div>
        <div class="row">
          <div style="" class="col-sm-4 form-group">
            <label for="f_used_name" class="font_normal_body">&ensp;曾&ensp;用&ensp;名</label>
            <input type="text" v-model="baseinfo.base.f_used_name" class="input_search" style="width:60%"
                   placeholder="曾用名">
          </div>
          <div style="" class="col-sm-4 form-group">
            <label for="f_rent_phone" class="font_normal_body">&ensp;备用电话</label>
            <input type="text" v-model="baseinfo.base.f_rent_phone" class="input_search" style="width:60%"
                   placeholder="备用电话">
          </div>
          <div class="col-sm-4 form-group">
            <label for="f_people_num" class="font_normal_body color-red">&ensp;人&ensp;口&ensp;数</label>
            <input type="number" v-model="baseinfo.base.f_people_num" v-validate:f_people_num='{dctest: [0, ">=" ]}'
                   :disabled="!jurisdiction.includes('修改人口数')" class="input_search" style="width:60%"
                   placeholder="家庭人口数">
          </div>
        </div>
        <div class="row">
          <div style="" class="col-sm-4 form-group">
            <label for="f_balance" class="font_normal_body">&ensp;用户余额</label>
            <input type="text" v-model="baseinfo.base.f_balance" class="input_search" style="width:60%"
                   placeholder="用户余额" :disabled="!jurisdiction.includes('档案信息查询修改')">
          </div>
          <div style="" class="col-sm-4 form-group">
            <label for="f_is_mgq" class="font_normal_body color-red">煤&ensp;改&ensp;气&ensp;</label>
            <v-select id="f_is_mgq" :value.sync="baseinfo.base.f_is_mgq"  v-model="baseinfo.base.f_is_mgq"
                      :options='mgq' placeholder='是否煤改气'   style="width: 65%"       close-on-select></v-select>
          </div>
          <div style="" class="col-sm-4 form-group">
            <label for="f_user_level" class="font_normal_body ">&ensp;用户等级</label>
            <v-select :value.sync="baseinfo.base.f_user_level" :search="false" :value-single="true"
                      :options='userlevel' placeholder='用户等级' close-on-select>
            </v-select>
          </div>
<!--          <div class="col-sm-4 form-group">-->
<!--            <label for="f_contract" class="font_normal_body color-red">&ensp;用户证号</label>-->
<!--            <input type="text"  v-model="baseinfo.base.f_book_no" class="input_search" style="width:60%" placeholder="用户证号">-->
<!--          </div>-->
        </div>
        <div class="row">
          <div style="" class="col-sm-4 form-group">
            <label for="f_rent_name" class="font_normal_body">&ensp;租户姓名</label>
            <input type="text" v-model="baseinfo.base.f_rent_name" class="input_search" style="width:60%"
                   placeholder="租户姓名">
          </div>
          <div style="" class="col-sm-4 form-group">
            <label for="f_zuhu_phone" class="font_normal_body">&ensp;租户电话</label>
            <input type="text" v-model="baseinfo.base.f_zuhu_phone" class="input_search" style="width:60%"
                   placeholder="租户电话">
          </div>
          <div style="" class="col-sm-4 form-group">
            <label for="f_is_mgq" class="font_normal_body ">&ensp;付款类型</label>
            <v-select id="f_is_mgq" :value.sync="baseinfo.base.f_cost_type"  v-model="baseinfo.base.f_cost_type"
                      :options='costtype' placeholder='付款类型'   style="width: 65%"       close-on-select></v-select>
          </div>
        </div>
        <div class="row">
          <div class="col-sm-8 form-group">
            <label for="f_contract" class="font_normal_body">&ensp;合同编号</label>
            <input type="text" v-model="baseinfo.base.f_contract_id" class="input_search" style="width:80%"
                   placeholder="合同编号">
          </div>
          <div class="col-sm-4 form-group">
            <label for="f_user_state" class="font_normal_body">&ensp;房屋类型</label>
            <input type="text" v-show="false" v-model="baseinfo.base.f_house_type">
            <v-select :value.sync="baseinfo.base.f_house_type" :search="false" :value-single="true"
                      :options='housetype' placeholder='房屋类型' close-on-select>
            </v-select>
          </div>
        </div>
        <div class="row">
          <div style="" class="col-sm-12 form-group">
            <label for="f_paper_account" class="font_normal_body ">&ensp;备&emsp;&emsp;注</label>
            <input class="input_search" style="width:86.5%;height: 40px" v-model="baseinfo.base.f_comments"/>
          </div>
        </div>

        <div class="row">
          <a style="text-decoration: none;font-weight: 300;float: left;color: #333;margin-top: 15px;font-weight: 500"
             v-if="baseinfo.base.f_cost_type[0] === '银行代扣'">银行信息</a>
        </div>
        <div v-if="baseinfo.base.f_cost_type[0] === '银行代扣'">
          <div class="row">
            <div class="col-sm-4 form-group"
                 :class="[$v.f_bank_accopen.required ? 'has-error' : '']">
              <label for="f_username" class="font_normal_body">银行户名</label>
              <input type="text" v-model="baseinfo.bank.f_bank_accopen"
                     class="input_search" style="width:60%" id="f_username" placeholder="客户名称"
                     v-validate:f_bank_accopen='{required: true}'
                     v-next-el="bankaccount">
            </div>
            <div class="col-sm-4 form-group" id=userfiles-useEssInf-银行名称>
              <label for="f_username" class="font_normal_body ">银行名称</label>
              <v-select :value.sync="baseinfo.bank.f_bank_name"
                        :options='banknames' placeholder='银行名称'
                        close-on-select></v-select>
            </div>
            <div class="col-sm-4 form-group">
              <label for="f_bank_idnumber" class="font_normal_body">缴费编号</label>
              <input type="text" v-model="baseinfo.bank.f_bank_pay_number"
                     class="input_search" style="width:60%"
                     aria-describedby="helpBlock" placeholder="缴费编号" v-el:bankpaynumber>
            </div>
            <div class="col-sm-12 form-group">
              <label for="f_bank_idnumber" class="font_normal_body">身份证号</label>
              <input type="text" v-model="baseinfo.bank.f_bank_idnumber"
                     class="input_search" style="width:54%"
                     aria-describedby="helpBlock" placeholder="身份证号" v-el:bankidnumber>
            </div>
            <div class="col-sm-12 form-group"
                 :class="[$v.f_bank_account.required ? 'has-error' : '']">
              <label for="f_userid" class="font_normal_body">银行账号</label>
              <input type="text" v-model="baseinfo.bank.f_bank_account" class="input_search" style="width:54%"
                     v-validate:f_bank_account='{required: true}' placeholder="银行账号" v-el:bankaccount
                     v-next-el="bankidnumber">
            </div>
          </div>
        </div>
      </form>
    </validator>
    <modal v-if="showselectaddress" :show.sync="showselectaddress" class="font_normal_body color-red" width="80%" title="地址信息" v-ref:modal large backdrop="false">
      <article slot="modal-body" class="modal-body" style="height: 700px;padding: 0!important;">
        <file-address-manage :is-select="isSelect" :fileinfo="addressinfo"
                             @address-valid="doNothing"   :showselectaddress.sync="showselectaddress" v-ref:fileaddress ></file-address-manage>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
  </div>
</template>

<script>
  import {HttpResetClass} from 'vue-client'
  // import HighMeter from '../../plugins/HighMeterPlugin'

  let getEditUserState = async function (self) {
    try {
      let http = new HttpResetClass()
      let result = await http.load('GET', `rs/vue/EditUserState.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', 'addressinfo', 'isedit'],
    data () {
      return {
        showselectaddress: false,
        site: '',
        areas: [],
        streets: [],
        residentials: [],
        inputtores: this.$appdata.getParam('抄表员'),
        credentials: this.$appdata.getParam('证件类型'),
        costtypes: this.$appdata.getParam('缴费类型'),
        banknames: this.$appdata.getParam('银行名称'),
        userstates: this.$appdata.getParam('用户状态'),
        mgq: this.$appdata.getParam('是否煤改气'),
        costtype: this.$appdata.getParam('付款类型'),
        usernature: this.$appdata.getParam('用户性质'),
        userlevel: this.$appdata.getParam('用户等级'),
        housetype: [{label: '楼房', value: '楼房'}, {label: '自建房', value: '自建房'}],
        jurisdiction: this.$login.r,
        edituserstate: false,
        // highMeterPlugin: {},
        readCardFlag: true,

        isSelect: false
      }
    },
    ready () {
      getEditUserState(this)
      this.$resetValidation()
      // this.highMeterPlugin = new HighMeter(this,this.readIDCardCallback)
    },
    beforeDestroy () {
      // this.highMeterPlugin.Stop()
    },
    methods: {
      selectaddress () {
        this.showselectaddress = true
        this.isSelect = true
      },
      modifyaddress () {
        this.showselectaddress = true
        this.isSelect = false
      },
      onValid (res) {
        this.$dispatch('valid')
      },
      onInvalid (res) {
        this.$dispatch('invalid')
      },
      doNothing () {
      },
      readIDCardCallback (compoent, msg) {
        console.log('进入高拍仪', msg)
        if (msg.err !== 0) {
          return
        }
        // document.getElementById("idCardType").getElementsByClassName("btn-content")[0].innerHTML="身份证"
        compoent.baseinfo.base.f_idnumber = msg.strID
        compoent.baseinfo.base.f_user_name = msg.strName.trim()
        // compoent.baseinfo.base.f_credentials=["身份证"]
      }
    },
    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: {},
    events: {
      'confirmaddress' (res) {
        console.log('选定地址', res)
        this.showselectaddress = false
        this.addressinfo.f_address = res.f_address
        this.addressinfo.id = res.id
        this.$dispatch('defaultOtheret', res)
      }
    }
  }
</script>
<style lang="less">
  #UserEssentialInfoTest {
    .color-red {
      color: red;
    }
  }
</style>
