<template>
  <div class="auto">
    <criteria-paged :model="model"  v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
        <div partial>
          <form>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/用户ID.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 col-sm-8 col-md-8" >
                <input class="search_input input-font"
                       v-model=model.f_card_id condition="f_card_id = '{}'" placeholder="请输入卡号" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/用户ID.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 col-sm-8 col-md-8" >
                <input class="search_input input-font"
                       v-model=model.f_meternumber condition="f_meternumber = '{}'" placeholder="请输入表号" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/用户姓名.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户名称：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input class="search_input input-font" v-model="model.f_username" placeholder="请输入用户名称">
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">小区名称：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_residential_area" placeholder="请输入用户小区（可模糊查询）">
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-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 col-sm-8 col-md-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_building" placeholder="请输入用户楼号">
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-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 col-sm-8 col-md-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_unit" placeholder="请输入用户单元">
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户地址：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input style="width: 100%" class="search_input input-font" v-model="model.f_address" placeholder="请输入用户地址（可模糊查询）">
              </div>
            </div>
            <!--<div class="row col-xs-12 col-sm-6 col-md-6 app-row">-->
            <!--<div class="col-xs-4 col-sm-4 col-md-4">-->
            <!--<img src="../../assets/安检状态.png" style="width: 20px;margin-bottom: 5px" alt="">-->
            <!--<label class="font text-left">用户状态：</label>-->
            <!--</div>-->
            <!--<div class="col-xs-8 col-sm-8 col-md-8-8" >-->
            <!--<v-select class="input-font"-->
            <!--placeholder='请选择用户状态'-->
            <!--:value.sync="model.f_table_state"-->
            <!--:options='$parent.$parent.f_table_states'-->
            <!--v-model="model.f_table_state"-->
            <!--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" >-->
            <!--<v-select class="input-font"-->
            <!--placeholder='请选择安检类型'-->
            <!--:value.sync="$parent.$parent.model.f_check_type"-->
            <!--:options='$parent.$parent.f_check_types'-->
            <!--close-on-select clear-button></v-select>-->
            <!--</div>-->
            <!--</div>-->

            <div class="row col-xs-12 col-sm-12 col-md-6 text-center" style="margin-top: 20px;">
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 45%;" @click="search">查询</button>
            </div>
            <div style="height:30px;"></div>
          </form>
        </div>
      </criteria>

      <list :model="model" partial='list'>
        <div partial>
          <div @click="$parent.$parent.$parent.inspect(row)" class="auto app-text" style="margin-top: 5px;">
            <div class="panel" style="padding: 10px 10px 5px 10px;"
                 :class="{
                   'panel-orange': row.f_emphasis_user === '星级用户',
                   'panel-sky'   : row.f_emphasis_user === '行业内用户',
                   'panel-green' : row.f_emphasis_user === '职工用户'
                 }">
              <div class="panel-body panel-self">
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">卡&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_card_id }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户名称</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_user_name }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户类型</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8-8 text-left input-font">{{ row.f_user_type }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">表具状态</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8-8 text-left input-font">{{ row.f_table_state }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">开户状态</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8-8 text-left input-font">{{ row.archives_state }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户电话</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone }}</p>
                </div>

                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">小区名称</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_residential_area }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4-4 text-left font">用户地址</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_address }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">最后安检日期</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_last_check_date }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">最后安检状态</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_last_check_state }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font" :style="{color:$parent.$parent.$parent.isYearDifference(3,row.f_last_check_date)?'red':''}">最后入户日期</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font" :style="{color:$parent.$parent.$parent.isYearDifference(3,row.f_last_ruhu_date)?'red':''}">{{ row.f_last_ruhu_date }}</p>
                </div>
              </div>
            </div>

          </div>
        </div>
      </list>
    </criteria-paged>
    <back-page :need-back='true'   @flag="$back()"></back-page>
  </div>
</template>

<script>
import { PagedList } from 'vue-client'
import Vue from 'vue'

export default {
  title: '安检员B',
  data () {
    let model = new PagedList(`${this.$androidUtil.getProxyUrl()}/rs/sql/FetchUserByChecker`,
      20,
      {
        groupitem: "''",
        orderitem: '"ud.f_residential_area,ud.f_address"',
        f_user_name:'this.model.f_username',
        f_residential_area:'this.model.f_residential_area',
        f_address:'this.model.f_address',
        f_unit:'this.model.f_unit',
        f_building:'this.model.f_building'
      })
    model.f_sign = ['']
    model.f_user_type = ''
    return {
      model: model,

    }
  },
  ready () {
  },
  computed: {
    reload(){
      this.$refs.paged.loadPage(this.$refs.paged.model.pageIndex)
    },
    selected () {
      return this.$refs.paged.$refs.grid.selected
    }
  },
  methods:{
    inspect (info){
      info.id = ''
      info.f_state = '未检'
      info.f_no_checkplan = '无计划安检'
      if(info.f_user_type == '民用') {
        this.$goto('paper-set', {item: info, role: 'inspect'}, 'self', this.reload)
      } else {
        // 长安不存在非民用安检（暂时无用）
        this.$goto('paper-set-noncivil', { item: info, role: 'inspect'}, 'self', this.reload)
      }
    },
    isYearDifference(yearNum, d1, date2 = new Date() ) {
      // const date1 = new Date(d1);
      // const date2 = new Date(d2);
      if(d1){
        const date1 = new Date(d1);
        // 计算完整年份差值
        let diff = date2.getFullYear() - date1.getFullYear();

        // 如果日期未超过，则减少一年
        if (
          date2.getMonth() < date1.getMonth() ||
          (date2.getMonth() === date1.getMonth() && date2.getDate() < date1.getDate())
        ) {
          diff--;
        }
        // 判断是否相差 yearNum 年以上
        return Math.abs(diff) >= yearNum;
      }
    }
  }
}
</script>
<style>
/* 星级用户 → 橙黄边框 */
.panel-orange {
  border: 2px solid #FFA940 !important; /* 橙黄色 */
  border-radius: 10px;
}

/* 行业内用户 → 天蓝色边框 */
.panel-sky {
  border: 2px solid #40A9FF !important; /* 天蓝色 */
  border-radius: 10px;
}

/* 职工用户 → 绿色边框 */
.panel-green {
  border: 2px solid #52C41A !important; /* 绿色 */
  border-radius: 10px;
}
.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>
