import {
	http,
	Method
} from '@/utils/request.js';
// 使用storage模块的方法设置登录状态为false
import storage from "@/utils/storage.js";
const request = http.request;

/**
 * 获取用户关联的地块列表
 * @param {number} pageNum - 页码
 * @param {number} pageSize - 每页数量
 * @returns {Promise} 
 */
export function fetchUserFieldList(pageNum = 1, pageSize = 10) {
	const user = storage.getUserInfo();
	return http.request({
		url: '/base/field/list/user',
		method: Method.POST,
		needToken: true,
		data: {
			userId: user.userid,
			params: {
				pageNum: pageNum,
				pageSize: pageSize
			}
		}
	});
}


/**
 * 获取当前登录用户默认地块
 */
export function listFieldName(userId) {
	return http.request({
		url: `/base/field/name/${userId}`,
		method: Method.GET,
		needToken: true
	});
}

/**
 * 根据当前登录用户搜索关联地块
 * @param keyWord 搜索关键词
 */
export function searchUserField(data) {
	console.log("da",data);
	const user = storage.getUserInfo();
	return http.request({
		url: '/base/field/search/user',
		method: Method.POST,
		needToken: true,
		data:{
			userId: user.userid,
			params: {
				keyword:data.keyword,
				pageNum: data.pageNum,
				pageSize: data.pageSize
			}
		}
	});
}

/**
 * 根据当前登录用户统计地块信息
 */
export function countUserPlots() {
	const user = storage.getUserInfo();
	return http.request({
		url: `/base/field/count/${user.userid}`,
		needToken: true,
		method: Method.GET,
	});
}