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

// 初始化供应商
export function initSupplier() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: `SELECT distinct * from 采购管理_供应商`
    }
  })
}
export function initSupplier11(num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '采购管理_采购合同_供应商_查询数据',
      param: '采购员流水号=' + num
    }
  })
}
// 查询询价单列表 表1
export function searchInquirySheet(check2, value2, check3, id, check4, supplier) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '采购管理_询价单_查询数据_创建合同',
      param: `询价单编号_check=${check2}&询价单编号=${value2}&采购员流水号_check=${check3}&采购员流水号=${id}&供应商流水号_check=${check4}&供应商流水号=${supplier}`
    }
  })
}
// 根据询价单流水号查询物料详情
export function searchSheetContract(num1) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '采购管理_询价单明细_查询数据',
      param: '询价单流水号=' + num1
    }
  })
}
// 生成采购合同
export function doneContract(...params) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: '采购管理_采购合同_增加数据',
      param: `采购合同编号=${params[0]}\\&采购合同名称=${params[1]}\\&交货日期=${params[2]}\\&支付日期=${params[3]}\\&支付方式=${params[4]}\\&开票信息=${params[5]}\\&其他说明=${params[6]}\\&合同总额=${params[7]}\\&采购员流水号=${params[8]}\\&供应商流水号=${params[9]}\\&单价是否含税=${params[10]}\\&组件零件流水号组=${params[11]}\\&组件零件基本件流水号组=${params[12]}\\&数量组=${params[13]}\\&单价组=${params[14]}\\&交货期组=${params[15]}\\&合同内容\\=${params[16]}\\&税率=${params[17]}\\&询价单明细流水号组=${params[18]}\\&备注组=${params[19]}`
    }
  })
}
// 查询询价单基础信息维护
export function searchBaseInfo(id) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '采购管理_询价单基础信息_查询数据',
      param: '人员编号=' + id
    }
  })
}
// 实时保存单价
export function savePrice(price, num1, num2, num3, num4, num5) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '4',
      name: `update 采购管理_询价单明细_视图 set 单价 = ${price} where isnull(物料流水号,0) = isnull('${num1}',0) and 询价单流水号 = ${num2} and isnull(零件名称,'') = '${num3}' and isnull(零件图号,'') = '${num4}' and (isnull(规格,'') = '${num5}' or isnull(物料规格,'') = '${num5}')`
    }
  })
}
// 实时保存单价
export function pricechange1(price, num1) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: `采购管理_优惠修改单价`,
      param: '单价=' + price + '&询价单明细流水号=' + num1
    }
  })
}
// 实时保存备注
export function saveRemark(price, num1, num2, num3, num4, num5) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '4',
      name: `update 采购管理_询价单明细_视图 set 备注 = '${price}' where isnull(物料流水号,0) = isnull('${num1}',0) and 询价单流水号 = ${num2} and isnull(零件名称,'') = '${num3}' and isnull(零件图号,'') = '${num4}' and (isnull(规格,'') = '${num5}' or isnull(物料规格,'') = '${num5}')`
    }
  })
}
// 实时保存合同头
export function saveContractHeader(...params) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '4',
      name: `update 采购管理_询价单 set 交货日期 = '${params[0]}' , 开票信息 = '${params[1]}' , 支付日期 = '${params[2]}' , 支付方式 = '${params[3]}' , 其他说明 = '${params[4]}' where 询价单流水号 = ${params[5]}`
    }
  })
}
// 获取合同头
export function searchContractHeader(...params) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: `select * from 采购管理_询价单 where 询价单流水号 = ${params[0]}`
    }
  })
}
