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

// 初始化 外协厂商
export function initOutHelp() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_基础表_外协厂家_查询数据'
    }
  })
}
// 初始化获取已预算价格，未选入到外协加工任务单的零件
export function getTable1(check, partNumber) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_外协任务执行_未选入零件_查询',
      param: '零件图号_check=' + check + '=int&零件图号=' + partNumber + '=string'
    }
  })
}
// 初始化获取已生成的外协加工任务单
export function getTable(checked, contractNumber, check) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理_外协加工任务单_查询数据_2020',
      param: '表单号_check=' + checked + '&表单号=' + contractNumber + '&查询历史_check=' + check
    }
  })
}
// 查询任务单明细
export function getParts(Number) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理工艺_外协任务执行_外协加工任务单明细_查询数据',
      param: '外协加工任务单流水号=' + Number
    }
  })
}

// 打回
export function getBack(processPlan, number) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理工艺_外协零件_打回',
      param: '工艺计划流水号=' + processPlan + '&外协数量=' + number
    }
  })
}
// 选入零件
export function insertParts(processNum, Number, outsourcingNumber) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理工艺_外协加工任务单_选入_循环执行',
      param: '外协加工任务单流水号=' + Number + '&工艺计划流水号组=' + processNum + '&外协数量组=' + outsourcingNumber
    }
  })
}
// 计算价格
export function getPrice(Number, money) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理工艺_外协加工任务单_保存_循环执行',
      param: '外协加工任务单明细流水号组=' + Number + '&加工价格_成交组=' + money
    }
  })
}
// 成交
export function editData1(Number, manufacturers, Group, money) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理_外协加工任务单_修改数据',
      param: '外协加工任务单流水号=' + Number + '&外协厂家=' + manufacturers + '&外协加工任务单明细流水号组=' + Group + '&加工价格_成交组=' + money + '&运费=0&单据状态=2&入库标志=1&扣款说明=&扣款_质量=0&扣款_计划=0&扣款_其他=0'
    }
  })
}
// 新建外协加工任务单
export function addTable(contractNumber, personNum, manufacturers, time, time2, freight) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理_外协加工任务单_增加数据',
      param: '表单号=' + contractNumber + '&外协计划员编号=' + personNum + '&外协厂家=' + manufacturers + '&任务下达日期=' + time + '&到货日期=' + time2 + '&运费=' + freight
    }
  })
}
// 外协加工任务单修改
export function editData(Number, manufacturers, freight, Explain, time2) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理_外协加工任务单_修改数据',
      param: '外协加工任务单流水号=' + Number + '&外协厂家=' + manufacturers + '&运费=' + freight + '&扣款说明=' + Explain + '&到货日期=' + time2
    }
  })
}
// 删除外协加工任务单
export function deleteData(Number) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理_外协加工任务单_删除数据',
      param: '外协加工任务单流水号=' + Number
    }
  })
}
// 移除零件
export function deleteData1(Number) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '车间生产管理_外协加工任务单明细_删除数据',
      param: '外协加工任务单明细流水号=' + Number
    }
  })
}

// 数据库生产表单号
export function getNumber(time) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '车间生产管理_外协加工任务单_查询数据_单据编号',
      param: '任务下达日期=' + time + '&表单号=1=string=output'
    }
  })
}
