import request from '@/router/axios';
/*获取列表*/
export const getList =
    (current, size, params) => {
      return request({
        url: '/api/jobslink-api/payment/businessOrder/tenant/list',
        method: 'get',
        params: {
          ...params,
          current,
          size,
        }
      })
    }

/*某个订单的发票列表*/
export const getDetail =
    (payOrderId) => {
      return new Promise(function(resolve, reject) {
        request({
          url: '/api/jobslink-api/payment/businessOrder/find/detail',
          method: 'get',
          params: {payOrderId}
        })
            .then((resp) => {
              const data = resp.data.data;
              if (data.length !== 0) {
                const result = {
                  data: [],
                  wageTotalNum: data[0].wageTotalNum,
                  serviceTotalNum: data[0].serviceTotalNum,
                };
                data.forEach(element => {
                  result.data.push({
                    missionTitle: element.missionTitle,
                    type: 1,
                    payrollNo: element.payrollNo,
                    total: element.wageTotal
                  });
                  result.data.push({
                    missionTitle: element.missionTitle,
                    type: 2,
                    payrollNo: element.payrollNo,
                    total: element.serviceTotal
                  });
                });
                resolve(result);
              } else {
                const result = {
                  data: [],
                  wageTotalNum: '',
                  serviceTotalNum: '',
                };
                resolve(result);
              }
            })
            .catch(reject)
      })
    }

/*查看某个发票详情*/
export const getDetailList =
    (payOrderId, orderNo) => {
      return request({
        url: '/api/jobslink-api/payment/invoice/list',
        method: 'get',
        params: {payOrderId, orderNo}
      })
    }


/*新增发票抬头*/
export const addFp =
    (row) => {
      return request({
        url: '/api/jobslink-api/tenant/fp/title/save',
        method: 'post',
        data: row
      })
    }

/*编辑发票抬头*/
export const updateFp =
    (row) => {
      return request({
        url: '/api/jobslink-api/tenant/fp/title/update',
        method: 'post',
        data: row
      })
    }
/*查看发票抬头*/
export const getFpDetail =
    () => {
      return request({
        url: '/api/jobslink-api/tenant/fp/title/detail',
        method: 'get',
        params: {}
      })
    }

/*获取默认收件地址*/
export const getAddressDetail =
    (id) => {
      return request({
        url: '/api/jobslink-api/tenant/fp/addressee/detail',
        method: 'get',
        params: {id}
      })
    }

/*获取收件地址列表*/
export const getAddressList =
    (current, size, params) => {
      return request({
        url: '/api/jobslink-api/tenant/fp/addressee/list',
        method: 'get',
        params: {...params, current, size}
      })
    }

/*获取不分页的收件地址(用于提交订单-选择收件地址)*/
export const getAddressAll =
    () => {
      return request({
        url: '/api/jobslink-api/tenant/fp/addressee/tenant/list',
        method: 'get',
        params: {}
      })
    }

/*收件地址详情*/
export const detail =
    (id) => {
      return request({
        url: '/api/jobslink-api/tenant/fp/addressee/detail',
        method: 'get',
        params: {id}
      })
    }

/*新增收件地址*/
export const add =
    (row) => {
      return request({
        url: '/api/jobslink-api/tenant/fp/addressee/save',
        method: 'post',
        data: row
      })
    }

/*编辑收件地址*/
export const update =
    (row) => {
      return request({
        url: '/api/jobslink-api/tenant/fp/addressee/update',
        method: 'post',
        data: row
      })
    }

/*删除收件地址*/
export const remove =
    (ids) => {
      return request({
        url: '/api/jobslink-api/tenant/fp/addressee/remove',
        method: 'post',
        params: {ids}
      })
    }

/*设置默认地址*/
export const setDefault = (id) => {
  return request({
    url: '/api/jobslink-api/tenant/fp/addressee/updateIsDefault',
    method: 'post',
    params: {id}
  })
}
