<template>
  <div>
    <div style="overflow-y: scroll;height: 92%">
      <div style="height: auto;width: 100%">
        <div style="margin-bottom: 2%; margin-top: 2%">
          <img style="margin-top: -5px" src="../../../static/images/lefticon/矩形1183.png">
          <a style="font-size: 20px;font-weight: 500;">基本信息</a>&nbsp;<a style="color: #999999;text-decoration: none"></a>
          <button class="button_search" style="width: max-content" v-show="data.baseinfo.base.f_user_nature === '单位'" @click="showUserDevices($index, data.baseinfo)">用户设备信息</button>
          <button class="button_search" style="width: max-content" @click="uploadFiles()">上传/查看附件</button>
          <button class="button_search" style="width: max-content" @click="uploadPictures()">拍照</button>
          <button class="button_search" style="width: max-content" @click="openBankAccount()" v-if="data.meterinfo[0].f_user_type[0] === '非民用' && ($login.r.includes('银行开户'))">银行开户</button>
        </div>
        <file-user-essential-info :usertype="row?row.f_user_type:null" :userphonelist="data.baseinfo.userphonelist" :baseinfo="data.baseinfo" :addressinfo="data.addressinfo" @valid="essentialInfo = true"
                                  :flag="2" @invalid="essentialInfo = false" v-ref:useressential :isedit="isedit"></file-user-essential-info>
        <file-userinfo-device :userinfodevices.sync="userinfodevices" :show_userinfodevices.sync="show_userinfodevices"
                              :userinfoid='data.baseinfo.base.f_userinfo_id'></file-userinfo-device>
      </div>

      <div style="height: auto;width: 100%">
        <file-user-meter-info :meterinfo.sync="data.meterinfo" :f_filialeid="f_filialeid" :metervalid.sync="meterInfo" :overdueset="overdueset" :curuser="row" :flag="2"
                              :f_userinfo_id="data.baseinfo.base.f_userinfo_id" :addressinfo="data.addressinfo" :baseinfo.sync="data.baseinfo.base" v-ref:meter></file-user-meter-info>
      </div>

      <div style="height: auto;width: 100%">
        <div style="margin-bottom: 2%; margin-top: 2%">
          <img style="margin-top: -5px" src="../../../static/images/lefticon/矩形1183.png">
          <a style="font-size: 20px;font-weight: 500;">发票信息</a>&nbsp;<a style="color: #999999"></a>
        </div>
        <user-paper-info-test :baseinfo="data.baseinfo"></user-paper-info-test>
      </div>

      <!--<div style="height: auto;width: 100%">-->
      <!--<div style="margin-bottom: 2%; margin-top: 2%">-->
      <!--<img style="margin-top: -5px" src="../../../static/images/lefticon/矩形1183.png">-->
      <!--<a style="font-size: 20px;font-weight: 500;">附件信息</a>&nbsp;<a style="color: #999999"></a>-->
      <!--</div>-->
      <!--<upload :blodid="blodid" isremark="true" fusetype="档案"></upload>-->
      <!--</div>-->
    </div>

    <div class="form-horizontal auto">
      <div class="form-group">
        <div style="text-align:right;">

          <button class="button_search" @click="confirm()" :disabled="!(essentialInfo && meterInfo )">确认
          </button>
          <button class="button_search" style="width: max-content" v-if="haslimit" @click="limitClick">限购配置</button>
          <button class="button_clear" @click="cancel()">取消</button>
        </div>
      </div>
    </div>
    <limit-gas :show.sync="limitShow" :f_userinfo_id="data.baseinfo.base.f_userinfo_id"
               @limit="getLimitGas"></limit-gas>
    <modal :show.sync="showfiles" width="80%" style="width:auto;"  v-ref:modal middle backdrop="false">
      <article slot="modal-body">
        <upload-idcard :blodid="blodid" isremark="true" @getidinfo="confirmIdCard" style="width:auto" fusetype="档案信息" v-ref:upload></upload-idcard>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
    <high-meter :show.sync="highmetershow" v-if="highmetershow"  @photo-finish="newPhoto" v-on:confirminfo="confirmIdCard"></high-meter>

    <modal :show.sync="filechangeDetailsShow" v-ref:filechangeDetailsShow backdrop="false" class="filechangeDetailsShow">
      <header slot="modal-header" class="modal-header" style="text-align: center">
        <h4 class="modal-title">档案修改明细</h4>
      </header>
      <article slot="modal-body" class="modal-body">
        <data-grid class="list_area table_sy" :model="filechangeDetails" partial='list'>
          <template partial='head'>
            <th><nobr>序号</nobr></th>
            <th><nobr>更改内容</nobr></th>
            <th><nobr>更改前</nobr></th>
            <th><nobr>更改后</nobr></th>
          </template>
          <template partial='body'>
            <td >{{$index+1}}</td>
            <td><nobr>{{row.f_field_name}}</nobr></td>
            <td><nobr>{{row.f_used_content}}</nobr></td>
            <td><nobr>{{row.f_new_content}}</nobr></td>
          </template>
        </data-grid>
        <div class="row">
          <div class="col-sm-12 form-group" >
            <label for="f_paper_account" class="col-sm-2 font_normal_body " title="参数:变更原因">变更原因:</label>
            <v-select v-model="fileSaveData.reason" style="width:60%"
                      placeholder='变更原因'
                      :value.sync="fileSaveData.reason"
                      :options='reasons'
                      :value-single="true"
                      v-ref:reason
                      close-on-select ></v-select>
          </div>
        </div>
        <div class="row">
          <div class="col-sm-2"></div>
          <input v-if="fileSaveData.reason==='其他'" class="input_search" style="width:60%" placeholder='修改原因' v-model="fileSaveData.modifyReason"/>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button type="button" class="btn btn-default" @click='filechangeDetailsShow = false'>取消</button>
        <button type="button" class="btn btn-success" :disabled="!fileSaveData.reason || (fileSaveData.reason === '其他' && !fileSaveData.modifyReason)" @click='confirmation()'>确认</button>
      </footer>
    </modal>
  </div>
  <work-busy :is-busy="seaching"></work-busy>
