<template>
  <div style="height: 100%;width: 100%;padding:10px 0px 10px 0px;">
    <div class="auto">
      <div>
        <partial-view v-ref:pv>
          <div class="row text-left" style="padding-bottom: 10px">
            <div class="col-sm-6 text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">隐患类型:</label>
              <span class="col-sm-9">{{ rowdata.f_defect_type }}</span>
            </div>
            <div class="col-sm-6 text-left" style="padding-bottom: 10px">
              <span class="col-sm-6" v-show="otherSearch">
                <button class="btn" @click="hidden()" style="padding: 2px 8px">
                   <span class="glyphicon glyphicon-chevron-up"></span>
                </button>
              </span>
            </div>
          </div>
          <div class="row text-left">
            <div class="col-sm-6 text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">隐患名称:</label>
              <span class="col-sm-9">{{ rowdata.f_defect_name }}</span>
            </div>
            <div class="col-sm-6 text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">隐患描述:</label>
              <span class="col-sm-9">{{ rowdata.f_defect_value }}</span>
            </div>
          </div>
          <div class="row">
            <button class="btn btn-xs" v-show="!otherSearch" style="width: 100%" @click="hidden()">
              <span class="glyphicon glyphicon-chevron-down" style="color: #000;"></span>
            </button>
          </div>
          <div class="row" v-show="otherSearch">
            <div class="col-sm-6 text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">隐患等级:</label>
              <span class="col-sm-9">{{ rowdata.f_defect_level }}</span>
            </div>
            <div class="col-sm-6 text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">隐患来源:</label>
              <span class="col-sm-9">{{ rowdata.f_data_sources }}</span>
            </div>
          </div>
        </partial-view>
      </div>
    </div>
    <div class="auto row">
      <criteria-paged :model="model" v-ref:paged>
        <criteria partial='criteria' @condition-changed='$parent.search' v-ref:criteria>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row">
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">卡号/出厂编号</label>
                <input type="text" class="form-control" v-model="model.f_card_id"
                       style="height:34px;margin-top: 8px" placeholder="卡号/出厂编号"
                       condition="dc.f_card_id = '{}'">
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">表号</label>
                <input type="text" class="form-control" v-model="model.f_meternumber"
                       style="height:34px;margin-top: 8px" placeholder="表号"
                       condition="uf.f_meternumber = '{}'">
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <button class="button_search button_spacing" @click="search()">查询</button>
                <export-excel :data="$parent.$parent.getCondition"
                              :field="$parent.$parent.getfield"
                              sqlurl="rs/logic/SafeExportExcel"
                              sql-name="getDefectPitfallCenterByDefectInfo"
                              template-name='隐患用户导出'
                              :choose-col="true"></export-excel>
                <span class="col-sm-2" v-show="$parent.$parent.listOtherSearch">
                  <button class="btn" @click="$parent.$parent.listSearchHidden()" style="padding: 2px 8px">
                     <span class="glyphicon glyphicon-chevron-up"></span>
                  </button>
                </span>
              </div>
            </div>
            <div class="row" v-show="$parent.$parent.listOtherSearch">
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">用户名称</label>
                <input type="text" class="form-control" v-model="model.f_user_name"
                       style="height:34px;margin-top: 8px" placeholder="用户名称"
                       condition="ui.f_user_name = '{}'">
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">用户电话</label>
                <input type="text" class="form-control" v-model="model.f_user_phone"
                       style="height:34px;margin-top: 8px" placeholder="用户电话"
                       condition="ui.f_user_phone = '{}'">
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">小区</label>
                <input type="text" class="form-control" v-model="model.f_residential_area"
                       style="height:34px;margin-top: 8px" placeholder="小区"
                       condition="uad.f_residential_area = '{}'">
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">档案地址</label>
                <input type="text" class="form-control" v-model="model.f_address"
                       style="height:34px;margin-top: 8px" placeholder="档案地址"
                       condition="uad.f_address like '{}%'">
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">气表状态</label>
                <v-select placeholder='气表状态'
                          :value.sync="model.f_table_state"
                          :value-single="true"
                          :options='$parent.$parent.f_table_states'
                          v-model="model.f_table_state"
                          close-on-select clear-button
                          condition="uf.f_table_state  = '{}'">
                </v-select>
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">用户状态</label>
                <v-select placeholder='用户状态'
                          :value.sync="model.f_user_state"
                          :value-single="true"
                          :options='$parent.$parent.f_user_states'
                          v-model="model.f_user_state"
                          close-on-select clear-button
                          condition="ui.f_user_state  = '{}'">
                </v-select>
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">用户类型</label>
                <v-select placeholder='用户类型'
                          :value.sync="model.f_user_type"
                          :value-single="true"
                          :options='$parent.$parent.f_user_types'
                          v-model="model.f_user_type"
                          close-on-select clear-button
                          condition="uf.f_user_type  = '{}'">
                </v-select>
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">在用状态</label>
                <v-select placeholder='在用状态'
                          :value-single="true" style="margin-top: 8px"
                          :value.sync="$parent.$parent.is_reuse_state"
                          :options='$parent.$parent.is_reuse_states'
                          v-model="$parent.$parent.is_reuse_state"
                          close-on-select clear-button></v-select>
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">小区编号</label>
                <input type="text" class="form-control" v-model="model.oldareaid"
                       style="height:34px;margin-top: 8px" placeholder="小区编号"
                       condition="uad.oldareaid = '{}'">
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">行政区域</label>
                <v-select placeholder='行政区域'
                          :value.sync="model.f_distinct"
                          :value-single="true"
                          :options='$parent.$parent.distincts'
                          v-model="model.f_distinct"
                          close-on-select clear-button
                          condition="ui.f_distinct  = '{}'">
                </v-select>
              </div>
              <div class="col-sm-4 form-group form-input-group">
                <label class="control-label">新档案</label>
                <v-select placeholder='是否第二套档案'
                          :value.sync="model.f_second_state"
                          :value-single="true"
                          :options='$parent.$parent.is_to_userinfos'
                          v-model="model.f_second_state"
                          close-on-select clear-button
                          condition="ui.f_second_state {}">
                </v-select>
              </div>
            </div>
            <div class="row">
              <button class="btn btn-xs" v-show="!$parent.$parent.listOtherSearch" style="width: 100%"
                      @click="$parent.$parent.listSearchHidden()">
                <span class="glyphicon glyphicon-chevron-down" style="color: #000;"></span>
              </button>
            </div>
          </div>
        </criteria>
        <data-grid :model="model" 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>&ensp;&ensp;档&ensp;案&ensp;地&ensp;址&ensp;&ensp;</nobr>
              </th>
              <th>
                <nobr>小区编号</nobr>
              </th>
              <th>
                <nobr>&ensp;&ensp;小&ensp;区&ensp;地&ensp;址&ensp;&ensp;</nobr>
              </th>
              <th>
                <nobr>行政区域</nobr>
              </th>
              <th>
                <nobr>用户状态</nobr>
              </th>
              <th>
                <nobr>气表状态</nobr>
              </th>
              <th>
                <nobr>用户类型</nobr>
              </th>
            </tr>
          </template>
          <template partial='body'>
            <td>{{ row.f_card_id }}</td>
            <td>{{ row.f_meternumber }}</td>
            <td>{{ row.f_user_name }}</td>
            <td>{{ row.f_user_phone }}</td>
            <td>{{ row.f_address }}</td>
            <td>{{ row.oldareaid }}</td>
            <td>{{ row.f_residential_area }}</td>
            <td>{{ row.f_distinct }}</td>
            <td>{{ row.f_user_state }}</td>
            <td>{{ row.f_table_state }}</td>
            <td>{{ row.f_user_type }}</td>
          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
