Why Muslims got a lot of loss in the battle of Uhad?

As it is clearly pointed out in the Surah Al-i Imran, verse 152 and 165, the reason why Muslims defeated in the battle of Uhud is because of archers leaving their flanks. Disobeying to the orders of Prophet Muhammad (pbuh) immediately changed the course of the battle.

In addition, when we look at the defeat from the wisdom point of view, we come across with this verse: If a wound has touched you (at Uhud), (you know that) a similar wound touched those (disbelieving) people (at Badr). Such (historic eventful) days- We deal them out in turns among people so that God may mark out those who (truly) believe and select from among you such as bear witness to the truth (with their lives);- (it is a fact that) God does not love the wrongdoers (and in the end He punishes wrong and makes truth superior). (Al-i Imran Surah, 3:140) As it is stated in the verse, Allah Almighty; to test Muslims sincerity and commitment, to exalt Companions Hazrath Hamza and Musab bin Umayr to the palm of martyrdom whom among those believers and much other wisdom that we cannot know, referred the defeat to the Muslims.

Besides, Companions (of the past) were defeated by the Companions of the future. Among the idolaters were many people like Hazrath Khalid who in the future would be equal to the leading Companions of that time. Therefore, so as not to degrade them entirely in the view of the future, which for them would be glorious and honorable. Divine wisdom gave them in the past immediate recompense for their future good works and did not completely destroy their pride. (Flashes, 7. Flash)

The leader of the idolaters in the battle of Uhud, Abu Sufyan; main reason for the Muslim defeat, Khalid bin Valid and such so on started to become a Muslim after the Hudabia Treaty.