<template>
  <div id='MbpeopleList' class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">用户编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code"
                     condition="f_userinfo_code like '%{}%'" placeholder='用户编号'>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">用户姓名</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_user_name"
                     condition="f_user_name like '%{}%'" placeholder='用户姓名'>
            </div>

            <div class="form-group button-range" style="float: right">
              <button class="button_search button_spacing" @click="$parent.$parent.search()">查询</button>
              <button class="button_clear button_spacing" @click="clear">清空</button>
              <!--              <button class="button_export button_spacing" @click="$parent.$parent.importFile">导入</button>-->
              <!--              <export-excel-->
              <!--                :data="{condition:$parent.$parent.condition}"-->
              <!--                :field="$parent.$parent.getfield"-->
              <!--                sqlurl="api/af-revenue/logic/exportfile" sql-name="salembPeopleList" template-name='表册用户导出'-->
              <!--                :choose-col="true"></export-excel>-->
              <div style="float: right" class="button_spacing"
                   :class="{'button_shrink_top': $parent.$parent.criteriaShow,'button_shrink_bottom': !$parent.$parent.criteriaShow}"
                   @click="$parent.$parent.criteriaShow = !$parent.$parent.criteriaShow"></div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <div class="col-sm-3 form-group">
              <label  class="font_normal_body">&nbsp;小&nbsp;区&nbsp;域</label>
              <v-select :value.sync="model.f_small_area" v-model="model.f_small_area"
                        :options='$parent.$parent.smallareas' placeholder='小区域'
                        close-on-select :search='true'
                        condition="f_small_area = '{}'"></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">用户电话</label>
              <input  type="text" class="form-control" v-model="model.f_user_phone" placeholder='用户电话'
                      condition="f_user_phone like '%{}%'" v-next-el='yhxm' style="width: 60%"
              >
            </div>
            <div class="form-group col-sm-3" title="参数名称：【用气类型】">
              <label class="font_normal_body" >用气类型</label>
              <v-select :value.sync="model.f_user_gas_type"
                        v-model="model.f_user_gas_type"
                        :multiple="true"
                        :options='$parent.$parent.usergastype' placeholder='请选择'
                        condition="f_user_gas_type in {}"
                        ></v-select>
            </div>
            <div class="form-group col-sm-3" title="参数名称：【用户标签】">
              <label class="font_normal_body" >用户标签</label>
              <v-select :value.sync="model.f_user_tags"
                        v-model="model.f_user_tags"
                        :multiple="true"
                        :options='$parent.$parent.usertags' placeholder='请选择'
                        condition="f_user_tags in {}"
                        ></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">客户类型</label>
              <v-select :options='$parent.$parent.user_type' :value.sync="model.f_user_type"
                        close-on-select condition="f_user_type='{}'"
                        placeholder='用户类型' v-model="model.f_user_type"></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">客户状态</label>
              <v-select :options='$parent.$parent.user_state' :value.sync="model.f_user_state"
                        close-on-select condition="f_user_state = '{}'"
                        placeholder='客户状态' v-model="model.f_user_state"></v-select>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">所属表册</label>
              <v-select :value.sync="model.f_check_book_num" v-model="model.f_check_book_num"
                        :options='$parent.$parent.meterbooks' placeholder='安检册'
                        :value-single="true"
                        condition="f_check_book_name='{}'"
                        style="width:60%"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">抄&nbsp;表&nbsp;员&nbsp;</label>
              <v-select :value.sync="model.f_inputtor" v-model='model.f_inputtor'
                        style="width:60%"
                        condition="f_inputtor in {}"
                        :options='$parent.$parent.inputtores' placeholder='抄表员'
                        close-on-select
                        v-el:cc></v-select>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">表箱号&emsp;</label>
              <input style="width:60%" type="text" class="form-control" v-model="model.f_metertitles"
                     condition="f_metertitles like '%{}%'"  placeholder='表箱号'
              >
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">用气性质</label>
              <v-select :options='$parent.$parent.gasproperties' :value.sync="model.f_gasproperties"
                        close-on-select condition="f_gasproperties='{}'"
                        placeholder='用气性质' v-model="model.f_gasproperties"></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">气表类型</label>
              <v-select :options='$parent.$parent.meter_classify' :value.sync="model.f_meter_classify"
                        close-on-select condition="f_meter_classify='{}'"
                        placeholder='气表类型' v-model="model.f_meter_classify"></v-select>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">气表品牌</label>
              <v-select :value.sync="model.f_meter_brand"
                        v-model="model.f_meter_brand"
                        :options='$parent.$parent.meterbrands' placeholder='请选择'
                        condition="f_meter_brand in {}"
                        close-on-select></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">气表状态</label>
              <v-select :options='$parent.$parent.table_state' :value.sync="model.f_table_state"
                        close-on-select condition="f_table_state = '{}'"
                        placeholder='气表状态' v-model="model.f_table_state"></v-select>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">小&emsp;区&emsp;</label>
              <input type="text" class="input_search" v-model="model.f_residential_area"  style="width: 60%"
                     condition=" f_residential_area like '{}%'" placeholder="输入小区">
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">客户地址</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_address"
                     condition="f_address like '%{}%'" placeholder='客户地址'>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">楼&emsp;号&emsp;</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_building"
                     condition="f_building = '{}'" placeholder='楼号'>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">组织机构</label>
              <res-select :initresid='$parent.$parent.curorgid'
                          @res-select="$parent.$parent.getorg"
                          class="select select_list"
                          restype='organization' :is-mul="false"
                          style="width: 60%">
              </res-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">是否在册</label>
              <v-select :options='$parent.$parent.whether_list'
                        :value.sync="model.f_book_name"
                        v-model="model.f_book_name"
                        close-on-select condition="f_check_book_name {}"
                        placeholder='是否在册' ></v-select>
            </div>
            <div class="col-sm-3 form-group">
              <label  class="font_normal_body">入户证号</label>
              <input style="width:60%" type="text" class="form-control" v-model="model.f_book_no"
                     condition="f_book_no like '%{}%'" placeholder='入户证号'
              >
            </div>
            <div class="col-sm-3 form-group">
              <label  class="font_normal_body">表&emsp;号&emsp;</label>
              <input style="width:60%" type="text" class="form-control" v-model="model.f_meternumber"
                     condition="f_meternumber like '%{}%'" placeholder='表号'
              >
            </div>

            <div class="col-sm-3 form-group">
              <label class="font_normal_body">街道/乡镇</label>
              <v-select :value.sync="model.f_street_id"
                        :multiple="true"
                        :options='$parent.$parent.streetslist' placeholder='请选择'
                        condition="f_street_id in {}"
                        v-model='model.f_street_id'
                        @change="$parent.$parent.streetChange"
                       :search="true" >
              </v-select>
            </div>
            <div class="col-sm-3 form-group">
              <label class="font_normal_body">片区/行政村</label>
              <v-select :value.sync="model.f_community_id"
                        :multiple="true"
                        v-model='model.f_community_id'
                        :options='$parent.$parent.communitylist'
                        placeholder='片区/管理站' filer-key="name"
                        condition="f_community_id in {}"
                        @change="$parent.$parent.communityChange"
                         v-ref:slice>
              </v-select>
            </div>
            <div  class="col-sm-3 form-group">
              <label class="font_normal_body">小区/自然村</label>
              <v-select :value.sync="model.f_residential_area_id"
                        :multiple="true"
                        :options='$parent.$parent.areaslist' placeholder='请选择'
                        condition="f_residential_area_id in {}"
                        v-model='model.f_residential_area_id'
                       >
              </v-select>
            </div>
            <div  class="col-sm-3 form-group">
              <label class="font_normal_body">开户时间</label>
              <datepicker
                :value.sync="model.f_open_date"
                placeholder='开户时间' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :select-month="true"
                v-model='model.f_open_date'
                :show-rest-button="reset">
              </datepicker>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid class="list_area table_sy" :model="model" partial='list' v-ref:grid :optional="true">
        <template partial='head'>
          <!--<th>-->
          <!--<input type="checkbox" id="f_operator" v-model="$parent.$parent.$parent.all[model.pageIndex-1]"-->
          <!--@change="$parent.$parent.$parent.select()"/>-->
          <!--</th>-->
          <th><nobr>序号</nobr></th>
          <th><nobr>客户编号</nobr></th>
          <th><nobr>客户名称</nobr></th>
          <th><nobr>客户状态</nobr></th>

          <th><nobr>区/县</nobr></th>
          <th><nobr>街道/乡镇</nobr></th>
          <th><nobr>片区/行政村</nobr></th>
          <th><nobr>小区/自然村</nobr></th>
          <th><nobr>客户地址</nobr></th>
          <th><nobr>表号</nobr></th>
          <th><nobr>气表状态</nobr></th>
          <th><nobr>所属表册</nobr></th>
