<template>
  <div class="panel panel-default auto repair-info-content">
    <div class="panel-body">
      <div v-show="title_name == '缴费记录'">
        <div class="panel panel-default well" v-for="row in model">
          <div class="bg-info">
            <div class="row form-group">
              <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="row">
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    购气量: {{ row.f_pregas }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    购气金额: {{ row.f_preamount }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    收费状态: {{ row.f_state }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    缴费方式: {{ row.f_payment }}
                  </div>
                  <div class="col-xs-12 col-sm-12 col-md-12">
                    购气时间: {{ row.f_operate_date.substring(0, 11) }} {{ row.f_operate_date.substring(11, 19) }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-show="title_name == '抄表记录'">
        <div class="panel panel-default well" v-for="row in model">
          <div class="bg-info">
            <div class="row form-group">
              <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="row">
                  <div class="col-xs-12 col-sm-12 col-md-12">
                    抄表时间: {{ row.f_operate_date.substring(0, 11) }} {{ row.f_operate_date.substring(11, 19) }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    抄表状态: {{ row.f_meter_state }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    气表分类: {{ row.f_meter_classify }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    用户类型: {{ row.f_user_type }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    用户地址: {{ row.f_address }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    用户姓名: {{ row.f_user_name }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    本次底数: {{ row.f_tablebase }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    上次底数: {{ row.f_last_tablebase }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-show="title_name == '指令记录'">
        <div class="panel panel-default well" v-for="row in model">
          <div class="bg-info">
            <div class="row form-group">
              <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="row">
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    执行结果: {{ row.f_receive_state }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    指令类型: {{ row.f_instruct_type }}
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    指令状态: {{ row.f_instruct_state }}
                  </div>
                  <div class="col-xs-12 col-sm-12 col-md-12">
                    指令时间: {{ row.f_instruct_date }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-show="title_name == '安检记录'">
        <div class="panel panel-default well" v-for="row in model">
          <div class="bg-info">
            <div class="row form-group">
              <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="row">
                  <div class="col-xs-12 col-sm-12 col-md-12">
                    安检时间: {{ row.f_offsite_time }}
                  </div>
                  <div class="col-xs-12 col-sm-12 col-md-12">
                    安检状态: {{ row.f_entry_status }}
                  </div>
                  <div class="col-xs-12 col-sm-12 col-md-12">
                    安检结果: {{ row.f_defect_text }}
                  </div>
                  <div class="col-xs-12 col-sm-12 col-md-12">
                    安检员: {{ row.f_checker_name }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <p v-show="model.length == 0 ">{{ message }}</p>
    </div>
  </div>
</template>

<script>

  export default {
    title: '查询用户',
    data() {
      return {
        model: [],
        show: false,
        row: Object,
        title_name: '',
        message: '请稍候。。。。。。'
      }
    },
    props: {
      user: {
        type: Object
      },
      f_userinfo_id: ''
    },
    methods: {
      getmodel() {
        let userinfoid
        if (this.f_userinfo_id) {
          userinfoid = this.f_userinfo_id
        } else {
          userinfoid = this.user.f_userinfo_id
        }
        this.title_name = this.title
        let searchItems = ''
        let tableName = ''
        let orderByItems = ''
        let condition = `f_userinfo_id = '${userinfoid}'`
        switch (this.title) {
          case '指令记录':
            searchItems = 'f_receive_state,f_instruct_type,f_instruct_state,f_instruct_date'
            tableName = 't_instruct'
            orderByItems = 'f_instruct_date desc'
            break
          case '缴费记录':
            searchItems = 'f_pregas,f_preamount,f_payment,f_operate_date,f_state'
            tableName = 't_sellinggas'
            orderByItems = 'f_operate_date desc'
            break
          case '抄表记录':
            searchItems = 'f_operate_date,f_meter_state,f_meter_classify,f_user_type,f_address,f_user_name,f_tablebase,f_last_tablebase'
            tableName = 't_handplan'
            orderByItems = 'f_operate_date desc'
            break
          case '安检记录':
            searchItems = "f_offsite_time,f_entry_status,CASE WHEN CHARINDEX( '\"result\":\"正常\"', f_defect_content ) > 0 THEN '无隐患' ELSE replace(replace(replace( replace( RIGHT ( f_defect_content, len( f_defect_content ) - 26 ), substring('{}',2,1), '' ), substring('{}',1,1), '' ),']',''),'\"','') END as f_defect_text,f_checker_name"
            tableName = 't_check_paper'
            orderByItems = 'f_offsite_time desc'
            condition = `f_userinfoid = '${userinfoid}'`
            break
        }
        this.searchHistory(userinfoid, searchItems, tableName, orderByItems,condition)
      },
      back() {

      },
      searchHistory(userinfoid, searchItems, tableName, orderByItems,condition) {
        this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/sql/tel_singleTable_OrderBy`, {
          data: {
            items: searchItems,
            tablename: tableName,
            orderitem: orderByItems,
            condition: condition
          }
        }).then(resp => {
          this.model = resp.data
          if (this.model.length == 0) {
            this.message = '该用户暂无' + this.title_name
          }
        }).catch(error => {
          this.message = '该用户暂无' + this.title_name
        })
      }
    },
    watch: {},
    ready() {
      if (this.user && this.user.f_userinfo_id) {
        this.getmodel()
      } else if (this.f_userinfo_id) {
        this.getmodel()
      }
    }
  }
</script>
<style>
  .app-botton {
    position: fixed;
    background: #87b2dd;
    color: #FFF;
    padding: 8px;
    text-align: center;
    font-size: 1.2em;
    z-index: 10;
    opacity: 0.5;
    bottom: 50px;
    margin-top: -10px;
    height: 40px;
  }
</style>
