orderDisplay.helpers.js 1.01 KB
const hasDisplayValue = value =>
  value !== null &&
  value !== undefined &&
  (typeof value !== 'string' || value.trim() !== '')

const preferCustomerValue = (customerValue, orderValue) =>
  hasDisplayValue(customerValue) ? customerValue : orderValue

/**
 * 将订单详情接口的嵌套客户、支付信息展开为页面展示对象。
 * 客户对象中的手机号和车牌号是权威值,避免被订单顶层空值覆盖。
 */
export function buildOrderDisplayInfo(order = {}) {
  const customer = order.customer || {}

  return {
    ...customer,
    ...(order.payOrder || {}),
    ...order,
    customerPhone: preferCustomerValue(
      customer.customerPhone,
      order.customerPhone
    ),
    plateNumber: preferCustomerValue(
      customer.plateNumber,
      order.plateNumber
    )
  }
}

export function resolveConstructionButton(confirmFlag) {
  if (Number(confirmFlag) === 1) {
    return {
      showBtn: '确认订单是否施工',
      btnName: 'confirmConstruction'
    }
  }

  return { showBtn: false }
}