<template>
  <div style="margin-bottom: 20px" class="form-group select-overspread">
    <label class="control-label-justify control-label col-sm-3">选择用户</label>
    <div class="col-sm-10" >
      <button class="button_search button_spacing" type="button" style="width: max-content;position: absolute" @click="openSelect" :disabled="mark === 1">选择</button>
    </div>
  </div>

  <modal v-if="showselect" :show.sync="showselect" width="80%" title="用户信息" v-ref:modal large backdrop="false">
    <article slot="modal-body" class="modal-body" style="height: 600px!important;">
      <criteria-paged :model="model" v-ref:cp>
        <criteria partial='criteria' @condition-changed='$parent.$parent.searchCondition' v-ref:cri>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row">
              <div class="form-group col-sm-3">
                <label class="font_normal_body">客户编号：</label>
                <input type="text" style="width:60%" class="input_search" placeholder='客户编号' v-model="model.f_userinfo_id"
                       v-on:keyup.enter="search"
                       condition="ui.f_userinfo_id = '{}'">
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">客户名称：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name"
                       v-on:keyup.enter="search" condition="f_user_name like '%{}%'" placeholder='客户名称'>
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">客户电话：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_user_phone"
                       v-on:keyup.enter="search" condition="f_user_phone = '{}'" placeholder='客户电话'>
              </div>

              <div class="form-group col-sm-3 button-range">
                <button class="button_search button_spacing" @click.prevent="search" v-el:cx>查询</button>
                <button class="button_clear button_spacing"  @click.prevent="$parent.$parent.$parent.clear()">清空</button>
                <div
                  :class="{'button_shrink_top':$parent.$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.$parent.criteriaShow}"
                  @click="$parent.$parent.$parent.criteriaShow = !$parent.$parent.$parent.criteriaShow"
                  class="button_spacing"
                  style="float: right">
                </div>
              </div>
            </div>
            <div class="row" v-show="$parent.$parent.$parent.criteriaShow">
              <div class="form-group col-sm-3">
                <label class="font_normal_body">小&emsp;&emsp;区：</label>
                <v-select
                  v-model="model.f_residential_area"
                  placeholder='小区'
                  condition="f_residential_area = '{}'"
                  :value.sync="model.f_residential_area"
                   :options='$parent.$parent.$parent.area'
                  class="select select_list"
                  :value-single="true"
                  close-on-select ></v-select>
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">楼&emsp;&emsp;号：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_building"
                       v-on:keyup.enter="search" condition="f_building like '%{}%'" placeholder='楼号'>
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">单&emsp;&emsp;元：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_unit"
                       v-on:keyup.enter="search" condition="f_unit like '%{}%'" placeholder='单元'>
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">门&nbsp;牌&nbsp;号：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_room"
                       v-on:keyup.enter="search" condition="f_room like '%{}%'" placeholder='门牌号'>
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">客户地址：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_address"
                       v-on:keyup.enter="search" condition="f_address like '%{}%'" placeholder='客户地址'>
              </div>
            </div>
          </div>
        </criteria>
        <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy" style="height: 100%">
          <template partial='head'>
            <tr>
              <th style="white-space: nowrap;">序号</th>
              <th style="white-space: nowrap;">客户编号</th>
              <th style="white-space: nowrap;">客户名称</th>
              <th style="white-space: nowrap;">客户电话</th>
              <th style="white-space: nowrap;">地址信息</th>
              <th style="white-space: nowrap;">选择</th>
            </tr>
          </template>
          <template partial='body'>
            <tr >
              <td style="text-align: center;">
                <nobr><font>{{$index+1}}</font></nobr>
              </td>
              <td style="text-align: center;">
                <nobr><font>{{ row.f_userinfo_id }}</font></nobr>
              </td>
              <td style="text-align: center;">
                <nobr><font>{{ row.f_user_name }}</font></nobr>
              </td>
              <td style="text-align: center;">
                <nobr><font>{{ row.f_user_phone }}</font></nobr>
              </td>
              <td style="text-align: center;">
                <nobr><font>{{ row.f_address }}</font></nobr>
              </td>
              <td style="text-align: center;">
                <nobr><font>
                  <button type="button" name="button" class="button_export" @click.prevent="$parent.$parent.$parent.$parent.select(row)">确认选择</button>
                </font></nobr>
              </td>
            </tr>
          </template>
        </data-grid>
      </criteria-paged>
    </article>
    <footer slot="modal-footer" class="modal-footer">
    </footer>
  </modal>
</template>
<script>
import {HttpResetClass, PagedList} from 'vue-client'
import Vue from 'vue'

export default {
  title: '选择用户',
  props: {
    selectdata: {
      type: Object
    },
    mark: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      showselect: false,
      model: new PagedList('rs/sql/applyGetUserinfos', 20, null),
      criteriaShow: false,
      area: []
    }
  },
  ready () {
    this.getArea()
  },
  methods: {
    select (row) {
      this.$dispatch('selectUserinfo', row)

      this.showselect = false
    },
    searchCondition (args) {
      args.condition = `${args.condition} and ui.f_filiale like '%${"榆林."+this.$login.f.orgs}%' and ui.f_user_state = '正常'`
      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
      })
    },
    openSelect () {
      this.showselect = true
      setTimeout(() => {
        this.$refs.cp.$refs.cri.search()
      }, 100)
    },
    // 获取小区
    async getArea () {
      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.area =  res.data.map(item => {
        return {
          label: item.f_residential_area,
          value: item.id
        }
      })
    },
  },
  events: {
  },
  computed: {
  },
  watch: {
  }
}
</script>
<style scoped>
.control-label-justify {
  display: inline-block;
  vertical-align: top;
  width: 110px;
  text-align: justify;
  font-family: PingFang-SC-Bold;
}

.control-label-justify::after {
  content: "";
  display: inline-block;
  width: 100%;
  overflow: hidden;
  height: 0;
}
.input_view{
  padding: 8px;
  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>
