const BASE_URL = 'http://110.42.33.196:8089';
const config = require('config.js');
const formatTime = date => {
  date = new Date(date);
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${formatNumber(hour)}:${formatNumber(minute)}:${formatNumber(second)}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const formatDate = date => {
  date = new Date(date);
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  return `${year}-${formatNumber(month)}-${formatNumber(day)}`
}

const formatDateTime = date => {
  return `${formatDate(date)} ${formatTime(date)}`
}
let staff = uni.getStorageSync('staff');
let staffisnull = (staff == null || staff == undefined || staff == '');
export function getHeaders() {
  const staff = uni.getStorageSync('staff') || null
  const staffisnull = !staff

  return {
    'content-type': 'application/json',
    'Authorization': staffisnull ? null : `Bearer ${uni.getStorageSync('token')}`,
    'hosp-ID': staffisnull ? config.defaultHospId : staff.hosp_id,
    'user-ID': staffisnull ? null : staff.id,
    'datetime': formatDateTime(new Date()),
    'createby': staffisnull ? null : staff.id
  }
}

//分页请求固定资产盘点信息
export function fetchAssetInventory(pageNum, pageSize) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${BASE_URL}/api/asset/inventory/page?pageNum=${pageNum}&pageSize=${pageSize}`,
      method: 'POST',
      data: {
		query:{},
      },

	  header:getHeaders(),
	 
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data); // 根据你的接口返回结构调整
        } else {
          reject(res);
        }
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}

