<template>
    <div>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="工单号" prop="workorderCode">
        <el-input
          v-model="queryParams.workorderCode"
          placeholder="请输入工单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售订单" prop="salesVoucher">
        <el-input
          v-model="queryParams.salesVoucher"
          placeholder="请输入销售订单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售订单项次" prop="salesVoucherItem">
        <el-input
          v-model="queryParams.salesVoucherItem"
          placeholder="请输入销售订单项次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="唯一码起始" prop="startSerial">
        <el-input
          v-model="queryParams.startSerial"
          placeholder="请输入唯一码起始"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="唯一码结束" prop="endSerial">
        <el-input
          v-model="queryParams.endSerial"
          placeholder="请输入唯一码结束"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="状态" prop="serialStatus">
        <el-select v-model="queryParams.serialStatus" placeholder="请选择状态" clearable>
            <el-option
            v-for="dict in option"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工单状态" prop="workorderStatus">
        <el-select v-model="queryParams.workorderStatus" placeholder="请选择工单状态" clearable>
            <el-option
            v-for="dict in dict.type.mes_workorder_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
            ></el-option>
        </el-select>
        </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-button size="mini" @click="markDelete" :disabled="multiple">删除</el-button>
        <el-button size="mini" @click="unMarkDelete" :disabled="multiple">取消删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="itemList"
      height="40vh"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="工单号" align="center" prop="workorderCode">
      </el-table-column>
      <el-table-column label="销售订单" align="center" prop="salesVoucher"/>
      <el-table-column label="销售订单项次" align="center" prop="salesVoucherItem"/>
      <el-table-column label="物料名称" align="center" prop="itemName"/>
      <el-table-column label="唯一码起始" align="center" prop="startSerial"/>
      <el-table-column label="唯一码结束" align="center" prop="endSerial"/>
      <el-table-column label="状态" align="center" prop="serialStatus">
        <template slot-scope="scope">
            {{ scope.row.serialStatus ? option.find(v => v.value === scope.row.serialStatus).label : '未使用'}}
        </template>
      </el-table-column>
      <el-table-column label="工单状态" align="center" prop="workorderStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_workorder_status" :value="scope.row.workorderStatus" />
        </template>
      </el-table-column>

    </el-table>

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

<script>
import {
    getLPNrecordList,
    markDelete,
    unMarkDelete
} from "@/api/mes/pro/dta";

export default {
  name: "orderList",
  components: { },
  dicts: [
    "mes_workorder_status"
  ],
  data() {
    return {
      showFlag: false,
      // 选中数组
      ids: [],
      selectedRows: [],
      option: [
        { label: '未使用', value: 0 },
        { label: '使用中', value: 1 },
        { label: '已完成', value: 2 },
        { label: '已删除', value: 3 }
      ],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料产品表格数据
      itemList: null,
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workorderCode: null,
        salesVoucher: null,
        salesVoucherItem: null,
        sapItemCode: null,
        itemName: null,
        serialStatus: null,
        startSerial: null,
        endSerial: null,
        workorderStatus: null
      },
    };
  },
  created() {

  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询物料编码列表 */
    getList() {
      this.loading = true;
      getLPNrecordList(this.queryParams).then((response) => {
        this.itemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    markDelete() {
        this.$modal.confirm('是否确认删除这条LPN？').then(() => {
        return markDelete(this.ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    unMarkDelete() {
        this.$modal.confirm('是否确认取消删除这条LPN？').then(() => {
        return unMarkDelete(this.ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("取消删除成功");
      }).catch(() => {});
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
     // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.selectedRows = selection;
    },
  },
};
</script>
