<template >
  <div class="panel panel-default auto repair-info-content">
    <div class="panel-body">
      <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_service_id}}
                </div>
                <div class="col-xs-6 col-sm-6 col-md-6">
                  电话: {{row.f_contact_phone}}
                </div>
                <div class="col-xs-6 col-sm-6 col-md-6">
                  维修状态: {{row.processins.activities[row.processins.activities.length-1].defname}}
                </div>
                <div class="col-xs-6 col-sm-6 col-md-6">
                  派单时间: {{row.f_created_date}}
                </div>
                <div class="col-xs-6 col-sm-6 col-md-6">
                  结束时间: {{row.serviceacitivity[row.serviceacitivity.length-1].f_date_leave}}
                </div>
                <div class="col-xs-12 col-sm-12 col-md-12">
                  维修员: {{row.f_order_man}}
                </div>
                <div class="col-xs-12 col-sm-12 col-md-12">
                  维修内容: {{getfailure(row.failure)}}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <p v-show="model.length == 0 ">此用户暂无维修记录</p>
    </div>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'
  import { HttpResetClass } from 'vue-client'
  import co from 'co'
  export default {
    title: '查询用户',
    data () {
      return {
        model: [],
        show: false,
        row: Object
      }
    },
    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
          console.log(this.user.f_userinfo_id)
        }
        console.log(userinfoid)
        let http=new HttpResetClass
        http.load('POST',`${this.$androidUtil.getProxyUrl()}/rs/path/serviceSummery`, {data:{condition: {condition1: `f_userinfo_id = '${userinfoid}'`, condition2: "", condition3: "1=1", condition4: "1=1"}}}, {resolveMsg: null, rejectMsg: null}).then((row) => {

          this.model = row.data
          console.log("model=========="+JSON.stringify(this.model))
        })
      },
      getfailure(failure){
        let failureJson=JSON.parse(failure)
        let showfailure=''
        for (let i = 0; i <failureJson.length ; i++) {
          let fault=failureJson[i]
          if (fault.f_failure_type){
            console.log(fault.f_failure_type)
            showfailure+=fault.f_failure_type+":"
          }
          if (fault.f_equipment){
            console.log(fault.f_equipment)
            showfailure+=fault.f_equipment+","
          }
          if (fault.failurecase){
            for (let j = 0; j <fault.failurecase.length ; j++) {
              if (i==failureJson.length-1&&j==fault.failurecase.length-1){
                showfailure+=fault.failurecase[j]+"."
              }else {
                showfailure+=fault.failurecase[j]+","
              }
            }
          }
        }
       return showfailure
      },
      back(){

      }
    },
    watch: {
      'user' (val) {
        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("进去维修组件的ready=====================>"+this.f_userinfo_id)
      if (this.user && this.user.f_userinfo_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>
