plVehicleRechargeCopy.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * ETC/油卡充值申请发微信群纯文本(无序号)
  3. */
  4. import { countPlAttachmentUrls } from '@/utils/plFuelRegisterCopy'
  5. const TYPE_LABELS = {
  6. etc: 'ETC',
  7. fuel: '油卡'
  8. }
  9. export function getPlRechargeTypeLabel(type) {
  10. return TYPE_LABELS[type] || type || '—'
  11. }
  12. export function buildVehicleRechargeApplyCopyText(row = {}) {
  13. const dash = '—'
  14. const plate = String(row.licensePlate || '').trim() || dash
  15. const odometer =
  16. row.odometerKm != null && Number.isFinite(Number(row.odometerKm))
  17. ? `${Number(row.odometerKm).toFixed(1)} KM`
  18. : dash
  19. return [
  20. `【${plate} - ETC/油卡充值申请】`,
  21. `申请单号:${row.applyNo || dash}`,
  22. `充值类型:${getPlRechargeTypeLabel(row.rechargeType)}`,
  23. `申请日期:${row.applyDate || dash}`,
  24. `申请人:${row.applicantName || dash}`,
  25. `车牌号:${plate}`,
  26. `期初公里数:${odometer}`,
  27. `附件个数:${countPlAttachmentUrls(row.attachmentUrls)}`,
  28. `备注:${String(row.remark || '').trim() || dash}`
  29. ].join('\n')
  30. }
  31. /** 复制到剪贴板;成功返回 true */
  32. export function copyVehicleRechargeApplyToClipboard(row) {
  33. const text = buildVehicleRechargeApplyCopyText(row)
  34. if (!text) {
  35. uni.showToast({ title: '暂无可复制内容', icon: 'none' })
  36. return Promise.resolve(false)
  37. }
  38. return new Promise((resolve) => {
  39. uni.setClipboardData({
  40. data: text,
  41. success: () => {
  42. uni.showToast({ title: '已复制', icon: 'success' })
  43. resolve(true)
  44. },
  45. fail: () => {
  46. uni.showToast({ title: '复制失败', icon: 'none' })
  47. resolve(false)
  48. }
  49. })
  50. })
  51. }