Hi, and Welcome to the Apple Community.
Wondering which iOS version is installed on your iPhone XR,
and which iMac model (year) you have,
and which Mac OS version is on the iMac.
Re: "The iPhone XR will not connect or charge at all. "
You might need to check this article carefully, and also ensure the cable meets requirements:
Connect iPhone and your computer with a cable – Apple Support
(NB: Also: says you need :
"Mac with a USB port and OSÂ X 10.9 or later")
_______________________________________________________________________________________
Re: "Why does my iPhone XR not charge when connected to my iMac?"
and
"slowly drains the battery"
Apple Support's article: Charge the iPhone battery – Apple Support
says:
Connect iPhone and your computer with a cable.
Eg:
✽ Make sure your computer is turned on—if iPhone is connected to a computer that’s turned off, the battery may drain instead of charge. Look for  on the battery icon to make sure your iPhone is charging.
✽ Note: Don’t try to charge your iPhone by connecting it to your keyboard, unless your keyboard has a high-power USB port.
_________________________________________________________________________________________________
Re: The device will not show up in iTunes
Make sure your iTunes is the latest version: Update to the latest version of iTunes – Apple Support
and
What to do: If your computer doesn't recognize your iPhone, iPad, or iPod - Apple Support
__________________________________________________________________________
Re: "cannot make a wired backup to my computer"
How to back up your iPhone, iPad and iPod touch with your Mac – Apple Support
Eg. says:
On a Mac with macOS Catalina or later : Back up with the Finder
_________________________________________________________________________
Re: " I was having the same problem with my iPhone 7, but was able to eventually get it to work"
Sometimes it may be that the software on Mac and / or iPhone needs updating to the latest versions.
All the best :-)