<template>
  <div style="float: right">
    <export-excel :data="getConditions"
                  :field="getfields"
                  sqlurl="rs/logic/applyExportfile"
                  sql-name="getApplyUserinfo"
                  template-name='用户信息导出'
                  :choose-col="true"></export-excel>
  </div>
  <div class="col-sm-12" style="margin: 20px 0px;">

    <criteria-paged :model="model" v-ref:cp>
      <criteria partial='criteria' @condition-changed='$parent.searchCondition' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
        </div>
      </criteria>
      <data-grid :model="model" v-ref:grid partial='list' class="list_area table_sy" style="padding: 0px">
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>客户编号</th>
            <th>客户名称</th>
            <th>客户电话</th>
            <th>身份证号</th>
            <th>地址信息</th>
            <th>表号</th>
            <th>气表品牌</th>
            <th>气表型号</th>
            <th>
              <button
                type="button"
                v-if="$parent.$parent.$parent.selectdata.f_apply_type !== '非民用报建'"
                class="btn btn-info head-but"
                @click="$parent.$parent.$parent.openModal()"
                :disabled="$parent.$parent.$parent.mark === 1 ||
                ($parent.$parent.$parent.model.count >= $parent.$parent.$parent.selectdata.f_apply_count &&
                $parent.$parent.$parent.selectdata.defname === '报建受理') ||
                ($parent.$parent.$parent.model.count >= $parent.$parent.$parent.selectdata.f_install_count &&
                $parent.$parent.$parent.selectdata.defname === '工程施工') ||
                $parent.$parent.$parent.selectdata.defname === '施工通气'"
              >添加用户</button>
              <button
                v-if="$parent.$parent.$parent.selectdata.defname === '工程施工'"
                type="button"
                class="btn btn-info head-but"
                @click="$parent.$parent.$parent.openSign()"
              >签字照片</button>
              <template v-if="$parent.$parent.$parent.selectdata.f_apply_type === '民用报建'">
                <button type="button" class="btn btn-info head-but" v-if="$parent.$parent.$parent.mark !== 1"
                        @click="$parent.$parent.$parent.importBefore()">导入</button>
                <a type="button" class="btn btn-info head-but" v-if="$parent.$parent.$parent.mark !== 1 && $parent.$parent.$parent.selectdata.f_apply_nature === '小区' && $parent.$parent.$parent.selectdata.defname !== '工程施工'"
                   href="/apply/download/excel/小区导入.xlsx" download>模板下载</a>
                <a type="button" class="btn btn-info head-but" v-if="$parent.$parent.$parent.mark !== 1 && $parent.$parent.$parent.selectdata.f_apply_nature === '散户' && $parent.$parent.$parent.selectdata.defname !== '工程施工'"
                   href="/apply/download/excel/散户导入模板.xlsx" download>模板下载</a>
                <export-excel :data="$parent.$parent.$parent.getCondition"
                              :field="$parent.$parent.$parent.getfield"
                              v-if="$parent.$parent.$parent.mark !== 1 && $parent.$parent.$parent.selectdata.f_apply_nature === '小区' && $parent.$parent.$parent.selectdata.defname === '工程施工'"
                              sqlurl="rs/logic/applyExportfile"
                              sql-name="getApplyUserinfoExcel"
                              template-name='待添加表号信息导出'
                              :choose-col="true"></export-excel>
              </template>
            </th>
          </tr>

        </template>
        <template partial='body'>
          <tr>
            <td style="text-align: center;">
              <nobr>{{$index+1}}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{row.f_userinfo_id}}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{row.f_user_name}}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{row.f_user_phone}}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{row.f_idnumber}}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{row.f_address}}{{row.f_address_detail}}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{row.f_meternumber}}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{row.f_meter_brand}}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{row.f_meter_style}}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>
                <button
                  type="button" name="button" class="btn btn-link"
                   @click="$parent.$parent.$parent.openModal(row)">
                  {{$parent.$parent.$parent.mark === 1 || row.f_user_state === '正常' ? '查看' : '修正'}}
                </button>
                <button
                  type="button" name="button" class="btn btn-link"
                  @click="$parent.$parent.$parent.deleteUserinfo(row)"
                  v-if="$parent.$parent.$parent.showDeleteUserInfo"
                  :disabled="$parent.$parent.$parent.mark === 1 || row.f_user_state === '正常'"
                >
                  销户
                </button>
                <button
                  type="button" name="button" class="btn btn-link"
                  @click="$parent.$parent.$parent.deleteUserinfo(row)"
                  v-if="$parent.$parent.$parent.newShowDeleteUserInfo"
                >
                  销户
                </button>
              </nobr>
            </td>
          </tr>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <modal v-if="showFile" :show.sync="showFile" v-ref:modal :backdrop="false" title="选择文件">
    <header slot="modal-header" class="modal-header">
      <button type="button" class="close" @click="closeFile"><span>&times;</span></button>
      <h4 class="modal-title">选择文件</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="form-group">
        <file-upload class="my-file-uploader" name="useraddressUploadFile" action="rs/file/uploadFile" tagname="确定" v-ref:file></file-upload>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer"></footer>
  </modal>
  <modal v-if="progressShow" :show.sync="progressShow" v-ref:modal :backdrop="false" title="导入进度">
    <header slot="modal-header" class="modal-header">
      <button type="button" class="close" @click="close"><span>&times;</span></button>
      <h4 class="modal-title">导入进度</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="progress" style="margin: 20px">
        <div class="progress-bar progress-bar-success progress-bar-striped active" :style="{width: percent}">
          {{ percent }}
        </div>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer"></footer>
  </modal>

  <modal v-if="Sign" :show.sync="Sign" 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="left col-sm-6 col-xs-6">
        <img-self :src="fileurl" width="100%" height="100%"></img-self>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <template v-if="mark !== 1 && userinfo.f_user_state !== '正常'">
      </template>
    </footer>
  </modal>
  <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-sm-12 panel panel-info" v-if="showUserInfo">
          <div class="panel-heading head col-sm-12" style="background-color: #e8f4ff;margin-bottom: 10px">
            <div class="col-sm-6 text-left">用户信息</div>
          </div>
          <div class="form-group col-sm-6" :class="[$v.f_user_name.required ? 'has-error' : '']">
            <label class="col-sm-4 control-label">客户名称：</label>
            <div class="col-sm-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 || userinfo.f_user_state === '正常'"
                     placeholder="客户名称"/>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">客户电话：</label>
            <div class="col-sm-8">
              <input class="form-control input_view" style=""
                     v-model="userinfo.f_user_phone"
                     :value.sync="showUserInformation.f_user_phone"
                     :readonly="mark === 1 || userinfo.f_user_state === '正常'"
                     placeholder="客户电话"/>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">证件类型：</label>
            <div class="col-sm-8">
              <input-select
                class="select select_list"
                :value.sync="showUserInformation.f_credentials"
                v-model="userinfo.f_credentials"
                :options="credentialsList"
                :disable="mark === 1 || userinfo.f_user_state === '正常'"
                :valueSingle="true"></input-select>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">证件号码：</label>
            <div class="col-sm-8">
              <input class="form-control input_view" style=""
                     placeholder="证件号码"
                     v-model="userinfo.f_idnumber"
                     :value="showUserInformation.f_idnumber"
                     :readonly="mark === 1 || userinfo.f_user_state === '正常'"/>
            </div>
          </div>
        </div>
        <!-- 地址信息 -->
        <div class="form-group col-sm-12 panel panel-info" v-if="showAddress">
          <div class="panel-heading head col-sm-12" style="background-color: #e8f4ff;margin-bottom: 10px">
            <div class="col-sm-6 text-left">地址信息</div>
          </div>
          <div class="form-group col-sm-6" :class="[$v.area.required ? 'has-error' : '']">
            <label class="col-sm-4 control-label">小区/巷道：</label>
            <div class="col-sm-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 || userinfo.f_user_state === '正常'"
                :valueSingle="true"></input-select>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">楼&emsp;&emsp;号：</label>
            <div class="col-sm-8">
              <input class="form-control input_view" placeholder="楼号"
                     v-model="userinfo.f_building"
                     :value="userinfo.f_building"
                     @change="addressSplicing"
                     :readonly="mark === 1 || userinfo.f_user_state === '正常'"/>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">单&emsp;&emsp;元：</label>
            <div class="col-sm-8">
              <input class="form-control input_view" placeholder="单元"
                     v-model="userinfo.f_unit"
                     :value="userinfo.f_unit"
                     @change="addressSplicing"
                     :readonly="mark === 1 || userinfo.f_user_state === '正常'"/>
            </div>
          </div>
          <div class="form-group col-sm-6" v-if="false">
            <label class="col-sm-4 control-label">楼&emsp;&emsp;层：</label>
            <div class="col-sm-8">
              <input class="form-control input_view" placeholder="楼层"
                     v-model="userinfo.f_floor"
                     :value="userinfo.f_floor"
                     @change="addressSplicing"
                     :readonly="mark === 1 || userinfo.f_user_state === '正常'"/>
            </div>
          </div>
          <div class="form-group col-sm-6" :class="[$v.f_room.required ? 'has-error' : '']">
            <label class="col-sm-4 control-label">门&ensp;牌&ensp;号：</label>
            <div class="col-sm-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 || userinfo.f_user_state === '正常'"/>
            </div>
          </div>
          <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label">地&emsp;&emsp;址：</label>
            <div class="col-sm-10">
              <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-sm-12 panel panel-info" v-if="showUserFile">
          <div class="panel-heading head col-sm-12" style="background-color: #e8f4ff;margin-bottom: 10px">
            <div class="col-sm-6 text-left">表具信息</div>
          </div>
          <div class="form-group col-sm-6" :class="[$v.f_gasbrand_id.required ? 'has-error' : '']">
            <label class="col-sm-4 control-label">气表品牌：</label>
            <div class="col-sm-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 || userinfo.f_user_state === '正常' || gasbrandDisable"
                :valueSingle="true"></input-select>
            </div>
          </div>
          <div class="form-group col-sm-6" :class="[$v.f_gasmodel_id.required ? 'has-error' : '']">
            <label class="col-sm-4 control-label">气表型号：</label>
            <div class="col-sm-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 || userinfo.f_user_state === '正常' || gasbrandDisable"
                :valueSingle="true"></input-select>
            </div>
          </div>
          <template v-if="showInstall">
          <div class="form-group col-sm-6" :class="[$v.f_meternumber.required ? 'has-error' : '']">
            <label class="col-sm-4 control-label">表&emsp;&emsp;号：</label>
            <div class="col-sm-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 || userinfo.f_user_state === '正常'"/>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">表&ensp;封&ensp;号：</label>
            <div class="col-sm-8">
              <input class="form-control input_view" style=""
                     placeholder="表封号"
                     v-model="userfile.f_metertitles"
                     :value="userfile.f_metertitles"
                     :readonly="mark === 1 || userinfo.f_user_state === '正常'"/>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">表&ensp;读&ensp;数：</label>
            <div class="col-sm-8">
              <input class="form-control input_view" style=""
                     type="number"
                     placeholder="表读数"
                     v-model="userfile.f_meter_base"
                     :value="userfile.f_meter_base"
                     :readonly="mark === 1 || userinfo.f_user_state === '正常'"/>
            </div>
          </div>
          <div class="form-group col-sm-6" v-show="false">
            <label class="col-sm-4 control-label">初始底数：</label>
            <div class="col-sm-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 || userinfo.f_user_state === '正常'"/>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">表&emsp;&emsp;向：</label>
            <div class="col-sm-8">
              <input-select
                class="select select_list"
                :value.sync="userfile.f_aroundmeter"
                v-model="userfile.f_aroundmeter"
                :options="aroundmeters"
                :disable="mark === 1 || userinfo.f_user_state === '正常'"
                :valueSingle="true"></input-select>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">安装位置：</label>
            <div class="col-sm-8">
              <input-select
                class="select select_list"
                :value.sync="userfile.f_position"
                v-model="userfile.f_position"
                :options="positions"
                :disable="mark === 1 || userinfo.f_user_state === '正常'"
                :valueSingle="true"></input-select>
            </div>
          </div>
          <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">安&ensp;装&ensp;人：</label>
            <div class="col-sm-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 col-sm-6">
              <label class="col-sm-4 control-label">安装日期：</label>
              <div class="col-sm-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>
        <div  class="form-group col-sm-12 panel panel-info" v-if="showUserFile" >
          <header slot="modal-header" class="modal-header">
            <h4 class="modal-title">表具设备信息</h4>
          </header>
          <div v-for="(i, item) in devicesinfo" class="form-group col-sm-12 panel panel-info">
              <div class="panel-heading head col-sm-12" style="background-color: #e8f4ff;margin-bottom: 10px">
                <div class="col-sm-12 text-left">设备{{$index+1}}信息</div>
              </div>
              <div class="form-group col-sm-3">
                <label class="col-sm-4 control-label">设备：</label>
                <div class="col-sm-8">
                  <input class="form-control input_view" style=""
                         placeholder="设备类型"
                         v-model="item.f_devices_type"
                         :value="item.f_devices_type"
                         readonly/>
                </div>
              </div>
              <div class="form-group col-sm-3">
                <label class="col-sm-4 control-label">编号：</label>
                <div class="col-sm-8">
                  <input class="form-control input_view" style=""
                         placeholder="设备编号"
                         v-model="item.f_devices_no"
                         :value="item.f_devices_no"
                         readonly/>
                </div>
              </div>
              <div class="form-group col-sm-3">
                <label class="col-sm-4 control-label">品牌：</label>
                <div class="col-sm-8">
                  <input class="form-control input_view" style=""
                         placeholder="设备品牌"
                         v-model="item.f_brand"
                         :value="item.f_brand"
                         readonly/>
                </div>
              </div>
              <div class="form-group col-sm-3">
                <label class="col-sm-4 control-label">型号：</label>
                <div class="col-sm-8">
                  <input class="form-control input_view" style=""
                         placeholder="设备型号"
                         v-model="item.f_devices_model"
                         :value="item.f_devices_model"
                         readonly/>
                </div>
              </div>
              <div class="form-group col-sm-3">
                <label class="col-sm-4 control-label">数量：</label>
                <div class="col-sm-8">
                  <input class="form-control input_view" style="" type="number"
                         placeholder="设备数量"
                         v-model="item.f_devices_num"
                         :value="item.f_devices_num"
                         readonly/>
                </div>
              </div>
              <div class="form-group col-sm-3">
                <label class="col-sm-4 control-label">功率：</label>
                <div class="col-sm-8">
                  <input class="form-control input_view" style=""
                         placeholder="设备功率"
                         type="number"
                         v-model="item.f_devices_tonnage"
                         :value="item.f_devices_tonnage"
                         readonly/>
                </div>
              </div>
              <div class="form-group col-sm-3">
                <label class="col-sm-4 control-label">日期：</label>
                <div class="col-sm-8">
                  <input class="form-control input_view" style=""
                         placeholder="安装日期"
                         v-model="item.f_install_date"
                         :value="item.f_install_date"
                         readonly/>
                </div>
              </div>
              <div class="form-group col-sm-3">
                <label class="col-sm-4 control-label">单位：</label>
                <div class="col-sm-8">
                  <input class="form-control input_view" style=""
                         placeholder="功率单位"
                         v-model="item.f_devices_tonnage_unit"
                         :value="item.f_devices_tonnage_unit"
                         readonly/>
                </div>
              </div>
            </div>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <template v-if="mark !== 1 && userinfo.f_user_state !== '正常'">
          <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="left col-sm-12 col-xs-12" :class="[$x.f_cancel_cause.required ? 'has-error' : '']">
          <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label">销户原因：</label>
            <div class="col-sm-10">
              <input class="form-control input_view" style=""
                     v-validate:f_cancel_cause = "['required']"
                     v-model="userinfo.f_cancel_cause"
                     :value.sync="userinfo.f_cancel_cause"
                     placeholder="销户原因"/>
            </div>
          </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>
