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

// 机床名称
export function getMachines(role, personnel) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '机床_查询_营销筛选',
      param: '角色编号=' + role + '&人员编号=' + personnel
    }
  })
}
// 获取组号
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 getTable(checkbox_Machine, Machine, checkbox_Group, Group, checkbox_number, number, pageCurrent, pageSize, order, orderName, role, personnel) {
  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}&排序方式=${order}&排序名称=${orderName}&角色编号=${role}&人员编号=${personnel}&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: '车间生产管理工艺_追溯加工过程_查询工序',
      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'
    }
  })
}
export function getExport(num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: `select s1.* from ( 
  select a1.*, row_number() over (partition by 工艺计划流水号 order

  by 工序顺序) as group_idx

from (select TOP 100 PERCENT 零件图号,工艺计划流水号,机床流水号,工序顺序,工艺名称,材料,零件名称,投产数量,组号,机床图号 from dbo.车间生产管理工艺_零件工序_视图
where 考核状态 =6  and 机床流水号 = ${num} and 工艺编号 is not null and 完成日期 is null
group by 零件图号,工艺计划流水号,考核状态,机床流水号,工艺名称,工序顺序,材料,零件名称,投产数量,组号,机床图号
order by 工艺计划流水号,工序顺序) as a1 ) s1
where s1.group_idx= 1`
    }
  })
}

export function searchWorkTime(code) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: 1,
      name: '车间生产管理工艺_零件工艺计划_完成零件数量状态更改查询',
      param: '工序流水号=' + code + '=int'
    }
  })
}
export function submit2(num, num1, num2) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理工艺_零件工艺计划_完成零件数量状态更改',
      param: `工序流水号=${num}&完成数量=${num1}&操作者=${num2}`
    }
  })
}
export function submitEdit3(num, num1, num2, num3, num4) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理工艺_修补完成数量_增加数据',
      param: `工序流水号=${num}&操作者编号=${num1}&完成数量=${num2}&修补工时=${num3}&完成时间=${num4}`
    }
  })
}
export function getPerson_Form3() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_追溯加工过程_操作者查询'
    }
  })
}
// 获取工艺
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) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间管理_自制件插序_增加数据',
      param: '工艺计划流水号=' + NUM + '&工序顺序=' + NUM1 + '&工艺编号=' + NUM2
    }
  })
}
// 删除加序
export function deleteProcess(NUM) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间管理_自制件插序_删除数据',
      param: '工序流水号=' + NUM
    }
  })
}
// 判断能否删除加序
export function isDeleteProcess(NUM) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间管理_自制件插序_判断加工',
      param: '工序流水号=' + NUM
    }
  })
}
export function revoke(num, num1, num2, num3, num4) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生成管理_完成状态_修改数据',
      param: `工艺计划流水号=${num}&工序流水号=${num1}&完成数量=${num2}&完成过程流水号=${num3}&是否加序=${num4}`
    }
  })
}
export function searchTableDetail(num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_追溯加工过程_查询_合并情况',
      param: `工艺计划流水号=${num}`
    }
  })
}
