<template>
  <!--  -->
  <div class="app-container">
    <el-form
      :model="queryParams"
      size="mini"
      ref="queryParams"
      :inline="true"
      v-show="showSearch"
      label-width="70px">
      <el-form-item
        :class="['treeselectForm', { borderRed: !validTree }]"
        label="组织架构"
        prop="orgIds">
        <!--        <tree @treeselectFn="treeselectFn" :treeval="queryParams.orgIds" :ismultiple="true"></tree>-->
        <treeselect
          class="treePopup"
          v-model="queryParams.orgIds"
          :multiple="false"
          value-consists-of="LEAF_PRIORITY"
          :options="menuOptions"
          :normalizer="normalizer1"
          placeholder="选择组织架构"
          noOptionsText="暂无数据"
          :show-count="true" />
        <!--        @select="treeselectFnSingle"-->
      </el-form-item>

      <el-form-item label="物料类型" prop="materialTypeName">
        <el-select
          v-model="queryParams.materialTypeName"
          size="mini"
          clearable
          filterable
          @change="materialTypeChangeQuery">
          <el-option
            v-for="item in materialTypeOption"
            :key="item.signType"
            :label="item.signType"
            :value="item.signType" />
        </el-select>
      </el-form-item>
      <el-form-item label="物料名称" prop="materialDataName">
        <el-select
          v-model="queryParams.materialDataName"
          size="mini"
          clearable
          filterable
          @change="onInput()">
          <el-option
            v-for="item in materialNameOptionQuery"
            :key="item.signName"
            :label="item.signName"
            :value="item.signName" />
        </el-select>
      </el-form-item>
      <el-form-item label="时间" prop="signTime" @change="onInput()">
        <div class="block">
          <el-date-picker
            v-model="signTime"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </div>
      </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="listRresetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['sfa:materialInventory:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sfa:materialInventory:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sfa:materialInventory:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          >导出</el-button
        >
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="materialInventoryList">
      <el-table-column
        label="公司"
        prop="inventory_gs_dept_name"
        width="140"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="仓库类型"
        prop="warehouse_type"
        width="140"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="物料类型"
        prop="material_type_name"
        width="140"
        :show-overflow-tooltip="true" />
      <el-table-column label="物料名称" prop="material_data_name" :show-overflow-tooltip="true" />
      <el-table-column label="物料编码" prop="material_data_code" width="130" />
      <el-table-column
        label="直发销售部数量"
        align="center"
        prop="xsbnum"
        width="120"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="实时库存"
        align="center"
        prop="inventory_num"
        width="120"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="剩余库存 "
        align="center"
        prop="xsbsyNum"
        width="120"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="实际领用"
        align="center"
        prop="xsysjlyNum"
        width="120"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="已领用"
        align="center"
        prop="xsylyNum"
        width="120"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="退回"
        align="center"
        prop="xsythNum"
        width="120"
        :show-overflow-tooltip="true" />
      <el-table-column
        label="已发放数量"
        align="center"
        prop="xsyffNum"
        width="120"
        :show-overflow-tooltip="true" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
      <el-form
        :model="queryParamsRw"
        size="mini"
        ref="queryParamsRw"
        :inline="true"
        v-show="showSearch"
        label-width="120px">
        <el-form-item label="操作人库位" prop="changeWarehouseName">
          <el-input
            v-model="queryParamsRw.changeWarehouseName"
            placeholder="请输入操作人库位"
            clearable
            size="small"
            @keyup.enter.native="handleQueryRw" />
        </el-form-item>
        <el-form-item label="变更类型" prop="changeType">
          <el-select
            v-model="queryParamsRw.changeType"
            placeholder="变更类型"
            clearable
            style="width: 240px">
            <el-option
              v-for="dict in dict.type.material_change_log_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryRw"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="listRresetQueryRw">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loadingRW" :data="materialInventoryLogList">
        <el-table-column label="操作人库位名称" align="center" prop="changeWarehouseName" />
        <el-table-column label="操作人库位代码" align="center" prop="changeWarehouseCode" />
        <!--        <el-table-column label="操作人库位层次" align="center" prop="inventoryLeavel">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.material_level_type" :value="scope.row.inventoryLeavel"/>
                  </template>
                </el-table-column>-->
        <el-table-column label="库存变更量" align="center" prop="inventoryNum" />
        <el-table-column label="变更类型" align="center" prop="changeType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.material_change_log_type" :value="scope.row.changeType" />
          </template>
        </el-table-column>
        <el-table-column label="变更时间" align="center" prop="createTime" />
        <!--        <el-table-column label="公司" align="center" prop="inventoryGsDeptName" />
                <el-table-column label="大区" align="center" prop="inventoryDqDeptName" />
                <el-table-column label="销售部" align="center" prop="inventoryMdDeptName" />-->
      </el-table>
      <pagination
        v-show="totalRw > 0"
        :total="totalRw"
        :page.sync="queryParamsRw.pageNum"
        :limit.sync="queryParamsRw.pageSize"
        @pagination="getMaterialInventoryLogData" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 盘点/调拨 -->
    <el-dialog :title="title" :visible.sync="openAllot" width="60%" append-to-body>
      <el-form
        ref="formAllot"
        :model="formAllot"
        size="mini"
        :rules="rulesAllot"
        label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="目标库位" prop="warehouseName">
              <el-input v-model="formAllot.warehouseName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料类型名称" prop="materialTypeName">
              <el-input v-model="formAllot.materialTypeName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料名称" prop="materialDataName">
              <el-input v-model="formAllot.materialDataName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="变更类型" prop="changeType">
              <el-select
                disabled
                v-model="formAllot.changeType"
                clearable
                placeholder="请选择变更类型"
                style="width: 100%"
                @change="onInput">
                <el-option
                  v-for="item in changeTypeOptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="盘点数量"
              prop="inventoryNumArray"
              v-if="formAllot.changeType != 3">
              <el-input-number
                v-model="formAllot.inventoryNum"
                controls-position="right"
                :min="1"
                @input="onInput" />
            </el-form-item>
            <el-form-item
              label="调拨数量"
              prop="inventoryNumArray"
              v-if="formAllot.changeType == 3">
              <el-input v-model="formAllot.inventoryNum" type="number" @input="onInput" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formAllot.changeType == 3">
            <el-form-item label="调拨库" prop="followInventoryNames">
              <div @click="followOpen">
                <el-input
                  v-model="formAllot.followInventoryNames"
                  placeholder="请输入调拨库"
                  @input="onInput" />
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormAllot">确 定</el-button>
        <el-button @click="cancelAllot">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="openAbet" width="90%" append-to-body>
      <el-form
        :model="queryParamsAbet"
        size="mini"
        ref="queryParamsAbet"
        :inline="true"
        v-show="showSearch"
        label-width="120px">
        <el-form-item label="库位名称" prop="warehouseName">
          <el-input
            v-model="queryParamsAbet.warehouseName"
            placeholder="请输入库位名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item
          :class="['treeselectForm', { borderRed: !validTree }]"
          label="组织架构"
          prop="orgIds">
          <tree
            @treeselectFn="treeselectFnAbet"
            :treeval="queryParamsAbet.orgIds"
            :ismultiple="true"></tree>
        </el-form-item>
        <el-form-item label="库位代码" prop="warehouseCode">
          <el-input
            v-model="queryParamsAbet.warehouseCode"
            placeholder="请输入库位代码"
            clearable
            size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="库位级别" prop="inventoryLeavel">
          <el-select
            v-model="queryParamsAbet.inventoryLeavel"
            placeholder="库位级别"
            clearable
            style="width: 240px">
            <el-option
              v-for="dict in dict.type.material_level_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryAbet"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="listRresetQueryAbet"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="materialInventoryListAbet">
        <el-table-column label="库位名称" align="center" prop="warehouseName" />
        <el-table-column label="库位代码" align="center" prop="warehouseCode" />
        <el-table-column label="库位层次" align="center" prop="inventoryLeavel">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.material_level_type" :value="scope.row.inventoryLeavel" />
          </template>
        </el-table-column>
        <el-table-column label="物料类型" align="center" prop="materialTypeName" />
        <el-table-column label="物料名称" align="center" prop="materialDataName" />
        <el-table-column label="公司" align="center" prop="inventoryGsDeptName" />
        <el-table-column label="大区" align="center" prop="inventoryDqDeptName" />
        <el-table-column label="销售部" align="center" prop="inventoryMdDeptName" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleUpdateAllotlist(scope.row)"
              >选择</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="totalAbet > 0"
        :total="totalAbet"
        :page.sync="queryParamsAbet.pageNum"
        :limit.sync="queryParamsAbet.pageSize"
        @pagination="getListAbet" />
      <!--      <div slot="footer" class="dialog-footer">-->
      <!--        <el-button type="primary" @click="submitFormAllot">确 定</el-button>-->
      <!--        <el-button @click="openAbet=false">关 闭</el-button>-->
      <!--      </div>-->
    </el-dialog>
  </div>
