<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 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 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 class="font text-left">安检员：</label>
              </div>
              <div class="col-xs-8">
                <v-select :value.sync="model.check" v-model='model.check'
                          :value-single="true"
                          class="select_list select"
                          :options='$parent.$parent.checkers'
                          placeholder='安检员'
                          close-on-select width="100%"></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">
                <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:00'"
                            :show-reset-button="reset"
                            condition="tcp.f_offsite_time > '{}'"
                            readonly="readonly">
                </datepicker>
              </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">
                <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:00'"
                            :show-reset-button="reset"
                            condition="tcp.f_offsite_time < '{}'"
                            readonly="readonly">
                </datepicker>
              </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 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: 23%;float: left"><b>安检时间:</b></p>
                  <p class="panel-title text-left input-font" style="width: 77%">{{ row.f_create_time }}</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-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_checker_name }}</p>
                </div>
                <div class="col-xs-12">
                  <p  class="panel-title col-xs-5 text-left font"><b>不通过原因:</b></p>
                  <p  style="color: red"   class="panel-title col-xs-7 text-left input-font">{{ row.f_approved_note }}</p>
                </div>
                <div class="col-xs-12">
                  <button type="button" name="button" class="btn btn-primary"
                          style="background-color:#499edf;float: right;margin-right:10px;"
                          @click="$parent.$parent.$parent.Handle(row)">处理
                  </button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </list>
    </criteria-paged>
  </div>
</template>
<script>
import Vue from 'vue'
import {HttpResetClass, PagedList} 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) => {
    //tag
    self.checkers.push({label:'全部',value:''})
    res.data.forEach((checker)=>{
      self.checkers.push({label:checker.name,value:checker.name})
    })
  })
}
export default {
  title: '安检单驳回',
  data() {
    return {
      checkers: [],
      showModal: false,
      f_filialeids: '',
      model: new PagedList(`${this.$androidUtil.getProxyUrl()}/rs/sql/AndroidGetcheckpaper`, 20, {
        condition: 'this.condition',
        f_filialeid: `'${Vue.user.orgid}'`,
        f_checker_id: `'${Vue.user.id}'`
      }),
      criteriaShow: false,
      select: {}
    }
  },
  ready() {
    this.selfSearch()
    let gen = select(this)
    co(gen)
  },
  methods: {
    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 tcp.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 tcp.f_offsite_time <= '" + this.$refs.paged.$refs.cri.model.f_end_date + "'"
        }
      }

      if (this.$refs.paged.$refs.cri.model.check) {
        if (this.$refs.paged.$refs.cri.model.check.toString().trim()) {
          condition += " and tcp.f_checker_name like '%" + this.$refs.paged.$refs.cri.model.check + "%'"
        }
      }else{
        condition += " and tcp.f_checker_name like '%" + Vue.user.name+ "%'"
      }
      this.model.search(condition)
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    Handle(row) {
      //跳转到无计划安检
      if (row.f_userinfo_code) {
        let http = new HttpResetClass()
        http.load('POST', `${this.$androidUtil.getProxyUrl()}/rs/sql/提取用户档案`, {data: {condition: "f_userinfo_code= '" + row.f_userinfo_code + "'",
            groupitem:'', orderitem: 'f_residential_area,CAST(build as int),f_unit,CAST(floor1 as int),f_room', f_check_type: '',f_filialeid:'',
            f_user_name: '', myCycle: '', fyCycle: '', f_user_type: '', f_sign: '', f_residential_area: '', f_address: '', f_user_state: '', f_orgids: '', f_unit: '', f_building: ''
          }}).then(
          (res) => {
            if(res.data.length==0){
              this.$showMessage('未查询到当前用户档案信息')
              return
            }
            let info = res.data[0]
            info.id = ''
            info.f_state = '未检'
            info.f_no_checkplan = '无计划安检'
            this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/sql/查询计划项表信息`,{data:{f_userid:info.f_userinfo_id}}).then((response)=>{
              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:'rejectInspecCheck'}, 'self', this.selfSearch)
            })
          })
      }
    },
    reassign(row) {
      this.select = row
      this.showModal = true
    },
    manyisok() {
      let  sqlstr=`update t_check_paper set f_checker_reciver='${this.check}' where id='${this.select.id}'`
      let http = new HttpResetClass()
      http.load('POST', 'rs/logic/runSQL', {data: {sql: sqlstr}},
        {resolveMsg: null, rejectMsg: '移出安检册失败'}).then(resp=>{
        this.showModal = false
        this.selfSearch()
      }).catch(error=>{
        this.$showMessage('转单失败',error)
      })
    },
    iscancel() {
      this.showModal = false
    }
  }
}
</script>
