import request from "@/utils/request"

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

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

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

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

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

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

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

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

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

/** Excel 导入 */
export function importCooperativeDevelopment(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/cooperativeDevelopment/importData",
    method: "post",
    headers: {
      repeatSubmit: false
    },
    data: formData
  })
}

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

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