<template>
  <div class="p-10">
    <criteria-paged :model="model" v-ref:cp>
      <criteria partial='criteria' @condition-changed='$parent.searchCondition' v-ref:cri>
        <div partial class="auto">
          <div class="row form-group app-input"  v-if="$parent.$parent.criteriaShow">
            <label class="">楼&emsp;&emsp;号：</label>
            <div class="col-xs-8" >
              <input class="" v-model=model.f_building condition="ui.f_building like '{}%'" />
            </div>
          </div>
          <div class="row form-group app-input"  v-if="$parent.$parent.criteriaShow">
            <label class="">单&emsp;&emsp;元：</label>
            <div class="col-xs-8" >
              <input class="" v-model=model.f_unit condition="ui.f_unit like '{}%'" />
            </div>
          </div>
          <div class="row form-group app-input"  v-if="$parent.$parent.criteriaShow">
            <label class="">门&ensp;牌&ensp;号：</label>
            <div class="col-xs-8" >
              <input class="" v-model=model.f_room condition="ui.f_room like '{}%'" />
            </div>
          </div>
          <div class="row form-group text-right" style="">
              <button class="btn btn-info" @click.prevent="$parent.$parent.openModal()"
                      :disabled="mark === 1 ||
              (model.rows.length >= selectdata.f_install_count && selectdata.defname === '工程施工') ||
              (model.rows.length >= selectdata.f_apply_count && (selectdata.defname === '报建受理')) ||
              selectdata.defname === '施工通气'"
              >添加</button>
            <button class="btn btn-primary" @click="search()">查询</button>
            <button class="btn btn-info" @click="$parent.$parent.clear()">清空</button>
            <button class="btn" :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}" @click="$parent.$parent.criteriaShow = !$parent.$parent.criteriaShow"></button>
          </div>
        </div>
      </criteria>
        <list :model="model" partial='list'>
          <div partial class="auto app-text panel">
            <div class="panel-body panel-self">
              <div class="row">
                <p class="col-xs-3 text-left font"><b class="control-label-justify">客户编号</b></p>
                <p class="col-xs-8 col-xs-offset-1 text-left input-font">{{ row.f_userinfo_id }}</p>
              </div>
              <div class="row">
                <p class="col-xs-3 text-left font"><b class="control-label-justify">客户名称</b></p>
                <p class="col-xs-8 col-xs-offset-1 text-left input-font">{{ row.f_user_name }}</p>
              </div>
              <div class="row">
                <p class="col-xs-3 text-left font"><b class="control-label-justify">客户电话</b></p>
                <p class="col-xs-8 col-xs-offset-1 text-left input-font">{{ row.f_user_phone }}</p>
              </div>
              <div class="row">
                <p class="col-xs-3 text-left font"><b class="control-label-justify">地址信息</b></p>
                <p class="col-xs-8 col-xs-offset-1 text-left input-font">{{row.f_address}}{{row.f_address_detail}}</p>
              </div>
              <div class="row">
                <p class="col-xs-3 text-left font"><b class="control-label-justify">表号</b></p>
                <p class="col-xs-8 col-xs-offset-1 text-left input-font">{{ row.f_meternumber }}</p>
              </div>
              <div class="row">
                <p class="col-xs-3 text-left font"><b class="control-label-justify">气表品牌</b></p>
                <p class="col-xs-8 col-xs-offset-1 text-left input-font">{{ row.f_meter_brand }}</p>
              </div>
              <div class="row">
                <p class="col-xs-3 text-left font"><b class="control-label-justify">气表型号</b></p>
                <p class="col-xs-8 col-xs-offset-1 text-left input-font">{{ row.f_meter_style }}</p>
              </div>
              <div class="row text-right">
                <button class="btn btn-danger"
                        @click="$parent.$parent.$parent.deleteUserinfo(row)"
                        v-if="$parent.$parent.$parent.DeleteUserInfo"
                        :disabled="$parent.mark === 1 || row.f_user_state === '正常'">
                  销户
                </button>
                <button class="btn btn-info"
                        @click.prevent="$parent.$parent.$parent.openModal(row)">
                  {{$parent.mark === 1 ? '查看' : '修正'}}
                </button>

              </div>
            </div>
          </div>
        </list>
    </criteria-paged>
  </div>
  <div>
    <validator name="v">
      <modal v-if="showModal" :show.sync="showModal" v-ref:modal :large="true" :backdrop="false">
        <header slot="modal-header" class="modal-header">
          <button type="button" class="close" @click="closeUserFile"><span>&times;</span></button>
          <h4 class="modal-title">安装明细</h4>
        </header>
        <article slot="modal-body" class="modal-body clearfix">
          <!-- 基本信息 -->
          <div class="form-group col-xs-12 panel panel-info" v-if="showUserInfo">
            <div class="panel-heading head col-xs-12" style="background-color: #e8f4ff;margin-bottom: 10px">
              <div class="col-xs-6 text-left">用户信息</div>
            </div>
            <div class="form-group row vertical-center" :class="[$v.f_user_name.required ? 'has-error' : '']">
              <label class="col-xs-4 control-label">客户名称：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" style=""
                       v-validate:f_user_name = "['required']"
                       v-model="userinfo.f_user_name"
                       :value.sync="showUserInformation.f_user_name"
                       :readonly="mark === 1"
                       placeholder="客户名称"/>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">客户电话：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" style=""
                       v-model="userinfo.f_user_phone"
                       :value.sync="showUserInformation.f_user_phone"
                       :readonly="mark === 1"
                       placeholder="客户电话"/>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">证件类型：</label>
              <div class="col-xs-8">
                <input-select
                  class="select select_list"
                  :value.sync="showUserInformation.f_credentials"
                  v-model="userinfo.f_credentials"
                  :options="credentialsList"
                  :disable="mark === 1"
                  :valueSingle="true"></input-select>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">证件号码：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" style=""
                       placeholder="证件号码"
                       v-model="userinfo.f_idnumber"
                       :value="showUserInformation.f_idnumber"
                       :readonly="mark === 1"/>
              </div>
            </div>
          </div>
          <!-- 地址信息 -->
          <div class="form-group col-xs-12 panel panel-info" v-if="showAddress">
            <div class="panel-heading head col-xs-12" style="background-color: #e8f4ff;margin-bottom: 10px">
              <div class="col-xs-6 text-left">地址信息</div>
            </div>
            <div class="form-group row vertical-center" :class="[$v.area.required ? 'has-error' : '']">
              <label class="col-xs-4 control-label">小&emsp;&emsp;区：</label>
              <div class="col-xs-8">
                <input type="text" v-show="false" v-model="area.id" :value.sync="area.id" v-validate:area = "['required']" >
                <input-select
                  class="select select_list"
                  :value.sync="area"
                  v-model="area"
                  :options="areaList"
                  @change="changeArea(),addressSplicing()"
                  @select-search = "selectArea"
                  :disable="mark === 1 || selectdata.f_apply_nature === '小区'"
                  :valueSingle="true"></input-select>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">楼&emsp;&emsp;号：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" placeholder="楼号"
                       v-model="userinfo.f_building"
                       :value="userinfo.f_building"
                       @change="addressSplicing"
                       :readonly="mark === 1"/>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">单&emsp;&emsp;元：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" placeholder="单元"
                       v-model="userinfo.f_unit"
                       :value="userinfo.f_unit"
                       @change="addressSplicing"
                       :readonly="mark === 1"/>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">楼&emsp;&emsp;层：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" placeholder="楼层"
                       v-model="userinfo.f_floor"
                       :value="userinfo.f_floor"
                       @change="addressSplicing"
                       :readonly="mark === 1"/>
              </div>
            </div>
            <div class="form-group row vertical-center" :class="[$v.f_room.required ? 'has-error' : '']">
              <label class="col-xs-4 control-label">门&ensp;牌&ensp;号：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" placeholder="门牌号"
                       v-validate:f_room = "['required']"
                       v-model="userinfo.f_room"
                       :value="userinfo.f_room"
                       @change="addressSplicing"
                       :readonly="mark === 1"/>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">地&emsp;&emsp;址：</label>
              <div class="col-xs-8">
                <input class="form-control input_view"
                       placeholder="地址"
                       v-model="userinfo.f_address"
                       :value.sync="userinfo.f_address"
                       :readonly="true"/>
              </div>
            </div>
          </div>
          <!-- 表具信息 -->
          <div class="form-group col-xs-12 panel panel-info" v-if="showUserFile">
            <div class="panel-heading head col-xs-12" style="background-color: #e8f4ff;margin-bottom: 10px">
              <div class="col-xs-6 text-left">表具信息</div>
              <div class="col-xs-6 text-right">
                <svg @click="scanCode()" style="width: 25px;height: 25px;margin-right: 10px" t="1636095770822" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2457" width="64" height="64">
                  <path d="M928.016126 543.908618 95.983874 543.908618c-17.717453 0-31.994625-14.277171-31.994625-31.994625S78.26642 479.919368 95.983874 479.919368l832.032253 0c17.717453 0 31.994625 14.277171 31.994625 31.994625S945.73358 543.908618 928.016126 543.908618z" p-id="2458"></path>
                  <path d="M832.032253 928.016126 639.892491 928.016126c-17.717453 0-31.994625-14.277171-31.994625-31.994625s14.277171-31.994625 31.994625-31.994625l191.967747 0c17.717453 0 31.994625-14.277171 31.994625-31.994625l0-159.973123c0-17.717453 14.277171-31.994625 31.994625-31.994625s31.994625 14.277171 31.994625 31.994625l0 159.973123C928.016126 884.840585 884.840585 928.016126 832.032253 928.016126z" p-id="2459"></path>
                  <path d="M351.94087 928.016126l-159.973123 0c-52.980346 0-95.983874-43.003528-95.983874-95.983874l0-159.973123c0-17.717453 14.277171-31.994625 31.994625-31.994625S159.973123 654.341676 159.973123 672.05913l0 159.973123c0 17.717453 14.449185 31.994625 31.994625 31.994625l159.973123 0c17.717453 0 31.994625 14.277171 31.994625 31.994625C383.935495 913.738955 369.658324 928.016126 351.94087 928.016126z" p-id="2460"></path>
                  <path d="M127.978498 383.935495c-17.717453 0-31.994625-14.277171-31.994625-31.994625l0-159.973123c0-52.980346 43.003528-95.983874 95.983874-95.983874l159.973123 0c17.717453 0 31.994625 14.277171 31.994625 31.994625S369.658324 159.973123 351.94087 159.973123l-159.973123 0c-17.545439 0-31.994625 14.449185-31.994625 31.994625l0 159.973123C159.973123 369.658324 145.695952 383.935495 127.978498 383.935495z" p-id="2461"></path>
                  <path d="M896.021502 383.935495c-17.717453 0-31.994625-14.277171-31.994625-31.994625l0-159.973123c0-17.545439-14.277171-31.994625-31.994625-31.994625L639.892491 159.973123c-17.717453 0-31.994625-14.277171-31.994625-31.994625s14.277171-31.994625 31.994625-31.994625l191.967747 0c52.980346 0 95.983874 43.003528 95.983874 95.983874l0 159.973123C928.016126 369.658324 913.738955 383.935495 896.021502 383.935495z" p-id="2462"></path>
                </svg>
              </div>
            </div>
            <div class="form-group row vertical-center" :class="[$v.f_gasbrand_id.required ? 'has-error' : '']">
              <label class="col-xs-4 control-label">气表品牌：</label>
              <div class="col-xs-8">
                <input type="text" v-show="false" v-model="userfile.f_gasbrand_id" :value.sync="userfile.f_gasbrand_id" v-validate:f_gasbrand_id = "['required']" >
                <input-select
                  class="select select_list"
                  :value.sync="userfile.f_gasbrand_id"
                  v-model="userfile.f_gasbrand_id"
                  :options="meterBrandList"
                  @change="gasbrandChange()"
                  :disable="mark === 1 || gasbrandDisable"
                  :valueSingle="true"></input-select>
              </div>
            </div>
            <div class="form-group row vertical-center" :class="[$v.f_gasmodel_id.required ? 'has-error' : '']">
              <label class="col-xs-4 control-label">气表型号：</label>
              <div class="col-xs-8">
                <input type="text" v-show="false" v-model="userfile.f_gasmodel_id" :value.sync="userfile.f_gasmodel_id" v-validate:f_gasmodel_id = "['required']" >
                <input-select
                  class="select select_list"
                  :value.sync="userfile.f_gasmodel_id"
                  v-model="userfile.f_gasmodel_id"
                  :options.sync="gasModelList"
                  :disable="mark === 1 || gasbrandDisable"
                  :valueSingle="true"></input-select>
              </div>
            </div>
            <template v-if="showInstall">
            <div class="form-group row vertical-center" :class="[$v.f_meternumber.required ? 'has-error' : '']">
              <label class="col-xs-4 control-label">表&emsp;&emsp;号：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" style=""
                       placeholder="表号" v-validate:f_meternumber = "['required']"
                       v-model="userfile.f_meternumber"
                       :value.sync="userfile.f_meternumber"
                       @change="meternumberValidate()"
                       :readonly="mark === 1"/>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">表&ensp;封&ensp;号：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" style=""
                       placeholder="表封号"
                       v-model="userfile.f_metertitles"
                       :value="userfile.f_metertitles"
                       :readonly="mark === 1"/>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">表&ensp;读&ensp;数：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" style=""
                       type="number"
                       placeholder="表读数"
                       v-model="userfile.f_meter_base"
                       :value="userfile.f_meter_base"
                       :readonly="false"/>
              </div>
            </div>
            <div class="form-group row vertical-center" v-show="false">
              <label class="col-xs-4 control-label">初始底数：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" style=""
                       type="number"
                       v-model="userfile.f_initial_base"
                       :value="userfile.f_meter_base"
                       placeholder="初始底数"
                       :readonly="mark === 1"/>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">表&emsp;&emsp;向：</label>
              <div class="col-xs-8">
                <input-select
                  class="select select_list"
                  :value.sync="userfile.f_aroundmeter"
                  v-model="userfile.f_aroundmeter"
                  :options="aroundmeters"
                  :disable="mark === 1"
                  :valueSingle="true"></input-select>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">安装位置：</label>
              <div class="col-xs-8">
                <input-select
                  class="select select_list"
                  :value.sync="userfile.f_position"
                  v-model="userfile.f_position"
                  :options="positions"
                  :disable="mark === 1"
                  :valueSingle="true"></input-select>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">安&ensp;装&ensp;人：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" style=""
                       v-model="userfile.f_install_person"
                       :value.sync="installperson(userfile.f_install_person)"
                       placeholder="安装人"
                       readonly/>
              </div>
            </div>
            <div class="form-group row vertical-center">
              <label class="col-xs-4 control-label">安装日期：</label>
              <div class="col-xs-8">
                <input class="form-control input_view" style=""
                       v-model="userfile.f_install_date"
                       :value.sync="installdate(userfile.f_install_date)"
                       placeholder="安装日期"
                       readonly/>
              </div>
            </div>
            </template>
          </div>
        </article>
        <footer slot="modal-footer" class="modal-footer">
          <template v-if="mark !== 1">
            <button type="button" class="btn btn-primary" @click="saveUserFile" :disabled="!$v.valid">确认</button>
          </template>
        </footer>
      </modal>
    </validator>
    <validator name="x">
      <modal v-if="showDeleteModel" :show.sync="showDeleteModel" v-ref:modal :large="true" :backdrop="false">
        <header slot="modal-header" class="modal-header">
          <button type="button" class="close" @click="closeUserFile"><span>&times;</span></button>
          <h4 class="modal-title">销户原因</h4>
        </header>
        <article slot="modal-body" class="modal-body clearfix">
          <div class="form-group row vertical-center" :class="[$v.f_cancel_cause.required ? 'has-error' : '']">
            <label class="col-xs-2 control-label">销户原因：</label>
            <div class="col-xs-10">
              <input class="form-control input_view" style=""
                     placeholder="销户原因"
                     v-validate:f_cancel_cause = "['required']"
                     v-model="userinfo.f_cancel_cause"
                     :value.sync="userinfo.f_cancel_cause"/>
            </div>
          </div>
        </article>
        <footer slot="modal-footer" class="modal-footer">
          <button type="button" class="btn btn-primary" @click="deleteUser" :disabled="!$x.valid">确认</button>
        </footer>
      </modal>
    </validator>
  </div>

