<template>
  <div class="app-container" ref="appPanel">
    <div ref="toolPanel" class="toolPanel">
      <el-row :gutter="10">
        <el-col :span="1.5">
          <div class="toolTitle">出库任务</div>
        </el-col>
        <el-col :span="1.5">
          <el-button
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:pickingwavegoods:remove']"
            >删除</el-button
          >
        </el-col>

        <el-col :span="1.5">
          <el-button icon="el-icon-search" size="mini" @click="handleQuery"
            >搜索</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >刷新</el-button
          >
        </el-col>
        <right-toolbar ref="toolBarRef" @customCols="customColsHandler" :showSearch.sync="showSearch"
                       showColumnsType="transfer" :columns="columns"></right-toolbar>
      </el-row>
    </div>
    <div class="search-container" ref="searchPanel">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="mini"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-form-item label="任务号" prop="pickingId">
          <el-input
            v-model="queryParams.plcId"
            placeholder="请输入任务号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="来源单号" prop="pickingId">
          <el-input
            v-model="queryParams.pickingId"
            placeholder="请输入来源单号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="物料编号" prop="goodsId">
          <el-input
            v-model="queryParams.goodsId"
            placeholder="请输入物料编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="库位编号" prop="locId">
          <el-input
            v-model="queryParams.locId"
            placeholder="请输入库位编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="容器编号" prop="ctl">
          <el-input
            v-model="queryParams.ctl"
            placeholder="请输入容器编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="出库类型" prop="ckType">
          <el-select
            v-model="queryParams.ckType"
            placeholder="请选择出库类型"
            clearable
          >
            <el-option
              v-for="dict in dict.type.outbound_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="状态" prop="confirmStatus">
          <el-select
            v-model="queryParams.confirmStatus"
            placeholder="请选择状态"
            clearable
          >
            <el-option
              v-for="dict in dict.type.task_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
      </el-form>
    </div>

    <div class="table-container">
      <div ref="mainTablePanel" :style="{ height: mainTableDivHeight }">
        <el-table :key="rndKey" ref="providerTableRef" v-loading="loading" border size="mini" :height="mainTableHeight"
                  :data="pickingwavegoodsList" @selection-change="handleSelectionChange" @header-dragend="handleHeaderDragEnd">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column v-for="item in columns" :key="item.key" :label="item.label" align="center"
                           :prop="item.columnName" v-if="item.visible" :width="item.width">
            <template v-slot="scope">
              <dict-tag v-if="item.columnName === 'periodUnit'" v-slot="scope" :options="dict.type.shelf_life_unit" :value="scope.row[item.columnName]"/>
              <dict-tag v-else-if="item.columnName === 'goodsTypeId'" v-slot="scope" :options="dict.type.goods_type" :value="scope.row[item.columnName]"/>
              <dict-tag v-else-if="item.columnName === 'status'" v-slot="scope" :options="dict.type.common_status" :value="scope.row[item.columnName]"/>
              <dict-tag v-else-if="item.columnName === 'confirmStatus'" v-slot="scope" :options="dict.type.task_status" :value="scope.row[item.columnName]"/>
              <dict-tag v-else-if="item.columnName === 'ckType'" v-slot="scope" :options="dict.type.outbound_type" :value="scope.row[item.columnName]"/>
              <span v-else>{{ scope.row[item.columnName] }}</span>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagePanel">
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  addPickingwavegoods,
  changeStatus,
  delPickingwavegoods,
  disabled,
  enabled,
  getPickingwavegoods,
  listPickingwavegoods,
  updatePickingwavegoods,
} from "@/api/system/pickingwavegoods";
import TableMixin from "@/api/tableMixin";

