<style scoped>
.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;
}

.button_shrink_top {width: 35px; height: 35px; background-size:100%;background-image: url("../../../../static/newStyle/stretch_top.png")}
.button_shrink_bottom {width: 35px; height: 35px;  background-size:100%;background-image: url("../../../../static/newStyle/stretch_bottom.png")}
.button_shrink_left {width: 35px; height: 35px;  background-size:100%;background-image: url("../../../../static/newStyle/stretch_left.png")}
.button_shrink_right {width: 35px; height: 35px; background-size:100%;background-image: url("../../../../static/newStyle/stretch_right.png")}
</style>

<template>
  <div style="height: auto;width: 100%">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
        <div partial>
          <form>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../../assets/用户姓名.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label  class="font text-left">用户姓名：</label>
              </div>
              <div class="col-xs-8" >
                <input  class="search_input input-font" v-model=model.f_user_name condition="f_user_name like '%{}%'" />
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-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" >
                <input id="f_userinfo_code" class="search_input input-font"
                       v-model=model.f_userinfo_code condition="f_userinfo_code = '%{}%'" />
              </div>
            </div>
            <div class="row app-row" >
              <div class="col-xs-4">
                <img src="../../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户地址：</label>
              </div>
              <div class="col-xs-8" >
                <input class="search_input input-font"
                       v-model=model.f_address condition="f_address like '%{}%'"  />
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../../assets/是否已检.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_state" class="font text-left">起始时间：</label>
              </div>
              <datepicker id="f_start_date"
                          placeholder= '起始时间'
                          :value.sync="model.f_start_date"
                          :disabled-days-of-Week="[]"
                          v-model="model.f_start_date"
                          class="input-font"
                          :width="'60%'"
                          :format="'yyyy-MM-dd 00:00:00'"
                          :show-reset-button="reset" readonly="readonly">
              </datepicker>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../../assets/是否已检.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_state" class="font text-left">结束时间：</label>
              </div>
              <datepicker id="f_end_date"
                          placeholder= '结束时间'
                          :value.sync="model.f_end_date"
                          :disabled-days-of-Week="[]"
                          v-model="model.f_end_date"
                          class="input-font"
                          style="width:60%"
                          :format="'yyyy-MM-dd 23:59:00'"
                          :show-reset-button="reset" readonly="readonly">
              </datepicker>
            </div>
            <div class="row app-row" v-if="$parent.$parent.criteriaShow">
              <div class="col-xs-4">
                <img src="../../../assets/是否已检.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_state" class="font text-left">安检结果：</label>
              </div>
              <v-select id="f_state"
                        :value.sync="model.f_state"
                        class="input-font"
                        :options='$parent.$parent.check_states'
                        placeholder='安检结果'
                        style="width:60%"
                        v-model="model.f_state"
                        condition="f_state='{}'"
                        close-on-select clear-button>
              </v-select>
            </div>

            <div class="row app-row" v-if="$parent.$parent.criteriaShow">
              <div class="col-xs-4">
                <img src="../../../assets/用户类型.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_user_type" class="font text-left">用户类型：</label>
              </div>
              <v-select id="f_user_type" :value.sync="model.f_user_type" class="input-font"
                        :width="'60%'"
                        :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 class="row app-row" v-if="$parent.$parent.criteriaShow">
              <div class="col-xs-4">
                <img src="../../../assets/是否已检.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="safechecktype" class="font text-left">安检类型：</label>
              </div>
              <v-select id="safechecktype" :value.sync="model.f_safecheck_type" class="input-font"
                        :width="'60%'"
                        :options='$parent.$parent.safechecktypes' placeholder='请选择安检类型'
                        v-model="model.f_safecheck_type" condition="f_safecheck_type ='{}'" close-on-select clear-button></v-select>
            </div>
            <div class="row app-row" v-if="$parent.$parent.criteriaShow">
              <div class="col-xs-4">
                <img src="../../../assets/用户姓名.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="checker" class="font text-left">安检员：</label>
              </div>
              <v-select id="checker" :value.sync="$parent.$parent.f_checker_id" class="input-font"
                        :width="'60%'"
                        :options='$parent.$parent.checkerOptions' placeholder='请选择安检员'
                        v-model="$parent.$parent.f_checker_id" close-on-select clear-button></v-select>
            </div>
            <div class="row app-row" v-if="$parent.$parent.criteriaShow">
              <div class="col-xs-4">
                <img src="../../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">气表品牌：</label>
              </div>
              <div class="col-xs-8" >
                <input class="search_input input-font"
                       v-model=model.f_item_value condition="f_item_value like '%{}%'"  />
              </div>
            </div>
            <div class="row app-row" v-if="$parent.$parent.criteriaShow">
              <div v-for="row in $parent.$parent.ruhu">
                <div class="col-xs-6" style="text-align: center">
                  <span class="font text-left">{{ row.f_entry_status }}{{row.number}}条</span>
                </div>
              </div>
              <div class="col-xs-6" style="text-align: center">
                <span class="font text-left">总共{{$parent.$parent.allPlanCount}}条</span>
              </div>
            </div>
            <div class="row text-center" style="margin-top: 20px;">
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 25%;" @click="$parent.$parent.selfSearch">查询</button>
              <div style="float: right;margin-right: 3% " class="button_spacing" :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"  @click="$parent.$parent.hidden()"></div>
            </div>

            <div class="col-sm-12">

            </div>

            <div style="height:30px;"></div>
          </form>
        </div>
      </criteria>
      <list :model="model" partial='list'>
        <div partial>
          <div  class="auto app-text" style="margin-top: 5px;" @click="$parent.$parent.$parent.gotocheckpaper(row)">
            <div class="panel" style="padding: 10px 10px 5px 10px;">
              <div class="panel-body panel-self">

                <div class="col-xs-12">
                  <p class="panel-title col-xs-5 text-left font" style="width: 21%;float: left"><b>用户编号:</b></p>
                  <p class="panel-title col-xs-5 text-left input-font" v-if="$parent.$parent.$parent.upUserinfoSta=='是'" style="width: 74%;color: #00b3ee" @click="$parent.$parent.$parent.upuserinfo(row.f_userinfoid)">{{ row.f_userinfo_code }}</p>
                  <p class="panel-title col-xs-5 text-left input-font" v-if="$parent.$parent.$parent.upUserinfoSta!='是'" style="width: 74%">{{ row.f_userinfo_code }}</p>
                </div>
                <div class="col-xs-12">
                  <p class="panel-title col-xs-5 text-left font" style="width: 21%;float: left"><b>用户名称:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font" style="width: 79%">{{ row.f_user_name }}</p>
                </div>
                <div class="col-xs-6">
                  <p class="panel-title col-xs-5 text-left font"><b>气表品牌:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_item_value }}</p>
                </div>
                <div class="col-xs-6">
                  <p class="panel-title col-xs-5 text-left font"><b>用户类型:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_check_type }}
                  </p>
                </div>
                <!--                <div class="col-xs-6">-->
                <!--                  <p class="panel-title col-xs-5 text-left font"><b>小区名称:</b></p>-->
                <!--                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_residential_area }}</p>-->
                <!--                </div>-->
                <div class="col-xs-12">
                  <p class="panel-title text-left font" style="width: 23%;float: left"><b>用户电话:</b></p>
                  <p class="panel-title text-left input-font" style="width: 77%">{{ 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="col-xs-12">
                  <p class="panel-title text-left font" style="width: 21%;float: left"><b>用户地址:</b></p>
                  <p class="panel-title text-left input-font" style="width: 79%">{{ row.f_address }}</p>
                </div>

                <!--                <div class="row">-->
                <!--                  <p class="panel-title col-xs-4 text-left font">计划年份</p>-->
                <!--                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_plan_year }}</p>-->
                <!--                </div>-->
                <!--                <div class="row">-->
                <!--                  <p class="panel-title col-xs-4 text-left font">计划月份</p>-->
                <!--                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_plan_month }}</p>-->
                <!--                </div>-->
                <!--                <div class="row">-->
                <!--                  <p class="panel-title col-xs-4 text-left font">预约时间</p>-->
                <!--                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_prearranged_date }}</p>-->
                <!--                </div>-->
                <!--<div class="row">-->
                <!--<p class="panel-title col-xs-4 text-left font">上次安检状态</p>-->
                <!--<p class="panel-title col-xs-8 text-left input-font">{{ row.f_last_check_state }}</p>-->
                <!--</div>-->
                <div class="col-xs-6">
                  <p class="panel-title col-xs-5 text-left font"><b>安检状态:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_entry_status }}</p>
                </div>
                <div class="col-xs-6">
                  <p class="panel-title col-xs-5 text-left font"><b>安检类型:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_safecheck_type }}</p>
                </div>
                <div class="col-xs-12">
                  <p class="panel-title col-xs-5 text-left font"><b>上传时间:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_upload_date }}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </list>
    </criteria-paged>
  </div>

