A vertex shader only calculates once per vertex. A fragment shader calculates once per pixel.
I'm not 100% on how you wanted to use the depth so I can't answer exactly what you need to do.
That said, one thing you do need to be aware of is that you can't reliably use multiple colour channels to represent a single value and have them interpolated automatically.
Trust me; I've tried to do exactly that and it looks fine... until it doesn't and you wonder what went wrong!. So, if you need depth to be interpolated, you should use just one channel. With that said, however, if you are using multiple integer values for depths - without interpolation - it should be ok; the values just represent a specific depth.
If what I understand about your intention is correct, you can assign a depth to the colour channel to each 'thing' you draw by setting the colour of all of their vertices to the same colour (just the channel(s) you are using for depth). You would need to do this for each vertex of each 'thing'. You would determine the depth to apply by reading its lowest vertex's y position and just set the colour to match.
Then, when you draw the 'thing', it (the fragment shader - per pixel) can compare the depth (colour channel) of what you are drawing with what is below it and decide which one (pixel colour) should be there based on which depth is higher/lower.
Note that this means you are calculating the depth per 'thing' manually and then setting its colour (channel(s)) to represent this depth but only per vertex, not per pixel, and you can, at this point, access the lowest vertex to see which depth it should have.
Hope that helps and it's somewhere near what you are going for. Or, at least, may spark some other idea!