import { request } from 'umi';
import { api } from '../api';
console.log('process1', process);
export interface Postlist {
  nickName?: string;
  pageNum?: string | number;
  pageSize?: string | number;
  platformId?: string;
  userId?: string;
}
export interface AddGroup {
  groupName: string;
  remark?: string;
}
export interface EditGroup {
  groupId: string;
  groupName: string;
  remark?: string;
}
export interface ListGroup {
  groupName?: string;
}

/**获取二维码 */
export async function getAccount(params: { params: string; mpId: string }) {
  let str = encodeURIComponent(params.params + '?uuid=UUID');
  return request(api + `/system/mp/auth/${params.mpId}?callbackPage=${str}`);
}
export async function authSuccess(params: string) {
  return request(api + `/system/mp/authSuccess?${params}`);
}
/**获取绑定公众号列表 */
export async function postList(params?: Postlist) {
  return request(api + '/system/mp/list', {
    method: 'POST',
    data: params,
  });
}
/**同步*/
export async function putWx(params: { id: string }) {
  return request(`${api}/system/mp/refresh/${params.id}`, {
    method: 'PUT',
  });
}
/**添加公众号分组 */
export async function addGroup(params: AddGroup) {
  return request(api + '/system/mpGroup/add', {
    method: 'POST',
    data: params,
  });
}
/**用户的所有公众号分组*/
export async function listGroup() {
  return request(api + '/system/mp/allOfUserByGroup');
}
/**账户下属的公众号*/
export async function allOfMember() {
  return request(api + '/system/mp/allOfMember').then((res) => {
    res.data = res.data.map((item: any) => {
      item.value = item.value.filter((v: any) => !!v);
      return item;
    });
    return res
  });
}
/** 获取账号 */
export async function getAllZhMemBerApi() {
  return request(`${api}/erp/resourceOfUser/allOfMember/10`);
}
/** 获取投手 */
export async function getPicherListApi() {
  return request(`${api}/erp/user/subUserWithSelf`);
}

/**编辑公众号分组 */
export async function editGroup(params: EditGroup) {
  let { groupId, ...param } = params;
  return request(`${api}/system/mpGroup/modify/${groupId}`, {
    method: 'PUT',
    data: param,
  });
}
/**删除公众号分组 */
export async function delGroup(params: { groupId: string }) {
  return request(`${api}/system/mpGroup/del/${params.groupId}`, {
    method: 'DELETE',
  });
}
/**修改公众号所属分组 */
export async function configGroup(params: { groupId: string; mpAccountId: string }) {
  return request(`${api}/system/mp/configGroup`, {
    method: 'PUT',
    data: params,
  });
}
/**修改公众号状态 */
export async function editApproveStatus(params: { mpId: string; status: string }) {
  return request(`${api}/system/mp/configStatus/${params.mpId}/${params.status}`, {
    method: 'PUT',
  });
}
/**公众号信息完善 */
export async function perfect(params: {
  mpId: string;
  administratorCard?: string; //管理员身份证号码
  administratorName?: string; //管理员名称
  administratorWechat?: string; //管理员微信号
  legalCard?: string; //法人身份证
  legalName?: string; //法人姓名
  legalWechat?: string; //法人手机号
}) {
  let { mpId, ...param } = params;
  return request(`${api}/system/mp/${mpId}`, {
    method: 'PUT',
    data: param,
  });
}
/**修改切书记录*/

export async function modify2(params:any) {
 let {changeRecordId,...param} = params
  return request(`${api}/erp/resourceChangeRecord/modify2/${changeRecordId}`,{
    method:'PUT',
    data:param
  })
}
/**获取所有用户*/
export async function getAllUser() {
   return request(`${api}/erp/user/all`)
 }
//**删除切书记录 */
export async function del(changeRecordId:number) {
  return request(`${api}/erp/resourceChangeRecord/${changeRecordId}`,{
    method:'DELETE',
  })
}
/**切书验证*/ 
export async function verify(params:{resourceId:number,beginTime:string}) {
  let {resourceId,beginTime} = params
  return request(`${api}/erp/resourceChangeRecord/checkTime/${resourceId}/${beginTime}`,{
    method:'PUT',
  })
}

/**
 * 获取所有人员
 * @returns 
 */
export async function getUserAllApi() {
  return request(`${api}/erp/user/all`);
}