<template>
  <div>
    <j-modal
      :title="title"
      width="70%"
      :visible="visible"
      :mask-closable="false"
      cancel-text="关闭"
      @close="close"
    >
      <!-- 操作按钮区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-form-item>
            <j-dict-select-tag
              v-model="queryParam.toolType"
              style="width: 150px"
              placeholder="选择工具名称"
              dict-code="tool_type"
            />
          </a-form-item>
          <a-form-item>
            <a-tree-select
              v-model="queryParam.deptId"
              style="width: 150px"
              :show-search="true"
              allow-clear
              placeholder="选择车间"
              :tree-data="treeData"
              tree-node-filter-prop="label"
              :replace-fields="{children:'children', title:'label', key:'id', value: 'id' }"
            />
          </a-form-item>
          <a-form-item>
            <a-input
              v-model="queryParam.storePlace"
              style="width: 150px"
              placeholder="输入存放处"
            />
          </a-form-item>
          <a-form-item>
            <a-date-picker
              v-model="queryParam.lastTestDate"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              placeholder="上次检验日期"
            />
          </a-form-item>
          <a-form-item>
            <a-input
              v-model="queryParam.toolCode"
              style="width: 150px"
              placeholder="输入编号"
            />
          </a-form-item>
          <a-form-item>
            <a-button type="primary" @click="searchQuery">查询</a-button>
            <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
          </a-form-item>
        </a-form>
      </div>

      <!-- table区域-begin -->
      <div style="margin-top: 10px">
        <a-table
          ref="table"
          size="middle"
          bordered
          row-key="toolId"
          :columns="columns"
          :data-source="dataSource"
          :pagination="ipagination"
          :loading="loading"
          @change="handleTableChange"
        >
          <template slot="isok" slot-scope="text, record">
            <span>{{ record.isok==='1'?'合格':'不合格' }}</span>
          </template>
        </a-table>
      </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    </j-modal>
  </div>
</template>
<script>
import { listMixin } from '@/mixin/listMixin'
import { getAction, httpAction } from '@/api/request'
import JModal from '@/components/JModal'
import columns from './syColumns'

export default {
  name: 'SyList',
  components: {
    JModal
  },
  mixins: [listMixin],
  data() {
    return {
      title: '完成试验',
      visible: false,
      queryParam: {},
      // 表头
      isNotCreateLoad: true,
      columns: columns(this),
      treeData: [],
      id: '',
      url: {
        list: '/business/safetool/base/safety/tool/listExperimentTool',
        tree: '/system/dept/treeSelect'
      }

    }
  },
  created() {
  },
  methods: {
    edit(record) {
      this.id = record.id
      this.loadData()
      this.visible = true
    },
    loadData() {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      var params = this.getQueryParams()// 查询条件
      this.queryParam = Object.assign({}, params, { id: this.id })
      this.loading = true
      getAction(this.url.list, this.queryParam).then((res) => {
        if (res.code === 200) {
          this.dataSource = res.rows || res.data
          if (res.total) {
            this.ipagination.total = res.total
          } else {
            this.ipagination.total = 0
          }
        } else {
          this.$message.warning(res.msg)
        }
      }).finally(() => {
        this.loading = false
      })
    },
    loadTree() {
      this.treeData = []
      getAction(this.url.tree).then((res) => {
        if (res.code === 200) {
          this.treeData = res.data
        }
      })
    },
    close() {
      this.visible = false
    }
  }
}
</script>
