<template>
  <div>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <!-- 操作按钮区域 -->
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <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-select
            v-model="queryParam.labId"
            placeholder="选择实验室"
            style="width:150px"
          >
            <a-select-option value="">
              请选择
            </a-select-option>
            <a-select-option
              v-for="(item,index) in dictOptions"
              :key="index"
              :value="item.deptId"
            >
              <span style="display: inline-block;width: 100%" :title=" item.deptName ">
                {{ item.deptName }}
              </span>
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item>
          <a-date-picker
            v-model="queryParam.endTime"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            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="id"
        :columns="columns"
        :data-source="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a-button size="small" type="link" @click="handleEdit(record)">
            完成实验
          </a-button>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <dy-list ref="modalForm" />
  </div>
</template>
<script>
import { listMixin } from '@/mixin/listMixin'
import columns from './indexColumns'
import { getAction, httpAction } from '@/api/request'
import dyList from './dyList'
export default {
  components: { dyList },
  mixins: [listMixin],
  data() {
    return {
      // 查询条件
      queryParam: { state: 0 },
      treeData: [],
      dictOptions: [],
      // 表头
      columns: columns(this),
      url: {
        list: '/business/safetool/sec/experiment/list',
        tree: '/system/dept/treeSelect',
        sysListL: '/system/dept/listLab'
      }
    }
  },
  created() {
    this.loadTree()
    this.getSysList()
  },
  methods: {
    handleEdit: function(record) {
      httpAction('/business/safetool/sec/experiment/expEnd', record, 'post').then((res) => {
        if (res.code === 200) {
          this.$refs.modalForm.edit(record)
          this.$refs.modalForm.title = '编辑'
          this.$refs.modalForm.disableSubmit = false
          this.$message.success(res.msg)
        } else {
          this.$message.error(res.msg)
          console.log(res)
        }
      })
    },
    loadTree() {
      this.treeData = []
      getAction(this.url.tree).then((res) => {
        if (res.code === 200) {
          this.treeData = res.data
        }
      })
    },
    getSysList() {
      getAction(this.url.sysListL).then((res) => {
        if (res.code === 200) {
          this.dictOptions = res.data
        }
      })
    }
  }
}
</script>
<style scoped>
  @import '~@/assets/less/common.less'
</style>
