plVehicleRechargeCopy.js 1.6 KB

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