<template>
  <storageList v-model:listData="listData" :storageType="storageType" :storageStatus="storageStatus" pickerCode="rkType"
    :queryByParams="queryByParams()" @remove="romoveStorage" @add="goAddInStorage" @reload="handleReload"
    :deleteText="'撤 销 入 库'" :GoText="'新 增 入 库'" />
</template>

<script setup>
import { onLoad, onShow } from '@dcloudio/uni-app';
import { ref } from 'vue';
// deleteStock
import { storageTypeList, stockList } from '@/api/storage';
import storageList from './storageList.vue';

const listData = ref([]);
const storageType = ref([]);

let queryParams = ref({
  billNo: "",
  operationType: "",
  pageNum: 1,
  pageSize: 10,
  bizTypeList: [0]
});

let storageStatus = ref([
  [
    { value: "", label: "全部" },
    { value: "0", label: "预入库" },
    { value: "1", label: "已入库" },
  ]
]);

let queryByParams = () => {
  let obj = JSON.parse(JSON.stringify(queryParams.value))
  delete obj.rkType
  return obj
}

// 获取入库类型列表
const getStoragTypeList = () => {
  storageTypeList().then(res => {
    res.data.unshift({ typeName: "全部", typeCode: "" });
    storageType.value[0] = res.data;
  });
};

// 获取列表数据
const handleReload = (params) => {
  stockList(params).then(res => {
    res.rows.forEach(e => {
      e.showMore = false;
    });
    listData.value = res.rows;
  });
};

// 撤销入库
const romoveStorage = (billNo) => {
  deleteStock(billNo).then(res => {
    uni.showToast({
      title: res.msg,
      icon: 'none',
      mask: true
    });
    // 重新加载列表
    handleReload(queryParams.value);
  });
};

// 新增入库
const goAddInStorage = () => {
  uni.navigateTo({
    url: "/pagesStorage/addInStorage",
  });
};

onLoad(() => {
  getStoragTypeList();
});

onShow(() => {
  handleReload(queryParams.value);
});
</script>