</template>

<script>
import tree from '@/views/components/sfa/treeselectParent';
import treeSingle from '@/views/components/sfa/treeselectSingle';
import user from '@/views/components/sfa/user';
import {
  listMaterialInventory,
  getMaterialInventory,
  delMaterialInventory,
  addMaterialInventory,
  updateMaterialInventory,
} from '@/api/sfa/materialInventory';
import {
  listMaterialInventoryLog,
  getMaterialInventoryLog,
  addMaterialInventoryLog,
  updateMaterialInventoryLog,
  delMaterialInventoryLog,
} from '@/api/sfa/materialInventoryLog';
import { listDictype } from '@/api/sfa/dictype';
import { adjustList, updateChange } from '@/api/sfa/allotInventory';
import { reportlist } from '@/api/sfa/inventoryReport';
import Treeselect from '@riophae/vue-treeselect';
import { listDept } from '@/api/system/dept';
import { changehomereport } from '@/api/sfa/changehomereport';
import { signhomestatement } from '../../../api/sfa/changehomereport';
export default {
  name: 'MaterialInventory',
  components: { treeSingle, user, tree, Treeselect },
  dicts: [
    'material_level_type',
    'material_change_type',
    'material_change_log_type',
    'material_change_type',
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      //遮罩层（变更记录）
      loadingRW: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //总条数（变更记录）
      totalRw: 0,
      totalAbet: 0,
      signTime: [],
      // 物料库存表格数据
      materialInventoryList: [],
      materialTypeOption: [],
      materialNameOptionQuery: [],
      // 物料库存变更表格数据
      materialInventoryLogList: [],
      materialInventoryListAbet: [],
      changeTypeOptions: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      openAllot: false,
      openAbet: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        inventoryGsDeptId: null,
        inventoryGsDeptName: null,
        inventoryDqDeptId: null,
        inventoryDqDeptName: null,
        inventoryMdDeptId: null,
        inventoryMdDeptName: null,
        materialTypeId: null,
        materialTypeName: null,
        materialDataId: null,
        materialDataName: null,
        inventoryNum: null,
        inventoryLeavel: null,
        status: null,
        orgIds: null,
        warehouseName: null,
        warehouseCode: null,
        inventoryLyUserId: null,
        inventoryLyUserName: null,
      },
      // 查询参数（变更记录）
      queryParamsRw: {
        pageNum: 1,
        pageSize: 10,
        materialInventoryId: null,
        changeWarehouseName: null,
        changeWarehouseCode: null,
        changeType: null,
      },
      queryParamsAbet: {
        pageNum: 1,
        pageSize: 10,
        materialInventoryId: null,
        changeWarehouseName: null,
        changeWarehouseCode: null,
        changeType: null,
      },
      validTree: true,
      // 表单参数
      form: {},
      formAllot: {},
      // 表单校验
      rulesAllot: {
        followInventoryNames: [{ required: true, message: '请输入调拨库', trigger: 'change' }],
        inventoryNum: [{ required: true, message: '请输入数量', trigger: 'blur' }],
      },
      rules: {},
      menuOptions: [],
    };
  },
  created() {
    this.getDicts('material_change_type').then((response) => {
      this.changeTypeOptions = response.data;
    });
    this.getList();
    this.getMaterialTypeOption();
    this.getTreeselect();
  },
  methods: {
    /** 转换菜单数据结构 */
    normalizer1(node) {
      let that = this;
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children,
        isDisabled: that.isDisabled,
      };
    },
    getTreeselect() {
      listDept().then((response) => {
        this.menuOptions = this.handleTree(response.data, 'deptId', 'parentId');
        if (
          this.menuOptions.length == 1 &&
          (this.menuOptions[0].children == null ||
            this.menuOptions[0].children == undefined ||
            (this.menuOptions[0].children != undefined &&
              this.menuOptions[0].children != null &&
              this.menuOptions[0].children.length == 0))
        ) {
          this.form.orgId = this.menuOptions[0].deptId;
        }
      });
    },
    treeselectFnSingle(val) {
      if (val.deptId != undefined && val.deptId != '' && val.deptId != null) {
        this.form.orgId = val.deptId;
        this.getList();
      }
    },
    materialTypeChangeQuery(val) {
      this.queryParams.materialName = '';
      if (val != '' && val != null) {
        let pid;
        this.materialTypeOption.forEach((item) => {
          if (item.signType == val) {
            console.log(item);
            pid = item.id;
            let obj = {
              type: 1,
              pid,
            };
            this.getMaterialNameOption(obj, 'materialNameOptionQuery');
          }
        });
      } else {
        this.materialNameOptionQuery = [];
      }
      this.$forceUpdate();
    },
    getMaterialTypeOption() {
      let obj = {
        type: 0,
      };
      this.getMaterialNameOption(obj, 'materialTypeOption');
    },
    onInput() {
      this.$forceUpdate();
    },
    getMaterialNameOption(obj, str) {
      let that = this;
      listDictype(obj).then((response) => {
        if (str == 'materialNameOptionAll') {
          that.materialNameOptionAll = response.rows;
        } else if (str == 'materialTypeOption') {
          that.materialTypeOption = response.rows;
        } else if (str == 'materialNameOption') {
          that.materialNameOption = response.rows;
        } else if (str == 'materialNameOptionQuery') {
          that.materialNameOptionQuery = response.rows;
        }
      });
    },
    /** 查询物料库存列表 */
    getList() {
      this.loading = true;
      this.queryParams.startTime = this.signTime == null ? '' : this.signTime[0];
      this.queryParams.endTime = this.signTime == null ? '' : this.signTime[1];
      changehomereport(this.queryParams).then((response) => {
        this.materialInventoryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getListAbet() {
      this.loading = true;
      adjustList(this.queryParamsAbet).then((response) => {
        this.materialInventoryListAbet = response.rows;
        this.totalAbet = response.total;
        this.loading = false;
      });
    },
    /** 查询物料变更记录列表 */
    getListRw() {
      this.loadingRW = true;
      listMaterialInventoryLog(this.queryParamsRw).then((response) => {
        this.materialInventoryLogList = response.rows;
        this.totalRw = response.total;
        this.loadingRW = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelAllot() {
      this.openAllot = false;
      this.resetAllot();
    },
    resetAllot() {
      this.formAllot = {
        inventoryId: null,
        inventoryGsDeptId: null,
        inventoryGsDeptName: null,
        inventoryDqDeptId: null,
        inventoryDqDeptName: null,
        inventoryMdDeptId: null,
        inventoryMdDeptName: null,
        materialTypeId: null,
        materialTypeName: null,
        materialDataId: null,
        materialDataName: null,
        inventoryNum: null,
        followInventoryId: null,
        followInventoryName: null,
        inventoryLeavel: null,
        status: '0',
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        warehouseName: null,
        warehouseCode: null,
        inventoryLyUserId: null,
        inventoryLyUserName: null,
      };
      this.resetForm('formAllot');
    },
    // 表单重置
    reset() {
      this.form = {
        inventoryId: null,
        inventoryGsDeptId: null,
        inventoryGsDeptName: null,
        inventoryDqDeptId: null,
        inventoryDqDeptName: null,
        inventoryMdDeptId: null,
        inventoryMdDeptName: null,
        materialTypeId: null,
        materialTypeName: null,
        materialDataId: null,
        materialDataName: null,
        inventoryNum: null,
        inventoryLeavel: null,
        status: '0',
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        warehouseName: null,
        warehouseCode: null,
        inventoryLyUserId: null,
        inventoryLyUserName: null,
      };
      this.resetForm('form');
    },
    // 变更记录表单重置
    resetRw() {
      this.form = {
        materialInventoryId: null,
        status: '0',
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        changeWarehouseName: null,
        changeWarehouseCode: null,
        changeType: null,
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 变更记录搜索按钮操作 */
    handleQueryRw() {
      this.queryParamsRw.pageNum = 1;
      this.getListRw();
    },
    handleQueryAbet() {
      this.queryParamsAbet.pageNum = 1;
      this.getListAbet();
    },
    handleUpdateAllotlist(row) {
      this.formAllot.followInventoryId = row.warehouseCode;
      this.formAllot.followInventoryNames = row.warehouseName;
      this.openAbet = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    followOpen() {
      this.openAbet = true;
      this.listRresetQueryAbet();
    },
    listRresetQueryAbet() {
      this.queryParamsAbet = {
        pageNum: 1,
        pageSize: 10,
        orgIds: null,
        warehouseCode: '',
        inventoryLeavel: '',
        materialTypeName: '',
        materialDataName: '',
      };
      this.handleQueryAbet();
    },
    // 库存重置
    listRresetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        orgIds: null,
        warehouseCode: '',
        inventoryLeavel: '',
        materialTypeName: '',
        materialDataName: '',
      };
      this.signTime = [];
      this.handleQuery();
    },
    // 变更记录重置
    listRresetQueryRw() {
      this.queryParamsRw.pageNum = 1;
      this.queryParamsRw.pageSize = 10;
      this.queryParamsRw.changeType = '';
      this.queryParamsRw.changeWarehouseName = '';
      this.queryParamsRw.changeWarehouseCode = '';
      this.handleQueryRw();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.inventoryId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = '添加物料库存';
    },
    handleUpdateAllot(row) {
      this.resetAllot();
      const inventoryId = row.inventoryId || this.ids;
      getMaterialInventory(inventoryId).then((response) => {
        response.data.followInventoryNames = '';
        response.data.inventoryNum = '';
        this.formAllot = response.data;
        this.formAllot.changeType = '4';
        this.formAllot.followInventoryNames = '';
        this.formAllot.inventoryNum = '';
        this.openAllot = true;
        this.title = '盘点物料';
      });
    },
    handleUpdateAllots(row) {
      this.resetAllot();
      // const inventoryId = row.inventoryId || this.ids
      // getMaterialInventory(inventoryId).then(response => {
      //   response.data.followInventoryNames=""
      this.formAllot = row.data;
      this.formAllot.changeType = '3';
      this.formAllot.followInventoryNames = '';
      this.formAllot.inventoryNum = '';
      this.openAllot = true;
      this.title = '调拨物料';
      // });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const inventoryId = row.inventoryId || this.ids;
      getMaterialInventory(inventoryId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = '修改物料库存';
      });
    },
    /** 提交按钮 */
    submitFormAllot() {
      console.log(this.formAllot);
      this.$refs['formAllot'].validate((valid) => {
        if (valid) {
          updateChange(this.formAllot).then((response) => {
            if (response.code == 200) {
              this.$modal.msgSuccess('操作成功');
              this.openAllot = false;
              this.getList();
            }
          });
        }
      });
    },
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.inventoryId != null) {
            updateMaterialInventory(this.form).then((response) => {
              this.$modal.msgSuccess('修改成功');
              this.open = false;
              this.getList();
            });
          } else {
            addMaterialInventory(this.form).then((response) => {
              this.$modal.msgSuccess('新增成功');
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const inventoryIds = row.inventoryId || this.ids;
      this.$modal
        .confirm('是否确认删除物料库存编号为"' + inventoryIds + '"的数据项？')
        .then(function () {
          return delMaterialInventory(inventoryIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess('删除成功');
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.queryParams.startTime = this.signTime == null ? '' : this.signTime[0];
      this.queryParams.endTime = this.signTime == null ? '' : this.signTime[1];
      signhomestatement(this.queryParams).then((response) => {
        window.location.href =
          process.env.VUE_APP_BASE_API +
          '/common/download?fileName=' +
          encodeURI(response.msg) +
          '&delete=' +
          true;
      });
    },
    treeselectFn(val) {
      this.queryParams.gs_deptid = val;
    },
    treeselectFnAbet(val) {
      this.queryParamsAbet.orgIds = val;
    },
    //变更记录点击事件
    getMaterialInventoryLogData(materialInventoryId) {
      console.log('库存id：' + materialInventoryId);
      this.queryParamsRw.materialInventoryId = materialInventoryId;
      this.loadingRW = true;
      listMaterialInventoryLog(this.queryParamsRw).then((response) => {
        this.materialInventoryLogList = response.rows;
        this.loadingRW = false;
        this.totalRw = response.total;
        this.open = true;
        this.title = '库存变更记录';
      });
    },
  },
};
</script>