</template>

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

export default {
  title: '安检记录列表',
  props: ['row'],
  data () {
    return {
      rowdata: this.row,
      otherSearch: false,
      model: new PagedList('rs/sql/getDefectPitfallCenterByDefectInfo', 20),
      f_user_states: [{label: '全部', value: ''}, {label: '正常', value: '正常'}, {label: '隐患', value: '隐患'}],
      f_user_types: [{label: '全部', value: ''}, {label: '民用', value: '民用'}, {label: '非民用', value: '非民用'}],
      is_reuse_states: [{label: '全部', value: ''}, {label: '在用', value: '在用'}],
      is_to_userinfos: [{label: '全部', value: ''}, {label: '否', value: 'is null'}, {
        label: '是',
        value: 'is not null'
      }],
      is_reuse_state: '在用',
      f_table_states: [{label: '全部', value: ''}, {label: '正常', value: '正常'}, {
        label: '有误',
        value: '有误'
      }, {label: '拆除', value: '拆除'}, {label: '停用', value: '停用'}, {label: '弃用', value: '弃用'}, {
        label: '废除',
        value: '废除'
      }],
      distincts: [
        {label: '全部', value: ''},
        {label: '航天', value: '航天'},
        {label: '曲江', value: '曲江'},
        {label: '高新', value: '高新'},
        {label: '长安', value: '长安'},
        {label: '沣东', value: '沣东'},
        {label: '雁塔', value: '雁塔'},
        {label: '沣西', value: '沣西'},
        {label: '浐灞生态区', value: '浐灞生态区'}
      ],
      listOtherSearch: false
    }
  },
  ready () {
    this.rowdata = this.row
    this.selfSearch()
  },
  methods: {
    listSearchHidden () {
      this.listOtherSearch = !this.listOtherSearch
    },
    hidden () {
      this.otherSearch = !this.otherSearch
    },
    search (args) {
      args.condition = this.selfCondition(args.condition)
      this.model.search(args.condition, args.model)
    },
    selfCondition (condition) {
      if (this.is_reuse_state === '在用') {
        condition += ` and (( ui.f_second_state is null and ui.f_user_state != '弃用')  or (ui.f_second_state is not null and uf.f_meternumber is not null)) `
      }
      if (this.row.f_defect_type) {
        condition += `  and  dc.f_defect_type = '${this.row.f_defect_type}'`
      }
      if (this.row.f_defect_name) {
        condition += `  and  dc.f_defect_name = '${this.row.f_defect_name}'`
      }
      if (this.row.f_defect_value) {
        condition += `  and  dc.f_defect_value = '${this.row.f_defect_value}'`
      }
      if (this.row.f_defect_level) {
        condition += `  and  dc.f_defect_level = '${this.row.f_defect_level}'`
      }
      if (this.row.f_data_sources) {
        condition += `  and  dc.f_data_sources = '${this.row.f_data_sources}'`
      }
      if (this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_start_discover_time) {
        condition += ` and dc.f_discover_time  >= '${this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_start_discover_time} 00:00:00' `
      }
      if (this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_end_discover_time) {
        condition += ` and dc.f_discover_time  <='${this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_end_discover_time} 23:59:59'`
      }
      if (this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_last_start_defect_task_time) {
        condition += ` and dc.f_last_defect_task_time  >= '${this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_last_start_defect_task_time} 00:00:00'`
      }
      if (this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_last_end_defect_task_time) {
        condition += ` and dc.f_last_defect_task_time  <='${this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_last_end_defect_task_time} 23:59:59'`
      }
      if (this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_start_rectify_time) {
        condition += ` and dc.f_rectify_time  >= '${this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_start_rectify_time} 00:00:00'`
      }
      if (this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_end_rectify_time) {
        condition += ` and dc.f_rectify_time  <= '${this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_end_rectify_time} 23:59:59'`
      }
      if (this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_is_eliminate) {
        condition += ` and dc.f_is_eliminate  = '${this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_is_eliminate}'`
      }
      if (this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_rectify_mode) {
        condition += ` and dc.f_rectify_mode  = '${this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_rectify_mode}'`
      }
      if (this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_data_sources) {
        condition += ` and dc.f_data_sources  = '${this.$parent.$refs.checksearch.$refs.paged.$refs.criteria.model.f_data_sources}'`
      }
      return condition
    },

    selfSearch () {
      let condition = this.model.condition ? this.model.condition : ' 1=1'
      condition = this.selfCondition(condition)
      this.model.search(condition)
    }
  },
  watch: {
    'row' (val) {
      if (val) {
        this.rowdata = val
        this.model.condition = ' 1=1 '
        this.selfSearch()
      }
    }
  },
  computed: {
    getCondition () {
      let condition = this.$refs.paged.$refs.criteria.condition ? this.$refs.paged.$refs.criteria.condition : ' 1=1'
      condition = this.selfCondition(condition)
      return {
        condition: condition
      }
    },
    getfield () {
      let Config = {
        'f_card_id': '卡号',
        'f_meternumber': '表号',
        'f_user_name': '用户名称',
        'f_user_phone': '用户电话',
        'f_address': '档案地址',
        'oldareaid': '小区编号',
        'f_residential_area': '小区地址',
        'f_distinct': '行政区域',
        'f_user_state': '用户状态',
        'f_table_state': '气表状态',
        'f_user_type': '用户类型'
      }
      return Config
    }
  }
}
</script>
<style>
.defect-list-diy-modal .modal-dialog {
  height: 100%;
}
</style>
