<template>
  <el-dialog
    v-dialogDrag
    title="查看投料明细"
    :visible.sync="open"
    width="1200px"
    append-to-body
    @open="dialogOpen"
  >

    <!-- 搜索工作栏 -->
    <!-- <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="98px"
    >
      <SearchBar :show-span="6" :collapse-span="6">
        <template #header>
          <el-col :span="6">
            <el-form-item label="用料清单编号" prop="workOrderBomNo">
              <el-input
                v-model="queryParams.workOrderBomNo"
                placeholder="请输入用料清单编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="物料编号" prop="materialNo">
              <el-input
                v-model="queryParams.materialNo"
                placeholder="请输入物料编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="物料名称" prop="materialName">
              <el-input
                v-model="queryParams.materialName"
                placeholder="请输入物料名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
        </template>
        <template #body>
          <el-col :span="6">
            <el-form-item label="物料数量" prop="materialAmount">
              <el-input
                v-model="queryParams.materialAmount"
                placeholder="请输入物料数量"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="物料规格型号" prop="materialModels">
              <el-input
                v-model="queryParams.materialModels"
                placeholder="请输入物料规格型号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="物料单位名称" prop="unitName">
              <el-input
                v-model="queryParams.unitName"
                placeholder="请输入物料基本单位名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="需求数量" prop="needAmount">
              <el-input
                v-model="queryParams.needAmount"
                placeholder="请输入需求数量"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="应发数量" prop="mustAmount">
              <el-input
                v-model="queryParams.mustAmount"
                placeholder="请输入应发数量"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="已领数量" prop="pickedAmount">
              <el-input
                v-model="queryParams.pickedAmount"
                placeholder="请输入已领数量"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="补领数量" prop="repickedAmount">
              <el-input
                v-model="queryParams.repickedAmount"
                placeholder="请输入补领数量"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报废数量" prop="scrapAmount">
              <el-input
                v-model="queryParams.scrapAmount"
                placeholder="请输入报废数量"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="仓库编号" prop="stockCode">
              <el-input
                v-model="queryParams.stockCode"
                placeholder="请输入仓库编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否超发" prop="allowOver">
              <el-input
                v-model="queryParams.allowOver"
                placeholder="请输入是否超发"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="领料状态" prop="status">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择领料状态:1-已下达,2-领料中,3-领料完成"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in getDictDatas(DICT_TYPE.MES_RECEIVE_MATERIALS_STATUS)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="创建时间" prop="createTime">
              <el-date-picker
                v-model="queryParams.createTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </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
      size="mini"
    >
      <el-table-column
        label="用料清单编号"
        align="center"
        prop="workOrderBomNo"
        width="120"
      />
      <el-table-column
        label="物料编号"
        align="center"
        prop="materialNo"
        width="150"
      />
      <el-table-column
        label="物料名称"
        align="center"
        prop="materialName"
        width="150"
        show-overflow-tooltip
      />
      <el-table-column label="物料数量" align="center" prop="materialQty" />
      <el-table-column
        label="物料规格型号"
        align="center"
        prop="materialModels"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="物料单位名称"
        align="center"
        prop="unitName"
        width="120"
      />
      <el-table-column label="需求数量" align="center" prop="needQty" />
      <el-table-column label="应发数量" align="center" prop="mustQty" />
      <el-table-column label="已领数量" align="center" prop="pickedQty" />
      <el-table-column label="补领数量" align="center" prop="repickedQty" />
      <el-table-column label="报废数量" align="center" prop="scrapQty" />
      <el-table-column label="仓库编号" align="center" prop="stockCode" />
      <el-table-column label="是否超发" align="center" prop="allowOver" />
      <el-table-column label="备注" align="center" prop="erpMark" />
      <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>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
import { getWorkOrderBomDetailPage, exportWorkOrderBomDetailExcel } from '@/api/wms/orders/productMaterials'

export default {
  name: 'WorkOrderBomDetail',
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用料清单明细列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        workId: null,
        workOrderBomId: null,
        workOrderBomNo: null,
        detailErpId: null,
        detailNumber: null,
        materialNo: null,
        materialName: null,
        materialAmount: null,
        materialModels: null,
        unitName: null,
        needAmount: null,
        mustAmount: null,
        pickedAmount: null,
        repickedAmount: null,
        scrapAmount: null,
        stockCode: null,
        allowOver: null,
        remark: null,
        status: null,
        createTime: [],
        erpMark: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      getWorkOrderBomDetailPage(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,
        workId: undefined,
        workOrderBomId: undefined,
        workOrderBomNo: undefined,
        detailErpId: undefined,
        detailNumber: undefined,
        materialNo: undefined,
        materialName: undefined,
        materialAmount: undefined,
        materialModels: undefined,
        unitName: undefined,
        needAmount: undefined,
        mustAmount: undefined,
        pickedAmount: undefined,
        repickedAmount: undefined,
        scrapAmount: undefined,
        stockCode: undefined,
        allowOver: undefined,
        remark: undefined,
        status: undefined,
        erpMark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加用料清单明细'
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      const params = { ...this.queryParams }
      params.pageNo = undefined
      params.pageSize = undefined
      this.$modal.confirm('是否确认导出所有用料清单明细数据项?').then(() => {
        this.exportLoading = true
        return exportWorkOrderBomDetailExcel(params)
      }).then(response => {
        this.$download.excel(response, '用料清单明细.xls')
        this.exportLoading = false
      }).catch(() => {})
    },
    dialogOpen() {
      this.getList()
    }
  }
}
</script>

