import request from "~/request/request"



export const ebookDialogVisible = ref(false)

export const ebookListLoading = ref(true)

// {
//   "zem_id": "87",
//   "zem_keyword": "数学（北师大版八上）;978-7-5447-2948-2-36",
//   "zem_name": "数学（北师大版八上）",
//   "zem_isbn": "978-7-5447-2948-2-36",
//   "zem_img": "https://openapi.bozedu.net/data/upload/component/ebook_main/978-7-5447-2948-2-36/1.jpg",
//   "zem_file": "https://openapi.bozedu.net/data/upload/component/ebook_main/978-7-5447-2948-2-36.zip",
//   "zem_brief": "",
//   "zem_type": "图片",
//   "zem_filesize": "62468417",
//   "zem_open": "是",
//   "grade_id": "0",
//   "grade_name": "",
//   "subject_id": "0",
//   "subject_name": "",
//   "zem_belongto": "个人",
//   "area_id1": "0",
//   "area_id2": "0",
//   "area_id3": "0",
//   "area_id4": "0",
//   "sm_id": "0",
//   "dept_id": "0",
//   "user_id": "278795",
//   "create_user_id": "278795",
//   "modify_user_id": "0",
//   "create_dateline": "1596987128",
//   "modify_dateline": "0",
//   "isdelete": "0",
//   "zem_type_option_n": "图片",
//   "zem_type_option_k": "1",
//   "zem_open_option_n": "是",
//   "zem_open_option_k": "1",
//   "zem_belongto_option_n": "个人",
//   "zem_belongto_option_k": "2"
// }
export const ebookList = ref<any[]>([])

export function requestEbookList(d: any = {}) {
  ebookListLoading.value = true
  return request({
    url: '/zhkt/ebook_main/index',
    data: {
      limit: 1000,
      ...d,
    }
  }).then((res) => {
    if (res.code === '1') {
      ebookList.value = res.data.page_data
    }
  }).catch((error) => {
    console.error(error)
  }).finally(() => {
    ebookListLoading.value = false
  })
}

// requestEbookList()

export const ebookSelectedList = ref<string[]>([])

export function deleteEbook() {
  if (inDebug) {
    ebookList.value = ebookList.value.filter((item) => !ebookSelectedList.value.includes(item.zem_id))
    ebookSelectedList.value = []
    return
  }

  return request({
    url: '/zhkt/ebook_main/delete',
    data: {
      zem_id: ebookSelectedList.value
    }
  }).then((res) => {
    if (res.code === '1') {
      // requestEbookList()
      ebookList.value = ebookList.value.filter((item) => !ebookSelectedList.value.includes(item.zem_id))
      ebookSelectedList.value = []
    }
  }).catch((error) => {
    console.error(error)
  })
}
