<template>
  <div class="basic-main" style="height: 100%">
    <div>
      <criteria-paged :model="model" v-ref:paged>
        <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
          <validator name='v' partial>
            <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
              <div class="row">
                <div class="col-sm-3">
                  <label class="font_normal_body">用户编号</label>
                  <input type="text" class="input_search"  v-model="model.f_userinfo_code"
                         placeholder='用户编号'
                         condition="ui.f_userinfo_code = '{}'">
                </div>

                <div class="col-sm-3">
                  <label class="font_normal_body">距上次安检</label>
                    <input type="number" class="input_search"  v-model="$parent.$parent.lastCheckDateStart" style="width: 20%;">
                  <label class="font_normal_body">到</label>
                    <input type="number" class="input_search"  v-model="$parent.$parent.lastCheckDateEnd" style="width: 20%;">
                  <span style="width: 20%" class="font_normal_body">
                    <input type="radio" value="天" v-model="$parent.$parent.checkDateUnit">天
                    <input type="radio" value="月" v-model="$parent.$parent.checkDateUnit">月
                  </span>
                </div>

                <div class="col-sm-3">
                  <label class="font_normal_body">&nbsp;公&nbsp;&nbsp;&nbsp;&nbsp;司&nbsp;</label>
                  <right-tree :userid.sync='$parent.$parent.userid' style="width: 60%;"
                              :source.sync='$parent.$parent.source' @re-res="$parent.$parent.getRes" ></right-tree>
                </div>

                <div class="col-sm-3" style="float:right;">
                  <div class="span" style="text-align: center;float: right;">
                    <button class="button_search" @click="search()">查询</button>
                    <export-excel   :data="$parent.$parent.searchData"
                                    :field="$parent.$parent.excelHeaders"
                                    sqlurl="api/af-safecheck/logic/exportfile" sql-name="SearchOverdueNoSafeCheck" template-name='超期未安检导出'></export-excel>
                    <div class="button_spacing" style = "float:right;"
                         :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom'
                     :!$parent.$parent.criteriaShow}"
                         @click="$parent.$parent.hidden()">
                    </div>
                  </div>
                </div>

              </div>
              <div class="row" v-show="$parent.$parent.criteriaShow">
                <div class="col-sm-3">
                  <label class="font_normal_body">用户姓名</label>
                  <input type="text" class="input_search"  v-model="model.f_user_name"
                         placeholder='用户姓名'
                         condition="ui.f_user_name like '%{}%'">
                </div>
                <div class="col-sm-3">
                  <label class="font_normal_body">联系电话</label>
                  <input type="text" class="input_search"  v-model="model.f_user_phone"
                         placeholder='联系电话'
                         condition="ui.f_user_phone like '%{}%'">
                </div>
                <div class="col-sm-3">
                  <label class="font_normal_body">用户类型</label>
                  <v-select id="f_user_type" closeOnSelect="true" search="false" valueSingle="false"
                            :value.sync="model.f_user_type" class="input-font"
                            :options='$parent.$parent.user_types' placeholder='请选择用户类型'
                            close-on-select clear-button
                            v-model="model.f_user_type" condition="uf.f_user_type='{}'"></v-select>
                </div>
                <div class="col-sm-3">
                  <label class="font_normal_body">用户地址</label>
                  <input type="text" class="input_search"  v-model="model.f_address"
                         placeholder='用户地址'
                         condition="ua.f_address like '%{}%'">
                </div>
                <div class="col-sm-3">
                  <label class="font_normal_body">气表状态</label>
                  <v-select id="f_table_state" closeOnSelect="true" search="false" valueSingle="false"
                            :value.sync="model.f_table_state" class="input-font"
                            :options='$parent.$parent.table_states' placeholder='请选择气表状态'
                            close-on-select clear-button
                            v-model="model.f_table_state" condition="uf.f_table_state='{}'"></v-select>
                </div>
              </div>
            </div>
          </validator>
        </criteria>
        <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
          <template partial='head'>
            <tr>
              <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>
            </tr>
          </template>
          <template partial='body'>
            <tr>
              <td style="text-align:center">{{ $index + 1 }}</td>
              <td style="text-align:center">{{ row.f_userinfo_code }}</td>
              <td style="text-align:center">{{ row.f_user_name }}</td>
              <td style="text-align:center">
                <nobr>{{ row.f_user_phone }}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{ row.f_address }}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{ row.f_meternumber }}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{ row.f_table_state }}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{ row.f_user_type }}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{ (row.f_defect_content).indexOf("正常")!=-1?'正常': '有隐患' }}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{ row.f_offsite_time }}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{ row.f_safecheck_type }}</nobr>
              </td>
            </tr>
          </template>
          <template partial='foot'></template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