<!--          <th><nobr>册内排序</nobr></th>-->
          <th><nobr>表箱号</nobr></th>
          <th><nobr>入户证号</nobr></th>
          <th><nobr>表底数</nobr></th>
        </template>
        <template partial='body'>
          <!--<td>-->
          <!--<input :id="'body'+model.pageIndex" type='checkbox' @change="$parent.$parent.$parent.selectOne($event,row,$index)"-->
          <!--:checked="$parent.$parent.$parent.ischecked(model.pageIndex-1,$index)"/>-->
          <!--</td>-->
          <td>{{$index+1}}</td>
          <td>{{row.f_userinfo_code}}</td>
          <td>{{row.f_user_name}}</td>
          <td>{{row.f_user_state}}</td>

          <td>{{row.f_pcd}}</td>
          <td>{{row.f_street}}</td>
          <td>{{row.f_community}}</td>
          <td>{{row.f_residential_area}}</td>
          <td>{{row.f_address}}</td>
          <td>{{row.f_meternumber}}</td>
          <td>{{row.f_table_state}}</td>
          <td>{{row.f_check_book_name}}</td>
<!--          <td>{{row.f_meter_book_sort}}</td>-->
          <!--          <td>{{row.f_adjustable_id}}</td>-->
          <td style="text-align:center">{{row.f_metertitles}}</td>
          <td style="text-align:center"><nobr>{{row.f_book_no}}</nobr></td>
          <td style="text-align:center">{{row.f_meter_base}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <modal :show.sync="show" width="500px" title="文件导入" v-ref:modal large backdrop="false">
    <article slot="modal-body" class="modal-body">
      <file-upload class="my-file-uploader " name="UploadFile"  style="border-radius: 2px;"
                   action="api/af-revenue/file/uploadFile" tagname="导入表册用户" v-ref:file  multiple></file-upload>
    </article>
    <footer slot="modal-footer" class="modal-footer">
    </footer>
  </modal>
</template>

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

let getAreaConfig = async function (self) {
  // 获取气价里面的配置
  await self.$getConfig(self, 'UserAddress')
  Object.assign(self.model, self.config)
  self.initdata()
}
let loadParamGem = async function (self) {
  await self.$LoadParams.loadParam()
  self.getfield = self.config.excelHeaders
  // self.$refs.paged.$refs.cri.model.f_meter_classify = ['机表']
  await self.initAdjustables()
  // await self.search()
}
export default {
  name: 'MbpeopleList',
  data () {
    return {
      f_filialeids: this.$login.f.orgid,
      // 初始化省市区数据
      pcdslist: [],
      //初始化街道数据
      streetslist:[],
      communitylist:[],
      areaslist: [],
      // 选中所有地址
      addresslist: [],
      sliceArea: [],
      orgCondtionStr: '',
      f_filialeid: this.$login.f.orgid,
      f_orgid: '',
      invoiceuse: [{label: '是', value: 'is not null'}, {label: '否', value: 'is null'}],
      model: new PagedList('rs/sql/getUserByCheckBookuser', 20),
      f_orgstr: this.$login.f.orgid,
      // 要操作的用户
      rowsdata: [],
      aaa: '',
      // 控制全选
      all: [],
      // 控制单选
      radio: [],
      show: false,
      meterbooks: [{label: '全部', value: ''}],
      criteriaShow: false,
      gasproperties: this.$appdata.getParam('用气性质') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')] : [],
      user_type: this.$appdata.getParam('用户类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')] : [],
      meter_classify: this.$appdata.getParam('气表类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')] : [],
      table_state: this.$appdata.getParam('气表状态') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('气表状态')] : [],
      f_small_areas: this.$appdata.getParam('小区域') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('小区域')] : [],
      user_state: [{label: '正常', value: '正常'}, {label: '预备', value: '预备'}, {label: '销户', value: '销户'}],
      whether_list: [{label: '全部', value: ''},{label: '已在册内', value: 'is not null'}, {label: '不在册内', value: 'is null'}],
      meterbrands: [],
      condition: '',
      adjustables: [],
      unnullrowdata: [],
      getfield: {},
      config: {
        // 导出列要和查询列相同
        excelHeaders: {
          'f_userfiles_id': '系统识别号',
          'f_userinfo_code': '用户编号',
          'f_user_name': '用户姓名',
          'f_address': '用户地址'
        }
      },
      curorgid: [this.$login.f.orgid]
    }
  },
  created () {
  },
  ready () {
    getAreaConfig(this)
    loadParamGem(this)
    this.getmeterbook()
  },
  methods: {
    async meterbook(){
      this.meterbooks=[]
      if(this.f_orgid==''){
        this.f_orgid=this.$login.f.orgid
      }
      let res=await this.$resetpost('rs/sql/tel_singleTable_OrderBy',{data:{items:' * ',tablename:'t_check_book',condition:` 1=1 `,orderitem:' id desc'}},{resolveMsg:null,rejectMsg:null})
      for(let i=0;i<res.data.length;i++){
        console.log("res",res.data[i])
        let temp=[]
        temp.label=res.data[i].f_check_book_name
        temp.value=res.data[i].id
        this.meterbooks.push(temp)
      }

    },
    invoiceuseChange (val) {
      // 查询已开票记录清空选项
      if (val == 'is not null') {
        this.rowsdata = []
        this.radio = []
      }
    },

    select () {
      let index = this.model.pageIndex - 1
      console.log('全选', this.all[index])
      if (!this.radio[index]) {
        this.radio.$set(index, [])
      }
      if (this.all[index]) {
        // 数据
        this.rowsdata[index] = Object.assign([], this.model.rows)
        // 勾选
        for (var i = 0; i < this.model.rows.length; i++) {
          this.radio[index].$set(i, true)
        }
      } else {
        // 数据
        this.rowsdata[index] = []
        // 不勾选
        for (var i = 0; i < this.model.rows.length; i++) {
          this.radio[index].$set(i, false)
        }
      }
      this.mergeRowData()
    },
    importFile () {
      this.show = true
    },
    async initAdjustables () {
      let arr = []
      let filter = this.$login.f.orgid
      this.$GetSaleParam.getAdjustable(filter).forEach((item) => {
        let temp = {}
        temp.label = '[' + item.value.f_adjustable_id + ']-' + item.label
        temp.value = item.value.id
        arr.push(temp)
      })
      this.adjustables = [{label: '全部', value: ''}, ...arr]
      // 初始化气表品牌
      let brandArr = []
      this.$GetSaleParam.getGasbrand().forEach((item) => {
        let temp1 = {}
        temp1.label = item.label
        temp1.value = item.value.f_meter_brand
        brandArr.push(temp1)
      })
      this.meterbrands = [{label: '全部', value: ''}, ...brandArr]
      //
      // // 加载安检册
      // console.log("------------------this.$GetSaleParam.getMeterBooks()",this.$GetSaleParam.getMeterBooks())
      // this.meterbooks = [{label: '全部', value: ''}, ...this.$GetSaleParam.getMeterBooks()]
    },
    search () {
      this.$refs.paged.$refs.cri.search()
      console.log('mbpeople this = ', this)
    },
    selfSearch (args) {
      let f_orgstr = this.orgCondtionStr ? this.orgCondtionStr : "and f_orgid in ('" + this.f_orgid + "')"
      args.condition = `${args.condition} ` + f_orgstr
      // args.condition += ` and f_orgid = ${this.f_orgstr}`
      if(args.model.f_open_date){
        args.condition += ` and  f_open_date <='${args.model.f_open_date}' `
      }
      this.condition = args.condition
      this.$parent.condition = this.condition
      this.model.search(args.condition, args.model)
    },
    // 合并二维数组并去空
    mergeRowData () {
      console.log('!!!!!!!!!!!!!数组去空', this.rowsdata)
      let data = []
      // 合并
      for (let array of this.rowsdata) {
        data.push.apply(data, array)
      }
      // 去空
      // 拓展数组去空值的方法
      Array.prototype.removeEmpty = function () {
        for (var i = 0; i < this.length; i++) {
          if (this[i] == '' || typeof (this[i]) == 'undefined') {
            this.splice(i, 1)
            i--
          }
        }
        return this
      }
      data = data.removeEmpty()
      this.unnullrowdata = []
      data.forEach((row) => {
        this.unnullrowdata.push(row.f_userfiles_id + '')
      })
      this.$parent.rowsdata = this.unnullrowdata
      // this.$parent.rowsdata = this.rowsdata
    },
    selectOne (event, row, i) {
      console.log('单选', event.target.checked)
      let index = this.model.pageIndex - 1
      if (!this.rowsdata[index]) {
        this.rowsdata[index] = []
      }
      if (!this.radio[index]) {
        this.radio.$set(index, [])
      }
      if (event.target.checked) {
        // 数据
        this.rowsdata[index][i] = row
        // 勾选
        this.radio[index].$set(i, true)
        // 判断是否全部选中
        var allState = true
        if (this.model.rows.length != this.radio[index].length) {
          allState = false
        }
        for (var state of this.radio[index]) {
          if (!state) {
            allState = false
          }
        }
        if (allState) {
          this.all.$set(index, true)
        } else {
          this.all.$set(index, false)
        }
      } else {
        // 数据
        this.rowsdata[index][i] = []
        // 不勾选
        this.radio[index].$set(i, false)
        // 任意取消一个则全选状态设为false
        this.all.$set(index, false)
      }
      this.mergeRowData()
    },
    getorg (val) {
      console.log('getorg:val=', val)
      console.log('getorg:this.f_orgid=', this.f_orgid)
      this.f_orgid = val
      this.f_filialeid = val[0]
    },
    async getmeterbook(){
      await this.meterbook()
      this.$emit('childre',this.meterbooks)
    },
    async initdata () {
      this.initAreas(this.f_filialeids)
      // 添加特殊地址选省市区

      this.initpcds(` f_orgid = '${this.f_filialeids}'`)
      this.initstreets(` f_orgid = '${this.f_filialeids}' `)
      this.initareas(` f_orgid = '${this.f_filialeids}'`)
    },
    // 初始化片区
    async initAreas (val) {
      if (val) {
        let getAllArea = await this.$resetpost('/rs/search', {
          source: 'this.getParentByType($organization$).getAllChildrens().where(row.getType() == $zone$)',
          userid: this.$login.f.id
        }, {resolveMsg: null, rejectMsg: '获取片区出错！！！'})

        let arr = getAllArea.data.filter((res) => {
          return res.parentid == val
        })
        console.log('过滤之后的片区', arr)
        this.sliceArea = []
        arr.forEach((res) => {
          this.sliceArea.push({label: res.name, value: res.name})
        })
      }
    },
    initModel () {
      if (this.row) {
        this.cleardata()
        this.model = Object.assign({}, this.model, this.row)
        // 处理片区代码
        this.model.slice_area = [{
          name: this.model.f_slice_area,
          code: this.model.f_area_code
        }]
      }
    },
    // 初始化省市区,添加街道
    async initpcds (pconditon) {
      this.pcdslist = []
      let HttpReset = new HttpResetClass()
      let req = await HttpReset.load('POST', 'api/af-revenue/sql/address_singleTableOrderBy?pageNo=1&pageSize=9999999', {
        data: {
          items: '*',
          tablename: 't_pcd',
          orderitem: 'id',
          condition: pconditon
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
      let redata = []
      req.data.forEach((row, n) => {
        redata[n] = {
          label: row.f_pcd,
          value: row.id,
          data: row,
          id: row.id
        }
      })
      this.pcdslist = redata
      console.log("xxxxxxxxxxxxxx")
      console.log(this.pcdslist)
      console.log("redataxxxxxxxx")
    },
    // 初始化街道 添加小区
    async initstreets (pconditon) {
      this.streetslist = []
      let HttpReset = new HttpResetClass()
      let req = await HttpReset.load('POST', 'api/af-revenue/sql/address_singleTableOrderBy', {
        data: {
          items: '*',
          tablename: 't_street',
          orderitem: 'id',
          condition: pconditon
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
      let redata = []
      req.data.forEach((row, n) => {
        redata[n] = {
          label: row.f_street,
          value: row.id,
          data: row,
          id: row.id
        }
      })
      this.streetslist = redata
      console.log("xxxxxxxxxxxxxx")
      console.log(this.streetslist)
      console.log("redataxxxxxxxx")
    },
    // 初始化小区添加小区
    async initareas (pconditon) {
      // if(this.usertype){
      //   pconditon=pconditon+` and  f_special='1' `
      // }
      this.areaslist = []
      let HttpReset = new HttpResetClass()
      let req = await HttpReset.load('POST', 'api/af-revenue/sql/address_singleTableOrderBy?pageNo=1&pageSize=9999999', {
        data: {
          items: '*',
          tablename: 't_area',
          orderitem: 'id',
          condition: pconditon
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
      let redata = []
      req.data.forEach((row) => {
        redata.push({
          label: row.f_residential_area,
          value: row.id,
          data: row,
          id: row.id
        })
      })
      this.areaslist = redata
    },
    //小区变化
    areaChange(val){
      console.log("小区变化",val)
      // 选择小区后级联出省市区和街道
      let selectArea // 选中的小区数据
      for (let row of this.areaslist) {
        if (val == row.value) {
          selectArea = row.data
          break
        }
      }
      if (selectArea) {
        this.model.f_street_id = selectArea.f_street_id
        this.model.f_pcd_id = selectArea.f_pcd_id
        this.model.f_community_id = selectArea.f_community_id
        console.log( this.model.f_community_id)

        this.initstreets(` f_filialeid = '${this.f_filialeids}' and id ='${selectArea.f_street_id}' `)
        this.initpcds(` f_filialeid = '${this.f_filialeids}' and id ='${selectArea.f_pcd_id}' `)
        if(selectArea.f_community_id){
          this.initcommunity(` f_filialeid = '${this.f_filialeids}' and id ='${selectArea.f_community_id}' `)
        }
        // this.model.f_slice_area = selectArea.f_slice_area
        // 拼接地址
        this.model.f_address = `${selectArea.f_street}${selectArea.f_community}${selectArea.f_residential_area}`
        console.log( this.model.f_community_id)
      }
      this.$nextTick(() => {
        this.$resetValidation()
      })
    },
    // 片区变化 f_area_code
    async areasChange (val) {
      console.log('街道变化', val)
      if (this.streetslist[0]) {
        var street = ''
        this.streetslist.forEach((item) => {
          if (item.id === val) {
            street = item.label
          }
        })
        // this.model.f_address = street
      }
      if (val) {
        // 那就把[小区]重新组织一下
        await this.initareas(` f_area_code ='${val}' `)
        if (this.$refs.paged.$refs.criteria.model.f_residential_area_id) {
          if (this.findbyid(this.areaslist, this.$refs.paged.$refs.criteria.model.f_residential_area_id)) {
            let street_id = this.findbyid(this.areaslist,this.$refs.paged.$refs.criteria.model.f_residential_area_id).f_street_id
            if (street_id != val) {
              this.$refs.paged.$refs.criteria.model.f_residential_area_id = ''
            }
          } else {
            this.$refs.paged.$refs.criteria.model.f_residential_area_id = ''
          }
        }
      }
    },
    //街道变化
    //初始化街道 添加小区
    async initcommunity(pconditon){
      this.communitylist = []
      let HttpReset = new HttpResetClass()
      let req = await HttpReset.load('POST', 'api/af-revenue/sql/address_singleTableOrderBy', {
        data: {
          items: '*',
          tablename: 't_community',
          orderitem: 'id',
          condition: pconditon
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
      let redata = []
      req.data.forEach((row, n) => {
        redata[n] = {
          label: row.f_community_name,
          value: row.id,
          data:row,
          id:row.id
        }
      })
      this.communitylist=redata
    },
    async streetChange(val) {
      if (val.length > 0) {
        // 使用数组来收集值
        const ids = [];
        for (let i = 0; i < val.length; i++) {
          ids.push(val[i]);
        }
        // 将数组转换为逗号分隔的字符串
        const strs = ids.join(',');
        // 调用 initcommunity 方法时确保 SQL 语法正确
        await this.initcommunity(`f_filialeid = '${this.f_filialeids}' and f_street_id in (${strs})`);
      }
    },
    async  communityChange(val){
      console.log(val)
      if(val.length > 0){
        // 使用数组来收集值
        const ids = [];
        for (let i = 0; i < val.length; i++) {
          ids.push(val[i]);
        }
        // 将数组转换为逗号分隔的字符串
        const strs = ids.join(',');
        await this.initareas(` f_filialeid = '${this.f_filialeids}' and f_community_id in (${strs}) `)
      }
    }
  },
  computed: {
    usergastype () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气类型')]
    },
    usertags () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户标签')]
    },
    ischecked () {
      return function (index, i) {
        if (!this.radio[index]) {
          return false
        }
        return this.radio[index][i]
      }
    },
    smallareas () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('小区域')]
    },
    inputtores () {
      // 获取抄表员
      console.log('获取抄表员', this.$login.f)
      let rs = []
      if (this.$login.f.f_gasman.length > 0) {
        for (let i = 0; i < this.$login.f.f_gasman.length; i++) {
          let temp = {
            label: this.$login.f.f_gasman[i].name,
            value: this.$login.f.f_gasman[i].name
          }
          rs.push(temp)
        }
      }
      this.inputtores2 = rs
      return [ ...rs]
    }
  },
  watch: {
    async 'f_orgid'(){
      this.meterbooks=[]
      await this.meterbook()
      this.$emit('childre',this.meterbooks)
    },
    batchMeterShow () {
      if (this.batchMeterShow == false) {
        // 将选的文件清空
        this.$refs.file.$el.querySelector('input').value = ''
      }
    },
    'f_filialeid' (val) {
      loadParamGem(this)
    }
  },
  events: {
    onFileUpload: function (file, res) {
      // let URL = res.f_downloadpath.substring(res.f_downloadpath.lastIndexOf(":\\") + 2)
      // res.f_downloadpath = "http://" + location.host + "/" + URL
      // res.f_downloadpath.replace('\\','/')
      this.$resetpost('api/af-revenue/logic/upLoadBookFile',
        {data: {
            condition: this.condition,
            filepath: res.f_downloadpath
          }
        },
        {resolveMsg: null, rejectMsg: '上传失败'}).then((res) => {
        this.show = false
        this.$showAlert(`导入成功`, 'success', 2000)
        this.search()
      })
    }
  }
}
</script>

<style lang="less">
#MbpeopleList {
  tr {
    th {
      text-align: center;
    }
    td {
      text-align: center;
    }
  }
}
</style>
