<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>
            <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;white-space:nowrap;">{{ row.f_offsite_time }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_checker_name }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_plan_name }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_has_defect }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_defect_count }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_deal_count }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_is_deal }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_repairman }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_repaire_type }}</td>
          <td style="text-align: center;white-space:nowrap;">
            {{ $parent.$parent.$parent.trouble(row.f_defect_content) }}
          </td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  /**
   *用户档案相关信息组件
   */
  import { PagedList } from 'vue-client'
  import Vue from 'vue'
  import { isEmpty } from "../../Util"
  // 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 () {
      let model = new PagedList('rs/sql/GetCheckPaperByDefectNew2', 20, {
        f_filialeids: 'this.f_filialeids', f_defect_content: 'this.f_defect_content'
      })
      model.f_filialeids = '(' + this.$login.f.orgid + ')'
      model.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"
      return {
        model: model,
        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(() => {
          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 ('获取配置文件失败')
          })
      },
      trouble(val) {
        const defect_content = JSON.parse(val)
        let result = ''
        if (defect_content.data) {
          const jsonData = defect_content.data
          for (const itemdata of jsonData) {
            const keys = Object.keys(itemdata)
            for (const itm of keys) {
              const value = itemdata[itm]
              result += itm + ':' + value
            }
          }
        }
        return result
      },
      isSelected (row) {
        return this.row === row
      }
    },
    watch: {
      'user' (val) {
        // tag
        this.model.search(`f_userinfo_id = '${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_userinfo_id = '${this.row.f_userinfo_id}'`)
      }
    }
  }
</script>
