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

<script setup>
import { onLoad, onShow } from '@dcloudio/uni-app';
import { ref } from 'vue';
// deleteOutStock
import { outStorageTypeList, 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: [1, 2, 3],
});

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

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

// 获取出库类型列表
const getStoragTypeList = () => {
  outStorageTypeList({ pageNum: 1, pageSize: 100 }).then(res => {
    res.rows.unshift({ typeName: "全部", typeCode: "" });
    storageType.value[0] = res.rows;
  });
};

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

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

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

onLoad(() => {
  console.log('onLoad');
  getStoragTypeList();
});

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