I assume that you have tried another charger / power supply, correct?
Try a Forced Restart on the phone. This is the first thing that a technician will do if you take the phone in for service, so it might save you a trip. Follow the instructions very carefully, as this is a bit tricky.
(Hint.....ignore the "slider" when it appears and keep holding the Side button in until the Apple logo appears. This might take another 30 seconds.)
Force restart iPhone - Apple Support
There are only 2 possible results when you perform a Forced Restart:
1) The phone and charging return to normal operation
If the phone still won't charge unless it is powered down......
2) There is a hardware problem with the phone that will need attention at the Apple Store (make an appointment) or take the phone to an authorized Apple Service shop.
You can find a list of authorized service shops in your area using the link just below:
Find Locations
Hopefully, a genuine Apple battery was installed in your phone. Otherwise, Apple will probably refuse to look at the phone.