<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' class="search_area" @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 " style="width: 20%">
            <label class="font_normal_body">用户姓名</label>
            <input type="text" class="input_search" style="width:60%" v-model="model.f_user_name"
                         placeholder="用户姓名"
                   condition="f_user_name like '%{}%'">
          </div>
          <div class="col-sm-4 " style="width: 20%">
            <label class="font_normal_body">用户电话</label>
            <input type="text" class="input_search" style="width:60%" v-model="model.f_user_phone"
                         placeholder="用户电话"
                   condition="f_user_phone like '%{}%'">
          </div>
          <div class="col-sm-4 " style="width: 20%">
            <label class="font_normal_body">用户编号</label>
            <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code"
                       placeholder="用户编号"
                   condition="f_userinfo_code like '%{}%'">
          </div>
          <div class="col-sm-4 " style="width: 20%">
            <label class="font_normal_body">小区名称</label>
            <input type="text" class="input_search" style="width:60%" v-model="model.f_residential_area"
                       placeholder="小区名称"
                   condition="f_residential_area like '%{}%'">
          </div>
          <div class="col-sm-4 " style="width: 20%;float: right">
            <div style="float: right;margin-top: 8px" class="button_spacing" :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"  @click="$parent.$parent.hidden()"></div>
            <div style="float: right;margin-top: 8px" class="button_spacing"
                 :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                 @click="$parent.$parent.hiddenr()"></div>
            <defects-chooser v-show="$parent.$parent.showModal"  v-ref:chooser></defects-chooser>
            <button class="button_search button_spacing" style="float: right; margin-top: 8px" @click="search()">查询</button>
          </div>
        </div>
          <div class="row">
          <div class="col-sm-4 " style="width: 20%" v-if="$parent.$parent.criteriaShow">
            <label class="font_normal_body">安检起始</label>
            <datepicker
              :value.sync="model.f_check_start"
              placeholder='开始时间'   style="width: 60%"
              :disabled-days-of-week="[]"
              :format="'yyyy-MM-dd'"
              :show-rest-button="reset"
              v-model = "model.f_check_start"
              condition="f_offsite_time >= '{} 00:00:00'">
            </datepicker>
          </div>
          <div class="col-sm-4 " style="width: 20%" v-if="$parent.$parent.criteriaShow">
            <label class="font_normal_body">安检结束</label>
            <datepicker
              :value.sync="model.f_check_end"
              placeholder='安检结束时间'
              style="width: 60%"
              :disabled-days-of-week="[]"
              :format="'yyyy-MM-dd'"
              :show-rest-button="reset"
              v-model = "model.f_check_end"
              condition="f_offsite_time <=  '{} 23:59:59'">
            </datepicker>
          </div>
          <div class="col-sm-4 " style="width: 20%" v-if="$parent.$parent.criteriaShow">
            <label class="font_normal_body">安&nbsp;&nbsp;检&nbsp;员</label>
            <v-select :value.sync="model.f_checker_id" v-model='model.f_checker_id'
                      :value-single="true"
                      class="select select_list" style="width: 60%"
                      :options='$parent.$parent.checkersid' placeholder='安检员'
                      close-on-select
                      condition="f_checker_id = '{}'"></v-select>
          </div>
          <div class="col-sm-4 " style="width: 20%" v-if="$parent.$parent.criteriaShow">
            <label class="font_normal_body">安检状态</label>
            <v-select
              placeholder='安检状态'
              :value-single="true"
              class="select select_list" style="width: 60%"
              v-model='model.f_entry_status'
              :value.sync="model.f_entry_status"
              :options='$parent.$parent.f_entry_status'
              condition="f_entry_status = '{}'"
              close-on-select clear-button> </v-select>
          </div>
          <div class="col-sm-4 " style="width: 20%" v-if="$parent.$parent.criteriaShow">
            <label class="font_normal_body">审核状态</label>
            <v-select id="f_approved"
                      placeholder='审核状态'
                      v-model='model.f_approved'
                      class="select select_list" style="width: 60%"
                      :value.sync="model.f_approved"
                      :options='$parent.$parent.f_approval_states'
                      condition="f_approved = '{}'"
                      close-on-select clear-button> </v-select>
          </div>
          <!--<div class="form-group">-->
          <!--<v-select id="f_approved"-->
          <!--placeholder='是否维修'-->
          <!--v-model='model.f_repaired'-->
          <!--:value.sync="model.f_repaired"-->
          <!--:options='$parent.$parent.f_repaired'-->
          <!--condition="f_repaired = '{}'"-->
          <!--close-on-select clear-button> </v-select>-->
          <!--</div>-->
          <div class="col-sm-4 " style="width: 20%" v-if="$parent.$parent.criteriaShow">
            <label class="font_normal_body">安&nbsp;&nbsp;检&nbsp;项</label>
            <v-select id="f_device_type"
                      placeholder='安检项'
                      class="select select_list" style="width: 60%"
                      v-model='model.f_device_type'
                      :value.sync="model.f_device_type"
                      :options='$parent.$parent.f_devices'
                      condition="f_devices.f_device_type = '{}'"
                      close-on-select clear-button> </v-select>
          </div>
          <div class="col-sm-4 " style="width: 20%" v-if="$parent.$parent.criteriaShow">
            <label class="font_normal_body">安检结果</label>
            <v-select
              placeholder='安检结果'
              :value-single="true"
              class="select select_list" style="width: 60%"
              v-model='model.f_check_result'
              :value.sync="model.f_check_result"
              :options='$parent.$parent.f_check_results'
              condition="f_defect_content  like '%{}%'"
              close-on-select clear-button> </v-select>
          </div>
          <div class="col-sm-4 " style="width: 20%" v-show="model.f_check_result == '有隐患'" v-if="$parent.$parent.criteriaShow">
            <label class="font_normal_body">隐患筛选</label>
            <input type="text" class="input_search" style="width:60%"
                   readonly="readonly"
                   placeholder="隐患筛选"
                   @click ="$parent.$parent.showDefects">
          </div>
          <!--<div class="col-sm-4 " style="width: 20%"  v-model="model.orgid">-->
          <!--<label class="font_normal_body">组织&nbsp;id</label>-->
          <!--<input type="text" v-show="false" class="input_search" style="width:60%"-->
          <!--      placeholder="组织id"-->
          <!--condition="orgid like '%{}%'">-->
          <!--</div>-->
          </div>
        </div>
      </criteria>

      <data-grid class="list_area table_sy" style="overflow: hidden" :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>安检状态</th>
            <th>审核状态</th>
            <th>用户名称</th>
            <th>用户编号</th>
            <th>入户时间</th>
            <th>离开时间</th>
            <th>安检人</th>
            <th>用户类型</th>
            <th>详细地址</th>
            <th>是否维修</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center">{{row.f_entry_status}}</td>
          <td style="text-align: center">{{row.f_approved}}</td>
          <td style="text-align: center">{{row.f_user_name}}</td>
          <td style="text-align: center">{{row.f_userinfo_code}}</td>
          <td style="text-align: center">{{row.f_onsite_time}}</td>
          <td style="text-align: center">{{row.f_offsite_time}}</td>
          <td style="text-align: center">{{row.f_checker_name}}</td>
          <td style="text-align: center">{{row.f_check_type}}</td>
          <td style="text-align: center">{{row.f_address}}</td>
          <td style="text-align: center">{{row.f_repaired}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  let select = function * (self) {
    let getGasman = yield self.$resetpost('/rs/search', {
      source: 'this.getParentByType($department$).getAllChildrens().where(row.getAttributes().get($rolestr$).indexOf($安检员$) != -1))',
      userid: self.$login.f.id
    }, {resolveMsg: null, rejectMsg: null})
    console.log('获取安检员', getGasman)
    getGasman.data.forEach((checker)=>{
    self.checkersid.push({label:checker.name,value:checker.id})
  })
    self.checkersid.push({label:'全部',value:''})
  }

  export default {
    title:'安检项查询',
    data() {
      let model = new PagedList('rs/path/getUserinfomation', 20)
      model.f_repaired = ['']
      model.f_check_plan = {f_plan_name: '', id: ''}
      model.f_approved = ['']
      model.f_no_checkplan = ['']
      model.f_filialeid = this.$login.f.orgid
      return {
        show:true,
        fun:this.$login.f,
        f_check_result:'',
        checkersid:[],
        criteriaShow:false,
        model: model,
        showModal: false,
        selfcondition:'',
        f_approval_states:  [{label: '全部', value: ''}, ...this.$appdata.getParam('安检单审核状态')],
        f_entry_status:  [{label: '全部', value: ''}, ...this.$appdata.getParam('安检状态')],
        f_devices:  [{label: '全部', value: ''}, ...this.$appdata.getParam('安检项')],
        f_check_results:  [{label: '全部', value: ''}, {label: '正常', value: '正常'},{label: '有隐患', value: '有隐患'}],
        f_repaired: [{label: '全部', value: ''},{label:'维修状态',value:''},{label:'已修',value:'已修'},{label:'未修',value:'未修'}]
      }
    },
    ready(){

      console.log('login-------',this.$login)
      this.$refs.paged.$refs.criteria.model.f_filialeid = this.$login.f.orgid
      this.$refs.paged.$refs.criteria.model.f_device_type = ['']

      let gen = select(this)
      return co(gen)
    },
    methods: {
        hidden() {
            this.criteriaShow = !this.criteriaShow
        },
        hiddenr() {
            this.$parent.showItem = !this.$parent.showItem
        },
      ok () {
        this.showModal = false
        let str = this.$refs.paged.$refs.criteria.$refs.chooser.condition.trim()
        if(str.length != 0) {
          let condition = ' and (' + this.$refs.paged.$refs.criteria.$refs.chooser.condition + ') '
          console.log(this.$refs.paged.$refs.criteria.$refs.chooser.condition)
          this.$set('selfcondition', condition)
        }else{
          this.$set('selfcondition', '')
        }
      },
      cancel () {
        this.showModal = false
        this.$set('selfcondition','')
    },
      search(args) {
        this.$parent.close()
        var str = args.condition
        str += this.selfcondition
        if(this.$refs.paged.$refs.criteria.model.f_entry_status == '未入户'){
          str = str.replace("f_entry_status = '未入户'", "f_entry_status != '入户'")
          console.log(args.condition)
          console.log(str)
        }
        this.model.search(str, args.model)

      },
      showDefects(){
        this.showModal = true
      }
    },

  }
</script>
