<style>
  .bg {
    background-color: blue;
    height: 1px;
    border: 0;
  }
  .app-row {
    background-color: white;
    padding: 10px 10px 0 10px;
    border-bottom: 1px solid rgba(235, 235, 235, 0.5);
  }
  .search_input {
    border: 0;
    outline: none;
  }
  .font{
    font: 15px PingFang-SC-Medium;
    color: #666666;
  }
  .input-font{
    font: 15px PingFang-SC-Medium;
    color: #333333;
  }
  .btn-font{
    font:600 16px PingFang-SC-Bold;
    color: #499EDF;
  }
  .btn-color{
    background-color: #FFFFFF;
    border-radius: 10px ;
    border: 1px solid #499EDF;
  }
  .app-text {
    font-size: 12px;
  }
  .panel-self{
    border-radius: 10px;
    border:1px solid #499EDF;
    background-color: #F8F8F8;
  }
  .yybtn-color{
    background-color:#499edf;
    border-radius: 4px ;
    border: 1px solid #499EDF;
    color: #FFFFFF;
    font: 14px PingFang-SC-Bold;
  }
  .qxbtn-color{
    background-color: #FFFFFF;
    border-radius: 4px ;
    color: #499edf;
    font: 14px PingFang-SC-Bold;
    border: 1px solid #499EDF;
  }
</style>

<template>
  <div class="auto">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
        <div partial>
          <form>
            <!--<div class="row col-xs-12 col-sm-6 col-md-6 app-row">-->
              <!--<div class="col-xs-4 col-sm-4 col-md-4">-->
                <!--<img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">-->
                <!--<label for="f_keyword" class="font text-left">小区名称：</label>-->
              <!--</div>-->
              <!--<div class="col-xs-8 col-sm-8 col-md-8" >-->
                <!--<input id="f_keyword" class="search_input input-font"-->
                       <!--v-model="model.f_residential_area" condition="f_residential_area like '%{}%'" />-->
              <!--</div>-->

            <!--</div>-->
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/用户ID.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_userinfo_code" class=" font text-left">计划名称：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input id="f_userinfo_code" class="search_input input-font"
                       v-model=model.f_plan_name condition="f_plan_name like '%{}%'" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/用户ID.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_userinfo_code" class=" font text-left">卡&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input id="f_userinfo_code" class="search_input input-font"
                       v-model=model.f_card_id condition="f_card_id = '{}'" />
              </div>
            </div>

            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/用户姓名.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label  class="font text-left">用户姓名：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input  class="search_input input-font"
                       v-model=model.f_user_name condition="f_user_name like '%{}%'" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
              <label class="font text-left">用户地址：</label>
              <input  class="search_input input-font"
                      v-model=model.f_keyword condition="f_address like '%{}%'" />
            </div>
