import request from "@/utils/request"

/** 分页列表 */
export function listLivestockProductOutput(query) {
  return request({
    url: "/dataModel/livestockProductOutput/list",
    method: "get",
    params: query
  })
}

/** 详情 */
export function getLivestockProductOutput(id) {
  return request({
    url: "/dataModel/livestockProductOutput/" + id,
    method: "get"
  })
}

/** 新增 */
export function addLivestockProductOutput(data) {
  return request({
    url: "/dataModel/livestockProductOutput",
    method: "post",
    data
  })
}

/** 修改 */
export function updateLivestockProductOutput(data) {
  return request({
    url: "/dataModel/livestockProductOutput",
    method: "put",
    data
  })
}

/** 删除 */
export function delLivestockProductOutput(ids) {
  return request({
    url: "/dataModel/livestockProductOutput/" + ids,
    method: "delete"
  })
}

/** 可选年份 */
export function listLivestockProductOutputYearOptions() {
  return request({
    url: "/dataModel/livestockProductOutput/yearOptions",
    method: "get"
  })
}

/** 可选月份（1～12） */
export function listLivestockProductOutputMonthOptions() {
  return request({
    url: "/dataModel/livestockProductOutput/monthOptions",
    method: "get"
  })
}

/** 乡镇下拉 */
export function listLivestockProductOutputTownOptions() {
  return request({
    url: "/dataModel/livestockProductOutput/townOptions",
    method: "get"
  })
}

/** 县→乡镇→村树 */
export function listLivestockProductOutputVillageTree() {
  return request({
    url: "/dataModel/livestockProductOutput/villageTree",
    method: "get"
  })
}

/** Excel 导入 */
export function importLivestockProductOutput(file, statYear, statMonth) {
  const formData = new FormData()
  formData.append("file", file, file.name)
  formData.append("statYear", String(statYear))
  formData.append("statMonth", String(statMonth))
  return request({
    url: "/dataModel/livestockProductOutput/importData",
    method: "post",
    headers: {
      repeatSubmit: false
    },
    data: formData
  })
}

/** 下载导入模板（GET） */
export function downloadLivestockProductOutputTemplate() {
  return request({
    url: "/dataModel/livestockProductOutput/importTemplate",
    method: "get",
    responseType: "blob"
  })
}

/**
 * 按年月导出（GET）
 * @param {number} statYear
 * @param {number} statMonth
 * @param {number} [townDeptId] 可选乡镇
 */
export function exportLivestockProductOutput(statYear, statMonth, townDeptId) {
  const params = { statYear, statMonth }
  if (townDeptId != null && townDeptId !== "") {
    params.townDeptId = townDeptId
  }
  return request({
    url: "/dataModel/livestockProductOutput/export",
    method: "get",
    params,
    responseType: "blob"
  })
}
