Here's a function to remove the current basemap from the bottom layer, then add a new basemap and move it to the bottom layer.

    function setBasemap(basemap) {
      if (currentBasemap) {
        map.removeLayer(currentBasemap);
      }
      currentBasemap = basemap;
      map.addLayer(basemap);
      basemap.bringToBack();
    }
    var currentBasemap = basemap1; // default map
    setBasemap(currentBasemap); // Init
    
Then add the following within a click event to swap in another basemap:
 

       setBasemap(basemap2);