<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="订单号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产订单号" prop="productionOrderNumber">
        <el-input
          v-model="queryParams.productionOrderNumber"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="materialCode">
        <el-input
          v-model="queryParams.materialCode"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="扣料时间" prop="createTimeString">
        <el-date-picker
          v-model="queryParams.createTimeString"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </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-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['materialRetentionLog:log:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"

        >导出</el-button>
        <!--          v-hasPermi="['materialRetentionLog:log:export']"-->
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading"  style="margin-top: 20px" :data="logList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="订单号" align="center" prop="orderNumber" />
      <el-table-column label="生产订单号" align="center" prop="productionOrderNumber" />
      <el-table-column label="产品编码" align="center" prop="productCode" />
      <el-table-column label="物料编码" align="center" prop="materialCode" />
      <el-table-column label="物料名称" align="center" prop="materialName" />
      <el-table-column label="规格" align="center" prop="specification" />
      <el-table-column label="子项类型" align="center" prop="materialType" >
          <template  v-slot="scope">
            <dict-tag  :options="dict.type.wlmxzxlx" :value="scope.row.materialType"/>
          </template>
      </el-table-column>
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="实发数量" align="center" prop="actualQuantityIssued" />
      <el-table-column label="发货仓库" align="center" prop="deliveryWarehouse" />
      <el-table-column label="工序" align="center" prop="process" />
      <el-table-column label="扣料时间" align="center" prop="createTime" width="150" />
<!--      <el-table-column label="单据备注" align="center" prop="documentRemarks" />-->
<!--      <el-table-column label="明细备注" align="center" prop="detailedRemarks" />-->
<!--      <el-table-column label="单据类型" align="center" prop="documentType" />-->
<!--      <el-table-column label="库存组织" align="center" prop="inventoryOrganization" />-->
<!--      <el-table-column label="库存组织" align="center" prop="receivingTissue" />-->
<!--      <el-table-column label="库存方向" align="center" prop="inventoryDirection" />-->
<!--      <el-table-column label="出库日期" align="center" prop="dateOfDelivery" />-->
<!--      <el-table-column label="领料部门" align="center" prop="materialsRequisitionDepartment" />-->
<!--      <el-table-column label="领料人" align="center" prop="materialTaker" />-->
<!--      <el-table-column label="业务类型" align="center" prop="businessType" />-->
<!--      <el-table-column label="货主类型" align="center" prop="ownerType" />-->
<!--      <el-table-column label="货主" align="center" prop="owner" />-->
<!--      <el-table-column label="单据状态" align="center" prop="documentStatus" />-->

<!--      <el-table-column label="创建者id " align="center" prop="createById" />-->
<!--      <el-table-column label="更新者id" align="center" prop="updateById" />-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-dropdown @command="(command)=>{handleCommand(command, scope.row)}">-->
<!--            <el-button type="warning">-->
<!--              操作<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
<!--            </el-button>-->
<!--            <el-dropdown-menu slot="dropdown">-->
<!--              <el-dropdown-item  icon="el-icon-edit"  command="handleUpdate">修改</el-dropdown-item>-->
<!--              <el-dropdown-item  icon="el-icon-delete" command="handleDelete">删除</el-dropdown-item>-->
<!--            </el-dropdown-menu>-->
<!--          </el-dropdown>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      :page-sizes="[50]"
    />

    <!-- 添加或修改扫码扣料日志对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="物料编码" prop="materialCode">
          <el-input v-model="form.materialCode" placeholder="请输入物料编码" />
        </el-form-item>
        <el-form-item label="物料名称" prop="materialName">
          <el-input v-model="form.materialName" placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="规格" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="型号" prop="model">
          <el-input v-model="form.model" placeholder="请输入型号" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="实发数量" prop="actualQuantityIssued">
          <el-input v-model="form.actualQuantityIssued" placeholder="请输入实发数量" />
        </el-form-item>
        <el-form-item label="发货仓库" prop="deliveryWarehouse">
          <el-input v-model="form.deliveryWarehouse" placeholder="请输入发货仓库" />
        </el-form-item>
        <el-form-item label="仓库仓库编码" prop="ckNumber">
          <el-input v-model="form.ckNumber" placeholder="请输入仓库仓库编码" />
        </el-form-item>
        <el-form-item label="单据备注" prop="documentRemarks">
          <el-input v-model="form.documentRemarks" placeholder="请输入单据备注" />
        </el-form-item>
        <el-form-item label="库存组织" prop="inventoryOrganization">
          <el-input v-model="form.inventoryOrganization" placeholder="请输入库存组织" />
        </el-form-item>
        <el-form-item label="库存组织" prop="receivingTissue">
          <el-input v-model="form.receivingTissue" placeholder="请输入库存组织" />
        </el-form-item>
        <el-form-item label="库存方向" prop="inventoryDirection">
          <el-input v-model="form.inventoryDirection" placeholder="请输入库存方向" />
        </el-form-item>
        <el-form-item label="出库日期" prop="dateOfDelivery">
          <el-input v-model="form.dateOfDelivery" placeholder="请输入出库日期" />
        </el-form-item>
        <el-form-item label="领料部门" prop="materialsRequisitionDepartment">
          <el-input v-model="form.materialsRequisitionDepartment" placeholder="请输入领料部门" />
        </el-form-item>
        <el-form-item label="领料人" prop="materialTaker">
          <el-input v-model="form.materialTaker" placeholder="请输入领料人" />
        </el-form-item>
        <el-form-item label="货主" prop="owner">
          <el-input v-model="form.owner" placeholder="请输入货主" />
        </el-form-item>
        <el-form-item label="明细备注" prop="detailedRemarks">
          <el-input v-model="form.detailedRemarks" placeholder="请输入明细备注" />
        </el-form-item>
        <el-form-item label="创建者id " prop="createById">
          <el-input v-model="form.createById" placeholder="请输入创建者id " />
        </el-form-item>
        <el-form-item label="更新者id" prop="updateById">
          <el-input v-model="form.updateById" placeholder="请输入更新者id" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLog, getLog, delLog, addLog, updateLog } from "@/api/amichi/materialRetentionLog/log";

