Maximilian Beier scored twice and Nico Schlotterbeck provided two assists as Borussia Dortmund secured a crucial 3-1 win against in-form Mainz.