<template>
  <div>
    <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="col-sm-4 form-group form-input-group" style="width: 20%">
            <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="f_user_name like '%{}%'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <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="f_user_phone like '%{}%'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">用户编号</label>
            <input type="text" class="form-control" v-model="model.f_userinfo_code"
                   style="height:34px;margin-top: 8px"    placeholder="用户编号"
                   condition="f_userinfo_code like '%{}%'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <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="f_residential_area like '%{}%'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">安检起始</label>
            <datepicker
              :value.sync="model.f_check_start"
              placeholder='开始时间'  style="margin-top: 8px"
              :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 form-group form-input-group" style="width: 20%">
            <label class="control-label">安检结束</label>
            <datepicker
              :value.sync="model.f_check_end"
              placeholder='安检结束时间' style="margin-top: 8px"
              :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 form-group form-input-group" style="width: 20%">
            <label class="control-label">安&nbsp;&nbsp;检&nbsp;员</label>
            <v-select :value.sync="model.f_checker_id" v-model='model.f_checker_id'
                      :value-single="true" style="margin-top: 8px"
                      :options='$parent.$parent.checkersid' placeholder='安检员'
                      close-on-select
                      condition="f_checker_id = '{}'"></v-select>
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">安检状态</label>
            <v-select
                      placeholder='安检状态'
                      :value-single="true" style="margin-top: 8px"
                      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 form-group form-input-group" style="width: 20%">
            <label class="control-label">审核状态</label>
            <v-select id="f_approved"
                      placeholder='审核状态'
                      v-model='model.f_approved' style="margin-top: 8px"
                      :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 form-group form-input-group" style="width: 20%">
            <label class="control-label">安&nbsp;&nbsp;检&nbsp;项</label>
            <v-select id="f_device_type"
                      placeholder='安检项' style="margin-top: 8px"
                      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 form-group form-input-group" style="width: 20%">
            <label class="control-label">安检结果</label>
            <v-select
              placeholder='安检结果'
              :value-single="true" style="margin-top: 8px"
              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 form-group form-input-group" style="width: 20%" v-show="model.f_check_result == '有隐患'">
            <label class="control-label">隐患筛选</label>
            <input type="text" class="form-control"
                   readonly="readonly" style="height:34px;margin-top: 8px"
                   placeholder="隐患筛选"
                   @click ="$parent.$parent.showDefects">
          </div>
          <!--<div class="col-sm-4 form-group form-input-group" style="width: 20%"  v-model="model.f_filialeids">-->
            <!--<label class="control-label">组织&nbsp;id</label>-->
            <!--<input type="text" v-show="false" class="form-control"-->
                   <!--style="height:34px;margin-top: 8px"      placeholder="组织id"-->
                   <!--condition="f_filialeids like '%{}%'">-->
          <!--</div>-->
          <div class="col-sm-4 form-group form-input-group" style="width: 20%;margin-top:8px;">
            <button class="button_search button_spacing" @click="search()">查询</button>
          </div>
          <defects-chooser v-show="$parent.$parent.showModal"  v-ref:chooser></defects-chooser>
        </div>
      </criteria>

      <data-grid :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>{{row.f_entry_status}}</td>
          <td>{{row.f_approved}}</td>
          <td>{{row.f_user_name}}</td>
          <td>{{row.f_userinfo_code}}</td>
          <td>{{row.f_onsite_time}}</td>
          <td>{{row.f_offsite_time}}</td>
          <td>{{row.f_checker_name}}</td>
          <td>{{row.f_user_type}}</td>
          <td>{{row.f_address}}</td>
          <td>{{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($organization$).getChildByName($安检员$).getUsers()',
      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_subcompany = this.$login.f.f_fengongsi
      model.f_filialeids = ''
      return {
        show:true,
        fun:this.$login.f,
        f_check_result:'',
        checkersid:[],
        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(){
      this.$refs.paged.$refs.criteria.model.f_filialeids = this.$login.f.f_orgids
      this.$refs.paged.$refs.criteria.model.f_device_type = ['']

      let gen = select(this)
      return co(gen)
    },
    methods: {
      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) {
        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>
