import server from '@/utils/request'

//新增
interface Addobj{
    typeCode:String                 //车辆型号编码
    vinNo:String	                //车辆识别代码VIN号
    frameworkNo:String	            //车架号
    ownerType:String|Number	        //车主类型：1-个人，2-企业
    ownerName:String	            //车主名称
    plateNum:String	                //车牌号
    engineNo:String	                //引擎号
    usageType:String	            //消费方式：1-电量，2-里程
    pkId?:String
    ownerId?:String	                //车主ID
    seatsCount?:String	            //座位数
    carColor?:String	            //车身颜色
    carArea?:String	                //车籍/归属地
    productionDate?:String	        //出厂日期
    purchaseDate?:String	        //购车日期
    boardDate?:String	            //上牌日期
    registrationDate?:String	    //首次登记日期
    totalMileage?:String	        //总里程
    phone?:String	                //联系电话
    cname?:String	                //公司名称
    ccode?:String	                //组织机构代码
}

export function addhdz(data:Addobj) {
  return server.request({
    url: '/cloud/vehicle/add',
    method: 'post',
    data
  })
}

//修改
export function update(data:Addobj) {
  return server.request({
    url: '/cloud/vehicle/update',
    method: 'post',
    data
  })
}

//查询
interface Querydata{
  pageSize:String|number,	//每页条数
  pageNo:String|number	    //页数
  typeCode?:String	        //型号编码
  vinNo?:String	            //车辆识别代码VIN号
  frameworkNo?:String	    //车架号
  ownerType?:String	        //车主类型：1-个人，2-企业
  ownerId?:String	        //车主ID
  ownerName?:String	        //车主名称
  plateNum?:String	        //车牌号
  phone?:String	            //联系电话
  engineNo?:String	        //引擎号
}
export function getjqrlist(params:Querydata) {
  return server.request({
    url: '/cloud/vehicle/list',
    method: 'get',
    params
  })
}


//删除车辆前查看是否有未结算订单
export function hasorder(plateNum:string) {
  return server.request({
    url: `cloud/order/swap/checkList?pageSize=20&pageNo=1&plateNum=${plateNum}`,
    method: 'get'
  })
}


//删除
export function delhdz(id:string) {
  return server.request({
    url: '/cloud/vehicle/del',
    method: 'post',
    data:{
      id
    }
  })
}

interface Bings{
  plateNum:String
  ccode:String
  cname:String
}

//绑定公司
export function Binggs(params:Bings) {
  return server.request({
    url: '/cloud/vehicle/company/relation',
    method: 'post',
    params
  })
}


interface Wxbin{
  ucode:String	          //用户编码
  uname:String	          //用户名称
  plateNum:String	        //车牌号
  ownerType:String	      //车主类型：1-个人，2-企业
  phone:String	          //关联人手机号
  openid?:String	          //微信用户标识
}

//绑定微信用户
export function Bingwx(params:Wxbin) {
  return server.request({
    url: '/cloud/vehicle/wechatuser/relation/add',
    method: 'post',
    params
  })
}

//解绑微信用户
export function unbindwx(id:String|Number) {
  return server.request({
    url: '/cloud/vehicle/wechatuser/relation/del',
    method: 'post',
    params:{id}
  })
}

//查询车辆绑关联微信用户
export function getcarwxlist(PlantNo:any) {
  return server.request({
    url: '/cloud/vehicle/relationuser/list',
    method: 'get',
    params:{
      PlantNo
    }
  })
}