<template>
  <div id="pc-finduser-page">
    <criteria-paged :model="model" v-ref:paged :simple="true">

      <data-grid :model="model" partial='list' v-ref:grid
                 class="list_area table_sy">
        <template partial='head'>
          <tr>
            <th><nobr>安检日期</nobr></th>
            <th><nobr>入户情况</nobr></th>
            <th><nobr>安检员</nobr></th>
            <th> <nobr>隐患明细</nobr></th>
            <th>
              <nobr>操作</nobr>
            </th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center"><nobr>{{row.f_onsite_time.substring(0,11)}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_entry_status}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_checker_name}}</nobr></td>
          <td style="text-align: center" ><nobr>{{row.f_defect_text?row.f_defect_text:$parent.$parent.$parent.getjsonData(row.f_defect_content)}}</nobr></td>
          <td style="text-align: center">
            <button class="button_spacing button_search-1" @click='$parent.$parent.$parent.change(row)'>查看</button>
          </td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>

</template>

<script>
  /**
   *用户档案相关信息组件
   */
  import { PagedList } from 'vue-client'
  import Vue from 'vue'
  import { isEmpty } from "../../Util"
  import HttpResetClass from "vue-client/src/plugins/HttpResetClass";
  // import newCheckPaper from "./NewCheckpaper.vue"
  // 获取json配置文件
  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: '用户安检历史',
    data () {
      return {
        model: new PagedList('rs/sql/findCheckPaper', 5),
        row: Object,
        infoshow: false,
        onedata: Object
      }
    },
    props: {
      user: {
        type: Object
      },
      clearflg: 0,
      row: {
        type: Object
      }
    },
    methods: {
      close () {
        this.infoshow = false
      },
      change (row) {
        // Vue.$login = {jwt: row.f_checker_id}
        asyncReady(this).then(() => {
          console.log("1234658", row)
          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 ('获取配置文件失败')
          })
      },
      getjsonData (value) {
        // 将value字符串转换成json对象
        let jsonStr = JSON.parse(value)
        let str = jsonStr.data
        if (jsonStr.result === '正常') {
          return '正常'
        } else {
          let result = ''
          if (str) {
            for (const itemdata of str) {
              const keys = Object.keys(itemdata)
              for (const itm of keys) {
                const value = itemdata[itm]
                result += itm + ':' + value + ' '
              }
            }
          }
          return result
        }
      },
      selected (row) {
        if (this.row === row) {
          this.row = null
        } else {
          this.row = row
        }
      },
      isSelected (row) {
        return this.row === row
      }
    },
    watch: {
      'user' (val) {
        // tag
        this.model.search(`f_userinfoid = '${this.row.f_userinfo_id}'`)
      },
      'clearflg' () {
        this.model.rows = []
      }
    },
    ready () {
      console.log('看看row的信息', this.row)
      if (this.row.f_userinfo_id) {
        this.model.search(`f_userinfoid = '${this.row.f_userinfo_id}'`)
      }
    }
  }
</script>
