Self-consistent calculation of transient beam loading in electron storage rings with passive harmonic cavities