<template>
  <div class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group col-sm-4">
              <label class="font_normal_body">客户编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code"
                     placeholder='客户编号'
                     condition="tui.f_userinfo_code = '{}'" @keyup.enter="search()">
            </div>
            <div class="form-group col-sm-4" style="width: 20%">
              <label class="font_normal_body">用户类型</label>
              <v-select
                placeholder='用户类型'
                :value-single="true"
                v-model='model.user_type'
                :value.sync="model.user_type"
                class="select select_list"
                :options='$parent.$parent.user_types'
                condition=" t1.f_user_type = '{}' "
                close-on-select clear-button></v-select>
            </div>
            <div class="form-group col-sm-4" >
              <label class="font_normal_body">安检状态</label>
              <v-select style="width:60% "
                        class="select select_list"
                        :value.sync="model.f_state"
                        v-model="model.f_state"
                        :options='$parent.$parent.checkState'
                        placeholder='安检状态'
                        close-on-select
              >
              </v-select>
            </div>
            <div class="form-group col-sm-4" >
              <v-select style="width:60% "
                        v-if="model.f_state=='未入户'"
                        class="select select_list"
                        :value.sync="model.f_noruhu"
                        v-model="model.f_noruhu"
                        :options='$parent.$parent.noChecks'
                        placeholder='请选择状态'
                        :multiple="true"
              >
              </v-select>
            </div>
            <div class="form-group col-sm-4 button-range">
              <button class="button_search" style="margin-right: 10px" @click="search()" v-el:cba>查询</button>
              <export-excel-safe :data="$parent.$parent.searchData"
                                 :field="$parent.$parent.excelHeaders"
                                 sqlurl="rs/logic/SafeExportExcel" sql-name="getAreaSafeRatioUserList"
                                 template-name='小区安检用户明细'></export-excel-safe>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" class="table_sy" partial='list' 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>
          </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">{{row.f_user_phone}}</td>
            <td style="text-align:center;white-space: nowrap;">{{row.f_address}}</td>
            <td style="text-align:center">{{row.f_user_type}}</td>
            <td style="text-align:center">{{row.f_street}}</td>
            <td style="text-align:center">{{row.xcs}}</td>
            <td style="text-align:center">{{row.xftime}}</td>
            <td style="text-align:center">{{row.ajtime}}</td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  export default {
    title: '小区用户明细',
    data() {
      return {
        model: new PagedList('rs/sql/getAreaSafeRatioUserList', 50, {
          startyear: 'this.startyear',
          startmon: 'this.startmon',
          endyear: 'this.endyear',
          endmon: 'this.endmon'
        }),
        condition: '',
        startyear: '',
        startmon: '',
        endyear: '',
        checkState:[{label:'全部',value:''},{label:'入户',value:'入户'},{label:'未入户',value:'未入户'}],
        noChecks:[{label:'未检',value:'未检'},{label:'到访不遇',value:'到访不遇'},{label:'拒检',value:'拒检'}],
        user_types:[{label:'全部',value:''},{label:'民用',value:'民用'},{label:'非民用',value:'非民用'}],
        endmon: '',
        getfield: {},
        config: {
          excelHeaders: {
            'f_userinfo_code': '用户编号',
            'f_user_name': '用户姓名',
            'f_user_phone': '用户电话',
            'f_address': '用户地址',
            'f_user_type': '用户类型',
            'f_street': '所属区域',
            'xcs': '派发次数',
            'xftime': '最后一次派发时间',
            'ajtime': '最后一次安检时间',
          }
        }
      }
    },
    props: ['row'],
    ready() {
      console.log('打印一下~')
      this.search()
      this.getfield = this.config.excelHeaders
    },
    methods: {
      search() {
        this.$refs.paged.$refs.criteria.search()
      },
      selfSearch(args) {
        var cc = this.$parent.$refs.checksearch.model.condition
        if(cc.indexOf('非民用小区')!=-1){
         cc= "1=1 and tui.f_filialeid =  '" + this.$login.f.orgid + "'"
        }
        cc = cc.replace('and xfqk.f_userinfoid is not null','')
        cc = cc.replace('and xfqk.f_userinfoid is null','')
        this.model.startyear = this.$parent.$refs.checksearch.model.startyear
        this.model.startmon = this.$parent.$refs.checksearch.model.startmon
        this.model.endyear = this.$parent.$refs.checksearch.model.endyear
        this.model.endmon = this.$parent.$refs.checksearch.model.endmon
        this.condition = args.condition
        if (this.row.f_residential_area && this.row.f_residential_area!='非民用小区') {
          args.condition = args.condition + ' and ' + cc + " and tui.f_residential_area = '" + this.row.f_residential_area + "' "
        } else if (this.row.f_residential_area=='非民用小区'){
          args.condition = args.condition + ' and ' + cc + " and tui.f_user_type = '非民用' "
        }else if (this.row.f_residential_area == null){
          args.condition = args.condition + ' and ' + cc + " and tui.f_residential_area is null "
        }else if(this.row.f_residential_area == ''){
          args.condition = args.condition + ' and ' + cc + " and tui.f_residential_area = '' "
        }
        if (this.$refs.paged.$refs.criteria.model.f_state == '入户'){
          args.condition += ` and t1.f_last_check_state = '入户' `
        }else if(this.$refs.paged.$refs.criteria.model.f_state == '未入户'){
          args.condition += ` and t1.f_last_check_state != '入户' `
            if(this.$refs.paged.$refs.criteria.model.f_noruhu == '未检'){
              args.condition += ` and t1.f_state = '未检' `
            }else if (this.$refs.paged.$refs.criteria.model.f_noruhu != ''){
              args.condition += ` and t1.f_last_check_state = '${this.$refs.paged.$refs.criteria.model.f_noruhu}' `
            }
        }
        this.model.search(args.condition, args.model)
      },
      dealmsg(val) {
        this.$parent.f_userinfo_id = val.f_userinfo_id
        this.$parent.listpage = false
      }
    },
    watch: {
      'row'() {
        this.search()
      }
    }
  }
</script>
