You probably need to do the same trick as the active class, but instead test for children…
<?php e($p->hasVisibleChildren(), ' has-dropdown') ?>
So that line becomes
<a class="al <?php e($p->hasVisibleChildren(), ' has-dropdown') ?> <?php e($p->isOpen(), ' active') ?>" href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>