import request from "~/request/request"

import { user } from "~/store/user"

export const docDialogVisible = ref(false)

export const docListLoading = ref(true)

export const docList = ref<any[]>([])

export function requestDocList(d: any = {}) {
  docListLoading.value = true
  return request({
    url: '/ybk/bkzy/index',
    data: {
      limit: 1000,
      ...d,
    }
  }).then((res) => {
    if (res.code === '1') {
      docList.value = res.data.page_data
    }
  }).catch((error) => {
    console.error(error)
  }).finally(() => {
    docListLoading.value = false
  })
}

// requestdocList()

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

export function sendDoc() {
  if (inDebug) {
    docSelectedList.value = []
    return
  }

  return request({
    url: '/ybk/bkzy_share/add',
    data: {
      ybk_bkzy_share: {
        ykz_id: docSelectedList.value,

        ybzs_send_user_id: user.value?.user_id,
        ybzs_send_user_realname: user.value?.user_realname,
        ybzs_receive: [
          {
            ybzs_receive_user_id: 278794,
            ybzs_receive_user_realname: '许胡明'
          }
        ],
      }
    }
  }).then((res) => {
    if (res.code === '1') {
      docSelectedList.value = []
    }
  }).catch((error) => {
    console.error(error)
  })
}
