<template>
  <div style="height: 100%;width: 100%;padding:10px 0px 10px 0px;">
    <div  class="auto" >
      <partial-view v-ref:pv>
        <div class="row text-left" style="padding-bottom: 10px">
          <label class = "col-sm-3 control-label">用户编号:</label>
          <span class = "col-sm-9">{{rowdata.f_userinfo_code}}</span>
        </div>
        <div class="row text-left" style="padding-bottom: 10px">
          <label class = "col-sm-3 control-label">用户姓名:</label>
          <span class = "col-sm-9">{{rowdata.f_user_name}}</span>
        </div>
        <div class="row text-left" style="padding-bottom: 10px">
          <label class = "col-sm-3 control-label">用户类型:</label>
          <span class = "col-sm-9">{{rowdata.f_user_type}}</span>
        </div>
        <div class="row text-left" style="padding-bottom: 10px">
          <label class = "col-sm-3 control-label">用户地址:</label>
          <span class = "col-sm-9">{{rowdata.f_address}}</span>
        </div>
        <!--        <div class="row text-left" style="padding-bottom: 10px">-->
        <!--          <label class = "col-sm-3 control-label">安检次数:</label>-->
        <!--          <span class = "col-sm-9">{{model.rows.length}}</span>-->
        <!--        </div>-->
      </partial-view>
    </div>
    <data-grid :model="model" partial='list' v-ref:grid>
      <template partial='head'>
        <tr>
          <th>安检人</th>
          <th>安检开始时间</th>
          <th>安检结束时间</th>
          <th>安检状态</th>
          <th>隐患情况</th>
          <th>操作</th>
        </tr>
      </template>
      <template partial='body'>
        <tr style="text-align: center">
          <td>{{row.f_checker_name}}</td>
          <td>{{row.f_onsite_time}}</td>
          <td>{{row.f_offsite_time}}</td>
          <td>{{row.f_entry_status}}</td>
          <td>{{$parent.$parent.getDefect(row.f_defect_content)}}</td>
          <td>
            <button class="button_spacing button_search-1" @click='$parent.$parent.goDetail(row)'>查看</button>
          </td>
        </tr>
      </template>
    </data-grid>
  </div>
</template>

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

  let asyncReady = async function (self) {
    // 获取配置信息
    try {
      let res = await Vue.resetget(`/phone/rs/vue`, {data: {}}, {resolveMsg: null, rejectMsg: null})
      Vue.config = res.data
    } catch (error) {
      // 忽略704,文件找不到异常R
      if (error.status !== 704) {
        throw error
      }
    }
  }

export default {
  title: '安检记录列表(未整合)',
  props: ['row'],
  data () {
    return {
      rowdata: this.row,
      model: new PagedList('api/af-safecheck/sql/QueryCheckPaperTS', 10, {
        f_filialeid:"''",
        f_plan_id: "''",
        f_approved: "''",
        f_entry_status: "''",
        f_no_checkplan: "''",
        orderitem: "'f_offsite_time desc'"
      })
    }
  },
  ready () {
    console.log("开始加载列表------------------------------")
    console.log(`('${this.$login.f.orgid}')`)
    this.rowdata = this.row
    var condition = "f_userinfoid = '"+ this.row.f_userinfo_id +"'"

      this.model.search(condition)
    },
    watch: {
      'row' (val) {
        if(val){
          this.rowdata = val
          var condition =  "f_userinfoid = '"+ this.row.f_userinfo_id +"'"
          this.model.search(condition)

        }
      }
    },
    methods: {
      getDefect(val){
        if(val){
          try {
            var defect = JSON.parse(val)
            return defect.result
          }catch (e) {
            console.log(val)
            return '正常'
          }
        }
        return '正常'
      },
      goDetail(row){
        asyncReady(this).then(() => {
          row.f_upload_state = '已传'
          this.$goto('new-check-paper-ts', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
        }).catch(
          (respanse) => {
            alert('获取配置文件失败')
          })
      }
    }
  }
</script>
