<template>
  <div class="auto">
    <criteria-paged :model="model"  v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.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 for="f_plan_name" class="font text-left">计划名称：</label>
              </div>
              <v-select
                id="f_plan_name"
                :value.sync="model.f_plan_name"
                class="input-font"
                :options='$parent.$parent.planNameOptions'
                placeholder='计划名称'
                :width="'60%'"
                v-model="model.f_plan_name"
                condition="f_plan_name = '{}'"
                close-on-select clear-button>
              </v-select>
            </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" >
                <v-select :value.sync="model.f_user_type" class="input-font" condition="ti.f_user_type='{}'"
                          :options='$parent.$parent.user_types' placeholder='请选择用户类型' :value-single="true"
                          v-model="model.f_user_type" close-on-select clear-button></v-select>
              </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 style="width: 100%" class="search_input input-font" v-model="model.f_districtname" placeholder="请输入用户小区" condition="ti.f_residential_area 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 class="font text-left">区/期：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_area_period" placeholder="请输入区/期" condition="ti.f_area_period 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 class="font text-left">楼&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_building" placeholder="请输入用户楼号" condition="ti.f_building 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 class="font text-left">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;元：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_unit" placeholder="请输入用户单元" condition="ti.f_unit 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 class="font text-left">用户地址：</label>
              </div>
              <div class="col-xs-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_address" placeholder="请输入用户地址（可模糊查询）" condition="ti.f_address like '%{}%'">
              </div>
            </div>
            <div class="row text-center" style="margin-top: 20px;">
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 45%;" @click="search">查询</button>
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 45%;" @click="$parent.$parent.laserLeakDetection()">激光检测</button>

            </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;">
            <div class="panel" style="padding: 10px 10px 5px 10px;">
              <div class="panel-body panel-self">
                <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_userinfo_code }}</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_user_name }}</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_user_type }}</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_residential_area }}</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_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_last_check_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>
            </div>
          </div>
        </div>
      </list>
    </criteria-paged>
  </div>
</template>

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