</template>

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

export default {
  title: '无计划安检查询',
  data() {
    return {
      //f_filialeids:`('${Vue.user.orgid}')`,
      f_filialeids:'',
      planparam:[],
      getSafeInfo:'',
      check:'',
      plan:'',
      planid:'',//http://ssl.odc.hk:8300
      model:new PagedList( `${this.$androidUtil.getProxyUrl()}/rs/sql/Get_khrq`,20,{condition:'this.condition',f_filialeids:`'${Vue.user.orgid}'`}),
      criteriaShow: false,
      planoption:[],
      condition:'',
      checkers:[],
      upUserinfoSta:'',
      param: null,
      f_preset_dt : Util.to3339TimeString(),
      flow_direction:[
        {label: '请选择挂表方式', value: ''},
        {label: '左表', value: '左表'},
        {label: '右表', value: '右表'}
      ],
      check_states: [
        {label: '请选择安检状态', value: ''},
        {label: '入户', value: '入户'},
        {label: '到访不遇', value: '到访不遇'},
        {label: '拒检', value: '拒检'}
      ],
      last_check_states: [
        {label: '请选择上次安检状态', value: ''},
        {label: '入户', value: '入户'},
        {label: '拒检', value: '拒检'},
        {label: '到访不遇', value: '到访不遇'},
        {label: '未使用天然气', value: '未使用天然气'}
      ],
      upload_states: [
        {label: '请选择上传状态', value: ''},
        {label: '未传', value: '未传'},
        {label: '已传', value: '已传'}
      ],
      user_types: [
        {label: '请选择用户类型', value: ''},
        {label: '民用', value: '民用'},
        {label: '非民用', value: '非民用'},
      ],
      safechecktypes: [
        {label: '请选择安检类型', value: ''},
        {label: '年度普检', value: '年度普检'},
        {label: '散户安检', value: '散户安检'},
      ],
      verify_state: [
        {label: '请选择审核状态', value: ''},
        {label: '未审核', value: '未审核'},
        {label: '打回', value: '打回'}
      ],
      residentialAreaOptions: [],
      buildOptions: [],
      unitOptions: [],
      planNameOptions: [],
      ruhu: [],
      allPlanCount: 0,
      f_checker_id: Vue.user.id,
      checkerOptions: []
    }
  },
  ready(){
    /*this.getAllArea()
    this.getAllPlanName()*/
    this.getCheckers()
    this.upUserinfoSta=this.$appdata.getSingleValue('安检在线统计修改档案信息')
    this.getSafeInfo=this.$appdata.getSingleValue('安检在线统计查看安检详情')
    let d=new Date()
    this.$refs.paged.$refs.cri.model.f_start_date=`${Util.toStandardDateString()} 00:00:00`
    this.selfSearch()
  },
  methods: {
    gotocheckpaper(row){
      if(!this.getSafeInfo){
        return
      }
      row.f_upload_state = '已传'
      let pardate = {
        _this:this,
        title:'安检信息',
        safe:false
      }
      this.$dispatch('gotoson',pardate)
      this.$goto('new-check-paper-android', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
    },
    async getCheckers() {
      console.log('Vue.user=', JSON.stringify(Vue.user))
      let res = await new HttpResetClass().load('POST', `${this.$androidUtil.getProxyUrl()}/rs/search`, {
        data: {
          source: `root.getResourceById($${Vue.user.orgid}$,$organization$).getSpecialResByType($user$).where(row.getAttributes().get($rolestr$).indexOf($安检员$) != -1)`,
          userid: Vue.user.id + ''
        }
      })
      console.log('res=', JSON.stringify(res))
      console.log('res.data.length=', res.data.length)
      const a = []
      const checkerOptions = []
      for (let item of res.data) {
        if (a.indexOf(item.id) < 0){
          checkerOptions.push({
            label: item.name,
            value: item.id
          })
          a.push(item.id)
        }
      }
      this.checkerOptions = checkerOptions
      console.log('this.checkerOptions=', JSON.stringify(this.checkerOptions))
    },
    upuserinfo(f_userinfo_id) {
      let _this = this
      this.$dispatch('gotoson', {
        _this: _this,
        title: '档案信息变更',
        safe: false
      })
      _this.$goto('PhoneUpUserinfo', {f_userinfo_id: f_userinfo_id,f_source:'安检'})
    },
    selfSearch () {
      // this.getPlanCount()
      //let condition = `f_filialeid='${Vue.user.orgid}' and f_checker_id='${Vue.user.id}' `
      let condition = "1=1 "
      if (this.f_checker_id){
        condition += " and f_checker_id = '"+ this.f_checker_id + "'"
      }
      if(this.$refs.paged.$refs.cri.model.f_user_name){
        if(this.$refs.paged.$refs.cri.model.f_user_name.toString().trim()){
          condition += " and f_user_name like '"+this.$refs.paged.$refs.cri.model.f_user_name+"%'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_userinfo_code){
        if(this.$refs.paged.$refs.cri.model.f_userinfo_code.toString().trim()){
          condition += " and f_userinfo_code = '"+this.$refs.paged.$refs.cri.model.f_userinfo_code+"'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_address){
        if(this.$refs.paged.$refs.cri.model.f_address.toString().trim()){
          condition += " and f_address like '%"+this.$refs.paged.$refs.cri.model.f_address+"%'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_start_date){
        if(this.$refs.paged.$refs.cri.model.f_start_date.toString().trim()){
          condition += " and f_offsite_time > '"+this.$refs.paged.$refs.cri.model.f_start_date +"'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_end_date){
        if(this.$refs.paged.$refs.cri.model.f_end_date.toString().trim()){
          condition += " and f_offsite_time < '"+this.$refs.paged.$refs.cri.model.f_end_date +"'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_state){
        if(this.$refs.paged.$refs.cri.model.f_state.toString().trim()){
          condition += " and f_entry_status = '"+this.$refs.paged.$refs.cri.model.f_state +"'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_user_type){
        if(this.$refs.paged.$refs.cri.model.f_user_type.toString().trim()){
          condition += " and f_check_type = '"+this.$refs.paged.$refs.cri.model.f_user_type +"'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_safecheck_type){
        if(this.$refs.paged.$refs.cri.model.f_safecheck_type.toString().trim()){
          condition += " and f_safecheck_type = '"+this.$refs.paged.$refs.cri.model.f_safecheck_type +"'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_item_value){
        if(this.$refs.paged.$refs.cri.model.f_item_value.toString().trim()){
          condition += " and f_item_value like '%"+this.$refs.paged.$refs.cri.model.f_item_value +"%'"
        }
      }
      this.getpaperCount(condition)
      //tag
      this.model.search(condition)
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    getpaperCount(condition){
      let http = new HttpResetClass()
      http.load('post',`${this.$androidUtil.getProxyUrl()}/rs/sql/Get_khrq_count`,{data:{condition:condition,f_filialeids:`${Vue.user.orgid}`}},{rejectMsg:null,resolveMsg:null}).then(row=>{
        if (row.data.length > 0){
          this.allPlanCount = 0
          this.ruhu = row.data
          for (let i = 0 ; i< row.data.length; i++){
            this.allPlanCount += row.data[i].number
          }
        }
      })
    }
  }
}
</script>
