<style scoped>
input::-webkit-input-placeholder {
  color: #cccccc;
}
.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">-->
<!--              &lt;!&ndash;小区名称&ndash;&gt;-->
<!--              <v-select :value.sync="model.f_residential_area"-->
<!--                        class="input-font"-->
<!--                        :options='$parent.$parent.residentialAreaOptions'-->
<!--                        placeholder='小区名称'-->
<!--                        :width="'32.5%'"-->
<!--                        v-model="model.f_residential_area"-->
<!--                        condition="ti.f_residential_area = '{}'"-->
<!--                        @change="$parent.$parent.getbuilds"-->
<!--                        close-on-select clear-button>-->
<!--              </v-select>-->
<!--              &lt;!&ndash;楼栋&ndash;&gt;-->
<!--              <v-select :value.sync="model.f_building"-->
<!--                        class="input-font"-->
<!--                        :options='$parent.$parent.buildOptions'-->
<!--                        placeholder='楼栋'-->
<!--                        :width="'32.5%'"-->
<!--                        v-model="model.f_building"-->
<!--                        condition="ti.f_building = '{}'"-->
<!--                        @change="$parent.$parent.getUnits"-->
<!--                        close-on-select clear-button>-->
<!--              </v-select>-->
<!--              &lt;!&ndash;单元&ndash;&gt;-->
<!--              <v-select :value.sync="model.f_unit"-->
<!--                        class="input-font"-->
<!--                        :options='$parent.$parent.unitOptions'-->
<!--                        placeholder='单元'-->
<!--                        :width="'32.5%'"-->
<!--                        v-model="model.f_unit"-->
<!--                        condition="ti.f_unit = '{}'"-->
<!--                        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" >-->
<!--                <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_residential_area condition="f_residential_area = '{}'"  placeholder="不可模糊搜索" />
              </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"
                       placeholder="不可模糊搜索"
                       v-model=model.f_building condition="f_building = '{}'"  />
              </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"
                       placeholder="不可模糊搜索"
                       v-model=model.f_unit condition="f_unit = '{}'"  />
              </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"
                       type="search"
                       placeholder="可模糊搜索"
                       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>
              <v-select id="f_state"
                        :value.sync="model.f_plan_id"
                        class="input-font"
                        :options='$parent.$parent.planAll'
                        placeholder='计划名称'
                        :width="'60%'"
                        v-model="model.f_plan_id"
                        condition="f_plan_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 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 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>
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 25%;" @click="$parent.$parent.showChooser()">转发</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>
          <modal :show.sync="$parent.$parent.showModal" v-ref:modal :backdrop="false">
            <div slot="modal-header" class="modal-header">
              <h4 class="modal-title">
                选择计划
              </h4>
            </div>
            <div slot="modal-body" class="modal-body">
              <plan-chooser-android :f.sync="$parent.$parent.fun" v-ref:chooser></plan-chooser-android>
            </div>
            <div slot="modal-footer" class="modal-footer" style="text-align: center">
              <button class="button_search" @click="$parent.$parent.ok">确认</button>
              <button class="button_search" @click="$parent.$parent.cancel">取消</button>
            </div>
          </modal>
        </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="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" 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_user_type }}
                  </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_residential_area }}</p>
                </div>
                <div class="col-xs-6">
                  <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_building }}</p>
                </div>
                <div class="col-xs-6">
                  <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_unit }}</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="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>
            </div>
          </div>
        </div>
      </list>
    </criteria-paged>
  </div>

</template>

