<template>
  <el-dialog
    title="检验方案明细"
    :visible.sync="visible"
    append-to-body
    width="1200px"
    @open="dialogOpen"
  >

    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
    >
      <SearchBar :show-more="true" :show-span="6" :collapse-span="6">
        <template #header>
          <el-col :span="6">
            <el-form-item label="物料编号" prop="code">
              <el-input
                v-model="queryParams.code"
                placeholder="请输入物料编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="下限值" prop="minValue">
              <el-input
                v-model="queryParams.minValue"
                placeholder="请输入下限值"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="标准值" prop="standValue">
              <el-input
                v-model="queryParams.standValue"
                placeholder="请输入标准值"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
        </template>
        <template #body>
          <el-col :span="6">
            <el-form-item label="上限值" prop="maxValue">
              <el-input
                v-model="queryParams.maxValue"
                placeholder="请输入上限值"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="修饰符" prop="standardPre">
              <el-input
                v-model="queryParams.standardPre"
                placeholder="请输入修饰符"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="工具" prop="tool">
              <el-input
                v-model="queryParams.tool"
                placeholder="请输入工具"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="检查数量" prop="checkQuantity">
              <el-input
                v-model="queryParams.checkQuantity"
                placeholder="请输入检查数量"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
        </template>
        <template #buttons>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </template>
      </SearchBar>
    </el-form>

    <!-- 操作工具栏 -->

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" border>
      <!-- <el-table-column label="检验方案" align="center" prop="wmsMaterialItemMasterId" />
      <el-table-column label="检验项" align="center" prop="wmsInspectionItemId" /> -->
      <el-table-column
        label="物料编号"
        align="center"
        prop="code"
        width="150"
        show-overflow-tooltip
      />
      <el-table-column label="下限值" align="center" prop="minValue" />
      <el-table-column label="标准值" align="center" prop="standValue" />
      <el-table-column label="上限值" align="center" prop="maxValue" />
      <el-table-column label="修饰符" align="center" prop="standardPre" />
      <el-table-column label="工具" align="center" prop="tool">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.WMS_INSPECTION_TOOLS" :value="scope.row.tool" />
        </template>
      </el-table-column>
      <el-table-column label="检查数量" align="center" prop="checkQuantity" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['wms:material-item-detail:update']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            v-hasPermi="['wms:material-item-detail:delete']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </el-dialog>
</template>

<script>
import { getMaterialItemDetailPage, getMaterialItemDetailLogPage } from '@/api/wms/quality/inspectStandardApproval'

export default {
  name: 'MaterialItemDetail',
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料检验方案明细列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      visible: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        wmsMaterialItemMasterId: null,
        wmsInspectionItemId: null,
        code: null,
        minValue: null,
        standValue: null,
        maxValue: null,
        standardPre: null,
        tool: null,
        checkQuantity: null,
        createTime: [],
        wmsMaterialAdditionalIdNew: null,
        wmsMaterialAdditionalId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        code: [{ required: true, message: '物料编号不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      console.log(this.queryParams.wmsMaterialAdditionalIdNew, this.queryParams.wmsMaterialAdditionalId)
      if (this.queryParams.wmsMaterialAdditionalIdNew !== null) {
        getMaterialItemDetailPage(this.queryParams).then(response => {
          this.list = response.data.list
          this.total = response.data.total
        }).finally(() => {
          this.loading = false
        })
      } else if (this.queryParams.wmsMaterialAdditionalId !== null) {
        getMaterialItemDetailLogPage(this.queryParams).then(response => {
          this.list = response.data.list
          this.total = response.data.total
        }).finally(() => {
          this.loading = false
        })
      }
    },
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        wmsMaterialAdditionalId: undefined,
        wmsMaterialItemMasterId: undefined,
        wmsInspectionItemId: undefined,
        code: undefined,
        minValue: undefined,
        standValue: undefined,
        maxValue: undefined,
        standardPre: undefined,
        tool: undefined,
        checkQuantity: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    dialogOpen() {
      this.getList()
    }
  }
}
</script>