<!--            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">-->
<!--              <div class="col-xs-4 col-sm-4 col-md-4">-->
<!--                <img src="../../assets/用户类型.png" style="width: 20px;margin-bottom: 5px" alt="">-->
<!--                <label for="f_user_type" class="font text-left">用户类型：</label>-->
<!--              </div>-->
<!--              <div class="col-xs-8 col-sm-8 col-md-8" >-->
<!--                <v-select id="f_user_type" :value.sync="model.f_user_type" class="input-font"-->
<!--                          :options='$parent.$parent.user_types' placeholder='请选择用户类型'-->
<!--                          v-model="model.f_user_type" condition="f_user_type='{}'" close-on-select clear-button></v-select>-->
<!--              </div>-->
<!--            </div>-->
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4 col-sm-4 col-md-4" style="margin-top: 8px">
                <img src="../../assets/shijian.png" style="width: 20px;margin-bottom: 5px" alt="">
                <span class="text-left font">入户时间</span>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8 col-sm-8 col-md-8">
                <datepicker
                  :value.sync="model.f_onsite_time"
                  :format="'yyyy-MM-dd'"
                  v-model="model.f_onsite_time"
                  :show-reset-button="reset" placeholder="请输入入户时间" style="margin-bottom: 8px">
                </datepicker>
                <!-- <input type="text" class="search_input" v-model="model.startDate" placeholder="请输入起下发时间"/> -->
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4 col-sm-4 col-md-4" style="margin-top: 8px">
                <img src="../../assets/shijian.png" style="width: 20px;margin-bottom: 5px" alt="">
                <span class="text-left font">离开时间</span>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8 col-sm-8 col-md-8">
                <datepicker
                  :value.sync="model.f_offsite_time"
                  :format="'yyyy-MM-dd'"
                  v-model="model.f_offsite_time"
                  :show-reset-button="reset" placeholder="请输入入户时间" style="margin-bottom: 8px">
                </datepicker>
                <!-- <input type="text" class="search_input" v-model="model.startDate" placeholder="请输入起下发时间"/> -->
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/安检状态.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_last_state" class="font text-left">本次安检情况：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <v-select id="f_last_state" :value.sync="model.f_entry_status" class="input-font"
                          :options='$parent.$parent.last_check_states' placeholder='请选择本次安检情况' :value-single="ture"
                          v-model="model.f_entry_status" condition="cp.f_entry_status='{}'" close-on-select clear-button></v-select>
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <span class="col-xs-4 col-sm-4 col-md-4" style="line-height: 20px;">安检账号:</span>
              <div class="col-xs-8 col-sm-8 col-md-8">
                <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="cp.f_checker_id = '{}'"></v-select>
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <span class="col-xs-4 col-sm-4 col-md-4" style="line-height: 20px;">安检人员:</span>
              <div class="col-xs-8 col-sm-8 col-md-8">
                <v-select :value.sync="model.f_order_checker_name" v-model='model.f_order_checker_name'
                          :value-single="true" style="margin-top: 8px"
                          :options='$parent.$parent.checkersname' placeholder='安检人员'
                          close-on-select condition="cp.f_order_checker_name = '{}'"></v-select>
              </div>
            </div>
            <div class="row col-xs-12 col-sm-12 col-md-6 text-center" style="margin-top: 20px;">
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 45%;" @click="$parent.$parent.selfSearch">查询</button>
            </div>
            <!--<div class="row col-xs-12 col-sm-6 col-md-6 app-btn">-->
            <!--<button class="btn btn-primary col-xs-6" type="button"  @click="search"><span class="glyphicon  glyphicon-search" style="margin-right: 20px;">查询</span></button>-->
            <!--</div>-->
            <div style="height:30px;"></div>
          </form>
        </div>
      </criteria>
      <list :model="model" partial='list'>
        <div partial>
          <div @click="$parent.$parent.$parent.inspect(row)" class="auto app-text" style="margin-top: 5px;">
            <div class="panel" style="padding: 10px 10px 5px 10px;">
              <div class="panel-body panel-self">
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">卡&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_card_id }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户编号</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_userinfo_code }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户名称</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_user_name }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户类型</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_user_type }}
                  </p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户电话</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone }}
                    <img src="../../assets/phone.png" style="width: 6%" v-on:click.stop.prevent='$parent.$parent.$parent.makeAPhoneCall(row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone)'></img>
                  </p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">小区名称</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_residential_area }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户地址</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_address }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">安检单类型</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_no_checkplan }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">计划名称</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_plan_name }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">本次安检情况</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_entry_status }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">入户时间</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_onsite_time }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">离开时间</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_offsite_time }}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </list>
    </criteria-paged>
    <back-page :need-back='true'  @flag="$back()"></back-page>
  </div>
</template>