</template>

<script>
import UserPaperInfoTest from './../../components/FilesManage/UserPaperInfoTest'
import FileManageService from './plugins/FileManageService'
import {HttpResetClass} from 'vue-client'
import * as Util from '../../Util'

let getFileGen = async function (self, data) {
  let http = new HttpResetClass()
  try {
    await self.$getConfig(self, 'FilesDetail')
  } catch (ignore) {}
  let result = await http.load('POST', 'rs/logic/filemanage_getFilesDetail', data, {
    resolveMsg: null,
    rejectMsg: '用户详细信息加载失败，请重新选择，如果多次失败，请检查系统是否正常！',
    newly: true
  })
  self.data = result.data
  self.data.meterinfo.forEach((item) => {
    item.devicesinfo.forEach((item2) => {
      if (item2.img.content) {
        if (item2.img.content.startsWith('data:image/')) {
          console.log('base64,直接展示不做处理')
        } else if (item2.img.content.startsWith('http')) {
          console.log('http,直接展示不做处理')
        } else if (/^[A-Z]:\\/.test(item2.img.content)) {
          // windwos 路径处理
          let URL = item2.img.content.substring(item2.img.content.lastIndexOf(':\\') + 2)
          // eslint-disable-next-line no-undef
          item2.img.content = 'http://' + location.host + '/' + URL
        } else if (item2.img.content.startsWith('/usr/local/tomcat/files')) {
          // linux 路径处理
          // eslint-disable-next-line no-undef
          item2.img.content = 'http://' + location.host + '/' + item2.img.content.replace('/usr/local/tomcat/files', 'resource')
        }
      }
    })
  })
  // 更新地址
  // 修改附件临时id为表档案id
  self.blodid = self.data.baseinfo.base.f_userinfo_id
  console.log('获取档案信息', self.data)
  self.checkout()
  console.log('附件id', self.blodid)
}

