<template>
  <div class="bg-in-stock dark:!bg-[#060818]" v-loading="loading">
    <el-form ref="goodsInventoryAddFormRef" :model="goodsInventoryAddForm" :rules="goodsInventoryAddFormRule" label-width="120px" inline class="change-form">
      <h3 style="width: 100%">{{ $t('inventory') }}</h3>
      <el-form-item :label="$t('inventorySn')" prop="sn" v-if="type === 'edit' || type === 'view'" class="change-form-item">
        <el-input v-model="goodsInventoryAddForm.sn" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item :label="$t('inventory_time')" prop="inventory_time" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ goodsInventoryAddForm.inventory_time }}</span>
        <el-date-picker
          v-else
          v-model="goodsInventoryAddForm.inventory_time"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="datetime"
          :disabled="type === 'detail' || type === 'audit' || type === 'check'"
          :placeholder="$t('change') + $t('date')"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="$t('warechouse')" prop="warehouse_id" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ getWarehouse(goodsInventoryAddForm.warehouse_id) }}</span>
        <el-select
          v-else
          v-model="goodsInventoryAddForm.warehouse_id"
          @change="handleChangeWareHouse"
          :disabled="type === 'detail' || type === 'audit' || type === 'check'"
        >
          <el-option v-for="item in warehouseList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('inventoryPeople')" prop="inventory_person_id" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ getadminList(goodsInventoryAddForm.inventory_person_id) }}</span>
        <el-select
          v-else
          @change="forceUpdate"
          v-model="goodsInventoryAddForm.inventory_person_id"
          :disabled="type === 'detail' || type === 'audit' || type === 'check'"
        >
          <el-option v-for="item in adminList" :key="item.id" :label="item.nickname" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('creator')" prop="creator_id" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ getadminList(goodsInventoryAddForm.creator_id) }}</span>
        <el-select
          v-else
          v-model="goodsInventoryAddForm.creator_id"
          :disabled="type === 'detail' || type === 'audit' || type === 'check'"
          @change="forceUpdate"
        >
          <el-option v-for="item in adminList" :key="item.id" :label="item.nickname" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('inventoryType')" prop="inventory_type" class="change-form-item">
        <span v-if="id && type !== 'edit'">{{ getRoleSplit(goodsInventoryAddForm.inventory_type) }}</span>
        <el-select
          v-else
          v-model="goodsInventoryAddForm.inventory_type"
          @change="handleChangeInventoryType($event)"
          :disabled="type === 'detail' || type === 'audit' || type === 'check'"
        >
          <el-option v-for="item in typeList" :key="item.id" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('notifiedre') + ':'" prop="has_notice" class="change-form-item">
        <el-switch v-model="goodsInventoryAddForm.has_notice" :disabled="type === 'view'" inline-prompt :active-text="true" :inactive-text="false" />
      </el-form-item>
      <el-form-item :label="$t('reviewer') + ':'" prop="notice_user_id" class="change-form-item" v-if="goodsInventoryAddForm.has_notice">
        <span v-if="id && type !== 'edit'">{{ getNotice(goodsInventoryAddForm.notice_user_id) }}</span>
        <el-select v-else v-model="goodsInventoryAddForm.notice_user_id" :disabled="type === 'detail' || type === 'audit' || type === 'view'">
          <el-option v-for="item in auditList" :key="item.id" :label="item.nickname" :value="item.id" />
        </el-select>
      </el-form-item>
      <div class="mx">
        <h3>{{ $t('goods_inventory') }}</h3>
        <el-button class="button" size="mini" type="primary" v-if="type !== 'detail' && type !== 'view'" @click="scanCode">{{$t('goods_code')}}</el-button>
        <el-button
          class="button"
          size="mini"
          type="primary"
          v-if="type !== 'detail' && type !== 'view'"
          @click="handleSelectWarehouseEntryBatch"
          :disabled="selectBtn"
          >{{$t('select')}}</el-button
        >
      </div>
      <div style="width: 100%; display: block">
        <el-form-item style="width: 100%">
          <el-table
            :data="goodsInventoryAddForm.product_list"
            border
            :cell-style="{ textAlign: 'center' }"
            :header-cell-style="{ textAlign: 'center' }"
            :loading="loading"
            style="width: 100%; margin-top: 20px"
          >
            <el-table-column :label="$t('warechouse_code')">
              <template #default="scope">
                <el-popover placement="right" trigger="click" v-if="scope.row.area_stock_list">
                  <div>
                    <p v-for="item in scope.row.area_stock_list" :key="item.id">{{ item.warehouse_area_name }}</p>
                  </div>
                  <template v-slot:reference>
                    <span v-if="scope.row.area_stock_list.length !== 0">
                      {{ scope.row.area_stock_list[0].warehouse_area_name }}
                    </span>
                  </template>
                  <!--  <span slot="reference" v-if="scope.row.area_stock_list.length !== 0">{{ scope.row.area_stock_list[0].warehouse_area_name }}</span> -->
                </el-popover>
              </template>
            </el-table-column>
            <!--  <el-table-column label="商品编号">
              <template #default="scope">
                <span v-if="id"> {{ scope.row.product_vo.sn }}</span>
                <span v-else>{{ scope.row.product_vo.sn }}</span>
              </template>
            </el-table-column> -->
            <el-table-column :label="$t('goods_name')">
              <template #default="scope">
                <span v-if="id">{{ scope.row.product_vo.name }}</span>
                <span v-else>{{ scope.row.product_vo.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="sku">
              <template #default="scope">
                <span v-if="!id"> {{ scope.row.product_vo.sku }}</span>
                <span v-else> {{ scope.row.product_vo.sku }}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column label="序列号" width="160">
              <template #default="scope">
                <div class="sn-code-container">
                  <span v-for="item in scope.row.sn_code_list" :key="item.id">
                    <p>{{ item.sn_code }}</p>
                  </span>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="product_vo.spec_name" label="规格型号"> </el-table-column> -->
            <el-table-column :label="$t('goods_unit')">
              <template #default="scope">
                <span v-if="!id"> {{ scope.row.product_vo.unit }}</span>
                <span v-else> {{ scope.row.product_vo.unit }}</span>
              </template>
            </el-table-column>
            <el-table-column :label="$t('stock')">
              <template #default="scope">
                {{ scope.row.actual_stock }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('inventory_num')">
              <template #default="scope">
                <span v-if="type === 'view'">{{ scope.row.inventory_num }}</span>
                <el-input
                  v-else
                  v-model="scope.row.inventory_num"
                  type="number"
                  :min="0"
                  :maxlength="20"
                  :disabled="type === 'detail' || type === 'audit' || type === 'view'"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column :label="$t('diff')">
              <template #default="scope">
                {{ scope.row.inventory_num - scope.row.actual_stock || 0 }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('operate')" v-if="type !== 'detail' && type !== 'audit' && type !== 'view'">
              <template #default="scope">
                <el-button size="mini" type="danger" @click="goodsInventoryAddForm.product_list.splice(scope.$index, 1)">{{$t('delete')}}</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </div>
    </el-form>
    <div class="footer">
      <el-button v-if="type !== 'audit' && type !== 'detail' && type !== 'view'" type="primary" @click="submitGoodsInventoryAddForm">{{$t('save')}} </el-button>
      <el-button @click="printIng" v-if="type == 'check'">{{$t('print')}}</el-button>
      <el-button @click="$router.back()">{{$t('return')}} </el-button>
    </div>
    <el-dialog :title="$t('goods_code')" v-model="scanDialogVisible" width="30%" :close-on-click-modal="false" class="!rounded-lg">
      <el-form ref="scanGoodsForm" :model="scanGoodsForm" label-width="120px" inline>
        <el-form-item label="sku" prop="bar_code">
          <el-input v-model="scanGoodsForm.bar_code" ref="input" @keyup.enter="toSearch()" :minlength="0" :maxlength="100"></el-input>
        </el-form-item>
        <el-form-item label="序列号" prop="sn_code">
          <el-input ref="sn_input" v-model="sn_code" @keyup.enter="toSnCode()" :minlength="0" :maxlength="100"></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog :title="$t('prompt')" v-model="dialogVisible" width="30%" class="!rounded-lg">
      <el-form ref="goodsInventoryAddForm" :model="goodsInventoryAddForm" label-width="120px" inline ><!-- style="width: 900px" -->
        <el-form-item :label="$t('reject')" prop="reject_reason" required="true">
          <el-input v-model="goodsInventoryAddForm.reject_reason" type="textarea" :minlength="0" :maxlength="100"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="dialogVisible = false">{{$t('cancel')}}</el-button>
        <el-button type="primary" @click="handleRejectGoodsInventory()">{{$t('submit')}}</el-button>
      </template>
    </el-dialog>
    <el-dialog :title="$t('inven')" v-model="goodsVisible" width="1000px" @close="closeGoosData" class="!rounded-lg">
      <div style="display: flex; align-items: center; justify-content: flex-end; padding: 10px 0">
        <span>{{$t('search')+$t('goods_info')}}:</span><el-input v-model="params.keyWord" style="width: 200px; margin-right: 5px"></el-input>
        <el-button @click="searchGoodEvent"> {{$t('search')}} </el-button>
      </div>
      <el-table :data="goodsData.records" border style="width: 100%" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="product_vo.name" :label="$t('goods_name')"></el-table-column>
        <el-table-column prop="product_vo.sku" label="sku"> </el-table-column>
        <el-table-column prop="" :label="$t('brand')">
          <template #default="scope">
            {{ scope.row.product_vo.brand }}
          </template>
        </el-table-column>
        <el-table-column prop="product_vo.weight" :label="$t('weight')"> </el-table-column>
        <el-table-column prop="product_vo.unit" :label="$t('goods_unit')"> </el-table-column>
      </el-table>
      <el-pagination
        @size-change="goodsPageSizeChange"
        @current-change="goodsPageCurrentChange"
        :current-page="goodsData.current"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="goodsData.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="goodsData.total"
      >
      </el-pagination>
      <template #footer>
        <el-button @click="closeGoosData">{{$t('cancel')}}</el-button>
        <el-button type="primary" @click="submitGoosData()">{{$t('submit')}}</el-button>
      </template>
    </el-dialog>
  </div>
</template>
  
  <script lang="ts" setup>
import { ref, onMounted, computed, nextTick, reactive } from 'vue';
import { useStore, mapGetters } from 'vuex';
/* import { Foundation, RegExp } from '~/ui-utils'; */
import * as API_GoodsInventory from '@/api/goodsInventory';
import * as API_GoodsExchange from '@/api/goodsExchange';
import * as API_Setting from '@/api/setting';
import * as API_BasicSetting from '@/api/basicSetting';
import * as API_Auth from '@/api/auth';
import { useRouter, useRoute } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import { useI18n } from 'vue-i18n';

const { t } = useI18n();

const router = useRouter();
const route = useRoute();

const store = useStore();
const loading = ref(false);
const adminList = ref<any>([]);
const dialogVisible = ref(false);
const warehouseList = ref<any>([]);
const deptList = ref([]);
const deptListAll = ref([]);
const id = ref('');
const type = ref('');
const goodsInventoryAddForm = ref<any>({
  product_list: [],
  inventory_time: '',
  inventory_person_id: '',
  creator_id: '',
  has_notice: false,
});
const goodsInventoryAddFormRule = ref({
  inventory_person_id: { required: true, message: t('change')+t('inventoryPeople'), trigger: 'change' },
  warehouse_id: { required: true, message: t('change')+t('warechouse'), trigger: 'change' },
  creator_id: { required: true, message:  t('change')+t('creator'), trigger: 'change' },
});
const warehouseProduct = ref(null);
const typeList = ref<any>([]);
const scanDialogVisible = ref(false);
const scanGoodsForm = ref<any>({});
const sn_code = ref('');
const sn_code_list = ref([]);
const index = ref('');
const selectBtn = ref(false);
/* 盘点商品信息 操作部分 */
const goodsVisible = ref(false);
const goodsData = ref<any>([]);
const params = reactive({
  page_no: 1,
  page_size: 10,
  keyWord: '',
});
/* 关闭盘点商品 */
const closeGoosData = () => {
  goodsVisible.value = false;
};
/* 搜索盘点商品 */
const searchGoodEvent = () => {
  API_GoodsExchange.getGoodsInfo(params, goodsInventoryAddForm.value.warehouse_id).then((res) => {
    goodsData.value = res;
  });
};
/* 选中的商品列表 */
const goodsList = ref([]);
const handleSelectionChange = (val) => {
  goodsList.value = val.map((el) => {
    /* el.product_id = el.id;
    el.goods_id = el.id;
    el.sn_code_list = []; */
    return el;
  });
};
const submitGoosData = () => {
  if (goodsList.value.length >= 1) {
    goodsInventoryAddForm.value.product_list = goodsList.value.map((el) => {
      /* el.sn_code_list = []; */
      return el;
    });
    goodsVisible.value = false;
  } else {
    ElMessage.error(t('change')+t('goods_info'));
  }
};
/* 盘点商品分页 */
const goodsPageSizeChange = (size) => {
  params.page_size = size;
  searchGoodEvent();
};

const goodsPageCurrentChange = (page) => {
  params.page_no = page;
  searchGoodEvent();
};

const user = computed(() => store.getters.user);
const timeDefault = computed(() => {
  const date = new Date();
  return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
});
/* 获取审核人列表 */
const auditList = ref<any>([]);
const GET_AuditList = () => {
  API_GoodsInventory.getUserByCompany().then((res) => {
    auditList.value = res;
  });
};

onMounted(() => {
  if (route.query.type === 'view') {
    type.value = 'view';
    id.value = route.query.id as string;
    GET_goodsInventoryAddDetail();
  } else if (route.query.type === 'edit') {
    type.value = 'edit';
    id.value = route.query.id as string;
    GET_goodsInventoryAddDetail();
  }
  /*  if (route.name === 'goodsInventoryAdd') {
    goodsInventoryAddForm.value.creator_id = user.value.uid;
    goodsInventoryAddForm.value.inventory_person_id = user.value.uid;
    goodsInventoryAddForm.value.dept_id = user.value.dept_id;
    //goodsInventoryAddForm.value.inventory_time = timeDefault.value;
  } else if (route.name === 'goodsInventoryDetail') {
    type.value = 'detail';
  } else if (route.query.type === 'view') {
    type.value = 'check';
    id.value = store.state.route.params.id;
    GET_goodsInventoryAddDetail();
    GET_AdministratorList();
    GET_WarehouseList();
  } else if (route.name === 'goodsInventoryEdit') {
    type.value = 'edit';
    goodsInventoryAddForm.value.creator_id = user.value.uid;
    goodsInventoryAddForm.value.inventory_person_id = user.value.uid;
    goodsInventoryAddForm.value.dept_id = user.value.dept_id;
    //goodsInventoryAddForm.value.inventory_time = timeDefault.value;
    id.value = store.state.route.params.id;
    GET_goodsInventoryAddDetail();
    GET_AdministratorList();
    GET_WarehouseList();
  } */
  goodsInventoryAddForm.value.creator_id = user.value.uid;
  goodsInventoryAddForm.value.inventory_person_id = user.value.uid;
  goodsInventoryAddForm.value.dept_id = user.value.dept_id;
  GET_AdministratorList();
  GET_WarehouseList();
  GET_DeptList();
  GET_AuditList();
});

const handleChangeInventoryType = (val: string) => {
  goodsInventoryAddForm.value.product_list = [];
  if (val === 'ALL_INVENTORY') {
    if (!goodsInventoryAddForm.value.warehouse_id) {
      store.dispatch('message/error', t('change')+t('warechouse')+'!');
      return;
    }
    loading.value = true;
    API_GoodsExchange.getGoodsInfo(params, goodsInventoryAddForm.value.warehouse_id, 'le')
      .then((res) => {
        /* res.records.forEach((el) => {
          el.sn_code_list = [];
        }); */
        goodsInventoryAddForm.value.product_list = res.records;
        selectBtn.value = true;
        loading.value = false;
      })
      .catch(() => {
        loading.value = false;
      });
  } else {
    selectBtn.value = false;
  }
};

const input = ref();
const toSnCode = async () => {
  if (scanGoodsForm.value.bar_code === '') return store.dispatch('message/error', '请录入正确的sku');
  await API_GoodsExchange.getSnCode('inventory', scanGoodsForm.value.bar_code, sn_code.value.replace(/\s+/g, '')).then(async (res) => {
    sn_code.value = '';
    const exists = goodsInventoryAddForm.value.product_list[index.value].sn_code_list.find((item: any) => item.sn_code === res.sn_code && item.sku === res.sku);
    if (!exists) {
      if (id.value) {
        await API_GoodsExchange.skuRedis({
          send_order_id: id.value,
          item_id: goodsInventoryAddForm.value.product_list[index.value].id,
          sku: res,
        }).then(() => {
          goodsInventoryAddForm.value.product_list[index.value].sn_code_list.push(res);
        });
      } else {
        goodsInventoryAddForm.value.product_list[index.value].sn_code_list.push(res);
      }
    }
    goodsInventoryAddForm.value.product_list[index.value].inventory_num = goodsInventoryAddForm.value.product_list[index.value].sn_code_list.length;
    scanGoodsForm.value.bar_code = '';
    nextTick(() => {
      input.value.focus();
    });
  });
};

const sn_input = ref();
const toSearch = () => {
  API_GoodsExchange.getProduct(goodsInventoryAddForm.value.warehouse_id, scanGoodsForm.value.bar_code.replace(/\s+/g, '')).then((res) => {
    res.sn_code_list = [];
    const indexs = goodsInventoryAddForm.value.product_list.findIndex(
      (el: any) => el.goods_id === res.goods_id && el.product_id === res.product_id && el.product_vo.sku === res.product_vo.sku
    );
    if (indexs === -1) {
      index.value = goodsInventoryAddForm.value.product_list.length;
      goodsInventoryAddForm.value.product_list.push(res);
    } else {
      index.value = indexs;
    }
    if (res.product_vo.have_sn) {
      nextTick(() => {
        sn_input.value.focus();
      });
    } else {
      goodsInventoryAddForm.value.product_list[index.value].inventory_num += 1;
    }
  });
};

const scanCode = () => {
  if (!goodsInventoryAddForm.value.warehouse_id) {
    store.dispatch('message/error', t('change')+t('warechouse')+'!');
    return;
  }
  if (!goodsInventoryAddForm.value.inventory_type) {
    store.dispatch('message/error', t('change')+t('inventoryType')+'!');
    return;
  }
  scanDialogVisible.value = true;
  nextTick(() => {
    input.value.focus();
  });
};
/* 获取审核人名称 */
const getNotice = (value: string) => {
  const type = auditList.value.find((type: any) => type.id === value);
  return type ? type.nickname : t('unknown');
};

const getadminList = (value: string) => {
  const type = adminList.value.find((type: any) => type.id === value);
  return type ? type.nickname : t('unknown');
};

const getRoleSplit = (value: string) => {
  const type = typeList.value.find((type: any) => type.value === value);
  return type ? type.label : t('unknown');
};

const getWarehouse = (value: string) => {
  const type = warehouseList.value.find((type: any) => type.id === value);
  return type ? type.name : t('unknown');
};

const printIng = () => {
  // Implement print functionality
};

const forceUpdate = () => {
  store.dispatch('forceUpdate');
};

const cleanGoodsList = () => {
  goodsInventoryAddForm.value.product_list = [];
};

const GET_AdministratorList = () => {
  API_Auth.getAdministratorList({
    page_no: 1,
    page_size: 9999,
    user_state: 0,
  }).then((response) => {
    adminList.value = response.data;
  });
};

const handlePassGoodsInventory = () => {
  /* store.dispatch('confirm', '确定通过吗？', '提示', { type: 'warning' }).then(() => {
    API_GoodsInventory.auditGoodsInventory(id.value, { status: 'PASS' })
      .then(() => {
        store.dispatch('message/success', '已通过！');
        const { callback } = store.state.route.params;
        if (typeof callback === 'function') callback();
        store.dispatch('delCurrentViews', {
          view: store.state.route,
          $router: store.state.router,
        });
        store.state.router.push({ name: 'goodsInventory' });
      })
      .catch(() => {});
  }); */
};

const handleRejectGoodsInventory = () => {
  if (!goodsInventoryAddForm.value.reject_reason) {
    ElMessage.error(t('reject_reason'));
    return;
  }
  ElMessageBox.confirm(t('confirm_rejec'), t('prompt'), { type: 'warning' })
    .then(() => {
      API_GoodsInventory.auditGoodsInventory(id.value, { status: 'REJECT', reject_reason: goodsInventoryAddForm.value.reject_reason }).then(() => {
        ElMessage.success(t('rejected'));
        const { callback } = store.state.route.params;
        if (typeof callback === 'function') callback();
        store.dispatch('delCurrentViews', {
          view: store.state.route,
          $router: store.state.router,
        });
        store.state.router.push({ name: 'goodsInventory' });
      });
    })
    .catch(() => {});
};

const changewarehouseList = (e: any) => {
  goodsInventoryAddForm.value.warehouse_id = '';
  GET_WarehouseList({ dept_id: e });
  cleanGoodsList();
};

const GET_WarehouseList = (e?: any) => {
  API_BasicSetting.getWarehouseListAll().then((response) => {
    warehouseList.value = response;
  });
};

const goodsInventoryAddFormRef = ref();
const submitGoodsInventoryAddForm = () => {
  goodsInventoryAddFormRef.value.validate((valid: boolean) => {
    if (valid) {
      const params = { ...goodsInventoryAddForm.value };
      if (params.warehouse_id) {
        params.warehouse_name = warehouseList.value.find((ware: any) => ware.id === params.warehouse_id).name;
      }
      if (params.creator_id) {
        params.creator = adminList.value.find((admin: any) => admin.id === params.creator_id).real_name;
      }
      if (params.inventory_person_id) {
        params.inventory_person = adminList.value.find((admin: any) => admin.id === params.inventory_person_id).real_name;
      }
      params.product_list = params.product_list.map((item: any) => ({
        diff_num: item.usable_stock - item.inventory_num,
        inventory_num: item.inventory_num * 1,
        product_name: item.product_name,
        product_sn: item.product_sn,
        product_id: item.product_id,
        specification: item.product_specification,
        unit: item.product_unit,
        remark: item.remark,
        product_stock_id: item.id,
        sn_code_list: item.sn_code_list,
      }));
      if (id.value) {
        API_GoodsInventory.editgoodsInventoryAdd(id.value, params).then(() => {
          ElMessage.success(t('edit_success')+'!');
          router.push({ name: 'goodsInventory' });
        });
      } else {
        API_GoodsInventory.addgoodsInventoryAdd(params).then(() => {
          ElMessage.success(t('add_success')+'!');
          router.push({ name: 'goodsInventory' });
        });
      }
    }
  });
};

const handleSelectWarehouseEntryBatch = async () => {
  if (!goodsInventoryAddForm.value.warehouse_id) {
    ElMessage.error(t('change')+t('warechouse')+'!');
    return;
  }
  API_GoodsExchange.getGoodsInfo(params, goodsInventoryAddForm.value.warehouse_id, 'le').then((res) => {
    goodsData.value = res;
    goodsVisible.value = true;
  });
};

const GET_DeptList = () => {
  API_Setting.getPage({ dictType: 'inventory_type' }).then((res) => {
    typeList.value = res.data;
  });
};

const handleChangeWareHouse = (val: any) => {
  goodsInventoryAddForm.value.product_list = [];
};

const GET_goodsInventoryAddDetail = () => {
  API_GoodsInventory.getGoodsInventoryInfo(route.query.id).then((response) => {
    if (!response.product_list) {
      response.product_list = [];
    }
    goodsInventoryAddForm.value = response;
    GET_WarehouseList();
    /* goodsInventoryAddForm.value.distribution_name = response.staff_name;
    if (goodsInventoryAddForm.value.product_list) {
      goodsInventoryAddForm.value.product_list = goodsInventoryAddForm.value.product_list.map((item: any) => {
        item.inventory_num = item.inventory_num;
        item.product_specification = item.specification;
        item.product_unit = item.unit;
        item.remain_num = item.stock_num;
        return item;
      });
    } else {
      goodsInventoryAddForm.value.product_list = [];
    } */
  });
};
</script>

<style scoped>
.footer {
  width: 100%;
  padding: 10px;
  bottom: 0px;
  text-align: center;
  z-index: 999;
}

.mx {
  display: flex;
  align-items: center;
  width: 100%;
}

.mx .button {
  margin-left: 10px;
}

.change-form {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  flex-wrap: wrap;
  /* min-width: 900px; */
}

.change-form .change-form-item {
  width: 30%;
  margin: 0 10px 20px 0;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
}

.change-form ::v-deep .el-form-item__content {
  flex: 1;
  width: 100%;
}

.change-form ::v-deep .el-date-editor,
.change-form ::v-deep .el-cascader,
.change-form ::v-deep .el-select {
  width: 100%;
}

.bg-in-stock {
  background-color: #fff;
  padding: 10px;
  padding: 25px;
}

.goods-info {
  display: flex;
}

.goods-info .goods-name-box {
  text-align: left;
}

.goods-info .goods-name-box .goods-name {
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 16px;
}

.goods-info .goods-name-box .specs {
  color: #999999;
}

.sn-code-container {
  max-height: 100px;
  overflow-y: auto;
}

::v-deep .el-input--suffix .el-input__inner {
  padding-right: 10px;
}

::v-deep .error-input .el-input__inner {
  border: 1px solid red;
}
</style>