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

// 初始化项目
export function initProject() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: 'PDM_项目名称_查询数据'
    }
  })
}
// 查询组件工艺
export function searchDetail(num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间装配管理_组件工艺_查询数据',
      param: '机床流水号=' + num
    }
  })
}
// 查询工序
export function searchProcess(num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间装配管理_装配工序_查询数据',
      param: '组件工艺流水号=' + num
    }
  })
}
// 编辑
export function update(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 getTree() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: 1,
      name: '人事档案管理_部门关系_查询节点',
      param: '子节点=0=int'
    }
  })
}
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 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
}