</template>
<script>
import Vue from 'vue'
import {PagedList} from 'vue-client'
import {HttpResetClass} from 'vue-client'
import {isEmpty} from '../../../Util'
// Date格式化
Date.prototype.Format = function (fmt) {
  var o = {
    'M+': this.getMonth() + 1, // 月份
    'd+': this.getDate(), // 日
    'H+': this.getHours(), // 小时
    'm+': this.getMinutes(), // 分
    's+': this.getSeconds(), // 秒
    'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
    'S': this.getMilliseconds() // 毫秒
  }
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
  for (var k in o) {
    if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
  }
  return fmt
}

export default {
  title: '安装明细',
  props: {
    selectdata: {
      type: Object
    },
    mark: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      gasbrandDisable: false,
      showFile: false,
      showModal: false,
      model: new PagedList('rs/sql/getApplyUserinfo', 20, null),
      areaList: [],
      area: {},
      userinfo: {},
      userfile: {},
      meterBrandList: [],
      gasModelList: [],
      Sign: false,
      fileurl: null,
      devicesinfo: [],
      showUserInformation: {},
      showDeleteModel: false,
      uuid: '',
      percent: '0%',
      progressShow: false,
      // 定时器
      timer: null,
      getfield: {
        'f_userinfo_id': '  客户编号  ',
        'f_address': '     地址     ',
        'f_meternumber': '   表号  ',
        'f_aroundmeter': '  表向 '
      },
      getfields:{
        'f_userinfo_id':'客户编号',
        'f_user_name':'客户名称',
        'f_user_phone':'客户电话',
        'f_meter_brand':'气表品牌',
        'f_meter_style':'气表型号',
        'f_idnumber':'身份证号',
        'f_address':'地址',
        'f_meternumber':'表号'
      }
    }
  },
  ready () {
    this.search()
    this.getMeterBrand()
    this.getAreaList()
  },
  methods: {
    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: this.$login.f,
        userinfo: this.userinfo,
        selectdata: this.selectdata
      }
      res = await this.$resetpost('rs/logic/applyDeleteUserinfo', {data:data}, {
        resolveMsg: null,
        rejectMsg: '删除失败！！！'
      })

      this.$dispatch('breakControl', this.selectdata)
    },
    // 保存档案
    async saveUserFile () {
      if (this.selectdata.defname === '工程施工'){
        await 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.$showMessage('表读数必须大于0小于或等于1.5！')
            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.$showMessage('表读数必须大于0小于或等于30！')
            throw '表读数必须大于0小于或等于30！'
          }
        }
      }
      let data = {
        user: this.$login.f,
        userinfo: this.userinfo,
        userfile: this.userfile,
        selectdata: this.selectdata
      }
      let res = await this.$resetpost('rs/logic/applyAddUserinfo', {data:data}, {
        resolveMsg: null,
        rejectMsg: '用户档案添加失败！！！'
      })
      this.$dispatch('breakControl', this.selectdata)
    },
    ifDisable() {
      if (this.selectdata.f_apply_type === '非民用报建' && this.selectdata.defname === '工程施工') {
        this.gasbrandDisable = true
      }
    },
    // 检查表号是否存在
    async meternumberValidate() {
      if (!this.userfile.f_gasbrand_id) {
        this.userfile.f_meternumber = ''
        this.$showMessage('请先选择气表品牌！！！')
        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 res = await this.$resetpost('rs/logic/meterbrandsNumberValidate', {data:data}, {
          resolveMsg: null,
          rejectMsg: '表号验证失败！！'
        })
        console.log(`查询结果${res.data}`)
        console.log(res.data)
        if (res.data === '表号已存在' || res.data === '表号无效') {
          this.userfile.f_meternumber = ''
          this.$showMessage(res.data)
          throw res.data
        }
      }
    },
    // 选择气表品牌
    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',
        `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',
      //   `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
      // this.addressSplicing()
    },
    openSign(){
      this.getFiles()
      this.Sign = true
    },
    importBefore(){
      if (this.selectdata.f_apply_nature === '小区' && !this.selectdata.f_residential_area_id){
        this.$showMessage('请选择小区/巷道后导入')
      }else {
        this.showFile = !this.showFile
      }
    },
    async getFiles() {
      let http = new HttpResetClass()
      console.log('=========pc签字查看===============')
      let data = {
        tablename: 't_files',
        condition: `f_blobid = '${this.selectdata.f_process_id}' and defname = '工程施工' and fremarks = '报装手机签字文件'`
      }
      let res = await http.load('POST', `rs/sql/applySingleTable`, {data: data}, {
        warnMsg: null,
        resolveMsg: null
      })
      if(res.data.length > 0){
        console.log('=========签字地址===============',res.data[0])
        let URL = res.data[0].f_downloadpath.substring(res.data[0].f_downloadpath.lastIndexOf(":\\") + 2)
        res.data[0].f_downloadURL = "http://" + location.host + "/" + URL
        console.log("=====查看文件地址=====",res.data[0].f_downloadURL)
        this.fileurl = res.data[0].f_downloadURL
      }
    },
    // 打开安装明细
    async openModal (row) {
      this.ifDisable()
      if (row) {
        this.getDeviceList(row)
        console.log('------------------修正---------------------',row)
        this.userinfo = row


        let data = {
          tablename: 't_userfiles',
          condition: `f_userinfo_id = ${row.f_userinfo_id}`
        }
        let http = new HttpResetClass()
        let res = await http.load(
          'POST',
          `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_gasbrand_id)) {
          let data = {
            f_gasbrand_id: this.userfile.f_gasbrand_id
          }
          let http = new HttpResetClass()
          let res = await http.load(
            'POST',
            `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',
          `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 getDeviceList(row){
      let data = {
        tablename: 't_devices',
        condition: `f_userinfo_id = '${row.f_userinfo_id}'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applySingleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '设备查询失败！！！'}
      )
      this.devicesinfo = res.data
    },
    // 获取气表品牌
    async getMeterBrand () {
      let data = {
      }

      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `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 '%${"榆林."+this.$login.f.orgs}%' and f_area_status = '启用'`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `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 '%${"榆林."+this.$login.f.orgs}%' and f_area_status = '启用' ${pcdText}`
      }
      new HttpResetClass().load("POST", `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
            }
          })
        }
      })
    },
    searchCondition (args) {
      if (this.selectdata.f_apply_type === '分户挂表') {
        args.condition = args.condition + `and ui.f_userinfo_id = '${this.selectdata.f_userinfo_id}'`
      } else {
        args.condition = args.condition + `and ui.f_process_id = '${this.selectdata.f_process_id}'`
      }

      this.model.search(args.condition, args.model)
    },
    // 查询
    async search () {
      this.$refs.cp.$refs.cri.search()
    },
    // 关闭安装明细
    closeUserFile() {
      this.showModal = false
      this.devicesinfo = []
      this.area = {}
      this.userinfo = {}
      this.userfile = {}
      this.gasModelList = {}
      this.Sign = {}
      this.showDeleteModel = false
      this.search()
    },
    //关闭导入弹框
    closeFile() {
      this.showFile = false
      // 将选的文件清空
      this.$refs.file.$el.querySelector('input').value = ''
      this.search()
    },
    progressQuery() {
      console.log('导出进度开始查询')
      this.progressShow = true
      // 启动定时器之前先关闭定时器,防止之前的定时器未关闭
      this.closeTimer()
      // 立即执行一遍
      this.progressTask()
      this.timer = setInterval(this.progressTask, 3000)
    },
    async progressTask() {
      let http = new HttpResetClass()
      let res = await http.load('POST', `rs/logic/getBatchOperaPro`,{data: {uuid: this.uuid}}, {resolveMsg: null, rejectMsg: null})
      res = res.data
      console.log('进度数据', res)
      if (res.result.type === 'error') {
        this.$showMessage(`导入excel错误: ${res.result.msg}`)
        await http.load('POST', `rs/logic/updateApplyInstallCount`,{data: this.selectdata}, {resolveMsg: null, rejectMsg: null})
        this.close()
      } else {
        this.percent = Math.floor((res.current && res.total ? res.current/res.total*100 : 0)) + '%'

        console.log("导入当前进度",this.percent)
        // 进度100%
        if (this.percent === '100%') {
          await http.load('POST', `rs/logic/updateApplyInstallCount`,{data: this.selectdata}, {resolveMsg: null, rejectMsg: null})
          this.close()
        }
      }
    },
    // 关闭定时器
    closeTimer() {
      if (this.timer) {
        clearInterval(this.timer)
        this.timer = null
      }
    },
    guid() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        let r = Math.random() * 16 | 0,
          v = c == 'x' ? r : (r & 0x3 | 0x8)
        return v.toString(16)
      })
    },
    close() {
      this.closeTimer()
      this.progressShow = false
      this.percent = '0%'
      this.$dispatch('breakControl', this.selectdata)
    },
  },
  events: {
    async 'onFileUpload'(file, result) {
      this.uuid = this.guid();
      let data = {
        selectdata: this.selectdata,
        filepath: result.f_downloadpath,
        user: this.$login.f,
        mark: this.mark,
        uuid: this.uuid
      }
      let http = new HttpResetClass()
      let res = await http.load('POST',`rs/logic/importAddressAndUserinfo`, {data:data}, {
        resolveMsg: null, rejectMsg: '导入失败！！！', silent: true
      }, 0)
      this.showFile = false
      // 将选的文件清空
      this.$refs.file.$el.querySelector('input').value = ''
      this.progressQuery()
    }
  },
  computed: {
    getConditions () {
      return {
        condition: `ui.f_process_id = '${this.selectdata.f_process_id}'`,
        data: {
          userid: this.$login.f.id,
          f_filiale: "榆林."+this.$login.f.orgs
        }
      }
    },
    showDeleteUserInfo () {
      return this.selectdata.f_apply_type === '民用报建' &&
        (this.selectdata.defname === '报建受理' || this.selectdata.defname === '现场勘察')
    },
    newShowDeleteUserInfo () {
      return this.selectdata.f_apply_type === '设备拆除' && this.selectdata.defname === '核对气量'
    },
    showAddress () {
      return (this.selectdata.f_apply_type === '民用报建' || this.selectdata.f_apply_type === '设备拆除') && (this.selectdata.defname !== '工程施工')
    },
    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 this.$login.f.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('安装位置')
    },
    getCondition () {
      return {
        condition: `ui.f_process_id = '${this.selectdata.f_process_id}'`,
        data: {
          userid: this.$login.f.id,
          f_filiale: "榆林."+this.$login.f.orgs
        }
      }
    }
  },
  watch: {
  }
}
</script>
<style scoped>
  .head-but{
    margin-left: 5px;
    height: 34px;
    /*background-color: #6aa6e2;*/
    border-radius: 4px;
    font-family: PingFang;
    color: #ffffff;
  }
  /*清除model中的浮动*/
  .clearfix:after,.clearfix:before{
    display: table;
  }
  .clearfix:after{
    clear: both;
  }
  .input_view{
    background-color: #ffffff;
    border-radius: 2px;
    border: solid 1px #c7c7c7!important;
    color: #333333!important;
    font-size: 15px!important;
  }

  .input_view[readonly]{
    border: 1px solid #DDD!important;
    color:#ACA899!important;
  }
  .input_view:disabled{
    border: 1px solid #DDD!important;
    color:#ACA899!important;
  }
</style>
