<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工器具名称" prop="equipName" label-width="120">
        <el-input
          v-model="queryParams.equipName"
          placeholder="请输入工器具名称"
          v-no-whitespace
          maxlength="100"
          show-word-limit
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="equipList" @selection-change="handleSelectionChange">
      <el-table-column
        type="index"
        width="55"
        label="序号"
        align="center"
        :index="indexContinuous(queryParams.pageNum, queryParams.pageSize)"
      />
      <el-table-column label="工器具名称" align="center" prop="equipName" />
      <el-table-column label="型号" align="center" prop="model" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="数量" align="center" prop="num" />
      <el-table-column label="设备类型" align="center" prop="equipType" />
      <el-table-column label="检测时间" align="center" prop="detectionTime" />
      <el-table-column label="是否强制检测检验" align="center" prop="isForceDetection" />
      <el-table-column label="下次检测时间" align="center" prop="nextDetectionTime" />
      <el-table-column label="工器具文件">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleShow(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="入场时间" align="center" prop="admissionDate" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleView(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="工器具信息" :visible.sync="message" width="80%" top="5vh" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <bns-equip-details-tabs :items="items" :isDisabled="true" />
        <el-form-item label="工器具文件" label-width="200px">
          <bns-file-list-tabs :items="fileList"/>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="工器具文件" :visible.sync="document" width="80%" top="5vh" append-to-body>
      <div style="width: 100%;height:720px">
        <bns-file-list-tabs :items="fileList" />
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listEquip, selectDetails } from '@/api/pro/cons/equip'
import BnsEquipDetailsTabs from '@/components/pro-tabs/bns-equip-details-tabs.vue'
import BnsFileListTabs from '@/components/pro-tabs/bns-file-list-tabs.vue'
import { indexContinuous } from '@/utils/bonus'

export default {
  name: 'Post',
  components: { BnsFileListTabs, BnsEquipDetailsTabs },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工程表格数据
      equipList: [],
      items: {},
      fileList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      document: false,
      message: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equipName: undefined,
        type: '列表'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}

    }
  },
  created() {
    this.getList()
  },
  methods: {
    indexContinuous,
    /** 查询工程列表 */
    getList() {
      this.loading = true
      this.queryParams.proId = this.$store.state.user.thisIds.proId
      this.queryParams.consUuid = this.$store.state.user.thisIds.consUuid
      listEquip(this.queryParams).then(response => {
        this.equipList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        equipName: undefined,
        postSort: 0
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.proId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 文件查看按钮操作 */
    handleShow(row) {
      this.reset()
      this.document = true
      selectDetails({ uuid: row.uuid }).then(response => {
        this.fileList = response.fileList
        this.loading = false
      })
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.message = true
      selectDetails({ uuid: row.uuid }).then(response => {
        this.items = response.data
        this.fileList = response.fileList
        this.loading = false
      })
    }
  }
}
</script>