</template>
<script>
import Vue from 'vue'
import {PagedList} from 'vue-client'
import {HttpResetClass} from 'vue-client'
import {isEmpty} from '../../../Util'

export default {
  title: '安装明细',
  props: {
    selectdata: {
      type: Object
    },
    mark: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      showModal: false,
      model: new PagedList(`${this.$androidUtil.getProxyUrl()}/rs/sql/getApplyUserinfo`, 10),
      criteriaShow: false,
      areaList: [],
      area: {},
      modelCode: '',
      userinfo: {},
      userfile: {},
      meterBrandList: [],
      gasModelList: [],
      showUserInformation: {},
      scanCodeConfig: null,
      gasbrandDisable: false,
      showDeleteModel: false,
      DeleteUserInfo: false,
    }
  },
  ready () {
    this.copydata()
    this.search()
    this.getMeterBrand()
    this.getAreaList()
    this.getScanCodeConfig()
    this.showDeleteUserInfo()
  },
  methods: {
   showDeleteUserInfo () {
     if(this.selectdata.f_apply_type === '民用报建' && (this.selectdata.defname === '报建受理' || this.selectdata.defname === '现场勘察')){
       this.DeleteUserInfo=true
     }
    },
    copydata(){
      if(!isEmpty(this.selectdata.f_building)){
        this.$refs.cp.$refs.cri.model.f_building=this.selectdata.f_building
      }
      if(!isEmpty(this.selectdata.f_unit)){
        this.$refs.cp.$refs.cri.model.f_unit=this.selectdata.f_unit
      }
      if(!isEmpty(this.selectdata.f_room)){
        this.$refs.cp.$refs.cri.model.f_room= this.selectdata.f_room
      }
    },

    async getScanCodeConfig () {
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `${this.$androidUtil.getProxyUrl()}/rs/logic/getScanCodeConfig`,
        null,
        {resolveMsg: null, rejectMsg: '扫码配置获取失败！！！'}
      )
      this.scanCodeConfig = res.data
    },
    // 查询
    search() {
      this.$refs.cp.$refs.cri.search();
    },
    searchCondition(args){
      if (this.selectdata.f_apply_type === '分户挂表') {
        args.condition += `  and  ui.f_userinfo_id = '${this.selectdata.f_userinfo_id}'`
      }else {
        args.condition += ` and ui.f_process_id = '${this.selectdata.f_process_id}'`
      }
      if(!isEmpty(this.model.f_building)){
        args.condition += " and ui.f_building like '"+this.model.f_building+"%'"
      }
      if(!isEmpty(this.model.f_unit)){
        args.condition+= " and ui.f_unit like '"+this.model.f_unit+"%'"
      }
      if(!isEmpty(this.model.f_room)){
        args.condition += " and ui.f_room like '"+this.model.f_room+"%'"
      }
      this.model.search(args.condition, args.model);
    },
    clear () {
      Object.keys(this.$refs.cp.$refs.cri.model).forEach((key) => {
        this.$refs.cp.$refs.cri.model[key] = null
      })
    },
    async scanCode () {
      console.log('===============扫码===================')
      HostApp.__this__ = this,
        HostApp.scanCode({callback: "javascript:HostApp.__this__.getCode();"})
      await this.getCode()
    },
    async getCode () {
      let code = HostApp.getCode().data;
      // let code = '012199312345'
      console.log('===========扫码结果=============')
      console.log(code)
      if (isEmpty(code)){
        return
      }
      if (!/^\d{12}$/.test(code)) {
        this.$showAlert('表号不符合规则', 'danger', 3000)
        return
      }
      // 解析厂家
      let factory = null
      for (const item of this.scanCodeConfig.factory) {
        if (item.key === code.substring(0, 2)) {
          factory = item.val
          break
        }
      }
      if (isEmpty(factory)) {
        this.$showAlert('未知厂家！！！', 'danger', 3000)
        return
      }
      console.log(factory)
      // 解析运营商
      let ips = null
      for (const item of this.scanCodeConfig.ips) {
        if (item.key === code.substring(5, 6)) {
          ips = item.val
          break
        }
      }
      if (isEmpty(ips)) {
        this.$showAlert('未知运营商！！！', 'danger', 3000)
        return
      }
      console.log(ips)
      //气表品牌
      if (code.startsWith('01')) {
        var num1 = this.getMeterBrands('金卡NB物联网表')
        this.userfile.f_gasbrand_id = num1
      } else if (code.startsWith('02') || code.startsWith('22')) {
        var num2 = this.getMeterBrands('千嘉NB物联网表')
        this.userfile.f_gasbrand_id = num2
      } else if (code.startsWith('03')) {
        var num2 = this.getMeterBrands('先锋NB民用物联网表')
        this.userfile.f_gasbrand_id = num2
      }
      //气表型号
      if (code.substring(4, 5) == 7 || code.substring(4, 5) == 0) {
        await this.gasbrandValue('JGD1.6-NNB物联网表')
        const  value=this.modelCode
        this.userfile.f_gasmodel_id = value
      } else if (code.substring(4, 5) == 8 ||code.substring(4, 5) == 1) {

        await this.gasbrandValue('JGD2.5-NNB物联网表')
        const  value1=this.modelCode
        this.userfile.f_gasmodel_id =value1
      } else if (code.substring(4, 5) == 9 ||code.substring(4, 5) == 2) {
        await this.gasbrandValue('JGD4S-NNB物联网表')
        const value2 =this.modelCode
        this.userfile.f_gasmodel_id = value2
      }
      // 表向
      console.log(code.substring(6, 7) % 2 === 0 ? '偶数' : '奇数')
      console.log(code.substring(6, 7) % 2 === 0 ? '右表' : '左表')
      this.userfile.f_aroundmeter = code.substring(6, 7) % 2 === 0 ? '右表' : '左表'
      // 顺序号
      console.log(code.substring(7, 12))
      if (code.substring(7, 12) < this.scanCodeConfig.number.min || code.substring(7, 12) > this.scanCodeConfig.number.max) {
        this.$showAlert('顺序号超出范围！！！', 'danger', 3000)
        return
      }
      for (const item of this.meterBrandList) {
        if (item.label === factory) {
          // this.userfile.f_gasbrand_id = item.value
          // this.gasbrandChange()
          break
        }
      }
      Vue.set(this.userfile, 'f_meternumber', code)
      this.meternumberValidate()
    },
    async gasbrandValue (name) {
      let data = {
        f_gasbrand_id: this.userfile.f_gasbrand_id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `${this.$androidUtil.getProxyUrl()}/rs/sql/getGasModel`,
        {data: data},
        {resolveMsg: null, rejectMsg: '气表型号查询失败！！！'}
      ).then(res => {
        for (const re of res.data) {
          if (re.label == name) {
            this.modelCode= re.value
            return re.value;
          }
        }
        return  'null'
      })
    },
    getMeterBrands (name) {
      for (const brand of this.meterBrandList) {
        if(brand.label==name){
          return  brand.value
        }
      }
      return   'null'
    },
    async deleteUserinfo (row) {
      this.userinfo = row
      let res = await this.$showMessage('此操作不可撤回，您确定要删除这条记录吗？')
      if (res === 'cancel') {
        return
      }
      this.showDeleteModel = !this.showDeleteModel
    },
    async deleteUser () {
      let res = await this.$showMessage('此操作不可撤回，您确定要删除这条记录吗？')
      if (res === 'cancel') {
        return
      }

      let data = {
        login: Vue.user,
        userinfo: this.userinfo,
        selectdata: this.selectdata
      }
      res = await this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/logic/applyDeleteUserinfo`, {data:data}, {
        resolveMsg: null,
        rejectMsg: '删除失败！！！'
      })

      this.$dispatch('breakControl', this.selectdata)
    },
    // 保存档案
    async saveUserFile() {
      if (this.selectdata.defname === '工程施工') {
        this.meternumberValidate()
        if(  this.selectdata.f_apply_type === '民用报建'){
          if (this.userfile.f_meter_base - 0 === 0 || this.userfile.f_meter_base - 0 > 1.5) {
            this.$showAlert('表读数必须大于0小于或等于1.5！', 'warning', 3000)
            throw '表读数必须大于0小于或等于1.5！'
          }
        }
        if(  this.selectdata.f_apply_type === '非民用报建'){
          if (this.userfile.f_meter_base - 0 === 0 || this.userfile.f_meter_base - 0 >30) {
            this.$showAlert('表读数必须大于0小于或等于30！', 'warning', 3000)
            throw '表读数必须大于0小于或等于30！'
          }
        }
      }
      if (this.userfile.f_gasbrand_id && this.userfile.f_meternumber) {
        let data = {
          f_meternumber: this.userfile.f_meternumber,
          f_gasbrand_id: this.userfile.f_gasbrand_id
        }
        if (this.userfile.f_user_id) {
          data.f_user_id = this.userfile.f_user_id
        }
        let http = new HttpResetClass()
        let res = await http.load("POST",`${this.$androidUtil.getProxyUrl()}/rs/logic/meterbrandsNumberValidate`, {data:data}, {
          resolveMsg: null,
          rejectMsg: '表号验证失败！！'
        })
        console.log(`查询结果${res.data}`)
        console.log(res.data)
        if (!/^\d{12}$/.test(this.userfile.f_meternumber)) {
          if(!/^\d{14}$/.test(this.userfile.f_meternumber)){
            this.$showAlert('表号不符合规则', 'danger', 3000)
            return
          }
        }
        if (res.data === '表号已存在' || res.data === '表号无效') {
          this.userfile.f_meternumber = ''
          this.$showAlert(res.data, 'danger', 3000)
          throw res.data
        }
      }
      let data = {
        user: Vue.user,
        userinfo: this.userinfo,
        userfile: this.userfile,
        selectdata: this.selectdata
      }
      let res = await this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/logic/applyAddUserinfo`, {data:data}, {
        resolveMsg: null,
        rejectMsg: '用户档案添加失败！！！'
      })
      // this.$showMessage('用户档案添加成功！！！')
      this.$showAlert('用户档案添加成功！！！', 'success', 3000)
      // this.search()  避免分页时，点击确定后，分页返回第一页
      this.showModal= false
      console.log("分页数据",this.model)
      this.selectdata.f_building=this.model.model.f_building
      this.selectdata.f_unit=this.model.model.f_unit
      this.selectdata.f_room=this.model.model.f_room
      this.selectdata.pageIndex=this.model.pageIndex
      this.$dispatch('breakControl', this.selectdata)
    },
    ifDisable() {
      if ( this.selectdata.defname === '工程施工') {
        this.gasbrandDisable = true
      }
    },
    // 检查表号是否存在
    async meternumberValidate() {
      if (!this.userfile.f_gasbrand_id) {
        this.userfile.f_meternumber = ''
        this.$showAlert('请先选择气表品牌！！！', 'warning', 3000)
        return
      }
      if (this.userfile.f_gasbrand_id && this.userfile.f_meternumber) {
        let data = {
          f_meternumber: this.userfile.f_meternumber,
          f_gasbrand_id: this.userfile.f_gasbrand_id
        }
        if (this.userfile.f_user_id) {
          data.f_user_id = this.userfile.f_user_id
        }
        let http = new HttpResetClass()
        let res = await http.load("POST",`${this.$androidUtil.getProxyUrl()}/rs/logic/meterbrandsNumberValidate`, {data:data}, {
          resolveMsg: null,
          rejectMsg: '表号验证失败！！'
        })
        console.log(`查询结果${res.data}`)
        console.log(res.data)
        if (!/^\d{12}$/.test(this.userfile.f_meternumber)) {
          if(!/^\d{14}$/.test(this.userfile.f_meternumber)){
            this.$showAlert('表号不符合规则', 'danger', 3000)
            return
          }
        }
        if (res.data === '表号已存在' || res.data === '表号无效') {
          this.userfile.f_meternumber = ''
          this.$showAlert(res.data, 'warning', 3000)
        }
      }
    },
    // 选择气表品牌
    async gasbrandChange() {
      // 清空已保存的气表型号
      this.userfile.f_gasmodel_id = null
      if (isEmpty(this.userfile.f_gasbrand_id)) {
        return
      }
      if (this.userfile.f_gasbrand_id === 'null') {
        this.gasModelList.push({label: '无', value: 'null'})
        this.userfile.f_meter_classify = 'null'
        return
      }
      let data = {
        f_gasbrand_id: this.userfile.f_gasbrand_id
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `${this.$androidUtil.getProxyUrl()}/rs/sql/getGasModel`,
        {data: data},
        {resolveMsg: null, rejectMsg: '气表型号查询失败！！！'}
      )

      this.gasModelList = res.data

      // data = {
      //   tablename: 't_gasbrand',
      //   condition: `id = '${this.userfile.f_gasbrand_id}'`
      // }
      // res = await http.load(
      //   'POST',
      //   `${this.$androidUtil.getProxyUrl()}/rs/sql/applySingleTable`,
      //   {data: data},
      //   {resolveMsg: null, rejectMsg: '表具类型查询失败！！！'}
      // )
      // this.userfile.f_meter_classify = res.data[0].f_meter_type
      this.userfile.f_meter_classify = '物联网表'
    },
    // 地址拼接
    addressSplicing () {
      let f_area = this.userinfo.f_area || ''
      let f_slice_area = this.userinfo.f_slice_area || ''
      let f_street = this.userinfo.f_street || ''
      let f_residential_area = this.userinfo.f_residential_area || ''
      let f_building = this.userinfo.f_building || ''
      let f_building_suffix = f_building ? '号楼' : ''
      let f_unit = this.userinfo.f_unit || ''
      let f_unit_suffix = f_unit ? '单元' : ''
      let f_floor = this.userinfo.f_floor || ''
      let f_floor_suffix = f_floor ? '层' : ''
      let f_room = this.userinfo.f_room || ''
      let f_room_suffix = f_room ? '室' : ''

      Vue.set(this.userinfo, 'f_address', f_area + f_slice_area + f_street + f_residential_area + f_building + f_building_suffix + f_unit + f_unit_suffix + f_floor + f_floor_suffix + f_room + f_room_suffix)
    },
    // 选择小区
    changeArea () {
      if (isEmpty(this.area)) {
        return
      }

      this.userinfo.f_area = this.area.f_area
      this.userinfo.f_slice_area = this.area.f_slice_area
      this.userinfo.f_street = this.area.f_street
      this.userinfo.f_residential_area = this.area.f_residential_area
      this.userinfo.f_residential_area_id = this.area.id
    },
    // 打开安装明细
    async openModal (row) {
      this.ifDisable()
      if (row) {
        console.log('------------------修正---------------------')
        this.userinfo = row

        if (this.userinfo.f_residential_area_id) {
          let data = {
            tablename: 't_area_address',
            condition: `id = '${this.userinfo.f_residential_area_id}'`
          }
          let http = new HttpResetClass()
          let res = await http.load(
            'POST',
            `${this.$androidUtil.getProxyUrl()}/rs/sql/applySingleTable`,
            {data: data},
            {resolveMsg: null, rejectMsg: '小区查询失败！！！'}
          )

          this.area = res.data[0]
        }

        let data = {
          tablename: 't_userfiles',
          condition: `f_userinfo_id = ${row.f_userinfo_id}`
        }
        let http = new HttpResetClass()
        let res = await http.load(
          'POST',
          `${this.$androidUtil.getProxyUrl()}/rs/sql/applySingleTable`,
          {data: data},
          {resolveMsg: null, rejectMsg: '表档案查询失败！！！'}
        )
        this.userfile = res.data[0]

        if (this.userfile.f_gasbrand_id === 0) {
          this.userfile.f_gasbrand_id = null
        }
        if (this.userfile.f_gasmodel_id === 0) {
          this.userfile.f_gasmodel_id = null
        }
        if(isEmpty(this.userfile.f_position)){
          this.userfile.f_position = '室内'
        }
        if (!isEmpty(this.userfile.f_gasbrand_id)) {
          let data = {
            f_gasbrand_id: this.userfile.f_gasbrand_id
          }
          let http = new HttpResetClass()
          let res = await http.load(
            'POST',
            `${this.$androidUtil.getProxyUrl()}/rs/sql/getGasModel`,
            {data: data},
            {resolveMsg: null, rejectMsg: '气表型号查询失败！！！'}
          )

          this.gasModelList = res.data
        }
      }
      if (this.selectdata.f_residential_area_id) {
        let data = {
          tablename: 't_area_address',
          condition: `id = '${this.selectdata.f_residential_area_id}'`
        }
        let http = new HttpResetClass()
        let res = await http.load(
          'POST',
          `${this.$androidUtil.getProxyUrl()}/rs/sql/applySingleTable`,
          {data: data},
          {resolveMsg: null, rejectMsg: '小区查询失败！！！'}
        )

        this.area = res.data[0]
        this.selectArea(this.area.f_residential_area)
        this.changeArea()
        this.addressSplicing()
      }

      // 档案回填定位信息
      this.userinfo.f_lng = this.selectdata.f_lng
      this.userinfo.f_lat = this.selectdata.f_lat
      this.userinfo.f_location_address = this.selectdata.f_order_address
      if(!row){
        // 档案回填用户信息
        this.showUserInformation.f_user_name = this.selectdata.f_user_name
        this.showUserInformation.f_user_phone = this.selectdata.f_phone
        this.showUserInformation.f_credentials = this.selectdata.f_credentials
        this.showUserInformation.f_idnumber = this.selectdata.f_idnumber
      }
      this.showModal = true
    },
    // 获取气表品牌
    async getMeterBrand () {
      let data = {
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `${this.$androidUtil.getProxyUrl()}/rs/sql/getMeterBrand`,
        {data: data},
        {resolveMsg: null, rejectMsg: '气表品牌查询失败！！！'}
      )

      this.meterBrandList = res.data
      this.meterBrandList.push({label: '无', value: 'null'})
    },
    // 获取小区
    async getAreaList () {
      let data = {
        tablename: 't_area_address',
        condition: `f_filiale like '%${"榆林."+Vue.user.orgs}%' and f_area_status = '启用'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `${this.$androidUtil.getProxyUrl()}/rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '小区查询失败！！！'}
      )
      this.areaList = res.data.map(item => {
        item.id = String(item.id)
        return {
          label: item.f_residential_area,
          value: item
        }
      })
    },
    //搜索小区
    selectArea (val) {
      let pcdText = `and f_residential_area like '%${val}%'`
      let data = {
        tablename: 't_area_address',
        condition: `f_filiale like '%${"榆林."+Vue.user.orgs}%' and f_area_status = '启用' ${pcdText}`
      }
      new HttpResetClass().load("POST", `${this.$androidUtil.getProxyUrl()}/rs/sql/applySingleTable`, {data:data}, {resolveMsg: null, rejectMsg: null}).then((res)=>{
        console.log('请求发送完成！！！！！'+JSON.stringify(res))
        if(res.data.length>0){
          this.areaList = res.data.map(item => {
            item.id = String(item.id)
            return {
              label: item.f_residential_area,
              value: item
            }
          })
        }
      })
    },
    // 关闭安装明细
    closeUserFile() {
      this.showModal = false
      this.area = {}
      this.userinfo = {}
      this.userfile = {}
      this.gasModelList = {}
      this.showDeleteModel = false
      this.search()
    }
  },
  events: {
  },
  computed: {

    showAddress () {
      return this.selectdata.f_apply_type === '民用报建' || this.selectdata.f_apply_type === '设备拆除'
    },
    showUserInfo () {
      return (this.selectdata.f_apply_type === '民用报建' && this.selectdata.f_apply_nature !== '分户挂表') || (this.selectdata.f_apply_type === '设备拆除')    },
    showUserFile () {
      return (this.selectdata.f_apply_type === '民用报建' && this.selectdata.f_apply_nature !== '分户挂表' && this.selectdata.defname === '工程施工') ||
        this.selectdata.f_apply_type === '非民用报建' ||
        this.selectdata.f_apply_type === '设备变更' ||
        this.selectdata.f_apply_type === '设备拆除' ||
        this.selectdata.f_apply_type === '分户挂表'
    },
    showInstall () {
      return (this.showUserFile && (this.selectdata.defname === '工程施工' || this.selectdata.defname === '施工通气' ||
        this.selectdata.defname === '点火通气')) || (this.selectdata.f_apply_type === '设备拆除')
    },
    // 证件类型
    credentialsList() {
      return this.$appdata.getParam('证件类型')
    },
    // 安装人
    installperson() {
      return function (f_install_person) {
        if (isEmpty(f_install_person)) {
          return Vue.user.name
        }
        return f_install_person
      }
    },
    // 安装时间
    installdate() {
      return function (f_install_date) {
        if (isEmpty(f_install_date)) {
          return new Date().Format('yyyy-MM-dd HH:mm:ss')
        }
        return f_install_date
      }
    },
    // 表向
    aroundmeters() {
      return this.$appdata.getParam('左右表')
    },
    // 安装位置
    positions() {
      return this.$appdata.getParam('安装位置')
    }
  },
  watch: {
  }
}
</script>
<style scoped>
.panel {
  margin-bottom: 8px;
}
.panel-self{
  border-radius: 10px;
  border:1px solid #499EDF;
  padding: 8px;
}
.button_shrink_top {
  width: 34px;
  height: 34px;
  border: solid 1px #6aa6e2;
  background-size: 100%;
  background-image: url("../../../../../static/newStyle/stretch_top.png")
}

.button_shrink_bottom {
  width: 34px;
  height: 34px;
  border: solid 1px #6aa6e2;
  background-size: 100%;
  background-image: url("../../../../../static/newStyle/stretch_bottom.png")
}
</style>
