<template>
  <div class="app-container">
    <el-alert title="以下操作关联的钢卷已是历史钢卷，可手动标记完成" type="warning" show-icon :closable="false" class="mb8" />
    <KLPTable v-loading="loading" :data="list">
      <el-table-column label="当前钢卷号" align="center" prop="currentCoilNo"/>
      <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo" width="180" />
      <el-table-column label="操作类型" align="center" prop="actionType" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_coil_action_type" :value="scope.row.actionType" />
        </template>
      </el-table-column>
      <el-table-column label="操作状态" align="center" prop="actionStatus" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_action_status" :value="scope.row.actionStatus" />
        </template>
      </el-table-column>
      <el-table-column label="逻辑库区" align="center" prop="warehouseName" width="150" />
      <el-table-column label="实际库区" align="center" prop="actualWarehouseName" width="150" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="160" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-check"
            @click="handleComplete(scope.row)">完成</el-button>
          <el-button size="mini" type="danger" icon="el-icon-close"
            @click="handleCancel(scope.row)">取消</el-button>
        </template>
      </el-table-column>
    </KLPTable>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { listStalePendingAction, completeAction, cancelAction } from "@/api/wms/pendingAction";

export default {
  name: "StaleAction",
  dicts: ['wms_coil_action_type', 'wms_action_status'],
  data() {
    return {
      loading: true,
      total: 0,
      list: [],
      queryParams: {
        pageNum: 1,
        pageSize: 20,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      listStalePendingAction(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleComplete(row) {
      this.$modal.confirm('确认完成操作ID为"' + row.actionId + '"的记录？').then(() => {
        return completeAction(row.actionId, '-');
      }).then(() => {
        this.$modal.msgSuccess("操作已完成");
        this.getList();
      });
    },
    handleCancel(row) {
      this.$modal.confirm('确认取消操作ID为"' + row.actionId + '"的记录？').then(() => {
        return cancelAction(row.actionId);
      }).then(() => {
        this.$modal.msgSuccess("操作已取消");
        this.getList();
      });
    },
  },
};
</script>