</template>

<script>
import {PagedList} from "vue-client";


export default {
  title: "超期未安检查看",
  data () {
    let model = new PagedList('api/af-safecheck/sql/SearchOverdueNoSafeCheck', 20, {
      f_filialeid_id: 'this.f_filialeid_id',
      lastCheckDateStart: 'this.lastCheckDateStart',
      lastCheckDateEnd: 'this.lastCheckDateEnd',
    })
    model.f_filialeid_id = `('${this.$login.f.orgid}')`
    model.lastCheckDateStart = 1
    model.lastCheckDateEnd =  1

    return {
      criteriaShow:false,
      checkDateUnit: '天',// 时间单位
      lastCheckDateStart: 1,
      lastCheckDateEnd: 1,
      f_filialeid_id:`('${this.$login.f.orgid}')`, //分公司id
      model: model,
      userid: this.$login.f.id,
      source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() == $organization$))`,
      user_types: [
        {label: '请选择用户类型', value: ''},
        {label: '民用', value: '民用'},
        {label: '非民用', value: '非民用'},
      ],
      table_states:[{label: '请选择', value: ''},
        {label: '正常', value: '正常'},
        {label: '停用', value: '停用'}],
      excelHeaders:{
        'f_userinfo_code': '用户编号',
        'f_user_name': '用户名称',
        'f_user_phone': '用户电话',
        'f_meternumber': '表号',
        'f_table_state': '气表状态',
        'f_user_type': '用户类型',
        'f_defect_content': '最后一次入户结果',
        'f_offsite_time': '最后一次入户时间',
        'f_safecheck_type': '最后一次入户计划类型',
        'f_address': '用户地址',
      },
      searchData: {
        condition:'1=1',
        lastCheckDateStart: 1,
        lastCheckDateEnd: 1,
        f_filialeid_id: `('${this.$login.f.orgid}')`
      }
    }
  },
  methods: {
    hidden(){
      this.criteriaShow = !this.criteriaShow;
    },
    getRes(obj) {
      this.f_filialeid_id = this.$login.convertToIn(obj.resids);
    },
    selfSearch(args) {
      if (this.checkDateUnit==='天') {
        this.model.lastCheckDateStart = this.lastCheckDateStart;
        this.model.lastCheckDateEnd = this.lastCheckDateEnd;
      }else if (this.checkDateUnit==='月') {
        this.model.lastCheckDateStart = this.lastCheckDateStart * 30;
        this.model.lastCheckDateEnd = this.lastCheckDateEnd * 30;
      }
      this.model.f_filialeid_id = this.f_filialeid_id;
      return this.model.search(args.condition, args.model)
    }
  },
  ready () {

  },
  watch: {
    'model.lastCheckDateStart': function(val){
      this.searchData.lastCheckDateStart = val
    },
    'model.f_filialeid_id': function(val){
      this.searchData.f_filialeid_id = val
    },
    'model.lastCheckDateEnd': function(val){
      this.searchData.lastCheckDateEnd = val
    },
    'model.condition':{
      deep:true, //深度监听设置为 true
      handler:function (newVal,oldVal) {
        if(newVal){
          this.searchData.condition = newVal
        }
      }
    },
    'lastCheckDateStart' : function (val) {
      if (val) {
        if (val*1 == 0) {
          this.lastCheckDateStart = 1
        }
      }else {
          this.lastCheckDateStart = 1
      }
    },
    'lastCheckDateEnd' : function (val) {
      if (val) {
        if (val*1 == 0) {
          this.lastCheckDateEnd = 1
        }
      }else {
        this.lastCheckDateEnd = 1
      }
    }
  }
}
</script>

<style scoped>

</style>
