import request from '@/utils/request'
import state from '@/store'
import router from '@/router'

// 机床名称
export function getMachines() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_传递后_机床名称_根据机床查询',
      param: '是否传递=2=int&考核状态=6=int&工艺任务分配状态=2=int&定额任务分配状态=2=int&单件是否外协=1=int'
    }
  })
}
// 获取组号
export function getGroups(stepNumber) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_传递后_组件名称_查询数据_查询所有组',
      param: '机床流水号=' + stepNumber + '=int'
    }
  })
}
// 获取工艺
export function initProcessNumber() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间管理_工艺_查询数据'
    }
  })
}
// 加序
export function addProcess(NUM, NUM1, NUM2, NUM3) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间管理_自制件插序_增加数据',
      param: '工艺计划流水号=' + NUM + '&工序顺序=' + NUM1 + '&工艺编号=' + NUM2 + '&操作工=' + NUM3
    }
  })
}
// 删除加序
export function deleteProcess(NUM) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间管理_自制件插序_删除数据',
      param: 'ID=' + NUM
    }
  })
}
export function getTable(checkbox_Machine, Machine, checkbox_Group, Group, checkbox_number, number, pageCurrent, pageSize) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_追溯加工过程_查询',
      param: `机床流水号_check=${checkbox_Machine}&机床流水号=${Machine}&组件流水号_check=${checkbox_Group}&组件流水号=${Group}&零件图号_check=${checkbox_number}&零件图号=${number}&PageCurrent=${pageCurrent}&PageSize=${pageSize}&PageCount=1111=int=output&ItemCount=1111=int=output`
    }
  })
}
// 获取组号
export function gettabledata1(num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_加工进度查询_查询_New_加序',
      param: '工艺计划流水号=' + num + '=int'
    }
  })
}
// 补录加工完成日期
export function editdata(processSerialNumber) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理工艺_加工进度查询_查询_New',
      param: '工艺计划流水号=' + processSerialNumber + '=int'
    }
  })
}
// 初始化人员信息 弹出框
export function getTree() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: 1,
      name: '人事档案管理_部门关系_查询节点',
      param: '子节点=0=int'
    }
  })
}

export function fn(data, pid) {
  const result = []
  let temp
  for (let i = 0; i < data.length; i++) {
    if (data[i].父节点 === pid) {
      const obj = { label: data[i].节点名称, id: data[i].子节点 }
      temp = fn(data, data[i].子节点)
      if (temp.length > 0) {
        obj.children = temp
      }
      result.push(obj)
    }
  }
  return result
}
export function getTable8(code) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: 1,
      name: '人事档案管理_人员_部门与人员_查询数据_根据部门编号',
      param: '考核部门编号=' + code + '=int'
    }
  })
}
export function submitEdit(Number1, completetime, processSerialNumber) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: 2,
      name: '车间生产管理工艺_零件工序_修改数据_工作者_根据人员编号和完成日期',
      param: '人员编号=' + Number1 + '=string&完成日期=' + completetime + '=string&工序流水号=' + processSerialNumber + '=string'
    }
  })
}