export default {
  title: '综合信息',
  props: ['f_filialeid', 'row', 'areainfo', 'haslimit', 'isedit', 'flag'],
  components: {UserPaperInfoTest},
  data () {
    return {
      config: {
        hasnumber: false,
        adddevices: false,
        f_building_suffix: '栋',
        f_unit_suffix: '单元',
        f_floor_suffix: '层',
        f_room_suffix: '室'
      },
      data: {
        baseinfo: {
          base: {
            f_user_name: '',
            f_user_state: '',
            f_user_type: '',
            f_credentials: '',
            f_cost_type: '',
            f_bz_type: '',
            f_paper_type: '',
            f_idnumber: ''
          },
          userinfodevices: [],
          bank: {
            f_bank_name: ''
          },
          // 用户备用电话信息
          userphonelist: []
        },
        addressinfo: {
          id: '',
          f_address: '',
          f_address_state: ''
        },
        meterinfo: [{
          f_user_type: '',
          f_gasproperties: '',
          devicesinfo: [],
          fireinfo: {}
        }],
        devicesinfo: [],
        fireinfo: {},
        address: {
          id: '',
          f_address: '',
          f_address_state: ''
        }
      },
      show_userinfodevices: false,
      userinfodevices: [],
      oldAddress: {},
      highmetershow: false, // 高拍仪组件控制
      showfiles: false,
      overdueset: [],
      // 子组件验证
      essentialInfo: false,
      meterInfo: false,

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

      // 限购相关属性
      limitShow: false,
      limit_gas: null,
      peopleNum: this.$appdata.getSingleValue('默认人口'),
      blodid: '', // 附件的临时id
      defaultMeterInfo: '',  // 默认的表具信息
      fileSaveData: {
        // 修改原因
        modifyReason: '',
        reason: ''
      },
      // 档案变更明细
      filechangeDetails: {rows: []},
      filechangeDetailsShow: false,
      seaching: false // 保存中
    }
  },
  async ready () {
    if (this.data.baseinfo.base.f_userinfo_id) {
      this.blodid = this.data.baseinfo.base.f_userinfo_id
    } else {
      this.blodid = '临时id' + Date.now()
    }
    console.log('ready，，，', this.row)
    await this.getOvedueset()
    if (this.row) { // 修改用户
      await this.areaGen(this.row)
    } else if (!this.row) { // 小区批量建档
      // 将小区信息转化为综合信息的格式
      await this.areainfoInUser(this.areainfo)
    }
    console.log('this.blodid------------>', this.blodid)
  },
  watch: {
    async 'row' (val) {
      console.log('观察row', val)
      if (val) {
        await this.areaGen(val)
      } else {
        await this.areainfoInUser(this.areainfo)
      }
    },
    'areainfo' (val) {
      console.log('小区观察。。', val)
      if (val) {
        this.$refs.meter.clearMeter()
        this.blodid = '临时id' + Date.now()
        this.areainfoInUser(val)
      }
    },
    'essentialInfo' (val) {
      console.log('观察到验证变化', val)
    }
  },
  methods: {
    async getOvedueset () {
      let overdueset = []
      let res = await this.$resetpost('rs/sql/saleSingleTable', {
        data: {
          tablename: 't_overdue_set',
          condition: `f_orgid = '${this.f_filialeid}' `
        }
      }, {resolveMsg: null, rejectMsg: '', newly: true})
      for (let row of res.data) {
        overdueset.push({label: row.f_rule_name, value: `${row.id}`})
      }
      this.overdueset = overdueset
    },
    confirmIdCard (IdCardInfo) {
      console.log('返回的身份证', IdCardInfo)
      this.uploadPictures()
      this.data.baseinfo.base.f_user_name = IdCardInfo.strName
      this.data.baseinfo.base.f_idnumber = IdCardInfo.strID
    },
    showUserDevices (index, row) {
      this.userinfodevices = []
      this.show_userinfodevices = true
      this.userinfodevices = row.userinfodevices
      console.log('查看设备信息', this.userinfodevices)
    },

    uploadFiles () {
      this.showfiles = !this.showfiles
    },

    uploadPictures () {
      this.highmetershow = !this.highmetershow
    },

    openBankAccount () {
      this.$resetpost('rs/logic/openBankAccount', {f_userinfo_code: this.data.baseinfo.base.f_userinfo_code, f_username: this.data.baseinfo.base.f_user_name},
        {resolveMsg: null, rejectMsg: null}).then((res) => {
        this.$showMessage(res.data.resultmessage)
      })
    },
    async confirm () {
      this.data.addressinfo.f_address = this.$refs.useressential.addressinfo.f_address
      this.data.addressinfo.id = this.$refs.useressential.addressinfo.id
      this.data.oldaddressinfo = this.oldAddress
      this.data.hasnumber = this.config.hasnumber
      this.data.limit_gas = this.limit_gas
      if (this.f_filialeid && this.f_filialeid != '') {
        this.data.f_filialeid = this.f_filialeid
      } else {
        this.data.f_filialeid = this.$login.f.orgid
      }
      if (this.row) {
        this.data.baseinfo.base.version = this.row.version
      }
      this.seaching = true
      console.log('档案保存之前，。。。', this.data)
      this.data.baseinfo.base.f_user_name = Util.removerUnnecessary(this.data.baseinfo.base.f_user_name)
      this.data.baseinfo.base.f_user_phone = Util.removerUnnecessary(this.data.baseinfo.base.f_user_phone)
      this.data.meterinfo.forEach((item) => {
        item.f_meternumber = Util.removerUnnecessary(item.f_meternumber)
      })
      if (this.data.meterinfo[0].f_gas_date != null) {
        this.data.addressinfo.f_address_state = '已通气'
      }
      // 获取保存数据
      Object.assign(this.fileSaveData, {}, FileManageService.fileSaveBefore(this.data))
      // 如果是修改, 则展示修改的明细给用户
      if (this.fileSaveData.userinfo.f_userinfo_id) {
        if (this.row.f_user_state === '预备' && this.fileSaveData.userinfo.f_user_state === '正常') {
          this.fileSaveData.userinfo.f_createfile_person = this.$login.f.name
          this.fileSaveData.userinfo.f_open_date = this.$login.toStandardTimeString()
          this.fileSaveData.modifyReason = this.reason = '建档（档案信息完善）'
        } else {
          this.reason = '其他'
          this.fileSaveData.modifyReason = ''
        }
        let details = await this.$resetpost('rs/logic/filechangeDetails', {data: this.fileSaveData}, {resolveMsg: null, rejectMsg: '获取修改明细出错!'})
        this.seaching = false
        this.filechangeDetails.rows = details.data.changeDetails
        this.filechangeDetailsShow = details.data.isChange
      }
      // 不是修改直接保存
      if (!this.filechangeDetailsShow) this.confirmation()
    },
    confirmation () {
      debugger
      if (this.fileSaveData.reason && this.fileSaveData.reason !== '其他') {
        this.fileSaveData.modifyReason = this.fileSaveData.reason
      }
      if (this.fileSaveData.userinfo.f_userinfo_id && this.row.f_user_state === '预备' && this.fileSaveData.userinfo.f_user_state === '正常') {
        this.fileSaveData.userinfo.f_createfile_person = this.$login.f.name
        this.fileSaveData.modifyReason = this.reason = '建档（档案信息完善）'
      }
      // for (let i = 0; i < this.filechangeDetails.rows.length; i++) {
      //   if (this.filechangeDetails.rows[i].f_field_name === '通气日期') {
      //     let name = this.$login.f.name
      //     let nameId = this.$login.f.id
      //     let parentname = this.$login.f.deps
      //     let parentnameId = this.$login.f.depids
      //     this.fileSaveData.userinfo.f_operator = name
      //     this.fileSaveData.userinfo.f_operatorid = nameId
      //     this.fileSaveData.userinfo.f_depname = parentname
      //     this.fileSaveData.userinfo.f_depid = parentnameId
      //     this.fileSaveData.userinfo.userfiles.f_operator = name
      //     this.fileSaveData.userinfo.userfiles.f_operatorid = nameId
      //     this.fileSaveData.userinfo.userfiles.f_depname = parentname
      //     this.fileSaveData.userinfo.userfiles.f_depid = parentnameId
      //   }
      // }
      console.log('打印保存数据', this.fileSaveData)
      console.log('打印id', this.fileSaveData.userinfo.f_userinfo_id)
      // 如果是修改操作则修改建党人
      // if (this.fileSaveData.userinfo.f_userinfo_id) {
      //   this.fileSaveData.userinfo.f_createfile_person = this.$login.f.name
      // }
      console.log('二次打印打印保存数据', this.fileSaveData)
      FileManageService.fileSave(this.fileSaveData).then((res) => {
        this.$parent.resdata = res.data.result[0].f_userinfo_code
        if (!this.row) {
          this.$parent.resshow = true
        }
        this.$dispatch('success')
      }).catch((error) => {
        if (error.status === 603) {
          this.$error('重复提交')
          return
        }
        this.seaching = false
        this.$dispatch('error', '档案保存', this.data, error)
      })
    },
    convertBase64ToBlob (base64String) {
      // 将base64解码
      var bytes = atob(base64String)
      // var bytes = base64;
      var bytesCode = new ArrayBuffer(bytes.length)
      // 转换为类型化数组
      var byteArray = new Uint8Array(bytesCode)

      // 将base64转换为ascii码
      for (var i = 0; i < bytes.length; i++) {
        byteArray[i] = bytes.charCodeAt(i)
      }
      // 生成Blob对象（文件对象）
      return new Blob([bytesCode], {type: 'image/jpeg'})
    },
    newPhoto (Imgbase64) {
      this.$refs.upload.newPhoto(Imgbase64)
      /* let form = new FormData()
      let xhr = new XMLHttpRequest()
      let formDataBoundary = "----WebkitFormBoundary" + "GaoPaiYi";
      form.append('Content-Type', 'multipart/form-data;boundary=' + formDataBoundary)
      form.append('file', this.convertBase64ToBlob(Imgbase64), "GaoPaiYi.jpg")
      xhr.open("POST", "rs/file/uploadFile")

      if (this.headers) {
        for (var header in this.headers) {
          xhr.setRequestHeader(header, encodeURIComponent(this.headers[header]))
        }
      }
      xhr.send(form)
      setTimeout(() => {
        this.load(this)
      }, 5000) */
    },
    async areaGen (data) {
      data.f_user_id = data.f_user_id + ''
      await getFileGen(this, data)
    },
    cancel () {
      this.$dispatch('clean', '取消档案修正', 'user-general-info', this.row)
    },
    checkout (val) {
      // 对收到的综合信息进行校验（主要目的是为了防止下拉框没有默认值）
      // 对综合用户基本信息进行校验

      // 将oldAddress 置为空，
      this.oldAddress = {}
      this.data.baseinfo.base.f_user_state = this.data.baseinfo.base.f_user_state === '预备' ? '正常' : this.data.baseinfo.base.f_user_state
      // this.data.baseinfo.base.f_user_nature = this.data.baseinfo.base.f_user_nature ? [this.data.baseinfo.base.f_user_nature] : '民用'
      // this.data.baseinfo.base.f_credentials = this.data.baseinfo.base.f_credentials ? [this.data.baseinfo.base.f_credentials] : '身份证'
      this.data.baseinfo.base.f_cost_type = this.data.baseinfo.base.f_cost_type ? [this.data.baseinfo.base.f_cost_type] : '现金缴费'
      this.data.baseinfo.base.f_bz_type = this.data.baseinfo.base.f_bz_type ? [this.data.baseinfo.base.f_bz_type] : ''

      this.data.baseinfo.base.f_paper_type = this.data.baseinfo.base.f_paper_type ? [this.data.baseinfo.base.f_paper_type] : '电子发票'
      this.data.baseinfo.bank.f_bank_name = this.data.baseinfo.bank.f_bank_name ? [this.data.baseinfo.bank.f_bank_name] : '中国银行'
      this.data.baseinfo.base.f_people_num = this.data.baseinfo.base.f_people_num ? this.data.baseinfo.base.f_people_num : (this.peopleNum ? this.peopleNum : 0)

      if (this.data.baseinfo.base.f_slice_area) {
        this.data.baseinfo.base.f_slice_area = [this.data.baseinfo.base.f_slice_area]
      } else {
        this.data.baseinfo.base.f_slice_area = ''
      }
      this.oldAddress.f_address = this.data.addressinfo.f_address
      this.oldAddress.id = this.data.addressinfo.id

      // 地址信息
      // loadStreetAndResGen(this)

      // 对表具信息进行校验
      this.data.meterinfo.forEach((row) => {
        console.log(row)
        if (row.gasbrand) {
          this.meterbrands.forEach((item) => {
            if (item.label === row.gasbrand) {
              row.gasbrand = [item.value]
            }
          })
        } else {
          row.gasbrand = ''
        }
        if (row.gasmodel && (row.gasbrand instanceof Array)) {
          row.gasbrand[0].gasmodel.forEach((item) => {
            if (item.label === (val === 'area' ? row.gasmodel : row.gasmodel + row.gasmodeltype)) {
              row.gasmodel = [item.value]
            }
          })
        } else {
          row.gasmodel = ''
        }
        if (row.f_fire_state === '1') {
          row.f_fire_state1 = true
        } else if (row.f_fire_state === '0') {
          row.f_fire_state1 = false
        }
        row.f_install_date = row.f_install_date ? row.f_install_date : null
        row.f_gas_date = row.f_gas_date ? row.f_gas_date : null
        row.f_changetube_date = row.f_changetube_date ? row.f_changetube_date : null
        row.f_aroundmeter = row.f_aroundmeter ? row.f_aroundmeter : ''
        row.f_garbage_fee = row.f_garbage_fee ? row.f_garbage_fee : ''
        row.f_valve_state = row.f_valve_state ? [row.f_valve_state] : ''
        row.f_usetype = row.f_usetype ? [row.f_usetype] : ''
        row.f_usestate = row.f_usestate && row.f_usestate.length > 0 ? [row.f_usestate] : ''
        row.f_meter_book_num = row.f_meter_book_num && row.f_meter_book_num.length > 0 ? [row.f_meter_book_num] : ''
        row.f_userfiles_address = row.f_userfiles_address && row.f_userfiles_address.length > 0 ? [row.f_userfiles_address] : ''
        row.f_inputtor = row.f_inputtor ? [row.f_inputtor] : ''
        row.f_position = row.f_position ? [row.f_position] : ''

        row.f_user_type = row.f_user_type ? [row.f_user_type] : ''
        row.f_gasproperties = row.f_gasproperties ? [row.f_gasproperties] : ''
        row.pricetype = row.pricetype ? [row.pricetype] : ''

        if (row.pricename) {
          let names = this.getPricenames(row.f_user_type,
            row.f_gasproperties,
            row.pricetype)

          console.log('=====2.===校验气价名称', names, row.f_user_type, row.f_gasproperties, row.pricetype)
          if (names.length > 0) {
            names.forEach((item) => {
              if (item.label === row.pricename) {
                row.pricename = [item.value]
                row.f_detailprice = this.$CommonService.getShowPriceDetail(item.value.detailprice)
              }
            })
          } else {
            row.pricename = ''
          }
        } else {
          row.pricename = ''
        }

        if (row.f_adjustable) {
          this.adjustables.forEach((item) => {
            if (item.label === row.f_adjustable) {
              row.f_adjustable = [item.value]
            }
          })
        } else {
          row.f_adjustable = ''
        }
      })
      // console.log('5555555555', this.data.meterinfo)
      // 对设备进行校验
      // this.data.devicesinfo.forEach((row) => {
      //     row.f_devices_type = row.f_devices_type ? [row.f_devices_type] : ''
      // })
    },
    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.f_filialeid
        })
      }
      return rs
    },
    // 将小区信息转化为综合信息的格式
    async areainfoInUser (areainfo) {
      // this.nextTick(() => {
      //
      // })
      // await this.$getConfig(this, 'UserAddress')
      this.data = {
        baseinfo: {
          base: {
            f_user_state: '正常',
            f_is_mgq: '',
            f_slice_area: '', // 片区
            // 附件表临时id
            blodid: this.blodid,
            // 用户姓名
            f_user_name: '',
            // 用户电话
            f_user_phone: '',
            f_people_num: this.$appdata.getSingleValue('默认人口数') ? this.$appdata.getSingleValue('默认人口数') : 0,
            f_packaging: '',
            // 备用电话
            f_rent_phone: '',
            f_credentials: '身份证',
            f_cost_type: '',
            f_bz_type: '',
            f_address: '',
            addressid: '',
            f_idnumber: '',
            f_meter_book_num: ''
          },
          bank: {},
          // 用户备用电话信息
          userphonelist: []
        },
        addressinfo: {
          // 详细地址
          f_address: '',
          id: ''
        },
        meterinfo: [{
          // 表号
          f_meternumber: '',
          f_metertitles: '',
          f_area_code: '',
          // 气表品牌
          gasbrand: '',
          // 气表型号
          gasmodel: '',
          // 气表类型
          gasmodeltype: '',
          pricetype: '', // 气价类型
          pricename: '', // 气价名称
          f_user_type: '', // 用户类型
          f_gasproperties: '', // 用气性质
          f_inputtor: '',
          // 安装位置
          f_position: '',
          // 安装地址
          f_userfiles_address: '',
          //  安装经度
          f_userfiles_lng: '',
          //  安装纬度
          f_userfiles_lat: '',
          // 使用类型
          f_usetype: '',
          // 使用状态
          f_usestate: '',
          // 左右表
          f_aroundmeter: '',
          f_garbage_fee: '否',
          f_meter_base: '',
          f_initial_base: '',
          // 通气人
          f_gas_person: '',
          f_adjustable: '', // 调压箱
          f_detailprice: '',  // 价格详情显示
          devicesinfo: [], // 设备信息
          f_hand_month: '', // 抄表月份
          fireinfo: {}, // 用气信息
          f_meter_book_num: '',
          f_use_limit: '',
          f_gas_date: '',
          f_install_date: ''
        }],
        devicesinfo: []
      }
            // 若有id，则表示该地址是更新操作
            /* if (areainfo.id) {
                this.data.addressinfo.id = areainfo.id
            }
            // 改地址是 只有表没有户信息
            if (areainfo.meter) {
                Object.assign(this.data.meterinfo[0], this.data.meterinfo[0], areainfo.meter)
            }
            if (areainfo.user) {
                Object.assign(this.data.baseinfo.base, this.data.baseinfo.base, areainfo.user)
            } */

      this.checkout('area')
    },
    limitClick () {
      this.limitShow = true
    },
    getLimitGas (val) {
      this.limit_gas = val
    },
    clearinfo () {
      this.blodid = this.data.baseinfo.base.f_userinfo_id
      this.areainfoInUser(this.areainfo)
    }
  },
  computed: {
    meterbrands () {
      return this.$GetSaleParam.getGasbrand()
    },
    reasons () {
      return this.$appdata.getParam('变更原因')
    },
    adjustables () {
      return this.$GetSaleParam.getAdjustable()
    },
    getMeterBooks () {
      return this.$GetSaleParam.getMeterBooks()
    }
  },
  events: {
      // 设置表具气价等默认值
    defaultOtheret (row) {
      if (!this.isedit) {
        let temp = {
          gasmodel: row.f_meter_style,
          gasbrand: row.f_meter_brand,
          gasmodeltype: row.f_meter_style,
          pricetype: row.f_price_type,
          pricename: row.f_price_name,
          f_user_type: row.f_user_type,
          f_gasproperties: row.f_gasproperties,
          f_position: row.f_position,
          f_meter_book_num: row.f_meter_book ? row.f_meter_book : '',
          f_usestate: '正常',
          f_adjustable: row.f_adjustable_id,
          f_install_date: row.f_install_date,
          f_inputtor: row.f_inputtor,
          f_hand_month: row.f_hand_month,
          f_usetype: ''
        }
        if (!temp.f_install_date) {
          delete temp.f_install_date
        }
        Object.assign(this.data.meterinfo[0], this.data.meterinfo[0], temp)
        this.data.baseinfo.base.f_house_type = row.f_house_type ? [row.f_house_type] : ''
        console.log('====1.=====', temp, row)
        this.checkout('area')
      }
    }
  }
}
</script>
<style lang="less">
  .filechangeDetailsShow {
    td {
      text-align: center !important;
    }
  }
</style>