<script>
import Vue from 'vue'
import { PagedList,HttpResetClass } from 'vue-client'
import * as Util from '../Util'
import co from 'co'
let select = function * (self) {
  let http = new HttpResetClass()
  http.load('POST', `${self.$androidUtil.getProxyUrl()}/rs/search`, {
    source: 'this.getParentByType($department$).getAllChildrens().where(row.getAttributes().get($rolestr$).indexOf($安检员$) != -1))',
    userid: Vue.user.id
  }, {resolveMsg: null, rejectMsg: null}).then((res) => {
    console.log('获取安检员', res)
    self.checkers.push({label:'全部',value:''})
    res.data.forEach((checker)=>{
      self.checkers.push({label:checker.name,value:checker.id})
    })
  })
}
export default {
  title: '无计划安检查询',
  data() {
    return {
      showModal:false,
      //f_filialeids:`('${Vue.user.orgid}')`,
      residentialAreaOptions: [],
      buildOptions: [],
      unitOptions: [],
      planAll:[],
      zdcon:'',
      f_filialeids:Vue.user.orgid,
      user_types:[{label:'民用',value:'民用'},{label:'非民用',value:'非民用'}],
      check:'',
      plan:'',
      fun: Vue.user,
      planid:'',
      model:new PagedList( `${this.$androidUtil.getProxyUrl()}/api/af-safecheck/sql/safe_singleTable_OrderBy`,100, {
        items: "' it.*,tcp.f_checker '",
        tablename: "'t_check_plan_item it LEFT JOIN t_check_plan tcp on it.f_plan_id=tcp.id'",
        orderitem: "'it.f_create_time desc'"
    }),
      criteriaShow: false,
    }
  },
  ready(){
    let criteria = {
      items: 'id,f_plan_name',
      tablename: 't_check_plan',
      condition: "f_checker='"+Vue.user.name+"'",
      orderitem: 'id'
    }
    new HttpResetClass().load('POST',`${this.$androidUtil.getProxyUrl()}/api/af-safecheck/sql/safe_singleTable_OrderBy`, {data:criteria}).then(res=>{
      res.data.forEach(item=>{
        this.planAll.push({
          label:item.f_plan_name,
          value:item.id
        })
      })
    })
    this.selfSearch()
  },
  methods: {
    ok() {
      if (this.$refs.paged.$refs.cri.$refs.modal.$children[0].selectedRow.id) {
        this.planid = this.$refs.paged.$refs.cri.$refs.modal.$children[0].selectedRow.id
        this.plan=this.$refs.paged.$refs.cri.$refs.modal.$children[0].selectedRow.f_plan_name
      }

      let data={
      f_plan_id:this.planid,
      f_operator:Vue.user.name,
      condition:this.zdcon,
      switchCheckAll:false,
      checkAll:false,
      param:[],
      columnName:''

      }
      this.$showMessage('将'+this.model.rows.length+'条安检计划单转入计划'+this.plan+',请再次进行确认', ['confirm', 'cancel']).then((res) => {
        if (res === 'confirm') {
          this.$resetpost( `${this.$androidUtil.getProxyUrl()}/api/af-safecheck/logic/UpCheckPlanItem`, data).then((res) => {
            if(res.data.code === 200){
              this.planid = ''
              this.plan = ''
              this.$showMessage('转单成功')
              this.showModal = false
              this.selfSearch()
            }
          }).catch((e) => {
            this.$showMessage(JSON.stringify(e) +'转单失败，网络异常，请稍后重试')
          })
        }
      })
      console.log("999999999999999999")
      console.log(this.planid)
      console.log(this.plan)
    },
    cancel() {
      this.showModal = false
      this.planid = ''
      this.plan = ''
    },
    showChooser() {
      this.showModal = true
    },
    getAllArea(){
      this.residentialAreaOptions = []
      this.buildOptions = []
      this.unitOptions = []
      this.$refs.paged.$refs.cri.model.f_residential_area = ''
      this.$refs.paged.$refs.cri.model.f_building = ''
      this.$refs.paged.$refs.cri.model.f_unit = ''
      let criteria = {
        items: 'f_residential_area',
        tablename: 't_check_plan_item',
        condition: `f_residential_area IS NOT NULL AND f_residential_area != '' AND ((f_complete = '' or f_complete = null or f_complete = '未完成') or (f_state = '未检'))`,
        groupitem: 'f_residential_area'
      }
      let result = new HttpResetClass().load('POST','/api/af-safecheck/sql/safe_singleTable_GroupBy', {data:criteria})
      console.log('result ===> ' + JSON.stringify(result))
      if(result.code == 200){
        result.data.rows.forEach(item => this.residentialAreaOptions.push({label:item.f_residential_area,value:item.f_residential_area}))
      }
      console.log('this.residentialAreaOptions ===> ' + JSON.stringify(this.residentialAreaOptions))
    },
    getbuilds(f_residential_area){
      console.log('f_residential_area ===> ' + JSON.stringify(f_residential_area))
      this.buildOptions = []
      this.unitOptions = []
      this.$refs.paged.$refs.cri.model.f_building = ''
      this.$refs.paged.$refs.cri.model.f_unit = ''
      if(!f_residential_area){
        return
      }
      let criteria = {
        items: 'f_building',
        tablename: 't_check_plan_item',
        condition: `f_building IS NOT NULL AND f_building != '' AND ((f_complete = '' or f_complete = null or f_complete = '未完成') or (f_state = '未检')) AND f_residential_area = '${f_residential_area}'`,
        groupitem: 'f_building'
      }
      let result = new HttpResetClass().load('POST','/api/af-safecheck/sql/safe_singleTable_GroupBy', {data:criteria})
      if(result.code == 200){
        result.data.rows.forEach(item => this.buildOptions.push({label:item.f_building,value:item.f_building}))
      }
      console.log('this.buildOptions ===> ' + JSON.stringify(this.buildOptions))
    },
    getUnits(f_building){
      f_building = f_building[0]
      console.log('f_building ===> ' + JSON.stringify(f_building))
      this.unitOptions = []
      this.$refs.paged.$refs.cri.model.f_unit = ''
      if(!f_building){
        return
      }
      let criteria = {
        items: 'f_unit',
        tablename: 't_check_plan_item',
        condition: `f_unit IS NOT NULL AND f_unit != '' AND ((f_complete = '' or f_complete = null or f_complete = '未完成') or (f_state = '未检')) AND f_residential_area = '${this.$refs.paged.$refs.cri.model.f_residential_area}' AND f_building = '${f_building}'`,
        groupitem: 'f_unit'
      }
      let result = new HttpResetClass().load('POST','/api/af-safecheck/sql/safe_singleTable_GroupBy', {data:criteria})
      if(result.code == 200){
        result.data.rows.forEach(item => this.unitOptions.push({label:item.f_unit,value:item.f_unit}))
      }
      console.log('this.unitOptions ===> ' + JSON.stringify(this.unitOptions))
    },











    reload(){
      // this.getAllArea()
      // this.getAllPlanName()
      // this.selfSearch()
           this.$refs.paged.loadPage(this.model.pageIndex)
    },






    selfSearch () {
      let condition = "1=1 and it.f_filialeid = '"+this.f_filialeids+"' and it.f_state ='未检' and it.f_safecheck_type='年度普检'"
      if(this.$refs.paged.$refs.cri.model.f_residential_area){
        if(this.$refs.paged.$refs.cri.model.f_residential_area.toString().trim()){
          condition += " and it.f_residential_area = '"+this.$refs.paged.$refs.cri.model.f_residential_area+"'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_building){
        if(this.$refs.paged.$refs.cri.model.f_building.toString().trim()){
          condition += " and it.f_building = '"+this.$refs.paged.$refs.cri.model.f_building+"'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_unit){
        if(this.$refs.paged.$refs.cri.model.f_unit.toString().trim()){
          condition += " and it.f_unit = '"+this.$refs.paged.$refs.cri.model.f_unit+"'"
        }
      }
      if(this.$refs.paged.$refs.cri.model.f_address){
        if(this.$refs.paged.$refs.cri.model.f_address.toString().trim()){
          condition += " and it.f_address like '%"+this.$refs.paged.$refs.cri.model.f_address+"%'"
        }
      }

      if(this.$refs.paged.$refs.cri.model.f_plan_id){
        if(this.$refs.paged.$refs.cri.model.f_plan_id.toString().trim()){
          condition += " and it.f_plan_id = '"+this.$refs.paged.$refs.cri.model.f_plan_id +"'"
        }
      }
      this.zdcon=condition
      condition+= " and tcp.f_checker='"+Vue.user.name+"'"
      console.log('condition ===> '+ condition)
      this.model.search(condition)
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    }
  }
}
</script>
