import request from 'libs/request'
import { getToken } from 'libs/token'
/*
** @decs 获取房源列表
*/
export function fetchHouseList (data) {
  data.estate_name = data.tools_0 || ''
  data.sale_type = data.tools_1 || ''
  data.query_name = data.searchKey || ''
  return request.get('house/queryAll', {params: data})
}

export function createHouse (data) {
  return request.post('house/add', data)
}

export function fetchHouseDetail (house_id) {
  return request.get('house/house', { params: {house_id} })
}

export function updateHouse (data) {
  return request.post('house/update', data)
}

export function fetchUnAgentHouse (params) {
  const defaultParams = {
    sale_type: 1,
    page_size: 10,
    page_num: 1,
    query_name: ''
  }
  params = Object.assign(defaultParams, params)
  return request.get('house/queryHouse', { params })
}

/*
** @desc 增加关联经纪人
** @params agency_user_id 经纪人id
** @params house_ids Array 房源id集合
*/
export function attachAgency (data) {
  return request.post('house/attachAgency', data)
}

/*
** @desc 修改关联经纪人
** @params agencyUserIdNew 准绑定经纪人id
** @params agencyUserIdOld 老绑定经纪人id
** @params house_id String 房源id
*/
export function changeAgency (data) {
  return request.post('house/changeAgency', data)
}
export function deleteHouse (strIds) {
  return request.post('house/delete', { strIds })
}

export function fetchAllScene (data) {
  const defaultParams = {
    page_num: 1,
    page_size: 10,
    searchKey: '',
    token: getToken()
  }
  return request.post('house/getAllScene', Object.assign(defaultParams, data))
}