export default {
  title: '安检员B',
  data () {
    let model = new PagedList(`${this.$androidUtil.getProxyUrl()}/rs/sql/androidGetuserinfoOnline`, 9999)
    return {
      planNameOptions:[],
      model: model,
      cbc:[],
      showModal:false,
      signs: [
        {label:'请选择录入状态', value:''},
        {label:'录入', value:'1'},
        {label:'非录入', value:'0'},
      ],
      ischecks: [
      ],
      user_types: [
        {label: '请选择用户类型', value: ''},
        {label: '民用', value: '民用'},
        {label: '非民用', value: '非民用'},
      ],
      f_user_states: [
        {label:'请选择档案状态', value:''},
        {label:'正常', value:'正常'},
        {label:'点火', value:'点火'},
      ],
      f_check_types: [
        {label:'请选择安检类型', value:''},
        {label:'应检', value:'应检'},
        {label:'超期', value:'超期'},
      ],
    }
  },
  ready () {
    this.getAllPlanName()
    // this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/logic/getSafeCheckCycle`,{},{resolveMsg: null, rejectMsg: null}).then((res) => {
    //   //tag)
    //   if(res.data.code == 200){
    //     this.model.myCycle = res.data.civil.value
    //     this.model.fyCycle = res.data.civilian.value
    //   }else{
    //     //this.$showMessage(res.data.msg)
    //   }
    //
    // })
    // this.getCheckTime()
    // this.Mreadibook()
  },
  computed: {
    reload(){
      this.$refs.paged.loadPage(this.$refs.paged.model.pageIndex)
    },
    selected () {
      return this.$refs.paged.$refs.grid.selected
    }
  },
  methods:{
    search(args){
      if (!args.condition.includes('f_plan_name')){
        this.$showMessage('计划名称为必选条件')
        return
      }
      args.condition += ` and (ti.f_last_check_state != '入户' or ti.f_state = '未检') and ui.f_laser_leak_detection is null`
      this.model.search(args.condition)
    },
    laserLeakDetection(){
      if(this.model.rows.length==0){
        this.$showMessage('查询结果为空')
        return
      }
      let ids = this.model.rows.map(item=>{return `'${item.id}'`}).join(',')
      let sql = `update t_userinfo set f_laser_leak_detection = '是',f_laser_leak_dete = '${Util.toStandardTimeString()}',f_laser_leak_people = '${Vue.user.name}' where f_userinfo_id in (select f_userinfoid from t_check_plan_item where id in (${ids}))`
      new HttpResetClass().load('POST', `${this.$androidUtil.getProxyUrl()}/rs/logic/runSQL`, {data: {sql: sql}},
        {resolveMsg: null, rejectMsg: null}).then(resp=>{
        this.$showMessage('提交完成')
      }).catch(error=>{
        this.$showMessage('提交失败')
      })
    },
    getAllPlanName(){
      this.planNameOptions = []
      this.$refs.paged.$refs.cri.model.f_plan_name = ''
      let criteria = {
        items: 'f_plan_name',
        tablename: 't_check_plan',
        condition: `f_plan_name IS NOT NULL AND f_plan_name != ''`,
        groupitem: 'f_plan_name'
      }
      let result = HostApp._executeTask({'type':'sql', 'data':{'alias': 'safe_singleTable_GroupBy', 'criteria': criteria}})
      if(result.code == 200){
        result.data.rows.forEach(item => this.planNameOptions.push({label:item.f_plan_name,value:item.f_plan_name}))
      }
    },
    // scan(){
    //   HostApp.__this__=this,
    //     HostApp.scanCode({callback:"javascript:HostApp.__this__.getCode();"})
    // },
    // getCode(){
    //   let datapa = HostApp.getCode().data;
    //   let indexnum = datapa.indexOf("]C1")
    //   if(indexnum != -1){
    //     datapa = datapa.substring(indexnum+3,datapa.length)
    //   }
    //   this.$refs.paged.$refs.cri.model.f_meternumber=datapa
    // },
    // getCheckTime(){
    //   //tag
    //   new HttpResetClass().load('post',`${this.$androidUtil.getProxyUrl()}/rs/sql/tel_singleTable_OrderBy`,{data: {
    //       items: 'f_circle,f_start_time',
    //       tablename: 't_safe_circle',
    //       condition: `f_filialeid  = '${Vue.user.orgid}'`,
    //       orderitem: 'id'
    //     }}).then(res=>{
    //     //tag)
    //     let  nocheck=''
    //     let  ischeck=''
    //     if (res.data[0]){
    //       if (res.data[0].f_circle=='1'){
    //         nocheck=`(ua.f_last_check_date<'${res.data[0].f_start_time}' or ua.f_last_check_date is null)`
    //         ischeck=`ua.f_last_check_date>'${res.data[0].f_start_time}'`
    //
    //       }else{
    //         let addtime= (Util.toStandardTimeString().substring(0,4)-res.data[0].f_start_time.substring(0,4))%res.data[0].f_circle
    //         //tag
    //         let time =(Util.toStandardTimeString().substring(0,4)-addtime)+'-01-01 00:00:00'
    //         //tag
    //         nocheck=`(ua.f_last_check_date<'${time}' or ua.f_last_check_date is null)`
    //         ischeck=`ua.f_last_check_date>'${time}'`
    //       }
    //       //tag
    //       this.ischecks=[
    //         {label: '全部', value: ''},
    //         {label: '已检', value: ischeck },
    //         {label: '未检', value: nocheck},
    //       ]
    //       //tag
    //     }else{
    //       this.$showMessage("未配置安检周期")
    //     }
    //
    //   })
    //   //tag
    // },
    // inspect (info){
    //   if(info.f_last_check_date){
    //     this.$showMessage("该用户最后一次安检时间为 "+info.f_last_check_date+" 是否继续对该用户进行安检",['confirm', 'cancel']).then((butt)=>{
    //       if(butt=="confirm"){
    //         info.id = ''
    //         info.f_state = '未检'
    //         info.f_no_checkplan = '无计划安检'
    //         //tag
    //         this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/sql/查询计划项表信息`,{data:{f_userid:info.f_userinfo_id}}).then((response)=>{
    //           //tag)
    //           info['f_plan_meters'] = response.data
    //           var pardate = {
    //             _this:this,
    //             tittle:'安检详情',
    //             safe:true
    //           }
    //           this.$dispatch('gotoson',pardate)
    //           this.$goto('safecheck-order-v', {item: info, role: 'inspect',parentPage:'AddPlanItem'}, 'self', this.reload)
    //
    //         })
    //       }
    //     })
    //   }else{
    //     info.id = ''
    //     info.f_state = '未检'
    //     info.f_no_checkplan = '无计划安检'
    //     //tag
    //     this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/sql/查询计划项表信息`,{data:{f_userid:info.f_userinfo_id}}).then((response)=>{
    //       //tag)
    //       info['f_plan_meters'] = response.data
    //       var pardate = {
    //         _this:this,
    //         tittle:'安检详情',
    //         safe:true
    //       }
    //       this.$dispatch('gotoson',pardate)
    //       this.$goto('safecheck-order-v', {item: info, role: 'inspect',parentPage:'AddPlanItem'}, 'self', this.reload)
    //
    //     })
    //   }
    // },
    // Mreadibook(){
    //   this.cbc=[]
    //   let http = new HttpResetClass()
    //   http.load('POST',`${this.$androidUtil.getProxyUrl()}/rs/logic/getMeterBooksData`,
    //     {data: {f_orgid: "('"+Vue.user.orgid+"')"}},
    //     {resolveMsg: null, rejectMsg: '获取失败！！！'}).then((getMeterReadingBooks)=>{
    //     this.cbc = [{label: '全部', value: ''}]
    //     //tag
    //     //tag)
    //     //tag
    //     getMeterReadingBooks.data.meterbooks.forEach((res) => {
    //       this.cbc.push({label: res.f_book_name, value: res.id})
    //       /*if(res.f_book_slice_area){
    //         if(this.sliceArea.indexOf(res.f_book_slice_area)<0){
    //           this.sliceArea.push(res.f_book_slice_area)
    //         }
    //       }*/
    //     })
    //   })
    //
    //
    // }
  }
}
</script>
<style scoped>
.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{
  border-radius: 4px ;
  border: 1px solid #499EDF;
}
.qxbtn-color{
  background-color: #FFFFFF;
  border-radius: 4px ;
  border: 1px solid #499EDF;
}
</style>