<script>
  import LocalPagedList from './LocalPagedList'
  import Vue from 'vue'
  import { PagedList } from 'vue-client'
  import * as Util from '../Util'
  import co from 'co'

  let select = function * (self) {
    let getGasman = yield self.$resetpost(`${self.Url}/rs/search`, {
      source: 'this.getParentByType($organization$).getChildByName($安检员$).getUsers()',
      userid: Vue.user.id
    }, {resolveMsg: null, rejectMsg: null})
    console.log('获取安检员', getGasman)
    getGasman.data.forEach((checker)=>{
      self.checkersid.push({label:checker.name,value:checker.name})
      self.checkersname.push({label:checker.name,value:checker.name})
    })
    self.checkersid.push({label:'全部',value:''})
    self.checkersname.push({label:'全部',value:''})
  }

  export default {
    title: '无计划安检查询',
    data() {
      return {
        model: new PagedList(`${this.$androidUtil.getProxyUrl()}/rs/sql/AndroidGetCheckPlanResult`,5,{condition:'this.condition'}),
        showModal: false,
        param: null,
        checkersid:[],
        checkersname:[],
        Url:this.$androidUtil.getProxyUrl(),
        f_preset_dt : Util.to3339TimeString(),
        upload_states: [
          {label: '请选择上传状态', value: null},
          {label: '未传', value: '未传'},
          {label: '已传', value: '已传'}
        ],
        user_types: [
          {label: '请选择用户类型', value: null},
          {label: '民用', value: '民用'},
          {label: '非民用', value: '非民用'},
        ],
        last_check_states: [
          //TODO 选全部查不出来
          {label: '全部', value: ''},
          {label: '入户', value: '入户'},
          {label: '拒检', value: '拒检'},
          {label: '到访不遇', value: '到访不遇'}
        ],
      }
    },
    ready(){
   //   this.selfSearch()
      let gen = select(this)
      co(gen)
    },
    methods: {
      reload(){
        this.$refs.paged.loadPage(this.$refs.paged.model.pageIndex)
      },
      inspect(row) {
        // this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/sql/查询计划项表信息`, {data: {f_userid: row.f_userinfoid}}).then((response) => {
        //   console.log(JSON.stringify(response))
        //     row['f_plan_meters'] = response.data

            // if (row.f_user_type == '民用') {
              this.$goto('paper-set', {f_plan_id: row.f_plan_id, item: row, role: 'androidview'}, 'self', this.reload)
            // } else {
            //   this.$goto('paper-set-noncivil', {f_plan_id: row.f_plan_id, item: row, role: 'androidview'}, 'self', this.reload)
            // }
          // })
      },
      makeAPhoneCall(phoneNumber) {
        this.$androidUtil.makeAPhoneCall(phoneNumber)
      },
      reserve (idx) {
        this.param = idx
        this.showModal = true
      },
      search(args) {
        this.model.rows = []
        this.model.search(args.condition, args.model)
      },
      selfSearch () {
        let condition = " 1 = 1 "
        if(this.$refs.paged.$refs.cri.model.f_keyword)
          condition += " and (cp.f_building like '%"+this.$refs.paged.$refs.cri.model.f_keyword+"%' or cp.f_unit like '%"+this.$refs.paged.$refs.cri.model.f_keyword+"%' or cp.f_floor like '%"+this.$refs.paged.$refs.cri.model.f_keyword+"%' or cp.f_room like '%"+this.$refs.paged.$refs.cri.model.f_keyword+"%' or cp.f_address like '%"+this.$refs.paged.$refs.cri.model.f_keyword+"%')"
        if(this.$refs.paged.$refs.cri.model.f_user_name)
          condition += " and cp.f_user_name like '%"+this.$refs.paged.$refs.cri.model.f_user_name+"%'"
        if(this.$refs.paged.$refs.cri.model.f_card_id)
          condition += " and cp.f_card_id = '"+this.$refs.paged.$refs.cri.model.f_card_id+"'"
        console.log('this.$refs.paged.$refs.cri.model.f_entry_status=>',this.$refs.paged.$refs.cri.model.f_entry_status[0])
        if(this.$refs.paged.$refs.cri.model.f_entry_status[0]){
          condition += " and cp.f_entry_status ='"+this.$refs.paged.$refs.cri.model.f_entry_status+"'"
          console.log('condition'+condition)
        }
        if(this.$refs.paged.$refs.cri.model.f_checker_id)
          condition += " and cp.f_checker_id = '"+this.$refs.paged.$refs.cri.model.f_checker_id+"'"
        if(this.$refs.paged.$refs.cri.model.f_order_checker_name)
          condition += " and cp.f_order_checker_name = '"+this.$refs.paged.$refs.cri.model.f_order_checker_name+"'"
        // if(this.$refs.paged.$refs.cri.model.f_user_type[0])
        //   condition += " and ti.f_user_type='"+this.$refs.paged.$refs.cri.model.f_user_type[0]+"'"
        if(this.$refs.paged.$refs.cri.model.f_plan_name)
          condition += " and tcp.f_plan_name like '%"+this.$refs.paged.$refs.cri.model.f_plan_name+"%'"
        if(this.$refs.paged.$refs.cri.model.f_onsite_time)
          condition += " and SUBSTR(cp.f_onsite_time,0,11) >='"+this.$refs.paged.$refs.cri.model.f_onsite_time+"'"
        if(this.$refs.paged.$refs.cri.model.f_offsite_time)
          condition += " and SUBSTR(cp.f_offsite_time,0,11) <= '"+this.$refs.paged.$refs.cri.model.f_offsite_time+"'"
          this.model.search(condition)
      },
    }
  }
</script>