export default {
  name: "Pickingwavegoods",
  mixins:[TableMixin],
  dicts: [
    "quality_inspect_status",
    "common_status",
    "outbound_type",
    "goods_type",
    "shelf_life_unit",
    "task_status",
  ],
  data() {
    return {
      rndKey:0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出库任务表格数据
      pickingwavegoodsList: [],
      // 弹出层标题
      title: "",
      mainTableHeight: "0px",
      mainTableDivHeight: "0px",
      businessCodeTrk: "pickingwavegoods",
      rightToolbarShow: false,
      tableNo: 0,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        pickingId: null,
        putinId: null,
        doctNumber: null,
        goodsId: null,
        locId: null,
        goodsNum: null,
        specification: null,
        productionDate: null,
        wareDate: null,
        providerId: null,
        unit: null,
        outId: null,
        scaleUnit: null,
        mistockNum: null,
        pickingNum: null,
        price: null,
        storageAreaId: null,
        storageId: null,
        ctl: null,
        ckType: null,
        status: null,
        outstand: null,
        goodsName: null,
        plcId: null,
        barcode: null,
        produclotId: null,
        toLoc: null,
        operatorId: null,
        shelvesNum: null,
        locationId: null,
        recNum: null,
        productId: null,
        callShelvesNum: null,
        salesOrderNo: null,
        salesOrderNumber: null,
        supplier: null,
        decId: null,
        recoil: null,
        operateDate: null,
        batchNo: null,
        customerId: null,
        reportTime: null,
        purchaseId: null,
        applicant: null,
        respDept: null,
        planDate: null,
        planTime: null,
        needCycle: null,
        needType: null,
        goodsTypeId: null,
        brand: null,
        totalMoney: null,
        expiryDate: null,
        providerName: null,
        receiver: null,
        needDept: null,
        purchaseDept: null,
        receiverDept: null,
        receivingArea: null,
        packageId: null,
        useType: null,
        telephone: null,
        totalVolume: null,
        totalRoughWeight: null,
        totalNetWeigh: null,
        defaultStorageAreaId: null,
        qualityInspecStatus: null,
        periodUnit: null,
        period: null,
        wgh: null,
        high: null,
        confirmStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      columns: [],
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    this.computedTableHeight();
  },
  watch: {
    showSearch: function () {
      this.computedTableHeight();
    },
  },
  methods: {
    /** 查询用户展示字段定义管理列表 */
    computedTableHeight() {
      this.$nextTick(() => {
        var totalHeight = this.$refs.appPanel.clientHeight;
        var toolHeight = this.$refs.toolPanel.clientHeight;
        var searchHeight = this.$refs.searchPanel.clientHeight;

        var tablePanelHeight = totalHeight - toolHeight - searchHeight - 14 - 5;

        this.mainTableDivHeight = tablePanelHeight + "px";
        this.mainTableHeight = tablePanelHeight - 25 + "px";
      });
    },
    /** 查询出库任务列表 */
    getList() {
      this.loading = true;
      listPickingwavegoods(this.queryParams).then((response) => {
        this.pickingwavegoodsList = response.rows;
        this.total = response.total;
        if (this.columns.length == 0) this.columns = response.columns;
        this.loading = false;
        this.getHideColumn();
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        pickingId: null,
        putinId: null,
        doctNumber: null,
        goodsId: null,
        locId: null,
        goodsNum: null,
        specification: null,
        productionDate: null,
        wareDate: null,
        providerId: null,
        unit: null,
        remark: null,
        outId: null,
        scaleUnit: null,
        mistockNum: null,
        pickingNum: null,
        price: null,
        storageAreaId: null,
        storageId: null,
        ctl: null,
        ckType: null,
        status: null,
        outstand: null,
        goodsName: null,
        plcId: null,
        barcode: null,
        produclotId: null,
        toLoc: null,
        operatorId: null,
        shelvesNum: null,
        locationId: null,
        recNum: null,
        productId: null,
        callShelvesNum: null,
        salesOrderNo: null,
        salesOrderNumber: null,
        supplier: null,
        decId: null,
        updateTime: null,
        recoil: null,
        operateDate: null,
        batchNo: null,
        customerId: null,
        createTime: null,
        createBy: null,
        updateBy: null,
        reportTime: null,
        purchaseId: null,
        applicant: null,
        respDept: null,
        planDate: null,
        planTime: null,
        needCycle: null,
        needType: null,
        goodsTypeId: null,
        brand: null,
        totalMoney: null,
        expiryDate: null,
        providerName: null,
        receiver: null,
        needDept: null,
        purchaseDept: null,
        receiverDept: null,
        receivingArea: null,
        packageId: null,
        useType: null,
        telephone: null,
        totalVolume: null,
        totalRoughWeight: null,
        totalNetWeigh: null,
        defaultStorageAreaId: null,
        qualityInspecStatus: null,
        periodUnit: null,
        period: null,
        wgh: null,
        high: null,
        confirmStatus: 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;
      getPickingwavegoods(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) {
            updatePickingwavegoods(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPickingwavegoods(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 delPickingwavegoods(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },

    /** 用户状态修改 */
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal
        .confirm('确认要"' + text + '"id为"' + row.id + '"数据项？')
        .then(function () {
          return changeStatus(row.id, row.status);
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    /** 启用按钮操作 */
    handleEnable(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认启用出库任务编号为"' + ids + '"的数据项？')
        .then(function () {
          return enabled(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("启用成功");
        })
        .catch(() => {});
    },
    /** 禁用按钮操作 */
    handleDisabled(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认禁用出库任务编号为"' + ids + '"的数据项？')
        .then(function () {
          return disabled(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("禁用成功");
        })
        .catch(() => {});
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/pickingwavegoods/export",
        {
          ...this.queryParams,
        },
        `pickingwavegoods_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style scoped>
.app-container {
  height: calc(100vh - 84px);
}
</style>
