<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_address }}</span>
        </div>
      </partial-view>
    </div>
    <data-grid :model="model" partial='list' class="list_area table_sy" 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 style="text-align: center">{{ row.f_checker_name }}</td>
          <!--          <td>{{row.f_onsite_time}}</td>-->
          <td style="text-align: center">{{ row.f_offsite_time }}</td>
          <td style="text-align: center">{{ row.f_entry_status }}</td>
          <!--          <td>{{$parent.$parent.getDefect(row.f_defect_content)}}</td>-->
          <td style="text-align: center">
            <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('rs/sql/查找安检单', 10, {
        f_filialeid: "''",
        f_plan_id: "''",
        f_approved: "''",
        f_entry_status: "''",
        f_no_checkplan: "''",
        orderitem: "'f_offsite_time desc'"
      })
    }
  },
  ready() {
    //tag
    this.rowdata = this.row
    var condition = "f_userinfoid = '" + this.row.f_userinfoid + "'"
     this.model.params.f_defect_content="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"
    this.model.search(condition)
  },
  watch: {
    'row'(val) {
      if (val) {
        this.rowdata = val
        var condition = "f_userinfoid = '" + this.row.f_userinfoid + "'"
        this.model.search(condition)

      }
    }
  },
  methods: {
    getDefect(val) {
      if (val) {
        try {
          var defect = JSON.parse(val)
          return defect.result
        } catch (e) {
          //tag
          return '正常'
        }
      }
      return '正常'
    },
    goDetail(row) {
      //tag
      //Vue.$login = {jwt: row.f_checker_id}
      asyncReady(this).then(() => {
        row.f_upload_state = '已传'
        this.$goto('new-check-paper', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')

      }).catch(
        (respanse) => {
          alert('获取配置文件失败')
        })
    }
  }
}
</script>
