<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="tcp.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="tcp.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="tcp.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"
                          :format="'yyyy-MM-dd 00:00:000'"
                          :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"
                          :format="'yyyy-MM-dd 23:59:000'"
                          :show-reset-button="reset" readonly="readonly">
              </datepicker>
            </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 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="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-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 }}</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>检&ensp;查&ensp;项:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_device_type }}</p>
                </div>
                <div class="col-xs-6">
                  <p class="panel-title col-xs-5 text-left font"><b>隐&ensp;患&ensp;项:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_item_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-12">
                  <button type="button" name="button" class="btn btn-primary" style="background-color:#499edf;float: right" @click="$parent.$parent.$parent.openshowModal(row.f_path)">查看</button>
                  <button type="button" name="button" class="btn btn-primary" style="background-color:#499edf;float: right;margin-right:10px;" @click="$parent.$parent.$parent.openshowModal1(row.id)">处理</button>
                  <!--<button type="button" class="btn btn-default" @click="$parent.$parent.$parent.ceshi">确认2</button>-->
                </div>
              </div>
            </div>
          </div>
        </div>
      </list>
    </criteria-paged>
  </div>
  <modal :show.sync="showModal">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        隐患照片
      </h4>
    </div>
    <div slot="modal-body" class="modal-body">
      <div class="from-group">
        <div class="row">
          <div class="col-md-6">
            <img-self  :src="showimg"   width="300" height="400"></img-self>
          </div>
        </div>
      </div>
    </div>
    <div slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-default" @click="closeshowModal">确认</button>
    </div>
  </modal>
  <modal :show.sync="showModal1">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        处理结果
      </h4>
    </div>
    <div slot="modal-body" class="modal-body">
      <div class="form-group col-sm-12">

        <div class="auto">
          <div class="panel" style="padding: 10px 10px 5px 10px;">
            <div class="panel-body panel-self" style="background-color: #F8F8F8;width: 100%;height: 260px;position: relative">


              <img-self :src="deal.f_deal_path"  alt="整改照片" :width="140" :height="170" capture="camera" type="file" ></img-self>



              <div class="row text-right div-photo" style="height: 50px;margin-top: -30px">
                <img src="../../../assets/remove.png"  @click="delfile('f_deal_path', deal.f_deal_path)" ></img>
                <button type="button" name="button" class="btn btn-primary btn-photo" @click="takePic('f_deal_path','整改照片')" >拍照</button>

              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="row app-row">
        <div class="col-xs-2">
          <p class="panel-title  text-left font" style="text-align: center">备注</p>
        </div>
        <div class="col-xs-9">
          <textarea class="input-font " v-model=deal.f_deal_remark style="width: 100%"></textarea>
        </div>




      </div>
    </div>
    <div slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-default" @click="commitDealDefect">确认</button>
      <button type="button" class="btn btn-default" @click="closeshowModal1">取消</button>
    </div>
  </modal>

</template>

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

export default {
  title: '无计划安检查询',
  data() {
    return {
      showModal:false,
      showModal1:false,
      showimg:'',
      deal:{
        id:'',
        f_deal_path:'',
        f_deal_remark:'',
        f_dealer:Vue.user.name,
        f_dealer_id:Vue.user.id
      },
      f_filialeids:'',
      model:new PagedList( `${this.$androidUtil.getProxyUrl()}/rs/sql/AndroidDealWith`,20,{condition:'this.condition',f_filialeids:`'${Vue.user.orgid}'`,f_checker_id:`'${Vue.user.id}'`}),
      criteriaShow: false,

    }
  },
  ready(){
    this.selfSearch()
  },
  methods: {
    commitDealDefect(){
      console.log("77777777777777777777777")
      console.log(JSON.stringify(this.deal))
      HostApp.__this__ = this
      HostApp.logicWithHint({'logic': 'safe_dealWithDefect', 'callback': 'javascript: HostApp.__this__.commitCallBack()',
        'data': this.deal, 'backresult':1
      })
    },
    commitCallBack(jo){
      console.log("9999999999999999999")
      console.log(JSON.stringify(jo))
      if (jo.state == "ok"){
        this.$showMessage('提交成功')
        this.closeshowModal1()
      }else{
        this.$showMessage('提交失败')
      }
    },
    delfile(prop, fileName) {
      if (fileName == Vue.nopic)
        return
      else {
        HostApp.delfile(fileName)
        this.deal[prop] = Vue.nopic
      }
    },
    openshowModal(val){
      console.log("888888888888")
      console.log(val)
      this.showimg=`${this.$androidUtil.getProxyUrl()}/rs/image/file/`+val
      this.showModal=true
    },
    closeshowModal(){
      this.showimg=''
      this.showModal=false
    },
    openshowModal1(val){
      this.deal.id=val
      console.log("888888888888")
      console.log(this.deal.id)
      this.showModal1=true
    },
    closeshowModal1(){
      this.deal={
        id:'',
        f_deal_path:'',
        f_deal_remark:'',
        f_dealer:Vue.user.name,
        f_dealer_id:Vue.user.id
      }
      this.showModal1=false
      this.selfSearch()
    },
    cameraCallBack(prop, fileName) {
      HostApp.__this__.deal.f_deal_path = fileName + '?' + Math.random()
      HostApp.__callback__ = null
      HostApp.__this__ = null
    },
    takePic(prop, title) {
      HostApp.__callback__ = this.cameraCallBack
      HostApp.__this__ = this
      let fileName
      if (!this.deal.f_deal_path || this.deal.f_deal_path.includes("nopic.png")) {
        fileName = Util.guid() + '-' + prop + '.jpg'
      } else {
        fileName = Util.getFileName(this.deal.f_deal_path)
      }
      console.log(this.deal.f_deal_path)
      console.log("88888888888999999999999")
      HostApp._open_a_page({
        type: 'boomerang',
        page: 'com.aofeng.hybrid.android.peripheral.CameraActivity',
        param: {
          file: fileName,
          requestCode: 111,
          callback: 'javascript:HostApp.__callback__("' + prop + '", "%s");',
          watermark: title + '\t时间：' + Util.toStandardTimeString() + '\t' + Vue.user.name
        }
      })
    },
    selfSearch () {

      let condition = "1=1 "
      if(this.$refs.paged.$refs.cri.model.f_user_name){
        if(this.$refs.paged.$refs.cri.model.f_user_name.toString().trim()){
          condition += " and tcp.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 tcp.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 tcp.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 tdl.f_create_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 tdl.f_create_time < '"+this.$refs.paged.$refs.cri.model.f_end_date +"'"
        }
      }

      console.log('condition ===> '+ condition)
      this.model.search(condition)
    },

    hidden() {
      this.criteriaShow = !this.criteriaShow
    }
  }
}
</script>
