<template >
  <div class="panel panel-default auto repair-info-content">
    <div class="panel-body" v-show="show">
      <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" v-for="item in dataConfig">
                <div class="col-xs-4 col-sm-4 col-md-4">
                  {{item.value}}:
                </div>
                <div class="col-xs-8 col-sm-8 col-md-8">
                  {{row[item.name]}}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <p v-show="model.length == 0 ">此用户暂无购气记录</p>
    </div>
  </div>
</template>

<script>
import {HttpResetClass, PagedList} from 'vue-client'
import co from 'co'
export default {
  title: '查询用户',
  data () {
    return {
      model: [],
      show: false,
      row: Object,
      dataConfig:[]
    }
  },
  props: {
    user: {
      type: Object
    },
    f_userinfo_id:'',
    config:"",
  },
  methods: {
    convertArray(arr) {
      return arr.map(obj => {
        const key = Object.keys(obj)[0];
        return {
          name: key,
          value: obj[key]
        };
      });
    },

    getmodel () {
      let userinfoid
      if(this.f_userinfo_id){
        userinfoid = this.f_userinfo_id
      }else{
        userinfoid = this.user.f_userinfo_id
        console.log(this.user.f_userinfo_id)
      }
      console.log(userinfoid)
      new HttpResetClass().load('POST',`${this.$androidUtil.getProxyUrl()}/rs/logic/geUserInfoIdData`, {data: {condition:`f_userinfo_id = '${userinfoid}'`,type:this.config}},{resolveMsg : null,rejectMsg :null}).then((row) => {
        console.log("9898988",row)
        if(row.data.state===200){
          this.model = row.data.userdata
          this.dataConfig = this.convertArray(row.data.filename)
          this.show=true
        }
      })

    },
    back(){

    }
  },
  watch: {
    'user' (val) {
      // this.model.search(`card_id = ${this.user.card_id}`)
      if(this.user){
        if (!(this.user.isNuN)) {
          this.model= []
          this.getmodel()
        }
      }
    },
    'f_userinfo_id'(){
      if(this.f_userinfo_id){
        this.model= []
        this.getmodel()
      }
    }
  },
  ready () {
    console.log("9797977",this.config)
    if (this.user && this.user.f_userinfo_id) {
      // this.model.search(`card_id = ${this.user.card_id}`)
      this.getmodel()
    }
    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>
