<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"  v-show="showSearch" label-width="68px">
      <el-row :gutter="40">
        <el-col :span="6">
          <el-form-item label="原仓库" prop="fromCangku">
            <el-select v-model="queryParams.fromCangku" placeholder="请选择仓库" clearable >
                <el-option v-for="dict in warehouseList" :key="dict.id" :label="dict.warehouseName" :value="dict.warehouseCode" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="目标仓库" prop="toCangku">
            <el-select v-model="queryParams.toCangku" placeholder="请选择仓库" clearable >
                <el-option v-for="dict in warehouseList" :key="dict.id" :label="dict.warehouseName" :value="dict.warehouseCode" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="项目号" prop="xmNo">
            <el-input
              v-model="queryParams.xmNo"
              placeholder="请输入项目号"
              clearable
              @keyup.enter="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item>
            <el-button type="primary" icon="Search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="recordList" border show-overflow-tooltip>
      <el-table-column label="物料描述" align="center" prop="wlMs" />
      <el-table-column label="供应商" align="center" prop="gysMc" />
      <el-table-column label="项目编号" align="center" prop="xmNo" />
      <el-table-column label="项目描述" align="center" prop="xmMs" />
      
      <el-table-column label="原仓库" align="center" prop="fromCangkuName" />
      <el-table-column label="原库位码" align="center" prop="fromPcode" />
      <el-table-column label="原托盘码" align="center" prop="fromTrayCode" />
      <el-table-column label="目标仓库" align="center" prop="toCangkuName" />
      <el-table-column label="目标库位码" align="center" prop="toPcode" />
      <el-table-column label="目标托盘码" align="center" prop="toTrayCode" />
      <el-table-column label="身份码" align="center" prop="entityId" />
      <el-table-column label="移库人" align="center" prop="movedByName" />
      <el-table-column label="移库原因" align="center" prop="moveReason" />

    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改移库记录对话框 -->
     <!-- :visible.sync="open" -->
    <el-dialog :title="title"  width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="关联的库存单据ID" prop="rkId">
          <el-input v-model="form.rkId" placeholder="请输入关联的库存单据ID" />
        </el-form-item>
        <el-form-item label="实物ID" prop="entityId">
          <el-input v-model="form.entityId" placeholder="请输入实物ID" />
        </el-form-item>
        <el-form-item label="原仓库" prop="fromCangku">
          <el-input v-model="form.fromCangku" placeholder="请输入原仓库" />
        </el-form-item>
        <el-form-item label="原库位码" prop="fromPcode">
          <el-input v-model="form.fromPcode" placeholder="请输入原库位码" />
        </el-form-item>
        <el-form-item label="原托盘码" prop="fromTrayCode">
          <el-input v-model="form.fromTrayCode" placeholder="请输入原托盘码" />
        </el-form-item>
        <el-form-item label="目标仓库" prop="toCangku">
          <el-input v-model="form.toCangku" placeholder="请输入目标仓库" />
        </el-form-item>
        <el-form-item label="目标库位码" prop="toPcode">
          <el-input v-model="form.toPcode" placeholder="请输入目标库位码" />
        </el-form-item>
        <el-form-item label="目标托盘码" prop="toTrayCode">
          <el-input v-model="form.toTrayCode" placeholder="请输入目标托盘码" />
        </el-form-item>
        <el-form-item label="移库原因" prop="moveReason">
          <el-input v-model="form.moveReason" placeholder="请输入移库原因" />
        </el-form-item>
        <el-form-item label="操作人" prop="movedBy">
          <el-input v-model="form.movedBy" placeholder="请输入操作人" />
        </el-form-item>
        <el-form-item label="操作时间" prop="movedAt">
          <el-input v-model="form.movedAt" placeholder="请输入操作时间" />
        </el-form-item>
        <el-form-item label="逻辑删除标志" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入逻辑删除标志" />
        </el-form-item>
      </el-form>
      <!-- slot="footer" -->
      <div  class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecord } from "@/api/wisdom/move";
import {warehouseDict} from "@/api/information/warehouseinfo";    //所属仓库

export default {
  name: "move",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 移库记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fromCangku: null,
        toCangku: null,
        xmNo:null
      },
      warehouseList:[],   //所属仓库下拉数据
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rkId: [
          { required: true, message: "关联的库存单据ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.warehouseFun()
  },
  methods: {
    //所属仓库
    warehouseFun(){
      //所属仓库下拉数据
      warehouseDict().then(response=>{
        this.warehouseList = response.data
      })
    },
    /** 查询移库记录列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        rkId: null,
        entityId: null,
        fromCangku: null,
        fromPcode: null,
        fromTrayCode: null,
        toCangku: null,
        toPcode: null,
        toTrayCode: null,
        moveReason: null,
        movedBy: null,
        movedAt: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDelete: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    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
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加移库记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改移库记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除移库记录编号为"' + ids + '"的数据项？').then(function() {
        return delRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // this.download('system/record/export', {
      //   ...this.queryParams
      // }, `record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