export default {
  name: "Log",
  dicts: ["wlmxzxlx"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 扫码扣料日志表格数据
      logList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        createTimeString:null,
        pageNum: 1,
        pageSize: 50,
        materialCode: null,
        materialName: null,
        specification: null,
        model: null,
        unit: null,
        actualQuantityIssued: null,
        deliveryWarehouse: null,
        ckNumber: null,
        documentRemarks: null,
        documentType: null,
        inventoryOrganization: null,
        receivingTissue: null,
        inventoryDirection: null,
        dateOfDelivery: null,
        materialsRequisitionDepartment: null,
        materialTaker: null,
        businessType: null,
        ownerType: null,
        owner: null,
        documentStatus: null,
        detailedRemarks: null,
        createById: null,
        updateById: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        materialCode: [
          { required: true, message: "物料编码不能为空", trigger: "blur" }
        ],
        materialName: [
          { required: true, message: "物料名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询扫码扣料日志列表 */
    getList() {
      this.loading = true;
      listLog(this.queryParams).then(response => {
        this.logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //下拉菜单点击事件
    handleCommand(command, row) {
      switch (command) {
        case "handleUpdate":
          this.handleUpdate(row)
          break;
        case "handleDelete":
          this.handleDelete(row)
          break;
        default:
          break;
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        materialCode: null,
        materialName: null,
        specification: null,
        model: null,
        unit: null,
        actualQuantityIssued: null,
        deliveryWarehouse: null,
        ckNumber: null,
        documentRemarks: null,
        documentType: null,
        inventoryOrganization: null,
        receivingTissue: null,
        inventoryDirection: null,
        dateOfDelivery: null,
        materialsRequisitionDepartment: null,
        materialTaker: null,
        businessType: null,
        ownerType: null,
        owner: null,
        documentStatus: null,
        detailedRemarks: null,
        createById: null,
        createBy: null,
        createTime: null,
        updateById: null,
        updateBy: null,
        updateTime: null,
        delFlag: 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
      getLog(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) {
            updateLog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLog(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 delLog(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('materialRetentionLog/log/export', {
        ...this.queryParams,
        ids: this.ids
      }, `log_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
