Plug-in hybrid electric vehicles (PHEVs) are becoming increasingly widespread due to their environmental benefits. However, PHEV penetration can overload distribution systems and increase operational costs. It is a major challenge to find an economically optimal solution under the condition of flattening load demand for systems. To this end, we formulate this problem as a two-layer optimization problem, and propose a hierarchical algorithm to solve it. For the upper layer, we flatten the load demand curve by using the water-filling principle. For the lower layer, we minimize the total cost for all consumers through a consensus-like iterative method in a distributed manner. Technical constraints caused by consumer demand and power limitations are both taken into account. In addition, a moving horizon approach is used to handle the random arrival of PHEVs and the inaccuracy of the forecast base demand. This paper focuses on distributed solutions under a time-varying switching topology so that all PHEV chargers conduct local computation and merely communicate with their neighbors, which is substantially different from the existing works. The advantages of our algorithm include a reduction in computational burden and high adaptability, which clearly has its own significance for the future smart grid. Finally, we demonstrate the advantages of the proposed algorithm in both theory and simulation.